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

8.0.x
Alex Pott 2013-10-02 18:03:19 +01:00
parent 33b448c203
commit 144ab03fbc
4 changed files with 107 additions and 3 deletions

View File

@ -44,8 +44,11 @@ class PathProcessorAlias implements InboundPathProcessorInterface, OutboundPathP
* 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;
}
}

View File

@ -154,6 +154,12 @@ class PathAliasTest extends PathTestBase {
$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.

View File

@ -55,13 +55,19 @@ class PathTaxonomyTermTest extends PathTestBase {
'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'));

View File

@ -0,0 +1,89 @@
<?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'));
}
}