You are here

public function FeedsFileHTTPTestCase::testSourceCaching in Feeds 7.2

Tests if a source is not refetched on a second import when the source did not change.

File

tests/feeds_fetcher_http.test, line 420
Contains FeedsFileHTTPTestCase.

Class

FeedsFileHTTPTestCase
HTTP fetcher test class.

Code

public function testSourceCaching() {
  $this
    ->setUpImporter();
  $source_url = url('testing/feeds/nodes.csv', array(
    'absolute' => TRUE,
  ));
  $edit = array(
    'feeds[FeedsHTTPFetcher][source]' => $source_url,
  );
  $this
    ->drupalPost('import/node', $edit, t('Import'));
  $this
    ->assertText('Created 9 nodes');

  // Ensure that the fetched content was cached in a file.
  $file_url = 'private://feeds/cache/' . hash('sha256', $source_url);
  $this
    ->assertTrue(file_exists($file_url), format_string('The file @file_url exists.', array(
    '@file_url' => $file_url,
  )));

  // Overwrite cached file, change one item.
  $csv = file_get_contents($file_url);
  $lines = explode("\n", $csv);
  $lines[3] = '"Nam liber tempor","CHANGED IN CACHED FILE",1151766000,1';
  $csv = implode("\n", $lines);
  $this
    ->verbose('<pre>' . $csv . '</pre>');
  file_put_contents($file_url, $csv);

  // Re-import file. Ensure that the data from the cache was used.
  $this
    ->drupalPost('import/node', $edit, t('Import'));
  $this
    ->assertText('Updated 1 node');

  // Assert that node 3 had changed.
  $node = node_load(3);
  $this
    ->assertEqual('Nam liber tempor', $node->title);
  $this
    ->assertEqual('CHANGED IN CACHED FILE', $node->body[LANGUAGE_NONE][0]['value']);
}