Commit d0b06ddd authored by damienmckenna's avatar damienmckenna Committed by Damien McKenna
Browse files

Issue #3210438 by DamienMcKenna: Test coverage - URLs with multiple query parameters.

parent fcc7f812
Link 7.x-1.x-dev, xxxx-xx-xx
----------------------------
#3210438 by DamienMcKenna: Test coverage - URLs with multiple query parameters.
Link 7.x-1.9, 2021-04-19
......
......@@ -531,6 +531,9 @@ class LinkFieldCrudTest extends LinkBaseTestClass {
array(
'href' => 'http://example.com/' . $this->randomName() . '?property=value',
),
array(
'href' => 'http://example.com/' . $this->randomName() . '?property=value&mango=thebest',
),
array(
'href' => 'http://example.com/' . $this->randomName() . '#position',
),
......@@ -565,7 +568,9 @@ class LinkFieldCrudTest extends LinkBaseTestClass {
// Loop over the nodes, confirm each URL is rendered correctly.
foreach ($link_title_tests as $input) {
$this->drupalGet($input['url']);
$this->assertRaw(l($input['href'], $input['href']), "Test that the link title has been set to " . $input['href']);
// This is precarious. It isn't possible to compare the link as-is because
// it is already filtered via check_plain().
$this->assertRaw(l($input['href'], $input['href'], array('html' => TRUE)), "Test that the link title has been set to " . $input['href']);
}
}
......
......@@ -137,10 +137,38 @@ class LinkSanitizeTest extends LinkBaseTestClass {
$this->verbose('<pre>' . print_r($item, TRUE) . '</pre>');
$this->assertEqual('https://www.drupal.org/?page=42', $item['display_url']);
$this->assertEqual('https://www.drupal.org/', $item['url']);
$this->assertTrue(is_array($item['query']));
$this->assertEqual(array('page' => 42), $item['query']);
$this->assertEqual(NULL, $item['fragment']);
}
/**
* Test that multiple query URLs can be turned into absolute URLs.
*/
public function testBlankTitleWithMultipleQueries() {
$item['title'] = '';
$item['url'] = 'https://www.drupal.org/?page=42&mango=thebest';
list($field, $instance, $entity) = $this->generateParams();
// Disable the URL cutoff to confirm the URL.
$instance['settings']['display']['url_cutoff'] = FALSE;
_link_sanitize($item, NULL, $field, $instance, $entity);
$this->verbose('<pre>' . print_r($item, TRUE) . '</pre>');
$this->assertEqual('https://www.drupal.org/?page=42&mango=thebest', $item['display_url']);
$this->assertEqual('https://www.drupal.org/', $item['url']);
$this->assertTrue(is_array($item['query']));
$this->assertTrue(isset($item['query']['page']));
$this->assertEqual($item['query']['page'], 42);
$this->assertTrue(isset($item['query']['page']));
$this->assertEqual($item['query']['mango'], 'thebest');
// Make sure there aren't any other items in the 'query' array.
unset($item['query']['mango']);
unset($item['query']['page']);
$this->assertEqual(array(), $item['query']);
$this->assertEqual(NULL, $item['fragment']);
}
/**
* Test that query URLs can be turned into absolute URLs.
*/
......
......@@ -46,6 +46,13 @@ class LinkUnitTestCase extends DrupalUnitTestCase {
'page' => 42,
),
),
'https://www.drupal.org/?page=42&mango=thebest' => array(
'url' => 'https://www.drupal.org/',
'query' => array(
'page' => 42,
'mango' => 'thebest',
),
),
'https://www.drupal.org/#footer' => array(
'url' => 'https://www.drupal.org/',
'fragment' => 'footer',
......@@ -69,6 +76,10 @@ class LinkUnitTestCase extends DrupalUnitTestCase {
$this->assertTrue(isset($actual_parts['query']));
$this->assertTrue(is_array($actual_parts['query']));
$this->assertEqual(count($expected_parts['query']), count($actual_parts['query']));
foreach ($expected_parts['query'] as $key => $val) {
$this->assertTrue(isset($actual_parts['query'][$key]));
$this->assertEqual($val, $actual_parts['query'][$key]);
}
}
// If it was not expected, make sure it wasn't added anyway.
else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment