Commit 497bf117 authored by alexpott's avatar alexpott

Issue #2800799 by aronne, Lendude: Views throws InvalidArgumentException in...

Issue #2800799 by aronne, Lendude: Views throws InvalidArgumentException in More Link with external URLs
parent ae1f599d
......@@ -1271,7 +1271,20 @@ public function renderText($alter) {
// @todo Views should expect and store a leading /. See
// https://www.drupal.org/node/2423913.
$more_link = ' ' . $this->linkGenerator()->generate($more_link_text, CoreUrl::fromUserInput('/' . $more_link_path, array('attributes' => array('class' => array('views-more-link')))));
$options = array(
'attributes' => array(
'class' => array(
'views-more-link',
),
),
);
if (UrlHelper::isExternal($more_link_path)) {
$more_link_url = CoreUrl::fromUri($more_link_path, $options);
}
else {
$more_link_url = CoreUrl::fromUserInput('/' . $more_link_path, $options);
}
$more_link = ' ' . $this->linkGenerator()->generate($more_link_text, $more_link_url);
}
}
......
......@@ -227,11 +227,17 @@ public function testRenderAsLinkWithoutPath() {
}
/**
* Test rendering as a link without a path.
* Test rendering with a more link.
*
* @param string $path
* An internal or external path.
* @param string $url
* The final url used by the more link.
*
* @dataProvider providerTestRenderTrimmedWithMoreLinkAndPath
* @covers ::renderText
*/
public function testRenderTrimmedWithMoreLink() {
public function testRenderTrimmedWithMoreLinkAndPath($path, $url) {
$alter = [
'trim' => TRUE,
'max_length' => 7,
......@@ -239,6 +245,7 @@ public function testRenderTrimmedWithMoreLink() {
// Don't invoke translation.
'ellipsis' => FALSE,
'more_link_text' => 'more link',
'more_link_path' => $path,
];
$this->display->expects($this->any())
......@@ -253,11 +260,38 @@ public function testRenderTrimmedWithMoreLink() {
$field->field_alias = 'key';
$row = new ResultRow(['key' => 'a long value']);
$expected_result = 'a long <a href="/%3Cfront%3E" class="views-more-link">more link</a>';
$expected_result = 'a long <a href="' . $url . '" class="views-more-link">more link</a>';
$result = $field->advancedRender($row);
$this->assertEquals($expected_result, $result);
}
/**
* Data provider for ::testRenderTrimmedWithMoreLinkAndPath().
*
* @return array
* Test data.
*/
public function providerTestRenderTrimmedWithMoreLinkAndPath() {
$data = [];
// Simple path with default options.
$data[] = ['test-path', '/test-path'];
// Add a fragment.
$data[] = ['test-path#test', '/test-path#test'];
// Query specified as part of the path.
$data[] = ['test-path?foo=bar', '/test-path?foo=bar'];
// Empty path.
$data[] = ['', '/%3Cfront%3E'];
// Front page path.
$data[] = ['<front>', '/%3Cfront%3E'];
// External URL.
$data[] = ['https://www.drupal.org', 'https://www.drupal.org'];
$data[] = ['http://www.drupal.org', 'http://www.drupal.org'];
$data[] = ['www.drupal.org', '/www.drupal.org'];
return $data;
}
/**
* Tests the "No results text" rendering.
*
......
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