|
|
@ -134,7 +134,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|
|
|
$with_backslash = ['foo' => '\Drupal\foo\Bar'];
|
|
|
|
$with_backslash = ['foo' => '\Drupal\foo\Bar'];
|
|
|
|
$backend->set('test1', $with_backslash);
|
|
|
|
$backend->set('test1', $with_backslash);
|
|
|
|
$cached = $backend->get('test1');
|
|
|
|
$cached = $backend->get('test1');
|
|
|
|
$this->assert(is_object($cached), "Backend returned an object for cache id test1.");
|
|
|
|
$this->assertIsObject($cached);
|
|
|
|
$this->assertSame($with_backslash, $cached->data);
|
|
|
|
$this->assertSame($with_backslash, $cached->data);
|
|
|
|
$this->assertTrue($cached->valid, 'Item is marked as valid.');
|
|
|
|
$this->assertTrue($cached->valid, 'Item is marked as valid.');
|
|
|
|
// We need to round because microtime may be rounded up in the backend.
|
|
|
|
// We need to round because microtime may be rounded up in the backend.
|
|
|
@ -144,7 +144,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|
|
|
$this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2.");
|
|
|
|
$this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2.");
|
|
|
|
$backend->set('test2', ['value' => 3], REQUEST_TIME + 3);
|
|
|
|
$backend->set('test2', ['value' => 3], REQUEST_TIME + 3);
|
|
|
|
$cached = $backend->get('test2');
|
|
|
|
$cached = $backend->get('test2');
|
|
|
|
$this->assert(is_object($cached), "Backend returned an object for cache id test2.");
|
|
|
|
$this->assertIsObject($cached);
|
|
|
|
$this->assertSame(['value' => 3], $cached->data);
|
|
|
|
$this->assertSame(['value' => 3], $cached->data);
|
|
|
|
$this->assertTrue($cached->valid, 'Item is marked as valid.');
|
|
|
|
$this->assertTrue($cached->valid, 'Item is marked as valid.');
|
|
|
|
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.');
|
|
|
|
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.');
|
|
|
@ -153,7 +153,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|
|
|
$backend->set('test3', 'foobar', REQUEST_TIME - 3);
|
|
|
|
$backend->set('test3', 'foobar', REQUEST_TIME - 3);
|
|
|
|
$this->assertFalse($backend->get('test3'), 'Invalid item not returned.');
|
|
|
|
$this->assertFalse($backend->get('test3'), 'Invalid item not returned.');
|
|
|
|
$cached = $backend->get('test3', TRUE);
|
|
|
|
$cached = $backend->get('test3', TRUE);
|
|
|
|
$this->assert(is_object($cached), 'Backend returned an object for cache id test3.');
|
|
|
|
$this->assertIsObject($cached);
|
|
|
|
$this->assertFalse($cached->valid, 'Item is marked as valid.');
|
|
|
|
$this->assertFalse($cached->valid, 'Item is marked as valid.');
|
|
|
|
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.');
|
|
|
|
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.');
|
|
|
|
$this->assertEqual($cached->expire, REQUEST_TIME - 3, 'Expire time is correct.');
|
|
|
|
$this->assertEqual($cached->expire, REQUEST_TIME - 3, 'Expire time is correct.');
|
|
|
@ -162,7 +162,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|
|
|
$with_eof = ['foo' => "\nEOF\ndata"];
|
|
|
|
$with_eof = ['foo' => "\nEOF\ndata"];
|
|
|
|
$backend->set('test4', $with_eof);
|
|
|
|
$backend->set('test4', $with_eof);
|
|
|
|
$cached = $backend->get('test4');
|
|
|
|
$cached = $backend->get('test4');
|
|
|
|
$this->assert(is_object($cached), "Backend returned an object for cache id test4.");
|
|
|
|
$this->assertIsObject($cached);
|
|
|
|
$this->assertSame($with_eof, $cached->data);
|
|
|
|
$this->assertSame($with_eof, $cached->data);
|
|
|
|
$this->assertTrue($cached->valid, 'Item is marked as valid.');
|
|
|
|
$this->assertTrue($cached->valid, 'Item is marked as valid.');
|
|
|
|
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.');
|
|
|
|
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.');
|
|
|
@ -172,7 +172,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|
|
|
$with_eof_and_semicolon = ['foo' => "\nEOF;\ndata"];
|
|
|
|
$with_eof_and_semicolon = ['foo' => "\nEOF;\ndata"];
|
|
|
|
$backend->set('test5', $with_eof_and_semicolon);
|
|
|
|
$backend->set('test5', $with_eof_and_semicolon);
|
|
|
|
$cached = $backend->get('test5');
|
|
|
|
$cached = $backend->get('test5');
|
|
|
|
$this->assert(is_object($cached), "Backend returned an object for cache id test5.");
|
|
|
|
$this->assertIsObject($cached);
|
|
|
|
$this->assertSame($with_eof_and_semicolon, $cached->data);
|
|
|
|
$this->assertSame($with_eof_and_semicolon, $cached->data);
|
|
|
|
$this->assertTrue($cached->valid, 'Item is marked as valid.');
|
|
|
|
$this->assertTrue($cached->valid, 'Item is marked as valid.');
|
|
|
|
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.');
|
|
|
|
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.');
|
|
|
@ -181,7 +181,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|
|
|
$with_variable = ['foo' => '$bar'];
|
|
|
|
$with_variable = ['foo' => '$bar'];
|
|
|
|
$backend->set('test6', $with_variable);
|
|
|
|
$backend->set('test6', $with_variable);
|
|
|
|
$cached = $backend->get('test6');
|
|
|
|
$cached = $backend->get('test6');
|
|
|
|
$this->assert(is_object($cached), "Backend returned an object for cache id test6.");
|
|
|
|
$this->assertIsObject($cached);
|
|
|
|
$this->assertSame($with_variable, $cached->data);
|
|
|
|
$this->assertSame($with_variable, $cached->data);
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure that a cached object is not affected by changing the original.
|
|
|
|
// Make sure that a cached object is not affected by changing the original.
|
|
|
@ -194,7 +194,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|
|
|
// Add a property to the original. It should not appear in the cached data.
|
|
|
|
// Add a property to the original. It should not appear in the cached data.
|
|
|
|
$data->this_should_not_be_in_the_cache = TRUE;
|
|
|
|
$data->this_should_not_be_in_the_cache = TRUE;
|
|
|
|
$cached = $backend->get('test7');
|
|
|
|
$cached = $backend->get('test7');
|
|
|
|
$this->assert(is_object($cached), "Backend returned an object for cache id test7.");
|
|
|
|
$this->assertIsObject($cached);
|
|
|
|
$this->assertEqual($expected_data, $cached->data);
|
|
|
|
$this->assertEqual($expected_data, $cached->data);
|
|
|
|
$this->assertFalse(isset($cached->data->this_should_not_be_in_the_cache));
|
|
|
|
$this->assertFalse(isset($cached->data->this_should_not_be_in_the_cache));
|
|
|
|
// Add a property to the cache data. It should not appear when we fetch
|
|
|
|
// Add a property to the cache data. It should not appear when we fetch
|
|
|
@ -231,16 +231,16 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertFalse($backend->get('test1'), "Backend does not contain data for cache id test1.");
|
|
|
|
$this->assertFalse($backend->get('test1'), "Backend does not contain data for cache id test1.");
|
|
|
|
$backend->set('test1', 7);
|
|
|
|
$backend->set('test1', 7);
|
|
|
|
$this->assert(is_object($backend->get('test1')), "Backend returned an object for cache id test1.");
|
|
|
|
$this->assertIsObject($backend->get('test1'));
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2.");
|
|
|
|
$this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2.");
|
|
|
|
$backend->set('test2', 3);
|
|
|
|
$backend->set('test2', 3);
|
|
|
|
$this->assert(is_object($backend->get('test2')), "Backend returned an object for cache id %cid.");
|
|
|
|
$this->assertIsObject($backend->get('test2'));
|
|
|
|
|
|
|
|
|
|
|
|
$backend->delete('test1');
|
|
|
|
$backend->delete('test1');
|
|
|
|
$this->assertFalse($backend->get('test1'), "Backend does not contain data for cache id test1 after deletion.");
|
|
|
|
$this->assertFalse($backend->get('test1'), "Backend does not contain data for cache id test1 after deletion.");
|
|
|
|
|
|
|
|
|
|
|
|
$this->assert(is_object($backend->get('test2')), "Backend still has an object for cache id test2.");
|
|
|
|
$this->assertIsObject($backend->get('test2'));
|
|
|
|
|
|
|
|
|
|
|
|
$backend->delete('test2');
|
|
|
|
$backend->delete('test2');
|
|
|
|
$this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2 after deletion.");
|
|
|
|
$this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2 after deletion.");
|
|
|
@ -274,7 +274,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|
|
|
// Retrieve and test cache objects.
|
|
|
|
// Retrieve and test cache objects.
|
|
|
|
foreach ($variables as $cid => $value) {
|
|
|
|
foreach ($variables as $cid => $value) {
|
|
|
|
$object = $backend->get($cid);
|
|
|
|
$object = $backend->get($cid);
|
|
|
|
$this->assert(is_object($object), sprintf("Backend returned an object for cache id %s.", $cid));
|
|
|
|
$this->assertIsObject($object, sprintf("Backend returned an object for cache id %s.", $cid));
|
|
|
|
$this->assertSame($value, $object->data, sprintf("Data of cached id %s kept is identical in type and value", $cid));
|
|
|
|
$this->assertSame($value, $object->data, sprintf("Data of cached id %s kept is identical in type and value", $cid));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|