/**
  * Tests the getAliasByPath cache with an unpreloaded path with alias.
  *
  * @covers ::getAliasByPath
  * @covers ::writeCache
  */
 public function testGetAliasByPathUncachedMissWithAlias()
 {
     $path_part1 = $this->randomMachineName();
     $path_part2 = $this->randomMachineName();
     $path = '/' . $path_part1 . '/' . $path_part2;
     $cached_path = $this->randomMachineName();
     $cached_no_alias_path = $this->randomMachineName();
     $cached_alias = $this->randomMachineName();
     $new_alias = $this->randomMachineName();
     $language = $this->setUpCurrentLanguage();
     $cached_paths = array($language->getId() => array($cached_path, $cached_no_alias_path));
     $this->cache->expects($this->once())->method('get')->with($this->cacheKey)->will($this->returnValue((object) array('data' => $cached_paths)));
     // Simulate a request so that the preloaded paths are fetched.
     $this->aliasManager->setCacheKey($this->path);
     $this->aliasWhitelist->expects($this->any())->method('get')->with($path_part1)->will($this->returnValue(TRUE));
     $this->aliasStorage->expects($this->once())->method('preloadPathAlias')->with($cached_paths[$language->getId()], $language->getId())->will($this->returnValue(array($cached_path => $cached_alias)));
     $this->aliasStorage->expects($this->once())->method('lookupPathAlias')->with($path, $language->getId())->will($this->returnValue($new_alias));
     $this->assertEquals($new_alias, $this->aliasManager->getAliasByPath($path));
     // Call it twice to test the static cache.
     $this->assertEquals($new_alias, $this->aliasManager->getAliasByPath($path));
     // There is already a cache entry, so this should not write out to the
     // cache.
     $this->cache->expects($this->never())->method('set');
     $this->aliasManager->writeCache();
 }
Ejemplo n.º 2
0
 /**
  * Tests the getAliasByPath cache with an unpreloaded path with alias.
  *
  * @covers ::getAliasByPath
  * @covers ::writeCache
  */
 public function testGetAliasByPathUncachedMissWithAlias()
 {
     $path_part1 = $this->randomMachineName();
     $path_part2 = $this->randomMachineName();
     $path = $path_part1 . '/' . $path_part2;
     $cached_path = $this->randomMachineName();
     $cached_no_alias_path = $this->randomMachineName();
     $cached_alias = $this->randomMachineName();
     $new_alias = $this->randomMachineName();
     $language = $this->setUpCurrentLanguage();
     $cached_paths = array($language->getId() => array($cached_path, $cached_no_alias_path));
     $this->cache->expects($this->once())->method('get')->with($this->cacheKey)->will($this->returnValue((object) array('data' => $cached_paths)));
     // Simulate a request so that the preloaded paths are fetched.
     $this->aliasManager->setCacheKey($this->path);
     $this->aliasWhitelist->expects($this->any())->method('get')->with($path_part1)->will($this->returnValue(TRUE));
     $this->aliasStorage->expects($this->once())->method('preloadPathAlias')->with($cached_paths[$language->getId()], $language->getId())->will($this->returnValue(array($cached_path => $cached_alias)));
     $this->aliasStorage->expects($this->once())->method('lookupPathAlias')->with($path, $language->getId())->will($this->returnValue($new_alias));
     $this->assertEquals($new_alias, $this->aliasManager->getAliasByPath($path));
     // Call it twice to test the static cache.
     $this->assertEquals($new_alias, $this->aliasManager->getAliasByPath($path));
     // This needs to write out the cache.
     $expected_new_cache = array($language->getId() => array($cached_path, $path, $cached_no_alias_path));
     $this->cache->expects($this->once())->method('set')->with($this->cacheKey, $expected_new_cache, (int) $_SERVER['REQUEST_TIME'] + 60 * 60 * 24);
     $this->aliasManager->writeCache();
 }
Ejemplo n.º 3
0
 /**
  * Rebuild the path alias white list.
  *
  * @param string $path
  *   An optional path for which an alias is being inserted.
  *
  * @return
  *   An array containing a white list of path aliases.
  */
 protected function pathAliasWhitelistRebuild($path = NULL)
 {
     // When paths are inserted, only rebuild the whitelist if the path has a top
     // level component which is not already in the whitelist.
     if (!empty($path)) {
         if ($this->whitelist->get(strtok($path, '/'))) {
             return;
         }
     }
     $this->whitelist->clear();
 }
Ejemplo n.º 4
0
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    $this->installSchema('system', 'sequences');
    $this->installEntitySchema('user');
    $this->installEntitySchema('node');

    $this->installConfig('subpathauto');

    // Create the node bundles required for testing.
    $type = NodeType::create([
      'type' => 'page',
      'name' => 'page',
    ]);
    $type->save();

    $this->aliasStorage = $this->container->get('path.alias_storage');
    $this->sut = $this->container->get('path_processor_subpathauto');
    $this->aliasWhiteList = $this->container->get('path.alias_whitelist');

    Node::create(['type' => 'page', 'title' => 'test'])->save();
    $this->aliasStorage->save('/node/1', '/kittens');
    $this->aliasWhiteList->set('node', TRUE);
  }