function DatabaseBackendTest::testSetGet
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Cache/DatabaseBackendTest.php \Drupal\KernelTests\Core\Cache\DatabaseBackendTest::testSetGet()
- 8.9.x core/tests/Drupal/KernelTests/Core/Cache/DatabaseBackendTest.php \Drupal\KernelTests\Core\Cache\DatabaseBackendTest::testSetGet()
- 10 core/tests/Drupal/KernelTests/Core/Cache/DatabaseBackendTest.php \Drupal\KernelTests\Core\Cache\DatabaseBackendTest::testSetGet()
Overrides GenericCacheBackendUnitTestBase::testSetGet
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Cache/ DatabaseBackendTest.php, line 49
Class
- DatabaseBackendTest
- Unit test of the database backend using the generic cache unit test base.
Namespace
Drupal\KernelTests\Core\CacheCode
public function testSetGet() : void {
parent::testSetGet();
$backend = $this->getCacheBackend();
// Set up a cache ID that is not ASCII and longer than 255 characters so we
// can test cache ID normalization.
$cid_long = str_repeat('愛€', 500);
$cached_value_long = $this->randomMachineName();
$backend->set($cid_long, $cached_value_long);
$this->assertSame($cached_value_long, $backend->get($cid_long)->data, "Backend contains the correct value for long, non-ASCII cache id.");
$cid_short = '愛1€';
$cached_value_short = $this->randomMachineName();
$backend->set($cid_short, $cached_value_short);
$this->assertSame($cached_value_short, $backend->get($cid_short)->data, "Backend contains the correct value for short, non-ASCII cache id.");
// Set multiple items to test exceeding the chunk size.
$backend->deleteAll();
$items = [];
for ($i = 0; $i <= DatabaseBackend::MAX_ITEMS_PER_CACHE_SET; $i++) {
$items["test{$i}"]['data'] = $i;
}
$backend->setMultiple($items);
$this->assertSame(DatabaseBackend::MAX_ITEMS_PER_CACHE_SET + 1, $this->getNumRows());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.