[177a560] | 1 | <?php |
---|
| 2 | module_load_include('test', 'feeds', 'tests/feeds'); |
---|
| 3 | |
---|
| 4 | /** |
---|
| 5 | * @file |
---|
| 6 | * Tests for plugins/FeedsDataProcessor.inc. |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /** |
---|
| 10 | * Test aggregating a feed as data records. |
---|
| 11 | */ |
---|
| 12 | class FeedsRSStoDataTest extends FeedsWebTestCase { |
---|
| 13 | public static function getInfo() { |
---|
| 14 | return array( |
---|
| 15 | 'name' => 'RSS import to data records', |
---|
| 16 | 'description' => 'Tests a feed configuration that is attached to a content type, uses common syndication parser and a node processor.', |
---|
| 17 | 'group' => 'Feeds', |
---|
| 18 | 'dependencies' => array('data', 'views'), |
---|
| 19 | ); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | public function setUp() { |
---|
| 23 | parent::setUp(array('data', 'data_ui', 'views')); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | /** |
---|
| 27 | * Test node creation, refreshing/deleting feeds and feed items. |
---|
| 28 | */ |
---|
| 29 | public function test() { |
---|
| 30 | |
---|
| 31 | // Create an importer. |
---|
| 32 | $this->createImporterConfiguration('Data feed', 'rss'); |
---|
| 33 | |
---|
| 34 | // Go to edit page and select the data processor. |
---|
| 35 | $edit = array( |
---|
| 36 | 'plugin_key' => 'FeedsDataProcessor', |
---|
| 37 | ); |
---|
| 38 | $this->drupalPost('admin/build/feeds/edit/rss/processor', $edit, 'Save'); |
---|
| 39 | $this->assertPlugins('rss', 'FeedsHTTPFetcher', 'FeedsSyndicationParser', 'FeedsDataProcessor'); |
---|
| 40 | |
---|
| 41 | // Go to mapping page and create a couple of mappings. |
---|
| 42 | $mappings = array( |
---|
| 43 | array( |
---|
| 44 | 'source' => 'guid', |
---|
| 45 | 'target' => 'new:text', |
---|
| 46 | 'unique' => TRUE, |
---|
| 47 | ), |
---|
| 48 | array( |
---|
| 49 | 'source' => 'url', |
---|
| 50 | 'target' => 'new:text', |
---|
| 51 | 'unique' => TRUE, |
---|
| 52 | ), |
---|
| 53 | array( |
---|
| 54 | 'source' => 'timestamp', |
---|
| 55 | 'target' => 'timestamp', // timestamp is an existing target. |
---|
| 56 | 'unique' => FALSE, |
---|
| 57 | ), |
---|
| 58 | array( |
---|
| 59 | 'source' => 'title', |
---|
| 60 | 'target' => 'new:varchar', |
---|
| 61 | 'unique' => FALSE, |
---|
| 62 | ), |
---|
| 63 | array( |
---|
| 64 | 'source' => 'description', |
---|
| 65 | 'target' => 'new:text', |
---|
| 66 | 'unique' => FALSE, |
---|
| 67 | ), |
---|
| 68 | ); |
---|
| 69 | $this->addMappings('rss', $mappings); |
---|
| 70 | |
---|
| 71 | // Verify the mapping configuration. |
---|
| 72 | $config = unserialize(db_result(db_query("SELECT config FROM {feeds_importer} WHERE id = 'rss'"))); |
---|
| 73 | $stored_mappings = $config['processor']['config']['mappings']; |
---|
| 74 | foreach ($mappings as $i => $mapping) { |
---|
| 75 | $this->assertEqual($mapping['source'], $stored_mappings[$i]['source']); |
---|
| 76 | // This is intentional: the target of the stored mapping should have the |
---|
| 77 | // same key as the source, this has to do with the fact that feeds data |
---|
| 78 | // creates storage as the mapping is created. |
---|
| 79 | $this->assertEqual($mapping['source'], $stored_mappings[$i]['target']); |
---|
| 80 | $this->assertEqual($mapping['unique'], $stored_mappings[$i]['unique']); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | // Create standard feed node. |
---|
| 84 | $nid = $this->createFeedNode('rss'); |
---|
| 85 | // Assert 10 items aggregated after creation of the node. |
---|
| 86 | $this->assertText('Created 10 items.'); |
---|
| 87 | |
---|
| 88 | // Login with a user with administer data permissions and review aggregated |
---|
| 89 | // content. |
---|
| 90 | $this->drupalLogin( |
---|
| 91 | $this->drupalCreateUser( |
---|
| 92 | array( |
---|
| 93 | 'administer data tables', |
---|
| 94 | 'administer feeds', |
---|
| 95 | 'administer nodes', |
---|
| 96 | ) |
---|
| 97 | ) |
---|
| 98 | ); |
---|
| 99 | |
---|
| 100 | // Assert accuracy of aggregated information. |
---|
| 101 | $this->drupalGet('admin/content/data/view/feeds_data_rss'); |
---|
| 102 | $this->assertText('Open Atrium Translation Workflow: Two Way Translation Updates'); |
---|
| 103 | $this->assertText('A new translation process for Open Atrium & integration with Localize Drupal'); |
---|
| 104 | $this->assertText('Week in DC Tech: October 5th Edition'); |
---|
| 105 | $this->assertText('There are some great technology events happening this week'); |
---|
| 106 | $this->assertText('Mapping Innovation at the World Bank with Open Atrium'); |
---|
| 107 | $this->assertText('is being used as a base platform for collaboration at the World Bank because of its feature flexibility'); |
---|
| 108 | $this->assertText('September GeoDC Meetup Tonight'); |
---|
| 109 | $this->assertText('Today is the last Wednesday of the month'); |
---|
| 110 | $this->assertText('Week in DC Tech: September 28th Edition'); |
---|
| 111 | $this->assertText('Looking to geek out this week? There are a bunch of'); |
---|
| 112 | $this->assertText('Open Data for Microfinance: The New MIXMarket.org'); |
---|
| 113 | $this->assertText('There are profiles for every country that the MIX Market is hosting.'); |
---|
| 114 | $this->assertText('Integrating the Siteminder Access System in an Open Atrium-based Intranet'); |
---|
| 115 | $this->assertText('In addition to authentication, the Siteminder system'); |
---|
| 116 | $this->assertText('Week in DC Tech: September 21 Edition'); |
---|
| 117 | $this->assertText('an interesting variety of technology events happening in Washington, DC '); |
---|
| 118 | $this->assertText('s Software Freedom Day: Impressions & Photos'); |
---|
| 119 | $this->assertText('Presenting on Features in Drupal and Open Atrium'); |
---|
| 120 | $this->assertText('Scaling the Open Atrium UI'); |
---|
| 121 | $this->assertText('The first major change is switching'); |
---|
| 122 | |
---|
| 123 | // Assert DB status. |
---|
| 124 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_data_rss}")); |
---|
| 125 | $this->assertEqual($count, 10, 'Accurate number of items in database.'); |
---|
| 126 | |
---|
| 127 | // Import again. |
---|
| 128 | $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); |
---|
| 129 | $this->assertText('There are no new items.'); |
---|
| 130 | |
---|
| 131 | // Assert DB status, there still shouldn't be more than 10 items. |
---|
| 132 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_data_rss}")); |
---|
| 133 | $this->assertEqual($count, 10, 'Accurate number of items in database.'); |
---|
| 134 | |
---|
| 135 | // Now delete all items. |
---|
| 136 | $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete'); |
---|
| 137 | $this->assertText('All items have been deleted.'); |
---|
| 138 | |
---|
| 139 | // Assert DB status, now there should be no items. |
---|
| 140 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_data_rss}")); |
---|
| 141 | $this->assertEqual($count, 0, 'Accurate number of items in database.'); |
---|
| 142 | |
---|
| 143 | // Import again, we should find new content. |
---|
| 144 | $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); |
---|
| 145 | $this->assertText('Created 10 items.'); |
---|
| 146 | |
---|
| 147 | // Assert DB status, there should be 10 again. |
---|
| 148 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_data_rss}")); |
---|
| 149 | $this->assertEqual($count, 10, 'Accurate number of items in database.'); |
---|
| 150 | |
---|
| 151 | // Test 'Delete items with source' setting. |
---|
| 152 | $this->setSettings('rss', 'FeedsDataProcessor', array('delete_with_source' => 1)); |
---|
| 153 | $this->drupalPost('node/'. $nid .'/delete', array(), 'Delete'); |
---|
| 154 | $this->assertText('Page Development Seed - Technological Solutions for Progressive Organizations has been deleted.'); |
---|
| 155 | |
---|
| 156 | // Assert DB status. |
---|
| 157 | $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_data_rss}")); |
---|
| 158 | $this->assertEqual($count, 0, 'Accurate number of items in database.'); |
---|
| 159 | |
---|
| 160 | // @todo Standalone import form testing. |
---|
| 161 | // @todo Create a second feed and test. |
---|
| 162 | } |
---|
| 163 | } |
---|