class CacheTestBase
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Cache/CacheTestBase.php \Drupal\Tests\system\Functional\Cache\CacheTestBase
- 10 core/modules/system/tests/src/Functional/Cache/CacheTestBase.php \Drupal\Tests\system\Functional\Cache\CacheTestBase
- 8.9.x core/modules/system/src/Tests/Cache/CacheTestBase.php \Drupal\system\Tests\Cache\CacheTestBase
- 8.9.x core/modules/system/tests/src/Functional/Cache/CacheTestBase.php \Drupal\Tests\system\Functional\Cache\CacheTestBase
Provides helper methods for cache tests.
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\Cache\CacheTestBase extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of CacheTestBase
File
-
core/
modules/ system/ tests/ src/ Functional/ Cache/ CacheTestBase.php, line 10
Namespace
Drupal\Tests\system\Functional\CacheView source
abstract class CacheTestBase extends BrowserTestBase {
protected $defaultBin = 'render';
protected $defaultCid = 'test_temporary';
protected $defaultValue = 'CacheTest';
/**
* Checks 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 bool
* TRUE on pass, FALSE on fail.
*/
protected function checkCacheExists($cid, $var, $bin = NULL) {
if ($bin == NULL) {
$bin = $this->defaultBin;
}
$cached = \Drupal::cache($bin)->get($cid);
return isset($cached->data) && $cached->data == $var;
}
/**
* Asserts that 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->defaultBin;
}
if ($cid == NULL) {
$cid = $this->defaultCid;
}
if ($var == NULL) {
$var = $this->defaultValue;
}
$this->assertTrue($this->checkCacheExists($cid, $var, $bin), $message);
}
/**
* Asserts that 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.
*/
public function assertCacheRemoved($message, $cid = NULL, $bin = NULL) {
if ($bin == NULL) {
$bin = $this->defaultBin;
}
if ($cid == NULL) {
$cid = $this->defaultCid;
}
$cached = \Drupal::cache($bin)->get($cid);
$this->assertFalse($cached, $message);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.