From 2e91324431165a067d5fe78c039ff6b7d37aa6b2 Mon Sep 17 00:00:00 2001 From: thangnn Date: Tue, 5 Nov 2024 11:18:01 +0700 Subject: [PATCH] Add unitTest_AppController_checkPermission --- .../src/Controller/AppController.php | 1 + .../TestCase/Controller/AppControllerTest.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/plugins/baser-core/src/Controller/AppController.php b/plugins/baser-core/src/Controller/AppController.php index 61e7822740..042326c8f9 100644 --- a/plugins/baser-core/src/Controller/AppController.php +++ b/plugins/baser-core/src/Controller/AppController.php @@ -195,6 +195,7 @@ public function beforeFilter(EventInterface $event) * @return bool * @noTodo * @checked + * @unitTest */ private function checkPermission() { diff --git a/plugins/baser-core/tests/TestCase/Controller/AppControllerTest.php b/plugins/baser-core/tests/TestCase/Controller/AppControllerTest.php index dc11139e95..14c27cb706 100644 --- a/plugins/baser-core/tests/TestCase/Controller/AppControllerTest.php +++ b/plugins/baser-core/tests/TestCase/Controller/AppControllerTest.php @@ -11,6 +11,7 @@ namespace BaserCore\Test\TestCase\Controller; +use BaserCore\Service\PermissionsServiceInterface; use BaserCore\Service\SiteConfigsServiceInterface; use BaserCore\Test\Scenario\ContentsScenario; use BaserCore\Test\Scenario\InitAppScenario; @@ -147,6 +148,28 @@ public function test_beforeRender() $this->assertEquals('BcAdminThird', $this->AppController->viewBuilder()->getVars()['currentAdminTheme']); } + /** + * test checkPermission + */ + public function testCheckPermission() + { + //準備 + $permissionsService = $this->getService(PermissionsServiceInterface::class); + $permissionsService->addCheck("/fuga", false); + $permissionsService->addCheck("/piyo", true); + + Configure::write('BcApp.adminGroupId', 2); + $this->loginAdmin($this->getRequest('/')); + + //result = false test + $this->AppController->setRequest($this->getRequest('/fuga')); + $this->assertFalse($this->execPrivateMethod($this->AppController, 'checkPermission', [])); + + //result = true test + $this->AppController->setRequest($this->getRequest('/piyo')); + $this->assertTrue($this->execPrivateMethod($this->AppController, 'checkPermission', [])); + } + /** * Test setupFrontView */