diff --git a/feeds_defaults/feeds_defaults.defaults.inc b/feeds_defaults/feeds_defaults.defaults.inc new file mode 100644 index 0000000000000000000000000000000000000000..c184114402109a4567e0599bebcdd37a7ae820d1 --- /dev/null +++ b/feeds_defaults/feeds_defaults.defaults.inc @@ -0,0 +1,430 @@ +<?php +// $Id$ + +/** + * @file + * Actual function bodies for default hook definitions in + * feeds_defaults.features.inc. + */ + +/** + * Helper to implementation of hook_ctools_plugin_api(). + */ +function _feeds_defaults_ctools_plugin_api() { + $args = func_get_args(); + $module = array_shift($args); + $api = array_shift($args); + if ($module == "data" && $api == "data_default") { + return array("version" => 1); + } + else if ($module == "feeds" && $api == "feeds_importer_default") { + return array("version" => 1); + } +} + +/** + * Helper to implementation of hook_data_default(). + */ +function _feeds_defaults_data_default() { + $export = array(); + $data_table = new stdClass; + $data_table->disabled = FALSE; /* Edit this to true to make a default data_table disabled initially */ + $data_table->api_version = 1; + $data_table->title = 'Fast feed'; + $data_table->name = 'feeds_data_feed_fast'; + $data_table->table_schema = array( + 'fields' => array( + 'feed_nid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'id' => array( + 'type' => 'serial', + 'size' => 'normal', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'timestamp' => array( + 'description' => 'The Unix timestamp for the data.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => FALSE, + ), + 'title' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + ), + 'description' => array( + 'type' => 'text', + 'not null' => FALSE, + ), + 'url' => array( + 'type' => 'text', + 'not null' => FALSE, + ), + 'guid' => array( + 'type' => 'text', + 'not null' => FALSE, + ), + ), + 'indexes' => array( + 'feed_nid' => array( + '0' => 'feed_nid', + ), + 'id' => array( + '0' => 'id', + ), + 'timestamp' => array( + '0' => 'timestamp', + ), + 'url' => array( + '0' => array( + '0' => 'url', + '1' => 255, + ), + ), + 'guid' => array( + '0' => array( + '0' => 'guid', + '1' => 255, + ), + ), + ), + 'primary key' => array( + '0' => 'id', + ), + ); + $data_table->meta = array( + 'fields' => array( + 'feed_nid' => array( + 'label' => '', + 'views_field_handler' => 'views_handler_field_numeric', + 'views_filter_handler' => 'views_handler_filter_numeric', + 'views_argument_handler' => 'views_handler_argument_numeric', + 'views_sort_handler' => 'views_handler_sort', + ), + 'id' => array( + 'label' => '', + 'views_field_handler' => 'views_handler_field_numeric', + 'views_filter_handler' => 'views_handler_filter_numeric', + 'views_argument_handler' => 'views_handler_argument_numeric', + 'views_sort_handler' => 'views_handler_sort', + ), + 'timestamp' => array( + 'label' => '', + 'views_field_handler' => 'views_handler_field_date', + 'views_filter_handler' => 'views_handler_filter_date', + 'views_argument_handler' => 'views_handler_argument_date', + 'views_sort_handler' => 'views_handler_sort_date', + ), + 'title' => array( + 'label' => '', + 'views_field_handler' => 'views_handler_field', + 'views_filter_handler' => 'views_handler_filter_string', + 'views_argument_handler' => 'views_handler_argument_string', + 'views_sort_handler' => 'views_handler_sort', + ), + 'description' => array( + 'label' => '', + 'views_field_handler' => 'views_handler_field', + 'views_filter_handler' => 'views_handler_filter_string', + 'views_argument_handler' => 'views_handler_argument', + 'views_sort_handler' => 'views_handler_sort', + ), + 'url' => array( + 'label' => '', + 'views_field_handler' => 'views_handler_field_url', + 'views_filter_handler' => 'views_handler_filter_string', + 'views_argument_handler' => 'views_handler_argument', + 'views_sort_handler' => 'views_handler_sort', + ), + 'guid' => array( + 'label' => '', + 'views_field_handler' => 'views_handler_field', + 'views_filter_handler' => 'views_handler_filter_string', + 'views_argument_handler' => 'views_handler_argument', + 'views_sort_handler' => 'views_handler_sort', + ), + ), + ); + + $export['feeds_data_feed_fast'] = $data_table; + return $export; +} + +/** + * Helper to implementation of hook_feeds_importer_default(). + */ +function _feeds_defaults_feeds_importer_default() { + $export = array(); + $feeds_importer = new stdClass; + $feeds_importer->disabled = TRUE; /* Edit this to true to make a default feeds_importer disabled initially */ + $feeds_importer->api_version = 1; + $feeds_importer->id = 'feed'; + $feeds_importer->config = array( + 'name' => 'Feed', + 'description' => 'Import RSS or Atom feeds.', + 'fetcher' => array( + 'plugin_key' => 'FeedsHTTPFetcher', + 'config' => array( + 'auto_detect_feeds' => FALSE, + ), + ), + 'parser' => array( + 'plugin_key' => 'FeedsSyndicationParser', + 'config' => array(), + ), + 'processor' => array( + 'plugin_key' => 'FeedsNodeProcessor', + 'config' => array( + 'content_type' => 'feed_item', + 'update_existing' => 0, + 'expire' => '-1', + 'mappings' => array( + '0' => array( + 'source' => 'title', + 'target' => 'title', + 'unique' => FALSE, + ), + '1' => array( + 'source' => 'description', + 'target' => 'body', + 'unique' => FALSE, + ), + '2' => array( + 'source' => 'timestamp', + 'target' => 'created', + 'unique' => FALSE, + ), + '3' => array( + 'source' => 'url', + 'target' => 'url', + 'unique' => TRUE, + ), + '4' => array( + 'source' => 'guid', + 'target' => 'guid', + 'unique' => TRUE, + ), + ), + ), + ), + 'content_type' => 'feed', + 'update' => 0, + 'import_period' => '1800', + 'expire_period' => 3600, + 'import_on_create' => 1, + ); + + $export['feed'] = $feeds_importer; + + // Expose a default configuration for Data if enabled. + if (module_exists('data')) { + + $feeds_importer = new stdClass; + $feeds_importer->disabled = TRUE; /* Edit this to true to make a default feeds_importer disabled initially */ + $feeds_importer->api_version = 1; + $feeds_importer->id = 'feed_fast'; + $feeds_importer->config = array( + 'name' => 'Fast feed', + 'description' => 'Creates light weight database records from feed items. Faster than aggregating nodes.', + 'fetcher' => array( + 'plugin_key' => 'FeedsHTTPFetcher', + 'config' => array( + 'auto_detect_feeds' => FALSE, + ), + ), + 'parser' => array( + 'plugin_key' => 'FeedsSyndicationParser', + 'config' => array(), + ), + 'processor' => array( + 'plugin_key' => 'FeedsDataProcessor', + 'config' => array( + 'update_existing' => 0, + 'expire' => '7257600', + 'mappings' => array( + '0' => array( + 'source' => 'title', + 'target' => 'title', + 'unique' => 0, + ), + '1' => array( + 'source' => 'description', + 'target' => 'description', + 'unique' => 0, + ), + '2' => array( + 'source' => 'url', + 'target' => 'url', + 'unique' => 1, + ), + '3' => array( + 'source' => 'guid', + 'target' => 'guid', + 'unique' => 1, + ), + ), + ), + ), + 'content_type' => 'feed_fast', + 'update' => 0, + 'import_period' => '1800', + 'expire_period' => 3600, + 'import_on_create' => 1, + ); + + $export['feed_fast'] = $feeds_importer; + } + + $feeds_importer = new stdClass; + $feeds_importer->disabled = TRUE; /* Edit this to true to make a default feeds_importer disabled initially */ + $feeds_importer->api_version = 1; + $feeds_importer->id = 'node'; + $feeds_importer->config = array( + 'name' => 'Node import', + 'description' => 'Imports nodes from CSV file.', + 'fetcher' => array( + 'plugin_key' => 'FeedsFileFetcher', + 'config' => array(), + ), + 'parser' => array( + 'plugin_key' => 'FeedsCSVParser', + 'config' => array( + 'delimiter' => ',', + ), + ), + 'processor' => array( + 'plugin_key' => 'FeedsNodeProcessor', + 'config' => array( + 'content_type' => 'story', + 'update_existing' => 1, + 'expire' => '-1', + 'mappings' => array( + '0' => array( + 'source' => 'title', + 'target' => 'title', + 'unique' => FALSE, + ), + '1' => array( + 'source' => 'body', + 'target' => 'body', + 'unique' => FALSE, + ), + '2' => array( + 'source' => 'published', + 'target' => 'created', + 'unique' => FALSE, + ), + '3' => array( + 'source' => 'guid', + 'target' => 'guid', + 'unique' => 1, + ), + ), + ), + ), + 'content_type' => '', + 'update' => 0, + 'import_period' => '-1', + 'expire_period' => 3600, + 'import_on_create' => 1, + ); + + $export['node'] = $feeds_importer; + $feeds_importer = new stdClass; + $feeds_importer->disabled = TRUE; /* Edit this to true to make a default feeds_importer disabled initially */ + $feeds_importer->api_version = 1; + $feeds_importer->id = 'opml'; + $feeds_importer->config = array( + 'name' => 'OPML import', + 'description' => 'Import subscriptions from OPML files. Use with together with "Feed" configuration.', + 'fetcher' => array( + 'plugin_key' => 'FeedsFileFetcher', + 'config' => array(), + ), + 'parser' => array( + 'plugin_key' => 'FeedsOPMLParser', + 'config' => array(), + ), + 'processor' => array( + 'plugin_key' => 'FeedsFeedNodeProcessor', + 'config' => array( + 'content_type' => 'feed', + 'update_existing' => 0, + 'mappings' => array( + '0' => array( + 'source' => 'title', + 'target' => 'title', + 'unique' => FALSE, + ), + '1' => array( + 'source' => 'xmlurl', + 'target' => 'source', + 'unique' => 1, + ), + ), + ), + ), + 'content_type' => '', + 'update' => 0, + 'import_period' => '-1', + 'expire_period' => 3600, + 'import_on_create' => 1, + ); + + $export['opml'] = $feeds_importer; + $feeds_importer = new stdClass; + $feeds_importer->disabled = TRUE; /* Edit this to true to make a default feeds_importer disabled initially */ + $feeds_importer->api_version = 1; + $feeds_importer->id = 'user'; + $feeds_importer->config = array( + 'name' => 'User import', + 'description' => 'Import users from CSV file.', + 'fetcher' => array( + 'plugin_key' => 'FeedsFileFetcher', + 'config' => array(), + ), + 'parser' => array( + 'plugin_key' => 'FeedsCSVParser', + 'config' => array( + 'delimiter' => ',', + ), + ), + 'processor' => array( + 'plugin_key' => 'FeedsUserProcessor', + 'config' => array( + 'roles' => array(), + 'update_existing' => FALSE, + 'status' => 1, + 'mappings' => array( + '0' => array( + 'source' => 'name', + 'target' => 'name', + 'unique' => 0, + ), + '1' => array( + 'source' => 'mail', + 'target' => 'mail', + 'unique' => 1, + ), + '2' => array( + 'source' => 'created', + 'target' => 'created', + 'unique' => FALSE, + ), + ), + ), + ), + 'content_type' => '', + 'update' => 0, + 'import_period' => '-1', + 'expire_period' => 3600, + 'import_on_create' => 1, + ); + + $export['user'] = $feeds_importer; + return $export; +} diff --git a/feeds_defaults/feeds_defaults.features.inc b/feeds_defaults/feeds_defaults.features.inc new file mode 100644 index 0000000000000000000000000000000000000000..2247f14f7f44a2fa8680675af18796b5fae86946 --- /dev/null +++ b/feeds_defaults/feeds_defaults.features.inc @@ -0,0 +1,35 @@ +<?php +// $Id$ + +/** + * @file + * Default hook definitions. This code is generated with Features module but it + * has been tweaked manually. Do not attempt to reexport. + */ + +/** + * Implementation of hook_ctools_plugin_api(). + */ +function feeds_defaults_ctools_plugin_api() { + module_load_include('inc', 'feeds_defaults', 'feeds_defaults.defaults'); + $args = func_get_args(); + return call_user_func_array('_feeds_defaults_ctools_plugin_api', $args); +} + +/** + * Implementation of hook_data_default(). + */ +function feeds_defaults_data_default() { + module_load_include('inc', 'feeds_defaults', 'feeds_defaults.defaults'); + $args = func_get_args(); + return call_user_func_array('_feeds_defaults_data_default', $args); +} + +/** + * Implementation of hook_feeds_importer_default(). + */ +function feeds_defaults_feeds_importer_default() { + module_load_include('inc', 'feeds_defaults', 'feeds_defaults.defaults'); + $args = func_get_args(); + return call_user_func_array('_feeds_defaults_feeds_importer_default', $args); +} diff --git a/feeds_defaults/feeds_defaults.info b/feeds_defaults/feeds_defaults.info new file mode 100644 index 0000000000000000000000000000000000000000..7f66e8ccd67b49b2d68b767dada421fa665f71dd --- /dev/null +++ b/feeds_defaults/feeds_defaults.info @@ -0,0 +1,7 @@ +; $Id$ +core = "6.x" +name = "Feeds defaults" +package = "Feeds" +description = "Get started: useful default configurations for Feeds: RSS/Atom aggregation, OPML import, node import and user import." +project = "Feeds" +dependencies[] = "feeds" \ No newline at end of file diff --git a/feeds_defaults/feeds_defaults.install b/feeds_defaults/feeds_defaults.install new file mode 100644 index 0000000000000000000000000000000000000000..d72e75d657bef90d9010832b7a43ab14da84209f --- /dev/null +++ b/feeds_defaults/feeds_defaults.install @@ -0,0 +1,36 @@ +<?php +// $Id$ + +/** + * @file + * Install hooks. + */ + +/** + * Implementation of hook_schema(). + */ +function feeds_defaults_schema() { + // Install data tables. + include_once('feeds_defaults.features.inc'); + $tables = feeds_defaults_data_default(); + $schema = array(); + foreach ($tables as $name => $table) { + $schema[$name] = $table->table_schema; + } + return $schema; +} + +/** + * Implementation of hook_install(). + */ +function feeds_defaults_install() { + drupal_install_schema('feeds_defaults'); +} + +/** + * Implementation of hook_uninstall(); + */ +function feeds_defaults_uninstall() { + drupal_uninstall_schema('feeds_defaults'); +} + diff --git a/feeds_defaults/feeds_defaults.module b/feeds_defaults/feeds_defaults.module new file mode 100644 index 0000000000000000000000000000000000000000..e1d458809da5ff939948f02ce3745dd1cf6045a7 --- /dev/null +++ b/feeds_defaults/feeds_defaults.module @@ -0,0 +1,51 @@ +<?php +// $Id$ + +/** + * @file + * Default importer configurations for Feeds module. + */ + +include(dirname(__FILE__) .'/feeds_defaults.features.inc'); + +/** + * Implementation of hook_node_info(). + */ +function feeds_defaults_node_info() { + $items = array(); + if (feeds_importer_enabled('feed')) { + $items['feed'] = array( + 'name' => t('Feed'), + 'module' => 'node', + 'description' => t('Subscribe to RSS or Atom feeds. Creates nodes of the content type "Feed item" from feed content.'), + 'has_title' => '1', + 'title_label' => t('Title'), + 'has_body' => '1', + 'body_label' => t('Body'), + 'locked' => TRUE, + ); + $items['feed_item'] = array( + 'name' => t('Feed item'), + 'module' => 'node', + 'description' => t('This content type is being used for automatically aggregated content from feeds.'), + 'has_title' => '1', + 'title_label' => t('Title'), + 'has_body' => '1', + 'body_label' => t('Body'), + 'locked' => TRUE, + ); + } + if (feeds_importer_enabled('feed_fast')) { + $items['feed_fast'] = array( + 'name' => t('Fast feed'), + 'module' => 'node', + 'description' => t('Subscribe to RSS or Atom feeds. Create light weight database records from feed content.'), + 'has_title' => '1', + 'title_label' => t('Title'), + 'has_body' => '1', + 'body_label' => t('Body'), + 'locked' => TRUE, + ); + } + return $items; +} diff --git a/feeds_defaults/tests/feeds_defaults.test b/feeds_defaults/tests/feeds_defaults.test new file mode 100644 index 0000000000000000000000000000000000000000..914c43e2f21aa1b50da74a7a8abfa4a27ee1901a --- /dev/null +++ b/feeds_defaults/tests/feeds_defaults.test @@ -0,0 +1,445 @@ +<?php +// $Id$ + +/** + * @file + * Tests for default configurations. + */ + +// Require FeedsWebTestCase class definition. +require_once(dirname(__FILE__) .'/../../tests/feeds.test.inc'); + +/** + * Base class for default tests. + */ +class FeedsDefaultsTestCase extends FeedsWebTestCase { + + /** + * Enable a default configuration and verify it. + */ + public function enable($ids) { + if (is_string($ids)) { + $ids = array($ids); + } + $edit = array(); + foreach ($ids as $id) { + $edit[$id] = TRUE; + } + $this->drupalPost('admin/build/feeds', $edit, 'Save'); + foreach ($ids as $id) { + $this->assertRaw('admin/build/feeds/edit/'. $id .'">Override', 'Enabled '. $id); + } + } + + /** + * Disable a default configuration and verify it. + */ + public function disable($ids) { + if (is_string($ids)) { + $ids = array($ids); + } + $edit = array(); + foreach ($ids as $id) { + $edit[$id] = FALSE; + } + $this->drupalPost('admin/build/feeds', $edit, 'Save'); + foreach ($ids as $id) { + $this->assertNoRaw('admin/build/feeds/edit/'. $id .'">Override', 'Disabled '. $id); + } + } +} + +/** + * Test Feed configuration. + */ +class FeedsDefaultsFeedTestCase extends FeedsDefaultsTestCase { + + /** + * Set up test. + */ + public function setUp() { + parent::setUp('feeds', 'feeds_ui', 'ctools', 'feeds_defaults'); + + $this->drupalLogin( + $this->drupalCreateUser( + array( + 'administer feeds', 'administer nodes', + ) + ) + ); + } + + /** + * Describe this test. + */ + public function getInfo() { + return array( + 'name' => t('Defaults: Feed'), + 'description' => t('Test "Feed" default configuration.'), + 'group' => t('Feeds'), + ); + } + + /** + * Run tests. + */ + public function test() { + $this->enable('feed'); + $nid = $this->createFeedNode('feed', NULL, '', 'feed'); + + // Assert results. + $count = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE type = "feed_item"')); + $this->assertEqual($count, 10, 'Found the correct number of feed item nodes in database.'); + + $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item}')); + $this->assertEqual($count, 10, 'Found the correct number of records in feeds_node_item.'); + + $count = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE title = "Open Atrium Translation Workflow: Two Way Translation Updates"')); + $this->assertEqual($count, 1, 'Found title.'); + $count = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE title = "Week in DC Tech: October 5th Edition"')); + $this->assertEqual($count, 1, 'Found title.'); + $count = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE title = "Integrating the Siteminder Access System in an Open Atrium-based Intranet"')); + $this->assertEqual($count, 1, 'Found title.'); + $count = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE title = "Scaling the Open Atrium UI"')); + $this->assertEqual($count, 1, 'Found title.'); + + $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item} WHERE url = "http://developmentseed.org/blog/2009/oct/06/open-atrium-translation-workflow-two-way-updating"')); + $this->assertEqual($count, 1, 'Found feed_node_item record.'); + $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item} WHERE url = "http://developmentseed.org/blog/2009/oct/05/week-dc-tech-october-5th-edition"')); + $this->assertEqual($count, 1, 'Found feed_node_item record.'); + $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item} WHERE guid = "974 at http://developmentseed.org"')); + $this->assertEqual($count, 1, 'Found feed_node_item record.'); + $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item} WHERE guid = "970 at http://developmentseed.org"')); + $this->assertEqual($count, 1, 'Found feed_node_item record.'); + + // Remove all items + $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete'); + $this->assertText('Deleted 10 nodes.'); + + // Import again. + $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); + $this->assertText('Created 10 Feed item nodes.'); + + // Delete and assert all items gone. + $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete'); + + $count = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE type = "feed_item"')); + $this->assertEqual($count, 0, 'Found the correct number of feed item nodes in database.'); + + $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item}')); + $this->assertEqual($count, 0, 'Found the correct number of records in feeds_node_item.'); + + // Create a batch of nodes. + $this->createFeedNodes('feed', 10, 'feed'); + $count = db_result(db_query('SELECT COUNT(*) from {node} WHERE type = "feed_item"')); + $this->assertEqual($count, 100, 'Imported 100 nodes.'); + $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item}')); + $this->assertEqual($count, 100, 'Found 100 records in feeds_node_item.'); + + // Disable the configuration. + $this->disable('feed'); + $this->drupalGet('node/add'); + $this->assertNoRaw('node/add/feed'); + $this->assertNoText('node/add/feed-item'); + } +} + +/** + * Test Feed fast configuration. + */ +class FeedsDefaultsFastFeedTestCase extends FeedsDefaultsTestCase { + + /** + * Set up test. + */ + public function setUp() { + parent::setUp('feeds', 'feeds_ui', 'ctools', 'feeds_defaults', 'data', 'data_ui', 'views', 'views_ui'); + + $this->drupalLogin( + $this->drupalCreateUser( + array( + 'administer feeds', 'administer nodes', 'administer data tables', + ) + ) + ); + } + + /** + * Describe this test. + */ + public function getInfo() { + return array( + 'name' => t('Defaults: Fast feed'), + 'description' => t('Test "Fast feed" default configuration <strong>Requires Data and Views.</strong>.'), + 'group' => t('Feeds'), + ); + } + + /** + * Run tests. + */ + public function test() { + + // Enable configuration and assert status. + $this->enable('feed_fast'); + $this->drupalGet('admin/build/data'); + $this->assertText('feeds_data_feed_fast'); + $this->drupalGet('admin/content/data/view/feeds_data_feed_fast'); + $this->assertText('Fast feed'); + $this->assertText('There is no data in this table.'); + + // Create feed node. + $nid = $this->createFeedNode('feed_fast', NULL, '', 'feed_fast'); + $this->assertText('Created 10 items.'); + + // Verify presence of aggregated items. + $this->drupalGet('admin/content/data/view/feeds_data_feed_fast'); + $this->assertText('Open Atrium Translation Workflow: Two Way Translation Updates'); + $this->assertText('n a word, nothing. There has been a major improvement on this front. Now your translation'); + $this->assertLink('http://developmentseed.org/blog/2009/oct/06/open-atrium-translation-workflow-two-way-updating'); + + // Delete and re import. + $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete'); + $this->assertText('Deleted 10 items.'); + $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_data_feed_fast}')); + $this->assertEqual($count, 0, 'Found correct number of items.'); + + $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete'); + $this->assertText('Deleted 0 items.'); + $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_data_feed_fast}')); + $this->assertEqual($count, 0, 'Found correct number of items.'); + + $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); + $this->assertText('Created 10 items.'); + $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_data_feed_fast}')); + $this->assertEqual($count, 10, 'Found correct number of items.'); + + $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); + $this->assertText('There are no new items.'); + $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_data_feed_fast}')); + $this->assertEqual($count, 10, 'Found correct number of items.'); + + // Disable. + $this->disable('feed_fast'); + $this->drupalGet('node/add'); + $this->assertNoRaw('node/add/feed-fast'); + } +} + +/** + * Test Node import configuration. + */ +class FeedsDefaultsNodeTestCase extends FeedsDefaultsTestCase { + + /** + * Set up test. + */ + public function setUp() { + parent::setUp('feeds', 'feeds_ui', 'ctools', 'feeds_defaults'); + + $this->drupalLogin( + $this->drupalCreateUser( + array( + 'administer feeds', 'administer nodes', + ) + ) + ); + } + + /** + * Describe this test. + */ + public function getInfo() { + return array( + 'name' => t('Defaults: Node import'), + 'description' => t('Test "Node import" default configuration.'), + 'group' => t('Feeds'), + ); + } + + /** + * Run tests. + */ + public function test() { + $this->enable('node'); + + // Import file. + $this->importFile('node', $this->absolutePath() .'/tests/feeds/nodes.csv'); + + // Assert returning page. + $this->assertText('Created 8 Story nodes.'); + $this->assertText('Import CSV files with one or more of these columns: title, body, published, guid.'); + $this->assertText('Column guid is mandatory and considered unique: only one item per guid value will be created.'); + $this->assertRaw('feeds/nodes.csv'); + + // Assert created nodes. + $this->drupalGet('node'); + $this->assertText('Typi non habent'); + $this->assertText('Eodem modo typi'); + $this->assertText('Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.'); + $this->assertText('Lorem ipsum'); + $this->assertText('Ut wisi enim ad minim veniam'); + $this->assertText('1976'); + + // Click through to one node. + $this->clickLink('Lorem ipsum'); + $this->assertText('Lorem ipsum'); + $this->assertText('Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.'); + $this->assertText('Anonymous'); + + // Assert DB status as is and again after an additional import. + for ($i = 0; $i < 2; $i++) { + $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item}')); + $this->assertEqual($count, 8, 'Found correct number of items.'); + $count = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE type = "story" AND status = 1 AND uid = 0')); + $this->assertEqual($count, 8, 'Found correct number of items.'); + // Do not filter on type intentionally. There shouldn't be more than 8 nodes total. + $count = db_result(db_query('SELECT COUNT(*) FROM {node_revisions}')); + $this->assertEqual($count, 8, 'Found correct number of items.'); + + // Import again. There are updates to 9 nodes because two nodes in the + // import have the same guid. + $this->drupalPost('import/node/import', array(), 'Import'); + $this->assertText('Updated 9 Story nodes.'); + } + + // Remove all nodes. + $this->drupalPost('import/node/delete-items', array(), 'Delete'); + $this->assertText('Story Lorem ipsum has been deleted.'); + $this->assertText('Story Ut wisi enim ad minim veniam has been deleted.'); + $this->assertText('Story Duis autem vel eum iriure dolor has been deleted.'); + $this->assertText('Story Typi non habent has been deleted.'); + $this->assertText('Story Investigationes demonstraverunt has been deleted.'); + $this->assertText('Story Claritas est etiam has been deleted.'); + $this->assertText('Story Mirum est notare has been deleted.'); + $this->assertText('Story Eodem modo typi has been deleted.'); + $this->assertText('Deleted 8 nodes.'); + + // Import once again. + $this->drupalPost('import/node/import', array(), 'Import'); + $this->assertText('Created 8 Story nodes.'); + + // Disable. + $this->disable('node'); + + // Nodes should be still present. + $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item}')); + $this->assertEqual($count, 8, 'Found correct number of items.'); + $count = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE type = "story" AND status = 1 AND uid = 0')); + $this->assertEqual($count, 8, 'Found correct number of items.'); + // Do not filter on type intentionally. There shouldn't be more than 8 nodes total. + $count = db_result(db_query('SELECT COUNT(*) FROM {node_revisions}')); + $this->assertEqual($count, 8, 'Found correct number of items.'); + } +} + +/** + * Test OPML import configuration. + */ +class FeedsDefaultsOPMLTestCase extends FeedsDefaultsTestCase { + + /** + * Set up test. + */ + public function setUp() { + parent::setUp('feeds', 'feeds_ui', 'ctools', 'feeds_defaults'); + + $this->drupalLogin( + $this->drupalCreateUser( + array( + 'administer feeds', 'administer nodes', + ) + ) + ); + } + + /** + * Describe this test. + */ + public function getInfo() { + return array( + 'name' => t('Defaults: OPML import'), + 'description' => t('Test "OPML import" default configuration.'), + 'group' => t('Feeds'), + ); + } + + /** + * Run tests. + */ + public function test() { + $this->enable('feed'); + $this->enable('opml'); + + // Import OPML and assert. + $file = $this->generateOPML(); + $this->importFile('opml', $file); + $this->assertText('Created 3 feed nodes.'); + $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_source}')); + $this->assertEqual($count, 4, 'Found correct number of items.'); + + // Import a feed and then delete all items from it. + $this->drupalPost('node/1/import', array(), 'Import'); + $this->assertText('Created 10 Feed item nodes.'); + $this->drupalPost('node/1/delete-items', array(), 'Delete'); + $this->assertText('Deleted 10 nodes.'); + + // Disable. + $this->disable('feed'); + $this->disable('opml'); + } +} + +/** + * Test User import configuration. + */ +class FeedsDefaultsUserTestCase extends FeedsDefaultsTestCase { + + /** + * Set up test. + */ + public function setUp() { + parent::setUp('feeds', 'feeds_ui', 'ctools', 'feeds_defaults'); + + $this->drupalLogin( + $this->drupalCreateUser( + array( + 'administer feeds', 'administer users', + ) + ) + ); + } + + /** + * Describe this test. + */ + public function getInfo() { + return array( + 'name' => t('Defaults: User import'), + 'description' => t('Test "User import" default configuration.'), + 'group' => t('Feeds'), + ); + } + + /** + * Run tests. + */ + public function test() { + $this->enable('user'); + + // Import CSV file. + $this->importFile('user', $this->absolutePath() .'/tests/feeds/users.csv'); + + // Assert result. + $this->assertText('Created 4 users.'); + // 1 user has an invalid email address. + $this->assertText('There were 1 users that could not be imported because either their name or their email was empty or not valid. Check import data and mapping settings on User processor.'); + $this->drupalGet('admin/user/user'); + $this->assertText('Morticia'); + $this->assertText('Fester'); + $this->assertText('Gomez'); + $this->assertText('Pugsley'); + + $this->disable('user'); + } +} \ No newline at end of file