diff --git a/core/modules/system/lib/Drupal/system/Tests/Cache/GenericBackendUnitTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Cache/GenericBackendUnitTestBase.php index ae59f01..56d9ba7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Cache/GenericBackendUnitTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Cache/GenericBackendUnitTestBase.php @@ -9,7 +9,8 @@ namespace Drupal\system\Tests\Cache; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\simpletest\UnitTestBase; -use stdClass; + +use \stdClass; /** * Full generic unit test suite for any cache backend. In order to use it for a @@ -184,7 +185,6 @@ abstract class GenericBackendUnitTestBase extends UnitTestBase { 'test3' => '', 'test4' => 12.64, 'test5' => false, - 'test6' => array(1,2,3), ); // Create cache entries. @@ -193,11 +193,10 @@ abstract class GenericBackendUnitTestBase extends UnitTestBase { } // Retrieve and test cache objects. - foreach ($variables as $cid => $data) { + foreach ($variables as $cid => $value) { $object = $backend->get($cid); - $this->assert(is_object($object), format_string("Backend returned an object for cache id %cid.", array('%cid' => $cid))); - // Ensure that variable type has been persisted. - $this->assertIdentical($data, $object->data); + $this->assert(is_object($object), sprintf("Backend returned an object for cache id %s.", $cid)); + $this->assertIdentical($value, $object->data, sprintf("Data of cached id %s kept is identical in type and value", $cid)); } } @@ -228,78 +227,52 @@ abstract class GenericBackendUnitTestBase extends UnitTestBase { $cids = $reference; $ret = $backend->getMultiple($cids); - - // Cids that should be keys $ret array and not in $cid array. - $returned_cids = array( - 'test2', - 'test3', - 'test6', - 'test7', - ); - // Cids that should in $cid array and not keys $ret array. - $missing_cids = array( - 'test19', - 'test21', - ); - - foreach ($returned_cids as $cid) { - // Should be a key in $ret. - $this->assert(isset($ret[$cid]), format_string("Existing cache id %cid is set in return from getMultiple().", array('%cid' => $cid))); - // Should not be a value in $cids. - $this->assertFalse(in_array($cid, $cids), format_string("Existing cache id %cid is not a value in array passed to getMultiple().", array('%cid' => $cid))); - } - foreach ($missing_cids as $cid) { - // Should be a not be key in $ret. - $this->assertFalse(isset($ret[$cid]), format_string("Non existing cache id %cid is not set.", array('%cid' => $cid))); - // Should be a value in $cids. - $this->assertTrue(in_array($cid, $cids), format_string("Non existing cache id %cid is a value in array passed to getMultiple().", array('%cid' => $cid))); - } - - // Test return array values. - $this->assertIdentical($ret['test2']->data, 3, "Existing cache id test2 has the correct value."); - $this->assertIdentical($ret['test3']->data, 5, "Existing cache id test3 has the correct value."); - $this->assertIdentical($ret['test6']->data, 13, "Existing cache id test6 has the correct value."); - $this->assertIdentical($ret['test7']->data, 17, "Existing cache id test7 has the correct value."); - - // Proceed the test a second time after deleting and setting new keys which - // ensures no static cache stall. + // Test return + $this->assert(isset($ret['test3']), "Existing key 3 is set"); + $this->assert(isset($ret['test7']), "Existing key 7 is set"); + $this->assertFalse(isset($ret['test21']), "Non existing key 21 is not set"); + $this->assert(isset($ret['test6']), "Existing key 6 is set"); + $this->assertFalse(isset($ret['test19']), "Non existing key 19 is not set"); + $this->assert(isset($ret['test2']), "Existing key 2 is set"); + // Test values + $this->assertIdentical($ret['test3']->data, 5, "Existing key 3 has the correct value"); + $this->assertIdentical($ret['test7']->data, 17, "Existing key 7 has the correct value"); + $this->assertIdentical($ret['test6']->data, 13, "Existing key 6 has the correct value"); + $this->assertIdentical($ret['test2']->data, 3, "Existing key 2 has the correct value"); + // Test $cids array + $this->assertFalse(in_array('test3', $cids), "Existing key 3 is not referenced"); + $this->assertFalse(in_array('test7', $cids), "Existing key 7 is not referenced"); + $this->assert(in_array('test21', $cids), "Non existing key 21 is referenced"); + $this->assertFalse(in_array('test6', $cids), "Existing key 6 is not referenced"); + $this->assert(in_array('test19', $cids), "Non existing key 19 is referenced"); + $this->assertFalse(in_array('test2', $cids), "Existing key 2 is not referenced"); + + // Proceed the test a second time after deleting and setting new keys + // (ensures no static cache stall). $backend->delete('test3'); $backend->delete('test6'); $backend->set('test19', 57); $cids = $reference; $ret = $backend->getMultiple($cids); - - // Cids that should be keys $ret array and not in $cid array. - $returned_cids = array( - 'test2', - 'test7', - 'test19' - ); - // Cids that should in $cid array and not keys $ret array. - $missing_cids = array( - 'test3', - 'test6', - 'test21', - ); - - foreach ($returned_cids as $cid) { - // Should be a key in $ret. - $this->assert(isset($ret[$cid]), format_string("Existing cache id %cid is set in return from getMultiple().", array('%cid' => $cid))); - // Should not be a value in $cids. - $this->assertFalse(in_array($cid, $cids), format_string("Existing cache id %cid is not a value in array passed to getMultiple().", array('%cid' => $cid))); - } - foreach ($missing_cids as $cid) { - // Should be a not be key in $ret. - $this->assertFalse(isset($ret[$cid]), format_string("Non existing cache id %cid is not set.", array('%cid' => $cid))); - // Should be a value in $cids. - $this->assertTrue(in_array($cid, $cids), format_string("Non existing cache id %cid is a value in array passed to getMultiple().", array('%cid' => $cid))); - } - - // Test return array values. - $this->assertIdentical($ret['test2']->data, 3, "Existing cache id test2 has the correct value."); - $this->assertIdentical($ret['test7']->data, 17, "Existing cache id test7 has the correct value."); - $this->assertIdentical($ret['test19']->data, 57, "Existing cache id test19 has the correct value."); + // Test return + $this->assertFalse(isset($ret['test3']), "Removed key 3 is not set"); + $this->assert(isset($ret['test7']), "Existing key 7 is set"); + $this->assertFalse(isset($ret['test21']), "Non existing key 21 is not set"); + $this->assertFalse(isset($ret['test6']), "Removed key 6 is not set"); + $this->assert(isset($ret['test19']), "Added key 19 is set"); + $this->assert(isset($ret['test2']), "Existing key 2 is set"); + // Test values + $this->assertIdentical($ret['test7']->data, 17, "Existing key 7 has the correct value"); + $this->assertIdentical($ret['test19']->data, 57, "Added key 19 has the correct value"); + $this->assertIdentical($ret['test2']->data, 3, "Existing key 2 has the correct value"); + // Test $cids array + $this->assert(in_array('test3', $cids), "Removed key 3 is referenced"); + $this->assertFalse(in_array('test7', $cids), "Existing key 7 is not referenced"); + $this->assert(in_array('test21', $cids), "Non existing key 21 is referenced"); + $this->assert(in_array('test6', $cids), "Removed key 6 is referenced"); + $this->assertFalse(in_array('test19', $cids), "Added key 19 is not referenced"); + $this->assertFalse(in_array('test2', $cids), "Existing key 2 is not referenced"); } /** @@ -337,8 +310,8 @@ abstract class GenericBackendUnitTestBase extends UnitTestBase { 'test3', 'test5', 'test7', - 'test19', // Non existing key should be silent - 'test21', // Non existing key should be silent + 'test19', // Non existing key should be silent. + 'test21', // Non existing key should be silent. )); // Test if expected keys have been deleted.