From f2f2b840bd5a0dcf116b56203a621336a57a03ad Mon Sep 17 00:00:00 2001 From: thangnn Date: Mon, 25 Nov 2024 14:06:45 +0700 Subject: [PATCH 1/2] Add unitTest_BcPlugin_siteRouting --- plugins/baser-core/src/BcPlugin.php | 1 + .../baser-core/tests/TestCase/BcPluginTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/plugins/baser-core/src/BcPlugin.php b/plugins/baser-core/src/BcPlugin.php index dcc449b98c..8b5f72b7f1 100644 --- a/plugins/baser-core/src/BcPlugin.php +++ b/plugins/baser-core/src/BcPlugin.php @@ -572,6 +572,7 @@ function(RouteBuilder $routes) use($isApi) { * @return RouteBuilder * @checked * @noTodo + * @unitTest */ public function siteRouting(RouteBuilder $routes, string $plugin) { diff --git a/plugins/baser-core/tests/TestCase/BcPluginTest.php b/plugins/baser-core/tests/TestCase/BcPluginTest.php index bf637057f2..a6c9f74cd6 100644 --- a/plugins/baser-core/tests/TestCase/BcPluginTest.php +++ b/plugins/baser-core/tests/TestCase/BcPluginTest.php @@ -684,4 +684,22 @@ public function testContentsRoutingForReverse() ])); } + /** + * test siteRouting + */ + public function testSiteRouting() + { + SiteFactory::make(['id' => '1', 'main_site_id' => null])->persist(); + SiteFactory::make(['id' => '2', 'main_site_id' => 1, 'alias' => 's'])->persist(); + ContentFactory::make( ['plugin' => 'BcBlog', 'type' => 'BlogContent', 'entity_id' => 31, 'url' => '/news/', 'site_id' => 1])->persist(); + + $this->getRequest('/'); + Router::reload(); + $routes = Router::createRouteBuilder(''); + $_SERVER['REQUEST_URI'] = '/s/'; + $this->BcPlugin->routes($routes); + $result = Router::parseRequest($this->getRequest('/s/bc-blog/blog_contents/index')); + $this->assertEquals('BlogContents', $result['controller']); + } + } From 2fe97aa49e831bd4d6c718722e30e69ad25f77f6 Mon Sep 17 00:00:00 2001 From: thangnn Date: Tue, 26 Nov 2024 14:39:54 +0700 Subject: [PATCH 2/2] modified --- plugins/baser-core/tests/TestCase/BcPluginTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/baser-core/tests/TestCase/BcPluginTest.php b/plugins/baser-core/tests/TestCase/BcPluginTest.php index a6c9f74cd6..0c53bc8ce8 100644 --- a/plugins/baser-core/tests/TestCase/BcPluginTest.php +++ b/plugins/baser-core/tests/TestCase/BcPluginTest.php @@ -691,12 +691,12 @@ public function testSiteRouting() { SiteFactory::make(['id' => '1', 'main_site_id' => null])->persist(); SiteFactory::make(['id' => '2', 'main_site_id' => 1, 'alias' => 's'])->persist(); - ContentFactory::make( ['plugin' => 'BcBlog', 'type' => 'BlogContent', 'entity_id' => 31, 'url' => '/news/', 'site_id' => 1])->persist(); + ContentFactory::make(['plugin' => 'BcBlog', 'type' => 'BlogContent', 'entity_id' => 31, 'url' => '/news/', 'site_id' => 1])->persist(); - $this->getRequest('/'); Router::reload(); $routes = Router::createRouteBuilder(''); $_SERVER['REQUEST_URI'] = '/s/'; + $this->BcPlugin->clearCurrentSite(); $this->BcPlugin->routes($routes); $result = Router::parseRequest($this->getRequest('/s/bc-blog/blog_contents/index')); $this->assertEquals('BlogContents', $result['controller']);