MockAliasManager.php

Contains Drupal\system\Tests\Routing\MockAliasManager.

Namespace

Drupal\system\Tests\Routing

File

drupal/core/modules/system/lib/Drupal/system/Tests/Routing/MockAliasManager.php
View source
<?php

/**
 * @file
 * Contains Drupal\system\Tests\Routing\MockAliasManager.
 */
namespace Drupal\system\Tests\Routing;

use Drupal\Core\Path\AliasManagerInterface;

/**
 * An easily configurable mock alias manager.
 */
class MockAliasManager implements AliasManagerInterface {

  /**
   * Array of mocked aliases. Keys are system paths, followed by language.
   *
   * @var array
   */
  protected $aliases = array();

  /**
   * Array of mocked aliases. Keys are aliases, followed by language.
   *
   * @var array
   */
  protected $systemPaths = array();

  /**
   * An index of aliases that have been requested.
   *
   * @var array
   */
  protected $lookedUp = array();

  /**
   * The language to assume a path alias is for if not specified.
   *
   * @var string
   */
  public $defaultLanguage = 'en';

  /**
   * Adds an alias to the in-memory alias table for this object.
   *
   * @param type $path
   *   The system path of the alias.
   * @param type $alias
   *   The alias of the system path.
   * @param type $path_language
   *   The language of this alias.
   */
  public function addAlias($path, $alias, $path_language = NULL) {
    $language = $path_language ?: $this->defaultLanguage;
    $this->aliases[$path][$language] = $alias;
    $this->systemPaths[$alias][$language] = $path;
  }

  /**
   * Implements \Drupal\Core\Path\AliasManagerInterface::getSystemPath().
   */
  public function getSystemPath($path, $path_language = NULL) {
    $language = $path_language ?: $this->defaultLanguage;
    return $this->systemPaths[$path][$language];
  }

  /**
   * Implements \Drupal\Core\Path\AliasManagerInterface::getPathAlias().
   */
  public function getPathAlias($path, $path_language = NULL) {
    $language = $path_language ?: $this->defaultLanguage;
    $this->lookedUp[$path] = 1;
    return $this->aliases[$path][$language];
  }

  /**
   * Implements \Drupal\Core\Path\AliasManagerInterface::getPathLookups().
   */
  public function getPathLookups() {
    return array_keys($this->lookedUp);
  }

  /**
   * Implements \Drupal\Core\Path\AliasManagerInterface::preloadPathLookups().
   */
  public function preloadPathLookups(array $path_list) {

    // Not needed.
  }

}

Classes

Namesort descending Description
MockAliasManager An easily configurable mock alias manager.