function ConfigEntityAdapterTest::testValidate

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityAdapterTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityAdapterTest::testValidate()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityAdapterTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityAdapterTest::testValidate()
  3. 11.x 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\Entity

Code

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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.