Skip to content

Commit

Permalink
Merge pull request #3974 from thangnnmd/unitTest_AppController_checkP…
Browse files Browse the repository at this point in the history
…ermission

AppController::checkPermission() ユニットテスト
  • Loading branch information
HungDV2022 authored Nov 7, 2024
2 parents 6514d53 + 904c91a commit 4b7370b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/baser-core/src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public function beforeFilter(EventInterface $event)
* @return bool
* @noTodo
* @checked
* @unitTest
*/
private function checkPermission()
{
Expand Down
23 changes: 23 additions & 0 deletions plugins/baser-core/tests/TestCase/Controller/AppControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 4b7370b

Please sign in to comment.