public function ContentEntityBaseUnitTest::testValidate in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php \Drupal\Tests\Core\Entity\ContentEntityBaseUnitTest::testValidate()
@covers ::validate
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ ContentEntityBaseUnitTest.php, line 329 - Contains \Drupal\Tests\Core\Entity\ContentEntityBaseUnitTest.
Class
- ContentEntityBaseUnitTest
- @coversDefaultClass \Drupal\Core\Entity\ContentEntityBase @group Entity @group Access
Namespace
Drupal\Tests\Core\EntityCode
public function testValidate() {
$validator = $this
->getMock('\\Symfony\\Component\\Validator\\ValidatorInterface');
/** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit_Framework_MockObject_MockObject $empty_violation_list */
$empty_violation_list = $this
->getMockBuilder('\\Symfony\\Component\\Validator\\ConstraintViolationList')
->setMethods(NULL)
->getMock();
$non_empty_violation_list = clone $empty_violation_list;
$violation = $this
->getMock('\\Symfony\\Component\\Validator\\ConstraintViolationInterface');
$non_empty_violation_list
->add($violation);
$validator
->expects($this
->at(0))
->method('validate')
->with($this->entity
->getTypedData())
->will($this
->returnValue($empty_violation_list));
$validator
->expects($this
->at(1))
->method('validate')
->with($this->entity
->getTypedData())
->will($this
->returnValue($non_empty_violation_list));
$this->typedDataManager
->expects($this
->exactly(2))
->method('getValidator')
->will($this
->returnValue($validator));
$this
->assertSame(0, count($this->entity
->validate()));
$this
->assertSame(1, count($this->entity
->validate()));
}