1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Tests that exercise the relative / absolute output of the link module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Testing that absolute / relative outputs match the expected format.
|
10
|
*/
|
11
|
class LinkPathPrefixesTest extends LinkBaseTestClass {
|
12
|
|
13
|
/**
|
14
|
*
|
15
|
*/
|
16
|
public static function getInfo() {
|
17
|
return array(
|
18
|
'name' => 'Link language path prefix',
|
19
|
'description' => 'Tests that path properly work with language path prefixes.',
|
20
|
'group' => 'Link',
|
21
|
);
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
* {@inheritdoc}
|
26
|
*/
|
27
|
public function setUp(array $modules = array()) {
|
28
|
$this->permissions = array_merge($this->permissions, array(
|
29
|
'administer site configuration',
|
30
|
'administer languages',
|
31
|
));
|
32
|
$modules[] = 'locale';
|
33
|
$modules[] = 'locale_test';
|
34
|
$modules[] = 'translation';
|
35
|
parent::setUp($modules);
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* Enables and configured language related stuff.
|
40
|
*/
|
41
|
public function setUpLanguage() {
|
42
|
global $language_url;
|
43
|
$this->drupalGet('admin/config/regional/language');
|
44
|
// Enable the path prefix for the default language: this way any un-prefixed
|
45
|
// URL must have a valid fallback value.
|
46
|
$edit = array('prefix' => 'en');
|
47
|
$this->drupalPost('admin/config/regional/language/edit/en', $edit, t('Save language'));
|
48
|
$language_url->prefix = $language_url->language;
|
49
|
|
50
|
// Add custom language - as we need more than 1 language to be multilingual.
|
51
|
// Code for the language.
|
52
|
$langcode = 'xx';
|
53
|
// The English name for the language.
|
54
|
$name = $this->randomName(16);
|
55
|
// The native name for the language.
|
56
|
$native = $this->randomName(16);
|
57
|
$edit = array(
|
58
|
'langcode' => $langcode,
|
59
|
'name' => $name,
|
60
|
'native' => $native,
|
61
|
'prefix' => $langcode,
|
62
|
'direction' => '0',
|
63
|
);
|
64
|
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
|
65
|
variable_set('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX);
|
66
|
|
67
|
// Enable URL language detection and selection.
|
68
|
$edit = array('language[enabled][locale-url]' => 1);
|
69
|
$this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
|
70
|
language_negotiation_set(LANGUAGE_TYPE_INTERFACE, array(LOCALE_LANGUAGE_NEGOTIATION_URL));
|
71
|
|
72
|
// Reset static caching.
|
73
|
drupal_static_reset('language_list');
|
74
|
drupal_static_reset('locale_url_outbound_alter');
|
75
|
drupal_static_reset('locale_language_url_rewrite_url');
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* Creates a link field, fills it, then uses a loaded node to test paths.
|
80
|
*/
|
81
|
public function testLanguagePrefixedPaths() {
|
82
|
$this->setUpLanguage();
|
83
|
|
84
|
// Create fields.
|
85
|
// Field for absolute urls.
|
86
|
$field_name_absolute = $this->createLinkField('page');
|
87
|
|
88
|
// Field for relative urls.
|
89
|
$settings = array(
|
90
|
'instance[settings][absolute_url]' => FALSE,
|
91
|
);
|
92
|
$field_name_relative = $this->createLinkField('page', $settings);
|
93
|
|
94
|
// Check the node edit form.
|
95
|
$this->drupalGet('node/add/page');
|
96
|
$this->assertField($field_name_absolute . '[und][0][title]', 'Title absolute found');
|
97
|
$this->assertField($field_name_absolute . '[und][0][url]', 'URL absolute found');
|
98
|
$this->assertField($field_name_relative . '[und][0][title]', 'Title relative found');
|
99
|
$this->assertField($field_name_relative . '[und][0][url]', 'URL relative found');
|
100
|
|
101
|
// Create test content.
|
102
|
$url_tests = array(
|
103
|
1 => array(
|
104
|
'href' => 'http://dummy.com/' . $this->randomName(),
|
105
|
'label' => $this->randomName(),
|
106
|
),
|
107
|
2 => array(
|
108
|
'href' => 'node/1',
|
109
|
'label' => $this->randomName(),
|
110
|
),
|
111
|
3 => array(
|
112
|
'href' => 'node/1?property=value',
|
113
|
'label' => $this->randomName(),
|
114
|
'query' => array('property' => 'value'),
|
115
|
),
|
116
|
4 => array(
|
117
|
'href' => 'node/1#position',
|
118
|
'label' => $this->randomName(),
|
119
|
'fragment' => 'position',
|
120
|
),
|
121
|
5 => array(
|
122
|
'href' => 'node/1?property=value2#lower',
|
123
|
'label' => $this->randomName(),
|
124
|
'fragment' => 'lower',
|
125
|
'query' => array('property' => 'value2'),
|
126
|
),
|
127
|
);
|
128
|
foreach ($url_tests as $index => &$input) {
|
129
|
$this->drupalGet('node/add/page');
|
130
|
|
131
|
$edit = array(
|
132
|
'title' => $input['label'],
|
133
|
$field_name_absolute . '[und][0][title]' => $input['label'],
|
134
|
$field_name_absolute . '[und][0][url]' => $input['href'],
|
135
|
$field_name_relative . '[und][0][title]' => $input['label'],
|
136
|
$field_name_relative . '[und][0][url]' => $input['href'],
|
137
|
);
|
138
|
$this->drupalPost(NULL, $edit, t('Save'));
|
139
|
$url = $this->getUrl();
|
140
|
$input['url'] = $url;
|
141
|
}
|
142
|
|
143
|
// Change to anonymous user.
|
144
|
$this->drupalLogout();
|
145
|
|
146
|
foreach (array_slice($url_tests, 1, NULL, TRUE) as $index => $input2) {
|
147
|
$node = node_load($index);
|
148
|
$this->assertNotEqual(NULL, $node, "Do we have a node?");
|
149
|
$this->assertEqual($node->nid, $index, "Test that we have a node.");
|
150
|
$this->drupalGet('node/' . $index);
|
151
|
|
152
|
$relative_expected = url('node/1', array('absolute' => FALSE) + $input2);
|
153
|
$absolute_expected = url('node/1', array('absolute' => TRUE) + $input2);
|
154
|
|
155
|
$absolute_result = $this->xpath('//*[contains(@class, "field-name-' . drupal_clean_css_identifier($field_name_absolute) . '")]/div/div/a/@href');
|
156
|
$absolute_result = (string) reset($absolute_result);
|
157
|
$this->assertEqual($absolute_result, $absolute_expected, "Absolute url output ('" . $absolute_result . "') looks as expected ('" . $absolute_expected . "')");
|
158
|
|
159
|
$relative_result = $this->xpath('//*[contains(@class, "field-name-' . drupal_clean_css_identifier($field_name_relative) . '")]/div/div/a/@href');
|
160
|
$relative_result = (string) reset($relative_result);
|
161
|
$this->assertEqual($relative_result, $relative_expected, "Relative url output ('" . $relative_result . "') looks as expected ('" . $relative_expected . "')");
|
162
|
}
|
163
|
|
164
|
// Check if this works with the alias too.
|
165
|
// Add a path alias for node 1.
|
166
|
$path = array(
|
167
|
'source' => 'node/1',
|
168
|
'alias' => $url_tests[1]['label'],
|
169
|
);
|
170
|
path_save($path);
|
171
|
// Another iteration over the same nodes - this time they should use the
|
172
|
// path alias.
|
173
|
foreach (array_slice($url_tests, 1, NULL, TRUE) as $index => $input2) {
|
174
|
$node = node_load($index);
|
175
|
$this->assertNotEqual(NULL, $node, "Do we have a node?");
|
176
|
$this->assertEqual($node->nid, $index, "Test that we have a node.");
|
177
|
$this->drupalGet('node/' . $index);
|
178
|
|
179
|
$relative_expected = url('node/1', array('absolute' => FALSE) + $input2);
|
180
|
$absolute_expected = url('node/1', array('absolute' => TRUE) + $input2);
|
181
|
|
182
|
$absolute_result = $this->xpath('//*[contains(@class, "field-name-' . drupal_clean_css_identifier($field_name_absolute) . '")]/div/div/a/@href');
|
183
|
$absolute_result = (string) reset($absolute_result);
|
184
|
$this->assertEqual($absolute_result, $absolute_expected, "Absolute alias-url output ('" . $absolute_result . "') looks as expected ('" . $absolute_expected . "')");
|
185
|
|
186
|
$relative_result = $this->xpath('//*[contains(@class, "field-name-' . drupal_clean_css_identifier($field_name_relative) . '")]/div/div/a/@href');
|
187
|
$relative_result = (string) reset($relative_result);
|
188
|
$this->assertEqual($relative_result, $relative_expected, "Relative alias-url output ('" . $relative_result . "') looks as expected ('" . $relative_expected . "')");
|
189
|
}
|
190
|
}
|
191
|
|
192
|
}
|