PathMatcherTest.php in Acquia Lift Connector 8
File
tests/src/Unit/Service/Helper/PathMatcherTest.php
View source
<?php
namespace Drupal\Tests\acquia_lift\Service\Helper;
use Drupal\Tests\UnitTestCase;
use Drupal\acquia_lift\Service\Helper\PathMatcher;
class PathMatcherTest extends UnitTestCase {
private $aliasManager;
private $basePathMatcher;
public function setUp() {
parent::setUp();
$this->aliasManager = $this
->getMock('Drupal\\Core\\Path\\AliasManagerInterface');
$this->basePathMatcher = $this
->getMock('Drupal\\Core\\Path\\PathMatcherInterface');
}
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);
}
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);
}
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);
}
}