cache_example.test

  1. examples
    1. 7 cache_example/cache_example.test
    2. 8 cache_example/cache_example.test

Test case for testing the cache example module.

Classes

NameDescription
CacheExampleTestCase@file Test case for testing the cache example module.

File

cache_example/cache_example.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Test case for testing the cache example module.
  5. */
  6. class CacheExampleTestCase extends DrupalWebTestCase {
  7. public static function getInfo() {
  8. return array(
  9. 'name' => 'Cache example functionality',
  10. 'description' => 'Test the Cache Example module.',
  11. 'group' => 'Examples',
  12. );
  13. }
  14. /**
  15. * Enable module.
  16. */
  17. function setUp() {
  18. parent::setUp('cache_example');
  19. }
  20. /**
  21. * Load cache example page and test if displaying uncached version. Reload once again and test
  22. * if displaying cached version. Find reload link and click on it. Clear cache at the end and
  23. * test if displaying uncached version again.
  24. */
  25. function testCacheExampleBasic() {
  26. // We need administrative privileges to clear the cache.
  27. $admin_user = $this->drupalCreateUser(array('administer site configuration'));
  28. $this->drupalLogin($admin_user);
  29. // Get uncached output of cache example page and assert some things to be sure.
  30. $this->drupalGet('examples/cache_example');
  31. $this->assertText('Source: actual file search');
  32. // Reload the page; the number should be cached.
  33. $this->drupalGet('examples/cache_example');
  34. $this->assertText('Source: cached');
  35. // Now push the button to remove the count.
  36. $this->drupalPost('examples/cache_example', array(), t('Explicitly remove cached file count'));
  37. $this->assertText('Source: actual file search');
  38. // Create a cached item. First make sure it doesn't already exist.
  39. $this->assertText('Cache item does not exist');
  40. $this->drupalPost('examples/cache_example', array('expiration' => -10), t('Create a cache item with this expiration'));
  41. // We should now have an already-expired item
  42. $this->assertText('Cache item exists and is set to expire');
  43. // Now do the expiration operation
  44. $this->drupalPost('examples/cache_example', array('cache_clear_type' => 'expire'), t('Clear or expire cache'));
  45. // And verify that it was removed.
  46. $this->assertText('Cache item does not exist');
  47. // Create a cached item. This time we'll make it not expire.
  48. $this->drupalPost('examples/cache_example', array('expiration' => 'never_remove'), t('Create a cache item with this expiration'));
  49. // We should now have an never-remove item
  50. $this->assertText('Cache item exists and is set to expire at Never expires');
  51. // Now do the expiration operation
  52. $this->drupalPost('examples/cache_example', array('cache_clear_type' => 'expire'), t('Clear or expire cache'));
  53. // And verify that it was not removed.
  54. $this->assertText('Cache item exists and is set to expire at Never expires');
  55. // Now do full removal
  56. $this->drupalPost('examples/cache_example', array('cache_clear_type' => 'remove_wildcard'), t('Clear or expire cache'));
  57. // And verify that it was removed.
  58. $this->assertText('Cache item does not exist');
  59. }
  60. }
Login or register to post comments