Skip to content

Commit

Permalink
Merge pull request #3941 from HungDV2022/unitest_InstallationsAdminSe…
Browse files Browse the repository at this point in the history
…rviceTest_initAdmin

InstallationsAdminService::initAdmin() のユニットテスト
  • Loading branch information
HungDV2022 authored Oct 24, 2024
2 parents 24c05e1 + 7ec4ce9 commit 31f5eaf
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ public function deleteAllTables(ServerRequest $request): bool
* @throws PersistenceFailedException
* @checked
* @noTodo
* @unitTest
*/
public function initAdmin(ServerRequest $request): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@

namespace BcInstaller\Test\TestCase\Service\Admin;

use BaserCore\Test\Factory\ContentFactory;
use BaserCore\Test\Factory\ContentFolderFactory;
use BaserCore\Test\Factory\UserFactory;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BcInstaller\Service\Admin\InstallationsAdminService;
use BcInstaller\Service\Admin\InstallationsAdminServiceInterface;
use Cake\Core\Configure;
use Cake\Http\ServerRequest;
use Cake\Http\Session;
use Cake\ORM\Exception\PersistenceFailedException;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
* InstallationsAdminServiceTest
Expand All @@ -31,6 +37,7 @@ class InstallationsAdminServiceTest extends BcTestCase
* Trait
*/
use BcContainerTrait;
use ScenarioAwareTrait;

/**
* set up
Expand Down Expand Up @@ -424,7 +431,49 @@ public function test_deleteAllTables()
*/
public function test_initAdmin()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
//データを生成
$this->loadFixtureScenario(InitAppScenario::class);
ContentFolderFactory::make(['id' => 1])->persist();
ContentFactory::make([
'id' => 1,
'plugin' => 'BaserCore',
'type' => 'ContentFolder',
'site_id' => 1,
'parent_id' => null,
'lft' => 1,
'rght' => 10,
'entity_id' => 1,
'site_root' => true,
'status' => true
])->persist();

//準備
$request = $this->loginAdmin($this->getRequest());
$request = $request->withParsedBody([
'admin_email' => '[email protected]',
'site_name' => 'basertest',
'admin_password' => '123456Abcdef@',
'admin_confirm_password' => '123456Abcdef@',
]);
//正常テスト
$this->Installations->initAdmin($request);

//SESSIONにデータが設定できるか確認
$this->assertEquals(2, $_SESSION["Installation"]["id"]);
//新しいユーザーが保存できるか確認
$user = UserFactory::get(2);
$this->assertEquals('[email protected]', $user->email);

//異常テスト
$request = $request->withParsedBody([
'admin_email' => '[email protected]',
'site_name' => 'basertest',
'admin_password' => '123456Abcdef@',
'admin_confirm_password' => '123456Abcdef@',
]);
$this->expectException(PersistenceFailedException::class);
$this->expectExceptionMessage('Entity save failure. Found the following errors (email.nameUnique: "既に登録のあるEメールです。');
$this->Installations->initAdmin($request);
}

/**
Expand Down

0 comments on commit 31f5eaf

Please sign in to comment.