function CommonURLUnitTest::testExternalUrls in SimpleTest 7
Test external URL handling.
File
- tests/
common.test, line 266 - Tests for common.inc functionality.
Class
- CommonURLUnitTest
- Tests for URL generation functions.
Code
function testExternalUrls() {
$test_url = 'http://drupal.org/';
// Verify external URL can contain a fragment.
$url = $test_url . '#drupal';
$result = url($url);
$this
->assertEqual($url, $result, t('External URL with fragment works without a fragment in $options.'));
// Verify fragment can be overidden in an external URL.
$url = $test_url . '#drupal';
$fragment = $this
->randomName(10);
$result = url($url, array(
'fragment' => $fragment,
));
$this
->assertEqual($test_url . '#' . $fragment, $result, t('External URL fragment is overidden with a custom fragment in $options.'));
// Verify external URL can contain a query string.
$url = $test_url . '?drupal=awesome';
$result = url($url);
$this
->assertEqual($url, $result, t('External URL with query string works without a query string in $options.'));
// Verify external URL can be extended with a query string.
$url = $test_url;
$query = array(
$this
->randomName(5) => $this
->randomName(5),
);
$result = url($url, array(
'query' => $query,
));
$this
->assertEqual($url . '?' . http_build_query($query, '', '&'), $result, t('External URL can be extended with a query string in $options.'));
// Verify query string can be extended in an external URL.
$url = $test_url . '?drupal=awesome';
$query = array(
$this
->randomName(5) => $this
->randomName(5),
);
$result = url($url, array(
'query' => $query,
));
$this
->assertEqual($url . '&' . http_build_query($query, '', '&'), $result, t('External URL query string can be extended with a custom query string in $options.'));
}