Commit 144ab03f authored by alexpott's avatar alexpott

Issue #2096135 by dawehner, longwave: Fixed PathProcessorAlias ignore 'alias' => TRUE.

parent 33b448c2
......@@ -44,8 +44,11 @@ public function processInbound($path, Request $request) {
* Implements Drupal\Core\PathProcessor\OutboundPathProcessorInterface::processOutbound().
*/
public function processOutbound($path, &$options = array(), Request $request = NULL) {
$langcode = isset($options['language']) ? $options['language']->id : NULL;
$path = $this->aliasManager->getPathAlias($path, $langcode);
if (empty($options['alias'])) {
$langcode = isset($options['language']) ? $options['language']->id : NULL;
$path = $this->aliasManager->getPathAlias($path, $langcode);
}
return $path;
}
}
......@@ -154,6 +154,12 @@ function testNodeAlias() {
$this->assertText($node1->label(), 'Alias works.');
$this->assertResponse(200);
// Confirm the 'canonical' and 'shortlink' URLs.
$elements = $this->xpath("//link[contains(@rel, 'canonical') and contains(@href, '" . $edit['path[alias]'] . "')]");
$this->assertTrue(!empty($elements), 'Page contains canonical link URL.');
$elements = $this->xpath("//link[contains(@rel, 'shortlink') and contains(@href, 'node/" . $node1->id() . "')]");
$this->assertTrue(!empty($elements), 'Page contains shortlink URL.');
// Change alias to one containing "exotic" characters.
$previous = $edit['path[alias]'];
$edit['path[alias]'] = "- ._~!$'\"()*@[]?&+%#,;=:" . // "Special" ASCII characters.
......
......@@ -55,13 +55,19 @@ function testTermAlias() {
'path[alias]' => $this->randomName(),
);
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add', $edit, t('Save'));
$tid = db_query("SELECT tid FROM {taxonomy_term_data} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
// Confirm that the alias works.
$this->drupalGet($edit['path[alias]']);
$this->assertText($description, 'Term can be accessed on URL alias.');
// Confirm the 'canonical' and 'shortlink' URLs.
$elements = $this->xpath("//link[contains(@rel, 'canonical') and contains(@href, '" . $edit['path[alias]'] . "')]");
$this->assertTrue(!empty($elements), 'Term page contains canonical link URL.');
$elements = $this->xpath("//link[contains(@rel, 'shortlink') and contains(@href, 'taxonomy/term/" . $tid . "')]");
$this->assertTrue(!empty($elements), 'Term page contains shortlink URL.');
// Change the term's URL alias.
$tid = db_query("SELECT tid FROM {taxonomy_term_data} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
$edit2 = array();
$edit2['path[alias]'] = $this->randomName();
$this->drupalPostForm('taxonomy/term/' . $tid . '/edit', $edit2, t('Save'));
......
<?php
/**
* @file
* Contains \Drupal\Tests\Core\PathProcessor\PathProcessorAliasTest.
*/
namespace Drupal\Tests\Core\PathProcessor;
use Drupal\Core\PathProcessor\PathProcessorAlias;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
/**
* Tests the path alias path processor.
*
* @group Drupal
*
* @see \Drupal\Core\PathProcessor\PathProcessorAlias
*/
class PathProcessorAliasTest extends UnitTestCase {
/**
* The mocked alias manager.
*
* @var \Drupal\Core\Path\AliasManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $aliasManager;
/**
* The tested path processor.
*
* @var \Drupal\Core\PathProcessor\PathProcessorAlias
*/
protected $pathProcessor;
public static function getInfo() {
return array(
'name' => t('Path Processor alias'),
'description' => t('Tests the path alias path processor.'),
'group' => t('Path API'),
);
}
protected function setUp() {
$this->aliasManager = $this->getMock('Drupal\Core\Path\AliasManagerInterface');
$this->pathProcessor = new PathProcessorAlias($this->aliasManager);
}
/**
* Tests the processInbound method.
*
* @see \Drupal\Core\PathProcessor\PathProcessorAlias::processInbound
*/
public function testProcessInbound() {
$this->aliasManager->expects($this->exactly(2))
->method('getSystemPath')
->will($this->returnValueMap(array(
array('urlalias', NULL, 'internal-url'),
array('url', NULL, 'url'),
)));
$request = Request::create('/urlalias');
$this->assertEquals('internal-url', $this->pathProcessor->processInbound('urlalias', $request));
$request = Request::create('/url');
$this->assertEquals('url', $this->pathProcessor->processInbound('url', $request));
}
/**
* Tests the processOutbound method.
*
* @see \Drupal\Core\PathProcessor\PathProcessorAlias::processOutbound
*/
public function testProcessOutbound() {
$this->aliasManager->expects($this->exactly(2))
->method('getPathAlias')
->will($this->returnValueMap(array(
array('internal-url', NULL, 'urlalias'),
array('url', NULL, 'url'),
)));
$this->assertEquals('urlalias', $this->pathProcessor->processOutbound('internal-url'));
$options = array('alias' => TRUE);
$this->assertEquals('internal-url', $this->pathProcessor->processOutbound('internal-url', $options));
$this->assertEquals('url', $this->pathProcessor->processOutbound('url'));
}
}
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