Commit 4527fc3f authored by sun's avatar sun Committed by gdd
Browse files

Added first CRUD tests.

parent 3e65c6d1
...@@ -92,6 +92,8 @@ class ConfigFileSecurityTestCase extends DrupalWebTestCase { ...@@ -92,6 +92,8 @@ class ConfigFileSecurityTestCase extends DrupalWebTestCase {
class ConfigFileContentTestCase extends DrupalWebTestCase { class ConfigFileContentTestCase extends DrupalWebTestCase {
protected $profile = 'testing'; protected $profile = 'testing';
protected $fileExtension = 'xml';
public static function getInfo() { public static function getInfo() {
return array( return array(
'name' => 'File content', 'name' => 'File content',
...@@ -101,12 +103,55 @@ class ConfigFileContentTestCase extends DrupalWebTestCase { ...@@ -101,12 +103,55 @@ class ConfigFileContentTestCase extends DrupalWebTestCase {
} }
/** /**
* Tests that a simple setting can be written and read. * Tests setting, writing, and reading of a configuration setting.
*/ */
function testReadWriteConfig() { function testReadWriteConfig() {
$config = config('foo.bar'); $name = 'foo.bar';
$config->set('foo', 'bar'); $key = 'foo';
$value = 'bar';
// Attempt to read non-existing configuration.
$nonexisting = $this->randomName();
$config = config($nonexisting);
// Verify an configuration object is returned.
// $this->assertEqual($config->name, $name);
$this->assertTrue($config);
// Verify the configuration object is empty.
$this->assertEqual($config->get(), array());
// Verify nothing was saved.
$db_config = db_query('SELECT * FROM {config} WHERE name = :name', array(':name' => $nonexisting))->fetch();
$this->assertIdentical($db_config, FALSE);
$this->assertFalse(file_exists($config_dir . '/' . $nonexisting . '.' . $this->fileExtension));
// Save the configuration.
$config = config($name);
$config->set($key, $value);
$config->save(); $config->save();
$this->assertEqual('bar', config('foo.bar')->get('foo'), 'Content retrived from written config data.'); // 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);
// Verify the file exists.
$config_dir = config_get_config_directory();
$this->assertTrue(file_exists($config_dir . '/' . $name . '.' . $this->fileExtension));
// Read the configuration.
$config = config($name);
// $this->assertEqual($config->name, $name);
$this->assertTrue($config);
$this->assertEqual($config->get($key), $value);
// 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);
$this->assertFalse(file_exists($config_dir . '/' . $name . '.' . $this->fileExtension));
// Write and read an array value.
// Add an array value to a nested key.
// Type casting into string.
// NULL value behavior.
// List config names by prefix.
} }
} }
Supports Markdown
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