Commit bb9b0faf authored by damienmckenna's avatar damienmckenna Committed by Damien McKenna
Browse files

Issue #3110061 by DamienMcKenna: Tidy up test files.

parent 5cb6837d
......@@ -6,6 +6,7 @@ Link 7.x-1.x-dev, xxxx-xx-xx
Paul Lomax, rcross, rooby, timofey, seanB, Adirael, esbite, kay_v,
joep.hendrix: Convert links to their internal link representation if they
exist.
#3110061 by DamienMcKenna: Tidy up test files.
Link 7.x-1.7, 2019-11-14
......
......@@ -3,19 +3,23 @@ description = Defines simple link field types.
core = 7.x
package = Fields
; Migrate integration.
files[] = link.migrate.inc
; Tests
files[] = tests/link.test
files[] = tests/link.attribute.test
files[] = tests/link.crud.test
files[] = tests/link.crud_browser.test
files[] = tests/link.token.test
files[] = tests/link.entity_token.test
files[] = tests/link.validate.test
files[] = tests/link.multilingual.test
files[] = tests/link.convert_alias.test
; Views Handlers
; Views integration.
files[] = views/link_views_handler_argument_target.inc
files[] = views/link_views_handler_filter_protocol.inc
; Tests.
; Most tests extend from this class.
files[] = tests/LinkBaseTestClass.test
; All of the actual tests.
files[] = tests/LinkConvertInternalPathsTest.test
files[] = tests/LinkEntityTokenTest.test
files[] = tests/LinkFieldAttributesTest.test
files[] = tests/LinkFieldCrudTest.test
files[] = tests/LinkFieldValidateTest.test
files[] = tests/LinkPathPrefixesTest.test
files[] = tests/LinkTokenTest.test
files[] = tests/LinkValidationApiTest.test
......@@ -2,14 +2,19 @@
/**
* @file
* Link base test file - contains common functions for testing links.
* Base test class with helper methods, etc.
*/
/**
* Base Test Class.
* Base test class with helper methods, etc.
*/
class LinkBaseTestClass extends DrupalWebTestCase {
/**
* Default permissions used on tests.
*
* @var array
*/
protected $permissions = array(
'access content',
'administer content types',
......@@ -26,8 +31,12 @@ class LinkBaseTestClass extends DrupalWebTestCase {
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
// Most of the tests require the field UI to create & modify fields.
$modules[] = 'field_ui';
// This module.
$modules[] = 'link';
parent::setUp($modules);
$this->web_user = $this->drupalCreateUser($this->permissions);
......
......@@ -8,7 +8,7 @@
/**
* Confirm path aliases are saved internally as the system path.
*/
class LinkConvertInternalTestCase extends LinkBaseTestClass {
class LinkConvertInternalPathsTest extends LinkBaseTestClass {
/**
* Description of the tests.
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains simpletests making sure entity_token integration works.
* Testing that tokens can be used in link titles.
*/
/**
......
......@@ -2,13 +2,13 @@
/**
* @file
* Basic simpletests to test options on link module.
* Field attributes test.
*/
/**
* Attribute Crud Test.
* Field attributes test.
*/
class LinkAttributeCrudTest extends DrupalWebTestCase {
class LinkFieldAttributesTest extends DrupalWebTestCase {
private $zebra;
......@@ -28,7 +28,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
*/
public static function getInfo() {
return array(
'name' => 'Link Attribute Tests',
'name' => 'Link field attribute Tests',
'description' => 'Tests the field attributes, making sure they appear in various displayed situations.',
'group' => 'Link',
);
......
......@@ -2,13 +2,13 @@
/**
* @file
* Testing CRUD API in the browser.
* Testing that users can not input bad URLs or labels.
*/
/**
* Testing that users can not input bad URLs or labels.
*/
class LinkUiTest extends DrupalWebTestcase {
class LinkFieldCrudTest extends DrupalWebTestcase {
/**
* Link supposed to be good.
......@@ -98,37 +98,43 @@ class LinkUiTest extends DrupalWebTestcase {
array(
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName() . '<script>alert("hi");</script>',
'msg' => 'js label',
'msg' => 'JS in label',
'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
),
array(
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName() . '<script src="http://devil.site.com"></script>',
'msg' => 'js label',
'msg' => 'Remote JS in label',
'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
),
array(
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName() . '" onmouseover="alert(\'hi\')',
'msg' => 'js label',
'msg' => 'JS in label',
'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
),
array(
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName() . '\' onmouseover="alert(\'hi\')',
'msg' => 'js label',
'msg' => 'Escaped JS in label',
'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
),
array(
'href' => 'javascript:alert("http://example.com/' . $this->randomName() . '")',
'label' => $this->randomName(),
'msg' => 'js url',
'msg' => 'JS in URL',
'type' => self::LINK_INPUT_TYPE_BAD_URL,
),
array(
'href' => 'http://example.com?foo=bar&fruit=mango',
'label' => $this->randomName(),
'msg' => 'URL with querystring',
'type' => self::LINK_INPUT_TYPE_GOOD,
),
array(
'href' => 'http://ecs-es.kelkoo.es/ctl/go/sitesearchGo?.ts=1338833010331&.sig=qP9GXeEFH6syBzwmzYkxmsvp1EI-',
'label' => 'http://ecs-es.kelkoo.es/ctl/go/sitesearchGo?.ts=1338833010331&.sig=qP9GXeEFH6syBzwmzYkxmsvp1EI-',
'msg' => 'Url with . in querystring',
'msg' => 'URL with . in querystring',
'type' => self::LINK_INPUT_TYPE_GOOD,
),
);
......@@ -173,13 +179,11 @@ class LinkUiTest extends DrupalWebTestcase {
// If simpletest starts using something to override the error system, this
// will flag us and let us know it's broken.
$this->assertFalse(libxml_use_internal_errors(TRUE));
$expected_href = $input['href'];
if (isset($input['expected_href'])) {
$path = '//a[@href="' . $input['expected_href'] . '" and text()="' . $input['label'] . '"]';
}
else {
$path = '//a[@href="' . $input['href'] . '" and text()="' . $input['label'] . '"]';
$expected_href = $input['expected_href'];
}
$elements = $this->xpath($path);
$elements = $this->xpath('//a[@href="' . $expected_href . '" and text()="' . $input['label'] . '"]');
libxml_use_internal_errors(FALSE);
$this->assertIdentical(isset($elements[0]), $input['type'] == self::LINK_INPUT_TYPE_GOOD, $input['msg']);
}
......
......@@ -2,13 +2,24 @@
/**
* @file
* Tests that exercise the validation functions in the link module.
* Link field Validation Tests.
*/
/**
* Validate Test Case.
* Link field Validation Tests.
*/
class LinkValidateTestCase extends LinkBaseTestClass {
class LinkFieldValidateTest extends LinkBaseTestClass {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'Link field validation tests',
'description' => 'Tests the field validation.',
'group' => 'Link',
);
}
/**
* Create Link.
......@@ -47,24 +58,6 @@ class LinkValidateTestCase extends LinkBaseTestClass {
$this->assertEqual($url, $node->{$field_name}[LANGUAGE_NONE][0]['url']);
}
}
/**
* Class for Validate Test.
*/
class LinkValidateTest extends LinkValidateTestCase {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'Link Validation Tests',
'description' => 'Tests the field validation.',
'group' => 'Link',
);
}
/**
* Validate basic URL.
*/
......@@ -233,6 +226,8 @@ class LinkValidateTest extends LinkValidateTestCase {
*
* Test if a bad url can sneak through un-filtered if we play with the
* validation...
*
* @todo Enable this, fix any problems that come up.
*/
public function xTestLinkValidateSwitchingBetweenValidationStatus() {
$this->acquireContentTypes(1);
......@@ -344,24 +339,6 @@ class LinkValidateTest extends LinkValidateTestCase {
$this->linkTestValidateUrl('ftp://www.example.com/');
}
}
/**
* Validate Test News.
*/
class LinkValidateTestNews extends LinkValidateTestCase {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'Link News Validation Tests',
'description' => 'Tests the field validation for usenet urls.',
'group' => 'Link',
);
}
/**
* Validate a news link to a message group.
*/
......@@ -376,24 +353,6 @@ class LinkValidateTestNews extends LinkValidateTestCase {
$this->linkTestValidateUrl('news:hj0db8$vrm$1@news.eternal-september.org');
}
}
/**
* Validate Specific URL.
*/
class LinkValidateSpecificURL extends LinkValidateTestCase {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'Link Specific URL Validation Tests',
'description' => 'Tests field validation with unusual urls',
'group' => 'Link',
);
}
/**
* Lets throw in a lot of umlouts for testing!
*/
......@@ -440,260 +399,3 @@ class LinkValidateSpecificURL extends LinkValidateTestCase {
}
}
/**
* Validate Url Light.
*
* 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 !
*/
class LinkValidateUrlLight extends DrupalWebTestCase {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'Link Light Validation Tests',
'description' => 'Tests the link_validate_url() function by itself, without invoking the full drupal/cck lifecycle.',
'group' => 'Link',
);
}
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
$modules[] = 'link';
parent::setUp($modules);
}
/**
* Name Link Type.
*
* Translates the LINK type constants to english for display and debugging of
* tests.
*
* @codingStandardsIgnoreStart
*/
public function name_Link_Type($type) {
// @codingStandardsIgnoreEnd
switch ($type) {
case LINK_FRONT:
return "Front";
case LINK_EMAIL:
return "Email";
case LINK_TEL:
return "Telephone";
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 labeled <front> works.
*/
public function testValidateFrontLink() {
$valid = link_validate_url('<front>');
$this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verified and identified');
}
/**
* Validate Email Link.
*/
public function testValidateEmailLink() {
$valid = link_validate_url('mailto:bob@example.com');
$this->assertEqual(LINK_EMAIL, $valid, "Make sure a basic mailto is verified and identified");
}
/**
* Validate Email Link Bad.
*/
public function testValidateEmailLinkBad() {
$valid = link_validate_url(':bob@example.com');
$this->assertEqual(FALSE, $valid, 'Make sure just a bad address is correctly failed');
}
/**
* Confirm that valid tel: links work as expected.
*/
public function testValidateTelLinks() {
$links = array(
'tel:01',
'tel:123456789012345',
'tel:+123456789012345',
);
foreach ($links as $link) {
$type = link_url_type($link);
$this->assertEqual(LINK_TEL, $type, 'Test ' . $link . ' is a tel link.');
$valid = link_validate_url($link);
$this->assertTrue($valid, 'Test ' . $link . ' is valid tel link.');
}
}
/**
* Confirm that invalid tel: links work as expected.
*/
public function testValidateTelLinksBad() {
$links = array(
'tel:0',
'tel:1234567890123456',
'tel:+1',
'tel:+0123456789',
'tel:+1234567890123456',
':12345678',
);
foreach ($links as $link) {
$type = link_url_type($link);
$this->assertFalse($type, 'Test ' . $link . ' is not a tel link.');
$valid = link_validate_url($link);
$this->assertFalse($valid, 'Test ' . $link . ' is not a valid tel link.');
}
}
/**
* Validate Newsgroup Link.
*/
public function testValidateNewsgroupLink() {
$valid = link_validate_url('news:comp.infosystems.www.misc');
$this->assertEqual(LINK_NEWS, $valid, 'Make sure link to newsgroup validates as news.');
}
/**
* Validate News Article Link.
*/
public 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 validates as news.');
}
/**
* Validate Bad Newsgroup Link.
*/
public 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.');
}
/**
* Validate Internal Links.
*/
public function testValidateInternalLinks() {
$tempfile = drupal_tempnam('public://files', 'test');
$links = array(
'rss.xml',
'foo#bar',
file_uri_target($tempfile),
drupal_realpath($tempfile),
);
foreach ($links as $link) {
$type = link_url_type($link);
$this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.');
$valid = link_validate_url($link);
$this->assertTrue($valid, 'Test ' . $link . ' is valid internal link.');
}
}
/**
* Validate External Links.
*/
public 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/?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) {
$type = link_url_type($link);
$this->assertEqual(LINK_EXTERNAL, $type, 'Testing that ' . $link . ' is an external link.');
$valid = link_validate_url($link);
$this->assertTrue($valid, 'Test ' . $link . ' is valid external link.');
// The following two lines are commented out and only used for
// comparisons.
// $valid2 = valid_url($link, TRUE);
// $this->assertEqual(TRUE, $valid2, "Using valid_url() on $link.");.
}
}
/**
* Check Invalid External Links.
*/
public function testInvalidExternalLinks() {
$links = array(
'http://www.ex ample.com/',
// Bad ip!
'http://25.0.0/',
'http://4827.0.0.2/',
// ß not allowed in domain names!
'http://www.testß.com/',
// Bad TLD.
'http://.www.foo.bar./',
// Domains can't have sections starting with a dash.
// 'http://www.-fudge.com/',
'http://example.com/index.php?page=this\that',
'example@example.com',
);
foreach ($links as $link) {
$valid = link_validate_url($link);
$this->assertEqual(FALSE, $valid, 'Testing that ' . $link . ' is not a valid link.');
}
}
}
......@@ -8,7 +8,18 @@
/**
* Testing that absolute / relative outputs match the expected format.
*/
class LinkMultilingualTestCase extends LinkBaseTestClass {
class LinkPathPrefixesTest extends LinkBaseTestClass {
/**
*
*/
public static function getInfo() {
return array(
'name' => 'Link language path prefix',
'description' => 'Tests that path properly work with language path prefixes.',
'group' => 'Link',
);
}
/**
* {@inheritdoc}
......@@ -64,23 +75,6 @@ class LinkMultilingualTestCase extends LinkBaseTestClass {
drupal_static_reset('locale_language_url_rewrite_url');
}
}
/**
*
*/
class LinkMultilingualPathTest extends LinkMultilingualTestCase {
/**
*
*/
public static function getInfo() {
return array(
'name' => 'Link language path prefix',
'description' => 'Tests that path properly work with language path prefixes.',
'group' => 'Link',
);
}
/**
* Creates a link field, fills it, then uses a loaded node to test paths.
*/
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains simpletests making sure token integration works.
* Testing that tokens can be used in link titles.