1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Tests for feeds_import feature.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Test Node import configuration.
|
10 |
|
|
*/
|
11 |
|
|
class FeedsExamplesNodeTestCase extends FeedsWebTestCase {
|
12 |
|
|
|
13 |
|
|
/**
|
14 |
|
|
* Set up test.
|
15 |
|
|
*/
|
16 |
|
|
public function setUp() {
|
17 |
|
|
parent::setUp(array('feeds_import'));
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
public static function getInfo() {
|
21 |
|
|
return array(
|
22 |
|
|
'name' => 'Feature: Node import',
|
23 |
|
|
'description' => 'Test "Node import" default configuration.',
|
24 |
|
|
'group' => 'Feeds',
|
25 |
|
|
);
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
/**
|
29 |
|
|
* Run tests.
|
30 |
|
|
*/
|
31 |
|
|
public function test() {
|
32 |
|
|
// Import file.
|
33 |
|
|
$this->importFile('node', $this->absolutePath() . '/tests/feeds/nodes.csv');
|
34 |
|
|
|
35 |
|
|
// Assert returning page.
|
36 |
|
|
$this->assertText('Created 8 nodes');
|
37 |
|
|
$this->assertText('Import CSV files with one or more of these columns: title, body, published, guid.');
|
38 |
|
|
$this->assertText('Column guid is mandatory and considered unique: only one item per guid value will be created.');
|
39 |
|
|
$this->assertRaw('feeds/nodes.csv');
|
40 |
|
|
|
41 |
|
|
// Assert created nodes.
|
42 |
|
|
$this->drupalGet('node');
|
43 |
|
|
$this->assertText('Typi non habent');
|
44 |
|
|
$this->assertText('Eodem modo typi');
|
45 |
|
|
$this->assertText('Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.');
|
46 |
|
|
$this->assertText('Lorem ipsum');
|
47 |
|
|
$this->assertText('Ut wisi enim ad minim veniam');
|
48 |
|
|
$this->assertText('1976');
|
49 |
|
|
// Nam liber tempor has the same GUID as Lorem ipsum.
|
50 |
|
|
$this->assertNoText('Nam liber tempor');
|
51 |
|
|
|
52 |
|
|
// Click through to one node.
|
53 |
|
|
$this->clickLink('Lorem ipsum');
|
54 |
|
|
$this->assertText('Lorem ipsum');
|
55 |
|
|
$this->assertText('Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.');
|
56 |
|
|
$this->assertText('Anonymous');
|
57 |
|
|
|
58 |
|
|
// Assert DB status as is and again after an additional import.
|
59 |
|
|
for ($i = 0; $i < 2; $i++) {
|
60 |
|
|
$count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node'")->fetchField();
|
61 |
|
|
$this->assertEqual($count, 8, 'Found correct number of items.');
|
62 |
|
|
$count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article' AND status = 1 AND uid = 0")->fetchField();
|
63 |
|
|
$this->assertEqual($count, 8, 'Found correct number of items.');
|
64 |
|
|
// Do not filter on type intentionally. There shouldn't be more than 8 nodes total.
|
65 |
|
|
$count = db_query("SELECT COUNT(*) FROM {node_revision}")->fetchField();
|
66 |
|
|
$this->assertEqual($count, 8, 'Found correct number of items.');
|
67 |
|
|
|
68 |
|
|
// Import again. Feeds only updates items that haven't changed. However,
|
69 |
|
|
// there are 2 different items with the same GUID in nodes.csv.
|
70 |
|
|
// Therefore, feeds will show updates to 2 nodes.
|
71 |
|
|
$this->drupalPost('import/node/import', array(), 'Import');
|
72 |
|
|
$this->assertText('Updated 2 nodes');
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
// Remove all nodes.
|
76 |
|
|
$this->drupalPost('import/node/delete-items', array(), 'Delete');
|
77 |
|
|
$this->assertText('Deleted 8 nodes');
|
78 |
|
|
|
79 |
|
|
// Import once again.
|
80 |
|
|
$this->drupalPost('import/node/import', array(), 'Import');
|
81 |
|
|
$this->assertText('Created 8 nodes');
|
82 |
|
|
|
83 |
|
|
// Import a similar file with changes in 4 records. Feeds should report 6
|
84 |
|
|
// Updated Article nodes (4 changed records, 2 records sharing a GUID
|
85 |
|
|
// subsequently being updated).
|
86 |
|
|
$this->importFile('node', $this->absolutePath() . '/tests/feeds/nodes_changes.csv');
|
87 |
|
|
$this->assertText('Updated 6 nodes');
|
88 |
|
|
|
89 |
|
|
// Import a larger file with more records.
|
90 |
|
|
$this->importFile('node', $this->absolutePath() . '/tests/feeds/many_nodes.csv');
|
91 |
|
|
$this->assertText('Created 71 nodes');
|
92 |
|
|
|
93 |
|
|
// Remove all nodes.
|
94 |
|
|
$this->drupalPost('import/node/delete-items', array(), 'Delete');
|
95 |
|
|
$this->assertText('Deleted 79 nodes');
|
96 |
|
|
|
97 |
|
|
// Import once again.
|
98 |
|
|
$this->drupalPost('import/node/import', array(), 'Import');
|
99 |
|
|
$this->assertText('Created 79 nodes');
|
100 |
|
|
$this->assertText('Updated 7 nodes');
|
101 |
|
|
|
102 |
|
|
// Import a tab separated file.
|
103 |
|
|
$this->drupalPost('import/node/delete-items', array(), 'Delete');
|
104 |
|
|
$edit = array(
|
105 |
|
|
'files[feeds]' => $this->absolutePath() . '/tests/feeds/nodes.tsv',
|
106 |
|
|
'feeds[FeedsCSVParser][delimiter]' => "TAB",
|
107 |
|
|
);
|
108 |
|
|
$this->drupalPost('import/node', $edit, 'Import');
|
109 |
|
|
$this->assertText('Created 8 nodes');
|
110 |
|
|
}
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
/**
|
114 |
|
|
* Test User import configuration.
|
115 |
|
|
*/
|
116 |
|
|
class FeedsExamplesUserTestCase extends FeedsWebTestCase {
|
117 |
|
|
public static function getInfo() {
|
118 |
|
|
return array(
|
119 |
|
|
'name' => 'Feature: User import',
|
120 |
|
|
'description' => 'Test "User import" default configuration.',
|
121 |
|
|
'group' => 'Feeds',
|
122 |
|
|
);
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
public function setUp() {
|
126 |
|
|
parent::setUp(array('feeds_import'));
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
/**
|
130 |
|
|
* Run tests.
|
131 |
|
|
*/
|
132 |
|
|
public function test() {
|
133 |
|
|
// Import CSV file.
|
134 |
|
|
$this->importFile('user', $this->absolutePath() . '/tests/feeds/users.csv');
|
135 |
|
|
|
136 |
|
|
// Assert result.
|
137 |
|
|
$this->assertText('Created 3 users');
|
138 |
|
|
// 1 user has an invalid email address.
|
139 |
|
|
$this->assertText('Failed importing 2 users');
|
140 |
|
|
$this->drupalGet('admin/people');
|
141 |
|
|
$this->assertText('Morticia');
|
142 |
|
|
$this->assertText('Fester');
|
143 |
|
|
$this->assertText('Gomez');
|
144 |
|
|
}
|
145 |
|
|
} |