Révision 39a181a4
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/link/tests/link.attribute.test | ||
---|---|---|
5 | 5 |
* Basic simpletests to test options on link module. |
6 | 6 |
*/ |
7 | 7 |
|
8 |
/** |
|
9 |
* Attribute Crud Test. |
|
10 |
*/ |
|
8 | 11 |
class LinkAttributeCrudTest extends DrupalWebTestCase { |
12 |
|
|
9 | 13 |
private $zebra; |
10 | 14 |
|
11 | 15 |
protected $permissions = array( |
... | ... | |
19 | 23 |
'access administration pages', |
20 | 24 |
); |
21 | 25 |
|
26 |
/** |
|
27 |
* Get Info. |
|
28 |
*/ |
|
22 | 29 |
public static function getInfo() { |
23 | 30 |
return array( |
24 | 31 |
'name' => 'Link Attribute Tests', |
... | ... | |
27 | 34 |
); |
28 | 35 |
} |
29 | 36 |
|
30 |
function setup() { |
|
37 |
/** |
|
38 |
* Setup. |
|
39 |
*/ |
|
40 |
public function setup() { |
|
31 | 41 |
parent::setup('field_ui', 'link'); |
32 | 42 |
$this->zebra = 0; |
33 | 43 |
// Create and login user. |
34 |
$this->web_user = $this->drupalCreateUser(array('administer content types')); |
|
44 |
$this->web_user = $this->drupalCreateUser(array( |
|
45 |
'administer content types', |
|
46 |
'administer fields', |
|
47 |
)); |
|
35 | 48 |
$this->drupalLogin($this->web_user); |
36 | 49 |
} |
37 | 50 |
|
51 |
/** |
|
52 |
* Create Link. |
|
53 |
*/ |
|
38 | 54 |
protected function createLink($url, $title, $attributes = array()) { |
39 | 55 |
return array( |
40 | 56 |
'url' => $url, |
... | ... | |
43 | 59 |
); |
44 | 60 |
} |
45 | 61 |
|
62 |
/** |
|
63 |
* Assert Link On Node. |
|
64 |
*/ |
|
46 | 65 |
protected function assertLinkOnNode($field_name, $link_value, $message = '', $group = 'Other') { |
47 | 66 |
$this->zebra++; |
48 | 67 |
$zebra_string = ($this->zebra % 2 == 0) ? 'even' : 'odd'; |
49 | 68 |
$cssFieldLocator = 'field-' . str_replace('_', '-', $field_name); |
50 | 69 |
$this->assertPattern('@<div class="field field-type-link ' . $cssFieldLocator . '".*<div class="field-item ' . $zebra_string . '">\s*' . $link_value . '\s*</div>@is', |
51 |
$message,
|
|
52 |
$group);
|
|
70 |
$message, |
|
71 |
$group); |
|
53 | 72 |
} |
54 | 73 |
|
55 | 74 |
/** |
56 |
* A simple test that just creates a new node type, adds a link field to it, creates a new node of that type, and makes sure |
|
57 |
* that the node is being displayed. |
|
75 |
* Test Basic. |
|
76 |
* |
|
77 |
* A simple test that just creates a new node type, adds a link field to it, |
|
78 |
* creates a new node of that type, and makes sure that the node is being |
|
79 |
* displayed. |
|
58 | 80 |
*/ |
59 |
function testBasic() { |
|
81 |
public function testBasic() {
|
|
60 | 82 |
$content_type_friendly = $this->randomName(20); |
61 | 83 |
$content_type_machine = strtolower($this->randomName(10)); |
62 | 84 |
$title = $this->randomName(20); |
... | ... | |
76 | 98 |
// Now add a singleton field. |
77 | 99 |
$single_field_name_friendly = $this->randomName(20); |
78 | 100 |
$single_field_name_machine = strtolower($this->randomName(10)); |
79 |
$single_field_name = 'field_' . $single_field_name_machine; |
|
101 |
|
|
80 | 102 |
$edit = array( |
81 | 103 |
'fields[_add_new_field][label]' => $single_field_name_friendly, |
82 | 104 |
'fields[_add_new_field][field_name]' => $single_field_name_machine, |
... | ... | |
101 | 123 |
$this->assertTrue($type_exists, 'The new content type has been created in the database.'); |
102 | 124 |
|
103 | 125 |
$permission = 'create ' . $content_type_machine . ' content'; |
104 |
$permission_edit = 'edit ' . $content_type_machine . ' content'; |
|
126 |
|
|
105 | 127 |
// Reset the permissions cache. |
106 | 128 |
$this->checkPermissions(array($permission), TRUE); |
107 | 129 |
|
... | ... | |
122 | 144 |
); |
123 | 145 |
|
124 | 146 |
$this->drupalPost(NULL, $edit, t('Save')); |
125 |
$this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $title))); |
|
147 |
$this->assertText(t('@content_type_friendly @title has been created', array( |
|
148 |
'@content_type_friendly' => $content_type_friendly, |
|
149 |
'@title' => $title, |
|
150 |
))); |
|
126 | 151 |
|
127 | 152 |
$this->drupalGet('node/add/' . $content_type_machine); |
128 | 153 |
|
... | ... | |
135 | 160 |
|
136 | 161 |
// Now we can fill in the second item in the multivalue field and save. |
137 | 162 |
$this->drupalPost(NULL, $edit, t('Save')); |
138 |
$this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $title))); |
|
163 |
$this->assertText(t('@content_type_friendly @title has been created', array( |
|
164 |
'@content_type_friendly' => $content_type_friendly, |
|
165 |
'@title' => $title, |
|
166 |
))); |
|
139 | 167 |
|
140 | 168 |
$this->assertText('Display'); |
141 | 169 |
$this->assertLinkByHref('http://www.example.com'); |
142 | 170 |
} |
143 | 171 |
|
172 |
/** |
|
173 |
* Create Simple Link Field. |
|
174 |
*/ |
|
144 | 175 |
protected function createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine) { |
145 | 176 |
$this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/fields'); |
146 | 177 |
$edit = array( |
... | ... | |
166 | 197 |
$this->assertTrue($type_exists, 'The new content type has been created in the database.'); |
167 | 198 |
} |
168 | 199 |
|
200 |
/** |
|
201 |
* Create Node Type User. |
|
202 |
*/ |
|
169 | 203 |
protected function createNodeTypeUser($content_type_machine) { |
170 | 204 |
$permission = 'create ' . $content_type_machine . ' content'; |
171 |
$permission_edit = 'edit ' . $content_type_machine . ' content'; |
|
172 | 205 |
// Reset the permissions cache. |
173 | 206 |
$this->checkPermissions(array($permission), TRUE); |
174 | 207 |
|
... | ... | |
179 | 212 |
$this->drupalLogin($this->web_user); |
180 | 213 |
} |
181 | 214 |
|
215 |
/** |
|
216 |
* Create Node For Testing. |
|
217 |
*/ |
|
182 | 218 |
protected function createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $title, $url, $node_title = '') { |
183 | 219 |
$this->drupalGet('node/add/' . $content_type_machine); |
184 | 220 |
|
... | ... | |
196 | 232 |
} |
197 | 233 |
|
198 | 234 |
$this->drupalPost(NULL, $edit, t('Save')); |
199 |
$this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $node_title))); |
|
235 |
$this->assertText(t('@content_type_friendly @title has been created', array( |
|
236 |
'@content_type_friendly' => $content_type_friendly, |
|
237 |
'@title' => $node_title, |
|
238 |
))); |
|
200 | 239 |
|
201 | 240 |
} |
202 | 241 |
|
203 | 242 |
/** |
204 | 243 |
* Test the link_plain formatter and it's output. |
205 | 244 |
*/ |
206 |
function testFormatterPlain() { |
|
245 |
public function testFormatterPlain() {
|
|
207 | 246 |
$content_type_friendly = $this->randomName(20); |
208 | 247 |
$content_type_machine = strtolower($this->randomName(10)); |
209 | 248 |
|
... | ... | |
215 | 254 |
// Now add a singleton field. |
216 | 255 |
$single_field_name_friendly = $this->randomName(20); |
217 | 256 |
$single_field_name_machine = strtolower($this->randomName(10)); |
218 |
//$single_field_name = 'field_'. $single_field_name_machine;
|
|
257 |
// $single_field_name = 'field_'. $single_field_name_machine;.
|
|
219 | 258 |
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); |
220 | 259 |
|
221 | 260 |
// Okay, now we want to make sure this display is changed: |
... | ... | |
227 | 266 |
$this->drupalPost(NULL, $edit, t('Save')); |
228 | 267 |
|
229 | 268 |
$this->createNodeTypeUser($content_type_machine); |
230 |
|
|
269 |
|
|
231 | 270 |
$link_tests = array( |
232 | 271 |
'plain' => array( |
233 | 272 |
'text' => 'Display', |
... | ... | |
243 | 282 |
), |
244 | 283 |
); |
245 | 284 |
|
246 |
foreach ($link_tests as $key => $link_test) {
|
|
285 |
foreach ($link_tests as $link_test) { |
|
247 | 286 |
$link_text = $link_test['text']; |
248 | 287 |
$link_url = $link_test['url']; |
249 | 288 |
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); |
250 |
|
|
289 |
|
|
251 | 290 |
$this->assertText($link_url); |
252 | 291 |
$this->assertNoText($link_text); |
253 | 292 |
$this->assertNoLinkByHref($link_url); |
254 | 293 |
} |
255 | 294 |
} |
256 | 295 |
|
257 |
function testFormatterHost() { |
|
296 |
/** |
|
297 |
* Formatter Host. |
|
298 |
*/ |
|
299 |
public function testFormatterHost() { |
|
258 | 300 |
$content_type_friendly = $this->randomName(20); |
259 | 301 |
$content_type_machine = strtolower($this->randomName(10)); |
260 | 302 |
|
... | ... | |
263 | 305 |
'name' => $content_type_friendly, |
264 | 306 |
)); |
265 | 307 |
|
266 |
|
|
267 | 308 |
// Now add a singleton field. |
268 | 309 |
$single_field_name_friendly = $this->randomName(20); |
269 | 310 |
$single_field_name_machine = strtolower($this->randomName(10)); |
270 |
//$single_field_name = 'field_'. $single_field_name_machine;
|
|
311 |
// $single_field_name = 'field_'. $single_field_name_machine;.
|
|
271 | 312 |
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); |
272 | 313 |
|
273 | 314 |
// Okay, now we want to make sure this display is changed: |
274 |
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
|
|
315 |
$this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display');
|
|
275 | 316 |
$edit = array( |
276 |
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
|
|
277 |
'fields[field_'. $single_field_name_machine .'][type]' => 'link_host',
|
|
317 |
'fields[field_' . $single_field_name_machine . '][label]' => 'above',
|
|
318 |
'fields[field_' . $single_field_name_machine . '][type]' => 'link_host',
|
|
278 | 319 |
); |
279 | 320 |
$this->drupalPost(NULL, $edit, t('Save')); |
280 | 321 |
|
... | ... | |
289 | 330 |
$this->assertNoLinkByHref($link_url); |
290 | 331 |
} |
291 | 332 |
|
292 |
function testFormatterURL() { |
|
333 |
/** |
|
334 |
* Formatter URL. |
|
335 |
* |
|
336 |
* @codingStandardsIgnoreStart |
|
337 |
*/ |
|
338 |
public function testFormatterURL() { |
|
339 |
// @codingStandardsIgnoreEnd |
|
293 | 340 |
$content_type_friendly = $this->randomName(20); |
294 | 341 |
$content_type_machine = strtolower($this->randomName(10)); |
295 | 342 |
|
... | ... | |
301 | 348 |
// Now add a singleton field. |
302 | 349 |
$single_field_name_friendly = $this->randomName(20); |
303 | 350 |
$single_field_name_machine = strtolower($this->randomName(10)); |
304 |
//$single_field_name = 'field_'. $single_field_name_machine;
|
|
351 |
// $single_field_name = 'field_'. $single_field_name_machine;.
|
|
305 | 352 |
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); |
306 | 353 |
|
307 | 354 |
// Okay, now we want to make sure this display is changed: |
... | ... | |
313 | 360 |
$this->drupalPost(NULL, $edit, t('Save')); |
314 | 361 |
|
315 | 362 |
$this->createNodeTypeUser($content_type_machine); |
316 |
|
|
363 |
|
|
317 | 364 |
$link_tests = array( |
318 | 365 |
'plain' => array( |
319 | 366 |
'text' => 'Display', |
... | ... | |
329 | 376 |
), |
330 | 377 |
); |
331 | 378 |
|
332 |
foreach ($link_tests as $key => $link_test) {
|
|
379 |
foreach ($link_tests as $link_test) { |
|
333 | 380 |
$link_text = $link_test['text']; |
334 | 381 |
$link_url = $link_test['url']; |
335 | 382 |
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); |
336 |
|
|
383 |
|
|
337 | 384 |
$this->assertNoText($link_text); |
338 | 385 |
$this->assertLinkByHref($link_url); |
339 | 386 |
} |
340 | 387 |
} |
341 | 388 |
|
342 |
function testFormatterShort() { |
|
389 |
/** |
|
390 |
* Formatter Short. |
|
391 |
*/ |
|
392 |
public function testFormatterShort() { |
|
343 | 393 |
$content_type_friendly = $this->randomName(20); |
344 | 394 |
$content_type_machine = strtolower($this->randomName(10)); |
345 | 395 |
|
... | ... | |
351 | 401 |
// Now add a singleton field. |
352 | 402 |
$single_field_name_friendly = $this->randomName(20); |
353 | 403 |
$single_field_name_machine = strtolower($this->randomName(10)); |
354 |
//$single_field_name = 'field_'. $single_field_name_machine;
|
|
404 |
// $single_field_name = 'field_'. $single_field_name_machine;.
|
|
355 | 405 |
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); |
356 | 406 |
|
357 | 407 |
// Okay, now we want to make sure this display is changed: |
... | ... | |
379 | 429 |
), |
380 | 430 |
); |
381 | 431 |
|
382 |
foreach ($link_tests as $key => $link_test) {
|
|
432 |
foreach ($link_tests as $link_test) { |
|
383 | 433 |
$link_text = $link_test['text']; |
384 | 434 |
$link_url = $link_test['url']; |
385 | 435 |
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); |
386 |
|
|
436 |
|
|
387 | 437 |
$this->assertText('Link'); |
388 | 438 |
$this->assertNoText($link_text); |
389 | 439 |
$this->assertLinkByHref($link_url); |
390 | 440 |
} |
391 | 441 |
} |
392 | 442 |
|
393 |
function testFormatterLabel() { |
|
443 |
/** |
|
444 |
* Formatter Label. |
|
445 |
*/ |
|
446 |
public function testFormatterLabel() { |
|
394 | 447 |
$content_type_friendly = $this->randomName(20); |
395 | 448 |
$content_type_machine = strtolower($this->randomName(10)); |
396 | 449 |
|
... | ... | |
402 | 455 |
// Now add a singleton field. |
403 | 456 |
$single_field_name_friendly = $this->randomName(20); |
404 | 457 |
$single_field_name_machine = strtolower($this->randomName(10)); |
405 |
//$single_field_name = 'field_'. $single_field_name_machine;
|
|
458 |
// $single_field_name = 'field_'. $single_field_name_machine;.
|
|
406 | 459 |
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); |
407 | 460 |
|
408 | 461 |
// Okay, now we want to make sure this display is changed: |
... | ... | |
430 | 483 |
), |
431 | 484 |
); |
432 | 485 |
|
433 |
foreach ($link_tests as $key => $link_test) {
|
|
486 |
foreach ($link_tests as $link_test) { |
|
434 | 487 |
$link_text = $link_test['text']; |
435 |
$link_url = $link_test['url'];
|
|
488 |
$link_url = $link_test['url']; |
|
436 | 489 |
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); |
437 |
|
|
490 |
|
|
438 | 491 |
$this->assertNoText($link_text); |
439 | 492 |
$this->assertText($single_field_name_friendly); |
440 | 493 |
$this->assertLinkByHref($link_url); |
441 | 494 |
} |
442 | 495 |
} |
443 | 496 |
|
444 |
function testFormatterSeparate() { |
|
497 |
/** |
|
498 |
* Formatter Separate. |
|
499 |
*/ |
|
500 |
public function testFormatterSeparate() { |
|
445 | 501 |
$content_type_friendly = $this->randomName(20); |
446 | 502 |
$content_type_machine = strtolower($this->randomName(10)); |
447 | 503 |
|
... | ... | |
453 | 509 |
// Now add a singleton field. |
454 | 510 |
$single_field_name_friendly = $this->randomName(20); |
455 | 511 |
$single_field_name_machine = strtolower($this->randomName(10)); |
456 |
//$single_field_name = 'field_'. $single_field_name_machine;
|
|
512 |
// $single_field_name = 'field_'. $single_field_name_machine;.
|
|
457 | 513 |
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); |
458 | 514 |
|
459 | 515 |
// Okay, now we want to make sure this display is changed: |
... | ... | |
482 | 538 |
), |
483 | 539 |
); |
484 | 540 |
|
485 |
foreach ($link_tests as $key => $link_test) {
|
|
541 |
foreach ($link_tests as $link_test) { |
|
486 | 542 |
$link_text = $link_test['text']; |
487 | 543 |
$link_url = $link_test['url']; |
488 | 544 |
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); |
489 |
|
|
545 |
|
|
490 | 546 |
$this->assertText($link_text); |
491 | 547 |
$this->assertLink($plain_url); |
492 | 548 |
$this->assertLinkByHref($link_url); |
493 | 549 |
} |
494 | 550 |
} |
495 |
|
|
496 |
function testFormatterPlainTitle() { |
|
551 |
|
|
552 |
/** |
|
553 |
* Formatter Plain Title. |
|
554 |
*/ |
|
555 |
public function testFormatterPlainTitle() { |
|
497 | 556 |
$content_type_friendly = $this->randomName(20); |
498 | 557 |
$content_type_machine = strtolower($this->randomName(10)); |
499 |
|
|
558 |
|
|
500 | 559 |
$this->drupalCreateContentType(array( |
501 | 560 |
'type' => $content_type_machine, |
502 | 561 |
'name' => $content_type_friendly, |
503 | 562 |
)); |
504 |
|
|
563 |
|
|
505 | 564 |
// Now add a singleton field. |
506 | 565 |
$single_field_name_friendly = $this->randomName(20); |
507 | 566 |
$single_field_name_machine = strtolower($this->randomName(10)); |
508 |
//$single_field_name = 'field_'. $single_field_name_machine;
|
|
567 |
// $single_field_name = 'field_'. $single_field_name_machine;.
|
|
509 | 568 |
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); |
510 |
|
|
569 |
|
|
511 | 570 |
// Okay, now we want to make sure this display is changed: |
512 | 571 |
$this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display'); |
513 | 572 |
$edit = array( |
... | ... | |
515 | 574 |
'fields[field_' . $single_field_name_machine . '][type]' => 'link_title_plain', |
516 | 575 |
); |
517 | 576 |
$this->drupalPost(NULL, $edit, t('Save')); |
518 |
|
|
577 |
|
|
519 | 578 |
$this->createNodeTypeUser($content_type_machine); |
520 |
|
|
579 |
|
|
521 | 580 |
$link_text = 'Display'; |
522 | 581 |
$link_url = 'http://www.example.com/'; |
523 | 582 |
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); |
524 |
|
|
583 |
|
|
525 | 584 |
$this->assertText($link_text); |
526 | 585 |
$this->assertNoText($link_url); |
527 | 586 |
$this->assertNoLinkByHref($link_url); |
528 | 587 |
} |
588 |
|
|
529 | 589 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules