diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php index b871245..d18eaec 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php @@ -64,7 +64,7 @@ public function get($collection) { * Deletes expired items. */ public function garbageCollection() { - $this->connection->delete('key_value_expirable') + $this->connection->delete('key_value_expire') ->condition('expire', REQUEST_TIME, '<') ->execute(); } diff --git a/core/modules/system/src/Tests/KeyValueStore/GarbageCollectionTest.php b/core/modules/system/src/Tests/KeyValueStore/GarbageCollectionTest.php index e583e75..99421a1 100644 --- a/core/modules/system/src/Tests/KeyValueStore/GarbageCollectionTest.php +++ b/core/modules/system/src/Tests/KeyValueStore/GarbageCollectionTest.php @@ -10,12 +10,19 @@ use Drupal\Component\Serialization\PhpSerialize; use Drupal\Core\Database\Database; use Drupal\Core\KeyValueStore\DatabaseStorageExpirable; -use Drupal\simpletest\UnitTestBase; +use Drupal\simpletest\KernelTestBase; /** * Tests garbage collection for DatabaseStorageExpirable. */ -class GarbageCollectionTest extends UnitTestBase { +class GarbageCollectionTest extends KernelTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('system'); public static function getInfo() { return array( @@ -27,14 +34,8 @@ public static function getInfo() { protected function setUp() { parent::setUp(); - module_load_install('system'); - $schema = system_schema(); - db_create_table('key_value_expire', $schema['key_value_expire']); - } - - protected function tearDown() { - db_drop_table('key_value_expire'); - parent::tearDown(); + // The additional tables are necessary due to the call to system_cron(). + $this->installSchema('system', array('key_value_expire', 'flood', 'queue')); } /** @@ -63,10 +64,10 @@ public function testGarbageCollection() { ->execute(); } - // Perform a new set operation and then manually destruct the object to - // trigger garbage collection. + + // Perform a new set operation and then trigger garbage collection. $store->setWithExpire('autumn', 'winter', rand(500, 1000000)); - $store->destruct(); + system_cron(); // Query the database and confirm that the stale records were deleted. $result = db_query( @@ -74,7 +75,7 @@ public function testGarbageCollection() { array( ':collection' => $collection, ))->fetchAll(); - $this->assertIdentical(sizeof($result), 1, 'Only one item remains after garbage collection'); + $this->assertIdentical(count($result), 1, 'Only one item remains after garbage collection'); }