Skip to content

Commit

Permalink
InstallationsService::addDefaultUser (#3901)
Browse files Browse the repository at this point in the history
Co-authored-by: thangnn <[email protected]>
  • Loading branch information
thangnnmd and thangnn authored Oct 16, 2024
1 parent 96fe6a5 commit 08c4909
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/bc-installer/src/Service/InstallationsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ public function setAdminEmailAndVersion(string $email)
* @throws PersistenceFailedException
* @checked
* @noTodo
* @unitTest
*/
public function addDefaultUser(array $user)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use BaserCore\Test\Factory\ContentFactory;
use BaserCore\Test\Factory\ContentFolderFactory;
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BaserCore\Utility\BcFile;
Expand All @@ -22,6 +23,7 @@
use BcInstaller\Service\InstallationsServiceInterface;
use Cake\Core\Configure;
use Cake\ORM\Exception\PersistenceFailedException;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
* InstallationsServiceTest
Expand All @@ -34,6 +36,7 @@ class InstallationsServiceTest extends BcTestCase
* Trait
*/
use BcContainerTrait;
use ScenarioAwareTrait;

/**
* setup
Expand Down Expand Up @@ -162,7 +165,38 @@ public function testSetAdminEmailAndVersion()
*/
public function testAddDefaultUser()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->loadFixtureScenario(InitAppScenario::class);
$this->loginAdmin($this->getRequest('/'));

//data
$userData = [
'name' => 'testuser',
'email' => '[email protected]',
'password_1' => 'Password1234',
'password_2' => 'Password1234'
];

$result = $this->Installations->addDefaultUser($userData);
$this->assertEquals('testuser', $result['name']);
$this->assertEquals('[email protected]', $result['email']);
$this->assertEquals('testuser', $result['real_name_1']);
$this->assertCount(1, $result['user_groups']);
}

public function testAddDefaultUserThrowsException()
{
$this->loadFixtureScenario(InitAppScenario::class);
$this->loginAdmin($this->getRequest('/'));

$userData = [
'email' => '[email protected]',
'password_1' => 'password123',
'password_2' => 'differentpassword'
];

$this->expectException(PersistenceFailedException::class);
$this->expectExceptionMessage('Entity save failure. Found the following errors (password.minLength: "パスワードは12文字以上で入力してください。", password.passwordConfirm: "パスワードが同じものではありません。", password.passwordRequiredCharacterType: "パスワード');
$this->Installations->addDefaultUser($userData);
}

/**
Expand Down

0 comments on commit 08c4909

Please sign in to comment.