CacheExampleTestCase.php
3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* @file
* Test case for testing the cache example module.
*/
namespace Drupal\cache_example\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests for the cache_example module.
*
* @ingroup cache_example
* @group cache_example
* @group examples
*/
class CacheExampleTestCase extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('cache_example');
/**
* The installation profile to use with this test.
*
* @var string
*/
protected $profile = 'minimal';
/**
* Test menu links and routes.
*
* Test the following:
* - A link to the cache_example in the Tools menu.
* - That you can successfully access the cache_example form.
*/
public function testCacheExampleMenu() {
// Test for a link to the cache_example in the Tools menu.
$this->drupalGet('');
$this->assertResponse(200, 'The Home page is available.');
$this->assertLinkByHref('examples/cache_example');
// Verify if the can successfully access the cache_example form.
$this->drupalGet('examples/cache_example');
$this->assertResponse(200, 'The Cache Example description page is available.');
}
/**
* Test that our caches function.
*
* Does the following:
* - Load cache example page and test if displaying uncached version.
* - Reload once again and test if displaying cached version.
* - Find reload link and click on it.
* - Clear cache at the end and test if displaying uncached version again.
*/
public function testCacheExampleBasic() {
// We need administrative privileges to clear the cache.
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
$this->drupalLogin($admin_user);
// Get initial page cache example page, first time accessed,
// and assert uncached output.
$this->drupalGet('examples/cache_example');
$this->assertText('Source: actual file search');
// Reload the page; the number should be cached.
$this->drupalGet('examples/cache_example');
$this->assertText('Source: cached');
// Now push the button to remove the count.
$this->drupalPostForm('examples/cache_example', array(), t('Explicitly remove cached file count'));
$this->assertText('Source: actual file search');
// Create a cached item. First make sure it doesn't already exist.
$this->assertText('Cache item does not exist');
$this->drupalPostForm('examples/cache_example', array('expiration' => -10), t('Create a cache item with this expiration'));
// We should now have an already-expired item. Automatically invalid.
$this->assertText('Cache_item is invalid');
// Now do the expiration operation.
$this->drupalPostForm('examples/cache_example', array('cache_clear_type' => 'expire'), t('Clear or expire cache'));
// And verify that it was removed.
$this->assertText('Cache item does not exist');
// Create a cached item. This time we'll make it not expire.
$this->drupalPostForm('examples/cache_example', array('expiration' => 'never_remove'), t('Create a cache item with this expiration'));
// We should now have an never-remove item.
$this->assertText('Cache item exists and is set to expire at Never expires');
// Now do the expiration operation.
$this->drupalPostForm('examples/cache_example', array('cache_clear_type' => 'expire'), t('Clear or expire cache'));
// And verify that it was not removed.
$this->assertText('Cache item exists and is set to expire at Never expires');
// Now do tag invalidation.
$this->drupalPostForm('examples/cache_example', array('cache_clear_type' => 'remove_tag'), t('Clear or expire cache'));
// And verify that it was invalidated.
$this->assertText('Cache_item is invalid');
// Do the hard delete
$this->drupalPostForm('examples/cache_example', array('cache_clear_type' => 'remove_all'), t('Clear or expire cache'));
// And verify that it was removed.
$this->assertText('Cache item does not exist');
}
}