You are here

function ConfigSchemaTest::testSchemaMappingWithParents in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/config/src/Tests/ConfigSchemaTest.php \Drupal\config\Tests\ConfigSchemaTest::testSchemaMappingWithParents()

Tests metadata retrieval with several levels of %parent indirection.

File

core/modules/config/src/Tests/ConfigSchemaTest.php, line 251
Contains \Drupal\config\Tests\ConfigSchemaTest.

Class

ConfigSchemaTest
Tests schema for configuration objects.

Namespace

Drupal\config\Tests

Code

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 = array(
    'type' => 'config_schema_test.someschema.with_parents.key_1',
    'label' => 'Test item nested one level',
    'class' => '\\Drupal\\Core\\TypedData\\Plugin\\DataType\\StringData',
    'definition_class' => '\\Drupal\\Core\\TypedData\\DataDefinition',
  );
  $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 = array(
    'type' => 'config_schema_test.someschema.with_parents.key_2',
    'label' => 'Test item nested two levels',
    'class' => '\\Drupal\\Core\\TypedData\\Plugin\\DataType\\StringData',
    'definition_class' => '\\Drupal\\Core\\TypedData\\DataDefinition',
  );
  $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 = array(
    'type' => 'config_schema_test.someschema.with_parents.key_3',
    'label' => 'Test item nested three levels',
    'class' => '\\Drupal\\Core\\TypedData\\Plugin\\DataType\\StringData',
    'definition_class' => '\\Drupal\\Core\\TypedData\\DataDefinition',
  );
  $this
    ->assertEqual($definition, $expected);
}