From 144ab03fbcd97fa25587a94a911ffc593374f3b7 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 2 Oct 2013 18:03:19 +0100 Subject: [PATCH] Issue #2096135 by dawehner, longwave: Fixed PathProcessorAlias ignore 'alias' => TRUE. --- .../Core/PathProcessor/PathProcessorAlias.php | 7 +- .../lib/Drupal/path/Tests/PathAliasTest.php | 6 ++ .../path/Tests/PathTaxonomyTermTest.php | 8 +- .../PathProcessor/PathProcessorAliasTest.php | 89 +++++++++++++++++++ 4 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorAliasTest.php diff --git a/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php b/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php index cfcf32e196d..66979d1c699 100644 --- a/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php +++ b/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php @@ -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; } + } diff --git a/core/modules/path/lib/Drupal/path/Tests/PathAliasTest.php b/core/modules/path/lib/Drupal/path/Tests/PathAliasTest.php index 37012e23a7f..184c9d9afa1 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathAliasTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathAliasTest.php @@ -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. diff --git a/core/modules/path/lib/Drupal/path/Tests/PathTaxonomyTermTest.php b/core/modules/path/lib/Drupal/path/Tests/PathTaxonomyTermTest.php index 99c6fc24f23..c483d9e9632 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathTaxonomyTermTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathTaxonomyTermTest.php @@ -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')); diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorAliasTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorAliasTest.php new file mode 100644 index 00000000000..40c8de0aaf4 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorAliasTest.php @@ -0,0 +1,89 @@ + 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')); + } + +}