Skip to content

Commit 80927d4

Browse files
committed
writing uni tests WIP
1 parent 70f2b01 commit 80927d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1013
-351
lines changed

config/autoload/navigation.global.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'options' => [
1616
'label' => 'Dashboard',
1717
'route' => [
18-
'route_name' => 'page::dashboard',
18+
'route_name' => 'app::index-redirect',
1919
],
2020
'icon' => 'c-blue-500 ti-home',
2121
],
@@ -31,15 +31,15 @@
3131
'options' => [
3232
'label' => 'Admins',
3333
'route' => [
34-
'route_name' => 'admin::list-admins',
34+
'route_name' => 'admin::admin-list',
3535
],
3636
],
3737
],
3838
[
3939
'options' => [
4040
'label' => 'Logins',
4141
'route' => [
42-
'route_name' => 'admin::list-admin-logins',
42+
'route_name' => 'admin::admin-login-list',
4343
],
4444
],
4545
],
@@ -65,7 +65,7 @@
6565
'options' => [
6666
'label' => 'Profile',
6767
'route' => [
68-
'route_name' => 'admin::account-form',
68+
'route_name' => 'admin::account-edit-form',
6969
],
7070
'icon' => 'ti-user',
7171
],

src/Admin/src/ConfigProvider.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414
use Admin\Admin\Form\AdminForm;
1515
use Admin\Admin\Form\ChangePasswordForm;
1616
use Admin\Admin\Form\LoginForm;
17-
use Admin\Admin\Handler\Account\ChangePasswordHandler;
18-
use Admin\Admin\Handler\Account\EditAdminAccountResourceHandler;
19-
use Admin\Admin\Handler\Account\GetAdminAccountFormHandler;
20-
use Admin\Admin\Handler\Account\GetAdminLoginFormHandler;
21-
use Admin\Admin\Handler\Account\LoginHandler;
22-
use Admin\Admin\Handler\Account\LogoutHandler;
23-
use Admin\Admin\Handler\Admin\DeleteAdminResourceHandler;
24-
use Admin\Admin\Handler\Admin\EditAdminResourceHandler;
25-
use Admin\Admin\Handler\Admin\GetAdminCollectionHandler;
17+
use Admin\Admin\Handler\Account\PostAccountChangePasswordHandler;
18+
use Admin\Admin\Handler\Account\PostAccountEditHandler;
19+
use Admin\Admin\Handler\Account\GetAccountEditFormHandler;
20+
use Admin\Admin\Handler\Account\GetAccountLoginFormHandler;
21+
use Admin\Admin\Handler\Account\PostAccountLoginHandler;
22+
use Admin\Admin\Handler\Account\GetAccountLogoutHandler;
23+
use Admin\Admin\Handler\Admin\PostAdminDeleteHandler;
24+
use Admin\Admin\Handler\Admin\PostAdminEditHandler;
25+
use Admin\Admin\Handler\Admin\GetAdminListHandler;
2626
use Admin\Admin\Handler\Admin\GetAdminCreateFormHandler;
2727
use Admin\Admin\Handler\Admin\GetAdminDeleteFormHandler;
2828
use Admin\Admin\Handler\Admin\GetAdminEditFormHandler;
29-
use Admin\Admin\Handler\Admin\GetAdminListCollectionHandler;
30-
use Admin\Admin\Handler\Admin\PostAdminResourceHandler;
29+
use Admin\Admin\Handler\Admin\GetAdminLoginListHandler;
30+
use Admin\Admin\Handler\Admin\PostAdminCreateHandler;
3131
use Admin\Admin\Repository\AdminLoginRepository;
3232
use Admin\Admin\Repository\AdminRepository;
3333
use Admin\Admin\Repository\AdminRoleRepository;
@@ -68,19 +68,19 @@ public function getDependencies(): array
6868
'factories' => [
6969
AdminController::class => AttributedServiceFactory::class,
7070
GetAdminCreateFormHandler::class => AttributedServiceFactory::class,
71-
PostAdminResourceHandler::class => AttributedServiceFactory::class,
71+
PostAdminCreateHandler::class => AttributedServiceFactory::class,
7272
GetAdminEditFormHandler::class => AttributedServiceFactory::class,
73-
EditAdminResourceHandler::class => AttributedServiceFactory::class,
73+
PostAdminEditHandler::class => AttributedServiceFactory::class,
7474
GetAdminDeleteFormHandler::class => AttributedServiceFactory::class,
75-
DeleteAdminResourceHandler::class => AttributedServiceFactory::class,
76-
GetAdminCollectionHandler::class => AttributedServiceFactory::class,
77-
GetAdminListCollectionHandler::class => AttributedServiceFactory::class,
78-
GetAdminAccountFormHandler::class => AttributedServiceFactory::class,
79-
EditAdminAccountResourceHandler::class => AttributedServiceFactory::class,
80-
ChangePasswordHandler::class => AttributedServiceFactory::class,
81-
GetAdminLoginFormHandler::class => AttributedServiceFactory::class,
82-
LoginHandler::class => AttributedServiceFactory::class,
83-
LogoutHandler::class => AttributedServiceFactory::class,
75+
PostAdminDeleteHandler::class => AttributedServiceFactory::class,
76+
GetAdminListHandler::class => AttributedServiceFactory::class,
77+
GetAdminLoginListHandler::class => AttributedServiceFactory::class,
78+
GetAccountEditFormHandler::class => AttributedServiceFactory::class,
79+
PostAccountEditHandler::class => AttributedServiceFactory::class,
80+
PostAccountChangePasswordHandler::class => AttributedServiceFactory::class,
81+
GetAccountLoginFormHandler::class => AttributedServiceFactory::class,
82+
PostAccountLoginHandler::class => AttributedServiceFactory::class,
83+
GetAccountLogoutHandler::class => AttributedServiceFactory::class,
8484
AdminService::class => AttributedServiceFactory::class,
8585
AdminRoleService::class => AttributedServiceFactory::class,
8686
AdminRepository::class => AttributedRepositoryFactory::class,

src/Admin/src/Handler/Account/GetAdminAccountFormHandler.php renamed to src/Admin/src/Handler/Account/GetAccountEditFormHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Psr\Http\Message\ServerRequestInterface;
1717
use Psr\Http\Server\RequestHandlerInterface;
1818

19-
class GetAdminAccountFormHandler implements RequestHandlerInterface
19+
class GetAccountEditFormHandler implements RequestHandlerInterface
2020
{
2121
#[Inject(
2222
AdminServiceInterface::class,

src/Admin/src/Handler/Account/GetAdminLoginFormHandler.php renamed to src/Admin/src/Handler/Account/GetAccountLoginFormHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Psr\Http\Message\ServerRequestInterface;
1818
use Psr\Http\Server\RequestHandlerInterface;
1919

20-
class GetAdminLoginFormHandler implements RequestHandlerInterface
20+
class GetAccountLoginFormHandler implements RequestHandlerInterface
2121
{
2222
#[Inject(
2323
RouterInterface::class,
@@ -40,7 +40,7 @@ public function __construct(
4040
public function handle(ServerRequestInterface $request): ResponseInterface
4141
{
4242
if ($this->authenticationService->hasIdentity()) {
43-
return new RedirectResponse($this->router->generateUri('page::dashboard'));
43+
return new RedirectResponse($this->router->generateUri('app::index-redirect'));
4444
}
4545

4646
$shouldRebind = $this->messenger->getData('shouldRebind') ?? true;

src/Admin/src/Handler/Account/LogoutHandler.php renamed to src/Admin/src/Handler/Account/GetAccountLogoutHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Psr\Http\Message\ServerRequestInterface;
1313
use Psr\Http\Server\RequestHandlerInterface;
1414

15-
class LogoutHandler implements RequestHandlerInterface
15+
class GetAccountLogoutHandler implements RequestHandlerInterface
1616
{
1717
#[Inject(
1818
RouterInterface::class,

src/Admin/src/Handler/Account/ChangePasswordHandler.php renamed to src/Admin/src/Handler/Account/PostAccountChangePasswordHandler.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use Psr\Http\Server\RequestHandlerInterface;
2525
use Throwable;
2626

27-
class ChangePasswordHandler implements RequestHandlerInterface
27+
class PostAccountChangePasswordHandler implements RequestHandlerInterface
2828
{
2929
use ServerRequestAwareTrait;
3030

@@ -52,26 +52,26 @@ public function __construct(
5252

5353
public function handle(ServerRequestInterface $request): ResponseInterface
5454
{
55-
$this->accountForm->setAttribute('action', $this->router->generateUri('admin::edit-account'));
56-
$this->changePasswordForm->setAttribute('action', $this->router->generateUri('admin::change-password'));
55+
try {
56+
$this->accountForm->setAttribute('action', $this->router->generateUri('admin::edit-account'));
57+
$this->changePasswordForm->setAttribute('action', $this->router->generateUri('admin::change-password'));
5758

58-
/** @var AdminIdentity $adminIdentity */
59-
$adminIdentity = $this->authenticationService->getIdentity();
60-
$admin = $this->adminService->getAdminRepository()->findOneBy([
61-
'identity' => $adminIdentity->getIdentity(),
62-
]);
59+
/** @var AdminIdentity $adminIdentity */
60+
$adminIdentity = $this->authenticationService->getIdentity();
61+
$admin = $this->adminService->getAdminRepository()->findOneBy([
62+
'identity' => $adminIdentity->getIdentity(),
63+
]);
6364

64-
$this->changePasswordForm->setData($this->getPostParams($request));
65-
if (! $this->changePasswordForm->isValid()) {
66-
return new HtmlResponse(
67-
$this->template->render('admin::account', [
68-
'accountForm' => $this->accountForm->prepare(),
69-
'changePasswordForm' => $this->changePasswordForm->prepare(),
70-
])
71-
);
72-
}
65+
$this->changePasswordForm->setData($this->getPostParams($request));
66+
if (! $this->changePasswordForm->isValid()) {
67+
return new HtmlResponse(
68+
$this->template->render('admin::account', [
69+
'accountForm' => $this->accountForm->prepare(),
70+
'changePasswordForm' => $this->changePasswordForm->prepare(),
71+
])
72+
);
73+
}
7374

74-
try {
7575
/** @var array $result */
7676
$result = $this->changePasswordForm->getData();
7777
if ($admin->verifyPassword($result['currentPassword'])) {
@@ -92,6 +92,6 @@ public function handle(ServerRequestInterface $request): ResponseInterface
9292
$this->messenger->addError(Message::AN_ERROR_OCCURRED);
9393
}
9494

95-
return new RedirectResponse($this->router->generateUri('admin::account-form'));
95+
return new RedirectResponse($this->router->generateUri('admin::account-edit-form'));
9696
}
9797
}

src/Admin/src/Handler/Account/EditAdminAccountResourceHandler.php renamed to src/Admin/src/Handler/Account/PostAccountEditHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Psr\Http\Server\RequestHandlerInterface;
2424
use Throwable;
2525

26-
class EditAdminAccountResourceHandler implements RequestHandlerInterface
26+
class PostAccountEditHandler implements RequestHandlerInterface
2727
{
2828
use ServerRequestAwareTrait;
2929

src/Admin/src/Handler/Account/LoginHandler.php renamed to src/Admin/src/Handler/Account/PostAccountLoginHandler.php

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use Psr\Http\Server\RequestHandlerInterface;
2525
use Throwable;
2626

27-
class LoginHandler implements RequestHandlerInterface
27+
class PostAccountLoginHandler implements RequestHandlerInterface
2828
{
2929
use ServerRequestAwareTrait;
3030

@@ -52,7 +52,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
5252
{
5353
try {
5454
if ($this->authenticationService->hasIdentity()) {
55-
return new RedirectResponse($this->router->generateUri('page::dashboard'));
55+
return new RedirectResponse($this->router->generateUri('app::index-redirect'));
5656
}
5757

5858
$shouldRebind = $this->messenger->getData('shouldRebind') ?? true;
@@ -61,53 +61,60 @@ public function handle(ServerRequestInterface $request): ResponseInterface
6161
}
6262

6363
$this->form->setData($this->getPostParams($request));
64-
if ($this->form->isValid()) {
65-
/** @var AuthenticationAdapter $adapter */
66-
$adapter = $this->authenticationService->getAdapter();
67-
68-
/** @var array $data */
69-
$data = $this->form->getData();
70-
$adapter->setIdentity($data['username']);
71-
$adapter->setCredential($data['password']);
72-
$authResult = $this->authenticationService->authenticate();
73-
if ($authResult->isValid()) {
74-
$identity = $authResult->getIdentity();
75-
$this->adminService->logAdminVisit(
76-
$this->getServerParams($request),
77-
$data['username'],
78-
AdminLogin::LOGIN_SUCCESS
79-
);
80-
if ($identity->getStatus() === Admin::STATUS_INACTIVE) {
81-
$this->authenticationService->clearIdentity();
82-
$this->messenger->addError('Admin is inactive');
83-
$this->messenger->addData('shouldRebind', true);
84-
$this->forms->saveState($this->form);
85-
return new RedirectResponse($request->getUri(), StatusCodeInterface::STATUS_SEE_OTHER);
86-
}
87-
$this->authenticationService->getStorage()->write($identity);
88-
89-
return new RedirectResponse($this->router->generateUri('page::dashboard'));
90-
} else {
91-
$this->adminService->logAdminVisit(
92-
$this->getServerParams($request),
93-
$data['username'],
94-
AdminLogin::LOGIN_FAIL
95-
);
96-
$this->messenger->addData('shouldRebind', true);
97-
$this->forms->saveState($this->form);
98-
$this->messenger->addError($authResult->getMessages());
99-
return new RedirectResponse($request->getUri(), StatusCodeInterface::STATUS_SEE_OTHER);
100-
}
101-
} else {
64+
65+
if (! $this->form->isValid()) {
10266
$this->messenger->addData('shouldRebind', true);
10367
$this->forms->saveState($this->form);
10468
$this->messenger->addError($this->forms->getMessages($this->form));
10569
return new RedirectResponse($request->getUri(), StatusCodeInterface::STATUS_SEE_OTHER);
10670
}
71+
72+
/** @var AuthenticationAdapter $adapter */
73+
$adapter = $this->authenticationService->getAdapter();
74+
75+
/** @var array $data */
76+
$data = $this->form->getData();
77+
$adapter->setIdentity($data['username']);
78+
$adapter->setCredential($data['password']);
79+
$authResult = $this->authenticationService->authenticate();
80+
if (! $authResult->isValid()) {
81+
$this->adminService->logAdminVisit(
82+
$this->getServerParams($request),
83+
$data['username'],
84+
AdminLogin::LOGIN_FAIL
85+
);
86+
87+
$this->messenger->addData('shouldRebind', true);
88+
$this->forms->saveState($this->form);
89+
$this->messenger->addError($authResult->getMessages());
90+
91+
return new RedirectResponse($request->getUri(), StatusCodeInterface::STATUS_SEE_OTHER);
92+
} else {
93+
$this->adminService->logAdminVisit(
94+
$this->getServerParams($request),
95+
$data['username'],
96+
AdminLogin::LOGIN_SUCCESS
97+
);
98+
99+
$identity = $authResult->getIdentity();
100+
if ($identity->getStatus() === Admin::STATUS_INACTIVE) {
101+
$this->authenticationService->clearIdentity();
102+
$this->messenger->addError(Message::ADMIN_INACTIVE);
103+
$this->messenger->addData('shouldRebind', true);
104+
$this->forms->saveState($this->form);
105+
return new RedirectResponse($request->getUri(), StatusCodeInterface::STATUS_SEE_OTHER);
106+
}
107+
108+
$this->authenticationService->getStorage()->write($identity);
109+
110+
return new RedirectResponse($this->router->generateUri('app::index-redirect'));
111+
}
107112
} catch (Throwable $e) {
113+
dd('catch', $e->getMessage());
108114
$this->messenger->addData('shouldRebind', true);
109115
$this->forms->saveState($this->form);
110116
$this->messenger->addError(Message::AN_ERROR_OCCURRED);
117+
111118
$this->logger->err(Message::LOGIN_FAILED, [
112119
'error' => $e->getMessage(),
113120
'file' => $e->getFile(),

src/Admin/src/Handler/Admin/GetAdminCreateFormHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(
2929

3030
public function handle(ServerRequestInterface $request): ResponseInterface
3131
{
32-
$this->form->setAttribute('action', $this->router->generateUri('admin::create-admin'));
32+
$this->form->setAttribute('action', $this->router->generateUri('admin::admin-create'));
3333

3434
return new HtmlResponse(
3535
$this->template->render('admin::add-admin-modal-content', [

src/Admin/src/Handler/Admin/GetAdminDeleteFormHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
4747

4848
$this->form->setAttribute(
4949
'action',
50-
$this->router->generateUri('admin::delete-admin', [
50+
$this->router->generateUri('admin::admin-delete', [
5151
'uuid' => $admin->getUuid()->toString(),
5252
])
5353
);

0 commit comments

Comments
 (0)