function ConfigSchemaTest::testSchemaMappingWithParents

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php \Drupal\KernelTests\Core\Config\ConfigSchemaTest::testSchemaMappingWithParents()
  2. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php \Drupal\KernelTests\Core\Config\ConfigSchemaTest::testSchemaMappingWithParents()
  3. 11.x core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php \Drupal\KernelTests\Core\Config\ConfigSchemaTest::testSchemaMappingWithParents()

Tests metadata retrieval with several levels of %parent indirection.

File

core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php, line 272

Class

ConfigSchemaTest
Tests schema for configuration objects.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testSchemaMappingWithParents() {
    $config_data = \Drupal::service('config.typed')->get('config_schema_test.someschema.with_parents');
    // Test fetching parent one level up.
    $entry = $config_data->get('one_level');
    $definition = $entry->get('testitem')
        ->getDataDefinition()
        ->toArray();
    $expected = [
        'type' => 'config_schema_test.someschema.with_parents.key_1',
        'label' => 'Test item nested one level',
        'class' => StringData::class,
        'definition_class' => '\\Drupal\\Core\\TypedData\\DataDefinition',
        'unwrap_for_canonical_representation' => TRUE,
    ];
    $this->assertEqual($definition, $expected);
    // Test fetching parent two levels up.
    $entry = $config_data->get('two_levels');
    $definition = $entry->get('wrapper')
        ->get('testitem')
        ->getDataDefinition()
        ->toArray();
    $expected = [
        'type' => 'config_schema_test.someschema.with_parents.key_2',
        'label' => 'Test item nested two levels',
        'class' => StringData::class,
        'definition_class' => '\\Drupal\\Core\\TypedData\\DataDefinition',
        'unwrap_for_canonical_representation' => TRUE,
    ];
    $this->assertEqual($definition, $expected);
    // Test fetching parent three levels up.
    $entry = $config_data->get('three_levels');
    $definition = $entry->get('wrapper_1')
        ->get('wrapper_2')
        ->get('testitem')
        ->getDataDefinition()
        ->toArray();
    $expected = [
        'type' => 'config_schema_test.someschema.with_parents.key_3',
        'label' => 'Test item nested three levels',
        'class' => StringData::class,
        'definition_class' => '\\Drupal\\Core\\TypedData\\DataDefinition',
        'unwrap_for_canonical_representation' => TRUE,
    ];
    $this->assertEqual($definition, $expected);
}

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