You are here

public function CleanerKernelTests::testClearingCaches in Cleaner 8.2

Test clearing caches.

File

tests/src/Kernel/CleanerKernelTests.php, line 73

Class

CleanerKernelTests
Class CleanerKernelTests.

Namespace

Drupal\Tests\cleaner\Kernel

Code

public function testClearingCaches() {
  try {
    $this
      ->config('cleaner.settings')
      ->set('cleaner_clear_cache', TRUE)
      ->save();

    // Prepare cache backend service.
    $cache_backend = $this->container
      ->get('cache.default');

    // Create cache.
    $cid = $this
      ->randomString();
    $cache_backend
      ->set($cid, $this
      ->randomString());

    // Run subscriber's method.
    CleanerCacheClearEventSubscriber::create($this->container)
      ->clearCaches();

    // Check if cache entry has been removed.
    $this
      ->assertFalse($cache_backend
      ->get($cid));
  } catch (\Exception $e) {
    $this
      ->fail($e
      ->getMessage());
  }
}