1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Unit tests for Link module's internal APIs.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Unit tests for Link module's internal APIs.
|
10
|
*/
|
11
|
class LinkUnitTestCase extends DrupalUnitTestCase {
|
12
|
|
13
|
/**
|
14
|
*
|
15
|
*/
|
16
|
public static function getInfo() {
|
17
|
return array(
|
18
|
'name' => 'Link Unit Tets',
|
19
|
'description' => 'Unit tests for the Link module.',
|
20
|
'group' => 'Link',
|
21
|
);
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
* {@inheritdoc}
|
26
|
*/
|
27
|
public function setUp() {
|
28
|
drupal_load('module', 'link');
|
29
|
parent::setUp();
|
30
|
}
|
31
|
|
32
|
/**
|
33
|
* Test _link_parse_url().
|
34
|
*/
|
35
|
public function testLinkParseUrl() {
|
36
|
// Each of the keys is the URL to check, it will then be converted into a
|
37
|
// matching array with three possible elements - 'url', 'query' and
|
38
|
// 'fragment'.
|
39
|
$urls = array(
|
40
|
'https://www.drupal.org' => array(
|
41
|
'url' => 'https://www.drupal.org',
|
42
|
),
|
43
|
'https://www.drupal.org/?page=42' => array(
|
44
|
'url' => 'https://www.drupal.org/',
|
45
|
'query' => array(
|
46
|
'page' => 42,
|
47
|
),
|
48
|
),
|
49
|
'https://www.drupal.org/#footer' => array(
|
50
|
'url' => 'https://www.drupal.org/',
|
51
|
'fragment' => 'footer',
|
52
|
),
|
53
|
'https://www.drupal.org/?page=42#footer' => array(
|
54
|
'url' => 'https://www.drupal.org/',
|
55
|
'query' => array(
|
56
|
'page' => 42,
|
57
|
),
|
58
|
'fragment' => 'footer',
|
59
|
),
|
60
|
);
|
61
|
foreach ($urls as $url => $expected_parts) {
|
62
|
$actual_parts = _link_parse_url($url);
|
63
|
|
64
|
// First off, compare the URL segment.
|
65
|
$this->assertEqual($expected_parts['url'], $actual_parts['url']);
|
66
|
|
67
|
// Secondly, compare the query string, if it was expected.
|
68
|
if (isset($expected_parts['query'])) {
|
69
|
$this->assertTrue(isset($actual_parts['query']));
|
70
|
$this->assertTrue(is_array($actual_parts['query']));
|
71
|
$this->assertEqual(count($expected_parts['query']), count($actual_parts['query']));
|
72
|
}
|
73
|
// If it was not expected, make sure it wasn't added anyway.
|
74
|
else {
|
75
|
$this->assertFalse(isset($actual_parts['query']));
|
76
|
}
|
77
|
|
78
|
// Lastly, compare the query fragment, if it was expected.
|
79
|
if (isset($expected_parts['fragment'])) {
|
80
|
$this->assertEqual($expected_parts['fragment'], $actual_parts['fragment']);
|
81
|
}
|
82
|
// If it was not expected, make sure it wasn't added anyway.
|
83
|
else {
|
84
|
$this->assertFalse(isset($actual_parts['fragment']));
|
85
|
}
|
86
|
}
|
87
|
}
|
88
|
|
89
|
}
|