public function FeedsHTTPCacheTest::testClearExpiredUsingCacheLifeTime in Feeds 7.2
@covers FeedsHTTPCache::clear().
Tests if expired cached files can get cleaned up using the cache_lifetime variable.
File
- tests/
FeedsHTTPCacheTest.test, line 385
Class
- FeedsHTTPCacheTest
- @coversDefaultClass FeedsHTTPCache @group feeds
Code
public function testClearExpiredUsingCacheLifeTime() {
variable_set('cache_lifetime', 120);
// Create a cache entry that should not expire.
$cid_permanent = $this
->createCacheRecordUsingApi();
// Create a cache entry with an expire time in the past.
$cid_expire_past = static::randomName();
$this->cache
->set($cid_expire_past, $this
->createHttpResponse(), REQUEST_TIME - 60);
// Create a cache entry that expires exactly now.
$cid_expire_now = static::randomName();
$this->cache
->set($cid_expire_now, $this
->createHttpResponse(), REQUEST_TIME);
// Create a cache entry that expires in the future.
$cid_expire_future = static::randomName();
$this->cache
->set($cid_expire_future, $this
->createHttpResponse(), REQUEST_TIME + 60);
// Call clear. Nothing should be cleared because the last cache flush was
// too recently.
variable_set('cache_flush_cache_feeds_http', REQUEST_TIME - 90);
$this->cache
->clear();
// Ensure all cached files still exist as cache lifetime has not exceeded.
$this
->assertCacheItemExists($cid_permanent);
$this
->assertCacheItemExists($cid_expire_past);
$this
->assertCacheItemExists($cid_expire_now);
$this
->assertCacheItemExists($cid_expire_future);
$this
->assertCacheFileExists($cid_permanent);
$this
->assertCacheFileExists($cid_expire_past);
$this
->assertCacheFileExists($cid_expire_now);
$this
->assertCacheFileExists($cid_expire_future);
// Now do as if cache lifetime has passed.
variable_set('cache_flush_cache_feeds_http', REQUEST_TIME - 121);
$this->cache
->clear();
// Assert existence of cache entries.
$this
->assertCacheItemExists($cid_permanent);
$this
->assertNoCacheItemExists($cid_expire_past);
$this
->assertCacheItemExists($cid_expire_now);
$this
->assertCacheItemExists($cid_expire_future);
// Assert existence of cache files.
$this
->assertCacheFileExists($cid_permanent);
$this
->assertNoCacheFileExists($cid_expire_past);
$this
->assertCacheFileExists($cid_expire_now);
$this
->assertCacheFileExists($cid_expire_future);
}