You are here

function VarsExtendedTestCase::testReadingVars in Variable API 7

Same name and namespace in other branches
  1. 6.2 tests/vars.test \VarsExtendedTestCase::testReadingVars()
  2. 6 tests/vars.test \VarsExtendedTestCase::testReadingVars()
  3. 7.2 tests/vars.test \VarsExtendedTestCase::testReadingVars()

File

tests/vars.test, line 126
Test file for the Variable API module.

Class

VarsExtendedTestCase

Code

function testReadingVars() {
  $default_values = array();
  Vars::staticReset();
  $vars = new VarsTestVars();
  $extended_vars = new VarsExtendedTestVars();
  $variables = $extended_vars
    ->getDefaults();
  $defaults = Vars::loadDefaults('module:vars_extended_test', "module = '%s'", 'vars_extended_test');
  $this
    ->assertTrue(isset($defaults) && !empty($defaults['dynamic']) && !empty($defaults['static']), t('The default values for the module %module has been saved in the database.', array(
    '%module' => 'vars_extended_test',
  )));
  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;
    }
    $default_values[$var_name] = $info['value'];
  }
  foreach ($default_values as $name => $value) {
    $this
      ->assertIdentical($vars[$name], $value, t('The value of the variable %var_name has been retrieved through the class %class.', array(
      '%var_name' => $name,
      '%class' => 'VarsTestVars',
    )));
    $this
      ->assertIdentical($extended_vars[$name], $value, t('The value of the variable %var_name has been retrieved through the class %class.', array(
      '%var_name' => $name,
      '%class' => 'VarsExtendedTestVars',
    )));
  }
}