function ConfigSchemaTest::testSchemaData
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php \Drupal\KernelTests\Core\Config\ConfigSchemaTest::testSchemaData()
- 8.9.x core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php \Drupal\KernelTests\Core\Config\ConfigSchemaTest::testSchemaData()
- 10 core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php \Drupal\KernelTests\Core\Config\ConfigSchemaTest::testSchemaData()
Tests metadata applied to configuration objects.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Config/ ConfigSchemaTest.php, line 367
Class
- ConfigSchemaTest
- Tests schema for configuration objects.
Namespace
Drupal\KernelTests\Core\ConfigCode
public function testSchemaData() : void {
// Try a simple property.
$meta = \Drupal::service('config.typed')->get('system.site');
$property = $meta->get('page')
->get('front');
$this->assertInstanceOf(StringInterface::class, $property);
$this->assertEquals('/user/login', $property->getValue(), 'Got the right value for page.front data.');
$definition = $property->getDataDefinition();
$this->assertEmpty($definition['translatable'], 'Got the right translatability setting for page.front data.');
// Check nested array of properties.
$list = $meta->get('page')
->getElements();
$this->assertCount(3, $list, 'Got a list with the right number of properties for site page data');
$this->assertArrayHasKey('front', $list);
$this->assertArrayHasKey('403', $list);
$this->assertArrayHasKey('404', $list);
$this->assertEquals('/user/login', $list['front']->getValue(), 'Got the right value for page.front data from the list.');
// And test some TypedConfigInterface methods.
$properties = $list;
$this->assertCount(3, $properties, 'Got the right number of properties for site page.');
$this->assertSame($list['front'], $properties['front']);
$values = $meta->get('page')
->toArray();
$this->assertCount(3, $values, 'Got the right number of property values for site page.');
$this->assertSame($values['front'], '/user/login');
// Now let's try something more complex, with nested objects.
$wrapper = \Drupal::service('config.typed')->get('image.style.large');
$effects = $wrapper->get('effects');
$this->assertCount(2, $effects->toArray(), 'Got an array with effects for image.style.large data');
foreach ($effects->toArray() as $uuid => $definition) {
$effect = $effects->get($uuid)
->getElements();
if ($definition['id'] == 'image_scale') {
$this->assertFalse($effect['data']->isEmpty(), 'Got data for the image scale effect from metadata.');
$this->assertSame('image_scale', $effect['id']->getValue(), 'Got data for the image scale effect from metadata.');
$this->assertInstanceOf(IntegerInterface::class, $effect['data']->get('width'));
$this->assertEquals(480, $effect['data']->get('width')
->getValue(), 'Got the right value for the scale effect width.');
}
if ($definition['id'] == 'image_convert') {
$this->assertFalse($effect['data']->isEmpty(), 'Got data for the image convert effect from metadata.');
$this->assertSame('image_convert', $effect['id']->getValue(), 'Got data for the image convert effect from metadata.');
$this->assertSame('webp', $effect['data']->get('extension')
->getValue(), 'Got the right value for the convert effect extension.');
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.