public function ConfigEntityAdapterTest::testValidate in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityAdapterTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityAdapterTest::testValidate()
@covers ::validate
File
- core/
tests/ Drupal/ KernelTests/ Core/ Entity/ ConfigEntityAdapterTest.php, line 62
Class
- ConfigEntityAdapterTest
- Tests entity adapter for configuration entities.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testValidate() {
$adapter = ConfigEntityAdapter::createFromEntity($this->entity);
$violations = $adapter
->validate();
$this
->assertEmpty($violations);
$this->entity = \Drupal::entityTypeManager()
->getStorage('config_test')
->create([
'id' => 'system',
'label' => 'foobar',
// Set weight to be a string which should not validate.
'weight' => 'very heavy',
]);
$adapter = ConfigEntityAdapter::createFromEntity($this->entity);
$violations = $adapter
->validate();
$this
->assertCount(1, $violations);
$violation = $violations
->get(0);
$this
->assertEquals('This value should be of the correct primitive type.', $violation
->getMessage());
$this
->assertEquals('weight', $violation
->getPropertyPath());
}