function GenericCacheBackendUnitTestBase::testDelete

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

Tests Drupal\Core\Cache\CacheBackendInterface::delete().

File

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

Class

GenericCacheBackendUnitTestBase
Tests any cache backend.

Namespace

Drupal\KernelTests\Core\Cache

Code

public function testDelete() : void {
    $backend = $this->getCacheBackend();
    $this->assertFalse($backend->get('test1'), "Backend does not contain data for cache id test1.");
    $backend->set('test1', 7);
    $this->assertIsObject($backend->get('test1'));
    $this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2.");
    $backend->set('test2', 3);
    $this->assertIsObject($backend->get('test2'));
    $backend->delete('test1');
    $this->assertFalse($backend->get('test1'), "Backend does not contain data for cache id test1 after deletion.");
    $this->assertIsObject($backend->get('test2'));
    $backend->delete('test2');
    $this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2 after deletion.");
    $long_cid = str_repeat('a', 300);
    $backend->set($long_cid, 'test');
    $backend->delete($long_cid);
    $this->assertFalse($backend->get($long_cid), "Backend does not contain data for long cache id after deletion.");
}

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