Added first CRUD tests.

8.0.x
sun 2012-02-14 06:40:40 +01:00 committed by Greg Dunlap
parent 3e65c6d1a1
commit 4527fc3f80
1 changed files with 49 additions and 4 deletions

View File

@ -92,6 +92,8 @@ class ConfigFileSecurityTestCase extends DrupalWebTestCase {
class ConfigFileContentTestCase extends DrupalWebTestCase {
protected $profile = 'testing';
protected $fileExtension = 'xml';
public static function getInfo() {
return array(
'name' => 'File content',
@ -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() {
$config = config('foo.bar');
$config->set('foo', 'bar');
$name = '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();
$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.
}
}