Newer
Older
Angie Byron
committed
<?php
/**
* @file
* Definition of Drupal\system\Tests\Cache\CacheTestBase.
*/
namespace Drupal\system\Tests\Cache;
use Drupal\simpletest\WebTestBase;
/**
* Provides helper methods for cache tests.
*/
Dries Buytaert
committed
abstract class CacheTestBase extends WebTestBase {
Angie Byron
committed
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
protected $default_bin = 'page';
protected $default_cid = 'test_temporary';
protected $default_value = 'CacheTest';
/**
* Check whether or not a cache entry exists.
*
* @param $cid
* The cache id.
* @param $var
* The variable the cache should contain.
* @param $bin
* The bin the cache item was stored in.
* @return
* TRUE on pass, FALSE on fail.
*/
protected function checkCacheExists($cid, $var, $bin = NULL) {
if ($bin == NULL) {
$bin = $this->default_bin;
}
$cached = cache($bin)->get($cid);
return isset($cached->data) && $cached->data == $var;
}
/**
* Assert or a cache entry exists.
*
* @param $message
* Message to display.
* @param $var
* The variable the cache should contain.
* @param $cid
* The cache id.
* @param $bin
* The bin the cache item was stored in.
*/
protected function assertCacheExists($message, $var = NULL, $cid = NULL, $bin = NULL) {
if ($bin == NULL) {
$bin = $this->default_bin;
}
if ($cid == NULL) {
$cid = $this->default_cid;
}
if ($var == NULL) {
$var = $this->default_value;
}
$this->assertTrue($this->checkCacheExists($cid, $var, $bin), $message);
}
/**
* Assert or a cache entry has been removed.
*
* @param $message
* Message to display.
* @param $cid
* The cache id.
* @param $bin
* The bin the cache item was stored in.
*/
function assertCacheRemoved($message, $cid = NULL, $bin = NULL) {
if ($bin == NULL) {
$bin = $this->default_bin;
}
if ($cid == NULL) {
$cid = $this->default_cid;
}
$cached = cache($bin)->get($cid);
$this->assertFalse($cached, $message);
}
/**
* Perform the general wipe.
* @param $bin
* The bin to perform the wipe on.
*/
protected function generalWipe($bin = NULL) {
if ($bin == NULL) {
$bin = $this->default_bin;
}
cache($bin)->expire();
}
}