class LinkValidateUrlLight in Link 6.2
A series of tests of links, only going against the link_validate_url function in link.module.
Validation is guided by the rules in http://tools.ietf.org/html/rfc1738 !
Hierarchy
- class \DrupalTestCase
- class \DrupalUnitTestCase
- class \LinkValidateUrlLight
- class \DrupalUnitTestCase
Expanded class hierarchy of LinkValidateUrlLight
File
- tests/
link.validate.test, line 366 - Tests that exercise the validation functions in the link module.
View source
class LinkValidateUrlLight extends DrupalUnitTestCase {
function setUp() {
// do we need to include something here?
module_load_include('module', 'link');
module_load_include('inc', 'link');
}
function getInfo() {
return array(
'name' => t('Link Light Validation Tests'),
'description' => t('Tests the link_validate_url() function by itself, without invoking the full drupal/cck lifecycle.'),
'group' => t('Link'),
);
}
/**
* Translates the LINK type constants to english for display and debugging of tests
*/
function name_Link_Type($type) {
switch ($type) {
case LINK_FRONT:
return "Front";
case LINK_EMAIL:
return "Email";
case LINK_NEWS:
return "Newsgroup";
case LINK_INTERNAL:
return "Internal Link";
case LINK_EXTERNAL:
return "External Link";
case FALSE:
return "Invalid Link";
default:
return "Bad Value:" . $type;
}
}
// Make sure that a link labelled <front> works.
function testValidateFrontLink() {
$valid = link_validate_url('<front>');
$this
->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verfied and identified');
}
function testValidateEmailLink() {
$valid = link_validate_url('mailto:bob@example.com');
$this
->assertEqual(LINK_EMAIL, $valid, "Make sure a basic mailto is verified and identified");
}
function testValidateEmailLinkBad() {
$valid = link_validate_url(':bob@example.com');
$this
->assertEqual(FALSE, $valid, 'Make sure just a bad address is correctly failed');
}
function testValidateNewsgroupLink() {
$valid = link_validate_url('news:comp.infosystems.www.misc');
$this
->assertEqual(LINK_NEWS, $valid, 'Make sure link to newsgroup validates as news.');
}
function testValidateNewsArticleLink() {
$valid = link_validate_url('news:hj0db8$vrm$1@news.eternal-september.org');
$this
->assertEqual(LINK_NEWS, $valid, 'Make sure link to specific article valiates as news.');
}
function testValidateBadNewsgroupLink() {
$valid = link_validate_url('news:comp.bad_name.misc');
$this
->assertEqual(FALSE, $valid, 'newsgroup names can\'t contain underscores, so it should come back as invalid.');
}
function testValidateInternalLink() {
$valid = link_validate_url('node/5');
$this
->assertEqual(LINK_INTERNAL, $valid, 'Test normal internal link.');
}
function testValidateInternalLinkWithDot() {
$valid = link_validate_url('rss.xml');
$this
->assertEqual(LINK_INTERNAL, $valid, 'Test rss.xml internal link.');
}
function testValidateInternalLinkToFile() {
$valid = link_validate_url('files/test.jpg');
$this
->assertEqual(LINK_INTERNAL, $valid, 'Test files/test.jpg internal link.');
}
function testValidateExternalLinks() {
$links = array(
'http://localhost:8080/',
'www.example.com',
'www.example.com/',
'http://username:p%40ssw0rd!@www.example.com/',
'http://@www.example.com/',
'http://username:@www.example.com/',
'http://username:password@www.example.com:8080/',
'http://127.0.0.1:80/',
'http://127.173.24.255:4723/',
'127.173.24.255:4723/',
'http://255.255.255.255:4823/',
'www.test-site.com',
'http://example.com/index.php?q=node/123',
'http://example.com/index.php?page=this\\that',
'http://example.com/?first_name=Joe Bob&last_name=Smith',
// Anchors
'http://www.example.com/index.php#test',
'http://www.example.com/index.php#this@that.',
'http://www.example.com/index.php#',
'http://www.cnn.com/video/#/video/politics/2008/12/09/intv.madeleine.albright.cnn',
'http://www.archive.org/stream/aesopsfables00aesorich#page/n7/mode/2up',
'http://www.example.com/blah/#this@that?',
);
// Test all of the protocols.
$allowed_protocols = variable_get('filter_allowed_protocols', array(
'http',
'https',
'ftp',
'news',
'nntp',
'telnet',
'mailto',
'irc',
'ssh',
'sftp',
'webcal',
));
foreach ($allowed_protocols as $protocol) {
if ($protocol !== 'news' && $protocol !== 'mailto') {
$links[] = $protocol . '://www.example.com';
}
}
foreach ($links as $link) {
$valid = link_validate_url($link);
$this
->assertEqual(LINK_EXTERNAL, $valid, 'Testing that ' . $link . ' is a valid external link.');
}
}
function testInvalidExternalLinks() {
$links = array(
'http://www.ex ample.com/',
'//www.example.com/',
'http://25.0.0/',
// bad ip!
'http://4827.0.0.2/',
'http://www.testß.com/',
);
foreach ($links as $link) {
$valid = link_validate_url($link);
$this
->assertEqual(FALSE, $valid, 'Testing that ' . $link . ' is not a valid link.');
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalTestCase:: |
protected | property | Assertions thrown in that test case. | |
DrupalTestCase:: |
protected | property | The database prefix of this test run. | |
DrupalTestCase:: |
protected | property | The original file directory, before it was changed for testing purposes. | |
DrupalTestCase:: |
protected | property | The original database prefix, before it was changed for testing purposes. | |
DrupalTestCase:: |
public | property | Current results of this test case. | |
DrupalTestCase:: |
protected | property | This class is skipped when looking for the source of an assertion. | |
DrupalTestCase:: |
protected | property | The test run ID. | |
DrupalTestCase:: |
protected | property | Time limit for the test. | |
DrupalTestCase:: |
protected | function | Internal helper: stores the assert. | |
DrupalTestCase:: |
protected | function | Check to see if two values are equal. | |
DrupalTestCase:: |
protected | function | Check to see if a value is false (an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
protected | function | Check to see if two values are identical. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not equal. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not identical. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
public static | function | Delete an assertion record by message ID. | |
DrupalTestCase:: |
protected | function | Fire an error assertion. | |
DrupalTestCase:: |
public | function | Handle errors during test runs. | |
DrupalTestCase:: |
protected | function | Handle exceptions. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always negative. | |
DrupalTestCase:: |
public static | function | Converts a list of possible parameters into a stack of permutations. | |
DrupalTestCase:: |
protected | function | Cycles through backtrace until the first non-assertion method is found. | |
DrupalTestCase:: |
public static | function | Store an assertion from outside the testing context. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always positive. | |
DrupalTestCase:: |
public static | function | Generates a random string containing letters and numbers. | |
DrupalTestCase:: |
public static | function | Generates a random string of ASCII characters of codes 32 to 126. | |
DrupalTestCase:: |
public | function | Run all tests in this class. | |
DrupalTestCase:: |
protected | function | Logs verbose message in a text file. | |
DrupalUnitTestCase:: |
protected | function | ||
DrupalUnitTestCase:: |
function |
Constructor for DrupalUnitTestCase. Overrides DrupalTestCase:: |
||
LinkValidateUrlLight:: |
function | |||
LinkValidateUrlLight:: |
function | Translates the LINK type constants to english for display and debugging of tests | ||
LinkValidateUrlLight:: |
function |
Sets up unit test environment. Overrides DrupalUnitTestCase:: |
||
LinkValidateUrlLight:: |
function | |||
LinkValidateUrlLight:: |
function | |||
LinkValidateUrlLight:: |
function | |||
LinkValidateUrlLight:: |
function | |||
LinkValidateUrlLight:: |
function | |||
LinkValidateUrlLight:: |
function | |||
LinkValidateUrlLight:: |
function | |||
LinkValidateUrlLight:: |
function | |||
LinkValidateUrlLight:: |
function | |||
LinkValidateUrlLight:: |
function | |||
LinkValidateUrlLight:: |
function |