AliasManager example

$this->assertEquals('/user/2', $aliasManager->getPathByAlias('/bar'), 'Newer alias record is returned when comparing two LanguageInterface::LANGCODE_NOT_SPECIFIED paths with the same alias.');
  }

  /** * Tests the alias whitelist. */
  public function testWhitelist() {
    $memoryCounterBackend = new MemoryCounterBackend();

    // Create AliasManager and Path object.     $whitelist = new AliasWhitelist('path_alias_whitelist', $memoryCounterBackend$this->container->get('lock')$this->container->get('state')$this->container->get('path_alias.repository'));
    $aliasManager = new AliasManager($this->container->get('path_alias.repository')$whitelist$this->container->get('language_manager')$memoryCounterBackend);

    // No alias for user and admin yet, so should be NULL.     $this->assertNull($whitelist->get('user'));
    $this->assertNull($whitelist->get('admin'));

    // Non-existing path roots should be NULL too. Use a length of 7 to avoid     // possible conflict with random aliases below.     $this->assertNull($whitelist->get($this->randomMachineName()));

    // Add an alias for user/1, user should get whitelisted now.     $this->createPathAlias('/user/1', '/' . $this->randomMachineName());
    
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->aliasRepository = $this->createMock(AliasRepositoryInterface::class);
    $this->aliasWhitelist = $this->createMock('Drupal\path_alias\AliasWhitelistInterface');
    $this->languageManager = $this->createMock('Drupal\Core\Language\LanguageManagerInterface');
    $this->cache = $this->createMock('Drupal\Core\Cache\CacheBackendInterface');

    $this->aliasManager = new AliasManager($this->aliasRepository, $this->aliasWhitelist, $this->languageManager, $this->cache);

  }

  /** * Tests the getPathByAlias method for an alias that have no matching path. * * @covers ::getPathByAlias */
  public function testGetPathByAliasNoMatch() {
    $alias = '/' . $this->randomMachineName();

    
Home | Imprint | This part of the site doesn't use cookies.