Révision 39a181a4
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/link/tests/link.crud_browser.test | ||
---|---|---|
6 | 6 |
*/ |
7 | 7 |
|
8 | 8 |
/** |
9 |
* Testing that users can not input bad URLs or labels |
|
9 |
* Testing that users can not input bad URLs or labels.
|
|
10 | 10 |
*/ |
11 | 11 |
class LinkUITest extends DrupalWebTestcase { |
12 | 12 |
|
13 | 13 |
/** |
14 |
* Link supposed to be good |
|
14 |
* Link supposed to be good.
|
|
15 | 15 |
*/ |
16 | 16 |
const LINK_INPUT_TYPE_GOOD = 0; |
17 | 17 |
|
18 | 18 |
/** |
19 |
* Link supposed to have a bad title |
|
19 |
* Link supposed to have a bad title.
|
|
20 | 20 |
*/ |
21 | 21 |
const LINK_INPUT_TYPE_BAD_TITLE = 1; |
22 | 22 |
|
23 | 23 |
/** |
24 |
* Link supposed to have a bad URL |
|
24 |
* Link supposed to have a bad URL.
|
|
25 | 25 |
*/ |
26 | 26 |
const LINK_INPUT_TYPE_BAD_URL = 2; |
27 | 27 |
|
28 |
/** |
|
29 |
* Get Info. |
|
30 |
*/ |
|
28 | 31 |
public static function getInfo() { |
29 | 32 |
return array( |
30 | 33 |
'name' => 'Link CRUD - browser test', |
... | ... | |
33 | 36 |
); |
34 | 37 |
} |
35 | 38 |
|
36 |
function setUp() { |
|
39 |
/** |
|
40 |
* Setup. |
|
41 |
*/ |
|
42 |
public function setUp() { |
|
37 | 43 |
parent::setUp('field_ui', 'link'); |
38 | 44 |
} |
39 | 45 |
|
40 | 46 |
/** |
41 | 47 |
* Creates a link field for the "page" type and creates a page with a link. |
42 | 48 |
*/ |
43 |
function testLinkCreate() { |
|
44 |
//libxml_use_internal_errors(true); |
|
49 |
public function testLinkCreate() {
|
|
50 |
// libxml_use_internal_errors(true);
|
|
45 | 51 |
$this->web_user = $this->drupalCreateUser(array( |
46 | 52 |
'administer content types', |
53 |
'administer fields', |
|
47 | 54 |
'administer nodes', |
48 | 55 |
'administer filters', |
49 | 56 |
'access content', |
50 | 57 |
'create page content', |
51 |
'access administration pages' |
|
58 |
'access administration pages',
|
|
52 | 59 |
)); |
53 | 60 |
$this->drupalLogin($this->web_user); |
54 | 61 |
|
55 |
// create field
|
|
62 |
// Create field.
|
|
56 | 63 |
$name = strtolower($this->randomName()); |
57 | 64 |
$edit = array( |
58 | 65 |
'fields[_add_new_field][label]' => $name, |
... | ... | |
72 | 79 |
$permission = 'create page content'; |
73 | 80 |
$this->checkPermissions(array($permission), TRUE); |
74 | 81 |
|
75 |
// create page form
|
|
76 |
//$this->drupalGet('node/add');
|
|
82 |
// Create page form
|
|
83 |
// $this->drupalGet('node/add');.
|
|
77 | 84 |
$this->drupalGet('node/add/page'); |
78 | 85 |
$field_name = 'field_' . $name; |
79 | 86 |
$this->assertField('edit-field-' . $name . '-und-0-title', 'Title found'); |
... | ... | |
84 | 91 |
'href' => 'http://example.com/' . $this->randomName(), |
85 | 92 |
'label' => $this->randomName(), |
86 | 93 |
'msg' => 'Link found', |
87 |
'type' => self::LINK_INPUT_TYPE_GOOD |
|
94 |
'type' => self::LINK_INPUT_TYPE_GOOD,
|
|
88 | 95 |
), |
89 | 96 |
array( |
90 | 97 |
'href' => 'http://example.com/' . $this->randomName(), |
91 | 98 |
'label' => $this->randomName() . '<script>alert("hi");</script>', |
92 | 99 |
'msg' => 'js label', |
93 |
'type' => self::LINK_INPUT_TYPE_BAD_TITLE |
|
100 |
'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
|
|
94 | 101 |
), |
95 | 102 |
array( |
96 | 103 |
'href' => 'http://example.com/' . $this->randomName(), |
97 | 104 |
'label' => $this->randomName() . '<script src="http://devil.site.com"></script>', |
98 | 105 |
'msg' => 'js label', |
99 |
'type' => self::LINK_INPUT_TYPE_BAD_TITLE |
|
106 |
'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
|
|
100 | 107 |
), |
101 | 108 |
array( |
102 | 109 |
'href' => 'http://example.com/' . $this->randomName(), |
103 | 110 |
'label' => $this->randomName() . '" onmouseover="alert(\'hi\')', |
104 | 111 |
'msg' => 'js label', |
105 |
'type' => self::LINK_INPUT_TYPE_BAD_TITLE |
|
112 |
'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
|
|
106 | 113 |
), |
107 | 114 |
array( |
108 | 115 |
'href' => 'http://example.com/' . $this->randomName(), |
109 | 116 |
'label' => $this->randomName() . '\' onmouseover="alert(\'hi\')', |
110 | 117 |
'msg' => 'js label', |
111 |
'type' => self::LINK_INPUT_TYPE_BAD_TITLE |
|
118 |
'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
|
|
112 | 119 |
), |
113 | 120 |
array( |
114 | 121 |
'href' => 'javascript:alert("http://example.com/' . $this->randomName() . '")', |
115 | 122 |
'label' => $this->randomName(), |
116 | 123 |
'msg' => 'js url', |
117 |
'type' => self::LINK_INPUT_TYPE_BAD_URL |
|
124 |
'type' => self::LINK_INPUT_TYPE_BAD_URL,
|
|
118 | 125 |
), |
119 | 126 |
array( |
120 | 127 |
'href' => 'http://ecs-es.kelkoo.es/ctl/go/sitesearchGo?.ts=1338833010331&.sig=qP9GXeEFH6syBzwmzYkxmsvp1EI-', |
... | ... | |
143 | 150 |
); |
144 | 151 |
$this->drupalPost(NULL, $edit, t('Save')); |
145 | 152 |
if ($input['type'] == self::LINK_INPUT_TYPE_BAD_URL) { |
146 |
$this->assertRaw(t('The value %value provided for %field is not a valid URL.', array('%field' => $name, '%value' => trim($input['href']))), 'Not a valid URL: ' . $input['href']); |
|
153 |
$this->assertRaw(t('The value %value provided for %field is not a valid URL.', array( |
|
154 |
'%field' => $name, |
|
155 |
'%value' => trim($input['href']), |
|
156 |
)), 'Not a valid URL: ' . $input['href']); |
|
147 | 157 |
continue; |
148 | 158 |
} |
149 | 159 |
else { |
150 | 160 |
$this->assertRaw(' ' . t('has been created.', |
151 |
array('@type' => 'Basic Page', '%title' => $edit['title'])),
|
|
152 |
'Page created: ' . $input['href']);
|
|
161 |
array('@type' => 'Basic Page', '%title' => $edit['title'])), |
|
162 |
'Page created: ' . $input['href']); |
|
153 | 163 |
} |
154 | 164 |
$url = $this->getUrl(); |
155 | 165 |
|
156 |
// change to Anonymous user.
|
|
166 |
// Change to Anonymous user.
|
|
157 | 167 |
$this->drupalLogout(); |
158 | 168 |
|
159 | 169 |
$this->drupalGet($url); |
160 |
//debug($this); |
|
161 |
// If simpletest starts using something to override the error system, this will flag
|
|
162 |
// us and let us know it's broken. |
|
170 |
// debug($this);
|
|
171 |
// If simpletest starts using something to override the error system, this |
|
172 |
// will flag us and let us know it's broken.
|
|
163 | 173 |
$this->assertFalse(libxml_use_internal_errors(TRUE)); |
164 | 174 |
if (isset($input['expected_href'])) { |
165 | 175 |
$path = '//a[@href="' . $input['expected_href'] . '" and text()="' . $input['label'] . '"]'; |
... | ... | |
171 | 181 |
libxml_use_internal_errors(FALSE); |
172 | 182 |
$this->assertIdentical(isset($elements[0]), $input['type'] == self::LINK_INPUT_TYPE_GOOD, $input['msg']); |
173 | 183 |
} |
174 |
//libxml_use_internal_errors(FALSE); |
|
184 |
// libxml_use_internal_errors(FALSE);
|
|
175 | 185 |
} |
176 | 186 |
|
177 | 187 |
/** |
188 |
* Static Link Create. |
|
189 |
* |
|
178 | 190 |
* Testing that if you use <strong> in a static title for your link, that the |
179 | 191 |
* title actually displays <strong>. |
180 | 192 |
*/ |
181 |
function testStaticLinkCreate() { |
|
182 |
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); |
|
193 |
public function testStaticLinkCreate() { |
|
194 |
|
|
195 |
$this->web_user = $this->drupalCreateUser(array( |
|
196 |
'administer content types', |
|
197 |
'administer fields', |
|
198 |
'access content', |
|
199 |
'create page content', |
|
200 |
)); |
|
201 |
|
|
183 | 202 |
$this->drupalLogin($this->web_user); |
184 | 203 |
|
185 |
// create field
|
|
204 |
// Create field.
|
|
186 | 205 |
$name = strtolower($this->randomName()); |
187 | 206 |
$field_name = 'field_' . $name; |
188 | 207 |
$edit = array( |
... | ... | |
195 | 214 |
$this->drupalPost(NULL, array(), t('Save field settings')); |
196 | 215 |
$this->drupalPost(NULL, array( |
197 | 216 |
'instance[settings][title]' => 'value', |
198 |
'instance[settings][title_value]' => '<strong>' . $name . '</strong>'), t('Save settings')); |
|
217 |
'instance[settings][title_value]' => '<strong>' . $name . '</strong>', |
|
218 |
), t('Save settings')); |
|
199 | 219 |
|
200 | 220 |
// Is field created? |
201 | 221 |
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added'); |
202 | 222 |
|
203 |
// create page form
|
|
223 |
// Create page form.
|
|
204 | 224 |
$this->drupalGet('node/add/page'); |
205 | 225 |
$this->assertField($field_name . '[und][0][url]', 'URL found'); |
206 | 226 |
|
207 | 227 |
$input = array( |
208 |
'href' => 'http://example.com/' . $this->randomName() |
|
228 |
'href' => 'http://example.com/' . $this->randomName(),
|
|
209 | 229 |
); |
210 | 230 |
|
211 | 231 |
$edit = array( |
... | ... | |
216 | 236 |
|
217 | 237 |
$url = $this->getUrl(); |
218 | 238 |
|
219 |
// change to anonymous user
|
|
239 |
// Change to anonymous user.
|
|
220 | 240 |
$this->drupalLogout(); |
221 | 241 |
$this->drupalGet($url); |
222 | 242 |
|
223 | 243 |
$this->assertRaw(l('<strong>' . $name . '</strong>', $input['href'], array('html' => TRUE))); |
224 | 244 |
} |
225 |
|
|
245 |
|
|
226 | 246 |
/** |
227 |
* Testing that if you have the title but no url, the title is not sanitized twice. |
|
247 |
* CRUD Title Only Title No Link. |
|
248 |
* |
|
249 |
* Testing that if you have the title but no url, the title is not sanitized |
|
250 |
* twice. |
|
251 |
* |
|
252 |
* @codingStandardsIgnoreStart |
|
228 | 253 |
*/ |
229 |
function testCRUDTitleOnlyTitleNoLink() { |
|
230 |
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); |
|
254 |
public function testCRUDTitleOnlyTitleNoLink() { |
|
255 |
// @codingStandardsIgnoreEnd |
|
256 |
$this->web_user = $this->drupalCreateUser(array( |
|
257 |
'administer content types', |
|
258 |
'administer fields', |
|
259 |
'access content', |
|
260 |
'create page content', |
|
261 |
)); |
|
231 | 262 |
$this->drupalLogin($this->web_user); |
232 | 263 |
|
233 |
// create field
|
|
264 |
// Create field.
|
|
234 | 265 |
$name = strtolower($this->randomName()); |
235 | 266 |
$field_name = 'field_' . $name; |
236 | 267 |
$edit = array( |
... | ... | |
247 | 278 |
|
248 | 279 |
// Is field created? |
249 | 280 |
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added'); |
250 |
|
|
251 |
// create page form
|
|
281 |
|
|
282 |
// Create page form.
|
|
252 | 283 |
$this->drupalGet('node/add/page'); |
253 | 284 |
$this->assertField($field_name . '[und][0][url]', 'URL found'); |
254 | 285 |
|
... | ... | |
265 | 296 |
$this->drupalPost(NULL, $edit, t('Save')); |
266 | 297 |
|
267 | 298 |
$url = $this->getUrl(); |
268 |
|
|
269 |
// change to anonymous user
|
|
299 |
|
|
300 |
// Change to anonymous user.
|
|
270 | 301 |
$this->drupalLogout(); |
271 | 302 |
$this->drupalGet($url); |
272 | 303 |
|
... | ... | |
274 | 305 |
} |
275 | 306 |
|
276 | 307 |
/** |
277 |
* If we're creating a new field and just hit 'save' on the default options, we want to make |
|
278 |
* sure they are set to the expected results. |
|
308 |
* CRUD Create Field Defaults. |
|
309 |
* |
|
310 |
* If we're creating a new field and just hit 'save' on the default options, |
|
311 |
* we want to make sure they are set to the expected results. |
|
312 |
* |
|
313 |
* @codingStandardsIgnoreStart |
|
279 | 314 |
*/ |
280 |
function testCRUDCreateFieldDefaults() { |
|
281 |
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); |
|
315 |
public function testCRUDCreateFieldDefaults() { |
|
316 |
// @codingStandardsIgnoreEnd |
|
317 |
|
|
318 |
$this->web_user = $this->drupalCreateUser(array( |
|
319 |
'administer content types', |
|
320 |
'administer fields', |
|
321 |
'access content', |
|
322 |
'create page content', |
|
323 |
)); |
|
324 |
|
|
282 | 325 |
$this->drupalLogin($this->web_user); |
283 | 326 |
|
284 |
// create field
|
|
327 |
// Create field.
|
|
285 | 328 |
$name = strtolower($this->randomName()); |
286 | 329 |
$edit = array( |
287 | 330 |
'fields[_add_new_field][label]' => $name, |
... | ... | |
312 | 355 |
$this->assertFalse($instance['settings']['attributes']['class'], 'By default, no class should be set.'); |
313 | 356 |
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.'); |
314 | 357 |
} |
315 |
|
|
358 |
|
|
316 | 359 |
/** |
317 |
* If we're creating a new field and just hit 'save' on the default options, we want to make |
|
318 |
* sure they are set to the expected results. |
|
360 |
* CRUD Create Field With Class. |
|
361 |
* |
|
362 |
* If we're creating a new field and just hit 'save' on the default options, |
|
363 |
* we want to make sure they are set to the expected results. |
|
364 |
* |
|
365 |
* @codingStandardsIgnoreStart |
|
319 | 366 |
*/ |
320 |
function testCRUDCreateFieldWithClass() { |
|
321 |
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); |
|
367 |
public function testCRUDCreateFieldWithClass() { |
|
368 |
// @codingStandardsIgnoreEnd |
|
369 |
$this->web_user = $this->drupalCreateUser(array( |
|
370 |
'administer content types', |
|
371 |
'administer fields', |
|
372 |
'access content', |
|
373 |
'create page content', |
|
374 |
)); |
|
322 | 375 |
$this->drupalLogin($this->web_user); |
323 | 376 |
|
324 |
// create field
|
|
377 |
// Create field.
|
|
325 | 378 |
$name = strtolower($this->randomName()); |
326 | 379 |
$edit = array( |
327 | 380 |
'fields[_add_new_field][label]' => $name, |
... | ... | |
356 | 409 |
$this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.'); |
357 | 410 |
$this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'One class should be set.'); |
358 | 411 |
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.'); |
359 |
|
|
412 |
|
|
360 | 413 |
// Now, let's create a node with this field and make sure the link shows up: |
361 |
// create page form |
|
414 |
// create page form.
|
|
362 | 415 |
$field_name = 'field_' . $name; |
363 | 416 |
$this->drupalGet('node/add/page'); |
364 | 417 |
$this->assertField($field_name . '[und][0][url]', 'URL found'); |
... | ... | |
376 | 429 |
$this->drupalPost(NULL, $edit, t('Save')); |
377 | 430 |
|
378 | 431 |
$url = $this->getUrl(); |
379 |
|
|
380 |
// change to anonymous user
|
|
432 |
|
|
433 |
// Change to anonymous user.
|
|
381 | 434 |
$this->drupalLogout(); |
382 | 435 |
$this->drupalGet($url); |
383 | 436 |
|
... | ... | |
385 | 438 |
$this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Class $link_class_name exists on page."); |
386 | 439 |
} |
387 | 440 |
|
388 |
/** |
|
389 |
* If we're creating a new field and just hit 'save' on the default options, we want to make |
|
390 |
* sure they are set to the expected results. |
|
441 |
/** |
|
442 |
* CRUD Create Field With Two Classes. |
|
443 |
* |
|
444 |
* If we're creating a new field and just hit 'save' on the default options, |
|
445 |
* we want to make sure they are set to the expected results. |
|
446 |
* |
|
447 |
* @codingStandardsIgnoreStart |
|
391 | 448 |
*/ |
392 |
function testCRUDCreateFieldWithTwoClasses() { |
|
393 |
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); |
|
449 |
public function testCRUDCreateFieldWithTwoClasses() { |
|
450 |
// @codingStandardsIgnoreEnd |
|
451 |
$this->web_user = $this->drupalCreateUser(array( |
|
452 |
'administer content types', |
|
453 |
'administer fields', |
|
454 |
'access content', |
|
455 |
'create page content', |
|
456 |
)); |
|
394 | 457 |
$this->drupalLogin($this->web_user); |
395 | 458 |
|
396 |
// create field
|
|
459 |
// Create field.
|
|
397 | 460 |
$name = strtolower($this->randomName()); |
398 | 461 |
$edit = array( |
399 | 462 |
'fields[_add_new_field][label]' => $name, |
... | ... | |
428 | 491 |
$this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.'); |
429 | 492 |
$this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'Two classes should be set.'); |
430 | 493 |
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.'); |
431 |
|
|
494 |
|
|
432 | 495 |
// Now, let's create a node with this field and make sure the link shows up: |
433 |
// create page form |
|
496 |
// create page form.
|
|
434 | 497 |
$field_name = 'field_' . $name; |
435 | 498 |
$this->drupalGet('node/add/page'); |
436 | 499 |
$this->assertField($field_name . '[und][0][url]', 'URL found'); |
... | ... | |
448 | 511 |
$this->drupalPost(NULL, $edit, t('Save')); |
449 | 512 |
|
450 | 513 |
$url = $this->getUrl(); |
451 |
|
|
452 |
// change to anonymous user
|
|
514 |
|
|
515 |
// Change to anonymous user.
|
|
453 | 516 |
$this->drupalLogout(); |
454 | 517 |
$this->drupalGet($url); |
455 | 518 |
|
456 | 519 |
$this->assertRaw('This & That'); |
457 | 520 |
$this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Classes $link_class_name exist on page."); |
458 | 521 |
} |
522 |
|
|
459 | 523 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules