function GenericCacheBackendUnitTestBase::testDeleteMultiple

Same name in other branches
  1. 8.9.x core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php \Drupal\system\Tests\Cache\GenericCacheBackendUnitTestBase::testDeleteMultiple()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php \Drupal\KernelTests\Core\Cache\GenericCacheBackendUnitTestBase::testDeleteMultiple()
  3. 10 core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php \Drupal\KernelTests\Core\Cache\GenericCacheBackendUnitTestBase::testDeleteMultiple()
  4. 11.x core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php \Drupal\KernelTests\Core\Cache\GenericCacheBackendUnitTestBase::testDeleteMultiple()

@covers \Drupal\Core\Cache\ApcuBackend::deleteMultiple @covers \Drupal\Core\Cache\BackendChain::deleteMultiple @covers \Drupal\Core\Cache\ChainedFastBackend::deleteMultiple @covers \Drupal\Core\Cache\DatabaseBackend::deleteMultiple @covers \Drupal\Core\Cache\MemoryBackend::deleteMultiple @covers \Drupal\Core\Cache\PhpBackend::deleteMultiple @covers \Drupal\Core\Cache\ApcuBackend::deleteMultiple @covers \Drupal\Core\Cache\BackendChain::deleteMultiple @covers \Drupal\Core\Cache\ChainedFastBackend::deleteMultiple @covers \Drupal\Core\Cache\DatabaseBackend::deleteMultiple @covers \Drupal\Core\Cache\MemoryBackend::deleteMultiple @covers \Drupal\Core\Cache\PhpBackend::deleteMultiple

File

core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php, line 455

Class

GenericCacheBackendUnitTestBase
Tests any cache backend.

Namespace

Drupal\KernelTests\Core\Cache

Code

public function testDeleteMultiple() {
    $backend = $this->getCacheBackend();
    // Set numerous testing keys.
    $backend->set('test1', 1);
    $backend->set('test2', 3);
    $backend->set('test3', 5);
    $backend->set('test4', 7);
    $backend->set('test5', 11);
    $backend->set('test6', 13);
    $backend->set('test7', 17);
    $backend->delete('test1');
    // Nonexistent key should not cause an error.
    $backend->delete('test23');
    $backend->deleteMultiple([
        'test3',
        'test5',
        'test7',
        // Nonexistent key should not cause an error.
'test19',
        // Nonexistent key should not cause an error.
'test21',
    ]);
    // Test if expected keys have been deleted.
    $this->assertFalse($backend->get('test1'), "Cache id test1 deleted.");
    $this->assertFalse($backend->get('test3'), "Cache id test3 deleted.");
    $this->assertFalse($backend->get('test5'), "Cache id test5 deleted.");
    $this->assertFalse($backend->get('test7'), "Cache id test7 deleted.");
    // Test if expected keys exist.
    $this->assertNotFalse($backend->get('test2'), "Cache id test2 exists.");
    $this->assertNotFalse($backend->get('test4'), "Cache id test4 exists.");
    $this->assertNotFalse($backend->get('test6'), "Cache id test6 exists.");
    // Test if that expected keys do not exist.
    $this->assertFalse($backend->get('test19'), "Cache id test19 does not exist.");
    $this->assertFalse($backend->get('test21'), "Cache id test21 does not exist.");
    // Calling deleteMultiple() with an empty array should not cause an error.
    $this->assertNull($backend->deleteMultiple([]));
}

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