function ClearTest::testFlushAllCaches

Same name in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/Cache/ClearTest.php \Drupal\Tests\system\Functional\Cache\ClearTest::testFlushAllCaches()
  2. 10 core/modules/system/tests/src/Functional/Cache/ClearTest.php \Drupal\Tests\system\Functional\Cache\ClearTest::testFlushAllCaches()
  3. 11.x core/modules/system/tests/src/Functional/Cache/ClearTest.php \Drupal\Tests\system\Functional\Cache\ClearTest::testFlushAllCaches()

Tests drupal_flush_all_caches().

File

core/modules/system/tests/src/Functional/Cache/ClearTest.php, line 33

Class

ClearTest

Namespace

Drupal\Tests\system\Functional\Cache

Code

public function testFlushAllCaches() {
    // Create cache entries for each flushed cache bin.
    $bins = Cache::getBins();
    $this->assertNotEmpty($bins, 'Cache::getBins() returned bins to flush.');
    foreach ($bins as $bin => $cache_backend) {
        $cid = 'test_cid_clear' . $bin;
        $cache_backend->set($cid, $this->defaultValue);
    }
    // Remove all caches then make sure that they are cleared.
    drupal_flush_all_caches();
    foreach ($bins as $bin => $cache_backend) {
        $cid = 'test_cid_clear' . $bin;
        $this->assertFalse($this->checkCacheExists($cid, $this->defaultValue, $bin), new FormattableMarkup('All cache entries removed from @bin.', [
            '@bin' => $bin,
        ]));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.