Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / system / tests / src / Functional / Cache / CacheTestBase.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Cache;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Provides helper methods for cache tests.
9  */
10 abstract class CacheTestBase extends BrowserTestBase {
11
12   protected $defaultBin = 'render';
13   protected $defaultCid = 'test_temporary';
14   protected $defaultValue = 'CacheTest';
15
16   /**
17    * Checks whether or not a cache entry exists.
18    *
19    * @param $cid
20    *   The cache id.
21    * @param $var
22    *   The variable the cache should contain.
23    * @param $bin
24    *   The bin the cache item was stored in.
25    * @return
26    *   TRUE on pass, FALSE on fail.
27    */
28   protected function checkCacheExists($cid, $var, $bin = NULL) {
29     if ($bin == NULL) {
30       $bin = $this->defaultBin;
31     }
32
33     $cached = \Drupal::cache($bin)->get($cid);
34
35     return isset($cached->data) && $cached->data == $var;
36   }
37
38   /**
39    * Asserts that a cache entry exists.
40    *
41    * @param $message
42    *   Message to display.
43    * @param $var
44    *   The variable the cache should contain.
45    * @param $cid
46    *   The cache id.
47    * @param $bin
48    *   The bin the cache item was stored in.
49    */
50   protected function assertCacheExists($message, $var = NULL, $cid = NULL, $bin = NULL) {
51     if ($bin == NULL) {
52       $bin = $this->defaultBin;
53     }
54     if ($cid == NULL) {
55       $cid = $this->defaultCid;
56     }
57     if ($var == NULL) {
58       $var = $this->defaultValue;
59     }
60
61     $this->assertTrue($this->checkCacheExists($cid, $var, $bin), $message);
62   }
63
64   /**
65    * Asserts that a cache entry has been removed.
66    *
67    * @param $message
68    *   Message to display.
69    * @param $cid
70    *   The cache id.
71    * @param $bin
72    *   The bin the cache item was stored in.
73    */
74   public function assertCacheRemoved($message, $cid = NULL, $bin = NULL) {
75     if ($bin == NULL) {
76       $bin = $this->defaultBin;
77     }
78     if ($cid == NULL) {
79       $cid = $this->defaultCid;
80     }
81
82     $cached = \Drupal::cache($bin)->get($cid);
83     $this->assertFalse($cached, $message);
84   }
85
86 }