[177a560] | 1 | <?php |
---|
| 2 | module_load_include('test', 'feeds', 'tests/feeds'); |
---|
| 3 | |
---|
| 4 | /** |
---|
| 5 | * @file |
---|
| 6 | * Tests for plugins/FeedsNodeProcessor.inc. |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /** |
---|
| 10 | * Test aggregating a feed as node items. |
---|
| 11 | */ |
---|
| 12 | class FeedsRSStoNodesTest extends FeedsWebTestCase { |
---|
| 13 | |
---|
| 14 | public static function getInfo() { |
---|
| 15 | return array( |
---|
| 16 | 'name' => 'RSS import to nodes', |
---|
| 17 | 'description' => 'Tests a feed configuration that is attached to a content type, uses HTTP fetcher, common syndication parser and a node processor. Repeats the same test for an importer configuration that is not attached to a content type and for a configuration that is attached to a content type and uses the file fetcher.', |
---|
| 18 | 'group' => 'Feeds', |
---|
| 19 | ); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | /** |
---|
| 23 | * Set up test. |
---|
| 24 | */ |
---|
| 25 | public function setUp() { |
---|
| 26 | parent::setUp(); |
---|
| 27 | |
---|
| 28 | // Set the front page to show 20 nodes so we can easily see what is aggregated. |
---|
| 29 | variable_set('default_nodes_main', 20); |
---|
| 30 | |
---|
| 31 | // Set the teaser length display to unlimited otherwise tests looking for |
---|
| 32 | // text on nodes will fail. |
---|
| 33 | variable_set('teaser_length', 0); |
---|
| 34 | |
---|
| 35 | // Create an importer configuration. |
---|
| 36 | $this->createImporterConfiguration('Syndication', 'syndication'); |
---|
| 37 | $this->addMappings('syndication', |
---|
| 38 | array( |
---|
| 39 | array( |
---|
| 40 | 'source' => 'title', |
---|
| 41 | 'target' => 'title', |
---|
| 42 | 'unique' => FALSE, |
---|
| 43 | ), |
---|
| 44 | array( |
---|
| 45 | 'source' => 'description', |
---|
| 46 | 'target' => 'body', |
---|
| 47 | 'unique' => FALSE, |
---|
| 48 | ), |
---|
| 49 | array( |
---|
| 50 | 'source' => 'timestamp', |
---|
| 51 | 'target' => 'created', |
---|
| 52 | 'unique' => FALSE, |
---|
| 53 | ), |
---|
| 54 | array( |
---|
| 55 | 'source' => 'url', |
---|
| 56 | 'target' => 'url', |
---|
| 57 | 'unique' => TRUE, |
---|
| 58 | ), |
---|
| 59 | array( |
---|
| 60 | 'source' => 'guid', |
---|
| 61 | 'target' => 'guid', |
---|
| 62 | 'unique' => TRUE, |
---|
| 63 | ), |
---|
| 64 | ) |
---|
| 65 | ); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | /** |
---|
| 69 | * Test node creation, refreshing/deleting feeds and feed items. |
---|
| 70 | */ |
---|
| 71 | public function test() { |
---|
| 72 | $nid = $this->createFeedNode(); |
---|
| 73 | |
---|
| 74 | // Assert 10 items aggregated after creation of the node. |
---|
| 75 | $this->assertText('Created 10 Story nodes.'); |
---|
| 76 | $story_nid = db_result(db_query_range('SELECT nid FROM {node} WHERE type = "story"', 0, 1)); |
---|
| 77 | $this->assertEqual("Created/updated by FeedsNodeProcessor", db_result(db_query("SELECT nr.log FROM {node} n JOIN {node_revisions} nr ON n.vid = nr.vid WHERE n.nid = %d", $story_nid))); |
---|
| 78 | |
---|
| 79 | // Navigate to feed node, there should be Feeds tabs visible. |
---|
| 80 | $this->drupalGet('node/'. $nid); |
---|
| 81 | $this->assertRaw('node/'. $nid .'/import'); |
---|
| 82 | $this->assertRaw('node/'. $nid .'/delete-items'); |
---|
| 83 | |
---|
| 84 | // Assert accuracy of aggregated information. |
---|
| 85 | $this->drupalGet('node'); |
---|
| 86 | $this->assertPattern('/<span class="submitted">(.*?)Anonymous<\/span>/'); |
---|
| 87 | $this->assertText('Open Atrium Translation Workflow: Two Way Translation Updates'); |
---|
| 88 | $this->assertText('Tue, 10/06/2009'); |
---|
| 89 | $this->assertText('A new translation process for Open Atrium & integration with Localize Drupal'); |
---|
| 90 | $this->assertText('Week in DC Tech: October 5th Edition'); |
---|
| 91 | $this->assertText('Mon, 10/05/2009'); |
---|
| 92 | $this->assertText('There are some great technology events happening this week'); |
---|
| 93 | $this->assertText('Mapping Innovation at the World Bank with Open Atrium'); |
---|
| 94 | $this->assertText('Fri, 10/02/2009'); |
---|
| 95 | $this->assertText('Open Atrium is being used as a base platform for collaboration'); |
---|
| 96 | $this->assertText('September GeoDC Meetup Tonight'); |
---|
| 97 | $this->assertText('Wed, 09/30/2009'); |
---|
| 98 | $this->assertText('Today is the last Wednesday of the month'); |
---|
| 99 | $this->assertText('Week in DC Tech: September 28th Edition'); |
---|
| 100 | $this->assertText('Mon, 09/28/2009'); |
---|
| 101 | $this->assertText('Looking to geek out this week? There are a bunch of'); |
---|
| 102 | $this->assertText('Open Data for Microfinance: The New MIXMarket.org'); |
---|
| 103 | $this->assertText('Thu, 09/24/2009'); |
---|
| 104 | $this->assertText('There are profiles for every country that the MIX Market is hosting.'); |
---|
| 105 | $this->assertText('Integrating the Siteminder Access System in an Open Atrium-based Intranet'); |
---|
| 106 | $this->assertText('Tue, 09/22/2009'); |
---|
| 107 | $this->assertText('In addition to authentication, the Siteminder system'); |
---|
| 108 | $this->assertText('Week in DC Tech: September 21 Edition'); |
---|
| 109 | $this->assertText('Mon, 09/21/2009'); |
---|
| 110 | $this->assertText('an interesting variety of technology events happening in Washington, DC '); |
---|
| 111 | $this->assertText('s Software Freedom Day: Impressions & Photos'); |
---|
| 112 | $this->assertText('Mon, 09/21/2009'); |
---|
| 113 | $this->assertText('Presenting on Features in Drupal and Open Atrium'); |
---|
| 114 | $this->assertText('Scaling the Open Atrium UI'); |
---|
| 115 | $this->assertText('Fri, 09/18/2009'); |
---|
| 116 | $this->assertText('The first major change is switching'); |
---|
| 117 | |
---|
| 118 | // Assert DB status. |
---|
| 119 | $count = db_result(db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid")); |
---|
| 120 | $this->assertEqual($count, 10, 'Accurate number of items in database.'); |
---|
| 121 | |
---|
| 122 | // Assert default input format on first imported feed node. |
---|
| 123 | $format = db_result(db_query_range("SELECT nr.format FROM {feeds_node_item} fi JOIN {node} n ON fi.nid = n.nid JOIN {node_revisions} nr ON n.vid = nr.vid", 0, 1)); |
---|
| 124 | $this->assertEqual($format, FILTER_FORMAT_DEFAULT, 'Using default Input format.'); |
---|
| 125 | |
---|
| 126 | // Import again. |
---|
| 127 | $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); |
---|
| 128 | $this->assertText('There is no new content.'); |
---|
| 129 | |
---|
| 130 | // Assert DB status, there still shouldn't be more than 10 items. |
---|
| 131 | $count = db_result(db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid")); |
---|
| 132 | $this->assertEqual($count, 10, 'Accurate number of items in database.'); |
---|
| 133 | |
---|
| 134 | // All of the above tests should have produced published nodes, set default |
---|
| 135 | // to unpublished, import again. |
---|
| 136 | $count = db_result(db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid WHERE n.status = 1")); |
---|
| 137 | $this->assertEqual($count, 10, 'All items are published.'); |
---|
| 138 | $edit = array( |
---|
| 139 | 'node_options[status]' => FALSE, |
---|
| 140 | ); |
---|
| 141 | $this->drupalPost('admin/content/node-type/story', $edit, t('Save content type')); |
---|
| 142 | $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete'); |
---|
| 143 | $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); |
---|
| 144 | $count = db_result(db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid WHERE n.status = 0")); |
---|
| 145 | $this->assertEqual($count, 10, 'No items are published.'); |
---|
| 146 | $edit = array( |
---|
| 147 | 'node_options[status]' => TRUE, |
---|
| 148 | ); |
---|
| 149 | $this->drupalPost('admin/content/node-type/story', $edit, t('Save content type')); |
---|
| 150 | $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete'); |
---|
| 151 | |
---|
| 152 | // Enable replace existing and import updated feed file. |
---|
| 153 | $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); |
---|
| 154 | $this->setSettings('syndication', 'FeedsNodeProcessor', array('update_existing' => 1)); |
---|
| 155 | $feed_url = $GLOBALS['base_url'] .'/'. drupal_get_path('module', 'feeds') .'/tests/feeds/developmentseed_changes.rss2'; |
---|
| 156 | $this->editFeedNode($nid, $feed_url); |
---|
| 157 | $this->drupalPost('node/' . $nid . '/import', array(), 'Import'); |
---|
| 158 | $this->assertText('Updated 2 Story nodes.'); |
---|
| 159 | |
---|
| 160 | // Assert accuracy of aggregated content (check 2 updates, one original). |
---|
| 161 | $this->drupalGet('node'); |
---|
| 162 | $this->assertText('Managing News Translation Workflow: Two Way Translation Updates'); |
---|
| 163 | $this->assertText('Presenting on Features in Drupal and Managing News'); |
---|
| 164 | $this->assertText('Scaling the Open Atrium UI'); |
---|
| 165 | |
---|
| 166 | // Import again. |
---|
| 167 | $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); |
---|
| 168 | $this->assertText('There is no new content.'); |
---|
| 169 | |
---|
| 170 | // Assert DB status, there still shouldn't be more than 10 items. |
---|
| 171 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}")); |
---|
| 172 | $this->assertEqual($count, 10, 'Accurate number of items in database.'); |
---|
| 173 | |
---|
| 174 | // Now delete all items. |
---|
| 175 | $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete'); |
---|
| 176 | $this->assertText('Deleted 10 nodes.'); |
---|
| 177 | |
---|
| 178 | // Assert DB status, now there should be no items. |
---|
| 179 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}")); |
---|
| 180 | $this->assertEqual($count, 0, 'Accurate number of items in database.'); |
---|
| 181 | |
---|
| 182 | // Change author. |
---|
| 183 | $author = $this->drupalCreateUser(); |
---|
| 184 | $this->setSettings('syndication', 'FeedsNodeProcessor', array('author' => $author->name)); |
---|
| 185 | |
---|
| 186 | // Change input format. |
---|
| 187 | $this->setSettings('syndication', 'FeedsNodeProcessor', array('input_format' => FILTER_FORMAT_DEFAULT + 1)); |
---|
| 188 | |
---|
| 189 | // Import again. |
---|
| 190 | $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); |
---|
| 191 | $this->assertText('Created 10 Story nodes.'); |
---|
| 192 | |
---|
| 193 | // Assert author. |
---|
| 194 | $this->drupalGet('node'); |
---|
| 195 | $this->assertPattern('/<span class="submitted">(.*?)'. check_plain($author->name) .'<\/span>/'); |
---|
| 196 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item} fi JOIN {node} n ON fi.nid = n.nid WHERE n.uid = %d", $author->uid)); |
---|
| 197 | $this->assertEqual($count, 10, 'Accurate number of items in database.'); |
---|
| 198 | |
---|
| 199 | // Assert input format. |
---|
| 200 | $format = db_result(db_query_range("SELECT nr.format FROM {feeds_node_item} fi JOIN {node} n ON fi.nid = n.nid JOIN {node_revisions} nr ON n.vid = nr.vid", 0, 1)); |
---|
| 201 | $this->assertEqual($format, FILTER_FORMAT_DEFAULT + 1, 'Set non-default Input format.'); |
---|
| 202 | |
---|
| 203 | // Set to update existing, remove authorship of above nodes and import again. |
---|
| 204 | $this->setSettings('syndication', 'FeedsNodeProcessor', array('update_existing' => 2)); |
---|
| 205 | $result = db_query("SELECT nid FROM {node} n INNER JOIN {feeds_node_item} USING (nid)"); |
---|
| 206 | while ($reset_nid = db_result($result)) { |
---|
| 207 | db_query("UPDATE {node} SET uid = 0 WHERE nid = %d", $reset_nid); |
---|
| 208 | db_query("UPDATE {feeds_node_item} SET hash = '' WHERE nid = %d", $reset_nid); |
---|
| 209 | } |
---|
| 210 | $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); |
---|
| 211 | $this->drupalGet('node'); |
---|
| 212 | $this->assertNoPattern('/<span class="submitted">(.*?)'. check_plain($author->name) .'<\/span>/'); |
---|
| 213 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item} fi JOIN {node} n ON fi.nid = n.nid WHERE n.uid = %d", $author->uid)); |
---|
| 214 | $this->assertEqual($count, 0, 'Accurate number of items in database.'); |
---|
| 215 | |
---|
| 216 | // Map feed node's author to feed item author, update - feed node's items |
---|
| 217 | // should now be assigned to feed node author. |
---|
| 218 | $this->addMappings('syndication', |
---|
| 219 | array( |
---|
| 220 | array( |
---|
| 221 | 'source' => 'parent:uid', |
---|
| 222 | 'target' => 'uid', |
---|
| 223 | ), |
---|
| 224 | ) |
---|
| 225 | ); |
---|
| 226 | $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); |
---|
| 227 | $this->drupalGet('node'); |
---|
| 228 | $this->assertNoPattern('/<span class="submitted">(.*?)'. check_plain($author->name) .'<\/span>/'); |
---|
| 229 | $uid = db_result(db_query("SELECT uid FROM {node} WHERE nid = %d", $nid)); |
---|
| 230 | $count = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE uid = %d", $uid)); |
---|
| 231 | $this->assertEqual($count, 11, 'All feed item nodes are assigned to feed node author.'); |
---|
| 232 | |
---|
| 233 | // Login with new user with only access content permissions. |
---|
| 234 | $this->drupalLogin( |
---|
| 235 | $this->drupalCreateUser() |
---|
| 236 | ); |
---|
| 237 | // Navigate to feed node, there should be no Feeds tabs visible. |
---|
| 238 | $this->drupalGet('node/'. $nid); |
---|
| 239 | $this->assertNoRaw('node/'. $nid .'/import'); |
---|
| 240 | $this->assertNoRaw('node/'. $nid .'/delete-items'); |
---|
| 241 | |
---|
| 242 | // Now create a second feed configuration that is not attached to a content |
---|
| 243 | // type and run tests on importing/purging. |
---|
| 244 | |
---|
| 245 | // Login with sufficient permissions. |
---|
| 246 | $this->drupalLogin( |
---|
| 247 | $this->drupalCreateUser(array('administer feeds', 'administer nodes')) |
---|
| 248 | ); |
---|
| 249 | // Remove all items again so that next test can check for them. |
---|
| 250 | $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete'); |
---|
| 251 | |
---|
| 252 | // Create an importer, not attached to content type. |
---|
| 253 | $this->createImporterConfiguration('Syndication standalone', 'syndication_standalone'); |
---|
| 254 | $edit = array( |
---|
| 255 | 'content_type' => '', |
---|
| 256 | ); |
---|
| 257 | $this->drupalPost('admin/build/feeds/edit/syndication_standalone/settings', $edit, 'Save'); |
---|
| 258 | $this->addMappings('syndication_standalone', |
---|
| 259 | array( |
---|
| 260 | array( |
---|
| 261 | 'source' => 'title', |
---|
| 262 | 'target' => 'title', |
---|
| 263 | 'unique' => FALSE, |
---|
| 264 | ), |
---|
| 265 | array( |
---|
| 266 | 'source' => 'description', |
---|
| 267 | 'target' => 'body', |
---|
| 268 | 'unique' => FALSE, |
---|
| 269 | ), |
---|
| 270 | array( |
---|
| 271 | 'source' => 'timestamp', |
---|
| 272 | 'target' => 'created', |
---|
| 273 | 'unique' => FALSE, |
---|
| 274 | ), |
---|
| 275 | array( |
---|
| 276 | 'source' => 'url', |
---|
| 277 | 'target' => 'url', |
---|
| 278 | 'unique' => TRUE, |
---|
| 279 | ), |
---|
| 280 | array( |
---|
| 281 | 'source' => 'guid', |
---|
| 282 | 'target' => 'guid', |
---|
| 283 | 'unique' => TRUE, |
---|
| 284 | ), |
---|
| 285 | ) |
---|
| 286 | ); |
---|
| 287 | |
---|
| 288 | // Import, assert 10 items aggregated after creation of the node. |
---|
| 289 | $this->importURL('syndication_standalone'); |
---|
| 290 | $this->assertText('Created 10 Story nodes.'); |
---|
| 291 | |
---|
| 292 | // Assert accuracy of aggregated information. |
---|
| 293 | $this->drupalGet('node'); |
---|
| 294 | $this->assertText('Open Atrium Translation Workflow: Two Way Translation Updates'); |
---|
| 295 | $this->assertText('Tue, 10/06/2009'); |
---|
| 296 | $this->assertText('A new translation process for Open Atrium & integration with Localize Drupal'); |
---|
| 297 | $this->assertText('Week in DC Tech: October 5th Edition'); |
---|
| 298 | $this->assertText('Mon, 10/05/2009'); |
---|
| 299 | $this->assertText('There are some great technology events happening this week'); |
---|
| 300 | $this->assertText('Mapping Innovation at the World Bank with Open Atrium'); |
---|
| 301 | $this->assertText('Fri, 10/02/2009'); |
---|
| 302 | $this->assertText('Open Atrium is being used as a base platform for collaboration'); |
---|
| 303 | $this->assertText('September GeoDC Meetup Tonight'); |
---|
| 304 | $this->assertText('Wed, 09/30/2009'); |
---|
| 305 | $this->assertText('Today is the last Wednesday of the month'); |
---|
| 306 | $this->assertText('Week in DC Tech: September 28th Edition'); |
---|
| 307 | $this->assertText('Mon, 09/28/2009'); |
---|
| 308 | $this->assertText('Looking to geek out this week? There are a bunch of'); |
---|
| 309 | $this->assertText('Open Data for Microfinance: The New MIXMarket.org'); |
---|
| 310 | $this->assertText('Thu, 09/24/2009'); |
---|
| 311 | $this->assertText('There are profiles for every country that the MIX Market is hosting.'); |
---|
| 312 | $this->assertText('Integrating the Siteminder Access System in an Open Atrium-based Intranet'); |
---|
| 313 | $this->assertText('Tue, 09/22/2009'); |
---|
| 314 | $this->assertText('In addition to authentication, the Siteminder system'); |
---|
| 315 | $this->assertText('Week in DC Tech: September 21 Edition'); |
---|
| 316 | $this->assertText('Mon, 09/21/2009'); |
---|
| 317 | $this->assertText('an interesting variety of technology events happening in Washington, DC '); |
---|
| 318 | $this->assertText('s Software Freedom Day: Impressions & Photos'); |
---|
| 319 | $this->assertText('Mon, 09/21/2009'); |
---|
| 320 | $this->assertText('Presenting on Features in Drupal and Open Atrium'); |
---|
| 321 | $this->assertText('Scaling the Open Atrium UI'); |
---|
| 322 | $this->assertText('Fri, 09/18/2009'); |
---|
| 323 | $this->assertText('The first major change is switching'); |
---|
| 324 | |
---|
| 325 | // Assert DB status. |
---|
| 326 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}")); |
---|
| 327 | $this->assertEqual($count, 10, 'Accurate number of items in database.'); |
---|
| 328 | |
---|
| 329 | // Import again. |
---|
| 330 | $this->drupalPost('import/syndication_standalone', array(), 'Import'); |
---|
| 331 | $this->assertText('There is no new content.'); |
---|
| 332 | |
---|
| 333 | // Assert DB status, there still shouldn't be more than 10 items. |
---|
| 334 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}")); |
---|
| 335 | $this->assertEqual($count, 10, 'Accurate number of items in database.'); |
---|
| 336 | |
---|
| 337 | // Enable replace existing and import updated feed file. |
---|
| 338 | $this->setSettings('syndication_standalone', 'FeedsNodeProcessor', array('update_existing' => 1)); |
---|
| 339 | $feed_url = $GLOBALS['base_url'] .'/'. drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed_changes.rss2'; |
---|
| 340 | $this->importURL('syndication_standalone', $feed_url); |
---|
| 341 | $this->assertText('Updated 2 Story nodes.'); |
---|
| 342 | |
---|
| 343 | // Assert accuracy of aggregated information (check 2 updates, one orig). |
---|
| 344 | $this->drupalGet('node'); |
---|
| 345 | $this->assertText('Managing News Translation Workflow: Two Way Translation Updates'); |
---|
| 346 | $this->assertText('Presenting on Features in Drupal and Managing News'); |
---|
| 347 | $this->assertText('Scaling the Open Atrium UI'); |
---|
| 348 | |
---|
| 349 | // Import again. |
---|
| 350 | $this->drupalPost('import/syndication_standalone', array(), 'Import'); |
---|
| 351 | $this->assertText('There is no new content.'); |
---|
| 352 | |
---|
| 353 | // Assert DB status, there still shouldn't be more than 10 items. |
---|
| 354 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}")); |
---|
| 355 | $this->assertEqual($count, 10, 'Accurate number of items in database.'); |
---|
| 356 | |
---|
| 357 | // Now delete all items. |
---|
| 358 | $this->drupalPost('import/syndication_standalone/delete-items', array(), 'Delete'); |
---|
| 359 | $this->assertText('Deleted 10 nodes.'); |
---|
| 360 | |
---|
| 361 | // Assert DB status, now there should be no items. |
---|
| 362 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}")); |
---|
| 363 | $this->assertEqual($count, 0, 'Accurate number of items in database.'); |
---|
| 364 | |
---|
| 365 | // Import again, we should find new content. |
---|
| 366 | $this->drupalPost('import/syndication_standalone', array(), 'Import'); |
---|
| 367 | $this->assertText('Created 10 Story nodes.'); |
---|
| 368 | |
---|
| 369 | // Assert DB status, there should be 10 again. |
---|
| 370 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}")); |
---|
| 371 | $this->assertEqual($count, 10, 'Accurate number of items in database.'); |
---|
| 372 | |
---|
| 373 | // Login with new user with only access content permissions. |
---|
| 374 | $this->drupalLogin( |
---|
| 375 | $this->drupalCreateUser() |
---|
| 376 | ); |
---|
| 377 | // Navigate to feed import form, access should be denied. |
---|
| 378 | $this->drupalGet('import/syndication_standalone'); |
---|
| 379 | $this->assertResponse(403); |
---|
| 380 | |
---|
| 381 | // Use File Fetcher. |
---|
| 382 | $this->drupalLogin( |
---|
| 383 | $this->drupalCreateUser(array('administer feeds', 'administer nodes')) |
---|
| 384 | ); |
---|
| 385 | $this->setPlugin('syndication', 'FeedsFileFetcher'); |
---|
| 386 | // Create a feed node. |
---|
| 387 | $edit = array( |
---|
| 388 | 'files[feeds]' => $this->absolutePath() .'/tests/feeds/drupalplanet.rss2', |
---|
| 389 | ); |
---|
| 390 | $this->drupalPost('node/add/page', $edit, 'Save'); |
---|
| 391 | $this->assertText('Page drupal.org aggregator has been created.'); |
---|
| 392 | $this->assertText('Created 25 Story nodes.'); |
---|
| 393 | } |
---|
| 394 | |
---|
| 395 | /** |
---|
| 396 | * Check that the total number of nodes in the feeds_node_item table is correct. |
---|
| 397 | */ |
---|
| 398 | function assertFeedItemCount($num) { |
---|
| 399 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}")); |
---|
| 400 | $this->assertEqual($count, $num, 'Accurate number of items in database.'); |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | /** |
---|
| 404 | * Test validation of feed URLs. |
---|
| 405 | */ |
---|
| 406 | function testFeedURLValidation() { |
---|
| 407 | $edit['feeds[FeedsHTTPFetcher][source]'] = 'invalid://url'; |
---|
| 408 | $this->drupalPost('node/add/page', $edit, 'Save'); |
---|
| 409 | $this->assertText('The URL invalid://url is invalid.'); |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | /** |
---|
| 413 | * Test using non-normal URLs like feed:// and webcal://. |
---|
| 414 | */ |
---|
| 415 | function testOddFeedSchemes() { |
---|
| 416 | $url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') .'/tests/feeds/developmentseed.rss2'; |
---|
| 417 | |
---|
| 418 | $schemes = array('feed'); |
---|
| 419 | $item_count = 0; |
---|
| 420 | foreach ($schemes as $scheme) { |
---|
| 421 | $feed_url = strtr($url, array('http://' => $scheme . '://', 'https://' => $scheme . '://')); |
---|
| 422 | |
---|
| 423 | $edit['feeds[FeedsHTTPFetcher][source]'] = $feed_url; |
---|
| 424 | $this->drupalPost('node/add/page', $edit, 'Save'); |
---|
| 425 | $this->assertText('Page Development Seed - Technological Solutions for Progressive Organizations has been created.'); |
---|
| 426 | $this->assertText('Created 10 Story nodes.'); |
---|
| 427 | $this->assertFeedItemCount($item_count + 10); |
---|
| 428 | $item_count += 10; |
---|
| 429 | } |
---|
| 430 | } |
---|
| 431 | |
---|
| 432 | /** |
---|
| 433 | * Test that feed elements and links are not found on non-feed nodes. |
---|
| 434 | */ |
---|
| 435 | function testNonFeedNodeUI() { |
---|
| 436 | // There should not be feed links on an article node. |
---|
| 437 | $non_feed_node = $this->drupalCreateNode(array('type' => 'story')); |
---|
| 438 | $this->drupalGet('node/' . $non_feed_node->nid); |
---|
| 439 | $this->assertNoLinkByHref('node/' . $non_feed_node->nid . '/import'); |
---|
| 440 | $this->assertNoLink('Delete items'); |
---|
| 441 | |
---|
| 442 | // Navigate to a non-feed node form, there should be no Feed field visible. |
---|
| 443 | $this->drupalGet('node/add/article'); |
---|
| 444 | $this->assertNoFieldByName('feeds[FeedsHTTPFetcher][source]'); |
---|
| 445 | } |
---|
| 446 | } |
---|