function ContentEntityBaseUnitTest::testValidate
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php \Drupal\Tests\Core\Entity\ContentEntityBaseUnitTest::testValidate()
- 10 core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php \Drupal\Tests\Core\Entity\ContentEntityBaseUnitTest::testValidate()
- 11.x 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 358
Class
- ContentEntityBaseUnitTest
- @coversDefaultClass \Drupal\Core\Entity\ContentEntityBase @group Entity @group Access
Namespace
Drupal\Tests\Core\EntityCode
public function testValidate() {
$validator = $this->createMock(ValidatorInterface::class);
/** @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->createMock('\\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->assertCount(0, $this->entity
->validate());
$this->assertCount(1, $this->entity
->validate());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.