From 1621c0527dd96f21cbb4d2f7a30d9d1d15252582 Mon Sep 17 00:00:00 2001 From: Vincent Gao Date: Mon, 10 May 2021 19:19:10 +1000 Subject: [PATCH] update site alias tests --- tests/src/Unit/TideSiteAliasTest.php | 86 ++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/src/Unit/TideSiteAliasTest.php diff --git a/tests/src/Unit/TideSiteAliasTest.php b/tests/src/Unit/TideSiteAliasTest.php new file mode 100644 index 0000000..a60d99a --- /dev/null +++ b/tests/src/Unit/TideSiteAliasTest.php @@ -0,0 +1,86 @@ +aliasManager = $this->createMock(AliasManager::class); + $this->entityTypeManager = $this->createMock(EntityTypeManager::class); + $methods = get_class_methods('Drupal\tide_site\AliasStorageHelper'); + unset($methods[array_search('getPathAliasWithoutSitePrefix', $methods)]); + $this->aliasHelper = $this->getMockBuilder('Drupal\tide_site\AliasStorageHelper') + ->disableOriginalConstructor() + ->setMethods($methods) + ->getMock(); + $alias_matrix = [ + ['/node/1', NULL, '/site-1/hello'], + ['/node/2', NULL, '/site-2/hello'], + ['/node/3', NULL, '/site-3/hello'], + ['/node/4', NULL, '/site-4/hello'], + ['/node/5', NULL, '/site-5/hello'], + ['/node/6', NULL, '/site-6/hello'], + ]; + $this->aliasManager->expects($this->any()) + ->method('getAliasByPath') + ->will($this->returnValueMap($alias_matrix)); + } + + function testUniquenessOfAlias() { + $this->assertEquals('/site-1/hello', $this->aliasManager->getAliasByPath('/node/1')); + $this->assertEquals('/site-2/hello', $this->aliasManager->getAliasByPath('/node/2')); + } + + /** + * @dataProvider providerAliasWithoutSite + */ + function testgetPathAliasWithoutSitePrefix($alias_with_site, $expection) { + $without_siteid = $this->aliasHelper->getPathAliasWithoutSitePrefix($alias_with_site); + $this->assertEquals($expection, $without_siteid); + } + + function providerAliasWithoutSite() { + return [ + [['alias' => '/site-1/hello'], '/hello'], + [['alias' => '/site-2/hello_1'], '/hello_1'], + [['alias' => '/site-3/hello_2'], '/hello_2'], + [['alias' => '/site-4/hello_3'], '/hello_3'], + [['alias' => '/site-5/hello_4'], '/hello_4'], + [['alias' => '/hello_5'], '/hello_5'], + [['alias' => '/node/1'], '/node/1'], + ]; + } + +} \ No newline at end of file