3 namespace Drupal\Tests\system\Functional\Cache;
5 use Drupal\Tests\BrowserTestBase;
8 * Provides helper methods for cache tests.
10 abstract class CacheTestBase extends BrowserTestBase {
12 protected $defaultBin = 'render';
13 protected $defaultCid = 'test_temporary';
14 protected $defaultValue = 'CacheTest';
17 * Checks whether or not a cache entry exists.
22 * The variable the cache should contain.
24 * The bin the cache item was stored in.
26 * TRUE on pass, FALSE on fail.
28 protected function checkCacheExists($cid, $var, $bin = NULL) {
30 $bin = $this->defaultBin;
33 $cached = \Drupal::cache($bin)->get($cid);
35 return isset($cached->data) && $cached->data == $var;
39 * Asserts that a cache entry exists.
44 * The variable the cache should contain.
48 * The bin the cache item was stored in.
50 protected function assertCacheExists($message, $var = NULL, $cid = NULL, $bin = NULL) {
52 $bin = $this->defaultBin;
55 $cid = $this->defaultCid;
58 $var = $this->defaultValue;
61 $this->assertTrue($this->checkCacheExists($cid, $var, $bin), $message);
65 * Asserts that a cache entry has been removed.
72 * The bin the cache item was stored in.
74 public function assertCacheRemoved($message, $cid = NULL, $bin = NULL) {
76 $bin = $this->defaultBin;
79 $cid = $this->defaultCid;
82 $cached = \Drupal::cache($bin)->get($cid);
83 $this->assertFalse($cached, $message);