/** * Tests the getPathByAlias method when a langcode is passed explicitly. * * @covers ::getPathByAlias() */ public function testGetPathByAliasLangcode() { $alias = $this->randomName(); $path = $this->randomName(); $this->languageManager->expects($this->never())->method('getCurrentLanguage'); $this->aliasStorage->expects($this->once())->method('lookupPathSource')->with($alias, 'de')->will($this->returnValue($path)); $this->assertEquals($path, $this->aliasManager->getPathByAlias($alias, 'de')); // Call it twice to test the static cache. $this->assertEquals($path, $this->aliasManager->getPathByAlias($alias, 'de')); }
/** * Normalizes the path aliases. * * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event */ public function globalredirectNormalizeAliases(GetResponseEvent $event) { if ($event->getRequestType() != HttpKernelInterface::MASTER_REQUEST || !$this->config->get('normalize_aliases') || !($path = trim($event->getRequest()->getPathInfo(), '/'))) { return; } $system_path = $this->aliasManager->getPathByAlias($path); $alias = $this->aliasManager->getAliasByPath($system_path, $this->languageManager->getCurrentLanguage()->getId()); // If the alias defined in the system is not the same as the one via which // the page has been accessed do a redirect to the one defined in the // system. if ($alias != $path) { if ($url = \Drupal::pathValidator()->getUrlIfValid($alias)) { $this->setResponse($event, $url); } } }
/** * @covers ::cacheClear */ public function testCacheClear() { $path = 'path'; $alias = 'alias'; $language = $this->setUpCurrentLanguage(); $this->aliasStorage->expects($this->exactly(2))->method('lookupPathAlias')->with($path, $language->getId())->willReturn($alias); $this->aliasWhitelist->expects($this->any())->method('get')->willReturn(TRUE); // Populate the lookup map. $this->assertEquals($alias, $this->aliasManager->getAliasByPath($path, $language->getId())); // Check that the cache is populated. $original_storage = clone $this->aliasStorage; $this->aliasStorage->expects($this->never())->method('lookupPathSource'); $this->assertEquals($path, $this->aliasManager->getPathByAlias($alias, $language->getId())); // Clear specific source. $this->cache->expects($this->exactly(2))->method('delete'); $this->aliasManager->cacheClear($path); // Ensure cache has been cleared (this will be the 2nd call to // `lookupPathAlias` if cache is cleared). $this->assertEquals($alias, $this->aliasManager->getAliasByPath($path, $language->getId())); // Clear non-existent source. $this->aliasManager->cacheClear('non-existent'); }