Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
1a04e970
Commit
1a04e970
authored
Feb 17, 2012
by
Greg Dunlap
Browse files
Options
Downloads
Patches
Plain Diff
Added a full range of tests for reading/writing config
parent
e607acf4
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/config/config.test
+65
-14
65 additions, 14 deletions
core/modules/config/config.test
with
65 additions
and
14 deletions
core/modules/config/config.test
+
65
−
14
View file @
1a04e970
...
@@ -110,38 +110,92 @@ class ConfigFileContentTestCase extends DrupalWebTestCase {
...
@@ -110,38 +110,92 @@ class ConfigFileContentTestCase extends DrupalWebTestCase {
$name
=
'foo.bar'
;
$name
=
'foo.bar'
;
$key
=
'foo'
;
$key
=
'foo'
;
$value
=
'bar'
;
$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.
// Attempt to read non-existing configuration.
$config
=
config
(
$name
);
$config
=
config
(
$name
);
// Verify an configuration object is returned.
// Verify an configuration object is returned.
// $this->assertEqual($config->name, $name);
// $this->assertEqual($config->name, $name);
$this
->
assertTrue
(
$config
);
$this
->
assertTrue
(
$config
,
t
(
'Config object created.'
));
// Verify the configuration object is empty.
// 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.
// Verify nothing was saved.
$db_config
=
db_query
(
'SELECT * FROM {config} WHERE name = :name'
,
array
(
':name'
=>
$name
))
->
fetch
();
$db_config
=
db_query
(
'SELECT * FROM {config} WHERE name = :name'
,
array
(
':name'
=>
$name
))
->
fetch
();
$this
->
assertIdentical
(
$db_config
,
FALSE
);
$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
));
$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
=
config
(
$name
);
$config
->
set
(
$key
,
$value
);
$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
();
$config
->
save
();
// Verify the database entry exists.
// Verify the database entry exists.
$db_config
=
db_query
(
'SELECT * FROM {config} WHERE name = :name'
,
array
(
':name'
=>
$name
))
->
fetch
();
$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.
// 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 t
he configuration.
// Read t
op level value
$config
=
config
(
$name
);
$config
=
config
(
$name
);
// $this->assertEqual($config->name, $name);
// $this->assertEqual($config->name, $name);
$this
->
assertTrue
(
$config
);
$this
->
assertTrue
(
$config
,
'Config object created.'
);
$this
->
assertEqual
(
$config
->
get
(
$key
),
$value
);
$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.
// Delete the configuration.
$config
=
config
(
$name
);
$config
=
config
(
$name
);
$config
->
delete
();
$config
->
delete
();
// Verify the database entry no longer exists.
// Verify the database entry no longer exists.
$db_config
=
db_query
(
'SELECT * FROM {config} WHERE name = :name'
,
array
(
':name'
=>
$name
))
->
fetch
();
$db_config
=
db_query
(
'SELECT * FROM {config} WHERE name = :name'
,
array
(
':name'
=>
$name
))
->
fetch
();
$this
->
assertIdentical
(
$db_config
,
FALSE
);
$this
->
assertIdentical
(
$db_config
,
FALSE
);
...
@@ -149,10 +203,7 @@ class ConfigFileContentTestCase extends DrupalWebTestCase {
...
@@ -149,10 +203,7 @@ class ConfigFileContentTestCase extends DrupalWebTestCase {
// Chainable ->set()->save()
// Chainable ->set()->save()
// Attempt to delete non-existing configuration.
// 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)
// Type casting into string. (recursively)
// NULL value behavior.
// List config names by prefix. (and without prefix)
// List config names by prefix. (and without prefix)
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment