From a422008a416e2fb114d55aa8080a43bfe46f4ebf Mon Sep 17 00:00:00 2001 From: Alex Barth <alex_b@53995.no-reply.drupal.org> Date: Fri, 23 Oct 2009 22:38:20 +0000 Subject: [PATCH] Adjust and improve tests along with addition of Feeds defaults module. --- tests/feeds.test | 25 ++++++------- tests/feeds.test.inc | 84 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 85 insertions(+), 24 deletions(-) diff --git a/tests/feeds.test b/tests/feeds.test index 09cb24ba..12fa4745 100644 --- a/tests/feeds.test +++ b/tests/feeds.test @@ -52,7 +52,7 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase { $nid = $this->createFeedNode(); // Assert 10 items aggregated after creation of the node. - $this->assertText('Created 10 story nodes.'); + $this->assertText('Created 10 Story nodes.'); // Navigate to feed node, there should be Feeds tabs visible. @@ -121,7 +121,7 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase { // Import again, we should find new content. $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); - $this->assertText('Created 10 story nodes.'); + $this->assertText('Created 10 Story nodes.'); // Assert DB status, there should be 10 again. $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item}')); @@ -184,7 +184,7 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase { // Import, assert 10 items aggregated after creation of the node. $this->importURL('syndication_standalone'); - $this->assertText('Created 10 story nodes.'); + $this->assertText('Created 10 Story nodes.'); // Assert accuracy of aggregated information. $this->drupalGet('node'); @@ -241,7 +241,7 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase { // Import again, we should find new content. $this->drupalPost('import/syndication_standalone', array(), 'Import'); - $this->assertText('Created 10 story nodes.'); + $this->assertText('Created 10 Story nodes.'); // Assert DB status, there should be 10 again. $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item}')); @@ -350,7 +350,7 @@ class FeedsRSStoDataTest extends FeedsWebTestCase { // Create standard feed node. $nid = $this->createFeedNode('rss'); // Assert 10 items aggregated after creation of the node. - $this->assertText('Created 10 records in feeds_data_rss.'); + $this->assertText('Created 10 items.'); // Login with a user with administer data permissions and review aggregated // content. @@ -392,7 +392,7 @@ class FeedsRSStoDataTest extends FeedsWebTestCase { // Import again. $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); - $this->assertText('There are no new records.'); + $this->assertText('There are no new items.'); // Assert DB status, there still shouldn't be more than 10 items. $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_data_rss}')); @@ -400,7 +400,7 @@ class FeedsRSStoDataTest extends FeedsWebTestCase { // Now delete all items. $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete'); - $this->assertText('Deleted 10 records from feeds_data_rss.'); + $this->assertText('Deleted 10 items.'); // Assert DB status, now there should be no items. // @todo: fails, is there something cached? @@ -409,7 +409,7 @@ class FeedsRSStoDataTest extends FeedsWebTestCase { // Import again, we should find new content. $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); - $this->assertText('Created 10 records in feeds_data_rss.'); + $this->assertText('Created 10 items.'); // Assert DB status, there should be 10 again. $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_data_rss}')); @@ -492,12 +492,7 @@ class FeedsCSVtoUsersTest extends FeedsWebTestCase { $this->drupalPost('admin/build/feeds/edit/user_import/settings', $edit, 'Save'); // Import CSV file. - $file = dirname($GLOBALS['_SERVER']['SCRIPT_FILENAME']) .'/'. drupal_get_path('module', 'feeds') .'/tests/feeds/users.csv'; - $this->assertTrue(file_exists($file), 'Source file exists'); - $edit = array( - 'files[feeds]' => $file, - ); - $this->drupalPost('import/user_import', $edit, 'Import'); + $this->importFile('user_import', $this->absolutePath() .'/tests/feeds/users.csv'); // Assert result. $this->assertText('Created 4 users.'); @@ -691,7 +686,7 @@ class FeedsSyndicationParserTestCase extends FeedsWebTestCase { $this->setPlugin('syndication', $parser); foreach ($this->feedUrls() as $url => $assertions) { $this->createFeedNode('syndication', $url); - $this->assertText('Created '. $assertions['item_count'] .' story nodes.'); + $this->assertText('Created '. $assertions['item_count'] .' Story nodes.'); } } } diff --git a/tests/feeds.test.inc b/tests/feeds.test.inc index 0708832e..10acce20 100644 --- a/tests/feeds.test.inc +++ b/tests/feeds.test.inc @@ -14,12 +14,64 @@ class FeedsWebTestCase extends DrupalWebTestCase { /** * Debug utility. Shows current screen. */ - public function show() { + public function show($path = NULL) { + if ($path !== NULL) { + $this->drupalGet($path); + } // Use error, this will make sure we don't forget accidental calls to show() // in our tests. $this->error($this->content); } + /** + * Absolute path to Drupal root. + */ + public function absolute() { + return dirname($GLOBALS['_SERVER']['SCRIPT_FILENAME']); + } + + /** + * Get the absolute directory path of the feeds module. + */ + public function absolutePath() { + return $this->absolute() .'/'. drupal_get_path('module', 'feeds'); + } + + /** + * Generate an OPML test feed. + * + * The purpose of this function is to create a dynamic OPML feed that points + * too feeds included in this test. + */ + public function generateOPML() { + $path = $GLOBALS['base_url'] .'/'. drupal_get_path('module', 'feeds') .'/tests/feeds/'; + + $output = +'<?xml version="1.0" encoding="utf-8"?> +<opml version="1.1"> +<head> + <title>Feeds test OPML</title> + <dateCreated>Fri, 16 Oct 2009 02:53:17 GMT</dateCreated> + <ownerName></ownerName> +</head> +<body> + <outline text="Feeds test group" > + <outline title="Development Seed - Technological Solutions for Progressive Organizations" text="" xmlUrl="'. $path .'developmentseed.rss2" type="rss" /> + <outline title="Magyar Nemzet Online - H’rek" text="" xmlUrl="'. $path .'feed_without_guid.rss2" type="rss" /> + <outline title="Drupal planet" text="" type="rss" xmlUrl="'. $path .'drupalplanet.rss2" /> + </outline> +</body> +</opml>'; + + // UTF 8 encode output string and write it to disk + $output = utf8_encode($output); + $file = $this->absolute() .'/'. file_directory_path() .'/test-opml-'. $this->randomName() .'.opml'; + $handle = fopen($file, 'w'); + fwrite($handle, $output); + fclose($handle); + return $file; + } + /** * Create an importer configuration. * @@ -82,21 +134,23 @@ class FeedsWebTestCase extends DrupalWebTestCase { * @return * The node id of the node created. */ - public function createFeedNode($id = 'syndication', $feed_url = NULL, $title = '') { + public function createFeedNode($id = 'syndication', $feed_url = NULL, $title = '', $content_type = NULL) { if (empty($feed_url)) { $feed_url = $GLOBALS['base_url'] .'/'. drupal_get_path('module', 'feeds') .'/tests/feeds/developmentseed.rss2'; } - // Ask the configuration for the content type to create. - $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); + // 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 = array( 'title' => $title, 'feeds[FeedsHTTPFetcher][source]' => $feed_url, ); - $this->drupalPost('node/add/'. $content_type, $edit, 'Save'); + $this->drupalPost('node/add/'. str_replace('_', '-', $content_type), $edit, 'Save'); $this->assertText('has been created.'); // Get the node id from URL. @@ -127,10 +181,10 @@ class FeedsWebTestCase extends DrupalWebTestCase { * @return * An array of node ids of the nodes created. */ - public function createFeedNodes($id = 'syndication', $num = 20) { + public function createFeedNodes($id = 'syndication', $num = 20, $content_type = NULL) { $nids = array(); for ($i = 0; $i < $num; $i++) { - $nids[] = $this->createFeedNode($id, NULL, $this->randomName()); + $nids[] = $this->createFeedNode($id, NULL, $this->randomName(), $content_type); } return $nids; } @@ -159,6 +213,18 @@ class FeedsWebTestCase extends DrupalWebTestCase { $this->assertEqual(1, db_result(db_query('SELECT COUNT(*) FROM {feeds_schedule} WHERE id = "%s" AND callback = "expire" AND last_scheduled_time = 0 AND scheduled = 0', $id))); } + /** + * Import a file through the import form. Assumes FeedsFileFetcher in place. + */ + public function importFile($id, $file) { + + $this->assertTrue(file_exists($file), 'Source file exists'); + $edit = array( + 'files[feeds]' => $file, + ); + $this->drupalPost('import/'. $id, $edit, 'Import'); + } + /** * Assert a feeds configuration's plugins. * -- GitLab