function VarsExtendedTestCase::testRenamingVars in Variable API 7
Same name and namespace in other branches
- 6.2 tests/vars.test \VarsExtendedTestCase::testRenamingVars()
- 6 tests/vars.test \VarsExtendedTestCase::testRenamingVars()
- 7.2 tests/vars.test \VarsExtendedTestCase::testRenamingVars()
File
- tests/
vars.test, line 234 - Test file for the Variable API module.
Class
Code
function testRenamingVars() {
global $conf;
$rename_variables = array();
$written_variables = array();
Vars::staticReset();
$vars = new VarsExtendedTestVars();
$variables = $vars
->getDefaults();
foreach ($variables as $variable_name => $info) {
if (!empty($info['flags']) && $info['flags'] == Vars::VARS_DYNAMIC) {
$var_name = $variable_name . '_' . $this
->randomName(16);
}
elseif (empty($info['flags'])) {
$var_name = $variable_name;
}
$var_value = $this
->randomName(16);
variable_set($var_name, $var_value);
$written_variables[$var_name] = $var_value;
$rename_variables[$var_name] = $var_name . '_renamed_' . $this
->randomName(16);
}
Vars::renameVariables($rename_variables);
foreach ($rename_variables as $old_name => $new_name) {
$this
->assertTrue(!isset($conf[$old_name]) && isset($conf[$new_name]) && $conf[$new_name] === $written_variables[$old_name], t('The variable %old_name has been renamed %new_name.', array(
'%old_name' => $old_name,
'%new_name' => $new_name,
)));
$this
->assertFalse(vars_test_search_variable($old_name), t('The variable %old_name has not been retrieved in the database.', array(
'%old_name' => $old_name,
)));
$this
->assertTrue(vars_test_search_variable($new_name), t('The variable %new_name has been retrieved in the database.', array(
'%new_name' => $new_name,
)));
}
}