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 ...@@ -6,6 +6,7 @@ Link 7.x-1.x-dev, xxxx-xx-xx
Paul Lomax, rcross, rooby, timofey, seanB, Adirael, esbite, kay_v, Paul Lomax, rcross, rooby, timofey, seanB, Adirael, esbite, kay_v,
joep.hendrix: Convert links to their internal link representation if they joep.hendrix: Convert links to their internal link representation if they
exist. exist.
#3110061 by DamienMcKenna: Tidy up test files.
Link 7.x-1.7, 2019-11-14 Link 7.x-1.7, 2019-11-14
......
...@@ -3,19 +3,23 @@ description = Defines simple link field types. ...@@ -3,19 +3,23 @@ description = Defines simple link field types.
core = 7.x core = 7.x
package = Fields package = Fields
; Migrate integration.
files[] = link.migrate.inc files[] = link.migrate.inc
; Tests ; Views integration.
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
files[] = views/link_views_handler_argument_target.inc files[] = views/link_views_handler_argument_target.inc
files[] = views/link_views_handler_filter_protocol.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 @@ ...@@ -2,14 +2,19 @@
/** /**
* @file * @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 { class LinkBaseTestClass extends DrupalWebTestCase {
/**
* Default permissions used on tests.
*
* @var array
*/
protected $permissions = array( protected $permissions = array(
'access content', 'access content',
'administer content types', 'administer content types',
...@@ -26,8 +31,12 @@ class LinkBaseTestClass extends DrupalWebTestCase { ...@@ -26,8 +31,12 @@ class LinkBaseTestClass extends DrupalWebTestCase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function setUp(array $modules = array()) { public function setUp(array $modules = array()) {
// Most of the tests require the field UI to create & modify fields.
$modules[] = 'field_ui'; $modules[] = 'field_ui';
// This module.
$modules[] = 'link'; $modules[] = 'link';
parent::setUp($modules); parent::setUp($modules);
$this->web_user = $this->drupalCreateUser($this->permissions); $this->web_user = $this->drupalCreateUser($this->permissions);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
/** /**
* Confirm path aliases are saved internally as the system path. * Confirm path aliases are saved internally as the system path.
*/ */
class LinkConvertInternalTestCase extends LinkBaseTestClass { class LinkConvertInternalPathsTest extends LinkBaseTestClass {
/** /**
* Description of the tests. * Description of the tests.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/** /**
* @file * @file
* Contains simpletests making sure entity_token integration works. * Testing that tokens can be used in link titles.
*/ */
/** /**
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
/** /**
* @file * @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; private $zebra;
...@@ -28,7 +28,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { ...@@ -28,7 +28,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
*/ */
public static function getInfo() { public static function getInfo() {
return array( return array(
'name' => 'Link Attribute Tests', 'name' => 'Link field attribute Tests',
'description' => 'Tests the field attributes, making sure they appear in various displayed situations.', 'description' => 'Tests the field attributes, making sure they appear in various displayed situations.',
'group' => 'Link', 'group' => 'Link',
); );
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
/** /**
* @file * @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. * Testing that users can not input bad URLs or labels.
*/ */
class LinkUiTest extends DrupalWebTestcase { class LinkFieldCrudTest extends DrupalWebTestcase {
/** /**
* Link supposed to be good. * Link supposed to be good.
...@@ -98,37 +98,43 @@ class LinkUiTest extends DrupalWebTestcase { ...@@ -98,37 +98,43 @@ class LinkUiTest extends DrupalWebTestcase {
array( array(
'href' => 'http://example.com/' . $this->randomName(), 'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName() . '<script>alert("hi");</script>', 'label' => $this->randomName() . '<script>alert("hi");</script>',
'msg' => 'js label', 'msg' => 'JS in label',
'type' => self::LINK_INPUT_TYPE_BAD_TITLE, 'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
), ),
array( array(
'href' => 'http://example.com/' . $this->randomName(), 'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName() . '<script src="http://devil.site.com"></script>', '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, 'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
), ),
array( array(
'href' => 'http://example.com/' . $this->randomName(), 'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName() . '" onmouseover="alert(\'hi\')', 'label' => $this->randomName() . '" onmouseover="alert(\'hi\')',
'msg' => 'js label', 'msg' => 'JS in label',
'type' => self::LINK_INPUT_TYPE_BAD_TITLE, 'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
), ),
array( array(
'href' => 'http://example.com/' . $this->randomName(), 'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName() . '\' onmouseover="alert(\'hi\')', 'label' => $this->randomName() . '\' onmouseover="alert(\'hi\')',
'msg' => 'js label', 'msg' => 'Escaped JS in label',
'type' => self::LINK_INPUT_TYPE_BAD_TITLE, 'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
), ),
array( array(
'href' => 'javascript:alert("http://example.com/' . $this->randomName() . '")', 'href' => 'javascript:alert("http://example.com/' . $this->randomName() . '")',
'label' => $this->randomName(), 'label' => $this->randomName(),
'msg' => 'js url', 'msg' => 'JS in URL',
'type' => self::LINK_INPUT_TYPE_BAD_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( array(
'href' => 'http://ecs-es.kelkoo.es/ctl/go/sitesearchGo?.ts=1338833010331&.sig=qP9GXeEFH6syBzwmzYkxmsvp1EI-', '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-', '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, 'type' => self::LINK_INPUT_TYPE_GOOD,
), ),
); );
...@@ -173,13 +179,11 @@ class LinkUiTest extends DrupalWebTestcase { ...@@ -173,13 +179,11 @@ class LinkUiTest extends DrupalWebTestcase {
// If simpletest starts using something to override the error system, this // If simpletest starts using something to override the error system, this
// will flag us and let us know it's broken. // will flag us and let us know it's broken.
$this->assertFalse(libxml_use_internal_errors(TRUE)); $this->assertFalse(libxml_use_internal_errors(TRUE));
$expected_href = $input['href'];
if (isset($input['expected_href'])) { if (isset($input['expected_href'])) {
$path = '//a[@href="' . $input['expected_href'] . '" and text()="' . $input['label'] . '"]'; $expected_href = $input['expected_href'];
}
else {
$path = '//a[@href="' . $input['href'] . '" and text()="' . $input['label'] . '"]';
} }
$elements = $this->xpath($path); $elements = $this->xpath('//a[@href="' . $expected_href . '" and text()="' . $input['label'] . '"]');
libxml_use_internal_errors(FALSE); libxml_use_internal_errors(FALSE);
$this->assertIdentical(isset($elements[0]), $input['type'] == self::LINK_INPUT_TYPE_GOOD, $input['msg']); $this->assertIdentical(isset($elements[0]), $input['type'] == self::LINK_INPUT_TYPE_GOOD, $input['msg']);
} }
......
...@@ -2,13 +2,24 @@ ...@@ -2,13 +2,24 @@
/** /**
* @file * @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. * Create Link.
...@@ -47,24 +58,6 @@ class LinkValidateTestCase extends LinkBaseTestClass { ...@@ -47,24 +58,6 @@ class LinkValidateTestCase extends LinkBaseTestClass {
$this->assertEqual($url, $node->{$field_name}[LANGUAGE_NONE][0]['url']); $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. * Validate basic URL.
*/ */
...@@ -233,6 +226,8 @@ class LinkValidateTest extends LinkValidateTestCase { ...@@ -233,6 +226,8 @@ class LinkValidateTest extends LinkValidateTestCase {
* *
* Test if a bad url can sneak through un-filtered if we play with the * Test if a bad url can sneak through un-filtered if we play with the
* validation... * validation...
*
* @todo Enable this, fix any problems that come up.
*/ */
public function xTestLinkValidateSwitchingBetweenValidationStatus() { public function xTestLinkValidateSwitchingBetweenValidationStatus() {
$this->acquireContentTypes(1); $this->acquireContentTypes(1);
...@@ -344,24 +339,6 @@ class LinkValidateTest extends LinkValidateTestCase { ...@@ -344,24 +339,6 @@ class LinkValidateTest extends LinkValidateTestCase {
$this->linkTestValidateUrl('ftp://www.example.com/'); $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. * Validate a news link to a message group.
*/ */
...@@ -376,24 +353,6 @@ class LinkValidateTestNews extends LinkValidateTestCase { ...@@ -376,24 +353,6 @@ class LinkValidateTestNews extends LinkValidateTestCase {
$this->linkTestValidateUrl('news:hj0db8$vrm$1@news.eternal-september.org'); $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! * Lets throw in a lot of umlouts for testing!
*/ */
...@@ -440,260 +399,3 @@ class LinkValidateSpecificURL extends LinkValidateTestCase { ...@@ -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',