public function FeedsFileHTTPTestCase::testChangedSource in Feeds 7.2
Tests if the source is refetched on a second import when the source changed.
File
- tests/
feeds_fetcher_http.test, line 459 - Contains FeedsFileHTTPTestCase.
Class
- FeedsFileHTTPTestCase
- HTTP fetcher test class.
Code
public function testChangedSource() {
$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);
// Set flag that the source has changed.
variable_set('feeds_tests_nodes_changed', TRUE);
// Re-import file. Ensure that the content was refetched.
$this
->drupalPost('import/node', $edit, t('Import'));
$this
->assertText('Updated 2 nodes');
// Assert that node 1 and 4 changed.
$node = node_load(1);
$this
->assertEqual('Ut wisi enim ad minim veniam', $node->title);
$this
->assertEqual('CHANGED IN SOURCE', $node->body[LANGUAGE_NONE][0]['value']);
$node = node_load(4);
$this
->assertEqual('Typi non habent', $node->title);
$this
->assertEqual('CHANGED IN SOURCE', $node->body[LANGUAGE_NONE][0]['value']);
// Assert that node 3 had NOT changed.
$node = node_load(3);
$this
->assertEqual('Nam liber tempor', $node->title);
$this
->assertNotEqual('CHANGED IN CACHED FILE', $node->body[LANGUAGE_NONE][0]['value']);
}