ClearTest.php

Same filename in other branches
  1. 9 core/modules/system/tests/src/Functional/Cache/ClearTest.php
  2. 8.9.x core/modules/system/tests/src/Functional/Cache/ClearTest.php
  3. 11.x core/modules/system/tests/src/Functional/Cache/ClearTest.php

Namespace

Drupal\Tests\system\Functional\Cache

File

core/modules/system/tests/src/Functional/Cache/ClearTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\system\Functional\Cache;

use Drupal\Core\Cache\Cache;

/**
 * Tests our clearing is done the proper way.
 *
 * @group Cache
 */
class ClearTest extends CacheTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        $this->defaultBin = 'render';
        $this->defaultValue = $this->randomMachineName(10);
        parent::setUp();
    }
    
    /**
     * Tests drupal_flush_all_caches().
     */
    public function testFlushAllCaches() : void {
        // 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), "All cache entries removed from {$bin}.");
        }
    }

}

Classes

Title Deprecated Summary
ClearTest Tests our clearing is done the proper way.

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