cache_example.test 3.0 KB

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