You are here

function ConfigSchemaTest::testSchemaData in Zircon Profile 8

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

Tests metadata applied to configuration objects.

File

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

Class

ConfigSchemaTest
Tests schema for configuration objects.

Namespace

Drupal\config\Tests

Code

function testSchemaData() {

  // Try a simple property.
  $meta = \Drupal::service('config.typed')
    ->get('system.site');
  $property = $meta
    ->get('page')
    ->get('front');
  $this
    ->assertTrue($property instanceof StringInterface, 'Got the right wrapper fo the page.front property.');
  $this
    ->assertEqual($property
    ->getValue(), '/user/login', 'Got the right value for page.front data.');
  $definition = $property
    ->getDataDefinition();
  $this
    ->assertTrue(empty($definition['translatable']), 'Got the right translatability setting for page.front data.');

  // Check nested array of properties.
  $list = $meta
    ->get('page')
    ->getElements();
  $this
    ->assertEqual(count($list), 3, 'Got a list with the right number of properties for site page data');
  $this
    ->assertTrue(isset($list['front']) && isset($list['403']) && isset($list['404']), 'Got a list with the right properties for site page data.');
  $this
    ->assertEqual($list['front']
    ->getValue(), '/user/login', 'Got the right value for page.front data from the list.');

  // And test some TypedConfigInterface methods.
  $properties = $list;
  $this
    ->assertTrue(count($properties) == 3 && $properties['front'] == $list['front'], 'Got the right properties for site page.');
  $values = $meta
    ->get('page')
    ->toArray();
  $this
    ->assertTrue(count($values) == 3 && $values['front'] == '/user/login', 'Got the right property values for site page.');

  // Now let's try something more complex, with nested objects.
  $wrapper = \Drupal::service('config.typed')
    ->get('image.style.large');
  $effects = $wrapper
    ->get('effects');
  $this
    ->assertTrue(count($effects
    ->toArray()) == 1, 'Got an array with effects for image.style.large data');
  $uuid = key($effects
    ->getValue());
  $effect = $effects
    ->get($uuid)
    ->getElements();
  $this
    ->assertTrue(!$effect['data']
    ->isEmpty() && $effect['id']
    ->getValue() == 'image_scale', 'Got data for the image scale effect from metadata.');
  $this
    ->assertTrue($effect['data']
    ->get('width') instanceof IntegerInterface, 'Got the right type for the scale effect width.');
  $this
    ->assertEqual($effect['data']
    ->get('width')
    ->getValue(), 480, 'Got the right value for the scale effect width.');
}