You are here

class PathMatcherTest in Acquia Lift Connector 8

PathMatcher Test.

@coversDefaultClass Drupal\acquia_lift\Service\Helper\PathMatcher @group acquia_lift

Hierarchy

Expanded class hierarchy of PathMatcherTest

File

tests/src/Unit/Service/Helper/PathMatcherTest.php, line 19
Contains \Drupal\Tests\acquia_lift\Service\Helper\PathMatcherTest.

Namespace

Drupal\Tests\acquia_lift\Service\Helper
View source
class PathMatcherTest extends UnitTestCase {

  /**
   * Alias manager.
   *
   * @var \Drupal\Core\Path\AliasManagerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  private $aliasManager;

  /**
   * Path matcher.
   *
   * @var \Drupal\Core\Path\PathMatcherInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  private $basePathMatcher;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    $this->aliasManager = $this
      ->getMock('Drupal\\Core\\Path\\AliasManagerInterface');
    $this->basePathMatcher = $this
      ->getMock('Drupal\\Core\\Path\\PathMatcherInterface');
  }

  /**
   * Tests the match() method - no match.
   *
   * @covers ::match
   */
  public function testMatchNoMatch() {
    $this->basePathMatcher
      ->expects($this
      ->exactly(2))
      ->method('matchPath')
      ->willReturn(FALSE);
    $pathMatcher = new PathMatcher($this->aliasManager, $this->basePathMatcher);
    $is_matched = $pathMatcher
      ->match('A_PATH', 'A_PATTERN');
    $this
      ->assertFalse($is_matched);
  }

  /**
   * Tests the match() method - path is matched.
   *
   * @covers ::match
   */
  public function testMatchPathMatched() {
    $this->basePathMatcher
      ->expects($this
      ->once())
      ->method('matchPath')
      ->with('a_path', 'a_pattern')
      ->willReturn(TRUE);
    $this->aliasManager
      ->expects($this
      ->never())
      ->method('getAliasByPath');
    $pathMatcher = new PathMatcher($this->aliasManager, $this->basePathMatcher);
    $is_matched = $pathMatcher
      ->match('A_PATH', 'A_PATTERN');
    $this
      ->assertTrue($is_matched);
  }

  /**
   * Tests the match() method - path's alias is matched.
   *
   * @covers ::match
   */
  public function testMatchAliasMatched() {
    $this->basePathMatcher
      ->expects($this
      ->at(0))
      ->method('matchPath')
      ->with('a_path', 'a_pattern')
      ->willReturn(FALSE);
    $this->aliasManager
      ->expects($this
      ->once())
      ->method('getAliasByPath')
      ->with('a_path')
      ->willReturn('AN_ALIAS');
    $this->basePathMatcher
      ->expects($this
      ->at(1))
      ->method('matchPath')
      ->with('an_alias', 'a_pattern')
      ->willReturn(TRUE);
    $pathMatcher = new PathMatcher($this->aliasManager, $this->basePathMatcher);
    $is_matched = $pathMatcher
      ->match('A_PATH', 'A_PATTERN');
    $this
      ->assertTrue($is_matched);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PathMatcherTest::$aliasManager private property Alias manager.
PathMatcherTest::$basePathMatcher private property Path matcher.
PathMatcherTest::setUp public function Overrides UnitTestCase::setUp
PathMatcherTest::testMatchAliasMatched public function Tests the match() method - path's alias is matched.
PathMatcherTest::testMatchNoMatch public function Tests the match() method - no match.
PathMatcherTest::testMatchPathMatched public function Tests the match() method - path is matched.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed 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.