1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Tests for FeedsXPathParserXML.inc.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Test single feeds.
|
10 |
|
|
*/
|
11 |
|
|
class FeedsXPathParserXMLTestCase extends FeedsXPathParserWebTestCase {
|
12 |
|
|
|
13 |
|
|
/**
|
14 |
|
|
* Describe this test.
|
15 |
|
|
*/
|
16 |
|
|
public static function getInfo() {
|
17 |
|
|
return array(
|
18 |
|
|
'name' => 'XML Parser',
|
19 |
|
|
'description' => 'Regression tests for Feeds XPath XML parser.',
|
20 |
|
|
'group' => 'Feeds XPath Parser',
|
21 |
|
|
);
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
/**
|
25 |
|
|
* Run tests.
|
26 |
|
|
*/
|
27 |
|
|
public function test() {
|
28 |
|
|
$this->createImporterConfiguration('XPathXML', 'xpath_xml');
|
29 |
|
|
|
30 |
|
|
$this->setPlugin('xpath_xml', 'FeedsXPathParserXML');
|
31 |
|
|
$importer_url = $this->feeds_base . '/xpath_xml/settings/FeedsXPathParserXML';
|
32 |
|
|
// Check help message.
|
33 |
|
|
$this->drupalGet($importer_url);
|
34 |
|
|
$this->assertText('No XPath mappings are defined.');
|
35 |
|
|
|
36 |
|
|
$this->addMappings('xpath_xml', array(
|
37 |
|
|
0 => array(
|
38 |
|
|
'source' => 'xpathparser:0',
|
39 |
|
|
'target' => 'title',
|
40 |
|
|
'unique' => FALSE,
|
41 |
|
|
),
|
42 |
|
|
1 => array(
|
43 |
|
|
'source' => 'xpathparser:1',
|
44 |
|
|
'target' => 'guid',
|
45 |
|
|
'unique' => TRUE,
|
46 |
|
|
),
|
47 |
|
|
2 => array(
|
48 |
|
|
'source' => 'xpathparser:2',
|
49 |
|
|
'target' => 'body',
|
50 |
|
|
),
|
51 |
|
|
));
|
52 |
|
|
// Set importer default settings.
|
53 |
|
|
$edit = array(
|
54 |
|
|
'xpath[context]' => '//entry',
|
55 |
|
|
'xpath[sources][xpathparser:0]' => 'title',
|
56 |
|
|
'xpath[sources][xpathparser:1]' => 'id',
|
57 |
|
|
'xpath[sources][xpathparser:2]' => 'id',
|
58 |
|
|
);
|
59 |
|
|
$this->postAndCheck($importer_url, $edit, 'Save', 'Your changes have been saved.');
|
60 |
|
|
|
61 |
|
|
// Test import.
|
62 |
|
|
$path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds_xpathparser') . '/tests/feeds_xpathparser/';
|
63 |
|
|
// We use an atom feed so that we can test that default namespaces are being
|
64 |
|
|
// applied appropriately.
|
65 |
|
|
$nid = $this->createFeedNode('xpath_xml', $path . 'sample_atom_feed.xml', 'Testing XPath XML Parser');
|
66 |
|
|
$feed_node_edit_url = 'node/' . $nid . '/edit';
|
67 |
|
|
$this->assertText('Created 3 nodes');
|
68 |
|
|
|
69 |
|
|
// Import again, this verifies url field was mapped correctly.
|
70 |
|
|
$this->drupalPost('node/' . $nid . '/import', array(), 'Import');
|
71 |
|
|
$this->assertText('There are no new nodes');
|
72 |
|
|
|
73 |
|
|
// Assert accuracy of aggregated content. I find humor in using our own
|
74 |
|
|
// issue queue to run tests against.
|
75 |
|
|
$this->drupalGet('node');
|
76 |
|
|
$this->assertText('Atom-Powered Robots Run Amok');
|
77 |
|
|
$this->assertText('My dog Jack is the best.');
|
78 |
|
|
$this->assertText('Physics is cool.');
|
79 |
|
|
|
80 |
|
|
// Test debugging.
|
81 |
|
|
$edit = array(
|
82 |
|
|
'feeds[FeedsXPathParserXML][xpath][exp][debug][xpathparser:0]' => TRUE,
|
83 |
|
|
);
|
84 |
|
|
$this->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Basic page Testing XPath XML Parser has been updated.');
|
85 |
|
|
$this->drupalPost('node/' . $nid . '/import', array(), 'Import');
|
86 |
|
|
$this->assertText('<title>Atom-Powered Robots Run Amok</title>');
|
87 |
|
|
$this->assertText('<title>My dog Jack is the best.</title>');
|
88 |
|
|
$this->assertText('<title>Physics is cool.</title>');
|
89 |
|
|
$this->assertText('There are no new nodes.');
|
90 |
|
|
|
91 |
|
|
// Turn debugging off.
|
92 |
|
|
$edit = array(
|
93 |
|
|
'feeds[FeedsXPathParserXML][xpath][exp][debug][xpathparser:0]' => FALSE,
|
94 |
|
|
);
|
95 |
|
|
$this->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Basic page Testing XPath XML Parser has been updated.');
|
96 |
|
|
|
97 |
|
|
// Check if update existing nodes works.
|
98 |
|
|
$this->setSettings('xpath_xml', 'FeedsNodeProcessor', array('update_existing' => 2));
|
99 |
|
|
$edit = array(
|
100 |
|
|
'feeds[FeedsHTTPFetcher][source]' => $path . 'sample_atom_feed_updated.xml',
|
101 |
|
|
);
|
102 |
|
|
$this->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Basic page Testing XPath XML Parser has been updated.');
|
103 |
|
|
$this->drupalPost('node/' . $nid . '/import', array(), 'Import');
|
104 |
|
|
$this->assertText('Updated 1 node.');
|
105 |
|
|
$this->drupalGet('node');
|
106 |
|
|
$this->assertText('Atom-Powered Robots Run Amok');
|
107 |
|
|
$this->assertText('My dog Jack is the best.');
|
108 |
|
|
$this->assertText('Physics is really cool.'); // The one that changed.
|
109 |
|
|
$this->assertNoText('Physics is cool.'); // Make sure the old node is changed.
|
110 |
|
|
// Be extra sure we updated.
|
111 |
|
|
$this->drupalGet('node/4');
|
112 |
|
|
$this->assertText('Physics is really cool.');
|
113 |
|
|
|
114 |
|
|
// Check if replace existing nodes works.
|
115 |
|
|
$this->setSettings('xpath_xml', 'FeedsNodeProcessor', array('update_existing' => 1));
|
116 |
|
|
$edit = array(
|
117 |
|
|
'feeds[FeedsHTTPFetcher][source]' => $path . 'sample_atom_feed.xml',
|
118 |
|
|
);
|
119 |
|
|
$this->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Basic page Testing XPath XML Parser has been updated.');
|
120 |
|
|
$this->drupalPost('node/' . $nid . '/import', array(), 'Import');
|
121 |
|
|
$this->assertText('Updated 1 node.');
|
122 |
|
|
$this->drupalGet('node');
|
123 |
|
|
$this->assertText('Atom-Powered Robots Run Amok');
|
124 |
|
|
$this->assertText('My dog Jack is the best.');
|
125 |
|
|
$this->assertText('Physics is cool.'); // The one that changed.
|
126 |
|
|
$this->assertNoText('Physics is really cool.'); // Make sure the old node is changed.
|
127 |
|
|
// Be extra sure we updated.
|
128 |
|
|
$this->drupalGet('node/4');
|
129 |
|
|
$this->assertText('Physics is cool.');
|
130 |
|
|
|
131 |
|
|
// Test that overriding default settings works.
|
132 |
|
|
$edit = array(
|
133 |
|
|
'feeds[FeedsXPathParserXML][xpath][context]' => '/foo',
|
134 |
|
|
'feeds[FeedsXPathParserXML][xpath][sources][xpathparser:0]' => 'bar',
|
135 |
|
|
'feeds[FeedsXPathParserXML][xpath][sources][xpathparser:1]' => 'baz',
|
136 |
|
|
'feeds[FeedsXPathParserXML][xpath][sources][xpathparser:2]' => 'wee',
|
137 |
|
|
);
|
138 |
|
|
$this->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Basic page Testing XPath XML Parser has been updated.');
|
139 |
|
|
|
140 |
|
|
// Assert the we don't create an empty node when XPath values don't return anything.
|
141 |
|
|
// That happened at one point.
|
142 |
|
|
$this->drupalPost('node/' . $nid . '/import', array(), 'Import');
|
143 |
|
|
$this->assertText('There are no new nodes.');
|
144 |
|
|
|
145 |
|
|
// Test that validation works.
|
146 |
|
|
$edit = array(
|
147 |
|
|
'feeds[FeedsXPathParserXML][xpath][context]' => 'sdf asf',
|
148 |
|
|
'feeds[FeedsXPathParserXML][xpath][sources][xpathparser:0]' => 'asdf[sadfas asdf]',
|
149 |
|
|
);
|
150 |
|
|
$this->drupalPost($feed_node_edit_url, $edit, 'Save');
|
151 |
|
|
// Check for valid error messages.
|
152 |
|
|
$this->assertText('There was an error with the XPath selector: Invalid expression');
|
153 |
|
|
$this->assertText('There was an error with the XPath selector: Invalid predicate');
|
154 |
|
|
// Make sure the fields are errored out correctly. I.e. we have red outlines.
|
155 |
|
|
$this->assertFieldByXPath('//input[@id="edit-feeds-feedsxpathparserxml-xpath-context"][1]/@class', 'form-text required error');
|
156 |
|
|
$this->assertFieldByXPath('//input[@id="edit-feeds-feedsxpathparserxml-xpath-sources-xpathparser0"][1]/@class', 'form-text error');
|
157 |
|
|
|
158 |
|
|
// Put the values back so we can test inheritance if the form was changed
|
159 |
|
|
// and then changed back.
|
160 |
|
|
$edit = array(
|
161 |
|
|
'feeds[FeedsXPathParserXML][xpath][context]' => '//entry',
|
162 |
|
|
'feeds[FeedsXPathParserXML][xpath][sources][xpathparser:0]' => 'title',
|
163 |
|
|
'feeds[FeedsXPathParserXML][xpath][sources][xpathparser:1]' => 'id',
|
164 |
|
|
'feeds[FeedsXPathParserXML][xpath][sources][xpathparser:2]' => 'id',
|
165 |
|
|
);
|
166 |
|
|
$this->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Basic page Testing XPath XML Parser has been updated.');
|
167 |
|
|
|
168 |
|
|
// Change importer defaults.
|
169 |
|
|
$edit = array(
|
170 |
|
|
'xpath[context]' => '//tr',
|
171 |
|
|
'xpath[sources][xpathparser:0]' => 'booya',
|
172 |
|
|
'xpath[sources][xpathparser:1]' => 'boyz',
|
173 |
|
|
'xpath[sources][xpathparser:2]' => 'woot',
|
174 |
|
|
);
|
175 |
|
|
$this->postAndCheck($importer_url, $edit, 'Save', 'Your changes have been saved.');
|
176 |
|
|
|
177 |
|
|
// Make sure the changes propigated.
|
178 |
|
|
$this->drupalGet($feed_node_edit_url);
|
179 |
|
|
$this->assertFieldByName('feeds[FeedsXPathParserXML][xpath][context]', '//tr');
|
180 |
|
|
$this->assertFieldByName('feeds[FeedsXPathParserXML][xpath][sources][xpathparser:0]', 'booya');
|
181 |
|
|
$this->assertFieldByName('feeds[FeedsXPathParserXML][xpath][sources][xpathparser:1]', 'boyz');
|
182 |
|
|
$this->assertFieldByName('feeds[FeedsXPathParserXML][xpath][sources][xpathparser:2]', 'woot');
|
183 |
|
|
// Check that our message comes out correct.
|
184 |
f066bdb5
|
Assos Assos
|
$this->assertRaw('Field <strong>GUID</strong> is mandatory and considered unique: only one item per GUID value will be created.');
|
185 |
85ad3d82
|
Assos Assos
|
|
186 |
|
|
// Check that allow_override works as expected.
|
187 |
|
|
$this->setSettings('xpath_xml', 'FeedsXPathParserXML', array('xpath[allow_override]' => FALSE));
|
188 |
|
|
$this->drupalGet($feed_node_edit_url);
|
189 |
|
|
$this->assertNoText('XPath Parser Settings');
|
190 |
|
|
$this->assertNoField('xpath[context]');
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
/**
|
194 |
|
|
* Test variable substitution.
|
195 |
|
|
*/
|
196 |
|
|
public function testVariables() {
|
197 |
|
|
$this->createImporterConfiguration();
|
198 |
|
|
|
199 |
|
|
$this->setPlugin('syndication', 'FeedsXPathParserXML');
|
200 |
|
|
$importer_url = $this->feeds_base . '/syndication/settings/FeedsXPathParserXML';
|
201 |
|
|
$this->addMappings('syndication', array(
|
202 |
|
|
0 => array(
|
203 |
|
|
'source' => 'xpathparser:0',
|
204 |
|
|
'target' => 'title',
|
205 |
|
|
'unique' => FALSE,
|
206 |
|
|
),
|
207 |
|
|
1 => array(
|
208 |
|
|
'source' => 'xpathparser:1',
|
209 |
|
|
'target' => 'guid',
|
210 |
|
|
'unique' => TRUE,
|
211 |
|
|
),
|
212 |
|
|
2 => array(
|
213 |
|
|
'source' => 'xpathparser:2',
|
214 |
|
|
'target' => 'body',
|
215 |
|
|
),
|
216 |
|
|
));
|
217 |
|
|
// Set importer default settings.
|
218 |
|
|
$edit = array(
|
219 |
|
|
'xpath[context]' => '//entry',
|
220 |
|
|
'xpath[sources][xpathparser:0]' => 'title',
|
221 |
|
|
'xpath[sources][xpathparser:1]' => 'id',
|
222 |
|
|
'xpath[sources][xpathparser:2]' => 'link/@$title',
|
223 |
|
|
);
|
224 |
|
|
$this->postAndCheck($importer_url, $edit, 'Save', 'Your changes have been saved.');
|
225 |
|
|
|
226 |
|
|
// Test import.
|
227 |
|
|
$path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds_xpathparser') . '/tests/feeds_xpathparser/';
|
228 |
|
|
// We use an atom feed so that we can test that default namespaces are being
|
229 |
|
|
// applied appropriately.
|
230 |
|
|
$nid = $this->createFeedNode('syndication', $path . 'rewrite_test.xml', 'Testing XPath XML Parser');
|
231 |
|
|
$feed_node_edit_url = 'node/' . $nid . '/edit';
|
232 |
|
|
$this->assertText('Created 3 nodes');
|
233 |
|
|
$this->drupalGet('node');
|
234 |
|
|
}
|
235 |
|
|
} |