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

Issue #3208957 by DamienMcKenna: Add unit tests for _link_parse_url().

parent f8c36b4d
......@@ -21,6 +21,7 @@ By DamienMcKenna: Unnecessary syntax change broke PHP 5.3 compatibility.
ignoring some tests.
#3208869 by DamienMcKenna: Simplify tests by extending LinkBaseTestClass.
#3208869 by DamienMcKenna: Forgot to update LinkSanitizeTest.
#3208957 by DamienMcKenna: Add unit tests for _link_parse_url().
Link 7.x-1.7, 2019-11-14
......
......@@ -28,3 +28,6 @@ files[] = tests/LinkValidationApiTest.test
; Testing dependencies.
test_dependencies[] = entity:entity
test_dependencies[] = token:token
; Standalone unit tests.
files[] = tests/LinkUnitTestCase.test
<?php
/**
* @file
* Unit tests for Link module's internal APIs.
*/
/**
* Unit tests for Link module's internal APIs.
*/
class LinkUnitTestCase extends DrupalUnitTestCase {
/**
*
*/
public static function getInfo() {
return array(
'name' => 'Link Unit Tets',
'description' => 'Unit tests for the Link module.',
'group' => 'Link',
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
drupal_load('module', 'link');
parent::setUp();
}
/**
* Test _link_parse_url().
*/
public function testLinkParseUrl() {
// Each of the keys is the URL to check, it will then be converted into a
// matching array with three possible elements - 'url', 'query' and
// 'fragment'.
$urls = array(
'https://www.drupal.org' => array(
'url' => 'https://www.drupal.org',
),
'https://www.drupal.org/?page=42' => array(
'url' => 'https://www.drupal.org/',
'query' => array(
'page' => 42,
),
),
'https://www.drupal.org/#footer' => array(
'url' => 'https://www.drupal.org/',
'fragment' => 'footer',
),
'https://www.drupal.org/?page=42#footer' => array(
'url' => 'https://www.drupal.org/',
'query' => array(
'page' => 42,
),
'fragment' => 'footer',
),
);
foreach ($urls as $url => $expected_parts) {
$actual_parts = _link_parse_url($url);
// First off, compare the URL segment.
$this->assertEqual($expected_parts['url'], $actual_parts['url']);
// Secondly, compare the query string, if it was expected.
if (isset($expected_parts['query'])) {
$this->assertTrue(isset($actual_parts['query']));
$this->assertTrue(is_array($actual_parts['query']));
$this->assertEqual(count($expected_parts['query']), count($actual_parts['query']));
}
// If it was not expected, make sure it wasn't added anyway.
else {
$this->assertFalse(isset($actual_parts['query']));
}
// Lastly, compare the query fragment, if it was expected.
if (isset($expected_parts['fragment'])) {
$this->assertEqual($expected_parts['fragment'], $actual_parts['fragment']);
}
// If it was not expected, make sure it wasn't added anyway.
else {
$this->assertFalse(isset($actual_parts['fragment']));
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment