public function FeedsFileHTTPTestCase::testRefetchWhenCachedFileIsRemoved in Feeds 7.2
Tests if the source is refetched when the cached file is manually removed.
A call to feeds_http_request() should always get us data.
File
- tests/
feeds_fetcher_http.test, line 205 - Contains FeedsFileHTTPTestCase.
Class
- FeedsFileHTTPTestCase
- HTTP fetcher test class.
Code
public function testRefetchWhenCachedFileIsRemoved() {
// Include http request functions.
feeds_include_library('http_request.inc', 'http_request');
// First request.
$url = url('testing/feeds/nodes.csv', array(
'absolute' => TRUE,
));
$result1 = feeds_http_request($url);
// Assert that the first request was successful and was not retrieved from
// cache.
$this
->assertEqual(200, $result1->code, 'Request status code is 200.');
$this
->assertTrue(empty($result1->from_cache), 'Request was not retrieved from cache.');
// Reset feeds_http_request() static cache.
drupal_static_reset('feeds_http_request');
// Write some garbage to the cached file to ensure that the cache is
// retrieved from that file.
$file_url = 'private://feeds/cache/' . hash('sha256', $url);
$garbage = static::randomString(100);
file_put_contents($file_url, $garbage);
// Second request.
$result2 = feeds_http_request($url);
// Assert that the second request was successful and was retrieved from
// cache.
$this
->assertEqual(200, $result2->code, 'Request status code is 200.');
$this
->assertTrue(!empty($result2->from_cache), 'Request was retrieved from cache.');
$this
->assertEqual($garbage, $result2->data, 'The cache came from the file cache.');
// Now remove the cached file.
drupal_unlink($file_url);
$this
->assertFalse(file_exists($file_url), format_string('The file @file_url no longer exists.', array(
'@file_url' => $file_url,
)));
// Third request.
$result3 = feeds_http_request($url);
// Assert that the data is refetched, even though the source hasn't changed.
$this
->assertEqual(200, $result3->code, 'Request status code is 200.');
$this
->assertTrue(empty($result3->from_cache), 'Request was not retrieved from cache.');
$this
->assertEqual($result1->data, $result3->data, 'Data is available on the response.');
}