Skip to content
Snippets Groups Projects
Commit 2d553f70 authored by Dave Reid's avatar Dave Reid
Browse files

Issue #723548: Added unit tests for feeds_valid_url().

parent eac480ef
No related branches found
No related tags found
No related merge requests found
......@@ -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)));
}
}
}
}
......@@ -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.');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment