You are here

class PathProcessorAliasTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorAliasTest.php \Drupal\Tests\Core\PathProcessor\PathProcessorAliasTest

@coversDefaultClass \Drupal\Core\PathProcessor\PathProcessorAlias @group PathProcessor

Hierarchy

Expanded class hierarchy of PathProcessorAliasTest

File

core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorAliasTest.php, line 20
Contains \Drupal\Tests\Core\PathProcessor\PathProcessorAliasTest.

Namespace

Drupal\Tests\Core\PathProcessor
View source
class PathProcessorAliasTest extends UnitTestCase {

  /**
   * The mocked alias manager.
   *
   * @var \Drupal\Core\Path\AliasManagerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $aliasManager;

  /**
   * The tested path processor.
   *
   * @var \Drupal\Core\PathProcessor\PathProcessorAlias
   */
  protected $pathProcessor;
  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('getPathByAlias')
      ->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));
  }

  /**
   * @covers ::processOutbound
   *
   * @dataProvider providerTestProcessOutbound
   */
  public function testProcessOutbound($path, array $options, $expected_path) {
    $this->aliasManager
      ->expects($this
      ->any())
      ->method('getAliasByPath')
      ->will($this
      ->returnValueMap(array(
      array(
        'internal-url',
        NULL,
        'urlalias',
      ),
      array(
        'url',
        NULL,
        'url',
      ),
    )));
    $bubbleable_metadata = new BubbleableMetadata();
    $this
      ->assertEquals($expected_path, $this->pathProcessor
      ->processOutbound($path, $options, NULL, $bubbleable_metadata));

    // Cacheability of paths replaced with path aliases is permanent.
    // @todo https://www.drupal.org/node/2480077
    $this
      ->assertEquals((new BubbleableMetadata())
      ->setCacheMaxAge(Cache::PERMANENT), $bubbleable_metadata);
  }

  /**
   * @return array
   */
  public function providerTestProcessOutbound() {
    return [
      [
        'internal-url',
        [],
        'urlalias',
      ],
      [
        'internal-url',
        [
          'alias' => TRUE,
        ],
        'internal-url',
      ],
      [
        'url',
        [],
        'url',
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PathProcessorAliasTest::$aliasManager protected property The mocked alias manager.
PathProcessorAliasTest::$pathProcessor protected property The tested path processor.
PathProcessorAliasTest::providerTestProcessOutbound public function
PathProcessorAliasTest::setUp protected function Overrides UnitTestCase::setUp
PathProcessorAliasTest::testProcessInbound public function Tests the processInbound method.
PathProcessorAliasTest::testProcessOutbound public function @covers ::processOutbound
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root.
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName protected function Mocks a block with a block plugin.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.