Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
4527fc3f
Commit
4527fc3f
authored
Feb 14, 2012
by
sun
Committed by
gdd
Feb 14, 2012
Browse files
Added first CRUD tests.
parent
3e65c6d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
core/modules/config/config.test
View file @
4527fc3f
...
@@ -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
writ
ten
and read.
* Tests
setting,
writ
ing,
and read
ing 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.
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment