public function FeedsExamplesNodeTestCase::test in Feeds 6
Same name and namespace in other branches
- 8.2 feeds_import/feeds_import.test \FeedsExamplesNodeTestCase::test()
- 7.2 feeds_import/feeds_import.test \FeedsExamplesNodeTestCase::test()
- 7 feeds_import/feeds_import.test \FeedsExamplesNodeTestCase::test()
Run tests.
File
- feeds_import/
feeds_import.test, line 32 - Tests for feeds_import feature.
Class
- FeedsExamplesNodeTestCase
- Test Node import configuration.
Code
public function test() {
// Import file.
$this
->importFile('node', $this
->absolutePath() . '/tests/feeds/nodes.csv');
// Assert returning page.
$this
->assertText('Created 8 Story nodes.');
$this
->assertText('Import CSV files with one or more of these columns: title, body, published, guid.');
$this
->assertText('Column guid is mandatory and considered unique: only one item per guid value will be created.');
$this
->assertRaw('feeds/nodes.csv');
// Assert created nodes.
$this
->drupalGet('node');
$this
->assertText('Typi non habent');
$this
->assertText('Eodem modo typi');
$this
->assertText('Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.');
$this
->assertText('Lorem ipsum');
$this
->assertText('Ut wisi enim ad minim veniam');
$this
->assertText('1976');
// Nam liber tempor has the same GUID as Lorem ipsum.
$this
->assertNoText('Nam liber tempor');
// Click through to one node.
$this
->clickLink('Lorem ipsum');
$this
->assertText('Lorem ipsum');
$this
->assertText('Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.');
$this
->assertText('Anonymous');
// Assert DB status as is and again after an additional import.
for ($i = 0; $i < 2; $i++) {
$count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}"));
$this
->assertEqual($count, 8, 'Found correct number of items.');
$count = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = 'story' AND status = 1 AND uid = 0"));
$this
->assertEqual($count, 8, 'Found correct number of items.');
// Do not filter on type intentionally. There shouldn't be more than 8 nodes total.
$count = db_result(db_query("SELECT COUNT(*) FROM {node_revisions}"));
$this
->assertEqual($count, 8, 'Found correct number of items.');
// Import again. Feeds only updates items that haven't changed. However,
// there are 2 different items with the same GUID in nodes.csv.
// Therefore, feeds will show updates to 2 nodes.
$this
->drupalPost('import/node/import', array(), 'Import');
$this
->assertText('Updated 2 Story nodes.');
}
// Remove all nodes.
$this
->drupalPost('import/node/delete-items', array(), 'Delete');
$this
->assertText('Deleted 8 nodes.');
// Import once again.
$this
->drupalPost('import/node/import', array(), 'Import');
$this
->assertText('Created 8 Story nodes.');
// Import a similar file with changes in 4 records. Feeds should report 6
// Updated story nodes (4 changed records, 2 records sharing a GUID
// subsequently being updated).
$this
->importFile('node', $this
->absolutePath() . '/tests/feeds/nodes_changes.csv');
$this
->assertText('Updated 6 Story nodes.');
// Import a larger file with more records.
$this
->importFile('node', $this
->absolutePath() . '/tests/feeds/many_nodes.csv');
$this
->assertText('Created 71 Story nodes.');
// Remove all nodes.
$this
->drupalPost('import/node/delete-items', array(), 'Delete');
$this
->assertText('Deleted 79 nodes.');
// Import once again.
$this
->drupalPost('import/node/import', array(), 'Import');
$this
->assertText('Created 79 Story nodes.');
// Import a tab separated file.
$this
->drupalPost('import/node/delete-items', array(), 'Delete');
$edit = array(
'files[feeds]' => $this
->absolutePath() . '/tests/feeds/nodes.tsv',
'feeds[FeedsCSVParser][delimiter]' => "TAB",
);
$this
->drupalPost('import/node', $edit, 'Import');
$this
->assertText('Created 8 Story nodes.');
}