Tests serialization of configuration to file.
function testSerialization() {
$name = $this
->randomName(10) . '.' . $this
->randomName(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_ACTIVE_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]);
}