--- feeds/tests/feeds.test.orig 2010-07-28 23:13:03.000000000 +0300 +++ feeds/tests/feeds.test 2010-07-29 14:13:38.000000000 +0300 @@ -390,6 +390,167 @@ class FeedsRSStoNodesTest extends FeedsW } /** + * Test aggregating a feed as node items. + */ +class FeedsRSStoNodesWithInheritanceTest extends FeedsWebTestCase { + + /** + * Describe this test. + */ + public function getInfo() { + return array( + 'name' => t('RSS import to nodes with inheritance '), + 'description' => t('Tests a feed configuration that is attached to a content type, uses HTTP fetcher, common syndication parser and a node processor with inheritance. Requires og and location modules.'), + 'group' => t('Feeds'), + ); + } + + /** + * Set up test. + */ + public function setUp() { + parent::setUp('feeds', 'feeds_ui', 'ctools', 'og', 'locale', 'taxonomy', 'location'); + $this->drupalLogin( + $this->drupalCreateUser( + array( + 'administer feeds', 'administer nodes', 'administer content types', + ) + ) + ); + } + + /** + * Test node creation, refreshing/deleting feeds and feed items. + */ + public function test() { + // Set the teaser length to unlimited otherwise tests looking for text on + // nodes will fail. + $edit = array( + 'teaser_length' => 0, + ); + $this->drupalPost('admin/content/node-settings', $edit, 'Save configuration'); + + // Configure our processor + $this->setSettings('syndication', 'FeedsNodeProcessor', array( + 'inherit[og]' => 'og', + 'inherit[user]' => 'user', + 'inherit[taxonomy]' => 'taxonomy', + 'inherit[locale]' => 'locale', + 'inherit[location]' => 'location', + )); + + // Create a feed. + $this->createFeedConfiguration('Syndication', 'syndication'); + $this->addMappings('syndication', + array( + array( + 'source' => 'title', + 'target' => 'title', + 'unique' => FALSE, + ), + array( + 'source' => 'description', + 'target' => 'body', + 'unique' => FALSE, + ), + array( + 'source' => 'timestamp', + 'target' => 'created', + 'unique' => FALSE, + ), + array( + 'source' => 'url', + 'target' => 'url', + 'unique' => TRUE, + ), + array( + 'source' => 'guid', + 'target' => 'guid', + 'unique' => TRUE, + ), + ) + ); + + // Set original values for inheritance on the feed + // organic groups (feeds_inherit_og) + // TODO + + // locale (feeds_inherit_translation) + // TODO + + // taxonomy (feeds_inherit_taxonomy) + // TODO + + // location (feeds_inherit_location) + // TODO + + // author (feeds_inherit_user) + $edit['uid'] = 1; + + + // Create the feed node + $feed_node_nid = $this->createCustomFeedNode('syndication', NULL, '', NULL, $edit); + $feed_node = node_load($feed_node_nid); + + + // Load one of the newly created nodes to test for our settings + $feed_item_node_nid = db_result(db_query("SELECT MAX(nid) FROM {feeds_node_item} WHERE feed_nid=%d", $feed_node_nid)); + $feed_item_node = node_load($feed_item_node_nid); + + + // Test organic groups (feeds_inherit_og) + // TODO + + // Test locale (feeds_inherit_translation) + // TODO + + // Test taxonomy (feeds_inherit_taxonomy) + // TODO + + // Test location (feeds_inherit_location) + // TODO + + // Test author (feeds_inherit_user) + $this->assertEqual($feed_node->uid, $feed_item_node->uid, 'Author inherited correctly.'); + } + + /** + * Create a test feed node. + * + * Assumes that page content type has been configured with createFeedConfiguration() + * as a feed content type. + * + * @return + * The node id of the node created. + */ + public function createCustomFeedNode($id = 'syndication', $feed_url = NULL, $title = '', $content_type = NULL, $edit = array()) { + if (empty($feed_url)) { + $feed_url = $GLOBALS['base_url'] .'/'. drupal_get_path('module', 'feeds') .'/tests/feeds/developmentseed.rss2'; + } + // If content type not given, retrieve it. + if (!$content_type) { + $config = unserialize(db_result(db_query("SELECT config FROM {feeds_importer} WHERE id = '%s'", $id))); + $content_type = $config['content_type']; + $this->assertFalse(empty($content_type), 'Valid content type found: '. $content_type); + } + + // Create a feed node. + $edit['title'] = $title; + $edit['feeds[FeedsHTTPFetcher][source]'] = $feed_url; + $this->drupalPost('node/add/'. str_replace('_', '-', $content_type), $edit, 'Save'); + $this->assertText('has been created.'); + + // Get the node id from URL. + $url = $this->getUrl(); + $matches = array(); + preg_match('/node\/(\d+?)$/', $this->getUrl(), $matches); + $nid = $matches[1]; + + return $nid; + } +} + +/** * Test aggregating a feed as data records. */ class FeedsRSStoDataTest extends FeedsWebTestCase {