3 namespace Drupal\system\Tests\Cache;
5 use Drupal\simpletest\WebTestBase;
8 * Provides helper methods for cache tests.
10 * @deprecated Scheduled for removal in Drupal 9.0.0.
11 * Use \Drupal\Tests\system\Functional\Cache\CacheTestBase instead.
13 abstract class CacheTestBase extends WebTestBase {
15 protected $defaultBin = 'render';
16 protected $defaultCid = 'test_temporary';
17 protected $defaultValue = 'CacheTest';
20 * Checks whether or not a cache entry exists.
25 * The variable the cache should contain.
27 * The bin the cache item was stored in.
29 * TRUE on pass, FALSE on fail.
31 protected function checkCacheExists($cid, $var, $bin = NULL) {
33 $bin = $this->defaultBin;
36 $cached = \Drupal::cache($bin)->get($cid);
38 return isset($cached->data) && $cached->data == $var;
42 * Asserts that a cache entry exists.
47 * The variable the cache should contain.
51 * The bin the cache item was stored in.
53 protected function assertCacheExists($message, $var = NULL, $cid = NULL, $bin = NULL) {
55 $bin = $this->defaultBin;
58 $cid = $this->defaultCid;
61 $var = $this->defaultValue;
64 $this->assertTrue($this->checkCacheExists($cid, $var, $bin), $message);
68 * Asserts that a cache entry has been removed.
75 * The bin the cache item was stored in.
77 public function assertCacheRemoved($message, $cid = NULL, $bin = NULL) {
79 $bin = $this->defaultBin;
82 $cid = $this->defaultCid;
85 $cached = \Drupal::cache($bin)->get($cid);
86 $this->assertFalse($cached, $message);