Révision 39a181a4
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/link/tests/link.token.test | ||
---|---|---|
6 | 6 |
*/ |
7 | 7 |
|
8 | 8 |
/** |
9 |
* Testing that tokens can be used in link titles |
|
9 |
* Testing that tokens can be used in link titles.
|
|
10 | 10 |
*/ |
11 | 11 |
class LinkTokenTest extends LinkBaseTestClass { |
12 | 12 |
|
13 |
/** |
|
14 |
* Get Info. |
|
15 |
*/ |
|
13 | 16 |
public static function getInfo() { |
14 | 17 |
return array( |
15 | 18 |
'name' => 'Link tokens - browser test', |
... | ... | |
19 | 22 |
); |
20 | 23 |
} |
21 | 24 |
|
22 |
function setUp($modules = array()) { |
|
25 |
/** |
|
26 |
* Setup. |
|
27 |
*/ |
|
28 |
public function setUp($modules = array()) { |
|
23 | 29 |
parent::setUp(array('token')); |
24 | 30 |
} |
25 | 31 |
|
26 | 32 |
/** |
27 | 33 |
* Creates a link field with a required title enabled for user-entered tokens. |
34 |
* |
|
28 | 35 |
* Creates a node with a token in the link title and checks the value. |
29 | 36 |
*/ |
30 |
function testUserTokenLinkCreate() { |
|
31 |
// create field
|
|
37 |
public function testUserTokenLinkCreate() {
|
|
38 |
// Create field.
|
|
32 | 39 |
$settings = array( |
33 | 40 |
'instance[settings][enable_tokens]' => 1, |
34 | 41 |
); |
35 | 42 |
$field_name = $this->createLinkField('page', |
36 |
$settings);
|
|
43 |
$settings); |
|
37 | 44 |
|
38 |
// create page form
|
|
45 |
// Create page form.
|
|
39 | 46 |
$this->drupalGet('node/add/page'); |
40 |
//$field_name = 'field_' . $name;
|
|
47 |
// $field_name = 'field_' . $name;.
|
|
41 | 48 |
$this->assertField($field_name . '[und][0][title]', 'Title found'); |
42 | 49 |
$this->assertField($field_name . '[und][0][url]', 'URL found'); |
43 | 50 |
|
44 | 51 |
$input = array( |
45 |
'href' => 'http://example.com/' . $this->randomName(),
|
|
46 |
'label' => $this->randomName(),
|
|
52 |
'href' => 'http://example.com/' . $this->randomName(), |
|
53 |
'label' => $this->randomName(), |
|
47 | 54 |
); |
48 | 55 |
|
49 |
//$this->drupalLogin($this->web_user);
|
|
56 |
// $this->drupalLogin($this->web_user);.
|
|
50 | 57 |
$this->drupalGet('node/add/page'); |
51 | 58 |
|
52 | 59 |
$edit = array( |
... | ... | |
57 | 64 |
$this->drupalPost(NULL, $edit, t('Save')); |
58 | 65 |
$url = $this->getUrl(); |
59 | 66 |
|
60 |
// change to anonymous user
|
|
67 |
// Change to anonymous user.
|
|
61 | 68 |
$this->drupalLogout(); |
62 | 69 |
$this->drupalGet($url); |
63 | 70 |
|
64 | 71 |
$this->assertRaw(l($input['label'] . ' page', $input['href'])); |
65 | 72 |
} |
66 | 73 |
|
67 |
|
|
68 | 74 |
/** |
69 | 75 |
* Creates a link field with a static title and an admin-entered token. |
76 |
* |
|
70 | 77 |
* Creates a node with a link and checks the title value. |
71 | 78 |
*/ |
72 |
function testStaticTokenLinkCreate() { |
|
79 |
public function testStaticTokenLinkCreate() {
|
|
73 | 80 |
|
74 |
// create field
|
|
81 |
// Create field.
|
|
75 | 82 |
$name = $this->randomName(); |
76 | 83 |
$settings = array( |
77 | 84 |
'instance[settings][title]' => 'value', |
78 |
'instance[settings][title_value]' => $name . ' [node:content-type:machine-name]'); |
|
85 |
'instance[settings][title_value]' => $name . ' [node:content-type:machine-name]', |
|
86 |
); |
|
79 | 87 |
$field_name = $this->createLinkField('page', $settings); |
80 | 88 |
|
81 |
// create page form
|
|
89 |
// Create page form.
|
|
82 | 90 |
$this->drupalGet('node/add/page'); |
83 | 91 |
$this->assertField($field_name . '[und][0][url]', 'URL found'); |
84 | 92 |
|
85 | 93 |
$input = array( |
86 |
'href' => 'http://example.com/' . $this->randomName() |
|
94 |
'href' => 'http://example.com/' . $this->randomName(),
|
|
87 | 95 |
); |
88 | 96 |
|
89 |
//$this->drupalLogin($this->web_user);
|
|
97 |
// $this->drupalLogin($this->web_user);.
|
|
90 | 98 |
$this->drupalGet('node/add/page'); |
91 | 99 |
|
92 | 100 |
$edit = array( |
... | ... | |
97 | 105 |
|
98 | 106 |
$url = $this->getUrl(); |
99 | 107 |
|
100 |
// change to anonymous user
|
|
108 |
// Change to anonymous user.
|
|
101 | 109 |
$this->drupalLogout(); |
102 | 110 |
$this->drupalGet($url); |
103 | 111 |
|
... | ... | |
106 | 114 |
|
107 | 115 |
/** |
108 | 116 |
* Creates a link field with a static title and an admin-entered token. |
117 |
* |
|
109 | 118 |
* Creates a node with a link and checks the title value. |
110 | 119 |
* |
111 | 120 |
* Basically, I want to make sure the [title-raw] token works, because it's a |
112 | 121 |
* token that changes from node to node, where [type]'s always going to be the |
113 | 122 |
* same. |
114 | 123 |
*/ |
115 |
function testStaticTokenLinkCreate2() { |
|
124 |
public function testStaticTokenLinkCreate2() {
|
|
116 | 125 |
|
117 |
// create field
|
|
126 |
// Create field.
|
|
118 | 127 |
$name = $this->randomName(); |
119 | 128 |
$settings = array( |
120 | 129 |
'instance[settings][title]' => 'value', |
121 |
'instance[settings][title_value]' => $name . ' [node:title]'); |
|
130 |
'instance[settings][title_value]' => $name . ' [node:title]', |
|
131 |
); |
|
122 | 132 |
$field_name = $this->createLinkField('page', $settings); |
123 | 133 |
|
124 |
// create page form
|
|
134 |
// Create page form.
|
|
125 | 135 |
$this->drupalGet('node/add/page'); |
126 | 136 |
$this->assertField($field_name . '[und][0][url]', 'URL found'); |
127 | 137 |
|
128 | 138 |
$input = array( |
129 |
'href' => 'http://example.com/' . $this->randomName() |
|
139 |
'href' => 'http://example.com/' . $this->randomName(),
|
|
130 | 140 |
); |
131 | 141 |
|
132 |
//$this->drupalLogin($this->web_user);
|
|
142 |
// $this->drupalLogin($this->web_user);.
|
|
133 | 143 |
$this->drupalGet('node/add/page'); |
134 | 144 |
|
135 | 145 |
$edit = array( |
... | ... | |
140 | 150 |
|
141 | 151 |
$url = $this->getUrl(); |
142 | 152 |
|
143 |
// change to anonymous user
|
|
153 |
// Change to anonymous user.
|
|
144 | 154 |
$this->drupalLogout(); |
145 | 155 |
$this->drupalGet($url); |
146 | 156 |
|
147 | 157 |
$this->assertRaw(l($name . ' ' . $name, $input['href'])); |
148 | 158 |
} |
149 | 159 |
|
150 |
// This test doesn't seem to actually work, due to lack of 'title' in url. |
|
151 |
function _test_Link_With_Title_Attribute_token_url_form() { |
|
152 |
/* $this->loginWithPermissions($this->permissions); |
|
160 |
/** |
|
161 |
* This test doesn't seem to actually work, due to lack of 'title' in url. |
|
162 |
* |
|
163 |
* @codingStandardsIgnoreStart |
|
164 |
*/ |
|
165 |
public function _test_Link_With_Title_Attribute_token_url_form() { |
|
166 |
// @codingStandardsIgnoreEnd |
|
167 |
/* $this->loginWithPermissions($this->permissions); |
|
153 | 168 |
$this->acquireContentTypes(1); |
154 | 169 |
$field_settings = array( |
155 |
'type' => 'link',
|
|
156 |
'widget_type' => 'link',
|
|
157 |
'type_name' => $this->content_types[0]->name,
|
|
158 |
'attributes' => array(
|
|
159 |
'class' => '',
|
|
160 |
'target' => 'default',
|
|
161 |
'rel' => 'nofollow',
|
|
162 |
'title' => '',
|
|
163 |
),
|
|
170 |
'type' => 'link', |
|
171 |
'widget_type' => 'link', |
|
172 |
'type_name' => $this->content_types[0]->name, |
|
173 |
'attributes' => array( |
|
174 |
'class' => '', |
|
175 |
'target' => 'default', |
|
176 |
'rel' => 'nofollow', |
|
177 |
'title' => '', |
|
178 |
), |
|
164 | 179 |
); |
165 | 180 |
|
166 | 181 |
$field = $this->createField($field_settings, 0); |
... | ... | |
170 | 185 |
$url_type = str_replace('_', '-', $this->content_types[0]->type); |
171 | 186 |
|
172 | 187 |
$edit = array('attributes[title]' => '['. $field_name .'-url]', |
173 |
'enable_tokens' => TRUE);
|
|
174 |
|
|
188 |
'enable_tokens' => TRUE); |
|
189 |
// @codingStandardsIgnoreLine |
|
175 | 190 |
$this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'], |
176 |
$edit, t('Save field settings'));
|
|
191 |
$edit, t('Save field settings')); |
|
177 | 192 |
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));*/ |
178 | 193 |
$name = $this->randomName(); |
179 | 194 |
$settings = array( |
... | ... | |
183 | 198 |
$field_name = $this->createLinkField('page', $settings); |
184 | 199 |
|
185 | 200 |
// So, having saved this field_name, let's see if it works... |
186 |
//$this->acquireNodes(1); |
|
187 |
|
|
188 |
//$node = node_load($this->nodes[0]->nid); |
|
189 |
|
|
190 |
//$this->drupalGet('node/'. $this->nodes[0]->nid); |
|
191 |
|
|
201 |
// $this->acquireNodes(1); |
|
202 |
// $node = node_load($this->nodes[0]->nid); |
|
203 |
// $this->drupalGet('node/'. $this->nodes[0]->nid);. |
|
192 | 204 |
$edit = array(); |
193 | 205 |
$test_link_url = 'http://www.example.com/test'; |
194 | 206 |
$edit[$field_name . '[und][0][url]'] = $test_link_url; |
... | ... | |
200 | 212 |
$this->drupalPost(NULL, $edit, t('Save')); |
201 | 213 |
|
202 | 214 |
// Make sure we get a new version! |
203 |
//$node = node_load($this->nodes[0]->nid, NULL, TRUE);
|
|
215 |
// $node = node_load($this->nodes[0]->nid, NULL, TRUE);.
|
|
204 | 216 |
$this->assertText(t('Basic page @title has been updated.', |
205 |
array('@title' => $name)));
|
|
217 |
array('@title' => $name))); |
|
206 | 218 |
|
207 |
//$this->drupalGet('node/'. $node->nid);
|
|
219 |
// $this->drupalGet('node/'. $node->nid);.
|
|
208 | 220 |
$this->assertText($title, 'Make sure the link title/text shows'); |
209 | 221 |
$this->assertRaw(' title="' . $test_link_url . '"', "Do we show the link url as the title attribute?"); |
210 | 222 |
$this->assertNoRaw(' title="[' . $field_name . '-url]"'); |
211 | 223 |
$this->assertTrue(module_exists('token'), t('Assure that Token Module is enabled.')); |
212 |
//$this->fail($this->content);
|
|
224 |
// $this->fail($this->content);.
|
|
213 | 225 |
} |
214 | 226 |
|
215 | 227 |
/** |
228 |
* Link With Title Attribute token title form. |
|
229 |
* |
|
216 | 230 |
* If the title of the link is set to the title attribute, then the title |
217 | 231 |
* attribute isn't supposed to show. |
232 |
* |
|
233 |
* @codingStandardsIgnoreStart |
|
218 | 234 |
*/ |
219 |
function _test_Link_With_Title_Attribute_token_title_form() { |
|
235 |
public function _test_Link_With_Title_Attribute_token_title_form() { |
|
236 |
// @codingStandardsIgnoreEnd |
|
220 | 237 |
$this->loginWithPermissions($this->permissions); |
221 | 238 |
$this->acquireContentTypes(1); |
222 | 239 |
$field_settings = array( |
... | ... | |
233 | 250 |
|
234 | 251 |
$field = $this->createField($field_settings, 0); |
235 | 252 |
$field_name = $field['field_name']; |
236 |
$field_db_info = content_database_info($field); |
|
237 | 253 |
$url_type = str_replace('_', '-', $this->content_types[0]->type); |
238 | 254 |
|
239 |
$edit = array('attributes[title]' => '[' . $field_name . '-title]', |
|
240 |
'enable_tokens' => TRUE); |
|
255 |
$edit = array( |
|
256 |
'attributes[title]' => '[' . $field_name . '-title]', |
|
257 |
'enable_tokens' => TRUE, |
|
258 |
); |
|
241 | 259 |
|
242 | 260 |
$this->drupalPost('admin/content/node-type/' . $url_type . '/fields/' . $field['field_name'], |
243 |
$edit, t('Save field settings'));
|
|
261 |
$edit, t('Save field settings')); |
|
244 | 262 |
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name']))); |
245 | 263 |
|
246 | 264 |
// So, having saved this field_name, let's see if it works... |
247 | 265 |
$this->acquireNodes(1); |
248 | 266 |
|
249 |
$node = node_load($this->nodes[0]->nid); |
|
250 |
|
|
251 | 267 |
$this->drupalGet('node/' . $this->nodes[0]->nid); |
252 | 268 |
|
253 | 269 |
$edit = array(); |
... | ... | |
260 | 276 |
// Make sure we get a new version! |
261 | 277 |
$node = node_load($this->nodes[0]->nid, NULL, TRUE); |
262 | 278 |
$this->assertText(t('@type @title has been updated.', |
263 |
array('@title' => $node->title, |
|
264 |
'@type' => $this->content_types[0]->name))); |
|
279 |
array( |
|
280 |
'@title' => $node->title, |
|
281 |
'@type' => $this->content_types[0]->name, |
|
282 |
))); |
|
265 | 283 |
|
266 | 284 |
$this->drupalGet('node/' . $node->nid); |
267 | 285 |
$this->assertText($title, 'Make sure the link title/text shows'); |
268 | 286 |
$this->assertNoRaw(' title="' . $title . '"', "We should not show the link title as the title attribute?"); |
269 | 287 |
$this->assertNoRaw(' title="[' . $field_name . '-title]"'); |
270 |
//$this->fail($this->content);
|
|
288 |
// $this->fail($this->content);.
|
|
271 | 289 |
} |
272 | 290 |
|
273 | 291 |
/** |
274 |
* Trying to set the url to contain a token. |
|
292 |
* Trying to set the url to contain a token. |
|
293 |
* |
|
294 |
* @codingStandardsIgnoreStart |
|
275 | 295 |
*/ |
276 |
function _testUserTokenLinkCreateInURL() { |
|
277 |
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); |
|
296 |
public function _testUserTokenLinkCreateInURL() { |
|
297 |
//@codingStandardsIgnoreEnd |
|
298 |
|
|
299 |
$this->web_user = $this->drupalCreateUser(array( |
|
300 |
'administer content types', |
|
301 |
'administer fields', |
|
302 |
'access content', |
|
303 |
'create page content', |
|
304 |
)); |
|
278 | 305 |
$this->drupalLogin($this->web_user); |
279 | 306 |
|
280 |
// create field
|
|
307 |
// Create field.
|
|
281 | 308 |
$name = strtolower($this->randomName()); |
282 | 309 |
$edit = array( |
283 | 310 |
'_add_new_field[label]' => $name, |
... | ... | |
288 | 315 |
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save')); |
289 | 316 |
$this->drupalPost(NULL, array( |
290 | 317 |
'title' => 'required', |
291 |
'enable_tokens' => 1), t('Save field settings')); |
|
318 |
'enable_tokens' => 1, |
|
319 |
), t('Save field settings')); |
|
292 | 320 |
|
293 | 321 |
// Is field created? |
294 | 322 |
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added'); |
295 | 323 |
|
296 |
// create page form
|
|
324 |
// Create page form.
|
|
297 | 325 |
$this->drupalGet('node/add/page'); |
298 | 326 |
$field_name = 'field_' . $name; |
299 | 327 |
$this->assertField($field_name . '[0][title]', 'Title found'); |
300 | 328 |
$this->assertField($field_name . '[0][url]', 'URL found'); |
301 | 329 |
|
302 | 330 |
$input = array( |
303 |
'href' => 'http://example.com/' . $this->randomName(),
|
|
304 |
'label' => $this->randomName(),
|
|
331 |
'href' => 'http://example.com/' . $this->randomName(), |
|
332 |
'label' => $this->randomName(), |
|
305 | 333 |
); |
306 | 334 |
|
307 | 335 |
$this->drupalLogin($this->web_user); |
... | ... | |
315 | 343 |
$this->drupalPost(NULL, $edit, t('Save')); |
316 | 344 |
$url = $this->getUrl(); |
317 | 345 |
|
318 |
// change to anonymous user
|
|
346 |
// Change to anonymous user.
|
|
319 | 347 |
$this->drupalLogout(); |
320 | 348 |
$this->drupalGet($url); |
321 | 349 |
|
322 | 350 |
$this->assertRaw(l($input['label'], $input['href'] . '/page')); |
323 |
//$this->fail($this->content);
|
|
351 |
// $this->fail($this->content);.
|
|
324 | 352 |
} |
325 | 353 |
|
326 | 354 |
/** |
327 |
* Trying to set the url to contain a token. |
|
355 |
* Trying to set the url to contain a token. |
|
356 |
* |
|
357 |
* @codingStandardsIgnoreStart |
|
328 | 358 |
*/ |
329 |
function _testUserTokenLinkCreateInURL2() { |
|
330 |
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); |
|
359 |
public function _testUserTokenLinkCreateInURL2() { |
|
360 |
// @codingStandardsIgnoreEnd |
|
361 |
|
|
362 |
$this->web_user = $this->drupalCreateUser(array( |
|
363 |
'administer content types', |
|
364 |
'administer fields', |
|
365 |
'access content', |
|
366 |
'create page content', |
|
367 |
)); |
|
331 | 368 |
$this->drupalLogin($this->web_user); |
332 | 369 |
|
333 |
// create field
|
|
370 |
// Create field.
|
|
334 | 371 |
$name = strtolower($this->randomName()); |
335 | 372 |
$edit = array( |
336 | 373 |
'_add_new_field[label]' => $name, |
... | ... | |
341 | 378 |
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save')); |
342 | 379 |
$this->drupalPost(NULL, array( |
343 | 380 |
'title' => 'required', |
344 |
'enable_tokens' => 1), t('Save field settings')); |
|
381 |
'enable_tokens' => 1, |
|
382 |
), t('Save field settings')); |
|
345 | 383 |
|
346 | 384 |
// Is field created? |
347 | 385 |
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added'); |
348 | 386 |
|
349 |
// create page form
|
|
387 |
// Create page form.
|
|
350 | 388 |
$this->drupalGet('node/add/page'); |
351 | 389 |
$field_name = 'field_' . $name; |
352 | 390 |
$this->assertField($field_name . '[0][title]', 'Title found'); |
353 | 391 |
$this->assertField($field_name . '[0][url]', 'URL found'); |
354 | 392 |
|
355 | 393 |
$input = array( |
356 |
'href' => 'http://example.com/' . $this->randomName(),
|
|
357 |
'label' => $this->randomName(),
|
|
394 |
'href' => 'http://example.com/' . $this->randomName(), |
|
395 |
'label' => $this->randomName(), |
|
358 | 396 |
); |
359 | 397 |
|
360 | 398 |
$this->drupalLogin($this->web_user); |
... | ... | |
368 | 406 |
$this->drupalPost(NULL, $edit, t('Save')); |
369 | 407 |
$url = $this->getUrl(); |
370 | 408 |
|
371 |
// change to anonymous user
|
|
409 |
// Change to anonymous user.
|
|
372 | 410 |
$this->drupalLogout(); |
373 | 411 |
$this->drupalGet($url); |
374 | 412 |
|
375 | 413 |
$this->assertRaw(l($input['label'], $input['href'] . '/' . $this->web_user->uid)); |
376 | 414 |
} |
377 |
|
|
415 |
|
|
378 | 416 |
/** |
379 |
* Test that if you have a title and no url on a field which does not have tokens enabled, |
|
380 |
* that the title is sanitized once. |
|
417 |
* CRUD Title Only Title No Link. |
|
418 |
* |
|
419 |
* Test that if you have a title and no url on a field which does not have |
|
420 |
* tokens enabled, that the title is sanitized once. |
|
421 |
* |
|
422 |
* @codingStandardsIgnoreStart |
|
381 | 423 |
*/ |
382 |
function testCRUDTitleOnlyTitleNoLink2() { |
|
383 |
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); |
|
424 |
public function testCRUDTitleOnlyTitleNoLink2() { |
|
425 |
//@codingStandardsIgnoreEnd |
|
426 |
|
|
427 |
$this->web_user = $this->drupalCreateUser(array( |
|
428 |
'administer content types', |
|
429 |
'administer fields', |
|
430 |
'access content', |
|
431 |
'create page content', |
|
432 |
)); |
|
433 |
|
|
384 | 434 |
$this->drupalLogin($this->web_user); |
385 | 435 |
|
386 |
// create field
|
|
436 |
// Create field.
|
|
387 | 437 |
$name = strtolower($this->randomName()); |
388 | 438 |
$field_name = 'field_' . $name; |
389 | 439 |
$edit = array( |
... | ... | |
401 | 451 |
|
402 | 452 |
// Is field created? |
403 | 453 |
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added'); |
404 |
|
|
405 |
// create page form
|
|
454 |
|
|
455 |
// Create page form.
|
|
406 | 456 |
$this->drupalGet('node/add/page'); |
407 | 457 |
$this->assertField($field_name . '[und][0][url]', 'URL found'); |
408 | 458 |
|
... | ... | |
419 | 469 |
$this->drupalPost(NULL, $edit, t('Save')); |
420 | 470 |
|
421 | 471 |
$url = $this->getUrl(); |
422 |
|
|
423 |
// change to anonymous user
|
|
472 |
|
|
473 |
// Change to anonymous user.
|
|
424 | 474 |
$this->drupalLogout(); |
425 | 475 |
$this->drupalGet($url); |
426 | 476 |
|
427 | 477 |
$this->assertRaw('This & That'); |
428 | 478 |
} |
429 |
|
|
430 |
|
|
479 |
|
|
431 | 480 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules