From 2d553f70502728b625c4c366bd638c938881211b Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Thu, 16 Jun 2011 23:06:38 -0500
Subject: [PATCH] Issue #723548: Added unit tests for feeds_valid_url().

---
 tests/feeds.test                | 76 +++++++++++++++++++++++++++++++++
 tests/feeds_processor_node.test |  7 +--
 2 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/tests/feeds.test b/tests/feeds.test
index c8982d47..215d62bb 100644
--- a/tests/feeds.test
+++ b/tests/feeds.test
@@ -434,3 +434,79 @@ class FeedsWebTestCase extends DrupalWebTestCase {
     }
   }
 }
+
+/**
+ * Provides a wrapper for DrupalUnitTestCase for Feeds unit testing.
+ */
+class FeedsUnitTestHelper extends DrupalUnitTestCase {
+  public function setUp() {
+    parent::setUp();
+
+    // Manually include the feeds module.
+    // @todo Allow an array of modules from the child class.
+    drupal_load('module', 'feeds');
+  }
+}
+
+class FeedsUnitTestCase extends FeedsUnitTestHelper {
+  public static function getInfo() {
+    return array(
+      'name' => 'Unit tests',
+      'description' => 'Test basic low-level Feeds module functionality.',
+      'group' => 'Feeds',
+    );
+  }
+
+  /**
+   * Test valid absolute urls.
+   *
+   * @see ValidUrlTestCase
+   *
+   * @todo Remove when http://drupal.org/node/1191252 is fixed.
+   */
+  function testFeedsValidURL() {
+    $url_schemes = array('http', 'https', 'ftp', 'feed', 'webcal');
+    $valid_absolute_urls = array(
+      'example.com',
+      'www.example.com',
+      'ex-ample.com',
+      '3xampl3.com',
+      'example.com/paren(the)sis',
+      'example.com/index.html#pagetop',
+      'example.com:8080',
+      'subdomain.example.com',
+      'example.com/index.php?q=node',
+      'example.com/index.php?q=node&param=false',
+      'user@www.example.com',
+      'user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop',
+      '127.0.0.1',
+      'example.org?',
+      'john%20doe:secret:foo@example.org/',
+      'example.org/~,$\'*;',
+      'caf%C3%A9.example.org',
+      '[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html',
+    );
+
+    foreach ($url_schemes as $scheme) {
+      foreach ($valid_absolute_urls as $url) {
+        $test_url = $scheme . '://' . $url;
+        $valid_url = feeds_valid_url($test_url, TRUE);
+        $this->assertTrue($valid_url, t('@url is a valid url.', array('@url' => $test_url)));
+      }
+    }
+
+    $invalid_ablosule_urls = array(
+      '',
+      'ex!ample.com',
+      'ex%ample.com',
+    );
+
+    foreach ($url_schemes as $scheme) {
+      foreach ($invalid_ablosule_urls as $url) {
+        $test_url = $scheme . '://' . $url;
+        $valid_url = feeds_valid_url($test_url, TRUE);
+        $this->assertFalse($valid_url, t('@url is NOT a valid url.', array('@url' => $test_url)));
+      }
+    }
+  }
+}
diff --git a/tests/feeds_processor_node.test b/tests/feeds_processor_node.test
index 476348e8..c16983f5 100644
--- a/tests/feeds_processor_node.test
+++ b/tests/feeds_processor_node.test
@@ -73,16 +73,14 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase {
 
     // 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');
 
-    // Navigate to a non-feed node, there should be no Feeds tabs visible.
-    $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());
-
     // Assert accuracy of aggregated information.
     $this->drupalGet('node');
     $this->assertRaw('<span class="username">Anonymous (not verified)</span>');
@@ -322,7 +320,6 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase {
    * Check that the total number of entries in the feeds_item table is correct.
    */
   function assertFeedItemCount($num) {
-    // Assert DB status, there should be 10 again.
     $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node'")->fetchField();
     $this->assertEqual($count, $num, 'Accurate number of items in database.');
   }
-- 
GitLab