Newer
Older
<?php
/**
* @file
* Tests for plugins/FeedsNodeProcessor.inc.
*/
/**
* Test aggregating a feed as node items.
*/
class FeedsRSStoNodesTest extends FeedsWebTestCase {
Dave Reid
committed
public static function getInfo() {
return array(
'name' => 'Processor: Node',
'description' => 'Tests for the node processor.',
Dave Reid
committed
'group' => 'Feeds',
);
}
/**
* Set up test.
*/
public function setUp() {
parent::setUp();
// Set the front page to show 20 nodes so we can easily see what is aggregated.
// Set the teaser length display to unlimited otherwise tests looking for
// text on nodes will fail.
$edit = array('fields[body][type]' => 'text_default');
$this->drupalPost('admin/structure/types/manage/article/display/teaser', $edit, 'Save');
// Create an importer configuration.
$this->createImporterConfiguration('Syndication', 'syndication');
$this->addMappings('syndication',
array(
niklas
committed
0 => array(
'source' => 'title',
'target' => 'title',
'unique' => FALSE,
),
'source' => 'description',
'target' => 'body',
),
'source' => 'timestamp',
'target' => 'created',
),
'source' => 'url',
'target' => 'url',
'unique' => TRUE,
),
'source' => 'guid',
'target' => 'guid',
'unique' => TRUE,
),
)
);
/**
* Test node creation, refreshing/deleting feeds and feed items.
*/
public function test() {
$nid = $this->createFeedNode();
Alex Barth
committed
// Assert 10 items aggregated after creation of the node.
$this->assertText('Created 10 nodes');
$article_nid = db_query_range("SELECT nid FROM {node} WHERE type = 'article'", 0, 1)->fetchField();
$this->assertEqual("Created by FeedsNodeProcessor", db_query("SELECT nr.log FROM {node} n JOIN {node_revision} nr ON n.vid = nr.vid WHERE n.nid = :nid", array(':nid' => $article_nid))->fetchField());
// Navigate to feed node, there should be Feeds tabs visible.
$this->drupalGet("node/$nid");
$this->assertRaw("node/$nid/import");
$this->assertRaw("node/$nid/delete-items");
// Assert accuracy of aggregated information.
$this->drupalGet('node');
Alex Barth
committed
$this->assertRaw('<span class="username">Anonymous (not verified)</span>');
$this->assertDevseedFeedContent();
// Assert DB status.
$count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id")->fetchField();
$this->assertEqual($count, 10, 'Accurate number of items in database.');
// Assert default input format on first imported feed node.
// NEEDS update.
// $format = db_query_range("SELECT nr.format FROM {feeds_node_item} fi JOIN {node} n ON fi.nid = n.nid JOIN {node_revision} nr ON n.vid = nr.vid", 0, 1)->fetchField();
// $this->assertEqual($format, filter_fallback_format(), 'Using default Input format.');
// Import again.
$this->drupalPost("node/$nid/import", array(), 'Import');
$this->assertText('There are no new nodes');
// Assert DB status, there still shouldn't be more than 10 items.
$count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id")->fetchField();
$this->assertEqual($count, 10, 'Accurate number of items in database.');
// All of the above tests should have produced published nodes, set default
// to unpublished, import again.
$count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id WHERE n.status = 1")->fetchField();
$this->assertEqual($count, 10, 'All items are published.');
$edit = array(
'node_options[status]' => FALSE,
);
Alex Barth
committed
$this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));
$this->drupalPost("node/$nid/delete-items", array(), 'Delete');
$this->drupalPost("node/$nid/import", array(), 'Import');
$count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id WHERE n.status = 0")->fetchField();
$this->assertEqual($count, 10, 'No items are published.');
$edit = array(
'node_options[status]' => TRUE,
);
Alex Barth
committed
$this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));
$this->drupalPost("node/$nid/delete-items", array(), 'Delete');
// Enable replace existing and import updated feed file.
$this->drupalPost("node/$nid/import", array(), 'Import');
$this->setSettings('syndication', 'FeedsNodeProcessor', array('update_existing' => 1));
$feed_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed_changes.rss2';
$this->editFeedNode($nid, $feed_url);
$this->drupalPost("node/$nid/import", array(), 'Import');
$this->assertText('Updated 2 nodes');
// Assert accuracy of aggregated content (check 2 updates, one original).
$this->drupalGet('node');
$this->assertText('Managing News Translation Workflow: Two Way Translation Updates');
$this->assertText('Presenting on Features in Drupal and Managing News');
$this->assertText('Scaling the Open Atrium UI');
// Import again.
$this->drupalPost("node/$nid/import", array(), 'Import');
$this->assertText('There are no new nodes');
// Now delete all items.
$this->drupalPost("node/$nid/delete-items", array(), 'Delete');
$this->assertText('Deleted 10 nodes');
// Change author and turn off authorization.
$this->auth_user = $this->drupalCreateUser(array('access content'));
$this->setSettings('syndication', 'FeedsNodeProcessor', array('author' => $this->auth_user->name, 'authorize' => FALSE));
// Change input format.
$this->setSettings('syndication', 'FeedsNodeProcessor', array('input_format' => 'plain_text'));
// Import again.
$this->drupalPost("node/$nid/import", array(), 'Import');
$this->assertText('Created 10 nodes');
// Assert author.
$this->drupalGet('node');
$this->assertPattern('/<span class="username">' . check_plain($this->auth_user->name) . '<\/span>/');
$count = db_query("SELECT COUNT(*) FROM {feeds_item} fi JOIN {node} n ON fi.entity_type = 'node' AND fi.entity_id = n.nid WHERE n.uid = :uid", array(':uid' => $this->auth_user->uid))->fetchField();
$this->assertEqual($count, 10, 'Accurate number of items in database.');
// Assert input format.
// NEEDS update.
// $format = db_query_range("SELECT nr.format FROM {feeds_node_item} fi JOIN {node} n ON fi.nid = n.nid JOIN {node_revision} nr ON n.vid = nr.vid", 0, 1)->fetchField();
// $this->assertEqual($format, filter_fallback_format() + 1, 'Set non-default Input format.');
// Set to update existing, remove authorship of above nodes and import again.
$this->setSettings('syndication', 'FeedsNodeProcessor', array('update_existing' => 2));
Dave Reid
committed
$nids = db_query("SELECT nid FROM {node} n INNER JOIN {feeds_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id")->fetchCol();
db_update('node')
->fields(array('uid' => 0))
->condition('nid', $nids, 'IN')
->execute();
db_update('feeds_item')
->fields(array('hash' => ''))
->condition('entity_type', 'node')
->condition('entity_id', $nids, 'IN')
->execute();
$this->drupalPost("node/$nid/import", array(), 'Import');
$this->drupalGet('node');
$this->assertNoPattern('/<span class="username">' . check_plain($this->auth_user->name) . '<\/span>/');
$count = db_query("SELECT COUNT(*) FROM {feeds_item} fi JOIN {node} n ON fi.entity_type = 'node' AND fi.entity_id = n.nid WHERE n.uid = :uid", array(':uid' => $this->auth_user->uid))->fetchField();
$this->assertEqual($count, 0, 'Accurate number of items in database.');
// Map feed node's author to feed item author, update - feed node's items
// should now be assigned to feed node author.
$this->addMappings('syndication',
array(
'source' => 'parent:uid',
'target' => 'uid',
),
)
);
$this->drupalPost("node/$nid/import", array(), 'Import');
$this->drupalGet('node');
$this->assertNoPattern('/<span class="username">' . check_plain($this->auth_user->name) . '<\/span>/');
$uid = db_query("SELECT uid FROM {node} WHERE nid = :nid", array(':nid' => $nid))->fetchField();
$count = db_query("SELECT COUNT(*) FROM {node} WHERE uid = :uid", array(':uid' => $uid))->fetchField();
$this->assertEqual($count, 11, 'All feed item nodes are assigned to feed node author.');
// Login with new user with only access content permissions.
$this->drupalLogin($this->auth_user);
// Navigate to feed node, there should be no Feeds tabs visible.
$this->drupalGet("node/$nid");
$this->assertNoRaw("node/$nid/import");
$this->assertNoRaw("node/$nid/delete-items");
// Now create a second feed configuration that is not attached to a content
// type and run tests on importing/purging.
// Login with sufficient permissions.
$this->drupalLogin($this->admin_user);
// Remove all items again so that next test can check for them.
$this->drupalPost("node/$nid/delete-items", array(), 'Delete');
// Create an importer, not attached to content type.
$this->createImporterConfiguration('Syndication standalone', 'syndication_standalone');
$edit = array(
'content_type' => '',
);
twistor
committed
$this->drupalPost('admin/structure/feeds/syndication_standalone/settings', $edit, 'Save');
$this->addMappings('syndication_standalone',
array(
niklas
committed
0 => array(
'source' => 'title',
'target' => 'title',
'unique' => FALSE,
),
niklas
committed
1 => array(
'source' => 'description',
'target' => 'body',
),
niklas
committed
2 => array(
'source' => 'timestamp',
'target' => 'created',
),
niklas
committed
3 => array(
'source' => 'url',
'target' => 'url',
'unique' => TRUE,
),
niklas
committed
4 => array(
'source' => 'guid',
'target' => 'guid',
'unique' => TRUE,
),
)
);
// Import, assert 10 items aggregated after creation of the node.
$this->importURL('syndication_standalone');
$this->assertText('Created 10 nodes');
// Assert accuracy of aggregated information.
$this->drupalGet('node');
Alex Barth
committed
$this->assertDevseedFeedContent();
// Import again.
$this->drupalPost('import/syndication_standalone', array(), 'Import');
$this->assertText('There are no new nodes');
// Enable replace existing and import updated feed file.
$this->setSettings('syndication_standalone', 'FeedsNodeProcessor', array('update_existing' => 1));
$feed_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed_changes.rss2';
$this->importURL('syndication_standalone', $feed_url);
$this->assertText('Updated 2 nodes');
// Assert accuracy of aggregated information (check 2 updates, one orig).
$this->drupalGet('node');
$this->assertText('Managing News Translation Workflow: Two Way Translation Updates');
$this->assertText('Presenting on Features in Drupal and Managing News');
$this->assertText('Scaling the Open Atrium UI');
// Import again.
$this->drupalPost('import/syndication_standalone', array(), 'Import');
$this->assertText('There are no new nodes');
// Now delete all items.
$this->drupalPost('import/syndication_standalone/delete-items', array(), 'Delete');
$this->assertText('Deleted 10 nodes');
// Import again, we should find new content.
$this->drupalPost('import/syndication_standalone', array(), 'Import');
$this->assertText('Created 10 nodes');
// Enable unpublish missing nodes and import updated feed file.
$this->setSettings('syndication_standalone', 'FeedsNodeProcessor', array('update_non_existent' => FEEDS_UNPUBLISH_NON_EXISTENT, 'update_existing' => FEEDS_REPLACE_EXISTING));
$missing_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed_missing.rss2';
$this->importURL('syndication_standalone', $missing_url);
$this->assertText('Unpublished 1 node');
$this->assertFeedItemCount(10);
// Import again to ensure the message that one node is unpublished doesn't
// reappear (since the node was already unpublished during the previous
// import).
$this->drupalPost('import/syndication_standalone', array(), 'Import');
$this->assertText('There are no new nodes');
$this->assertFeedItemCount(10);
// Re-import the original feed to ensure the unpublished node is updated,
// even though the item is the same since the last time it was available in
// the feed. Fact is that the node was not available in the previous import
// and that should be seen as a change.
$this->importURL('syndication_standalone', $feed_url);
$this->assertText('Updated 1 node');
$this->assertFeedItemCount(10);
// Now delete all items.
$this->drupalPost('import/syndication_standalone/delete-items', array(), 'Delete');
$this->assertText('Deleted 10 nodes');
$this->assertFeedItemCount(0);
// Import again, to reset node counts.
$this->importURL('syndication_standalone', $feed_url);
$this->assertText('Created 10 nodes');
$this->assertFeedItemCount(10);
// Change settings to delete non-existent nodes from feed.
$this->setSettings('syndication_standalone', 'FeedsNodeProcessor', array('update_non_existent' => 'delete'));
$this->importURL('syndication_standalone', $missing_url);
$this->assertText('Removed 1 node');
$this->assertFeedItemCount(9);
// Now delete all items.
$this->drupalPost('import/syndication_standalone/delete-items', array(), 'Delete');
$this->assertText('Deleted 9 nodes');
$this->assertFeedItemCount(0);
// Login with new user with only access content permissions.
$this->drupalLogin($this->auth_user);
Alex Barth
committed
// Navigate to feed import form, access should be denied.
$this->drupalGet('import/syndication_standalone');
$this->assertResponse(403);
// Use File Fetcher.
$this->drupalLogin($this->admin_user);
$edit = array('plugin_key' => 'FeedsFileFetcher');
twistor
committed
$this->drupalPost('admin/structure/feeds/syndication_standalone/fetcher', $edit, 'Save');
$edit = array(
'allowed_extensions' => 'rss2',
);
twistor
committed
$this->drupalPost('admin/structure/feeds/syndication_standalone/settings/FeedsFileFetcher', $edit, 'Save');
Alex Barth
committed
// Create a feed node.
$edit = array(
'files[feeds]' => $this->absolutePath() . '/tests/feeds/drupalplanet.rss2',
$this->drupalPost('import/syndication_standalone', $edit, 'Import');
$this->assertText('Created 25 nodes');
Alex Barth
committed
* Check that the total number of entries in the feeds_item table is correct.
public function assertFeedItemCount($num) {
$count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node'")->fetchField();
$this->assertEqual($count, $num, 'Accurate number of items in database.');
}
Alex Barth
committed
/**
* Check thet contents of the current page for the DS feed.
*/
public function assertDevseedFeedContent() {
Alex Barth
committed
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
$this->assertText('Open Atrium Translation Workflow: Two Way Translation Updates');
$this->assertText('Tue, 10/06/2009');
$this->assertText('A new translation process for Open Atrium & integration with Localize Drupal');
$this->assertText('Week in DC Tech: October 5th Edition');
$this->assertText('Mon, 10/05/2009');
$this->assertText('There are some great technology events happening this week');
$this->assertText('Mapping Innovation at the World Bank with Open Atrium');
$this->assertText('Fri, 10/02/2009');
$this->assertText('is being used as a base platform for collaboration at the World Bank');
$this->assertText('September GeoDC Meetup Tonight');
$this->assertText('Wed, 09/30/2009');
$this->assertText('Today is the last Wednesday of the month');
$this->assertText('Week in DC Tech: September 28th Edition');
$this->assertText('Mon, 09/28/2009');
$this->assertText('Looking to geek out this week? There are a bunch of');
$this->assertText('Open Data for Microfinance: The New MIXMarket.org');
$this->assertText('Thu, 09/24/2009');
$this->assertText('There are profiles for every country that the MIX Market is hosting.');
$this->assertText('Integrating the Siteminder Access System in an Open Atrium-based Intranet');
$this->assertText('Tue, 09/22/2009');
$this->assertText('In addition to authentication, the Siteminder system');
$this->assertText('Week in DC Tech: September 21 Edition');
$this->assertText('Mon, 09/21/2009');
$this->assertText('an interesting variety of technology events happening in Washington, DC ');
$this->assertText('s Software Freedom Day: Impressions & Photos');
$this->assertText('Mon, 09/21/2009');
$this->assertText('Presenting on Features in Drupal and Open Atrium');
$this->assertText('Scaling the Open Atrium UI');
$this->assertText('Fri, 09/18/2009');
$this->assertText('The first major change is switching');
}
/**
* Test validation of feed URLs.
*/
public function testFeedURLValidation() {
$edit['feeds[FeedsHTTPFetcher][source]'] = 'invalid://url';
$this->drupalPost('node/add/page', $edit, 'Save');
$this->assertText('The URL invalid://url is invalid.');
}
/**
* Test using non-normal URLs like feed:// and webcal://.
*/
public function testOddFeedSchemes() {
$url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2';
$schemes = array('feed', 'webcal');
$item_count = 0;
foreach ($schemes as $scheme) {
$feed_url = strtr($url, array('http://' => $scheme . '://', 'https://' => $scheme . '://'));
$edit['feeds[FeedsHTTPFetcher][source]'] = $feed_url;
$this->drupalPost('node/add/page', $edit, 'Save');
$this->assertText('Basic page Development Seed - Technological Solutions for Progressive Organizations has been created.');
$this->assertText('Created 10 nodes.');
$this->assertFeedItemCount($item_count + 10);
$item_count += 10;
}
}
/**
* Test that feed elements and links are not found on non-feed nodes.
*/
public function testNonFeedNodeUI() {
// There should not be feed links on an article node.
$non_feed_node = $this->drupalCreateNode(array('type' => 'article'));
$this->drupalGet('node/' . $non_feed_node->nid);
Dave Reid
committed
$this->assertNoLinkByHref('node/' . $non_feed_node->nid . '/import');
$this->assertNoLink('Delete items');
Dave Reid
committed
// Navigate to a non-feed node form, there should be no Feed field visible.
$this->drupalGet('node/add/article');
$this->assertNoFieldByName('feeds[FeedsHTTPFetcher][source]');
}
* Test that nodes will not be created if the user is unauthorized to create
* them.
*/
public function testAuthorize() {
// Create a user with limited permissions. We can't use
// $this->drupalCreateUser here because we need to to set a specific user
// name.
$edit = array(
'name' => 'Development Seed',
'mail' => 'devseed@example.com',
'pass' => user_password(),
'status' => 1,
);
$account = user_save(drupal_anonymous_user(), $edit);
// Adding a mapping to the user_name will invoke authorization.
$this->addMappings('syndication',
array(
5 => array(
'source' => 'author_name',
'target' => 'user_name',
),
)
);
$nid = $this->createFeedNode();
$this->assertText('Failed importing 10 nodes.');
megachriz
committed
$this->assertText('The user ' . $account->name . ' is not authorized to create content of type article.');
$node_count = db_query("SELECT COUNT(*) FROM {node}")->fetchField();
// We should have 1 node, the feed node.
$this->assertEqual($node_count, 1, t('Correct number of nodes in the database.'));
// Give the user our admin powers.
$edit = array(
'roles' => $this->admin_user->roles,
);
$account = user_save($account, $edit);
$this->drupalPost("node/$nid/import", array(), 'Import');
$this->assertText('Created 10 nodes.');
$node_count = db_query("SELECT COUNT(*) FROM {node}")->fetchField();
$this->assertEqual($node_count, 11, t('Correct number of nodes in the database.'));
}
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
/**
* Tests expiring nodes.
*/
public function testExpiry() {
// Create importer configuration.
$this->setSettings('syndication', NULL, array('content_type' => ''));
$this->setSettings('syndication', 'FeedsNodeProcessor', array(
'expire' => 2592000,
));
// Create importer.
$this->importURL('syndication');
// Set date of a few nodes to current date so they don't expire.
$edit = array(
'date' => date('Y-m-d'),
);
$this->drupalPost('node/2/edit', $edit, 'Save');
$this->assertText(date('m/d/Y'), 'Found correct date.');
$this->drupalPost('node/5/edit', $edit, 'Save');
$this->assertText(date('m/d/Y'), 'Found correct date.');
// Run cron to schedule jobs.
$this->cronRun();
// Set feeds source expire to run immediately.
db_update('job_schedule')
->fields(array(
'next' => 0,
))
->condition('name', 'feeds_source_expire')
->execute();
// Run cron to execute scheduled jobs.
$this->cronRun();
// Query the feeds_items table and count the number of entries.
$row_count = db_query('SELECT COUNT(*) FROM {feeds_item}')->fetchField();
// Check that number of feeds items is equal to the expected items.
$this->assertEqual($row_count, 2, 'Nodes expired.');
}
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
/**
* Tests process in background option.
*/
public function testImportInBackground() {
// Just remove the mappings rather than creating a new importer.
$this->removeMappings('syndication', $this->getCurrentMappings('syndication'));
// Set our process limit to something simple.
variable_set('feeds_process_limit', 5);
$this->setPlugin('syndication', 'FeedsFileFetcher');
$this->setPlugin('syndication', 'FeedsCSVParser');
$this->setSettings('syndication', NULL, array(
'content_type' => '',
'process_in_background' => TRUE,
'import_period' => FEEDS_SCHEDULE_NEVER,
));
$this->addMappings('syndication', array(
0 => array(
'source' => 'title',
'target' => 'title',
),
1 => array(
'source' => 'GUID',
'target' => 'guid',
'unique' => TRUE,
),
));
$this->importFile('syndication', $this->absolutePath() . '/tests/feeds/many_nodes_ordered.csv');
$this->assertEqual(5, db_query("SELECT COUNT(*) FROM {node}")->fetchField());
// The feed should still be scheduled because it is being processed.
// @see https://drupal.org/node/2275893
$this->cronRun();
$this->assertEqual(86, db_query("SELECT COUNT(*) FROM {node}")->fetchField());
}
fietserwin
committed
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
/**
* Tests skip new items.
*/
public function testSkipNewItems() {
// Include FeedsProcessor.inc so processor related constants are available.
module_load_include('inc', 'feeds', 'plugins/FeedsProcessor');
// Attach to standalone importer.
$this->setSettings('syndication', NULL, array('content_type' => ''));
// Set that new items should not be imported.
$this->setSettings('syndication', 'FeedsNodeProcessor', array(
'insert_new' => FEEDS_SKIP_NEW,
'update_existing' => FEEDS_SKIP_EXISTING,
));
// Make title unique target.
$this->removeMappings('syndication', $this->getCurrentMappings('syndication'));
$this->addMappings('syndication', array(
0 => array(
'source' => 'title',
'target' => 'title',
'unique' => TRUE,
),
1 => array(
'source' => 'description',
'target' => 'body',
),
2 => array(
'source' => 'timestamp',
'target' => 'created',
),
));
// Do a first import, no nodes should be created.
$edit = array(
'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2',
);
$this->drupalPost('import/syndication', $edit, 'Import');
$this->assertText('There are no new nodes');
// Now create two nodes with titles that are present in the source
// "developmentseed.rss2".
$this->drupalCreateNode(array(
'type' => 'article',
'title' => 'Open Atrium Translation Workflow: Two Way Translation Updates',
));
$this->drupalCreateNode(array(
'type' => 'article',
'title' => 'Week in DC Tech: October 5th Edition',
));
// Import again. Since the processor is set to not update as well, nothing
// should be imported.
$this->drupalPost('import/syndication', array(), 'Import');
$this->assertText('There are no new nodes');
// Now set importer to update existing.
$this->setSettings('syndication', 'FeedsNodeProcessor', array(
'update_existing' => FEEDS_UPDATE_EXISTING,
));
// And import again. Two nodes should be updated.
$this->drupalPost('import/syndication', array(), 'Import');
$this->assertText('Updated 2 nodes.');
// Change "insert_new" setting to insert new items to verify if changing the
// setting later has the effect that new items will be imported as yet.
$this->setSettings('syndication', 'FeedsNodeProcessor', array(
'insert_new' => FEEDS_INSERT_NEW,
));
// Import. Eight nodes should be created. No nodes should be updated.
$this->drupalPost('import/syndication', array(), 'Import');
$this->assertText('Created 8 nodes.');
$this->assertNoText('Updated 2 nodes.');
}
megachriz
committed
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
/**
* Tests if the target "changed" works as expected.
*/
public function testChangedTarget() {
// Create and configure importer.
$this->createImporterConfiguration('Content CSV', 'csv');
$this->setSettings('csv', NULL, array('content_type' => '', 'import_period' => FEEDS_SCHEDULE_NEVER));
$this->setPlugin('csv', 'FeedsFileFetcher');
$this->setPlugin('csv', 'FeedsCSVParser');
$this->addMappings('csv', array(
0 => array(
'source' => 'title',
'target' => 'title',
),
// Borrow the timestamp value from the "created" column in the csv.
1 => array(
'source' => 'created',
'target' => 'changed',
),
));
// Import CSV file.
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
$this->assertText('Created 2 nodes');
// Assert changed date of nodes.
$expected_values = array(
1 => array(
'changed' => 1251936720,
),
2 => array(
'changed' => 1251932360,
),
);
for ($i = 1; $i <= 2; $i++) {
$node = node_load($i);
$this->assertEqual($expected_values[$i]['changed'], $node->changed);
}
}
/**
* Tests the FeedsSource::pushImport() method.
*/
public function testPushImport() {
// Attach to standalone importer.
$this->setSettings('syndication', NULL, array('content_type' => ''));
$raw = file_get_contents(dirname(__FILE__) . '/feeds/developmentseed.rss2');
feeds_source('syndication', 0)->pushImport(new FeedsFetcherResult($raw));
$this->assertEqual(10, db_query("SELECT COUNT(*) FROM {node}")->fetchField());
}
grahamC
committed
/**
* Tests the FeedsSource::pushImport() method with a CSV file.
*/
public function testPushImportWithCSV() {
// Attach to standalone importer and configure.
$this->setSettings('syndication', NULL, array('content_type' => ''));
$this->setPlugin('syndication', 'FeedsCSVParser');
$this->removeMappings('syndication', $this->getCurrentMappings('syndication'));
$this->addMappings('syndication', array(
0 => array(
'source' => 'title',
'target' => 'title',
),
));
$raw = file_get_contents($this->absolutePath() . '/tests/feeds/many_nodes.csv');
feeds_source('syndication', 0)->pushImport(new FeedsFetcherResult($raw));
$this->assertEqual(86, db_query("SELECT COUNT(*) FROM {node}")->fetchField());
}
mikran
committed
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
/**
* Tests if target item is not updated when only non-mapped data on the source changed.
*/
public function testIrrelevantUpdate() {
// Include FeedsProcessor.inc so processor related constants are available.
module_load_include('inc', 'feeds', 'plugins/FeedsProcessor');
// Attach to standalone importer and configure.
$this->setSettings('syndication', NULL, array('content_type' => ''));
$this->setPlugin('syndication', 'FeedsFileFetcher');
$this->setPlugin('syndication', 'FeedsCSVParser');
$this->removeMappings('syndication', $this->getCurrentMappings('syndication'));
$this->addMappings('syndication', array(
0 => array(
'source' => 'name',
'target' => 'title',
'unique' => TRUE,
),
));
// Import file.
$this->importFile('syndication', $this->absolutePath() . '/tests/feeds/users.csv');
$this->assertText('Created 5 nodes');
// Ensure that no nodes are updated when only non-mapped columns changed.
$this->setSettings('syndication', 'FeedsNodeProcessor', array(
'skip_hash_check' => FALSE,
'update_existing' => FEEDS_UPDATE_EXISTING,
));
$this->importFile('syndication', $this->absolutePath() . '/tests/feeds/users_updated.csv');
$this->assertText('There are no new nodes.');
}