variable.test 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * @file
  4. * Tests for variable.module.
  5. */
  6. /**
  7. * Helper class for module test cases.
  8. */
  9. class VariableTestCase extends DrupalWebTestCase {
  10. protected $admin_user;
  11. public static function getInfo() {
  12. return array(
  13. 'name' => 'Test Variable API',
  14. 'description' => 'Exercise the Variable API, default values, save and delete variables, etc.',
  15. 'group' => 'Variable',
  16. );
  17. }
  18. function setUp() {
  19. parent::setUp('variable', 'variable_admin');
  20. $this->admin_user = $this->drupalCreateUser(array('access administration pages', 'administer site configuration'));
  21. $this->drupalLogin($this->admin_user);
  22. }
  23. /**
  24. * Test that all core modules can be enabled, disabled and uninstalled.
  25. */
  26. function testVariableAPI() {
  27. // Check default values, set, get, delete.
  28. $this->assertEqual(variable_get_value('site_name'), 'Drupal', 'Function variable_get_value() returns proper default values.');
  29. $name = 'My test site';
  30. variable_set_value('site_name', $name);
  31. $this->assertTrue(variable_get('site_name'), 'Variable has been set using Variable API.');
  32. $this->drupalGet('');
  33. $this->assertText($name, 'Site name set with variable_set_value() is displayed.');
  34. variable_delete('site_name');
  35. $this->assertFalse(variable_get('site_name'), 'Variable has been deleted using Variable API.');
  36. $this->assertEqual(variable_get_value('site_name'), 'Drupal', 'Variable has been reset to its default value.');
  37. // Find variable information and specific variable in module and group list
  38. $variable = variable_get_info('site_name');
  39. $this->assertEqual($variable['title'], t('Site name'), 'Variable information can be retrieved for specific variable.');
  40. // Check our admin pages just to make sure all variable widgets are properly displayed.
  41. $this->drupalGet('admin/config/system/variable');
  42. $this->drupalGet('admin/config/system/variable/module');
  43. $this->drupalGet('admin/config/system/variable/edit/site_name');
  44. }
  45. }