Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
222
Merge Requests
222
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
e6e359b4
Commit
e6e359b4
authored
Apr 02, 2015
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2142997
by stefan.r: Test for ValidReferenceConstraintValidator
parent
2d149c81
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
0 deletions
+75
-0
core/modules/system/src/Tests/Entity/ValidReferenceConstraintValidatorTest.php
...rc/Tests/Entity/ValidReferenceConstraintValidatorTest.php
+75
-0
No files found.
core/modules/system/src/Tests/Entity/ValidReferenceConstraintValidatorTest.php
0 → 100644
View file @
e6e359b4
<?php
/**
* @file
* Contains \Drupal\system\Tests\Entity\ValidReferenceConstraintValidatorTest.
*/
namespace
Drupal\system\Tests\Entity
;
use
Drupal\Core\Field\BaseFieldDefinition
;
use
Drupal\system\Tests\TypedData
;
/**
* Tests validation constraints for ValidReferenceConstraintValidator.
*
* @group Validation
*/
class
ValidReferenceConstraintValidatorTest
extends
EntityUnitTestBase
{
/**
* The typed data manager to use.
*
* @var \Drupal\Core\TypedData\TypedDataManager
*/
protected
$typedData
;
/**
* {@inheritdoc}
*/
public
static
$modules
=
array
(
'field'
,
'user'
);
/**
* @inheritdoc
*/
public
function
setUp
()
{
parent
::
setUp
();
$this
->
installSchema
(
'user'
,
array
(
'users_data'
));
$this
->
typedData
=
$this
->
container
->
get
(
'typed_data_manager'
);
}
/**
* Tests the ValidReferenceConstraintValidator.
*/
public
function
testValidation
()
{
// Create a test entity to be referenced.
$entity
=
$this
->
createUser
();
// By default entity references already have the ValidReference constraint.
$definition
=
BaseFieldDefinition
::
create
(
'entity_reference'
)
->
setSettings
(
array
(
'target_type'
=>
'user'
));
$typed_data
=
$this
->
typedData
->
create
(
$definition
,
array
(
'target_id'
=>
$entity
->
id
()));
$violations
=
$typed_data
->
validate
();
$this
->
assertFalse
(
$violations
->
count
(),
'Validation passed for correct value.'
);
// NULL is also considered a valid reference.
$typed_data
=
$this
->
typedData
->
create
(
$definition
,
array
(
'target_id'
=>
NULL
));
$violations
=
$typed_data
->
validate
();
$this
->
assertFalse
(
$violations
->
count
(),
'Validation passed for correct value.'
);
$typed_data
=
$this
->
typedData
->
create
(
$definition
,
array
(
'target_id'
=>
$entity
->
id
()));
// Delete the referenced entity.
$entity
->
delete
();
$violations
=
$typed_data
->
validate
();
$this
->
assertTrue
(
$violations
->
count
(),
'Validation failed for incorrect value.'
);
// Make sure the information provided by a violation is correct.
$violation
=
$violations
[
0
];
$this
->
assertEqual
(
$violation
->
getMessage
(),
t
(
'The referenced entity (%type: %id) does not exist.'
,
array
(
'%type'
=>
'user'
,
'%id'
=>
$entity
->
id
(),
)),
'The message for invalid value is correct.'
);
$this
->
assertEqual
(
$violation
->
getRoot
(),
$typed_data
,
'Violation root is correct.'
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment