public function ContentEntityBaseUnitTest::testValidate in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php \Drupal\Tests\Core\Entity\ContentEntityBaseUnitTest::testValidate()
- 9 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 419
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 $empty_violation_list */
$empty_violation_list = new ConstraintViolationList();
$non_empty_violation_list = clone $empty_violation_list;
$violation = $this
->createMock('\\Symfony\\Component\\Validator\\ConstraintViolationInterface');
$non_empty_violation_list
->add($violation);
$validator
->expects($this
->exactly(2))
->method('validate')
->with($this->entity
->getTypedData())
->willReturnOnConsecutiveCalls($empty_violation_list, $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());
}