Commit 1a04e970 authored by gdd's avatar gdd

Added a full range of tests for reading/writing config

parent e607acf4
......@@ -110,38 +110,92 @@ class ConfigFileContentTestCase extends DrupalWebTestCase {
$name = 'foo.bar';
$key = 'foo';
$value = 'bar';
$nested_key = 'biff.bang';
$nested_value = 'pow';
$array_key = 'array';
$array_value = array(
'foo' => 'bar',
'biff' => array(
'bang' => 'pow',
)
);
$nested_array_key = 'nested.array';
$true_key = 'true';
$false_key = 'false';
// Attempt to read non-existing configuration.
$config = config($name);
// Verify an configuration object is returned.
// $this->assertEqual($config->name, $name);
$this->assertTrue($config);
$this->assertTrue($config, t('Config object created.'));
// Verify the configuration object is empty.
$this->assertEqual($config->get(), array());
$this->assertEqual($config->get(), array(), t('New config object is empty.'));
// Verify nothing was saved.
$db_config = db_query('SELECT * FROM {config} WHERE name = :name', array(':name' => $name))->fetch();
$this->assertIdentical($db_config, FALSE);
$this->assertFalse(file_exists($config_dir . '/' . $name . '.' . $this->fileExtension));
$this->assertIdentical($db_config, FALSE, t('Active store does not have a record for %name', array('%name' => $name)));
$this->assertFalse(file_exists($config_dir . '/' . $name . '.' . $this->fileExtension), 'Configuration file does not exist.');
// Save the configuration.
// Add a top level value
$config = config($name);
$config->set($key, $value);
// Add a nested value
$config->set($nested_key, $nested_value);
// Add an array
$config->set($array_key, $array_value);
// Add a nested array
$config->set($nested_array_key, $array_value);
// Add a boolean false value. Should get cast to 0
$config->set($false_key, FALSE);
// Add a boolean true value. Should get cast to 1
$config->set($true_key, TRUE);
$config->save();
// Verify the database entry exists.
$db_config = db_query('SELECT * FROM {config} WHERE name = :name', array(':name' => $name))->fetch();
$this->assertEqual($db_config->name, $name);
$this->assertEqual($db_config->name, $name, t('After saving configuration, active store has a record for %name', array('%name' => $name)));
// Verify the file exists.
$this->assertTrue(file_exists($config_dir . '/' . $name . '.' . $this->fileExtension));
$this->assertTrue(file_exists($config_dir . '/' . $name . '.' . $this->fileExtension), t('After saving configuration, config file exists.'));
// Read the configuration.
// Read top level value
$config = config($name);
// $this->assertEqual($config->name, $name);
$this->assertTrue($config);
$this->assertEqual($config->get($key), $value);
$this->assertTrue($config, 'Config object created.');
$this->assertEqual($config->get($key), 'bar', t('Top level configuration value found.'));
// Read nested value
$this->assertEqual($config->get($nested_key), $nested_value, t('Nested configuration value found.'));
// Read array
$this->assertEqual($config->get($array_key), $array_value, t('Top level array configuration value found.'));
// Read nested array
$this->assertEqual($config->get($nested_array_key), $array_value, t('Nested array configuration value found.'));
// Read a top level value that doesn't exist
$this->assertNull($config->get('i_dont_exist'), t('Non-existent top level value returned NULL.'));
// Read a nested value that doesn't exist
$this->assertNull($config->get('i.dont.exist'), t('Non-existent nested value returned NULL.'));
// Read false value
$this->assertEqual($config->get($false_key), '0', t('Boolean FALSE value returned the string \'0\'.'));
// Read true value
$this->assertEqual($config->get($true_key), '1', t('Boolean TRUE value returned the string \'1\'.'));
// Delete the configuration.
$config = config($name);
$config->delete();
// Verify the database entry no longer exists.
$db_config = db_query('SELECT * FROM {config} WHERE name = :name', array(':name' => $name))->fetch();
$this->assertIdentical($db_config, FALSE);
......@@ -149,10 +203,7 @@ class ConfigFileContentTestCase extends DrupalWebTestCase {
// Chainable ->set()->save()
// Attempt to delete non-existing configuration.
// Write and read an array value.
// Add an array value to a nested key.
// Type casting into string. (recursively)
// NULL value behavior.
// List config names by prefix. (and without prefix)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment