diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/simpletest/tests/cache.test | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/modules/simpletest/tests/cache.test b/modules/simpletest/tests/cache.test index d292fa661..47f2df318 100644 --- a/modules/simpletest/tests/cache.test +++ b/modules/simpletest/tests/cache.test @@ -339,6 +339,40 @@ class CacheClearCase extends CacheTestCase { $this->assertFalse($this->checkCacheExists($id, $this->default_value, $bin), t('All cache entries removed from @bin.', array('@bin' => $bin))); } } + + /** + * Test minimum cache lifetime. + */ + function testMinimumCacheLifetime() { + // Set a minimum/maximum cache lifetime. + $this->setupLifetime(300); + // Login as a newly-created user. + $account = $this->drupalCreateUser(array()); + $this->drupalLogin($account); + + // Set two cache objects in different bins. + $data = $this->randomName(100); + cache_set($data, $data, 'cache', CACHE_TEMPORARY); + $cached = cache_get($data); + $this->assertTrue(isset($cached->data) && $cached->data === $data, 'Cached item retrieved.'); + cache_set($data, $data, 'cache_page', CACHE_TEMPORARY); + + // Expire temporary items in the 'page' bin. + cache_clear_all(NULL, 'cache_page'); + + // Since the database cache uses REQUEST_TIME, set the $_SESSION variable + // manually to force it to the current time. + $_SESSION['cache_expiration']['cache_page'] = time(); + + // Items in the default cache bin should not be expired. + $cached = cache_get($data); + $this->assertTrue(isset($cached->data) && $cached->data == $data, 'Cached item retrieved'); + + // Despite the minimum cache lifetime, the item in the 'page' bin should + // be invalidated for the current user. + $cached = cache_get($data, 'cache_page'); + $this->assertFalse($cached, 'Cached item was invalidated'); + } } /** |