Skip to content

Commit

Permalink
Allow registar account disable and add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Dec 8, 2023
1 parent bc909bc commit 673a2b6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/UseCase/Register/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public function actionIndex(): Response|string
$registerForm = new $this->formModelClass($this->userModule);
$event = new RegisterEvent($registerForm, $this->userModule);

if ($this->userModule->register === false) {
$this->trigger(RegisterEvent::MODULE_DISABLE, $event);

return $this->goHome();
}

$this->trigger(RegisterEvent::BEFORE_REGISTER, $event);
$this->ajaxValidator->validate($registerForm);

Expand Down
1 change: 1 addition & 0 deletions src/UseCase/Register/RegisterEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class RegisterEvent extends Event
{
public const AFTER_REGISTER = 'afterRegister';
public const BEFORE_REGISTER = 'beforeRegister';
public const MODULE_DISABLE = 'moduleDisable';

public function __construct(
public readonly Model $formModel,
Expand Down
5 changes: 2 additions & 3 deletions src/UseCase/Register/view/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,9 @@
->class('btn btn-icon-only btn-pill btn-outline-gray-500')
->content(
Span::widget()
->class('fa-stack fa-2x')
->class('btn btn-outline-secondary fa-2x')
->content(
Icon::renderIcon('solid', 'square-full', ['class' => 'fas fa-stack-2x']),
Icon::renderIcon('brands', 'github', ['class' => 'fab fa-stack-1x fa-inverse text-center'])
Icon::renderIcon('brands', 'github', ['class' => 'fab text-center'])
)
)
->href('#')
Expand Down
15 changes: 15 additions & 0 deletions tests/Acceptance/RegisterCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@

final class RegisterCest
{
public function disablePage(AcceptanceTester $I): void
{
$I->amGoingTo('disable register page.');
$I->accountRegister(false);

$I->amGoingTo('go to the page registration.');
$I->amOnRoute('register/index');

$I->expectTo('see message register disabled.');
$I->see(Yii::t('app.basic', 'Web Application'));

$I->amGoingTo('enable register page.');
$I->accountRegister(true);
}

public function indexPage(AcceptanceTester $I): void
{
$I->amGoingTo('navigate to the register page.');
Expand Down
12 changes: 12 additions & 0 deletions tests/Support/AcceptanceTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,16 @@ public function accountGeneratePassword(bool $option): void
],
);
}

public function accountRegister(bool $option): void
{
\Yii::$container->set(
\Yii\User\UserModule::class,
[
'__construct()' => [
'register' => $option,
],
],
);
}
}

0 comments on commit 673a2b6

Please sign in to comment.