From 0f53330d40d09bec6cd66583f5f0414780c729d9 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Fri, 19 Jul 2024 17:22:21 +0900 Subject: [PATCH] =?UTF-8?q?BcAuthHelper::isAdminUser()=E3=81=AE=E3=83=A6?= =?UTF-8?q?=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88=20(#3611?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- .../src/View/Helper/BcAuthHelper.php | 1 + .../tests/Factory/UserGroupFactory.php | 2 +- .../tests/TestCase/Model/Entity/UserTest.php | 2 +- .../TestCase/View/Helper/BcAuthHelperTest.php | 27 +++++++++++++------ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/plugins/baser-core/src/View/Helper/BcAuthHelper.php b/plugins/baser-core/src/View/Helper/BcAuthHelper.php index 1af660808b..7acc1f4d08 100644 --- a/plugins/baser-core/src/View/Helper/BcAuthHelper.php +++ b/plugins/baser-core/src/View/Helper/BcAuthHelper.php @@ -258,6 +258,7 @@ public function isSuperUser(): bool * @return boolean * @checked * @noTodo + * @unitTest */ public function isAdminUser(): bool { diff --git a/plugins/baser-core/tests/Factory/UserGroupFactory.php b/plugins/baser-core/tests/Factory/UserGroupFactory.php index 15c1449127..1db3feb3f2 100644 --- a/plugins/baser-core/tests/Factory/UserGroupFactory.php +++ b/plugins/baser-core/tests/Factory/UserGroupFactory.php @@ -55,7 +55,7 @@ public function admins() return $this->setField('id', 1) ->setField('name', 'admins') ->setField('title', 'システム管理') - ->setField('auth_prefix', 'Admin, Api/Admin') + ->setField('auth_prefix', 'Admin,Api/Admin') ->setField('use_move_contents', 1); } diff --git a/plugins/baser-core/tests/TestCase/Model/Entity/UserTest.php b/plugins/baser-core/tests/TestCase/Model/Entity/UserTest.php index 678aab766e..896ccd02c1 100644 --- a/plugins/baser-core/tests/TestCase/Model/Entity/UserTest.php +++ b/plugins/baser-core/tests/TestCase/Model/Entity/UserTest.php @@ -183,7 +183,7 @@ public function test_getAuthPrefixes() //user group is not empty $user_groups = $this->User->getAuthPrefixes(); - $this->assertEquals([0 => 'Admin', 1 => ' Api/Admin'], $user_groups); + $this->assertEquals([0 => 'Admin', 1 => 'Api/Admin'], $user_groups); } public function test_isSuper() diff --git a/plugins/baser-core/tests/TestCase/View/Helper/BcAuthHelperTest.php b/plugins/baser-core/tests/TestCase/View/Helper/BcAuthHelperTest.php index d03c3fa19d..701c41ac45 100644 --- a/plugins/baser-core/tests/TestCase/View/Helper/BcAuthHelperTest.php +++ b/plugins/baser-core/tests/TestCase/View/Helper/BcAuthHelperTest.php @@ -11,10 +11,8 @@ namespace BaserCore\Test\TestCase\View\Helper; -use BaserCore\Test\Scenario\SitesScenario; -use BaserCore\Test\Scenario\UserGroupsScenario; -use BaserCore\Test\Scenario\UserScenario; -use BaserCore\Test\Scenario\UsersUserGroupsScenario; +use BaserCore\Test\Factory\UserFactory; +use BaserCore\Test\Scenario\InitAppScenario; use BaserCore\TestSuite\BcTestCase; use BaserCore\View\BcAdminAppView; use BaserCore\View\Helper\BcAuthHelper; @@ -38,10 +36,6 @@ class BcAuthHelperTest extends BcTestCase public function setUp(): void { parent::setUp(); - $this->loadFixtureScenario(UserScenario::class); - $this->loadFixtureScenario(UserGroupsScenario::class); - $this->loadFixtureScenario(UsersUserGroupsScenario::class); - $this->loadFixtureScenario(SitesScenario::class); // adminの場合 $BcAdminAppView = new BcAdminAppView(); $BcAdminAppView->setRequest($this->getRequest()->withParam('prefix', 'Admin')); @@ -67,6 +61,7 @@ public function tearDown(): void */ public function testGetCurrentPrefix() { + $this->loadFixtureScenario(InitAppScenario::class); // adminの場合 $result = $this->BcAuth->getCurrentPrefix(); $this->assertEquals('Admin', $result); @@ -81,6 +76,7 @@ public function testGetCurrentPrefix() */ public function testGetPrefixSetting() { + $this->loadFixtureScenario(InitAppScenario::class); // 管理画面の場合 $result = $this->BcAuth->getPrefixSetting('Admin'); $this->assertEquals($result['name'], "管理システム"); @@ -94,6 +90,7 @@ public function testGetPrefixSetting() */ public function testGetCurrentPrefixSetting() { + $this->loadFixtureScenario(InitAppScenario::class); // 管理画面の場合 $result = $this->BcAuth->getCurrentPrefixSetting(); $this->assertEquals($result['name'], "管理システム"); @@ -111,6 +108,7 @@ public function testGetCurrentPrefixSetting() */ public function testGetLoginUrl() { + $this->loadFixtureScenario(InitAppScenario::class); // 管理画面の場合 $this->assertEquals('/baser/admin/baser-core/users/login', $this->BcAuth->getLoginUrl('Admin')); // 設定がない場合 @@ -123,6 +121,7 @@ public function testGetLoginUrl() */ public function testGetCurrentLoginUrl() { + $this->loadFixtureScenario(InitAppScenario::class); // Adminの場合 $expected = "/baser/admin/baser-core/users/login"; $result = $this->BcAuth->getCurrentLoginUrl(); @@ -142,6 +141,7 @@ public function testGetCurrentLoginUrl() */ public function testGetCurrentUserPrefixes() { + $this->loadFixtureScenario(InitAppScenario::class); // TODO getCurrentUserPrefixSettings() の実装が完了したら別パターンのテストを追加する $this->loginAdmin($this->getRequest('/baser/admin')); $result = $this->BcAuth->getCurrentUserPrefixes(); @@ -154,6 +154,7 @@ public function testGetCurrentUserPrefixes() */ public function testIsCurrentUserAdminAvailable() { + $this->loadFixtureScenario(InitAppScenario::class); $this->loginAdmin($this->getRequest('/baser/admin')); $result = $this->BcAuth->isCurrentUserAdminAvailable(); $this->assertTrue($result); @@ -165,6 +166,7 @@ public function testIsCurrentUserAdminAvailable() */ public function testGetCurrentName() { + $this->loadFixtureScenario(InitAppScenario::class); // prefix(admin)の場合 $expected = Configure::read('BcPrefixAuth.Admin')['name']; $result = $this->BcAuth->getCurrentName(); @@ -177,6 +179,7 @@ public function testGetCurrentName() */ public function testIsAdminLogin() { + $this->loadFixtureScenario(InitAppScenario::class); // ログインしない場合; $result = $this->BcAuth->isAdminLogin(); $this->assertFalse($result); @@ -191,6 +194,7 @@ public function testIsAdminLogin() */ public function testGetLogoutUrl() { + $this->loadFixtureScenario(InitAppScenario::class); // Adminの場合 $this->assertEquals([ 'prefix' => 'Admin', @@ -208,6 +212,7 @@ public function testGetLogoutUrl() */ public function testGetCurrentLogoutUrl() { + $this->loadFixtureScenario(InitAppScenario::class); // Adminの場合 $expected = "/baser/admin/baser-core/users/logout"; $result = $this->BcAuth->getCurrentLogoutUrl(); @@ -230,6 +235,7 @@ public function testGetCurrentLogoutUrl() */ public function testGetCurrentLoginRedirectUrl() { + $this->loadFixtureScenario(InitAppScenario::class); // Adminの場合 $expected = "/baser/admin"; $result = $this->BcAuth->getCurrentLoginRedirectUrl(); @@ -247,6 +253,8 @@ public function testGetCurrentLoginRedirectUrl() */ public function testGetCurrentLoginUser() { + $this->loadFixtureScenario(InitAppScenario::class); + UserFactory::make(['id' => 2])->persist(); $ids = [1, 2]; foreach($ids as $id) { $expected = $this->getUser($id); @@ -264,6 +272,8 @@ public function testGetCurrentLoginUser() */ public function testIsAdminUser($id, $expected) { + $this->loadFixtureScenario(InitAppScenario::class); + UserFactory::make(['id' => 2])->persist(); if ($id) { $this->loginAdmin($this->getRequest('/baser/admin'), $id); } @@ -289,6 +299,7 @@ public static function isAdminUserDataProvider() */ public function testIsAgentUser() { + $this->loadFixtureScenario(InitAppScenario::class); // AuthAgent.Userが書き込まれてない場合 $result = $this->BcAuth->isAgentUser(); $this->assertFalse($result);