Commit af813036 authored by catch's avatar catch

Issue #2569117 by othermachines, Lendude, cilefen: "Source path ... has to...

Issue #2569117 by othermachines, Lendude, cilefen: "Source path ... has to start with a slash" exception when using contextual filter
parent a56fa001
......@@ -112,11 +112,15 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function getArgument() {
$path = trim($this->currentPath->getPath($this->view->getRequest()), '/');
// Don't trim the leading slash since getAliasByPath() requires it.
$path = rtrim($this->currentPath->getPath($this->view->getRequest()), '/');
if ($this->options['use_alias']) {
$path = $this->aliasManager->getAliasByPath($path);
}
$args = explode('/', $path);
// Drop the empty first element created by the leading slash since the path
// component index doesn't take it into account.
array_shift($args);
if (isset($args[$this->options['index']])) {
return $args[$this->options['index']];
}
......
......@@ -42,7 +42,15 @@ public function testGetArgument() {
$alias_manager->expects($this->never())
->method('getAliasByPath');
// Don't use aliases.
// Don't use aliases. Check against NULL and nonexistent path component
// values in addition to valid ones.
$raw = new Raw(array(), 'raw', array(), $alias_manager, $current_path);
$options = array(
'use_alias' => FALSE,
);
$raw->init($view, $display_plugin, $options);
$this->assertEquals(NULL, $raw->getArgument());
$raw = new Raw(array(), 'raw', array(), $alias_manager, $current_path);
$options = array(
'use_alias' => FALSE,
......@@ -59,12 +67,27 @@ public function testGetArgument() {
$raw->init($view, $display_plugin, $options);
$this->assertEquals('example', $raw->getArgument());
$raw = new Raw(array(), 'raw', array(), $alias_manager, $current_path);
$options = array(
'use_alias' => FALSE,
'index' => 2,
);
$raw->init($view, $display_plugin, $options);
$this->assertEquals(NULL, $raw->getArgument());
// Setup an alias manager with a path alias.
$alias_manager = $this->getMock('Drupal\Core\Path\AliasManagerInterface');
$alias_manager->expects($this->any())
->method('getAliasByPath')
->with($this->equalTo('test/example'))
->will($this->returnValue('other/example'));
->with($this->equalTo('/test/example'))
->will($this->returnValue('/other/example'));
$raw = new Raw(array(), 'raw', array(), $alias_manager, $current_path);
$options = array(
'use_alias' => TRUE,
);
$raw->init($view, $display_plugin, $options);
$this->assertEquals(NULL, $raw->getArgument());
$raw = new Raw(array(), 'raw', array(), $alias_manager, $current_path);
$options = array(
......@@ -82,6 +105,13 @@ public function testGetArgument() {
$raw->init($view, $display_plugin, $options);
$this->assertEquals('example', $raw->getArgument());
$raw = new Raw(array(), 'raw', array(), $alias_manager, $current_path);
$options = array(
'use_alias' => TRUE,
'index' => 2,
);
$raw->init($view, $display_plugin, $options);
$this->assertEquals(NULL, $raw->getArgument());
}
}
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