1 |
bad4e148
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Test setting a global protocol, and using it for links when needed.
|
5 |
|
|
*
|
6 |
|
|
* Ensure that any links that are created not using an explict protocol (e.g.
|
7 |
|
|
* a link entered as www.drupal.org, without a http:// or https:// prefix) will
|
8 |
|
|
* use the globally defined protocol.
|
9 |
|
|
*
|
10 |
|
|
* Any links created with an explicit protocol will continue to use that
|
11 |
|
|
* protocol and will ignore the global setting.
|
12 |
|
|
*/
|
13 |
|
|
class LinkDefaultProtocolTest extends LinkBaseTestClass {
|
14 |
|
|
|
15 |
|
|
/**
|
16 |
|
|
* Get Info.
|
17 |
|
|
*/
|
18 |
|
|
public static function getInfo() {
|
19 |
|
|
return array(
|
20 |
|
|
'name' => 'Set default link protocol',
|
21 |
|
|
'description' => 'Test that an url with a default protocol set.',
|
22 |
|
|
'group' => 'Link',
|
23 |
|
|
);
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
/**
|
27 |
|
|
* A link without a default protocol uses the default (HTTP).
|
28 |
|
|
*/
|
29 |
|
|
public function testHttpDefaultProtocolOnUrlWithoutDefinedProtocol() {
|
30 |
|
|
$user = $this->drupalCreateUser($this->permissions);
|
31 |
|
|
$this->drupalLogin($user);
|
32 |
|
|
|
33 |
|
|
$this->createNodeWithLink('www.example.com');
|
34 |
|
|
|
35 |
|
|
$this->drupalGet('node/1');
|
36 |
|
|
|
37 |
|
|
$this->assertRaw('http://www.example.com');
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
/**
|
41 |
|
|
* The protocol is set to HTTP by default if a wrong protocol has been set.
|
42 |
|
|
*/
|
43 |
|
|
public function testHttpDefaultProtocolFromVariableConf() {
|
44 |
|
|
variable_set('link_default_protocol', 'banana');
|
45 |
|
|
|
46 |
|
|
try {
|
47 |
|
|
link_ensure_valid_default_protocol();
|
48 |
|
|
}
|
49 |
|
|
catch (Exception $e) {
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
$protocol = variable_get('link_default_protocol');
|
53 |
|
|
|
54 |
|
|
$this->assertEqual($protocol, LINK_HTTP_PROTOCOL);
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
/**
|
58 |
|
|
* A link with no defined protocol in the URL uses the default (HTTPS).
|
59 |
|
|
*/
|
60 |
|
|
public function testHttpsDefaultProtocolOnUrlWithoutDefinedProtocol() {
|
61 |
|
|
$this->setupDefaultProtocol(LINK_HTTPS_PROTOCOL);
|
62 |
|
|
|
63 |
|
|
$this->createNodeWithLink('www.example.com');
|
64 |
|
|
|
65 |
|
|
$this->drupalGet('node/1');
|
66 |
|
|
|
67 |
|
|
$this->assertRaw('https://www.example.com');
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
/**
|
71 |
|
|
* A link with a defined protocol HTTPS overrides the default HTTP protocol.
|
72 |
|
|
*/
|
73 |
|
|
public function testHttpDefaultProtocolOnUrlWithDefinedHttpsProtocol() {
|
74 |
|
|
$this->setupDefaultProtocol(LINK_HTTP_PROTOCOL);
|
75 |
|
|
|
76 |
|
|
$this->createNodeWithLink('https://www.example.com');
|
77 |
|
|
|
78 |
|
|
$this->drupalGet('node/1');
|
79 |
|
|
|
80 |
|
|
$this->assertRaw('https://www.example.com');
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
/**
|
84 |
|
|
* A link with a defined protocol HTTP overrides the default HTTPS protocol.
|
85 |
|
|
*/
|
86 |
|
|
public function testHttpsDefaultProtocolOnUrlWithDefinedHttpProtocol() {
|
87 |
|
|
$this->setupDefaultProtocol(LINK_HTTPS_PROTOCOL);
|
88 |
|
|
|
89 |
|
|
$this->createNodeWithLink('http://www.example.com');
|
90 |
|
|
|
91 |
|
|
$this->drupalGet('node/1');
|
92 |
|
|
|
93 |
|
|
$this->assertRaw('http://www.example.com');
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
/**
|
97 |
|
|
* Setup the default global link protocol to either HTTP or HTTPS.
|
98 |
|
|
*
|
99 |
|
|
* @param string $protocol
|
100 |
|
|
* The protocol to use.
|
101 |
|
|
*/
|
102 |
|
|
private function setupDefaultProtocol($protocol) {
|
103 |
|
|
$user = $this->drupalCreateUser($this->permissions);
|
104 |
|
|
$this->drupalLogin($user);
|
105 |
|
|
|
106 |
|
|
$this->drupalPost(
|
107 |
|
|
'admin/config/content/link',
|
108 |
|
|
array('link_default_protocol' => $protocol),
|
109 |
|
|
'Save configuration'
|
110 |
|
|
);
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
/**
|
114 |
|
|
* Create a page node with a link field.
|
115 |
|
|
*
|
116 |
|
|
* @param string $url
|
117 |
|
|
* The link URL.
|
118 |
|
|
*
|
119 |
|
|
* @return object
|
120 |
|
|
* The created node.
|
121 |
|
|
*/
|
122 |
|
|
private function createNodeWithLink($url) {
|
123 |
|
|
$link_field = $this->createLinkField('page');
|
124 |
|
|
|
125 |
|
|
$settings = array(
|
126 |
|
|
'title' => 'Basic page link test',
|
127 |
|
|
$link_field => array(
|
128 |
|
|
LANGUAGE_NONE => array(
|
129 |
|
|
array(
|
130 |
|
|
'title' => 'Field protocol link Test',
|
131 |
|
|
'url' => $url,
|
132 |
|
|
),
|
133 |
|
|
),
|
134 |
|
|
),
|
135 |
|
|
);
|
136 |
|
|
|
137 |
|
|
return $this->drupalCreateNode($settings);
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
} |