You are here

function ConfigFileContentTest::testSerialization in Zircon Profile 8

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

Tests serialization of configuration to file.

File

core/modules/config/src/Tests/ConfigFileContentTest.php, line 195
Contains \Drupal\config\Tests\ConfigFileContentTest.

Class

ConfigFileContentTest
Tests reading and writing of configuration files.

Namespace

Drupal\config\Tests

Code

function testSerialization() {
  $name = $this
    ->randomMachineName(10) . '.' . $this
    ->randomMachineName(10);
  $config_data = array(
    // Indexed arrays; the order of elements is essential.
    'numeric keys' => array(
      'i',
      'n',
      'd',
      'e',
      'x',
      'e',
      'd',
    ),
    // Infinitely nested keys using arbitrary element names.
    'nested keys' => array(
      // HTML/XML in values.
      'HTML' => '<strong> <bold> <em> <blockquote>',
      // UTF-8 in values.
      'UTF-8' => 'FrançAIS is ÜBER-åwesome',
      // Unicode in keys and values.
      'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ' => 'αβγδεζηθικλμνξοσὠ',
    ),
    'invalid xml' => '</title><script type="text/javascript">alert("Title XSS!");</script> & < > " \' ',
  );

  // Encode and write, and reload and decode the configuration data.
  $filestorage = new FileStorage($this->configDirectories[CONFIG_SYNC_DIRECTORY]);
  $filestorage
    ->write($name, $config_data);
  $config_parsed = $filestorage
    ->read($name);
  $key = 'numeric keys';
  $this
    ->assertIdentical($config_data[$key], $config_parsed[$key]);
  $key = 'nested keys';
  $this
    ->assertIdentical($config_data[$key], $config_parsed[$key]);
  $key = 'HTML';
  $this
    ->assertIdentical($config_data['nested keys'][$key], $config_parsed['nested keys'][$key]);
  $key = 'UTF-8';
  $this
    ->assertIdentical($config_data['nested keys'][$key], $config_parsed['nested keys'][$key]);
  $key = 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ';
  $this
    ->assertIdentical($config_data['nested keys'][$key], $config_parsed['nested keys'][$key]);
  $key = 'invalid xml';
  $this
    ->assertIdentical($config_data[$key], $config_parsed[$key]);
}