Révision 134c7813
Ajouté par Mathieu Schiano Di Schiabica il y a environ 8 ans
drupal7/modules/simpletest/tests/common.test | ||
---|---|---|
372 | 372 |
} |
373 | 373 |
} |
374 | 374 |
|
375 |
/** |
|
376 |
* Tests url_is_external(). |
|
377 |
*/ |
|
378 |
class UrlIsExternalUnitTest extends DrupalUnitTestCase { |
|
379 |
|
|
380 |
public static function getInfo() { |
|
381 |
return array( |
|
382 |
'name' => 'External URL checking', |
|
383 |
'description' => 'Performs tests on url_is_external().', |
|
384 |
'group' => 'System', |
|
385 |
); |
|
386 |
} |
|
387 |
|
|
388 |
/** |
|
389 |
* Tests if each URL is external or not. |
|
390 |
*/ |
|
391 |
function testUrlIsExternal() { |
|
392 |
foreach ($this->examples() as $path => $expected) { |
|
393 |
$this->assertIdentical(url_is_external($path), $expected, $path); |
|
394 |
} |
|
395 |
} |
|
396 |
|
|
397 |
/** |
|
398 |
* Provides data for testUrlIsExternal(). |
|
399 |
* |
|
400 |
* @return array |
|
401 |
* An array of test data, keyed by a path, with the expected value where |
|
402 |
* TRUE is external, and FALSE is not external. |
|
403 |
*/ |
|
404 |
protected function examples() { |
|
405 |
return array( |
|
406 |
// Simple external URLs. |
|
407 |
'http://example.com' => TRUE, |
|
408 |
'https://example.com' => TRUE, |
|
409 |
'http://drupal.org/foo/bar?foo=bar&bar=baz&baz#foo' => TRUE, |
|
410 |
'//drupal.org' => TRUE, |
|
411 |
// Some browsers ignore or strip leading control characters. |
|
412 |
"\x00//www.example.com" => TRUE, |
|
413 |
"\x08//www.example.com" => TRUE, |
|
414 |
"\x1F//www.example.com" => TRUE, |
|
415 |
"\n//www.example.com" => TRUE, |
|
416 |
// JSON supports decoding directly from UTF-8 code points. |
|
417 |
json_decode('"\u00AD"') . "//www.example.com" => TRUE, |
|
418 |
json_decode('"\u200E"') . "//www.example.com" => TRUE, |
|
419 |
json_decode('"\uE0020"') . "//www.example.com" => TRUE, |
|
420 |
json_decode('"\uE000"') . "//www.example.com" => TRUE, |
|
421 |
// Backslashes should be normalized to forward. |
|
422 |
'\\\\example.com' => TRUE, |
|
423 |
// Local URLs. |
|
424 |
'node' => FALSE, |
|
425 |
'/system/ajax' => FALSE, |
|
426 |
'?q=foo:bar' => FALSE, |
|
427 |
'node/edit:me' => FALSE, |
|
428 |
'/drupal.org' => FALSE, |
|
429 |
'<front>' => FALSE, |
|
430 |
); |
|
431 |
} |
|
432 |
} |
|
433 |
|
|
375 | 434 |
/** |
376 | 435 |
* Tests for check_plain(), filter_xss(), format_string(), and check_url(). |
377 | 436 |
*/ |
... | ... | |
1256 | 1315 |
$this->assertText('drupal_goto', 'Drupal goto redirect succeeded.'); |
1257 | 1316 |
$this->assertEqual($this->getUrl(), url('common-test/drupal_goto', array('query' => array('foo' => '123'), 'absolute' => TRUE)), 'Drupal goto redirected to expected URL.'); |
1258 | 1317 |
|
1318 |
// Test that calling drupal_goto() on the current path is not dangerous. |
|
1319 |
variable_set('common_test_redirect_current_path', TRUE); |
|
1320 |
$this->drupalGet('', array('query' => array('q' => 'http://www.example.com/'))); |
|
1321 |
$headers = $this->drupalGetHeaders(TRUE); |
|
1322 |
list(, $status) = explode(' ', $headers[0][':status'], 3); |
|
1323 |
$this->assertEqual($status, 302, 'Expected response code was sent.'); |
|
1324 |
$this->assertNotEqual($this->getUrl(), 'http://www.example.com/', 'Drupal goto did not redirect to external URL.'); |
|
1325 |
$this->assertTrue(strpos($this->getUrl(), url('<front>', array('absolute' => TRUE))) === 0, 'Drupal redirected to itself.'); |
|
1326 |
variable_del('common_test_redirect_current_path'); |
|
1259 | 1327 |
// Test that drupal_goto() respects ?destination=xxx. Use an complicated URL |
1260 | 1328 |
// to test that the path is encoded and decoded properly. |
1261 | 1329 |
$destination = 'common-test/drupal_goto/destination?foo=%2525&bar=123'; |
Formats disponibles : Unified diff
Update to 7.43