diff --git a/app/modules/web/Controllers/Account/SaveEditRestoreController.php b/app/modules/web/Controllers/Account/SaveEditRestoreController.php
index 4c244c5a..7f294a41 100644
--- a/app/modules/web/Controllers/Account/SaveEditRestoreController.php
+++ b/app/modules/web/Controllers/Account/SaveEditRestoreController.php
@@ -29,7 +29,6 @@ use JsonException;
use SP\Core\Application;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
-use SP\Domain\Account\Dtos\AccountHistoryDto;
use SP\Domain\Account\Ports\AccountHistoryService;
use SP\Domain\Account\Ports\AccountService;
use SP\Domain\Core\Acl\AclActionsInterface;
@@ -73,9 +72,7 @@ final class SaveEditRestoreController extends AccountControllerBase
public function saveEditRestoreAction(int $historyId, int $id): bool
{
try {
- $this->accountService->restoreModified(
- AccountHistoryDto::fromAccount($this->accountHistoryService->getById($historyId))
- );
+ $this->accountService->restoreModified($this->accountHistoryService->getById($historyId));
$accountDetails = $this->accountService->getByIdEnriched($id);
diff --git a/app/modules/web/Controllers/Account/SaveRequestController.php b/app/modules/web/Controllers/Account/SaveRequestController.php
index eb6f017c..6a5c33ed 100644
--- a/app/modules/web/Controllers/Account/SaveRequestController.php
+++ b/app/modules/web/Controllers/Account/SaveRequestController.php
@@ -96,7 +96,7 @@ final class SaveRequestController extends AccountControllerBase
->addDescription(__u('Request'))
->addDetail(
__u('Requester'),
- sprintf('%s (%s)', $this->userData->getName(), $this->userData->getLogin())
+ sprintf('%s (%s)', $this->userDto->name, $this->userDto->login)
)
->addDetail(__u('Account'), $accountView->getName())
->addDetail(__u('Client'), $accountView->getClientName())
@@ -106,7 +106,7 @@ final class SaveRequestController extends AccountControllerBase
$deepLink->getUriSigned($this->configData->getPasswordSalt())
)
->addExtra('accountId', $id)
- ->addExtra('whoId', $this->userData->getId())
+ ->addExtra('whoId', $this->userDto->id)
->setExtra('userId', $usersId)
->setExtra(
'email',
diff --git a/app/modules/web/Controllers/Account/ViewHistoryController.php b/app/modules/web/Controllers/Account/ViewHistoryController.php
index 39d5c720..2352b1be 100644
--- a/app/modules/web/Controllers/Account/ViewHistoryController.php
+++ b/app/modules/web/Controllers/Account/ViewHistoryController.php
@@ -65,12 +65,10 @@ final class ViewHistoryController extends AccountControllerBase
try {
$this->accountHistoryHelper->initializeFor(AclActionsInterface::ACCOUNT_HISTORY_VIEW);
- $accountHistoryViewDto = AccountHistoryViewDto::fromArray(
- $this->accountHistoryService->getById($id)->toArray(includeOuter: true)
+ $this->accountHistoryHelper->setViewForAccount(
+ AccountHistoryViewDto::fromArray($this->accountHistoryService->getById($id)->toArray())
);
- $this->accountHistoryHelper->setViewForAccount($accountHistoryViewDto);
-
$this->view->addTemplate('account-history');
$this->view->assign(
diff --git a/app/modules/web/Controllers/Account/ViewLinkController.php b/app/modules/web/Controllers/Account/ViewLinkController.php
index 0ddb22e8..d8b4225a 100644
--- a/app/modules/web/Controllers/Account/ViewLinkController.php
+++ b/app/modules/web/Controllers/Account/ViewLinkController.php
@@ -88,7 +88,9 @@ final class ViewLinkController extends AccountControllerBase
$accountViewDto = AccountViewDto::fromModel(
Serde::deserialize(
- $vault->getData($this->publicLinkService->getPublicLinkKey($publicLink->getHash())->getKey()),
+ $vault->getData(
+ $this->publicLinkService->getPublicLinkKey($publicLink->getHash())->getKey()
+ ),
Simple::class
)
);
@@ -110,7 +112,7 @@ final class ViewLinkController extends AccountControllerBase
if ($useImage) {
$this->view->assign(
'accountPassImage',
- $this->imageUtil->convertText($accountViewDto->getPass())
+ $this->imageUtil->convertText($accountViewDto->pass)
);
} else {
$this->view->assign(
diff --git a/app/modules/web/Controllers/AccountFavorite/AccountFavoriteBase.php b/app/modules/web/Controllers/AccountFavorite/AccountFavoriteBase.php
index a5bcfb63..c8a99ff8 100644
--- a/app/modules/web/Controllers/AccountFavorite/AccountFavoriteBase.php
+++ b/app/modules/web/Controllers/AccountFavorite/AccountFavoriteBase.php
@@ -42,9 +42,9 @@ abstract class AccountFavoriteBase extends SimpleControllerBase
* @throws SPException
*/
public function __construct(
- Application $application,
- SimpleControllerHelper $simpleControllerHelper,
- protected AccountToFavoriteService $accountToFavoriteService
+ Application $application,
+ SimpleControllerHelper $simpleControllerHelper,
+ protected readonly AccountToFavoriteService $accountToFavoriteService
) {
parent::__construct($application, $simpleControllerHelper);
diff --git a/app/modules/web/Controllers/AccountFavorite/MarkController.php b/app/modules/web/Controllers/AccountFavorite/MarkController.php
index d791a9bc..ba10075d 100644
--- a/app/modules/web/Controllers/AccountFavorite/MarkController.php
+++ b/app/modules/web/Controllers/AccountFavorite/MarkController.php
@@ -51,7 +51,7 @@ final class MarkController extends AccountFavoriteBase
public function markAction(int $accountId): bool
{
try {
- $this->accountToFavoriteService->add($accountId, $this->session->getUserData()->getId());
+ $this->accountToFavoriteService->add($accountId, $this->session->getUserData()->id);
return $this->returnJsonResponse(JsonMessage::JSON_SUCCESS, __u('Favorite added'));
} catch (Exception $e) {
diff --git a/app/modules/web/Controllers/AccountFavorite/UnmarkController.php b/app/modules/web/Controllers/AccountFavorite/UnmarkController.php
index 4b191346..e127d64b 100644
--- a/app/modules/web/Controllers/AccountFavorite/UnmarkController.php
+++ b/app/modules/web/Controllers/AccountFavorite/UnmarkController.php
@@ -51,7 +51,7 @@ final class UnmarkController extends AccountFavoriteBase
public function unmarkAction(int $accountId): bool
{
try {
- $this->accountToFavoriteService->delete($accountId, $this->session->getUserData()->getId());
+ $this->accountToFavoriteService->delete($accountId, $this->session->getUserData()->id);
return $this->returnJsonResponse(JsonMessage::JSON_SUCCESS, __u('Favorite deleted'));
} catch (Exception $e) {
diff --git a/app/modules/web/Controllers/AccountFile/AccountFileBase.php b/app/modules/web/Controllers/AccountFile/AccountFileBase.php
index 90528514..46fce048 100644
--- a/app/modules/web/Controllers/AccountFile/AccountFileBase.php
+++ b/app/modules/web/Controllers/AccountFile/AccountFileBase.php
@@ -24,25 +24,30 @@
namespace SP\Modules\Web\Controllers\AccountFile;
-
use SP\Core\Application;
use SP\Domain\Account\Ports\AccountFileService;
+use SP\Domain\Auth\Services\AuthException;
+use SP\Domain\Core\Exceptions\SessionTimeout;
use SP\Modules\Web\Controllers\ControllerBase;
use SP\Mvc\Controller\WebControllerHelper;
+/**
+ * Class AccountFileBase
+ */
abstract class AccountFileBase extends ControllerBase
{
- protected AccountFileService $accountFileService;
+ /**
+ * @throws AuthException
+ * @throws SessionTimeout
+ */
public function __construct(
- Application $application,
- WebControllerHelper $webControllerHelper,
- AccountFileService $accountFileService
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ protected readonly AccountFileService $accountFileService
) {
parent::__construct($application, $webControllerHelper);
$this->checkLoggedIn();
-
- $this->accountFileService = $accountFileService;
}
}
diff --git a/app/modules/web/Controllers/AccountFile/DeleteController.php b/app/modules/web/Controllers/AccountFile/DeleteController.php
index 4ebeabd4..a3996ee6 100644
--- a/app/modules/web/Controllers/AccountFile/DeleteController.php
+++ b/app/modules/web/Controllers/AccountFile/DeleteController.php
@@ -27,9 +27,13 @@ namespace SP\Modules\Web\Controllers\AccountFile;
use Exception;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
+use SP\Domain\Core\Exceptions\SPException;
use SP\Modules\Web\Controllers\Traits\JsonTrait;
use SP\Mvc\Controller\ItemTrait;
+use function SP\__u;
+use function SP\processException;
+
/**
* Class DeleteController
*
@@ -37,17 +41,18 @@ use SP\Mvc\Controller\ItemTrait;
*/
final class DeleteController extends AccountFileBase
{
- use JsonTrait, ItemTrait;
+ use ItemTrait;
+ use JsonTrait;
/**
* Delete action
*
- * @param int|null $id
+ * @param int|null $id
*
* @return bool
- * @throws \JsonException
+ * @throws SPException
*/
- public function deleteAction(?int $id = null): bool
+ public function deleteAction(?int $id): bool
{
try {
if ($id === null) {
@@ -71,7 +76,7 @@ final class DeleteController extends AccountFileBase
$this->accountFileService->delete($id);
- return $this->returnJsonResponse(0, __u('File Deleted'));
+ return $this->returnJsonResponse(0, __u('File deleted'));
} catch (Exception $e) {
processException($e);
diff --git a/app/modules/web/Controllers/AccountFile/DownloadController.php b/app/modules/web/Controllers/AccountFile/DownloadController.php
index ddd52cc3..8267dbdd 100644
--- a/app/modules/web/Controllers/AccountFile/DownloadController.php
+++ b/app/modules/web/Controllers/AccountFile/DownloadController.php
@@ -27,9 +27,11 @@ namespace SP\Modules\Web\Controllers\AccountFile;
use Exception;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
-use SP\Domain\Core\Exceptions\SPException;
use SP\Modules\Web\Controllers\Traits\JsonTrait;
+use function SP\__u;
+use function SP\processException;
+
/**
* Class DownloadController
*
@@ -38,20 +40,18 @@ use SP\Modules\Web\Controllers\Traits\JsonTrait;
final class DownloadController extends AccountFileBase
{
use JsonTrait;
-
+
/**
* Download action
*
- * @param int $id
+ * @param int $id
*
* @return string
*/
public function downloadAction(int $id): string
{
try {
- if (null === ($fileData = $this->accountFileService->getById($id))) {
- throw new SPException(__u('File does not exist'), SPException::INFO);
- }
+ $fileDto = $this->accountFileService->getById($id);
$this->eventDispatcher->notify(
'download.accountFile',
@@ -59,29 +59,29 @@ final class DownloadController extends AccountFileBase
$this,
EventMessage::factory()
->addDescription(__u('File downloaded'))
- ->addDetail(__u('File'), $fileData->getName())
+ ->addDetail(__u('File'), $fileDto->name)
)
);
$response = $this->router->response();
- $response->header('Content-Length', $fileData->getSize());
- $response->header('Content-Type', $fileData->getType());
+ $response->header('Content-Length', $fileDto->size);
+ $response->header('Content-Type', $fileDto->type);
$response->header('Content-Description', ' sysPass file');
$response->header('Content-Transfer-Encoding', 'binary');
$response->header('Accept-Ranges', 'bytes');
- $type = strtolower($fileData->getType());
+ $type = strtolower($fileDto->type);
if ($type === 'application/pdf') {
- $disposition = sprintf('inline; filename="%s"', $fileData->getName());
+ $disposition = sprintf('inline; filename="%s"', $fileDto->name);
} else {
- $disposition = sprintf('attachment; filename="%s"', $fileData->getName());
+ $disposition = sprintf('attachment; filename="%s"', $fileDto->name);
$response->header('Set-Cookie', 'fileDownload=true; path=/');
}
$response->header('Content-Disposition', $disposition);
- $response->body($fileData->getContent());
+ $response->body($fileDto->content);
$response->send(true);
} catch (Exception $e) {
processException($e);
diff --git a/app/modules/web/Controllers/AccountFile/ListController.php b/app/modules/web/Controllers/AccountFile/ListController.php
index 8da41f91..7bd7cf51 100644
--- a/app/modules/web/Controllers/AccountFile/ListController.php
+++ b/app/modules/web/Controllers/AccountFile/ListController.php
@@ -25,11 +25,13 @@
namespace SP\Modules\Web\Controllers\AccountFile;
use Exception;
-use SP\Core\Acl\Acl;
use SP\Core\Events\Event;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Modules\Web\Util\ErrorUtil;
+use function SP\__;
+use function SP\processException;
+
/**
* Class ListController
*
@@ -40,7 +42,7 @@ final class ListController extends AccountFileBase
/**
* Obtener los datos para la vista de archivos de una cuenta
*
- * @param int $accountId Account's ID
+ * @param int $accountId Account's ID
*/
public function listAction(int $accountId): void
{
@@ -53,14 +55,18 @@ final class ListController extends AccountFileBase
try {
$this->view->addTemplate('files-list', 'account');
- $this->view->assign('deleteEnabled', $this->request->analyzeInt('del', false));
- $this->view->assign('files', $this->accountFileService->getByAccountId($accountId));
- $this->view->assign('fileViewRoute', Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_VIEW));
- $this->view->assign('fileDownloadRoute', Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_DOWNLOAD));
- $this->view->assign('fileDeleteRoute', Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_DELETE));
+ $files = $this->accountFileService->getByAccountId($accountId);
- if (!is_array($this->view->files)
- || count($this->view->files) === 0) {
+ $this->view->assign('deleteEnabled', $this->request->analyzeInt('del', false));
+ $this->view->assign('files', $files);
+ $this->view->assign('fileViewRoute', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_VIEW));
+ $this->view->assign(
+ 'fileDownloadRoute',
+ $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_DOWNLOAD)
+ );
+ $this->view->assign('fileDeleteRoute', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_DELETE));
+
+ if (count($files) === 0) {
$this->view->addTemplate('no_records_found', '_partials');
$this->view->assign('message', __('There are no linked files for the account'));
diff --git a/app/modules/web/Controllers/AccountFile/SearchController.php b/app/modules/web/Controllers/AccountFile/SearchController.php
index 962d24aa..992e1d91 100644
--- a/app/modules/web/Controllers/AccountFile/SearchController.php
+++ b/app/modules/web/Controllers/AccountFile/SearchController.php
@@ -27,9 +27,12 @@ namespace SP\Modules\Web\Controllers\AccountFile;
use JsonException;
use SP\Core\Application;
use SP\Domain\Account\Ports\AccountFileService;
+use SP\Domain\Auth\Services\AuthException;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
+use SP\Domain\Core\Exceptions\SessionTimeout;
+use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Http\Dtos\JsonMessage;
use SP\Html\DataGrid\DataGridInterface;
use SP\Modules\Web\Controllers\ControllerBase;
@@ -38,6 +41,8 @@ use SP\Modules\Web\Controllers\Traits\JsonTrait;
use SP\Mvc\Controller\ItemTrait;
use SP\Mvc\Controller\WebControllerHelper;
+use function SP\__u;
+
/**
* Class SearchController
*
@@ -48,21 +53,19 @@ final class SearchController extends ControllerBase
use ItemTrait;
use JsonTrait;
- private AccountFileService $accountFileService;
- private FileGrid $fileGrid;
-
+ /**
+ * @throws AuthException
+ * @throws SessionTimeout
+ */
public function __construct(
- Application $application,
- WebControllerHelper $webControllerHelper,
- FileGrid $fileGrid,
- AccountFileService $accountFileService
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ private readonly FileGrid $fileGrid,
+ private readonly AccountFileService $accountFileService
) {
parent::__construct($application, $webControllerHelper);
$this->checkLoggedIn();
-
- $this->fileGrid = $fileGrid;
- $this->accountFileService = $accountFileService;
}
/**
@@ -72,9 +75,11 @@ final class SearchController extends ControllerBase
* @throws JsonException
* @throws ConstraintException
* @throws QueryException
+ * @throws SPException
*/
public function searchAction(): bool
{
+ /** @noinspection DuplicatedCode */
if (!$this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_FILE_SEARCH)) {
return $this->returnJsonResponse(
JsonMessage::JSON_ERROR,
@@ -95,6 +100,7 @@ final class SearchController extends ControllerBase
* @return DataGridInterface
* @throws ConstraintException
* @throws QueryException
+ * @throws SPException
*/
protected function getSearchGrid(): DataGridInterface
{
diff --git a/app/modules/web/Controllers/AccountHistoryManager/SearchController.php b/app/modules/web/Controllers/AccountHistoryManager/SearchController.php
index 037c0b47..52ba01e8 100644
--- a/app/modules/web/Controllers/AccountHistoryManager/SearchController.php
+++ b/app/modules/web/Controllers/AccountHistoryManager/SearchController.php
@@ -24,12 +24,12 @@
namespace SP\Modules\Web\Controllers\AccountHistoryManager;
-use JsonException;
use SP\Core\Application;
use SP\Domain\Account\Ports\AccountHistoryService;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
+use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Http\Dtos\JsonMessage;
use SP\Html\DataGrid\DataGridInterface;
use SP\Modules\Web\Controllers\ControllerBase;
@@ -39,6 +39,8 @@ use SP\Modules\Web\Controllers\Traits\JsonTrait;
use SP\Mvc\Controller\ItemTrait;
use SP\Mvc\Controller\WebControllerHelper;
+use function SP\__u;
+
/**
* Class SearchController
*
@@ -69,12 +71,13 @@ final class SearchController extends ControllerBase
/**
* @return bool
- * @throws JsonException
* @throws ConstraintException
* @throws QueryException
+ * @throws SPException
*/
public function searchAction(): bool
{
+ /** @noinspection DuplicatedCode */
if (!$this->acl->checkUserAccess(AclActionsInterface::ACCOUNTMGR_HISTORY_SEARCH)) {
return $this->returnJsonResponse(
JsonMessage::JSON_ERROR,
diff --git a/app/modules/web/Controllers/ConfigManager/IndexController.php b/app/modules/web/Controllers/ConfigManager/IndexController.php
index a97fa162..c962b1d6 100644
--- a/app/modules/web/Controllers/ConfigManager/IndexController.php
+++ b/app/modules/web/Controllers/ConfigManager/IndexController.php
@@ -215,12 +215,12 @@ final class IndexController extends ControllerBase
$template->assign(
'isDemoMode',
$this->configData->isDemoEnabled()
- && !$this->userData->getIsAdminApp()
+ && !$this->userDto->getIsAdminApp()
);
$template->assign(
'isDisabled',
$this->configData->isDemoEnabled()
- && !$this->userData->getIsAdminApp() ? 'disabled' : ''
+ && !$this->userDto->getIsAdminApp() ? 'disabled' : ''
);
$template->assign(
'users',
@@ -528,12 +528,12 @@ final class IndexController extends ControllerBase
$template->assign(
'userGroups',
SelectItemAdapter::factory($this->userGroupService->getAll())
- ->getItemsFromModelSelected([$this->userData->getUserGroupId()])
+ ->getItemsFromModelSelected([$this->userDto->getUserGroupId()])
);
$template->assign(
'users',
SelectItemAdapter::factory($this->userService->getAll())
- ->getItemsFromModelSelected([$this->userData->getId()])
+ ->getItemsFromModelSelected([$this->userDto->getId()])
);
return new DataTab(__('Import Accounts'), $template);
@@ -571,11 +571,11 @@ final class IndexController extends ControllerBase
$template->assign(
'downloadConfigBackup',
- !$isDemo && $this->userData->getIsAdminApp()
+ !$isDemo && $this->userDto->getIsAdminApp()
);
$template->assign(
'downloadLog',
- !$isDemo && is_readable($this->pathsContext[Path::LOG_FILE]) && $this->userData->getIsAdminApp()
+ !$isDemo && is_readable($this->pathsContext[Path::LOG_FILE]) && $this->userDto->getIsAdminApp()
);
return new DataTab(__('Information'), $template);
diff --git a/app/modules/web/Controllers/ControllerBase.php b/app/modules/web/Controllers/ControllerBase.php
index 16d70f03..9bd186d0 100644
--- a/app/modules/web/Controllers/ControllerBase.php
+++ b/app/modules/web/Controllers/ControllerBase.php
@@ -42,7 +42,7 @@ use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Core\PhpExtensionCheckerService;
use SP\Domain\Core\UI\ThemeInterface;
use SP\Domain\Http\Ports\RequestService;
-use SP\Domain\User\Dtos\UserDataDto;
+use SP\Domain\User\Dtos\UserDto;
use SP\Domain\User\Models\ProfileData;
use SP\Modules\Web\Controllers\Helpers\LayoutHelper;
use SP\Modules\Web\Controllers\Traits\WebControllerTrait;
@@ -72,7 +72,7 @@ abstract class ControllerBase
protected readonly TemplateInterface $view;
protected readonly LayoutHelper $layoutHelper;
protected readonly UriContextInterface $uriContext;
- protected ?UserDataDto $userData = null;
+ protected ?UserDto $userDto = null;
protected ?ProfileData $userProfileData = null;
protected readonly bool $isAjax;
protected readonly string $actionName;
@@ -104,7 +104,7 @@ abstract class ControllerBase
$loggedIn = $this->session->isLoggedIn();
if ($loggedIn) {
- $this->userData = clone $this->session->getUserData();
+ $this->userDto = clone $this->session->getUserData();
$this->userProfileData = clone $this->session->getUserProfile();
}
@@ -128,10 +128,10 @@ abstract class ControllerBase
$this->view->assign('action', $this->actionName);
if ($loggedIn) {
- $this->view->assignWithScope('userId', $this->userData->getId(), 'ctx');
- $this->view->assignWithScope('userGroupId', $this->userData->getUserGroupId(), 'ctx');
- $this->view->assignWithScope('userIsAdminApp', $this->userData->getIsAdminApp(), 'ctx');
- $this->view->assignWithScope('userIsAdminAcc', $this->userData->getIsAdminAcc(), 'ctx');
+ $this->view->assignWithScope('userId', $this->userDto->id, 'ctx');
+ $this->view->assignWithScope('userGroupId', $this->userDto->userGroupId, 'ctx');
+ $this->view->assignWithScope('userIsAdminApp', $this->userDto->isAdminApp, 'ctx');
+ $this->view->assignWithScope('userIsAdminAcc', $this->userDto->isAdminAcc, 'ctx');
}
}
@@ -185,8 +185,8 @@ abstract class ControllerBase
if ($this->session->isLoggedIn()
&& $this->session->getAuthCompleted() === $requireAuthCompleted
&& $this->configData->isAuthBasicEnabled()
- && $this->browser->checkServerAuthUser($this->userData->getLogin()) === false
- && $this->browser->checkServerAuthUser($this->userData->getSsoLogin()) === false
+ && $this->browser->checkServerAuthUser($this->userDto->login) === false
+ && $this->browser->checkServerAuthUser($this->userDto->ssoLogin) === false
) {
throw new AuthException('Invalid browser auth');
}
@@ -220,6 +220,6 @@ abstract class ControllerBase
*/
protected function checkAccess(int $action): bool
{
- return $this->userData->getIsAdminApp() || $this->acl->checkUserAccess($action);
+ return $this->userDto->isAdminApp || $this->acl->checkUserAccess($action);
}
}
diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php
index cbf2ab6f..e027eead 100644
--- a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php
+++ b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php
@@ -191,8 +191,8 @@ final class AccountHelper extends AccountHelperBase
if ($this->configData->isPublinksEnabled() && $this->accountPermission->isShowLink()) {
try {
$publicLinkData = $this->publicLinkService->getHashForItem($this->accountId);
- $accountActionsDto->setPublicLinkId($publicLinkData->getId());
- $accountActionsDto->setPublicLinkCreatorId($publicLinkData->getUserId());
+ $accountActionsDto->setPublicLinkId($publicLinkData['id']);
+ $accountActionsDto->setPublicLinkCreatorId($publicLinkData['userId']);
$baseUrl = ($this->configData->getApplicationUrl() ?: $this->uriContext->getWebUri()) .
$this->uriContext->getSubUri();
@@ -201,10 +201,10 @@ final class AccountHelper extends AccountHelperBase
'publicLinkUrl',
PublicLink::getLinkForHash(
$baseUrl,
- $publicLinkData->getHash()
+ $publicLinkData['hash']
)
);
- $this->view->assign('publicLinkId', $publicLinkData->getId());
+ $this->view->assign('publicLinkId', $publicLinkData['id']);
} catch (NoSuchItemException $e) {
$this->view->assign('publicLinkId', 0);
$this->view->assign('publicLinkUrl', null);
@@ -221,15 +221,15 @@ final class AccountHelper extends AccountHelperBase
$this->view->assign(
'allowPrivate',
($userProfileData->isAccPrivate()
- && $accountData->getUserId() === $userData->getId())
- || $userData->getIsAdminApp()
+ && $accountData->getUserId() === $userData->id)
+ || $userData->isAdminApp
);
$this->view->assign(
'allowPrivateGroup',
($userProfileData->isAccPrivateGroup()
- && $accountData->getUserGroupId() === $userData->getUserGroupId())
- || $userData->getIsAdminApp()
+ && $accountData->getUserGroupId() === $userData->userGroupId)
+ || $userData->isAdminApp
);
$this->view->assign(
@@ -382,8 +382,8 @@ final class AccountHelper extends AccountHelperBase
$userData = $this->context->getUserData();
$this->accountPermission->setShowPermission(
- $userData->getIsAdminApp()
- || $userData->getIsAdminAcc()
+ $userData->isAdminApp
+ || $userData->isAdminAcc
|| $userProfileData->isAccPermission()
);
@@ -427,8 +427,8 @@ final class AccountHelper extends AccountHelperBase
$this->view->assign('users', $selectUsers->getItemsFromModel());
$this->view->assign('userGroups', $selectUserGroups->getItemsFromModel());
$this->view->assign('tags', $selectTags->getItemsFromModel());
- $this->view->assign('allowPrivate', $userProfileData->isAccPrivate() || $userData->getIsAdminApp());
- $this->view->assign('allowPrivateGroup', $userProfileData->isAccPrivateGroup() || $userData->getIsAdminApp());
+ $this->view->assign('allowPrivate', $userProfileData->isAccPrivate() || $userData->isAdminApp);
+ $this->view->assign('allowPrivateGroup', $userProfileData->isAccPrivateGroup() || $userData->isAdminApp);
$this->view->assign('privateUserCheck', $accountPrivate->isPrivateUser());
$this->view->assign('privateUserGroupCheck', $accountPrivate->isPrivateGroup());
$this->view->assign('accountId', 0);
diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelperBase.php b/app/modules/web/Controllers/Helpers/Account/AccountHelperBase.php
index 2d7e19ae..72c35e0d 100644
--- a/app/modules/web/Controllers/Helpers/Account/AccountHelperBase.php
+++ b/app/modules/web/Controllers/Helpers/Account/AccountHelperBase.php
@@ -73,7 +73,7 @@ abstract class AccountHelperBase extends HelperBase
throw UnauthorizedPageException::info($actionId);
}
- if (!$this->masterPassService->checkUserUpdateMPass($this->context->getUserData()->getLastUpdateMPass())
+ if (!$this->masterPassService->checkUserUpdateMPass($this->context->getUserData()->lastUpdateMPass)
) {
throw UpdatedMasterPassException::info(__u('The master password needs to be updated'));
}
diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php
index 087e34fe..ef806651 100644
--- a/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php
+++ b/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php
@@ -28,25 +28,20 @@ use SP\Core\Application;
use SP\Domain\Account\Adapters\AccountPermission;
use SP\Domain\Account\Dtos\AccountAclDto;
use SP\Domain\Account\Dtos\AccountHistoryViewDto;
-use SP\Domain\Account\Models\AccountHistory;
use SP\Domain\Account\Ports\AccountAclService;
use SP\Domain\Account\Ports\AccountHistoryService;
use SP\Domain\Account\Ports\AccountToUserGroupService;
use SP\Domain\Account\Ports\AccountToUserService;
use SP\Domain\Category\Ports\CategoryService;
use SP\Domain\Client\Ports\ClientService;
-use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Acl\AccountPermissionException;
use SP\Domain\Core\Acl\AclInterface;
use SP\Domain\Core\Acl\UnauthorizedActionException;
-use SP\Domain\Core\Acl\UnauthorizedPageException;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Crypt\Ports\MasterPassService;
use SP\Domain\Http\Ports\RequestService;
-use SP\Domain\User\Services\UpdatedMasterPassException;
-use SP\Infrastructure\Common\Repositories\NoSuchItemException;
use SP\Mvc\View\Components\SelectItemAdapter;
use SP\Mvc\View\TemplateInterface;
@@ -76,16 +71,13 @@ final class AccountHistoryHelper extends AccountHelperBase
}
/**
- * @param AccountHistory $accountHistoryViewDto
+ * @param AccountHistoryViewDto $accountHistoryViewDto
*
* @throws AccountPermissionException
- * @throws UnauthorizedPageException
* @throws ConstraintException
* @throws QueryException
* @throws SPException
- * @throws ServiceException
- * @throws UpdatedMasterPassException
- * @throws NoSuchItemException
+ * @throws UnauthorizedActionException
*/
public function setViewForAccount(AccountHistoryViewDto $accountHistoryViewDto): void
{
@@ -93,7 +85,7 @@ final class AccountHistoryHelper extends AccountHelperBase
throw new UnauthorizedActionException();
}
- $this->accountId = $accountHistoryViewDto->getAccountId();
+ $this->accountId = $accountHistoryViewDto->accountId;
$this->checkAccess($accountHistoryViewDto);
@@ -108,30 +100,30 @@ final class AccountHistoryHelper extends AccountHelperBase
'historyData',
SelectItemAdapter::factory(
self::mapHistoryForDateSelect($this->accountHistoryService->getHistoryForAccount($this->accountId))
- )->getItemsFromArraySelected([$accountHistoryViewDto->getId()])
+ )->getItemsFromArraySelected([$accountHistoryViewDto->id])
);
- $this->view->assign('accountPassDate', date('Y-m-d H:i:s', $accountHistoryViewDto->getPassDate()));
+ $this->view->assign('accountPassDate', date('Y-m-d H:i:s', $accountHistoryViewDto->passDate));
$this->view->assign(
'accountPassDateChange',
- date('Y-m-d', $accountHistoryViewDto->getPassDateChange() ?: 0)
+ date('Y-m-d', $accountHistoryViewDto->passDateChange ?: 0)
);
$this->view->assign(
'categories',
SelectItemAdapter::factory($this->categoryService->getAll())
- ->getItemsFromModelSelected([$accountHistoryViewDto->getCategoryId()])
+ ->getItemsFromModelSelected([$accountHistoryViewDto->categoryId])
);
$this->view->assign(
'clients',
SelectItemAdapter::factory($this->clientService->getAll())
- ->getItemsFromModelSelected([$accountHistoryViewDto->getClientId()])
+ ->getItemsFromModelSelected([$accountHistoryViewDto->clientId])
);
$this->view->assign(
'isModified',
- strtotime($accountHistoryViewDto->getDateEdit()) !== false
+ strtotime($accountHistoryViewDto->dateEdit) !== false
);
- $accountActionsDto = new AccountActionsDto($this->accountId, $accountHistoryViewDto->getId(), 0);
+ $accountActionsDto = new AccountActionsDto($this->accountId, $accountHistoryViewDto->id, 0);
$this->view->assign(
'accountActions',
@@ -144,10 +136,6 @@ final class AccountHistoryHelper extends AccountHelperBase
}
/**
- * Comprobar si el usuario dispone de acceso al módulo
- *
- * @param AccountHistoryViewDto $accountHistoryViewDto
- *
* @throws AccountPermissionException
* @throws ConstraintException
* @throws QueryException
@@ -157,11 +145,11 @@ final class AccountHistoryHelper extends AccountHelperBase
{
$acccountAclDto = new AccountAclDto(
$this->accountId,
- $accountHistoryViewDto->getUserId(),
+ $accountHistoryViewDto->userId,
$this->accountToUserService->getUsersByAccountId($this->accountId),
- $accountHistoryViewDto->getUserGroupId(),
+ $accountHistoryViewDto->userGroupId,
$this->accountToUserGroupService->getUserGroupsByAccountId($this->accountId),
- $accountHistoryViewDto->getDateEdit()
+ $accountHistoryViewDto->dateEdit
);
$this->accountPermission = $this->accountAclService->getAcl($this->actionId, $acccountAclDto, true);
diff --git a/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php
index 8751aa3a..1ed1670d 100644
--- a/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php
+++ b/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php
@@ -129,7 +129,7 @@ final class AccountPasswordHelper extends HelperBase
{
$this->checkActionAccess();
- if (!$this->masterPassService->checkUserUpdateMPass($this->context->getUserData()->getLastUpdateMPass())) {
+ if (!$this->masterPassService->checkUserUpdateMPass($this->context->getUserData()->lastUpdateMPass)) {
throw new HelperException(
__('Master password updated')
. '
'
diff --git a/app/modules/web/Controllers/Helpers/Account/AccountSearchData.php b/app/modules/web/Controllers/Helpers/Account/AccountSearchData.php
index 7102c168..9acaa541 100644
--- a/app/modules/web/Controllers/Helpers/Account/AccountSearchData.php
+++ b/app/modules/web/Controllers/Helpers/Account/AccountSearchData.php
@@ -133,11 +133,11 @@ final class AccountSearchData
public function buildFrom(QueryResult $queryResult): QueryResult
{
$maxTextLength = $this->configData->isResultsAsCards() ? self::TEXT_LENGTH_CARDS : self::TEXT_LENGTH_NORMAL;
- $userPreferencesData = $this->context->getUserData()->getPreferences();
+ $userPreferencesData = $this->context->getUserData()->preferences;
$accountLinkEnabled = (null !== $userPreferencesData && $userPreferencesData->isAccountLink())
|| $this->configData->isAccountLink();
- $favorites = $this->accountToFavoriteService->getForUserId($this->context->getUserData()->getId());
+ $favorites = $this->accountToFavoriteService->getForUserId($this->context->getUserData()->id);
return $queryResult->mutateWithCallback(
function (AccountSearchView $accountSearchView) use (
diff --git a/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php
index 2b811cf2..5fe15983 100644
--- a/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php
+++ b/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php
@@ -99,7 +99,7 @@ final class AccountSearchHelper extends HelperBase
{
$userData = $this->context->getUserData();
- $this->view->assign('isAdmin', $userData->getIsAdminApp() || $userData->getIsAdminAcc());
+ $this->view->assign('isAdmin', $userData->isAdminApp || $userData->isAdminAcc);
$profileData = $this->context->getUserProfile() ?? new ProfileData();
@@ -136,7 +136,7 @@ final class AccountSearchHelper extends HelperBase
return $accountSearchFilter;
}
- $userPreferences = $this->context->getUserData()->getPreferences() ?? new UserPreferences();
+ $userPreferences = $this->context->getUserData()->preferences ?? new UserPreferences();
$limitCount = $userPreferences->getResultsPerPage() > 0
? $userPreferences->getResultsPerPage()
: $this->configData->getAccountCount();
@@ -207,7 +207,7 @@ final class AccountSearchHelper extends HelperBase
|| $this->accountSearchFilter->isSearchFavorites()
|| $this->accountSearchFilter->isSortViews());
- $userPreferences = $this->context->getUserData()->getPreferences() ?? new UserPreferences();
+ $userPreferences = $this->context->getUserData()->preferences ?? new UserPreferences();
AccountSearchItem::$accountLink = $userPreferences->isAccountLink();
AccountSearchItem::$topNavbar = $userPreferences->isTopNavbar();
@@ -283,7 +283,7 @@ final class AccountSearchHelper extends HelperBase
$gridPager->setFilterOn($this->filterOn);
$gridPager->setSourceAction(new DataGridActionSearch(AclActionsInterface::ACCOUNT_SEARCH));
- $userPreferences = $this->context->getUserData()->getPreferences() ?? new UserPreferences();
+ $userPreferences = $this->context->getUserData()->preferences ?? new UserPreferences();
$showOptionalActions = $userPreferences->isOptionalActions()
|| $userPreferences->isResultsAsCards()
|| ($userPreferences->getUserId() === 0
diff --git a/app/modules/web/Controllers/Helpers/Grid/FileGrid.php b/app/modules/web/Controllers/Helpers/Grid/FileGrid.php
index 659fbdc8..34688b72 100644
--- a/app/modules/web/Controllers/Helpers/Grid/FileGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/FileGrid.php
@@ -24,7 +24,6 @@
namespace SP\Modules\Web\Controllers\Helpers\Grid;
-use SP\Core\Acl\Acl;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Exceptions\SPException;
use SP\Html\DataGrid\Action\DataGridAction;
@@ -52,6 +51,7 @@ final class FileGrid extends GridBase
* @param QueryResult $queryResult
*
* @return DataGridInterface
+ * @throws SPException
*/
public function getGrid(QueryResult $queryResult): DataGridInterface
{
@@ -81,6 +81,9 @@ final class FileGrid extends GridBase
return $grid;
}
+ /**
+ * @throws SPException
+ */
protected function getGridLayout(): DataGridInterface
{
// Grid
@@ -143,7 +146,7 @@ final class FileGrid extends GridBase
$gridActionSearch->setOnSubmitFunction('appMgmt/search');
$gridActionSearch->addData(
'action-route',
- Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_SEARCH)
+ $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_SEARCH)
);
return $gridActionSearch;
@@ -161,7 +164,7 @@ final class FileGrid extends GridBase
$gridAction->setFilterRowSource('type', 'application/pdf');
$gridAction->addData(
'action-route',
- Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_VIEW)
+ $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_VIEW)
);
return $gridAction;
@@ -178,7 +181,7 @@ final class FileGrid extends GridBase
$gridAction->setOnClickFunction('file/download');
$gridAction->addData(
'action-route',
- Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_DOWNLOAD)
+ $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_DOWNLOAD)
);
$gridAction->setRuntimeData(
function ($dataItem) {
@@ -200,7 +203,7 @@ final class FileGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/delete');
$gridAction->addData(
'action-route',
- Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_DELETE)
+ $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_DELETE)
);
return $gridAction;
diff --git a/app/modules/web/Controllers/Helpers/LayoutHelper.php b/app/modules/web/Controllers/Helpers/LayoutHelper.php
index 93baf1d1..459c2691 100644
--- a/app/modules/web/Controllers/Helpers/LayoutHelper.php
+++ b/app/modules/web/Controllers/Helpers/LayoutHelper.php
@@ -178,7 +178,7 @@ final class LayoutHelper extends HelperBase
$this->view->append('jsLinks', $jsUriTheme->getUriSigned($this->configData->getPasswordSalt()));
}
- $userPreferences = $this->context->getUserData()->getPreferences();
+ $userPreferences = $this->context->getUserData()->preferences;
if ($this->loggedIn
&& $userPreferences
@@ -237,20 +237,20 @@ final class LayoutHelper extends HelperBase
{
$userType = null;
- $userData = $this->context->getUserData();
+ $userDto = $this->context->getUserData();
$icons = $this->theme->getIcons();
- if ($userData->getIsAdminApp()) {
+ if ($userDto->isAdminApp) {
$userType = $icons->appAdmin();
- } elseif ($userData->getIsAdminAcc()) {
+ } elseif ($userDto->isAdminAcc) {
$userType = $icons->accAdmin();
}
$this->view->assign('ctx_userType', $userType);
- $this->view->assign('ctx_userLogin', mb_strtoupper($userData->getLogin()));
- $this->view->assign('ctx_userName', $userData->getName() ?: mb_strtoupper($userData->getLogin()));
- $this->view->assign('ctx_userGroup', $userData->getUserGroupName());
- $this->view->assign('showPassIcon', !($this->configData->isLdapEnabled() && $userData->getIsLdap()));
+ $this->view->assign('ctx_userLogin', mb_strtoupper($userDto->login));
+ $this->view->assign('ctx_userName', $userDto->name ?: mb_strtoupper($userDto->login));
+ $this->view->assign('ctx_userGroup', $userDto->userGroupName);
+ $this->view->assign('showPassIcon', !($this->configData->isLdapEnabled() && $userDto->isLdap));
}
/**
diff --git a/app/modules/web/Controllers/Notification/DeleteController.php b/app/modules/web/Controllers/Notification/DeleteController.php
index c4197a77..f30e78e8 100644
--- a/app/modules/web/Controllers/Notification/DeleteController.php
+++ b/app/modules/web/Controllers/Notification/DeleteController.php
@@ -53,7 +53,7 @@ final class DeleteController extends NotificationSaveBase
{
try {
if ($id === null) {
- if ($this->userData->getIsAdminApp()) {
+ if ($this->userDto->getIsAdminApp()) {
$this->notificationService->deleteAdminBatch($this->getItemsIdFromRequest($this->request));
} else {
$this->notificationService->deleteByIdBatch($this->getItemsIdFromRequest($this->request));
@@ -67,7 +67,7 @@ final class DeleteController extends NotificationSaveBase
return $this->returnJsonResponse(JsonMessage::JSON_SUCCESS, __u('Notifications deleted'));
}
- if ($this->userData->getIsAdminApp()) {
+ if ($this->userDto->getIsAdminApp()) {
$this->notificationService->deleteAdmin($id);
} else {
$this->notificationService->delete($id);
diff --git a/app/modules/web/Controllers/Notification/NotificationViewBase.php b/app/modules/web/Controllers/Notification/NotificationViewBase.php
index 2f80de16..a6fbef07 100644
--- a/app/modules/web/Controllers/Notification/NotificationViewBase.php
+++ b/app/modules/web/Controllers/Notification/NotificationViewBase.php
@@ -79,7 +79,7 @@ abstract class NotificationViewBase extends ControllerBase
$this->view->assign('notification', $notification);
- if ($this->userData->getIsAdminApp()) {
+ if ($this->userDto->getIsAdminApp()) {
$this->view->assign(
'users',
SelectItemAdapter::factory($this->userService->getAll())
diff --git a/app/modules/web/Controllers/UserSettingsGeneral/SaveController.php b/app/modules/web/Controllers/UserSettingsGeneral/SaveController.php
index 29fa9174..35af7401 100644
--- a/app/modules/web/Controllers/UserSettingsGeneral/SaveController.php
+++ b/app/modules/web/Controllers/UserSettingsGeneral/SaveController.php
@@ -29,7 +29,7 @@ use JsonException;
use SP\Core\Application;
use SP\Core\Events\Event;
use SP\Domain\Http\Dtos\JsonMessage;
-use SP\Domain\User\Dtos\UserDataDto;
+use SP\Domain\User\Dtos\UserDto;
use SP\Domain\User\Models\UserPreferences;
use SP\Domain\User\Ports\UserService;
use SP\Domain\User\Services\User;
@@ -87,11 +87,11 @@ final class SaveController extends SimpleControllerBase
}
/**
- * @param UserDataDto $userData
+ * @param UserDto $userData
*
* @return UserPreferences
*/
- private function getUserPreferencesData(UserDataDto $userData): UserPreferences
+ private function getUserPreferencesData(UserDto $userData): UserPreferences
{
$userPreferencesData = clone $userData->getPreferences();
diff --git a/app/modules/web/Forms/AccountForm.php b/app/modules/web/Forms/AccountForm.php
index a0139681..874bf37a 100644
--- a/app/modules/web/Forms/AccountForm.php
+++ b/app/modules/web/Forms/AccountForm.php
@@ -30,6 +30,7 @@ use SP\Domain\Account\Dtos\AccountDto;
use SP\Domain\Account\Dtos\AccountUpdateDto;
use SP\Domain\Account\Ports\AccountPresetService;
use SP\Domain\Core\Acl\AclActionsInterface;
+use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Core\Exceptions\ValidationException;
use SP\Domain\Http\Ports\RequestService;
use SP\Util\Chainable;
@@ -41,18 +42,15 @@ use function SP\__u;
*/
final class AccountForm extends FormBase implements FormInterface
{
- private AccountPresetService $accountPresetService;
private null|AccountCreateDto|AccountUpdateDto $accountDto = null;
public function __construct(
- Application $application,
- RequestService $request,
- AccountPresetService $accountPresetService,
- ?int $itemId = null
+ Application $application,
+ RequestService $request,
+ private readonly AccountPresetService $accountPresetService,
+ ?int $itemId = null
) {
parent::__construct($application, $request, $itemId);
-
- $this->accountPresetService = $accountPresetService;
}
/**
@@ -71,39 +69,35 @@ final class AccountForm extends FormBase implements FormInterface
$chain = new Chainable(fn() => $this->analyzeRequestData(), $this);
- switch ($action) {
- case AclActionsInterface::ACCOUNT_EDIT_PASS:
- $this->accountDto = $chain->next(fn(AccountDto $dto) => $this->checkPassword($dto))
- ->next(
- fn(AccountDto $dto) => $this->accountPresetService->checkPasswordPreset(
- $dto
- )
- )
- ->resolve();
- break;
- case AclActionsInterface::ACCOUNT_EDIT:
- $this->accountDto = $chain->next(fn(AccountDto $dto) => $this->analyzeItems($dto))
- ->next(fn(AccountDto $dto) => $this->checkCommon($dto))
- ->resolve();
- break;
- case AclActionsInterface::ACCOUNT_CREATE:
- case AclActionsInterface::ACCOUNT_COPY:
- $this->accountDto = $chain->next(fn(AccountDto $dto) => $this->analyzeItems($dto))
- ->next(fn(AccountDto $dto) => $this->checkCommon($dto))
- ->next(fn(AccountDto $dto) => $this->checkPassword($dto))
- ->next(
- fn(AccountDto $dto) => $this->accountPresetService->checkPasswordPreset(
- $dto
- )
- )
- ->resolve();
- break;
- case AclActionsInterface::ACCOUNTMGR_BULK_EDIT:
- $this->accountDto = $chain->next(fn(AccountDto $dto) => $this->analyzeItems($dto))
- ->next(fn(AccountDto $dto) => $this->analyzeBulkEdit($dto))
- ->resolve();
- break;
- }
+ $this->accountDto = match ($action) {
+ AclActionsInterface::ACCOUNT_EDIT_PASS =>
+ $chain->next(fn(AccountDto $dto) => $this->checkPassword($dto))
+ ->next(
+ fn(AccountDto $dto) => $this->accountPresetService->checkPasswordPreset(
+ $dto
+ )
+ )
+ ->resolve(),
+ AclActionsInterface::ACCOUNT_EDIT =>
+ $chain->next(fn(AccountDto $dto) => $this->analyzeItems($dto))
+ ->next(fn(AccountDto $dto) => $this->checkCommon($dto))
+ ->resolve(),
+ AclActionsInterface::ACCOUNT_CREATE,
+ AclActionsInterface::ACCOUNT_COPY =>
+ $chain->next(fn(AccountDto $dto) => $this->analyzeItems($dto))
+ ->next(fn(AccountDto $dto) => $this->checkCommon($dto))
+ ->next(fn(AccountDto $dto) => $this->checkPassword($dto))
+ ->next(
+ fn(AccountDto $dto) => $this->accountPresetService->checkPasswordPreset(
+ $dto
+ )
+ )
+ ->resolve(),
+ AclActionsInterface::ACCOUNTMGR_BULK_EDIT =>
+ $chain->next(fn(AccountDto $dto) => $this->analyzeItems($dto))
+ ->next(fn(AccountDto $dto) => $this->analyzeBulkEdit($dto))
+ ->resolve()
+ };
return $this;
}
@@ -112,62 +106,29 @@ final class AccountForm extends FormBase implements FormInterface
* Analizar los datos de la petición HTTP
*
* @return AccountCreateDto|AccountUpdateDto
+ * @throws SPException
*/
private function analyzeRequestData(): AccountCreateDto|AccountUpdateDto
{
- $name = $this->request->analyzeString('name');
- $login = $this->request->analyzeString('login');
- $clientId = $this->request->analyzeInt('client_id');
- $categoryId = $this->request->analyzeInt('category_id');
- $password = $this->request->analyzeEncrypted('password');
- $userId = $this->request->analyzeInt('owner_id');
- $url = $this->request->analyzeString('url');
- $notes = $this->request->analyzeUnsafeString('notes');
- $private = (int)$this->request->analyzeBool('private_enabled', false);
- $privateGroup = (int)$this->request->analyzeBool('private_group_enabled', false);
- $passDateChange = $this->request->analyzeInt('password_date_expire_unix');
- $parentId = $this->request->analyzeInt('parent_account_id');
- $userGroupId = $this->request->analyzeInt('main_usergroup_id');
+ $properties = [
+ 'name' => $this->request->analyzeString('name'),
+ 'login' => $this->request->analyzeString('login'),
+ 'clientId' => $this->request->analyzeInt('client_id'),
+ 'categoryId' => $this->request->analyzeInt('category_id'),
+ 'pass' => $this->request->analyzeEncrypted('password'),
+ 'userId' => $this->request->analyzeInt('owner_id', $this->context->getUserData()->id),
+ 'url' => $this->request->analyzeString('url'),
+ 'notes' => $this->request->analyzeUnsafeString('notes'),
+ 'private' => (int)$this->request->analyzeBool('private_enabled', false),
+ 'privateGroup' => (int)$this->request->analyzeBool('private_group_enabled', false),
+ 'passDateChange' => $this->request->analyzeInt('password_date_expire_unix'),
+ 'parentId' => $this->request->analyzeInt('parent_account_id'),
+ 'userGroupId' => $this->request->analyzeInt('main_usergroup_id'),
+ ];
- if (null === $this->itemId) {
- $accountDto = new AccountCreateDto(
- $name,
- $login,
- $clientId,
- $categoryId,
- $password,
- $userId,
- null,
- $url,
- $notes,
- $this->context->getUserData()->getId(),
- $private,
- $privateGroup,
- $passDateChange,
- $parentId,
- $userGroupId
- );
- } else {
- $accountDto = new AccountUpdateDto(
- $name,
- $login,
- $clientId,
- $categoryId,
- $password,
- $userId,
- null,
- $url,
- $notes,
- $this->context->getUserData()->getId(),
- $private,
- $privateGroup,
- $passDateChange,
- $parentId,
- $userGroupId
- );
- }
-
- return $accountDto;
+ return $this->itemId === null ? AccountCreateDto::fromArray($properties) : AccountUpdateDto::fromArray(
+ $properties
+ );
}
/**
@@ -175,21 +136,24 @@ final class AccountForm extends FormBase implements FormInterface
*/
private function checkPassword(AccountDto $accountDto): AccountDto
{
- if ($accountDto->getParentId() > 0) {
+ if ($accountDto->parentId > 0) {
return $accountDto;
}
- if (!$accountDto->getPass()) {
+ if (!$accountDto->pass) {
throw new ValidationException(__u('A key is needed'));
}
- if ($this->request->analyzeEncrypted('password_repeat') !== $accountDto->getPass()) {
+ if ($this->request->analyzeEncrypted('password_repeat') !== $accountDto->pass) {
throw new ValidationException(__u('Passwords do not match'));
}
return $accountDto;
}
+ /**
+ * @throws SPException
+ */
private function analyzeItems(AccountDto $accountDto): AccountDto
{
if ($this->request->analyzeInt('other_users_view_update') === 1) {
@@ -222,21 +186,24 @@ final class AccountForm extends FormBase implements FormInterface
*/
private function checkCommon(AccountDto $accountDto): AccountDto
{
- if (!$accountDto->getName()) {
+ if (!$accountDto->name) {
throw new ValidationException(__u('An account name needed'));
}
- if (!$accountDto->getClientId()) {
+ if (!$accountDto->clientId) {
throw new ValidationException(__u('A client is needed'));
}
- if (!$accountDto->getCategoryId()) {
+ if (!$accountDto->categoryId) {
throw new ValidationException(__u('A category is needed'));
}
return $accountDto;
}
+ /**
+ * @throws SPException
+ */
private function analyzeBulkEdit(AccountDto $accountDto): AccountDto
{
if ($this->request->analyzeBool('clear_permission_users_view', false)) {
diff --git a/app/modules/web/themes/material-blue/views/account/account-history.inc b/app/modules/web/themes/material-blue/views/account/account-history.inc
index d8a65480..bb06e98c 100644
--- a/app/modules/web/themes/material-blue/views/account/account-history.inc
+++ b/app/modules/web/themes/material-blue/views/account/account-history.inc
@@ -25,6 +25,7 @@
use SP\Domain\Account\Adapters\AccountPermission;
use SP\Domain\Account\Dtos\AccountHistoryViewDto;
+use SP\Domain\Account\Dtos\AccountViewDto;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\UI\ThemeIconsInterface;
use SP\Mvc\View\Components\SelectItem;
@@ -34,7 +35,7 @@ use function SP\__;
/**
* @var callable $_getvar
* @var ThemeIconsInterface $icons
- * @var AccountHistoryViewDto $accountView
+ * @var AccountHistoryViewDto|AccountViewDto $accountView
* @var AccountPermission $accountAcl
* @var ConfigDataInterface $configData
*/
@@ -90,7 +91,7 @@ $accountAcl = $_getvar('accountAcl');
class="mdl-textfield__input mdl-color-text--indigo-400"
maxlength="50"
value="getName(), ENT_QUOTES); ?>"
+ echo htmlspecialchars($accountView->name, ENT_QUOTES); ?>"
tabindex="1" readonly>
- *
- * The return value will be cast to boolean if non-boolean was returned.
- */
- public function offsetExists(mixed $offset): bool
- {
- return array_key_exists($offset, $this->properties);
- }
-
- /**
- * Unset a non-class property
- *
- * @param mixed $offset
- *
- * @return void
- */
- public function offsetUnset(mixed $offset): void
- {
- unset($this->properties[$offset]);
+ throw new Error('Dynamic properties not allowed');
}
}
diff --git a/lib/SP/Domain/Common/Ports/Dto.php b/lib/SP/Domain/Common/Ports/Dto.php
new file mode 100644
index 00000000..197e7510
--- /dev/null
+++ b/lib/SP/Domain/Common/Ports/Dto.php
@@ -0,0 +1,59 @@
+.
+ */
+
+namespace SP\Domain\Common\Ports;
+
+use SP\Domain\Common\Models\Model;
+use SP\Infrastructure\Database\QueryResult;
+
+/**
+ * Interface Dto
+ */
+interface Dto
+{
+ /**
+ * @param QueryResult $queryResult
+ * @param string|null $type
+ * @return static
+ */
+ public static function fromResult(QueryResult $queryResult, ?string $type = null): static;
+
+ /**
+ * @param Model $model
+ * @return static
+ */
+ public static function fromModel(Model $model): static;
+
+ public static function fromArray(array $properties): static;
+
+ /**
+ * Set any properties in batch mode. This allows to set any property from dynamic calls.
+ *
+ * @param string[] $properties
+ * @param array $values
+ *
+ * @return Dto Returns a new instance with the poperties set.
+ */
+ public function setBatch(array $properties, array $values): static;
+}
diff --git a/lib/SP/Domain/Config/Services/ConfigFile.php b/lib/SP/Domain/Config/Services/ConfigFile.php
index 68c18f25..04d2e631 100644
--- a/lib/SP/Domain/Config/Services/ConfigFile.php
+++ b/lib/SP/Domain/Config/Services/ConfigFile.php
@@ -176,7 +176,7 @@ class ConfigFile implements ConfigFileService
ConfigDataInterface $configData,
?bool $commit = true
): ConfigFileService {
- $configSaver = $this->context->getUserData()->getLogin() ?: AppInfoInterface::APP_NAME;
+ $configSaver = $this->context->getUserData()->login ?: AppInfoInterface::APP_NAME;
$configData->setConfigDate(time());
$configData->setConfigSaver($configSaver);
diff --git a/lib/SP/Domain/Core/Context/Context.php b/lib/SP/Domain/Core/Context/Context.php
index dbe32d4b..5835f5c2 100644
--- a/lib/SP/Domain/Core/Context/Context.php
+++ b/lib/SP/Domain/Core/Context/Context.php
@@ -27,7 +27,7 @@ namespace SP\Domain\Core\Context;
use SP\Core\Context\ContextException;
use SP\Domain\Account\Dtos\AccountCacheDto;
-use SP\Domain\User\Dtos\UserDataDto;
+use SP\Domain\User\Dtos\UserDto;
use SP\Domain\User\Models\ProfileData;
/**
@@ -57,7 +57,7 @@ interface Context
/**
* Establece los datos del usuario en la sesión.
*/
- public function setUserData(?UserDataDto $userDataDto = null);
+ public function setUserData(?UserDto $userDataDto = null);
/**
* Obtiene el objeto de perfil de usuario de la sesión.
@@ -77,7 +77,7 @@ interface Context
/**
* Devuelve los datos del usuario en la sesión.
*/
- public function getUserData(): UserDataDto;
+ public function getUserData(): UserDto;
/**
* Establecer el lenguaje de la sesión
diff --git a/lib/SP/Domain/Export/Services/XmlExport.php b/lib/SP/Domain/Export/Services/XmlExport.php
index 9fd02b49..84c96ec6 100644
--- a/lib/SP/Domain/Export/Services/XmlExport.php
+++ b/lib/SP/Domain/Export/Services/XmlExport.php
@@ -179,7 +179,7 @@ final class XmlExport extends Service implements XmlExportService
private function appendMeta(): void
{
try {
- $userData = $this->context->getUserData();
+ $userDto = $this->context->getUserData();
$nodeMeta = $this->document->createElement('Meta');
$nodeMeta->append(
@@ -188,11 +188,11 @@ final class XmlExport extends Service implements XmlExportService
$this->document->createElement('Time', (string)time()),
$this->document->createElement(
'User',
- $this->document->createTextNode($userData->getLogin())->nodeValue
+ $this->document->createTextNode($userDto->login)->nodeValue
),
$this->document->createElement(
'Group',
- $this->document->createTextNode($userData->getUserGroupName())->nodeValue
+ $this->document->createTextNode($userDto->userGroupName)->nodeValue
)
);
diff --git a/lib/SP/Domain/Import/Services/CsvImport.php b/lib/SP/Domain/Import/Services/CsvImport.php
index 3c9a9399..f72fd717 100644
--- a/lib/SP/Domain/Import/Services/CsvImport.php
+++ b/lib/SP/Domain/Import/Services/CsvImport.php
@@ -121,10 +121,10 @@ final class CsvImport extends ImportBase implements ItemsImportService
$categoryId = $this->addCategory(new Category(['name' => $categoryName]));
$accountCreateDto = new AccountCreateDto(
- name: $accountName,
- login: $login,
clientId: $clientId,
categoryId: $categoryId,
+ name: $accountName,
+ login: $login,
pass: $password,
url: $url,
notes: $notes
diff --git a/lib/SP/Domain/Import/Services/ImportBase.php b/lib/SP/Domain/Import/Services/ImportBase.php
index 0cb0ab70..f3960b3f 100644
--- a/lib/SP/Domain/Import/Services/ImportBase.php
+++ b/lib/SP/Domain/Import/Services/ImportBase.php
@@ -1,4 +1,5 @@
getCategoryId())) {
+ if (empty($accountCreateDto->categoryId)) {
throw ImportException::error(__u('Category Id not set. Unable to import account.'));
}
- if (empty($accountCreateDto->getClientId())) {
+ if (empty($accountCreateDto->clientId)) {
throw ImportException::error(__u('Client Id not set. Unable to import account.'));
}
- $dto = $accountCreateDto->setBatch(
- ['userId', 'userGroupId'],
- [$importParams->getDefaultUser(), $importParams->getDefaultGroup()]
+ $dto = $accountCreateDto->mutate(
+ ['userId' => $importParams->getDefaultUser(), 'userGroupId' => $importParams->getDefaultGroup()]
);
if ($useEncryption) {
@@ -130,12 +130,12 @@ abstract class ImportBase extends Service implements ImportService
if ($hasValidHash === true && !empty($importParams->getMasterPassword())) {
if ($this->version >= 210) {
$pass = $this->crypt->decrypt(
- $accountCreateDto->getPass(),
- $accountCreateDto->getKey(),
+ $accountCreateDto->pass,
+ $accountCreateDto->key,
$importParams->getMasterPassword()
);
- $dto = $dto->setBatch(['pass', 'key'], [$pass, '']);
+ $dto = $dto->mutate(['pass' => $pass, 'key' => '']);
} else {
throw ImportException::error(__u('The file was exported with an old sysPass version (<= 2.10).'));
}
diff --git a/lib/SP/Domain/Import/Services/KeepassImport.php b/lib/SP/Domain/Import/Services/KeepassImport.php
index 68f5819b..8d18fc26 100644
--- a/lib/SP/Domain/Import/Services/KeepassImport.php
+++ b/lib/SP/Domain/Import/Services/KeepassImport.php
@@ -1,4 +1,5 @@
$accounts
+ * @param int $clientId
+ * @param ImportParamsDto $importParamsDto
+ * @param string $groupName
+ * @return void
+ */
private function processAccounts(
SplObjectStorage $accounts,
int $clientId,
@@ -195,14 +203,14 @@ final class KeepassImport extends XmlImportBase implements ItemsImportService
): void {
foreach ($accounts as $account) {
try {
- $this->addAccount($account->set('clientId', $clientId), $importParamsDto);
+ $this->addAccount($account->mutate(['clientId' => $clientId]), $importParamsDto);
$this->eventDispatcher->notify(
'run.import.keepass.process.account',
new Event(
$this,
EventMessage::factory()
- ->addDetail(__u('Account imported'), $account->getName())
+ ->addDetail(__u('Account imported'), $account->name)
->addDetail(__u('Category'), $groupName)
)
);
diff --git a/lib/SP/Domain/Import/Services/SyspassImport.php b/lib/SP/Domain/Import/Services/SyspassImport.php
index 3ab66ac0..d261fcd2 100644
--- a/lib/SP/Domain/Import/Services/SyspassImport.php
+++ b/lib/SP/Domain/Import/Services/SyspassImport.php
@@ -365,7 +365,7 @@ final class SyspassImport extends XmlImportBase implements ItemsImportService
}
try {
- $dto = AccountCreateDto::fromAccount(new Account($data));
+ $dto = AccountCreateDto::fromModel(new Account($data));
$dtoWithTags = $dto->withTags($data['tags']);
$this->addAccount($dtoWithTags, $importParams, true);
diff --git a/lib/SP/Domain/ItemPreset/Services/ItemPreset.php b/lib/SP/Domain/ItemPreset/Services/ItemPreset.php
index e06cf2fc..13696846 100644
--- a/lib/SP/Domain/ItemPreset/Services/ItemPreset.php
+++ b/lib/SP/Domain/ItemPreset/Services/ItemPreset.php
@@ -1,4 +1,5 @@
context->getUserData();
+ $userDto = $this->context->getUserData();
return $this->getForUser(
$type,
- $userData->getId(),
- $userData->getUserGroupId(),
- $userData->getUserProfileId()
+ $userDto->id,
+ $userDto->userGroupId,
+ $userDto->userProfileId
);
}
diff --git a/lib/SP/Domain/Log/Providers/LoggerBase.php b/lib/SP/Domain/Log/Providers/LoggerBase.php
index 34e9e84c..011af110 100644
--- a/lib/SP/Domain/Log/Providers/LoggerBase.php
+++ b/lib/SP/Domain/Log/Providers/LoggerBase.php
@@ -81,7 +81,7 @@ abstract class LoggerBase extends Provider implements EventReceiver
$userLogin = 'N/A';
if ($this->context->isInitialized()) {
- $userLogin = $this->context->getUserData()->getLogin() ?? 'N/A';
+ $userLogin = $this->context->getUserData()->login ?? 'N/A';
}
$source = $event->getSource();
diff --git a/lib/SP/Domain/Notification/Services/MailEvent.php b/lib/SP/Domain/Notification/Services/MailEvent.php
index a4302f6a..a92d9605 100644
--- a/lib/SP/Domain/Notification/Services/MailEvent.php
+++ b/lib/SP/Domain/Notification/Services/MailEvent.php
@@ -123,8 +123,8 @@ final class MailEvent extends Service implements EventReceiver
$mailMessage->addDescription(
sprintf(
__('Performed by: %s (%s)'),
- $userData->getName() ?? 'sysPass',
- $userData->getLogin() ?? 'APP'
+ $userData->name ?? 'sysPass',
+ $userData->login ?? 'APP'
)
);
diff --git a/lib/SP/Domain/Notification/Services/Notification.php b/lib/SP/Domain/Notification/Services/Notification.php
index 5714f32d..1eadb3bf 100644
--- a/lib/SP/Domain/Notification/Services/Notification.php
+++ b/lib/SP/Domain/Notification/Services/Notification.php
@@ -1,4 +1,5 @@
context->getUserData();
- if ($userData->getIsAdminApp()) {
+ if ($userData->isAdminApp) {
return $this->notificationRepository
- ->getAllActiveForAdmin($userData->getId())
+ ->getAllActiveForAdmin($userData->id)
->getDataAsArray(NotificationModel::class);
}
return $this->notificationRepository
- ->getAllActiveForUserId($userData->getId())
+ ->getAllActiveForUserId($userData->id)
->getDataAsArray(NotificationModel::class);
}
@@ -259,13 +260,13 @@ final class Notification extends Service implements NotificationService
{
$userData = $this->context->getUserData();
- if ($userData->getIsAdminApp()) {
+ if ($userData->isAdminApp) {
return $this->notificationRepository
- ->searchForAdmin($itemSearchData, $userData->getId());
+ ->searchForAdmin($itemSearchData, $userData->id);
}
return $this->notificationRepository
- ->searchForUserId($itemSearchData, $userData->getId());
+ ->searchForUserId($itemSearchData, $userData->id);
}
/**
diff --git a/lib/SP/Domain/Security/Services/Eventlog.php b/lib/SP/Domain/Security/Services/Eventlog.php
index 2db731ee..2f2137b9 100644
--- a/lib/SP/Domain/Security/Services/Eventlog.php
+++ b/lib/SP/Domain/Security/Services/Eventlog.php
@@ -79,8 +79,8 @@ final class Eventlog extends Service implements EventlogService
$userData = $this->context->getUserData();
$data = [
- 'userId' => $userData->getId(),
- 'login' => $userData->getLogin() ?: '-',
+ 'userId' => $userData->id,
+ 'login' => $userData->login ?: '-',
'ipAddress' => $this->request->getClientAddress()
];
diff --git a/lib/SP/Domain/User/Dtos/UserDataDto.php b/lib/SP/Domain/User/Dtos/UserDataDto.php
deleted file mode 100644
index b018a49d..00000000
--- a/lib/SP/Domain/User/Dtos/UserDataDto.php
+++ /dev/null
@@ -1,158 +0,0 @@
-.
- */
-
-namespace SP\Domain\User\Dtos;
-
-use SP\Domain\Common\Dtos\Dto;
-use SP\Domain\Core\Exceptions\SPException;
-use SP\Domain\User\Models\User;
-use SP\Domain\User\Models\UserPreferences;
-
-/**
- * Class UserDataDto
- */
-final class UserDataDto extends Dto
-{
- protected ?UserPreferences $preferences;
-
- /**
- * @throws SPException
- */
- public function __construct(private readonly ?User $user = null)
- {
- $this->preferences = $this->user?->hydrate(UserPreferences::class);
- }
-
- public function getLogin(): ?string
- {
- return $this->user?->getLogin();
- }
-
- public function getSsoLogin(): ?string
- {
- return $this->user?->getSsoLogin();
- }
-
- public function getName(): ?string
- {
- return $this->user?->getName();
- }
-
- public function getEmail(): ?string
- {
- return $this->user?->getEmail();
- }
-
- public function getUserGroupId(): int
- {
- return (int)$this->user?->getUserGroupId();
- }
-
- public function getUserProfileId(): int
- {
- return (int)$this->user?->getUserProfileId();
- }
-
- public function getIsAdminApp(): bool
- {
- return (bool)$this->user?->isAdminApp();
- }
-
- public function getIsAdminAcc(): bool
- {
- return (bool)$this->user?->isAdminAcc();
- }
-
- public function getIsDisabled(): bool
- {
- return (bool)$this->user?->isDisabled();
- }
-
- public function getIsChangePass(): bool
- {
- return (bool)$this->user?->isChangePass();
- }
-
- public function getIsChangedPass(): bool
- {
- return (bool)$this->user?->isChangedPass();
- }
-
- public function getIsLdap(): bool
- {
- return (bool)$this->user?->isLdap();
- }
-
- public function getIsMigrate(): bool
- {
- return (bool)$this->user?->isMigrate();
- }
-
- public function getPreferences(): ?UserPreferences
- {
- return $this->preferences;
- }
-
- public function getPass(): ?string
- {
- return $this->user?->getPass();
- }
-
- public function getMPass(): ?string
- {
- return $this->user?->getMPass();
- }
-
- public function getMKey(): ?string
- {
- return $this->user?->getMKey();
- }
-
- public function getLastUpdateMPass(): int
- {
- return $this->user?->getLastUpdateMPass();
- }
-
- public function getHashSalt(): ?string
- {
- return $this->user?->getHashSalt();
- }
-
- public function getId(): ?int
- {
- return $this->user?->getId();
- }
-
- public function getUserGroupName(): ?string
- {
- return $this->user?->offsetGet('userGroup.name');
- }
-
- public function getLastUpdate(): int
- {
- return (int)strtotime($this->user?->getLastUpdate());
- }
-}
diff --git a/lib/SP/Domain/User/Dtos/UserDto.php b/lib/SP/Domain/User/Dtos/UserDto.php
new file mode 100644
index 00000000..913d7c5a
--- /dev/null
+++ b/lib/SP/Domain/User/Dtos/UserDto.php
@@ -0,0 +1,79 @@
+.
+ */
+
+namespace SP\Domain\User\Dtos;
+
+use SP\Domain\Common\Attributes\DtoTransformation;
+use SP\Domain\Common\Attributes\ModelBounded;
+use SP\Domain\Common\Dtos\Dto;
+use SP\Domain\Core\Exceptions\SPException;
+use SP\Domain\User\Models\User;
+use SP\Domain\User\Models\UserPreferences;
+
+/**
+ * Class UserDto
+ */
+#[ModelBounded(User::class)]
+final class UserDto extends Dto
+{
+ public function __construct(
+ public readonly ?int $id = null,
+ public readonly ?int $lastUpdateMPass = null,
+ public readonly ?int $userGroupId = null,
+ public readonly ?int $userProfileId = null,
+ public readonly ?int $loginCount = null,
+ public readonly ?string $pass = null,
+ public readonly ?string $hashSalt = null,
+ public readonly ?string $mPass = null,
+ public readonly ?string $mKey = null,
+ public readonly ?string $login = null,
+ public readonly ?string $ssoLogin = null,
+ public readonly ?string $name = null,
+ public readonly ?string $email = null,
+ public readonly ?string $notes = null,
+ public readonly ?string $lastLogin = null,
+ public readonly ?string $lastUpdate = null,
+ public readonly ?string $userGroupName = null,
+ public readonly ?bool $isAdminApp = null,
+ public readonly ?bool $isAdminAcc = null,
+ public readonly ?bool $isDisabled = null,
+ public readonly ?bool $isChangePass = null,
+ public readonly ?bool $isChangedPass = null,
+ public readonly ?bool $isLdap = null,
+ public readonly ?bool $isMigrate = null,
+ public readonly ?UserPreferences $preferences = null
+ ) {
+ }
+
+ /**
+ * @throws SPException
+ */
+ #[DtoTransformation('preferences')]
+ private static function transformPreferences(User $user): UserPreferences
+ {
+ return $user->hydrate(UserPreferences::class);
+ }
+}
diff --git a/lib/SP/Domain/User/Ports/UserMasterPassService.php b/lib/SP/Domain/User/Ports/UserMasterPassService.php
index c57da678..563abed2 100644
--- a/lib/SP/Domain/User/Ports/UserMasterPassService.php
+++ b/lib/SP/Domain/User/Ports/UserMasterPassService.php
@@ -1,4 +1,5 @@
load($userLoginDto, $userDataDto, $oldUserPass);
+ $response = $this->load($userLoginDto, $userDto, $oldUserPass);
if ($response->getUserMasterPassStatus() === UserMasterPassStatus::Ok) {
- return $this->updateOnLogin($response->getClearMasterPass(), $userLoginDto, $userDataDto->getId());
+ return $this->updateOnLogin($response->getClearMasterPass(), $userLoginDto, $userDto->id);
}
return new UserMasterPassDto(UserMasterPassStatus::Invalid);
@@ -83,31 +84,31 @@ final class UserMasterPass extends Service implements UserMasterPassService
*/
public function load(
UserLoginDto $userLoginDto,
- UserDataDto $userDataDto,
+ UserDto $userDataDto,
?string $userPass = null
): UserMasterPassDto {
try {
- if (empty($userDataDto->getMPass())
- || empty($userDataDto->getMKey())
+ if (empty($userDataDto->mPass)
+ || empty($userDataDto->mKey)
|| empty($systemMasterPassHash = $this->configService->getByParam(self::PARAM_MASTER_PWD))
) {
return new UserMasterPassDto(UserMasterPassStatus::NotSet);
}
- if ($userDataDto->getLastUpdateMPass() <
+ if ($userDataDto->lastUpdateMPass <
(int)$this->configService->getByParam(self::PARAM_LASTUPDATEMPASS, 0)
) {
return new UserMasterPassDto(UserMasterPassStatus::Changed);
}
- if ($userPass === null && $userDataDto->getIsChangedPass()) {
+ if ($userPass === null && $userDataDto->isChangedPass) {
return new UserMasterPassDto(UserMasterPassStatus::CheckOld);
}
$key = $this->makeKeyForUser($userLoginDto->getLoginUser(), $userPass ?? $userLoginDto->getLoginPass());
- $userMasterPass = $this->crypt->decrypt($userDataDto->getMPass(), $userDataDto->getMKey(), $key);
+ $userMasterPass = $this->crypt->decrypt($userDataDto->mPass, $userDataDto->mKey, $key);
// Comprobamos el hash de la clave del usuario con la guardada
if (Hash::checkHashKey($userMasterPass, $systemMasterPassHash)) {
@@ -116,8 +117,8 @@ final class UserMasterPass extends Service implements UserMasterPassService
return new UserMasterPassDto(
UserMasterPassStatus::Ok,
$userMasterPass,
- $userDataDto->getMPass(),
- $userDataDto->getMKey()
+ $userDataDto->mPass,
+ $userDataDto->mKey
);
}
} catch (CryptException $e) {
diff --git a/lib/SP/Infrastructure/Account/Repositories/AccountFile.php b/lib/SP/Infrastructure/Account/Repositories/AccountFile.php
index 647978cb..e2ab89a2 100644
--- a/lib/SP/Infrastructure/Account/Repositories/AccountFile.php
+++ b/lib/SP/Infrastructure/Account/Repositories/AccountFile.php
@@ -1,4 +1,5 @@
bindValues(['id' => $id])
->limit(1);
- return $this->db->runQuery(QueryData::build($query));
+ return $this->db->runQuery(QueryData::buildWithMapper($query, FileModel::class));
}
/**
- * Returns the item for given id
- *
- * @param int $id
- *
- * @return QueryResult
+ * @inheritDoc
* @throws ConstraintException
* @throws QueryException
*/
@@ -136,15 +125,11 @@ final class AccountFile extends BaseRepository implements AccountFileRepository
->orderBy(['name ASC'])
->limit(1);
- return $this->db->runQuery(QueryData::build($query));
+ return $this->db->runQuery(QueryData::buildWithMapper($query, FileModel::class));
}
/**
- * Deletes an item
- *
- * @param int $id
- *
- * @return bool
+ * @inheritDoc
* @throws ConstraintException
* @throws QueryException
*/
@@ -162,11 +147,7 @@ final class AccountFile extends BaseRepository implements AccountFileRepository
}
/**
- * Deletes all the items for given ids
- *
- * @param array $ids
- *
- * @return int
+ * @inheritDoc
* @throws ConstraintException
* @throws QueryException
*/
@@ -187,11 +168,7 @@ final class AccountFile extends BaseRepository implements AccountFileRepository
}
/**
- * Searches for items by a given filter
- *
- * @param ItemSearchDto $itemSearchData
- *
- * @return QueryResult
+ * @inheritDoc
* @throws ConstraintException
* @throws QueryException
*/
@@ -233,6 +210,6 @@ final class AccountFile extends BaseRepository implements AccountFileRepository
]);
}
- return $this->db->runQuery(QueryData::build($query), true);
+ return $this->db->runQuery(QueryData::buildWithMapper($query, FileModel::class), true);
}
}
diff --git a/lib/SP/Infrastructure/Account/Repositories/AccountSearch.php b/lib/SP/Infrastructure/Account/Repositories/AccountSearch.php
index b5ec3f6b..65fc3d2c 100644
--- a/lib/SP/Infrastructure/Account/Repositories/AccountSearch.php
+++ b/lib/SP/Infrastructure/Account/Repositories/AccountSearch.php
@@ -206,7 +206,7 @@ final class AccountSearch extends BaseRepository implements AccountSearchReposit
'AccountToFavorite',
'AccountToFavorite.accountId = Account.id AND AccountToFavorite.userId = :userId',
[
- 'userId' => $this->context->getUserData()->getId(),
+ 'userId' => $this->context->getUserData()->id,
]
);
}
diff --git a/lib/SP/Infrastructure/Database/QueryResult.php b/lib/SP/Infrastructure/Database/QueryResult.php
index 95be07c4..6ad4255b 100644
--- a/lib/SP/Infrastructure/Database/QueryResult.php
+++ b/lib/SP/Infrastructure/Database/QueryResult.php
@@ -35,7 +35,7 @@ use function SP\__u;
/**
* Class QueryResult
*
- * @template T of Model
+ * @template T of Model&object
*/
class QueryResult
{
@@ -72,7 +72,7 @@ class QueryResult
* @param class-string|null $dataType
* @return T
*/
- public function getData(?string $dataType = null): ?Model
+ public function getData(?string $dataType = null): ?object
{
if ($dataType) {
$this->checkDataType($dataType);
diff --git a/lib/SP/Infrastructure/User/Repositories/User.php b/lib/SP/Infrastructure/User/Repositories/User.php
index b484b262..a2dce15a 100644
--- a/lib/SP/Infrastructure/User/Repositories/User.php
+++ b/lib/SP/Infrastructure/User/Repositories/User.php
@@ -246,7 +246,7 @@ final class User extends BaseRepository implements UserRepository
->limit($itemSearchData->getLimitCount())
->offset($itemSearchData->getLimitStart());
- if (!$this->context->getUserData()->getIsAdminApp()) {
+ if (!$this->context->getUserData()->isAdminApp) {
$query->where(sprintf('%s.isAdminApp = 0', UserModel::TABLE));
}
diff --git a/lib/SP/Util/Util.php b/lib/SP/Util/Util.php
index 7a8b6bf6..65c420aa 100644
--- a/lib/SP/Util/Util.php
+++ b/lib/SP/Util/Util.php
@@ -129,21 +129,24 @@ final class Util
$methodParameters = [];
foreach ($reflectionMethod->getParameters() as $parameter) {
- if (!$parameter->isOptional() && !isset($parametersValue[$parameter->getPosition()])) {
+ if (isset($parametersValue[$parameter->getPosition()])) {
+ $type = self::getMethodParameterTypes($parameter)[0]->getName();
+
+ $methodParameters[$parameter->getPosition()] = match ($type) {
+ 'int' => (int)$parametersValue[$parameter->getPosition()],
+ 'bool' => (bool)$parametersValue[$parameter->getPosition()],
+ 'float' => (float)$parametersValue[$parameter->getPosition()],
+ 'array' => (array)$parametersValue[$parameter->getPosition()],
+ 'object' => (object)$parametersValue[$parameter->getPosition()],
+ default => (string)$parametersValue[$parameter->getPosition()]
+ };
+ } elseif ($parameter->allowsNull()) {
+ $methodParameters[$parameter->getPosition()] = null;
+ } elseif (!$parameter->isOptional()) {
throw new ValueError('Method parameter expects a value');
}
-
- $type = self::getMethodParameterTypes($parameter)[0]->getName();
-
- $methodParameters[$parameter->getPosition()] = match ($type) {
- 'int' => (int)$parametersValue[$parameter->getPosition()],
- 'bool' => (bool)$parametersValue[$parameter->getPosition()],
- 'float' => (float)$parametersValue[$parameter->getPosition()],
- 'array' => (array)$parametersValue[$parameter->getPosition()],
- 'object' => (object)$parametersValue[$parameter->getPosition()],
- default => (string)$parametersValue[$parameter->getPosition()]
- };
}
+
return $methodParameters;
}
diff --git a/tests/SP/Core/Acl/ActionsTest.php b/tests/SP/Core/Acl/ActionsTest.php
index 12162248..1ac82982 100644
--- a/tests/SP/Core/Acl/ActionsTest.php
+++ b/tests/SP/Core/Acl/ActionsTest.php
@@ -33,6 +33,7 @@ use PHPUnit\Framework\MockObject\MockObject;
use SP\Core\Acl\Actions;
use SP\Core\Context\ContextException;
use SP\Domain\Core\Acl\ActionNotFoundException;
+use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Core\Models\Action;
use SP\Domain\Storage\Ports\FileCacheService;
use SP\Domain\Storage\Ports\YamlFileStorageService;
@@ -302,6 +303,7 @@ class ActionsTest extends UnitaryTestCase
* @throws ContextException
* @throws Exception
* @throws FileException
+ * @throws SPException
*/
protected function setUp(): void
{
diff --git a/tests/SP/Core/LanguageTest.php b/tests/SP/Core/LanguageTest.php
index e2d206f0..c4c1263f 100644
--- a/tests/SP/Core/LanguageTest.php
+++ b/tests/SP/Core/LanguageTest.php
@@ -30,8 +30,9 @@ use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\MockObject;
use SP\Core\Language;
use SP\Domain\Config\Ports\ConfigDataInterface;
+use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Http\Ports\RequestService;
-use SP\Domain\User\Dtos\UserDataDto;
+use SP\Domain\User\Dtos\UserDto;
use SP\Domain\User\Models\User;
use SP\Domain\User\Models\UserPreferences;
use SP\Tests\UnitaryTestCase;
@@ -71,6 +72,9 @@ class LanguageTest extends UnitaryTestCase
$this->assertEquals($locale . '.utf8', getenv('LANGUAGE'));
}
+ /**
+ * @throws SPException
+ */
public function testSetLanguageForceWithUserLanguage()
{
$locale = 'es_ES';
@@ -84,7 +88,7 @@ class LanguageTest extends UnitaryTestCase
$user = (new User(['id' => self::$faker->randomNumber(2)]))
->dehydrate(new UserPreferences(['lang' => $locale]));
- $this->context->setUserData(new UserDataDto($user));
+ $this->context->setUserData(UserDto::fromModel($user));
$this->language->setLanguage(true);
@@ -101,7 +105,7 @@ class LanguageTest extends UnitaryTestCase
$this->context->setLocale($locale);
- $this->context->setUserData(new UserDataDto(new User()));
+ $this->context->setUserData(new UserDto());
$this->configData
->expects(self::once())
@@ -123,7 +127,7 @@ class LanguageTest extends UnitaryTestCase
$this->context->setLocale($locale);
- $this->context->setUserData(new UserDataDto(new User()));
+ $this->context->setUserData(new UserDto());
$this->configData
->expects(self::once())
diff --git a/tests/SP/Core/UI/ThemeTest.php b/tests/SP/Core/UI/ThemeTest.php
index 7cc2ebf5..5af8261b 100644
--- a/tests/SP/Core/UI/ThemeTest.php
+++ b/tests/SP/Core/UI/ThemeTest.php
@@ -1,4 +1,5 @@
method('isLoggedIn')
->willReturn(true);
- $userDataDto = new UserDataDto(UserDataGenerator::factory()->buildUserData());
+ $userDto = UserDto::fromModel(UserDataGenerator::factory()->buildUserData());
$context->expects(self::once())
->method('getUserData')
- ->willReturn($userDataDto);
+ ->willReturn($userDto);
$configData = $this->config->getConfigData();
$configData->setSiteTheme(self::$faker->colorName);
$current = Theme::getThemeName($this->config->getConfigData(), $context);
- $this->assertEquals($userDataDto->getPreferences()->getTheme(), $current);
+ $this->assertEquals($userDto->preferences->getTheme(), $current);
}
public function testGetViewsPath()
diff --git a/tests/SP/Domain/Account/Services/AccountAclTest.php b/tests/SP/Domain/Account/Services/AccountAclTest.php
index 939bb469..23732514 100644
--- a/tests/SP/Domain/Account/Services/AccountAclTest.php
+++ b/tests/SP/Domain/Account/Services/AccountAclTest.php
@@ -41,8 +41,9 @@ use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Acl\ActionsInterface;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
+use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Storage\Ports\FileCacheService;
-use SP\Domain\User\Dtos\UserDataDto;
+use SP\Domain\User\Dtos\UserDto;
use SP\Domain\User\Models\User;
use SP\Domain\User\Ports\UserToUserGroupService;
use SP\Infrastructure\File\FileException;
@@ -327,6 +328,7 @@ class AccountAclTest extends UnitaryTestCase
* @param bool|int $isAdminAcc
*
* @return AccountAclDto
+ * @throws SPException
*/
private function setUpAccountEnvironment(
int $accountId,
@@ -336,7 +338,7 @@ class AccountAclTest extends UnitaryTestCase
bool $isAdminAcc = false
): AccountAclDto {
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
new User(
[
'id' => $userId,
@@ -676,6 +678,7 @@ class AccountAclTest extends UnitaryTestCase
* @throws Exception
* @throws ConstraintException
* @throws QueryException
+ * @throws SPException
*/
public function testCacheIsUsedWithHit(): void
{
@@ -696,7 +699,7 @@ class AccountAclTest extends UnitaryTestCase
$lastUpdate = DateTime::createFromFormat('U', (string)($dto->getDateEdit() + 10))->format('Y-m-d H:i:s');
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(['lastUpdate' => $lastUpdate])
diff --git a/tests/SP/Domain/Account/Services/AccountFileTest.php b/tests/SP/Domain/Account/Services/AccountFileTest.php
index 20e1b0a8..47daadce 100644
--- a/tests/SP/Domain/Account/Services/AccountFileTest.php
+++ b/tests/SP/Domain/Account/Services/AccountFileTest.php
@@ -28,14 +28,15 @@ namespace SP\Tests\Domain\Account\Services;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\MockObject;
+use SP\Domain\Account\Dtos\FileDto;
use SP\Domain\Account\Models\File;
-use SP\Domain\Account\Models\FileExtData;
use SP\Domain\Account\Ports\AccountFileRepository;
use SP\Domain\Account\Services\AccountFile;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\InvalidImageException;
use SP\Domain\Core\Exceptions\QueryException;
+use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Image\Ports\ImageService;
use SP\Infrastructure\Common\Repositories\NoSuchItemException;
use SP\Infrastructure\Database\QueryResult;
@@ -100,9 +101,15 @@ class AccountFileTest extends UnitaryTestCase
$this->accountFile->create($fileData);
}
+ /**
+ * @throws NoSuchItemException
+ * @throws ConstraintException
+ * @throws SPException
+ * @throws QueryException
+ */
public function testGetById(): void
{
- $fileData = FileExtData::buildFromSimpleModel(FileDataGenerator::factory()->buildFileExtData());
+ $fileData = File::buildFromSimpleModel(FileDataGenerator::factory()->buildFileExtData());
$queryResult = new QueryResult([$fileData]);
@@ -114,7 +121,7 @@ class AccountFileTest extends UnitaryTestCase
$out = $this->accountFile->getById($fileData->getId());
- $this->assertEquals($fileData, $out);
+ $this->assertEquals(FileDto::fromModel($fileData), $out);
}
/**
@@ -200,7 +207,7 @@ class AccountFileTest extends UnitaryTestCase
public function testSearch(): void
{
$files = array_map(
- static fn() => FileExtData::buildFromSimpleModel(FileDataGenerator::factory()->buildFileExtData()),
+ static fn() => File::buildFromSimpleModel(FileDataGenerator::factory()->buildFileExtData()),
range(0, 4)
);
$itemSearchData = ItemSearchDataGenerator::factory()->buildItemSearchData();
@@ -219,6 +226,7 @@ class AccountFileTest extends UnitaryTestCase
/**
* @throws ConstraintException
* @throws QueryException
+ * @throws SPException
*/
public function testGetByAccountId(): void
{
diff --git a/tests/SP/Domain/Account/Services/AccountFilterUserTest.php b/tests/SP/Domain/Account/Services/AccountFilterUserTest.php
index d2f06877..3d896c4a 100644
--- a/tests/SP/Domain/Account/Services/AccountFilterUserTest.php
+++ b/tests/SP/Domain/Account/Services/AccountFilterUserTest.php
@@ -1,4 +1,5 @@
willReturnSelf();
$select->expects(self::exactly(1))->method('bindValues')
->with([
- 'userId' => $this->context->getUserData()->getId(),
- 'userGroupId' => $this->context->getUserData()->getUserGroupId(),
+ 'userId' => $this->context->getUserData()->id,
+ 'userGroupId' => $this->context->getUserData()->userGroupId,
]);
}
@@ -143,19 +145,21 @@ class AccountFilterUserTest extends UnitaryTestCase
$select->expects(self::exactly(3))->method('where')->willReturnSelf();
$select->expects(self::exactly(1))->method('bindValues')
->with([
- 'userId' => $this->context->getUserData()->getId(),
- 'userGroupId' => $this->context->getUserData()->getUserGroupId(),
+ 'userId' => $this->context->getUserData()->id,
+ 'userGroupId' => $this->context->getUserData()->userGroupId,
]);
$this->accountFilter->buildFilter(false, $select);
}
+ /**
+ * @throws Exception
+ * @throws SPException
+ */
public function testBuildFilterWithGlobalSearchForAdminAcc()
{
$this->context->setUserData(
- new UserDataDto(
- UserDataGenerator::factory()->buildUserData()->mutate(['isAdminAcc' => true])
- )
+ UserDto::fromModel(UserDataGenerator::factory()->buildUserData()->mutate(['isAdminAcc' => true]))
);
$this->setExpectationForGlobalSearch('Account');
@@ -183,17 +187,19 @@ class AccountFilterUserTest extends UnitaryTestCase
->willReturnSelf();
$select->expects(self::exactly(1))->method('bindValues')
->with([
- 'userId' => $this->context->getUserData()->getId(),
- 'userGroupId' => $this->context->getUserData()->getUserGroupId(),
+ 'userId' => $this->context->getUserData()->id,
+ 'userGroupId' => $this->context->getUserData()->userGroupId,
]);
}
+ /**
+ * @throws Exception
+ * @throws SPException
+ */
public function testBuildFilterWithGlobalSearchForAdminApp()
{
$this->context->setUserData(
- new UserDataDto(
- UserDataGenerator::factory()->buildUserData()->mutate(['isAdminApp' => true])
- )
+ UserDto::fromModel(UserDataGenerator::factory()->buildUserData()->mutate(['isAdminApp' => true]))
);
$this->setExpectationForGlobalSearch('Account');
@@ -218,12 +224,14 @@ class AccountFilterUserTest extends UnitaryTestCase
$this->accountFilter->buildFilterHistory();
}
+ /**
+ * @throws Exception
+ * @throws SPException
+ */
public function testBuildFilterHistoryWithGlobalSearchForAdminAcc()
{
$this->context->setUserData(
- new UserDataDto(
- UserDataGenerator::factory()->buildUserData()->mutate(['isAdminAcc' => true])
- )
+ UserDto::fromModel(UserDataGenerator::factory()->buildUserData()->mutate(['isAdminAcc' => true]))
);
$this->setExpectationForGlobalSearch('AccountHistory');
@@ -231,12 +239,14 @@ class AccountFilterUserTest extends UnitaryTestCase
$this->accountFilter->buildFilterHistory();
}
+ /**
+ * @throws Exception
+ * @throws SPException
+ */
public function testBuildFilterHistoryWithGlobalSearchForAdminApp()
{
$this->context->setUserData(
- new UserDataDto(
- UserDataGenerator::factory()->buildUserData()->mutate(['isAdminApp' => true])
- )
+ UserDto::fromModel(UserDataGenerator::factory()->buildUserData()->mutate(['isAdminApp' => true]))
);
$this->setExpectationForGlobalSearch('AccountHistory');
@@ -254,6 +264,9 @@ class AccountFilterUserTest extends UnitaryTestCase
$this->accountFilter->buildFilterHistory(true);
}
+ /**
+ * @throws Exception
+ */
public function testBuildFilterHistoryWithQueryProvided()
{
$this->queryFactory->expects(self::never())->method('newSelect');
@@ -263,8 +276,8 @@ class AccountFilterUserTest extends UnitaryTestCase
$select->expects(self::exactly(3))->method('where')->willReturnSelf();
$select->expects(self::exactly(1))->method('bindValues')
->with([
- 'userId' => $this->context->getUserData()->getId(),
- 'userGroupId' => $this->context->getUserData()->getUserGroupId(),
+ 'userId' => $this->context->getUserData()->id,
+ 'userGroupId' => $this->context->getUserData()->userGroupId,
]);
$this->accountFilter->buildFilterHistory(false, $select);
diff --git a/tests/SP/Domain/Account/Services/AccountHistoryTest.php b/tests/SP/Domain/Account/Services/AccountHistoryTest.php
index 26f345ab..75600035 100644
--- a/tests/SP/Domain/Account/Services/AccountHistoryTest.php
+++ b/tests/SP/Domain/Account/Services/AccountHistoryTest.php
@@ -1,4 +1,5 @@
accountHistoryRepository->expects(self::once())->method('getById')->with($id)->willReturn($queryResult);
- $this->assertEquals($accountHistoryData, $this->accountHistory->getById($id));
+ $this->assertEquals(
+ $accountHistoryData->toArray(),
+ $this->accountHistory->getById($id)->toArray()
+ );
}
/**
diff --git a/tests/SP/Domain/Account/Services/AccountItemsTest.php b/tests/SP/Domain/Account/Services/AccountItemsTest.php
index 0d07c664..0fd72aed 100644
--- a/tests/SP/Domain/Account/Services/AccountItemsTest.php
+++ b/tests/SP/Domain/Account/Services/AccountItemsTest.php
@@ -75,8 +75,8 @@ class AccountItemsTest extends UnitaryTestCase
->method('addByType')
->with(
...
- self::withConsecutive([100, $accountUpdateDto->getUserGroupsView(), false],
- [100, $accountUpdateDto->getUserGroupsEdit(), true])
+ self::withConsecutive([100, $accountUpdateDto->userGroupsView, false],
+ [100, $accountUpdateDto->userGroupsEdit, true])
);
$this->accountToUserRepository
@@ -94,8 +94,8 @@ class AccountItemsTest extends UnitaryTestCase
->method('addByType')
->with(
...
- self::withConsecutive([100, $accountUpdateDto->getUsersView(), false],
- [100, $accountUpdateDto->getUsersEdit(), true])
+ self::withConsecutive([100, $accountUpdateDto->usersView, false],
+ [100, $accountUpdateDto->usersEdit, true])
);
$this->accountToTagRepository
@@ -111,29 +111,29 @@ class AccountItemsTest extends UnitaryTestCase
$this->accountToTagRepository
->expects($this->once())
->method('add')
- ->with(100, $accountUpdateDto->getTags());
+ ->with(100, $accountUpdateDto->tags);
$this->accountItems->updateItems(true, 100, $accountUpdateDto);
}
/**
* @throws ConstraintException
- * @throws ServiceException
* @throws QueryException
+ * @throws SPException
+ * @throws ServiceException
*/
public function testUpdateItemsWithNoItems()
{
$accountUpdateDto = AccountDataGenerator::factory()
->buildAccountUpdateDto()
- ->setBatch(
+ ->mutate(
[
- 'usersView',
- 'usersEdit',
- 'userGroupsView',
- 'userGroupsEdit',
- 'tags'
- ],
- [null, null, null, null, null]
+ 'usersView' => null,
+ 'usersEdit' => null,
+ 'userGroupsView' => null,
+ 'userGroupsEdit' => null,
+ 'tags' => null
+ ]
);
$this->accountToUserGroupRepository
@@ -224,7 +224,7 @@ class AccountItemsTest extends UnitaryTestCase
$this->accountToTagRepository
->expects($this->once())
->method('add')
- ->with(100, $accountUpdateDto->getTags());
+ ->with(100, $accountUpdateDto->tags);
$this->accountItems->updateItems(false, 100, $accountUpdateDto);
}
@@ -238,8 +238,10 @@ class AccountItemsTest extends UnitaryTestCase
->method('addByType')
->with(
...
- self::withConsecutive([100, $accountCreateDto->getUserGroupsView(), false],
- [100, $accountCreateDto->getUserGroupsEdit(), true])
+ self::withConsecutive(
+ [100, $accountCreateDto->userGroupsView, false],
+ [100, $accountCreateDto->userGroupsEdit, true]
+ )
);
$this->accountToUserRepository
@@ -247,14 +249,14 @@ class AccountItemsTest extends UnitaryTestCase
->method('addByType')
->with(
...
- self::withConsecutive([100, $accountCreateDto->getUsersView(), false],
- [100, $accountCreateDto->getUsersEdit(), true])
+ self::withConsecutive([100, $accountCreateDto->usersView, false],
+ [100, $accountCreateDto->usersEdit, true])
);
$this->accountToTagRepository
->expects($this->once())
->method('add')
- ->with(100, $accountCreateDto->getTags());
+ ->with(100, $accountCreateDto->tags);
$this->accountItems->addItems(true, 100, $accountCreateDto);
}
@@ -274,7 +276,7 @@ class AccountItemsTest extends UnitaryTestCase
$this->accountToTagRepository
->expects($this->once())
->method('add')
- ->with(100, $accountCreateDto->getTags());
+ ->with(100, $accountCreateDto->tags);
$this->accountItems->addItems(false, 100, $accountCreateDto);
}
diff --git a/tests/SP/Domain/Account/Services/AccountPresetTest.php b/tests/SP/Domain/Account/Services/AccountPresetTest.php
index 8e647ff4..d87c56be 100644
--- a/tests/SP/Domain/Account/Services/AccountPresetTest.php
+++ b/tests/SP/Domain/Account/Services/AccountPresetTest.php
@@ -162,11 +162,11 @@ class AccountPresetTest extends UnitaryTestCase
->method('validate');
$accountDto = AccountDataGenerator::factory()->buildAccountCreateDto();
- $accountDto = $accountDto->set('passDateChange', 0);
+ $accountDto = $accountDto->mutate(['passDateChange' => 0]);
$out = $this->accountPreset->checkPasswordPreset($accountDto);
- $this->assertGreaterThan(0, $out->getPassDateChange());
+ $this->assertGreaterThan(0, $out->passDateChange);
}
/**
diff --git a/tests/SP/Domain/Account/Services/AccountSearchTest.php b/tests/SP/Domain/Account/Services/AccountSearchTest.php
index 24dc5f39..e35246ef 100644
--- a/tests/SP/Domain/Account/Services/AccountSearchTest.php
+++ b/tests/SP/Domain/Account/Services/AccountSearchTest.php
@@ -200,7 +200,7 @@ class AccountSearchTest extends UnitaryTestCase
$this->accountSearchRepository
->expects(self::once())
->method('withFilterForIsPrivate')
- ->with($this->context->getUserData()->getId(), $this->context->getUserData()->getUserGroupId());
+ ->with($this->context->getUserData()->id, $this->context->getUserData()->userGroupId);
break;
case AccountSearchConstants::FILTER_NOT_PRIVATE:
$this->accountSearchRepository
diff --git a/tests/SP/Domain/Account/Services/AccountTest.php b/tests/SP/Domain/Account/Services/AccountTest.php
index c1fc9a03..75508fec 100644
--- a/tests/SP/Domain/Account/Services/AccountTest.php
+++ b/tests/SP/Domain/Account/Services/AccountTest.php
@@ -54,7 +54,7 @@ use SP\Domain\ItemPreset\Models\AccountPrivate;
use SP\Domain\ItemPreset\Models\ItemPreset;
use SP\Domain\ItemPreset\Ports\ItemPresetInterface;
use SP\Domain\ItemPreset\Ports\ItemPresetService;
-use SP\Domain\User\Dtos\UserDataDto;
+use SP\Domain\User\Dtos\UserDto;
use SP\Domain\User\Models\ProfileData;
use SP\Infrastructure\Common\Repositories\NoSuchItemException;
use SP\Infrastructure\Database\QueryResult;
@@ -85,6 +85,7 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testUpdate()
{
@@ -93,7 +94,7 @@ class AccountTest extends UnitaryTestCase
$accountUpdateDto = $accountDataGenerator->buildAccountUpdateDto();
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()->buildUserData()->mutate(['isAdminApp' => true])
)
);
@@ -118,6 +119,7 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testUpdateUserCannotChangePermissionsWithoutPermission()
{
@@ -126,7 +128,7 @@ class AccountTest extends UnitaryTestCase
$accountUpdateDto = $accountDataGenerator->buildAccountUpdateDto();
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(['isAdminApp' => false, 'isAdminAcc' => false])
@@ -155,6 +157,7 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testUpdateUserCanChangePermissionsWithAdminAcc()
{
@@ -163,7 +166,7 @@ class AccountTest extends UnitaryTestCase
$accountUpdateDto = $accountDataGenerator->buildAccountUpdateDto();
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(['isAdminApp' => false, 'isAdminAcc' => true])
@@ -192,6 +195,7 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testUpdateUserCanChangePermissionsWithProfilePermission()
{
@@ -200,7 +204,7 @@ class AccountTest extends UnitaryTestCase
$accountUpdateDto = $accountDataGenerator->buildAccountUpdateDto();
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(['isAdminApp' => false, 'isAdminAcc' => false])
@@ -229,6 +233,7 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testUpdateWithPresetPrivateForUser()
{
@@ -247,13 +252,13 @@ class AccountTest extends UnitaryTestCase
]);
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
[
- 'id' => $accountUpdateDto->getUserId(),
- 'userGroupId' => $accountUpdateDto->getUserGroupId(),
+ 'id' => $accountUpdateDto->userId,
+ 'userGroupId' => $accountUpdateDto->userGroupId,
'isAdminApp' => true,
'isAdminAcc' => false
]
@@ -269,7 +274,7 @@ class AccountTest extends UnitaryTestCase
->willReturn($itemPreset);
$account = new AccountModel(
[
- 'userId' => $accountUpdateDto->getUserId(),
+ 'userId' => $accountUpdateDto->userId,
'userGroupId' => self::$faker->randomNumber(),
]
);
@@ -306,6 +311,7 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testUpdateWithPresetPrivateForGroup()
{
@@ -324,13 +330,13 @@ class AccountTest extends UnitaryTestCase
]);
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
[
- 'id' => $accountUpdateDto->getUserId(),
- 'userGroupId' => $accountUpdateDto->getUserGroupId(),
+ 'id' => $accountUpdateDto->userId,
+ 'userGroupId' => $accountUpdateDto->userGroupId,
'isAdminApp' => true,
'isAdminAcc' => false
]
@@ -347,7 +353,7 @@ class AccountTest extends UnitaryTestCase
$account = new AccountModel(
[
'userId' => self::$faker->randomNumber(),
- 'userGroupId' => $accountUpdateDto->getUserGroupId(),
+ 'userGroupId' => $accountUpdateDto->userGroupId,
]
);
@@ -557,6 +563,7 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testUpdateBulk()
{
@@ -566,7 +573,7 @@ class AccountTest extends UnitaryTestCase
$accountUpdateBulkDto = new AccountUpdateBulkDto($accountsId, $accounts);
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
@@ -601,6 +608,7 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testUpdateBulkCannotChangePermissionsWithoutAdminApp()
{
@@ -610,7 +618,7 @@ class AccountTest extends UnitaryTestCase
$accountUpdateBulkDto = new AccountUpdateBulkDto($accountsId, $accounts);
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
@@ -641,6 +649,7 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testUpdateBulkCanChangePermissionsWithAdminAcc()
{
@@ -650,7 +659,7 @@ class AccountTest extends UnitaryTestCase
$accountUpdateBulkDto = new AccountUpdateBulkDto($accountsId, $accounts);
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
@@ -686,6 +695,7 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testUpdateBulkCanChangePermissionsWithProfilePermission()
{
@@ -695,7 +705,7 @@ class AccountTest extends UnitaryTestCase
$accountUpdateBulkDto = new AccountUpdateBulkDto($accountsId, $accounts);
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
@@ -720,10 +730,7 @@ class AccountTest extends UnitaryTestCase
$this->accountItemsService->expects(self::exactly(count($accountsId)))->method('updateItems')
->with(
...self::withConsecutive(
- ...array_map(
- fn($v) => [true, $v, $accounts[$v]],
- $accountsId
- )
+ ...array_map(fn($v) => [true, $v, $accounts[$v]], $accountsId)
)
);
@@ -838,9 +845,6 @@ class AccountTest extends UnitaryTestCase
$this->assertFalse($this->account->incrementViewCounter($id));
}
- /**
- * @throws SPException
- */
public function testGetAllBasic()
{
$this->accountRepository->expects(self::once())->method('getAll');
@@ -900,10 +904,10 @@ class AccountTest extends UnitaryTestCase
->with(
AccountModel::restoreRemoved(
$accountHistoryDto,
- $this->context->getUserData()->getId()
+ $this->context->getUserData()->id
)
)
- ->willReturn(new QueryResult(null, 1));
+ ->willReturn(new QueryResult(null, 1));
$this->account->restoreRemoved($accountHistoryDto);
}
@@ -923,7 +927,7 @@ class AccountTest extends UnitaryTestCase
->with(
AccountModel::restoreRemoved(
$accountHistoryDto,
- $this->context->getUserData()->getId()
+ $this->context->getUserData()->id
)
)
->willReturn($queryResult);
@@ -936,12 +940,13 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testEditPassword()
{
$id = self::$faker->randomNumber();
$account = AccountDataGenerator::factory()->buildAccount();
- $accountUpdateDto = AccountUpdateDto::fromAccount($account);
+ $accountUpdateDto = AccountUpdateDto::fromModel($account);
$password = self::$faker->password;
@@ -957,9 +962,9 @@ class AccountTest extends UnitaryTestCase
->with($accountHistoryCreateDto);
$this->accountCryptService->expects(self::once())->method('getPasswordEncrypted')
- ->with($accountUpdateDto->getPass())
+ ->with($accountUpdateDto->pass)
->willReturn(
- new EncryptedPassword($accountUpdateDto->getPass(), $accountUpdateDto->getKey())
+ new EncryptedPassword($accountUpdateDto->pass, $accountUpdateDto->key)
);
$this->accountRepository->expects(self::once())->method('editPassword')
@@ -975,7 +980,8 @@ class AccountTest extends UnitaryTestCase
{
$password = self::$faker->password;
- $this->configService->expects(self::once())->method('getByParam')
+ $this->configService->expects(self::once())
+ ->method('getByParam')
->with('masterPwd')->willReturn($password);
$accountDataGenerator = AccountDataGenerator::factory();
@@ -984,7 +990,7 @@ class AccountTest extends UnitaryTestCase
$accountHistoryDto = $accountDataGenerator->buildAccountHistoryDto();
$this->accountRepository->expects(self::once())->method('getById')
- ->with($accountHistoryDto->getAccountId())->willReturn(new QueryResult([$account]));
+ ->with($accountHistoryDto->accountId)->willReturn(new QueryResult([$account]));
$accountHistoryCreateDto = new AccountHistoryCreateDto($account, true, false, $password);
@@ -993,13 +999,13 @@ class AccountTest extends UnitaryTestCase
$this->accountRepository->expects(self::once())->method('restoreModified')
->with(
- $accountHistoryDto->getAccountId(),
+ $accountHistoryDto->accountId,
AccountModel::restoreModified(
$accountHistoryDto,
- $this->context->getUserData()->getId()
+ $this->context->getUserData()->id
)
)
- ->willReturn(new QueryResult(null, 1));
+ ->willReturn(new QueryResult(null, 1));
$this->account->restoreModified($accountHistoryDto);
}
@@ -1020,7 +1026,7 @@ class AccountTest extends UnitaryTestCase
$accountHistoryDto = $accountDataGenerator->buildAccountHistoryDto();
$this->accountRepository->expects(self::once())->method('getById')
- ->with($accountHistoryDto->getAccountId())->willReturn(new QueryResult([$account]));
+ ->with($accountHistoryDto->accountId)->willReturn(new QueryResult([$account]));
$accountHistoryCreateDto = new AccountHistoryCreateDto($account, true, false, $password);
@@ -1030,13 +1036,13 @@ class AccountTest extends UnitaryTestCase
$this->accountRepository->expects(self::once())->method('restoreModified')
->with(
- $accountHistoryDto->getAccountId(),
+ $accountHistoryDto->accountId,
AccountModel::restoreModified(
$accountHistoryDto,
- $this->context->getUserData()->getId()
+ $this->context->getUserData()->id
)
)
- ->willReturn(new QueryResult(null, 0));
+ ->willReturn(new QueryResult(null, 0));
$this->expectException(ServiceException::class);
$this->expectExceptionMessage('Error on restoring the account');
@@ -1075,6 +1081,7 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testCreate()
{
@@ -1083,7 +1090,7 @@ class AccountTest extends UnitaryTestCase
$accountCreateDto = $accountDataGenerator->buildAccountCreateDto();
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
@@ -1098,7 +1105,7 @@ class AccountTest extends UnitaryTestCase
$encryptedPassword = new EncryptedPassword(self::$faker->password, self::$faker->password);
$this->accountCryptService->expects(self::once())->method('getPasswordEncrypted')
- ->with($accountCreateDto->getPass())
+ ->with($accountCreateDto->pass)
->willReturn($encryptedPassword);
$this->itemPresetService->expects(self::once())->method('getForCurrentUser')
@@ -1119,6 +1126,7 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testCreateCannotChangePermissions()
{
@@ -1126,17 +1134,17 @@ class AccountTest extends UnitaryTestCase
$accountDataGenerator = AccountDataGenerator::factory();
$userData = $this->context->getUserData();
$accountCreateDto = $accountDataGenerator->buildAccountCreateDto()
- ->withUserId($userData->getId())
- ->withUserGroupId($userData->getUserGroupId());
+ ->withUserId($userData->id)
+ ->withUserGroupId($userData->userGroupId);
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
[
- 'id' => $userData->getId(),
- 'userGroupId' => $userData->getUserGroupId(),
+ 'id' => $userData->id,
+ 'userGroupId' => $userData->userGroupId,
'isAdminApp' => false,
'isAdminAcc' => false
]
@@ -1147,7 +1155,7 @@ class AccountTest extends UnitaryTestCase
$encryptedPassword = new EncryptedPassword(self::$faker->password, self::$faker->password);
$this->accountCryptService->expects(self::once())->method('getPasswordEncrypted')
- ->with($accountCreateDto->getPass())
+ ->with($accountCreateDto->pass)
->willReturn($encryptedPassword);
$this->itemPresetService->expects(self::once())->method('getForCurrentUser')
@@ -1168,6 +1176,7 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testCreateWithPrivateForUser()
{
@@ -1187,12 +1196,12 @@ class AccountTest extends UnitaryTestCase
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
[
- 'id' => $accountCreateDto->getUserId(),
+ 'id' => $accountCreateDto->userId,
'isAdminApp' => true,
'isAdminAcc' => false
]
@@ -1204,7 +1213,7 @@ class AccountTest extends UnitaryTestCase
$encryptedPassword = new EncryptedPassword(self::$faker->password, self::$faker->password);
$this->accountCryptService->expects(self::once())->method('getPasswordEncrypted')
- ->with($accountCreateDto->getPass())
+ ->with($accountCreateDto->pass)
->willReturn($encryptedPassword);
$this->itemPresetService->expects(self::once())->method('getForCurrentUser')
@@ -1235,6 +1244,7 @@ class AccountTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testCreateWithPrivateForGroup()
{
@@ -1253,12 +1263,12 @@ class AccountTest extends UnitaryTestCase
]);
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
[
- 'userGroupId' => $accountCreateDto->getUserGroupId(),
+ 'userGroupId' => $accountCreateDto->userGroupId,
'isAdminApp' => true,
'isAdminAcc' => false
]
@@ -1269,7 +1279,7 @@ class AccountTest extends UnitaryTestCase
$encryptedPassword = new EncryptedPassword(self::$faker->password, self::$faker->password);
$this->accountCryptService->expects(self::once())->method('getPasswordEncrypted')
- ->with($accountCreateDto->getPass())
+ ->with($accountCreateDto->pass)
->willReturn($encryptedPassword);
$this->itemPresetService->expects(self::once())->method('getForCurrentUser')
@@ -1437,8 +1447,6 @@ class AccountTest extends UnitaryTestCase
{
$id = self::$faker->randomNumber();
- $queryResult = new QueryResult();
-
$this->accountRepository->expects(self::once())->method('incrementDecryptCounter')
->with($id)
->willReturn(new QueryResult(null, 0));
diff --git a/tests/SP/Domain/Auth/Services/AuthTokenTest.php b/tests/SP/Domain/Auth/Services/AuthTokenTest.php
index 628454db..41cf7372 100644
--- a/tests/SP/Domain/Auth/Services/AuthTokenTest.php
+++ b/tests/SP/Domain/Auth/Services/AuthTokenTest.php
@@ -1,4 +1,5 @@
getVault() === $authToken->getVault()
&& $current->getToken() === $authToken->getToken()
&& $current->getHash() === null
- && $current->getCreatedBy() === $this->context->getUserData()->getId();
+ && $current->getCreatedBy() === $this->context->getUserData()->id;
})
)
->willReturn(new QueryResult(null, 0, 100));
@@ -196,7 +197,7 @@ class AuthTokenTest extends UnitaryTestCase
&& $current->getVault() === $authToken->getVault()
&& $current->getToken() !== $authToken->getToken()
&& $current->getHash() === null
- && $current->getCreatedBy() === $this->context->getUserData()->getId();
+ && $current->getCreatedBy() === $this->context->getUserData()->id;
})
)
->willReturn(new QueryResult(null, 0, 100));
@@ -240,7 +241,7 @@ class AuthTokenTest extends UnitaryTestCase
&& $current->getToken() === $authToken->getToken()
&& $current->getVault() !== $authToken->getVault()
&& $current->getHash() !== $authToken->getHash()
- && $current->getCreatedBy() === $this->context->getUserData()->getId();
+ && $current->getCreatedBy() === $this->context->getUserData()->id;
})
)
->willReturn(new QueryResult(null, 0, 100));
@@ -301,9 +302,6 @@ class AuthTokenTest extends UnitaryTestCase
/**
* @throws NoSuchItemException
- * @throws ConstraintException
- * @throws QueryException
- * @throws SPException
*/
public function testGetTokenByTokenWithNoFound()
{
@@ -352,7 +350,7 @@ class AuthTokenTest extends UnitaryTestCase
&& $current->getVault() === $authToken->getVault()
&& $current->getToken() === $authToken->getToken()
&& $current->getHash() === null
- && $current->getCreatedBy() === $this->context->getUserData()->getId();
+ && $current->getCreatedBy() === $this->context->getUserData()->id;
})
)
->willReturn(true);
@@ -389,7 +387,7 @@ class AuthTokenTest extends UnitaryTestCase
&& $current->getVault() === $authToken->getVault()
&& $current->getToken() !== $authToken->getToken()
&& $current->getHash() === null
- && $current->getCreatedBy() === $this->context->getUserData()->getId();
+ && $current->getCreatedBy() === $this->context->getUserData()->id;
})
)
->willReturn(true);
@@ -431,7 +429,7 @@ class AuthTokenTest extends UnitaryTestCase
&& $current->getToken() === $authToken->getToken()
&& $current->getVault() !== $authToken->getVault()
&& $current->getHash() !== $authToken->getHash()
- && $current->getCreatedBy() === $this->context->getUserData()->getId();
+ && $current->getCreatedBy() === $this->context->getUserData()->id;
})
)
->willReturn(true);
@@ -453,11 +451,6 @@ class AuthTokenTest extends UnitaryTestCase
$this->authToken->update($authToken);
}
- /**
- * @throws ConstraintException
- * @throws SPException
- * @throws QueryException
- */
public function testGetById()
{
$id = self::$faker->randomNumber();
@@ -475,11 +468,6 @@ class AuthTokenTest extends UnitaryTestCase
$this->assertEquals($authToken, $out);
}
- /**
- * @throws ConstraintException
- * @throws SPException
- * @throws QueryException
- */
public function testGetAll()
{
$authToken = AuthTokenGenerator::factory()->buildAuthToken();
@@ -599,7 +587,7 @@ class AuthTokenTest extends UnitaryTestCase
&& $current->getVault() === $authToken->getVault()
&& $current->getToken() !== $authToken->getToken()
&& $current->getHash() === null
- && $current->getCreatedBy() === $this->context->getUserData()->getId();
+ && $current->getCreatedBy() === $this->context->getUserData()->id;
})
)
->willReturn(true);
diff --git a/tests/SP/Domain/Auth/Services/LoginMasterPassTest.php b/tests/SP/Domain/Auth/Services/LoginMasterPassTest.php
index 23885a44..81116dc0 100644
--- a/tests/SP/Domain/Auth/Services/LoginMasterPassTest.php
+++ b/tests/SP/Domain/Auth/Services/LoginMasterPassTest.php
@@ -1,4 +1,5 @@
buildUserData());
+ $userDto = UserDto::fromModel(UserDataGenerator::factory()->buildUserData());
$userLoginDto = new UserLoginDto('a_user', 'a_password');
$this->request
@@ -89,20 +92,21 @@ class LoginMasterPassTest extends UnitaryTestCase
$this->userMasterPassService
->expects($this->once())
->method('load')
- ->with($userLoginDto, $userDataDto)
+ ->with($userLoginDto, $userDto)
->willReturn($userMasterPassDto);
- $this->loginMasterPass->loadMasterPass($userLoginDto, $userDataDto);
+ $this->loginMasterPass->loadMasterPass($userLoginDto, $userDto);
}
/**
* @throws AuthException
* @throws ServiceException
+ * @throws SPException
*/
#[DataProvider('wrongStatusDataProvider')]
public function testLoadMasterPassWithWrongPassword(UserMasterPassStatus $userMasterPassStatus)
{
- $userDataDto = new UserDataDto(UserDataGenerator::factory()->buildUserData());
+ $userDto = UserDto::fromModel(UserDataGenerator::factory()->buildUserData());
$userLoginDto = new UserLoginDto('a_user', 'a_password');
$this->request
@@ -116,7 +120,7 @@ class LoginMasterPassTest extends UnitaryTestCase
$this->userMasterPassService
->expects($this->once())
->method('load')
- ->with($userLoginDto, $userDataDto)
+ ->with($userLoginDto, $userDto)
->willReturn($userMasterPassDto);
$this->trackService
@@ -126,16 +130,17 @@ class LoginMasterPassTest extends UnitaryTestCase
$this->expectException(AuthException::class);
$this->expectExceptionMessage('The Master Password either is not saved or is wrong');
- $this->loginMasterPass->loadMasterPass($userLoginDto, $userDataDto);
+ $this->loginMasterPass->loadMasterPass($userLoginDto, $userDto);
}
/**
* @throws AuthException
* @throws ServiceException
+ * @throws SPException
*/
public function testLoadMasterPassWithPreviousNeeded()
{
- $userDataDto = new UserDataDto(UserDataGenerator::factory()->buildUserData());
+ $userDto = UserDto::fromModel(UserDataGenerator::factory()->buildUserData());
$userLoginDto = new UserLoginDto('a_user', 'a_password');
$this->request
@@ -149,22 +154,23 @@ class LoginMasterPassTest extends UnitaryTestCase
$this->userMasterPassService
->expects($this->once())
->method('load')
- ->with($userLoginDto, $userDataDto)
+ ->with($userLoginDto, $userDto)
->willReturn($userMasterPassDto);
$this->expectException(AuthException::class);
$this->expectExceptionMessage('Your previous password is needed');
- $this->loginMasterPass->loadMasterPass($userLoginDto, $userDataDto);
+ $this->loginMasterPass->loadMasterPass($userLoginDto, $userDto);
}
/**
* @throws AuthException
* @throws ServiceException
+ * @throws SPException
*/
public function testLoadMasterPassWithTemporary()
{
- $userDataDto = new UserDataDto(UserDataGenerator::factory()->buildUserData());
+ $userDto = UserDto::fromModel(UserDataGenerator::factory()->buildUserData());
$userLoginDto = new UserLoginDto('a_user', 'a_password');
$this->request
@@ -190,23 +196,24 @@ class LoginMasterPassTest extends UnitaryTestCase
$this->userMasterPassService
->expects($this->once())
->method('updateOnLogin')
- ->with('a_master_pass', $userLoginDto, $userDataDto->getId())
+ ->with('a_master_pass', $userLoginDto, $userDto->id)
->willReturn($userMasterPassDto);
$this->trackService
->expects($this->never())
->method('add');
- $this->loginMasterPass->loadMasterPass($userLoginDto, $userDataDto);
+ $this->loginMasterPass->loadMasterPass($userLoginDto, $userDto);
}
/**
* @throws AuthException
* @throws ServiceException
+ * @throws SPException
*/
public function testLoadMasterPassWithTemporaryAndWrongKey()
{
- $userDataDto = new UserDataDto(UserDataGenerator::factory()->buildUserData());
+ $userDto = UserDto::fromModel(UserDataGenerator::factory()->buildUserData());
$userLoginDto = new UserLoginDto('a_user', 'a_password');
$this->request
@@ -228,17 +235,18 @@ class LoginMasterPassTest extends UnitaryTestCase
$this->expectException(AuthException::class);
$this->expectExceptionMessage('Wrong master password');
- $this->loginMasterPass->loadMasterPass($userLoginDto, $userDataDto);
+ $this->loginMasterPass->loadMasterPass($userLoginDto, $userDto);
}
/**
* @throws AuthException
* @throws ServiceException
+ * @throws SPException
*/
#[DataProvider('wrongStatusDataProvider')]
public function testLoadMasterPassWithTemporaryAndInvalidStatus(UserMasterPassStatus $userMasterPassStatus)
{
- $userDataDto = new UserDataDto(UserDataGenerator::factory()->buildUserData());
+ $userDto = UserDto::fromModel(UserDataGenerator::factory()->buildUserData());
$userLoginDto = new UserLoginDto('a_user', 'a_password');
$this->request
@@ -264,7 +272,7 @@ class LoginMasterPassTest extends UnitaryTestCase
$this->userMasterPassService
->expects($this->once())
->method('updateOnLogin')
- ->with('a_master_pass', $userLoginDto, $userDataDto->getId())
+ ->with('a_master_pass', $userLoginDto, $userDto->id)
->willReturn($userMasterPassDto);
$this->trackService
@@ -274,16 +282,17 @@ class LoginMasterPassTest extends UnitaryTestCase
$this->expectException(AuthException::class);
$this->expectExceptionMessage('Wrong master password');
- $this->loginMasterPass->loadMasterPass($userLoginDto, $userDataDto);
+ $this->loginMasterPass->loadMasterPass($userLoginDto, $userDto);
}
/**
* @throws AuthException
* @throws ServiceException
+ * @throws SPException
*/
public function testLoadMasterPassWithTemporaryAndException()
{
- $userDataDto = new UserDataDto(UserDataGenerator::factory()->buildUserData());
+ $userDto = UserDto::fromModel(UserDataGenerator::factory()->buildUserData());
$userLoginDto = new UserLoginDto('a_user', 'a_password');
$this->request
@@ -315,16 +324,17 @@ class LoginMasterPassTest extends UnitaryTestCase
$this->expectException(ServiceException::class);
$this->expectExceptionMessage('Internal error');
- $this->loginMasterPass->loadMasterPass($userLoginDto, $userDataDto);
+ $this->loginMasterPass->loadMasterPass($userLoginDto, $userDto);
}
/**
* @throws AuthException
* @throws ServiceException
+ * @throws SPException
*/
public function testLoadMasterPassWithOld()
{
- $userDataDto = new UserDataDto(UserDataGenerator::factory()->buildUserData());
+ $userDto = UserDto::fromModel(UserDataGenerator::factory()->buildUserData());
$userLoginDto = new UserLoginDto('a_user', 'a_password');
$this->request
@@ -338,24 +348,25 @@ class LoginMasterPassTest extends UnitaryTestCase
$this->userMasterPassService
->expects($this->once())
->method('updateFromOldPass')
- ->with('an_old_pass', $userLoginDto, $userDataDto)
+ ->with('an_old_pass', $userLoginDto, $userDto)
->willReturn($userMasterPassDto);
$this->trackService
->expects($this->never())
->method('add');
- $this->loginMasterPass->loadMasterPass($userLoginDto, $userDataDto);
+ $this->loginMasterPass->loadMasterPass($userLoginDto, $userDto);
}
/**
* @throws AuthException
* @throws ServiceException
+ * @throws SPException
*/
#[DataProvider('wrongStatusDataProvider')]
public function testLoadMasterPassWithOldAndWrongStatus(UserMasterPassStatus $userMasterPassStatus)
{
- $userDataDto = new UserDataDto(UserDataGenerator::factory()->buildUserData());
+ $userDto = UserDto::fromModel(UserDataGenerator::factory()->buildUserData());
$userLoginDto = new UserLoginDto('a_user', 'a_password');
$this->request
@@ -369,7 +380,7 @@ class LoginMasterPassTest extends UnitaryTestCase
$this->userMasterPassService
->expects($this->once())
->method('updateFromOldPass')
- ->with('an_old_pass', $userLoginDto, $userDataDto)
+ ->with('an_old_pass', $userLoginDto, $userDto)
->willReturn($userMasterPassDto);
$this->trackService
@@ -379,7 +390,7 @@ class LoginMasterPassTest extends UnitaryTestCase
$this->expectException(AuthException::class);
$this->expectExceptionMessage('Wrong master password');
- $this->loginMasterPass->loadMasterPass($userLoginDto, $userDataDto);
+ $this->loginMasterPass->loadMasterPass($userLoginDto, $userDto);
}
@@ -387,6 +398,7 @@ class LoginMasterPassTest extends UnitaryTestCase
* @throws Exception
* @throws ContextException
* @throws InvalidArgumentException
+ * @throws SPException
*/
protected function setUp(): void
{
diff --git a/tests/SP/Domain/Auth/Services/LoginTest.php b/tests/SP/Domain/Auth/Services/LoginTest.php
index b8013ab1..8f2b82ca 100644
--- a/tests/SP/Domain/Auth/Services/LoginTest.php
+++ b/tests/SP/Domain/Auth/Services/LoginTest.php
@@ -1,4 +1,5 @@
buildUserData());
+ $userDto = UserDto::fromModel(UserDataGenerator::factory()->buildUserData());
$this->request
->expects($this->once())
@@ -226,12 +231,12 @@ class LoginTest extends UnitaryTestCase
&& $callable[1] === 'handleAuthResponse';
})
)
- ->willReturn($userDataDto);
+ ->willReturn($userDto);
$this->loginUserService
->expects($this->once())
->method('checkUser')
- ->with($userDataDto)
+ ->with($userDto)
->willReturn(new LoginResponseDto(LoginStatus::PASS));
$this->loginMasterPassService
@@ -242,25 +247,25 @@ class LoginTest extends UnitaryTestCase
return $userLoginDto->getLoginUser() === 'a_user'
&& $userLoginDto->getLoginPass() === 'a_password';
}),
- $userDataDto
+ $userDto
);
$this->userService
->expects($this->once())
->method('updateLastLoginById')
- ->with($userDataDto->getId());
+ ->with($userDto->id);
$this->context
->expects($this->once())
->method('setUserData')
- ->with($userDataDto);
+ ->with($userDto);
$userProfile = UserProfileDataGenerator::factory()->buildUserProfileData();
$this->userProfileService
->expects($this->once())
->method('getById')
- ->with($userDataDto->getUserProfileId())
+ ->with($userDto->userProfileId)
->willReturn($userProfile);
$this->context
@@ -312,13 +317,8 @@ class LoginTest extends UnitaryTestCase
$this->login->doLogin();
}
- /**
- * @throws AuthException
- */
public function testDoLoginWithNullUserData()
{
- $userDataDto = new UserDataDto(UserDataGenerator::factory()->buildUserData());
-
$this->request
->expects($this->once())
->method('analyzeString')
@@ -359,11 +359,12 @@ class LoginTest extends UnitaryTestCase
/**
* @throws AuthException
+ * @throws SPException
*/
#[DataProvider('loginStatusDataProvider')]
public function testDoLoginWithCheckUserFail(LoginStatus $loginStatus)
{
- $userDataDto = new UserDataDto(UserDataGenerator::factory()->buildUserData());
+ $userDataDto = UserDto::fromModel(UserDataGenerator::factory()->buildUserData());
$this->request
->expects($this->once())
@@ -413,8 +414,6 @@ class LoginTest extends UnitaryTestCase
*/
public function testDoLoginWithServiceException()
{
- $userDataDto = new UserDataDto(UserDataGenerator::factory()->buildUserData());
-
$this->request
->expects($this->once())
->method('analyzeString')
@@ -448,8 +447,6 @@ class LoginTest extends UnitaryTestCase
*/
public function testDoLoginWithException()
{
- $userDataDto = new UserDataDto(UserDataGenerator::factory()->buildUserData());
-
$this->request
->expects($this->once())
->method('analyzeString')
@@ -487,9 +484,10 @@ class LoginTest extends UnitaryTestCase
}
/**
- * @throws Exception
* @throws ContextException
+ * @throws Exception
* @throws InvalidArgumentException
+ * @throws SPException
*/
protected function setUp(): void
{
diff --git a/tests/SP/Domain/Auth/Services/LoginUserTest.php b/tests/SP/Domain/Auth/Services/LoginUserTest.php
index f91f86e2..8e8ded2f 100644
--- a/tests/SP/Domain/Auth/Services/LoginUserTest.php
+++ b/tests/SP/Domain/Auth/Services/LoginUserTest.php
@@ -1,4 +1,5 @@
buildUserData();
- $userDataDto = new UserDataDto($user->mutate(['isDisabled' => false, 'isChangePass' => false]));
+ $userDataDto = UserDto::fromModel($user->mutate(['isDisabled' => false, 'isChangePass' => false]));
$out = $this->loginUser->checkUser($userDataDto);
@@ -72,11 +75,12 @@ class LoginUserTest extends UnitaryTestCase
/**
* @throws AuthException
* @throws ServiceException
+ * @throws SPException
*/
public function testCheckUserWithDisabled()
{
$user = UserDataGenerator::factory()->buildUserData();
- $userDataDto = new UserDataDto($user->mutate(['isDisabled' => true, 'isChangePass' => false]));
+ $userDataDto = UserDto::fromModel($user->mutate(['isDisabled' => true, 'isChangePass' => false]));
$this->expectException(AuthException::class);
$this->expectExceptionMessage('User disabled');
@@ -87,11 +91,12 @@ class LoginUserTest extends UnitaryTestCase
/**
* @throws AuthException
* @throws ServiceException
+ * @throws SPException
*/
public function testCheckUserWithChangePass()
{
$user = UserDataGenerator::factory()->buildUserData();
- $userDataDto = new UserDataDto($user->mutate(['isDisabled' => false, 'isChangePass' => true]));
+ $userDataDto = UserDto::fromModel($user->mutate(['isDisabled' => false, 'isChangePass' => true]));
$this->userPassRecoverService
->expects($this->once())
@@ -107,11 +112,12 @@ class LoginUserTest extends UnitaryTestCase
/**
* @throws AuthException
* @throws ServiceException
+ * @throws SPException
*/
public function testCheckUserWithChangePassWithException()
{
$user = UserDataGenerator::factory()->buildUserData();
- $userDataDto = new UserDataDto($user->mutate(['isDisabled' => false, 'isChangePass' => true]));
+ $userDataDto = UserDto::fromModel($user->mutate(['isDisabled' => false, 'isChangePass' => true]));
$this->userPassRecoverService
->expects($this->once())
@@ -129,6 +135,7 @@ class LoginUserTest extends UnitaryTestCase
* @throws Exception
* @throws ContextException
* @throws InvalidArgumentException
+ * @throws SPException
*/
protected function setUp(): void
{
diff --git a/tests/SP/Domain/Common/Models/ModelTest.php b/tests/SP/Domain/Common/Models/ModelTest.php
new file mode 100644
index 00000000..5b61293f
--- /dev/null
+++ b/tests/SP/Domain/Common/Models/ModelTest.php
@@ -0,0 +1,132 @@
+.
+ */
+
+declare(strict_types=1);
+
+namespace SP\Tests\Domain\Common\Models;
+
+use Error;
+use Faker\Factory;
+use Faker\Generator;
+use PHPUnit\Framework\Attributes\Group;
+use PHPUnit\Framework\Attributes\TestWith;
+use PHPUnit\Framework\TestCase;
+use SP\Tests\Stubs\ModelStub;
+
+/**
+ * Class ModelTest
+ */
+#[Group('unitary')]
+class ModelTest extends TestCase
+{
+ protected static Generator $faker;
+
+ public static function setUpBeforeClass(): void
+ {
+ parent::setUpBeforeClass();
+
+ self::$faker = Factory::create();
+ }
+
+ public function testInstance()
+ {
+ $data = [
+ 'id' => self::$faker->randomNumber(3),
+ 'name' => self::$faker->colorName(),
+ 'test' => self::$faker->text()
+ ];
+
+ $model = new ModelStub($data);
+ self::assertEquals($data['id'], $model->getId());
+ self::assertEquals($data['id'], $model->id);
+ self::assertEquals($data['name'], $model->getName());
+ self::assertEquals($data['name'], $model->name);
+ self::assertEquals($data['test'], $model['test']);
+ self::assertNull($model->test);
+ }
+
+ #[TestWith(['id', 100])]
+ #[TestWith(['test_a', 'a_text'])]
+ public function testModifyClassProperties(string $property, mixed $value)
+ {
+ $data = [
+ 'id' => self::$faker->randomNumber(3),
+ 'test' => self::$faker->text()
+ ];
+
+ $model = new ModelStub($data);
+
+ self::expectException(Error::class);
+
+ $model->{$property} = $value;
+ }
+
+ public function testModifyInternalProperties()
+ {
+ $data = [
+ 'test' => self::$faker->text()
+ ];
+
+ $model = new ModelStub($data);
+
+ self::expectException(Error::class);
+
+ $model['test'] = 'a_text';
+ }
+
+ public function testGetColsWithPreffix()
+ {
+ self::markTestIncomplete();
+ }
+
+ public function testGetCols()
+ {
+ self::markTestIncomplete();
+ }
+
+ public function testToJson()
+ {
+ self::markTestIncomplete();
+ }
+
+ public function testBuildFromSimpleModel()
+ {
+ self::markTestIncomplete();
+ }
+
+ public function testToArray()
+ {
+ self::markTestIncomplete();
+ }
+
+ public function testMutate()
+ {
+ self::markTestIncomplete();
+ }
+
+ public function testJsonSerialize()
+ {
+ self::markTestIncomplete();
+ }
+}
diff --git a/tests/SP/Domain/Export/Services/FileBackupServiceTest.php b/tests/SP/Domain/Export/Services/FileBackupServiceTest.php
index 10af1158..db9fe7c4 100644
--- a/tests/SP/Domain/Export/Services/FileBackupServiceTest.php
+++ b/tests/SP/Domain/Export/Services/FileBackupServiceTest.php
@@ -33,7 +33,6 @@ use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use SP\Core\Bootstrap\Path;
use SP\Core\Context\ContextException;
-use SP\Domain\Common\Models\Simple;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Database\Ports\DatabaseInterface;
@@ -46,6 +45,7 @@ use SP\Infrastructure\Database\QueryData;
use SP\Infrastructure\Database\QueryResult;
use SP\Infrastructure\File\FileException;
use SP\Tests\UnitaryTestCase;
+use stdClass;
/**
* Class FileBackupServiceTest
@@ -135,7 +135,7 @@ class FileBackupServiceTest extends UnitaryTestCase
private function buildCreateResult(string $type): QueryResult
{
- $data = new Simple();
+ $data = new stdClass();
switch ($type) {
case 'table':
diff --git a/tests/SP/Domain/Export/Services/XmlExportTest.php b/tests/SP/Domain/Export/Services/XmlExportTest.php
index 9e83ea91..9e0eb4da 100644
--- a/tests/SP/Domain/Export/Services/XmlExportTest.php
+++ b/tests/SP/Domain/Export/Services/XmlExportTest.php
@@ -1,4 +1,5 @@
context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
[
'login' => 'test_user',
- 'userGroup.name' => 'test_group',
+ 'userGroupName' => 'test_group',
]
)
)
@@ -224,11 +227,12 @@ class XmlExportTest extends UnitaryTestCase
* @throws Exception
* @throws FileException
* @throws ServiceException
+ * @throws SPException
*/
public function testExportWithCheckDirectoryException()
{
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
@@ -256,17 +260,18 @@ class XmlExportTest extends UnitaryTestCase
* @throws Exception
* @throws FileException
* @throws ServiceException
+ * @throws SPException
*/
public function testExportWithExportCategoryException()
{
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
[
'login' => 'test_user',
- 'userGroup.name' => 'test_group',
+ 'userGroupName' => 'test_group',
]
)
)
@@ -298,17 +303,18 @@ class XmlExportTest extends UnitaryTestCase
* @throws ServiceException
* @throws DOMException
* @throws EnvironmentIsBrokenException
+ * @throws SPException
*/
public function testExportWithExportClientException()
{
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
[
'login' => 'test_user',
- 'userGroup.name' => 'test_group',
+ 'userGroupName' => 'test_group',
]
)
)
@@ -347,17 +353,18 @@ class XmlExportTest extends UnitaryTestCase
* @throws ServiceException
* @throws DOMException
* @throws EnvironmentIsBrokenException
+ * @throws SPException
*/
public function testExportWithExportTagException()
{
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
[
'login' => 'test_user',
- 'userGroup.name' => 'test_group',
+ 'userGroupName' => 'test_group',
]
)
)
@@ -401,17 +408,18 @@ class XmlExportTest extends UnitaryTestCase
* @throws ServiceException
* @throws DOMException
* @throws EnvironmentIsBrokenException
+ * @throws SPException
*/
public function testExportWithExportAccountException()
{
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
[
'login' => 'test_user',
- 'userGroup.name' => 'test_group',
+ 'userGroupName' => 'test_group',
]
)
)
@@ -459,17 +467,18 @@ class XmlExportTest extends UnitaryTestCase
* @throws FileException
* @throws CheckException
* @throws DOMException
+ * @throws SPException
*/
public function testExportWithCryptException()
{
$this->context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
[
'login' => 'test_user',
- 'userGroup.name' => 'test_group',
+ 'userGroupName' => 'test_group',
]
)
)
@@ -503,6 +512,7 @@ class XmlExportTest extends UnitaryTestCase
* @throws Exception
* @throws ServiceException
* @throws ContextException
+ * @throws SPException
*/
protected function setUp(): void
{
diff --git a/tests/SP/Domain/Import/Services/CsvImportTest.php b/tests/SP/Domain/Import/Services/CsvImportTest.php
index ae68b0a7..dc99e259 100644
--- a/tests/SP/Domain/Import/Services/CsvImportTest.php
+++ b/tests/SP/Domain/Import/Services/CsvImportTest.php
@@ -1,4 +1,5 @@
method('create')
->with(
new Callback(static function (AccountCreateDto $dto) {
- return $dto->getName() === 'Account_name'
- && $dto->getLogin() === 'a_login'
- && $dto->getClientId() === 100
- && $dto->getCategoryId() === 200
- && $dto->getPass() === 'a_password'
- && $dto->getNotes() === 'a_note'
- && $dto->getUrl() === 'a_url';
+ return $dto->name === 'Account_name'
+ && $dto->login === 'a_login'
+ && $dto->clientId === 100
+ && $dto->categoryId === 200
+ && $dto->pass === 'a_password'
+ && $dto->notes === 'a_note'
+ && $dto->url === 'a_url';
})
);
@@ -239,13 +240,13 @@ class CsvImportTest extends UnitaryTestCase
->method('create')
->with(
new Callback(static function (AccountCreateDto $dto) {
- return $dto->getName() === 'Account_name'
- && $dto->getLogin() === 'a_login'
- && $dto->getClientId() === 100
- && $dto->getCategoryId() === 200
- && $dto->getPass() === 'a_password'
- && $dto->getNotes() === 'a_note'
- && $dto->getUrl() === 'a_url';
+ return $dto->name === 'Account_name'
+ && $dto->login === 'a_login'
+ && $dto->clientId === 100
+ && $dto->categoryId === 200
+ && $dto->pass === 'a_password'
+ && $dto->notes === 'a_note'
+ && $dto->url === 'a_url';
})
);
@@ -295,13 +296,13 @@ class CsvImportTest extends UnitaryTestCase
->method('create')
->with(
new Callback(static function (AccountCreateDto $dto) {
- return $dto->getName() === 'Account_name'
- && $dto->getLogin() === 'a_login'
- && $dto->getClientId() === 100
- && $dto->getCategoryId() === 200
- && $dto->getPass() === 'a_password'
- && $dto->getNotes() === 'a_note'
- && $dto->getUrl() === 'a_url';
+ return $dto->name === 'Account_name'
+ && $dto->login === 'a_login'
+ && $dto->clientId === 100
+ && $dto->categoryId === 200
+ && $dto->pass === 'a_password'
+ && $dto->notes === 'a_note'
+ && $dto->url === 'a_url';
})
);
diff --git a/tests/SP/Domain/Import/Services/SyspassImportTest.php b/tests/SP/Domain/Import/Services/SyspassImportTest.php
index be0a3c70..2b6e7d6f 100644
--- a/tests/SP/Domain/Import/Services/SyspassImportTest.php
+++ b/tests/SP/Domain/Import/Services/SyspassImportTest.php
@@ -1,4 +1,5 @@
method('create')
->with(
self::callback(function (AccountCreateDto $dto) use ($accountCounter) {
- return $dto->getClientId() > 0
- && $dto->getCategoryId() > 0
- && $dto->getUserId() === 100
- && $dto->getUserGroupId() === 200
- && !empty($dto->getPass())
- && !empty($dto->getKey())
+ return $dto->clientId > 0
+ && $dto->categoryId > 0
+ && $dto->userId === 100
+ && $dto->userGroupId === 200
+ && !empty($dto->pass)
+ && !empty($dto->key)
&& $this->getCommonAccountMatcher($accountCounter, $dto);
})
);
@@ -153,38 +154,36 @@ class SyspassImportTest extends UnitaryTestCase
* @param AccountCreateDto $dto
* @return bool
*/
- protected function getCommonAccountMatcher(
- InvokedCount $accountCounter,
- AccountCreateDto $dto
- ): bool {
- $tagsCount = count(array_filter($dto->getTags() ?? [], static fn($value) => is_int($value)));
+ protected function getCommonAccountMatcher(InvokedCount $accountCounter, AccountCreateDto $dto): bool
+ {
+ $tagsCount = count(array_filter($dto->tags ?? [], static fn($value) => is_int($value)));
return match ($accountCounter->numberOfInvocations()) {
1 => $tagsCount === 3
- && $dto->getName() === 'Google'
- && $dto->getLogin() === 'admin'
- && $dto->getUrl() === 'https://google.com'
- && empty($dto->getNotes()),
+ && $dto->name === 'Google'
+ && $dto->login === 'admin'
+ && $dto->url === 'https://google.com'
+ && empty($dto->notes),
2 => $tagsCount === 3
- && $dto->getName() === 'Google'
- && $dto->getLogin() === 'admin'
- && $dto->getUrl() === 'https://google.com'
- && $dto->getNotes() === 'blablacar',
+ && $dto->name === 'Google'
+ && $dto->login === 'admin'
+ && $dto->url === 'https://google.com'
+ && $dto->notes === 'blablacar',
3 => $tagsCount === 0
- && $dto->getName() === 'Test CSV 1'
- && $dto->getLogin() === 'csv_login1'
- && $dto->getUrl() === 'http://test.me'
- && $dto->getNotes() === 'CSV Notes',
+ && $dto->name === 'Test CSV 1'
+ && $dto->login === 'csv_login1'
+ && $dto->url === 'http://test.me'
+ && $dto->notes === 'CSV Notes',
4 => $tagsCount === 0
- && $dto->getName() === 'Test CSV 2'
- && $dto->getLogin() === 'csv_login2'
- && $dto->getUrl() === 'http://linux.org'
- && str_starts_with($dto->getNotes(), 'CSV Notes 2'),
+ && $dto->name === 'Test CSV 2'
+ && $dto->login === 'csv_login2'
+ && $dto->url === 'http://linux.org'
+ && str_starts_with($dto->notes, 'CSV Notes 2'),
5 => $tagsCount === 0
- && $dto->getName() === 'Test CSV 3'
- && $dto->getLogin() === 'csv_login2'
- && $dto->getUrl() === 'http://apple.com'
- && $dto->getNotes() === 'CSV Notes 3',
+ && $dto->name === 'Test CSV 3'
+ && $dto->login === 'csv_login2'
+ && $dto->url === 'http://apple.com'
+ && $dto->notes === 'CSV Notes 3',
};
}
@@ -260,12 +259,12 @@ class SyspassImportTest extends UnitaryTestCase
->method('create')
->with(
self::callback(function (AccountCreateDto $dto) use ($accountCounter) {
- return $dto->getClientId() > 0
- && $dto->getCategoryId() > 0
- && $dto->getUserId() === 100
- && $dto->getUserGroupId() === 200
- && $dto->getPass() === 'super_secret'
- && empty($dto->getKey())
+ return $dto->clientId > 0
+ && $dto->categoryId > 0
+ && $dto->userId === 100
+ && $dto->userGroupId === 200
+ && $dto->pass === 'super_secret'
+ && empty($dto->key)
&& $this->getCommonAccountMatcher($accountCounter, $dto);
})
);
@@ -330,12 +329,12 @@ class SyspassImportTest extends UnitaryTestCase
->method('create')
->with(
self::callback(function (AccountCreateDto $dto) use ($accountCounter) {
- return $dto->getClientId() > 0
- && $dto->getCategoryId() > 0
- && $dto->getUserId() === 100
- && $dto->getUserGroupId() === 200
- && !empty($dto->getPass())
- && !empty($dto->getKey())
+ return $dto->clientId > 0
+ && $dto->categoryId > 0
+ && $dto->userId === 100
+ && $dto->userGroupId === 200
+ && !empty($dto->pass)
+ && !empty($dto->key)
&& $this->getCommonAccountMatcher($accountCounter, $dto);
})
);
@@ -415,12 +414,12 @@ class SyspassImportTest extends UnitaryTestCase
->method('create')
->with(
self::callback(function (AccountCreateDto $dto) use ($accountCounter) {
- return $dto->getClientId() > 0
- && $dto->getCategoryId() > 0
- && $dto->getUserId() === 100
- && $dto->getUserGroupId() === 200
- && !empty($dto->getPass())
- && !empty($dto->getKey())
+ return $dto->clientId > 0
+ && $dto->categoryId > 0
+ && $dto->userId === 100
+ && $dto->userGroupId === 200
+ && !empty($dto->pass)
+ && !empty($dto->key)
&& $this->getCommonAccountMatcher($accountCounter, $dto);
})
);
@@ -665,27 +664,27 @@ class SyspassImportTest extends UnitaryTestCase
->method('create')
->with(
self::callback(function (AccountCreateDto $dto) use ($accountCounter) {
- $tagsCount = count(array_filter($dto->getTags() ?? [], static fn($value) => is_int($value)));
+ $tagsCount = count(array_filter($dto->tags ?? [], static fn($value) => is_int($value)));
$accountMatcher = match ($accountCounter->numberOfInvocations()) {
1 => $tagsCount === 1
- && $dto->getName() === 'Amazon SES'
- && $dto->getLogin() === 'admin'
- && $dto->getUrl() === 'https://aws.amazon.com/'
- && $dto->getNotes() === 'Simple Email Service',
+ && $dto->name === 'Amazon SES'
+ && $dto->login === 'admin'
+ && $dto->url === 'https://aws.amazon.com/'
+ && $dto->notes === 'Simple Email Service',
2 => $tagsCount === 1
- && $dto->getName() === 'Google GCP'
- && $dto->getLogin() === 'admin'
- && $dto->getUrl() === 'https://cloud.google.com/'
- && $dto->getNotes() === 'Google Cloud'
+ && $dto->name === 'Google GCP'
+ && $dto->login === 'admin'
+ && $dto->url === 'https://cloud.google.com/'
+ && $dto->notes === 'Google Cloud'
};
- return $dto->getClientId() > 0
- && $dto->getCategoryId() > 0
- && $dto->getUserId() === 100
- && $dto->getUserGroupId() === 200
- && !empty($dto->getPass())
- && !empty($dto->getKey())
+ return $dto->clientId > 0
+ && $dto->categoryId > 0
+ && $dto->userId === 100
+ && $dto->userGroupId === 200
+ && !empty($dto->pass)
+ && !empty($dto->key)
&& $accountMatcher;
})
);
diff --git a/tests/SP/Domain/ItemPreset/Services/ItemPresetTest.php b/tests/SP/Domain/ItemPreset/Services/ItemPresetTest.php
index f6dcbdb3..22b5f8b8 100644
--- a/tests/SP/Domain/ItemPreset/Services/ItemPresetTest.php
+++ b/tests/SP/Domain/ItemPreset/Services/ItemPresetTest.php
@@ -113,12 +113,12 @@ class ItemPresetTest extends UnitaryTestCase
{
$itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData((object)['foo' => 'bar']);
- $userData = $this->context->getUserData();
+ $userDto = $this->context->getUserData();
$this->itemPresetRepository
->expects(self::once())
->method('getByFilter')
- ->with('test', $userData->getId(), $userData->getUserGroupId(), $userData->getUserProfileId())
+ ->with('test', $userDto->id, $userDto->userGroupId, $userDto->userProfileId)
->willReturn(new QueryResult([$itemPreset]));
$out = $this->itemPreset->getForCurrentUser('test');
diff --git a/tests/SP/Domain/Log/Providers/LogHandlerTest.php b/tests/SP/Domain/Log/Providers/LogHandlerTest.php
index 7a84c7bd..b187738c 100644
--- a/tests/SP/Domain/Log/Providers/LogHandlerTest.php
+++ b/tests/SP/Domain/Log/Providers/LogHandlerTest.php
@@ -82,7 +82,7 @@ class LogHandlerTest extends UnitaryTestCase
self::callback(function (array $event) use ($eventMessage, $ipv4) {
return $event['message'] === $eventMessage->composeText(' | ')
&& $event['address'] === $ipv4
- && $event['user'] === $this->context->getUserData()->getLogin()
+ && $event['user'] === $this->context->getUserData()->login
&& !empty($event['caller']);
})
);
@@ -121,7 +121,7 @@ class LogHandlerTest extends UnitaryTestCase
self::callback(function (array $event) use ($ipv4) {
return $event['message'] === 'N/A'
&& $event['address'] === $ipv4
- && $event['user'] === $this->context->getUserData()->getLogin()
+ && $event['user'] === $this->context->getUserData()->login
&& !empty($event['caller']);
})
);
@@ -160,7 +160,7 @@ class LogHandlerTest extends UnitaryTestCase
self::callback(function (array $event) use ($ipv4) {
return $event['message'] === 'an_exception'
&& $event['address'] === $ipv4
- && $event['user'] === $this->context->getUserData()->getLogin()
+ && $event['user'] === $this->context->getUserData()->login
&& !empty($event['caller']);
})
);
diff --git a/tests/SP/Domain/Notification/Services/NotificationTest.php b/tests/SP/Domain/Notification/Services/NotificationTest.php
index 5b58b1f3..7974728a 100644
--- a/tests/SP/Domain/Notification/Services/NotificationTest.php
+++ b/tests/SP/Domain/Notification/Services/NotificationTest.php
@@ -1,4 +1,5 @@
assertEquals([1], $out);
}
+ /**
+ * @throws SPException
+ */
public function testSearchWithAdmin()
{
- $userDataDto = new UserDataDto(
+ $userDto = UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
@@ -97,28 +102,28 @@ class NotificationTest extends UnitaryTestCase
)
);
- $this->context->setUserData($userDataDto);
+ $this->context->setUserData($userDto);
$itemSearchData = new ItemSearchDto();
$this->notificationRepository
->expects($this->once())
->method('searchForAdmin')
- ->with($itemSearchData, $userDataDto->getId());
+ ->with($itemSearchData, $userDto->id);
$this->notification->search($itemSearchData);
}
public function testSearchWithNoAdmin()
{
- $userData = $this->context->getUserData();
+ $userDto = $this->context->getUserData();
$itemSearchData = new ItemSearchDto();
$this->notificationRepository
->expects($this->once())
->method('searchForUserId')
- ->with($itemSearchData, $userData->getId());
+ ->with($itemSearchData, $userDto->id);
$this->notification->search($itemSearchData);
}
@@ -160,10 +165,11 @@ class NotificationTest extends UnitaryTestCase
/**
* @throws Exception
+ * @throws SPException
*/
public function testGetAllActiveForCurrentUserWithAdmin()
{
- $userDataDto = new UserDataDto(
+ $userDto = UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
@@ -172,7 +178,7 @@ class NotificationTest extends UnitaryTestCase
]
)
);
- $this->context->setUserData($userDataDto);
+ $this->context->setUserData($userDto);
$queryResult = $this->createMock(QueryResult::class);
$queryResult->expects($this->once())
@@ -183,7 +189,7 @@ class NotificationTest extends UnitaryTestCase
$this->notificationRepository
->expects($this->once())
->method('getAllActiveForAdmin')
- ->with($userDataDto->getId())
+ ->with($userDto->id)
->willReturn($queryResult);
$out = $this->notification->getAllActiveForCurrentUser();
@@ -196,7 +202,7 @@ class NotificationTest extends UnitaryTestCase
*/
public function testGetAllActiveForCurrentUserWithNoAdmin()
{
- $userData = $this->context->getUserData();
+ $userDto = $this->context->getUserData();
$queryResult = $this->createMock(QueryResult::class);
$queryResult->expects($this->once())
@@ -207,7 +213,7 @@ class NotificationTest extends UnitaryTestCase
$this->notificationRepository
->expects($this->once())
->method('getAllActiveForUserId')
- ->with($userData->getId())
+ ->with($userDto->id)
->willReturn($queryResult);
$out = $this->notification->getAllActiveForCurrentUser();
diff --git a/tests/SP/Domain/Security/Services/EventlogTest.php b/tests/SP/Domain/Security/Services/EventlogTest.php
index 2d9916e9..ed891b9f 100644
--- a/tests/SP/Domain/Security/Services/EventlogTest.php
+++ b/tests/SP/Domain/Security/Services/EventlogTest.php
@@ -1,4 +1,5 @@
context->getUserData();
- return $eventlog->getUserId() == $userData->getId()
- && $eventlog->getLogin() == $userData->getLogin()
+ return $eventlog->getUserId() == $userData->id
+ && $eventlog->getLogin() == $userData->login
&& $eventlog->getIpAddress() == '192.168.0.1';
})
)
diff --git a/tests/SP/Domain/User/Services/UserMasterPassTest.php b/tests/SP/Domain/User/Services/UserMasterPassTest.php
index 901598ee..56d3f62c 100644
--- a/tests/SP/Domain/User/Services/UserMasterPassTest.php
+++ b/tests/SP/Domain/User/Services/UserMasterPassTest.php
@@ -1,4 +1,5 @@
buildUserData()
->mutate(['isChangedPass' => false, 'lastUpdateMPass' => 10]);
- $userDataDto = new UserDataDto($user);
+ $userDto = UserDto::fromModel($user);
$userLoginDto = new UserLoginDto(self::$faker->userName(), self::$faker->password());
$this->configService
@@ -82,16 +84,17 @@ class UserMasterPassTest extends UnitaryTestCase
->with($user->getMPass(), $user->getMKey(), $key)
->willReturn('a_master_pass');
- $out = $this->userMasterPass->load($userLoginDto, $userDataDto);
+ $out = $this->userMasterPass->load($userLoginDto, $userDto);
$this->assertEquals(UserMasterPassStatus::Ok, $out->getUserMasterPassStatus());
$this->assertEquals('a_master_pass', $out->getClearMasterPass());
- $this->assertEquals($userDataDto->getMPass(), $out->getCryptMasterPass());
- $this->assertEquals($userDataDto->getMKey(), $out->getCryptSecuredKey());
+ $this->assertEquals($userDto->mPass, $out->getCryptMasterPass());
+ $this->assertEquals($userDto->mKey, $out->getCryptSecuredKey());
}
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testLoadWithUserPass()
{
@@ -99,7 +102,7 @@ class UserMasterPassTest extends UnitaryTestCase
->buildUserData()
->mutate(['isChangedPass' => false, 'lastUpdateMPass' => 10]);
- $userDataDto = new UserDataDto($user);
+ $userDto = UserDto::fromModel($user);
$userLoginDto = new UserLoginDto(self::$faker->userName(), self::$faker->password());
$this->configService
@@ -118,12 +121,12 @@ class UserMasterPassTest extends UnitaryTestCase
->with($user->getMPass(), $user->getMKey(), $key)
->willReturn('a_master_pass');
- $out = $this->userMasterPass->load($userLoginDto, $userDataDto, 'a_password');
+ $out = $this->userMasterPass->load($userLoginDto, $userDto, 'a_password');
$this->assertEquals(UserMasterPassStatus::Ok, $out->getUserMasterPassStatus());
$this->assertEquals('a_master_pass', $out->getClearMasterPass());
- $this->assertEquals($userDataDto->getMPass(), $out->getCryptMasterPass());
- $this->assertEquals($userDataDto->getMKey(), $out->getCryptSecuredKey());
+ $this->assertEquals($userDto->mPass, $out->getCryptMasterPass());
+ $this->assertEquals($userDto->mKey, $out->getCryptSecuredKey());
}
/**
@@ -131,7 +134,7 @@ class UserMasterPassTest extends UnitaryTestCase
*/
public function testLoadWithNotSet()
{
- $userDataDto = new UserDataDto(new User());
+ $userDto = new UserDto();
$userLoginDto = new UserLoginDto(self::$faker->userName(), self::$faker->password());
$this->configService
@@ -142,17 +145,18 @@ class UserMasterPassTest extends UnitaryTestCase
->expects($this->never())
->method('decrypt');
- $out = $this->userMasterPass->load($userLoginDto, $userDataDto);
+ $out = $this->userMasterPass->load($userLoginDto, $userDto);
$this->assertEquals(UserMasterPassStatus::NotSet, $out->getUserMasterPassStatus());
}
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testLoadWithNotSetAndEmptyPass()
{
- $userDataDto = new UserDataDto(new User(['use' => self::$faker->userName]));
+ $userDto = UserDto::fromArray(['use' => self::$faker->userName]);
$userLoginDto = new UserLoginDto(self::$faker->userName());
$this->configService
@@ -163,17 +167,18 @@ class UserMasterPassTest extends UnitaryTestCase
->expects($this->never())
->method('decrypt');
- $out = $this->userMasterPass->load($userLoginDto, $userDataDto);
+ $out = $this->userMasterPass->load($userLoginDto, $userDto);
$this->assertEquals(UserMasterPassStatus::NotSet, $out->getUserMasterPassStatus());
}
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testLoadWithNotSetAndEmptyUser()
{
- $userDataDto = new UserDataDto(new User(['pass' => self::$faker->password]));
+ $userDto = UserDto::fromArray(['pass' => self::$faker->password]);
$userLoginDto = new UserLoginDto();
$this->configService
@@ -184,13 +189,14 @@ class UserMasterPassTest extends UnitaryTestCase
->expects($this->never())
->method('decrypt');
- $out = $this->userMasterPass->load($userLoginDto, $userDataDto);
+ $out = $this->userMasterPass->load($userLoginDto, $userDto);
$this->assertEquals(UserMasterPassStatus::NotSet, $out->getUserMasterPassStatus());
}
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testLoadWithNotSetAndNullHash()
{
@@ -198,7 +204,7 @@ class UserMasterPassTest extends UnitaryTestCase
->buildUserData()
->mutate(['isChangedPass' => false, 'lastUpdateMPass' => 10]);
- $userDataDto = new UserDataDto($user);
+ $userDto = UserDto::fromModel($user);
$userLoginDto = new UserLoginDto(self::$faker->userName(), self::$faker->password());
$this->configService
@@ -210,13 +216,14 @@ class UserMasterPassTest extends UnitaryTestCase
->expects($this->never())
->method('decrypt');
- $out = $this->userMasterPass->load($userLoginDto, $userDataDto);
+ $out = $this->userMasterPass->load($userLoginDto, $userDto);
$this->assertEquals(UserMasterPassStatus::NotSet, $out->getUserMasterPassStatus());
}
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testLoadWithChanged()
{
@@ -224,7 +231,7 @@ class UserMasterPassTest extends UnitaryTestCase
->buildUserData()
->mutate(['isChangedPass' => false, 'lastUpdateMPass' => 0]);
- $userDataDto = new UserDataDto($user);
+ $userDto = UserDto::fromModel($user);
$userLoginDto = new UserLoginDto(self::$faker->userName(), self::$faker->password());
$this->configService
@@ -237,13 +244,14 @@ class UserMasterPassTest extends UnitaryTestCase
->expects($this->never())
->method('decrypt');
- $out = $this->userMasterPass->load($userLoginDto, $userDataDto);
+ $out = $this->userMasterPass->load($userLoginDto, $userDto);
$this->assertEquals(UserMasterPassStatus::Changed, $out->getUserMasterPassStatus());
}
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testLoadWithCheckOld()
{
@@ -251,7 +259,7 @@ class UserMasterPassTest extends UnitaryTestCase
->buildUserData()
->mutate(['isChangedPass' => true, 'lastUpdateMPass' => 10]);
- $userDataDto = new UserDataDto($user);
+ $userDto = UserDto::fromModel($user);
$userLoginDto = new UserLoginDto(self::$faker->userName(), null);
$this->configService
@@ -264,13 +272,14 @@ class UserMasterPassTest extends UnitaryTestCase
->expects($this->never())
->method('decrypt');
- $out = $this->userMasterPass->load($userLoginDto, $userDataDto);
+ $out = $this->userMasterPass->load($userLoginDto, $userDto);
$this->assertEquals(UserMasterPassStatus::CheckOld, $out->getUserMasterPassStatus());
}
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testLoadWithCryptException()
{
@@ -278,7 +287,7 @@ class UserMasterPassTest extends UnitaryTestCase
->buildUserData()
->mutate(['isChangedPass' => false, 'lastUpdateMPass' => 10]);
- $userDataDto = new UserDataDto($user);
+ $userDto = UserDto::fromModel($user);
$userLoginDto = new UserLoginDto(self::$faker->userName(), self::$faker->password());
$this->configService
@@ -292,13 +301,14 @@ class UserMasterPassTest extends UnitaryTestCase
->method('decrypt')
->willThrowException(CryptException::error('test'));
- $out = $this->userMasterPass->load($userLoginDto, $userDataDto);
+ $out = $this->userMasterPass->load($userLoginDto, $userDto);
$this->assertEquals(UserMasterPassStatus::CheckOld, $out->getUserMasterPassStatus());
}
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testLoadWithInvalid()
{
@@ -306,7 +316,7 @@ class UserMasterPassTest extends UnitaryTestCase
->buildUserData()
->mutate(['isChangedPass' => false, 'lastUpdateMPass' => 10]);
- $userDataDto = new UserDataDto($user);
+ $userDto = UserDto::fromModel($user);
$userLoginDto = new UserLoginDto(self::$faker->userName(), self::$faker->password());
$this->configService
@@ -325,13 +335,14 @@ class UserMasterPassTest extends UnitaryTestCase
->with($user->getMPass(), $user->getMKey(), $key)
->willReturn('a_pass');
- $out = $this->userMasterPass->load($userLoginDto, $userDataDto);
+ $out = $this->userMasterPass->load($userLoginDto, $userDto);
$this->assertEquals(UserMasterPassStatus::Invalid, $out->getUserMasterPassStatus());
}
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testLoadWithException()
{
@@ -339,7 +350,7 @@ class UserMasterPassTest extends UnitaryTestCase
->buildUserData()
->mutate(['isChangedPass' => false, 'lastUpdateMPass' => 10]);
- $userDataDto = new UserDataDto($user);
+ $userDto = UserDto::fromModel($user);
$userLoginDto = new UserLoginDto(self::$faker->userName(), self::$faker->password());
$this->configService
@@ -356,12 +367,13 @@ class UserMasterPassTest extends UnitaryTestCase
$this->expectException(ServiceException::class);
$this->expectExceptionMessage('test');
- $this->userMasterPass->load($userLoginDto, $userDataDto);
+ $this->userMasterPass->load($userLoginDto, $userDto);
}
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testUpdateFromOldPass()
{
@@ -369,7 +381,7 @@ class UserMasterPassTest extends UnitaryTestCase
->buildUserData()
->mutate(['isChangedPass' => false, 'lastUpdateMPass' => 10]);
- $userDataDto = new UserDataDto($user);
+ $userDto = UserDto::fromModel($user);
$userLoginDto = new UserLoginDto(self::$faker->userName(), self::$faker->password());
$this->configService
@@ -407,9 +419,9 @@ class UserMasterPassTest extends UnitaryTestCase
$this->userRepository
->expects($this->once())
->method('updateMasterPassById')
- ->with($userDataDto->getId(), 'encrypted', 'a_secure_key');
+ ->with($userDto->id, 'encrypted', 'a_secure_key');
- $out = $this->userMasterPass->updateFromOldPass('an_old_user_pass', $userLoginDto, $userDataDto);
+ $out = $this->userMasterPass->updateFromOldPass('an_old_user_pass', $userLoginDto, $userDto);
$this->assertEquals(UserMasterPassStatus::Ok, $out->getUserMasterPassStatus());
$this->assertEquals('encrypted', $out->getCryptMasterPass());
@@ -419,6 +431,7 @@ class UserMasterPassTest extends UnitaryTestCase
/**
* @throws ServiceException
+ * @throws SPException
*/
public function testUpdateFromOldPassWithInvalid()
{
@@ -426,7 +439,7 @@ class UserMasterPassTest extends UnitaryTestCase
->buildUserData()
->mutate(['isChangedPass' => false, 'lastUpdateMPass' => 10]);
- $userDataDto = new UserDataDto($user);
+ $userDto = UserDto::fromModel($user);
$userLoginDto = new UserLoginDto(self::$faker->userName(), self::$faker->password());
$this->configService
@@ -457,7 +470,7 @@ class UserMasterPassTest extends UnitaryTestCase
->expects($this->never())
->method('updateMasterPassById');
- $out = $this->userMasterPass->updateFromOldPass('an_old_user_pass', $userLoginDto, $userDataDto);
+ $out = $this->userMasterPass->updateFromOldPass('an_old_user_pass', $userLoginDto, $userDto);
$this->assertEquals(UserMasterPassStatus::Invalid, $out->getUserMasterPassStatus());
}
diff --git a/tests/SP/Generators/AccountDataGenerator.php b/tests/SP/Generators/AccountDataGenerator.php
index f2cfe74b..ae6fd882 100644
--- a/tests/SP/Generators/AccountDataGenerator.php
+++ b/tests/SP/Generators/AccountDataGenerator.php
@@ -146,8 +146,8 @@ final class AccountDataGenerator extends DataGenerator
'userGroupId' => $this->faker->randomNumber(3),
'key' => $this->faker->text(),
'pass' => $this->faker->text(),
- 'dateEdit' => $this->faker->unixTime(),
- 'dateAdd' => $this->faker->unixTime(),
+ 'dateEdit' => $this->faker->dateTime()->format('Y-m-d H:i:s'),
+ 'dateAdd' => $this->faker->dateTime()->format('Y-m-d H:i:s'),
'isModify' => $this->faker->numberBetween(0, 1),
'isDeleted' => $this->faker->numberBetween(0, 1),
'otherUserGroupEdit' => $this->faker->numberBetween(0, 1),
@@ -160,86 +160,86 @@ final class AccountDataGenerator extends DataGenerator
public function buildAccountUpdateDto(): AccountUpdateDto
{
return new AccountUpdateDto(
- name: $this->faker->name(),
- login: $this->faker->userName(),
clientId: $this->faker->randomNumber(3),
categoryId: $this->faker->randomNumber(3),
- pass: $this->faker->sha1(),
userId: $this->faker->randomNumber(3),
+ userGroupId: $this->faker->randomNumber(3),
+ userEditId: $this->faker->randomNumber(3),
+ parentId: $this->faker->randomNumber(3),
+ passDateChange: $this->faker->unixTime(),
+ name: $this->faker->name(),
+ login: $this->faker->userName(),
+ pass: $this->faker->sha1(),
key: $this->faker->sha1(),
url: $this->faker->url(),
notes: $this->faker->text(),
- userEditId: $this->faker->randomNumber(3),
isPrivate: $this->faker->boolean(),
isPrivateGroup: $this->faker->boolean(),
- passDateChange: $this->faker->unixTime(),
- parentId: $this->faker->randomNumber(3),
- userGroupId: $this->faker->randomNumber(3),
otherUserEdit: $this->faker->boolean(),
otherUserGroupEdit: $this->faker->boolean(),
usersView: array_map(fn() => $this->faker->randomNumber(3), range(0, 4)),
usersEdit: array_map(fn() => $this->faker->randomNumber(3), range(0, 4)),
+ tags: array_map(fn() => $this->faker->randomNumber(3), range(0, 4)),
userGroupsView: array_map(fn() => $this->faker->randomNumber(3), range(0, 4)),
- userGroupsEdit: array_map(fn() => $this->faker->randomNumber(3), range(0, 4)),
- tags: array_map(fn() => $this->faker->randomNumber(3), range(0, 4))
+ userGroupsEdit: array_map(fn() => $this->faker->randomNumber(3), range(0, 4))
);
}
public function buildAccountCreateDto(): AccountCreateDto
{
return new AccountCreateDto(
- name: $this->faker->name(),
- login: $this->faker->userName(),
clientId: $this->faker->randomNumber(3),
categoryId: $this->faker->randomNumber(3),
- pass: $this->faker->sha1(),
userId: $this->faker->randomNumber(3),
+ userGroupId: $this->faker->randomNumber(3),
+ userEditId: $this->faker->randomNumber(3),
+ parentId: $this->faker->randomNumber(3),
+ passDateChange: $this->faker->unixTime(),
+ name: $this->faker->name(),
+ login: $this->faker->userName(),
+ pass: $this->faker->sha1(),
url: $this->faker->url(),
notes: $this->faker->text(),
- userEditId: $this->faker->randomNumber(3),
isPrivate: $this->faker->boolean(),
isPrivateGroup: $this->faker->boolean(),
- passDateChange: $this->faker->unixTime(),
- parentId: $this->faker->randomNumber(3),
- userGroupId: $this->faker->randomNumber(3),
otherUserEdit: $this->faker->boolean(),
otherUserGroupEdit: $this->faker->boolean(),
usersView: array_map(fn() => $this->faker->randomNumber(3), range(0, 4)),
usersEdit: array_map(fn() => $this->faker->randomNumber(3), range(0, 4)),
+ tags: array_map(fn() => $this->faker->randomNumber(3), range(0, 4)),
userGroupsView: array_map(fn() => $this->faker->randomNumber(3), range(0, 4)),
- userGroupsEdit: array_map(fn() => $this->faker->randomNumber(3), range(0, 4)),
- tags: array_map(fn() => $this->faker->randomNumber(3), range(0, 4))
+ userGroupsEdit: array_map(fn() => $this->faker->randomNumber(3), range(0, 4))
);
}
public function buildAccountHistoryDto(): AccountHistoryDto
{
return new AccountHistoryDto(
- accountId: $this->faker->randomNumber(3),
- isDelete: (int)$this->faker->boolean(),
- isModify: (int)$this->faker->boolean(),
- dateAdd: $this->faker->dateTime()->format('Y-m-d H:i:s'),
- dateEdit: $this->faker->dateTime()->format('Y-m-d H:i:s'),
- passDate: $this->faker->unixTime(),
- countView: $this->faker->randomNumber(3),
- countDecrypt: $this->faker->randomNumber(3),
- name: $this->faker->name(),
- login: $this->faker->userName(),
clientId: $this->faker->randomNumber(3),
categoryId: $this->faker->randomNumber(3),
- pass: $this->faker->sha1(),
userId: $this->faker->randomNumber(3),
+ userGroupId: $this->faker->randomNumber(3),
+ userEditId: $this->faker->randomNumber(3),
+ parentId: $this->faker->randomNumber(3),
+ countView: $this->faker->randomNumber(3),
+ countDecrypt: $this->faker->randomNumber(3),
+ passDateChange: $this->faker->unixTime(),
+ name: $this->faker->name(),
+ login: $this->faker->userName(),
+ pass: $this->faker->sha1(),
key: $this->faker->sha1(),
url: $this->faker->url(),
notes: $this->faker->text(),
- userEditId: $this->faker->randomNumber(3),
isPrivate: $this->faker->boolean(),
isPrivateGroup: $this->faker->boolean(),
- passDateChange: $this->faker->unixTime(),
- parentId: $this->faker->randomNumber(3),
- userGroupId: $this->faker->randomNumber(3),
otherUserEdit: $this->faker->boolean(),
otherUserGroupEdit: $this->faker->boolean(),
+ accountId: $this->faker->randomNumber(3),
+ isDelete: (int)$this->faker->boolean(),
+ isModify: (int)$this->faker->boolean(),
+ passDate: $this->faker->unixTime(),
+ dateAdd: $this->faker->dateTime()->format('Y-m-d H:i:s'),
+ dateEdit: $this->faker->dateTime()->format('Y-m-d H:i:s'),
);
}
}
diff --git a/tests/SP/Infrastructure/Account/Repositories/AccountFileTest.php b/tests/SP/Infrastructure/Account/Repositories/AccountFileTest.php
index b7b3006e..f9971ea7 100644
--- a/tests/SP/Infrastructure/Account/Repositories/AccountFileTest.php
+++ b/tests/SP/Infrastructure/Account/Repositories/AccountFileTest.php
@@ -29,7 +29,7 @@ use Aura\SqlQuery\QueryFactory;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Constraint\Callback;
use PHPUnit\Framework\MockObject\MockObject;
-use SP\Domain\Account\Models\File;
+use SP\Domain\Account\Models\File as FileModel;
use SP\Domain\Common\Models\Simple;
use SP\Domain\Core\Dtos\ItemSearchDto;
use SP\Domain\Core\Exceptions\ConstraintException;
@@ -97,7 +97,7 @@ class AccountFileTest extends UnitaryTestCase
*/
public function testCreate(): void
{
- $fileData = File::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData());
+ $fileData = FileModel::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData());
$expected = new QueryResult(null, 0, 1);
@@ -131,14 +131,14 @@ class AccountFileTest extends UnitaryTestCase
*/
public function testGetByAccountId(): void
{
- $id = self::$faker->randomNumber();
+ $id = self::$faker->randomNumber(3);
$callback = new Callback(
static function (QueryData $arg) use ($id) {
$query = $arg->getQuery();
return $query->getBindValues()['accountId'] === $id
- && $arg->getMapClassName() === Simple::class
+ && $arg->getMapClassName() === FileModel::class
&& !empty($query->getStatement());
}
);
@@ -184,7 +184,7 @@ class AccountFileTest extends UnitaryTestCase
$query = $arg->getQuery();
return $query->getBindValues()['id'] === $id
- && $arg->getMapClassName() === Simple::class
+ && $arg->getMapClassName() === FileModel::class
&& !empty($query->getStatement());
}
);
@@ -210,7 +210,7 @@ class AccountFileTest extends UnitaryTestCase
&& $params['clientName'] === $searchStringLike
&& $params['accountName'] === $searchStringLike
&& $params['type'] === $searchStringLike
- && $arg->getMapClassName() === Simple::class
+ && $arg->getMapClassName() === FileModel::class
&& !empty($arg->getQuery()->getStatement());
}
);
diff --git a/tests/SP/Infrastructure/User/Repositories/UserTest.php b/tests/SP/Infrastructure/User/Repositories/UserTest.php
index 348c0e3a..333dfec7 100644
--- a/tests/SP/Infrastructure/User/Repositories/UserTest.php
+++ b/tests/SP/Infrastructure/User/Repositories/UserTest.php
@@ -1,4 +1,5 @@
context->setUserData(
- new UserDataDto(
+ UserDto::fromModel(
UserDataGenerator::factory()
->buildUserData()
->mutate(
diff --git a/tests/SP/IntegrationTestCase.php b/tests/SP/IntegrationTestCase.php
index ae7aca24..e4de36b8 100644
--- a/tests/SP/IntegrationTestCase.php
+++ b/tests/SP/IntegrationTestCase.php
@@ -26,6 +26,7 @@ declare(strict_types=1);
namespace SP\Tests;
+use Closure;
use DI\ContainerBuilder;
use Faker\Factory;
use Faker\Generator;
@@ -58,8 +59,10 @@ use SP\Domain\Core\UI\ThemeContextInterface;
use SP\Domain\Database\Ports\DatabaseInterface;
use SP\Domain\Database\Ports\DbStorageHandler;
use SP\Domain\Notification\Ports\MailService;
-use SP\Domain\User\Dtos\UserDataDto;
+use SP\Domain\User\Dtos\UserDto;
use SP\Domain\User\Models\ProfileData;
+use SP\Domain\User\Models\User;
+use SP\Domain\User\Models\UserPreferences;
use SP\Infrastructure\Database\QueryData;
use SP\Infrastructure\Database\QueryResult;
use SP\Infrastructure\File\ArchiveHandler;
@@ -81,10 +84,11 @@ abstract class IntegrationTestCase extends TestCase
{
protected static Generator $faker;
protected readonly string $passwordSalt;
+ protected Closure|null $databaseQueryResolver = null;
/**
- * @var array $databaseResolvers
+ * @var array $databaseMapperResolvers
*/
- private array $databaseResolvers = [];
+ private array $databaseMapperResolvers = [];
public static function setUpBeforeClass(): void
{
@@ -178,6 +182,7 @@ abstract class IntegrationTestCase extends TestCase
$configData->method('isMaintenance')->willReturn(false);
$configData->method('getDbName')->willReturn(self::$faker->colorName());
$configData->method('getPasswordSalt')->willReturn($this->passwordSalt);
+ $configData->method('isFilesEnabled')->willReturn(true);
return $configData;
}
@@ -185,10 +190,14 @@ abstract class IntegrationTestCase extends TestCase
protected function getDatabaseReturn(): callable
{
return function (QueryData $queryData): QueryResult {
+ if ($this->databaseQueryResolver) {
+ return $this->databaseQueryResolver->call($this, $queryData);
+ }
+
$mapClassName = $queryData->getMapClassName();
- if (isset($this->databaseResolvers[$mapClassName])) {
- return $this->databaseResolvers[$mapClassName];
+ if (isset($this->databaseMapperResolvers[$mapClassName])) {
+ return $this->databaseMapperResolvers[$mapClassName];
}
return new QueryResult([], 1, 100);
@@ -211,14 +220,15 @@ abstract class IntegrationTestCase extends TestCase
}
/**
- * @return UserDataDto
+ * @return UserDto
* @throws SPException
*/
- protected function getUserDataDto(): UserDataDto
+ protected function getUserDataDto(): UserDto
{
- return new UserDataDto(
- UserDataGenerator::factory()->buildUserData()->mutate(['isAdminApp' => false, 'isAdminAcc' => false])
- );
+ $user = UserDataGenerator::factory()->buildUserData()->mutate(['isAdminApp' => false, 'isAdminAcc' => false]);
+
+ return UserDto::fromModel($user, User::class)
+ ->mutate(['preferences', $user->hydrate(UserPreferences::class)]);
}
/**
@@ -229,9 +239,9 @@ abstract class IntegrationTestCase extends TestCase
return UserProfileDataGenerator::factory()->buildProfileData();
}
- final protected function addDatabaseResolver(string $className, QueryResult $queryResult): void
+ final protected function addDatabaseMapperResolver(string $className, QueryResult $queryResult): void
{
- $this->databaseResolvers[$className] = $queryResult;
+ $this->databaseMapperResolvers[$className] = $queryResult;
}
protected function buildRequest(string $method, string $uri, array $paramsGet = [], array $paramsPost = []): Request
diff --git a/tests/SP/Modules/Cli/Commands/UpdateMasterPasswordCommandTest.php b/tests/SP/Modules/Cli/Commands/UpdateMasterPasswordCommandTest.php
index a7227398..a5bbfc2b 100644
--- a/tests/SP/Modules/Cli/Commands/UpdateMasterPasswordCommandTest.php
+++ b/tests/SP/Modules/Cli/Commands/UpdateMasterPasswordCommandTest.php
@@ -31,7 +31,6 @@ use SP\Domain\Core\Exceptions\FileNotFoundException;
use SP\Modules\Cli\Commands\Crypt\UpdateMasterPasswordCommand;
use SP\Tests\DatabaseTrait;
use SP\Tests\Modules\Cli\CliTestCase;
-use SP\Tests\Services\Account\AccountCryptServiceTest;
use function SP\Tests\recreateDir;
@@ -51,8 +50,8 @@ class UpdateMasterPasswordCommandTest extends CliTestCase
* @var string[]
*/
protected static array $commandInputData = [
- '--currentMasterPassword' => AccountCryptServiceTest::CURRENT_MASTERPASS,
- '--masterPassword' => AccountCryptServiceTest::NEW_MASTERPASS
+ '--currentMasterPassword' => 'a_pass',
+ '--masterPassword' => 'a_new_pass'
];
/**
diff --git a/tests/SP/Modules/Web/Controllers/Account/CopyControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/CopyControllerTest.php
index 8dc51a76..22c8fa35 100644
--- a/tests/SP/Modules/Web/Controllers/Account/CopyControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/CopyControllerTest.php
@@ -55,12 +55,12 @@ class CopyControllerTest extends IntegrationTestCase
*/
public function testCopyAction()
{
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountView::class,
new QueryResult([AccountDataGenerator::factory()->buildAccountDataView()])
);
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
Item::class,
new QueryResult(
[
diff --git a/tests/SP/Modules/Web/Controllers/Account/CopyPassControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/CopyPassControllerTest.php
index 8dd47137..9c71ef28 100644
--- a/tests/SP/Modules/Web/Controllers/Account/CopyPassControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/CopyPassControllerTest.php
@@ -58,7 +58,7 @@ class CopyPassControllerTest extends IntegrationTestCase
*/
public function testCopyPassAction()
{
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountPassItemWithIdAndName::class,
new QueryResult([
AccountPassItemWithIdAndName::buildFromSimpleModel(
diff --git a/tests/SP/Modules/Web/Controllers/Account/CopyPassHistoryControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/CopyPassHistoryControllerTest.php
index 78bb3ab0..88488267 100644
--- a/tests/SP/Modules/Web/Controllers/Account/CopyPassHistoryControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/CopyPassHistoryControllerTest.php
@@ -58,7 +58,7 @@ class CopyPassHistoryControllerTest extends IntegrationTestCase
*/
public function testCopyPassHistoryAction()
{
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountPassItemWithIdAndName::class,
new QueryResult([
AccountPassItemWithIdAndName::buildFromSimpleModel(
diff --git a/tests/SP/Modules/Web/Controllers/Account/DeleteControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/DeleteControllerTest.php
index a211fce7..a681b50e 100644
--- a/tests/SP/Modules/Web/Controllers/Account/DeleteControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/DeleteControllerTest.php
@@ -56,7 +56,7 @@ class DeleteControllerTest extends IntegrationTestCase
*/
public function testDeleteAction()
{
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountView::class,
new QueryResult([AccountDataGenerator::factory()->buildAccountDataView()])
);
@@ -78,7 +78,7 @@ class DeleteControllerTest extends IntegrationTestCase
$container = $this->buildContainer(
$definitions,
- $this->buildRequest('get', 'index.php', ['r' => 'account/delete'])
+ $this->buildRequest('get', 'index.php', ['r' => 'account/delete/100'])
);
$this->runApp($container);
diff --git a/tests/SP/Modules/Web/Controllers/Account/EditControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/EditControllerTest.php
index 6c8ef24f..fd9efdc3 100644
--- a/tests/SP/Modules/Web/Controllers/Account/EditControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/EditControllerTest.php
@@ -55,7 +55,7 @@ class EditControllerTest extends IntegrationTestCase
*/
public function testEditAction()
{
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountView::class,
new QueryResult([AccountDataGenerator::factory()->buildAccountDataView()])
);
diff --git a/tests/SP/Modules/Web/Controllers/Account/RequestAccessControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/RequestAccessControllerTest.php
index 01a45767..87e0680a 100644
--- a/tests/SP/Modules/Web/Controllers/Account/RequestAccessControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/RequestAccessControllerTest.php
@@ -55,7 +55,7 @@ class RequestAccessControllerTest extends IntegrationTestCase
*/
public function testRequestAccessAction()
{
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountView::class,
new QueryResult([AccountDataGenerator::factory()->buildAccountDataView()])
);
diff --git a/tests/SP/Modules/Web/Controllers/Account/SaveCopyControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/SaveCopyControllerTest.php
index a1431da2..df0ee142 100644
--- a/tests/SP/Modules/Web/Controllers/Account/SaveCopyControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/SaveCopyControllerTest.php
@@ -59,7 +59,7 @@ class SaveCopyControllerTest extends IntegrationTestCase
{
$accountDataGenerator = AccountDataGenerator::factory();
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountView::class,
new QueryResult([$accountDataGenerator->buildAccountDataView()])
);
diff --git a/tests/SP/Modules/Web/Controllers/Account/SaveCreateControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/SaveCreateControllerTest.php
index 58c5c6d3..3431c2c0 100644
--- a/tests/SP/Modules/Web/Controllers/Account/SaveCreateControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/SaveCreateControllerTest.php
@@ -59,7 +59,7 @@ class SaveCreateControllerTest extends IntegrationTestCase
{
$accountDataGenerator = AccountDataGenerator::factory();
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountView::class,
new QueryResult([$accountDataGenerator->buildAccountDataView()])
);
diff --git a/tests/SP/Modules/Web/Controllers/Account/SaveDeleteControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/SaveDeleteControllerTest.php
index 1089f3f3..ed687fab 100644
--- a/tests/SP/Modules/Web/Controllers/Account/SaveDeleteControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/SaveDeleteControllerTest.php
@@ -57,12 +57,12 @@ class SaveDeleteControllerTest extends IntegrationTestCase
{
$accountDataGenerator = AccountDataGenerator::factory();
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountView::class,
new QueryResult([$accountDataGenerator->buildAccountDataView()])
);
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
Account::class,
new QueryResult([$accountDataGenerator->buildAccount()])
);
diff --git a/tests/SP/Modules/Web/Controllers/Account/SaveEditControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/SaveEditControllerTest.php
index 44a9626b..25da1257 100644
--- a/tests/SP/Modules/Web/Controllers/Account/SaveEditControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/SaveEditControllerTest.php
@@ -57,12 +57,12 @@ class SaveEditControllerTest extends IntegrationTestCase
{
$accountDataGenerator = AccountDataGenerator::factory();
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
Account::class,
new QueryResult([$accountDataGenerator->buildAccount()])
);
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountView::class,
new QueryResult([$accountDataGenerator->buildAccountDataView()])
);
diff --git a/tests/SP/Modules/Web/Controllers/Account/SaveEditPassControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/SaveEditPassControllerTest.php
index cc0a896d..600da1b5 100644
--- a/tests/SP/Modules/Web/Controllers/Account/SaveEditPassControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/SaveEditPassControllerTest.php
@@ -60,12 +60,12 @@ class SaveEditPassControllerTest extends IntegrationTestCase
{
$accountDataGenerator = AccountDataGenerator::factory();
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
Account::class,
new QueryResult([$accountDataGenerator->buildAccount()])
);
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountView::class,
new QueryResult([$accountDataGenerator->buildAccountDataView()])
);
diff --git a/tests/SP/Modules/Web/Controllers/Account/SaveEditRestoreControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/SaveEditRestoreControllerTest.php
index 637c890e..8b0b9ee0 100644
--- a/tests/SP/Modules/Web/Controllers/Account/SaveEditRestoreControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/SaveEditRestoreControllerTest.php
@@ -61,17 +61,17 @@ class SaveEditRestoreControllerTest extends IntegrationTestCase
{
$accountDataGenerator = AccountDataGenerator::factory();
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountHistory::class,
new QueryResult([$accountDataGenerator->buildAccountHistoryData()])
);
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
Account::class,
new QueryResult([$accountDataGenerator->buildAccount()])
);
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountView::class,
new QueryResult([$accountDataGenerator->buildAccountDataView()])
);
diff --git a/tests/SP/Modules/Web/Controllers/Account/SaveRequestControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/SaveRequestControllerTest.php
index 4d741ee0..0897c023 100644
--- a/tests/SP/Modules/Web/Controllers/Account/SaveRequestControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/SaveRequestControllerTest.php
@@ -56,7 +56,7 @@ class SaveRequestControllerTest extends IntegrationTestCase
{
$accountDataGenerator = AccountDataGenerator::factory();
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountView::class,
new QueryResult([$accountDataGenerator->buildAccountDataView()])
);
diff --git a/tests/SP/Modules/Web/Controllers/Account/SearchControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/SearchControllerTest.php
index cb710ea8..32f2262f 100644
--- a/tests/SP/Modules/Web/Controllers/Account/SearchControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/SearchControllerTest.php
@@ -32,7 +32,7 @@ use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use SP\Domain\Account\Models\AccountSearchView;
use SP\Domain\Core\Exceptions\InvalidClassException;
-use SP\Domain\User\Dtos\UserDataDto;
+use SP\Domain\User\Dtos\UserDto;
use SP\Infrastructure\Database\QueryResult;
use SP\Infrastructure\File\FileException;
use SP\Mvc\View\OutputHandlerInterface;
@@ -59,7 +59,7 @@ class SearchControllerTest extends IntegrationTestCase
{
$accountSearchView = AccountDataGenerator::factory()->buildAccountSearchView();
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountSearchView::class,
QueryResult::withTotalNumRows([$accountSearchView], 1)
);
@@ -95,9 +95,9 @@ class SearchControllerTest extends IntegrationTestCase
$this->runApp($container);
}
- protected function getUserDataDto(): UserDataDto
+ protected function getUserDataDto(): UserDto
{
$userPreferences = UserDataGenerator::factory()->buildUserPreferencesData()->mutate(['topNavbar' => true]);
- return parent::getUserDataDto()->set('preferences', $userPreferences);
+ return parent::getUserDataDto()->mutate(['preferences' => $userPreferences]);
}
}
diff --git a/tests/SP/Modules/Web/Controllers/Account/ViewControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/ViewControllerTest.php
index ff116079..c237b3a6 100644
--- a/tests/SP/Modules/Web/Controllers/Account/ViewControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/ViewControllerTest.php
@@ -56,12 +56,12 @@ class ViewControllerTest extends IntegrationTestCase
*/
public function testViewAction()
{
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountView::class,
new QueryResult([AccountDataGenerator::factory()->buildAccountDataView()])
);
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
Item::class,
new QueryResult(
[
diff --git a/tests/SP/Modules/Web/Controllers/Account/ViewHistoryControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/ViewHistoryControllerTest.php
index 537380dd..8cc74bde 100644
--- a/tests/SP/Modules/Web/Controllers/Account/ViewHistoryControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/ViewHistoryControllerTest.php
@@ -64,12 +64,12 @@ class ViewHistoryControllerTest extends IntegrationTestCase
'userEditName' => self::$faker->userName(),
'userEditLogin' => self::$faker->userName(),
]);
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountHistory::class,
new QueryResult([$accountHistory])
);
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
Item::class,
new QueryResult(
[
diff --git a/tests/SP/Modules/Web/Controllers/Account/ViewLinkControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/ViewLinkControllerTest.php
index 8e51739d..da840d12 100644
--- a/tests/SP/Modules/Web/Controllers/Account/ViewLinkControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/ViewLinkControllerTest.php
@@ -79,7 +79,7 @@ class ViewLinkControllerTest extends IntegrationTestCase
'data' => $vault->getSerialized()
]
);
- $this->addDatabaseResolver(PublicLink::class, new QueryResult([$publicLink]));
+ $this->addDatabaseMapperResolver(PublicLink::class, new QueryResult([$publicLink]));
$definitions = $this->getModuleDefinitions();
$definitions[OutputHandlerInterface::class] = $this->setupOutputHandler(function (string $output): void {
diff --git a/tests/SP/Modules/Web/Controllers/Account/ViewPassControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/ViewPassControllerTest.php
index 42f0c9bf..00407875 100644
--- a/tests/SP/Modules/Web/Controllers/Account/ViewPassControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/ViewPassControllerTest.php
@@ -60,7 +60,7 @@ class ViewPassControllerTest extends IntegrationTestCase
*/
public function testViewPassAction()
{
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountPassItemWithIdAndName::class,
new QueryResult([
AccountPassItemWithIdAndName::buildFromSimpleModel(
diff --git a/tests/SP/Modules/Web/Controllers/Account/ViewPassHistoryControllerTest.php b/tests/SP/Modules/Web/Controllers/Account/ViewPassHistoryControllerTest.php
index 048acb13..712d30d7 100644
--- a/tests/SP/Modules/Web/Controllers/Account/ViewPassHistoryControllerTest.php
+++ b/tests/SP/Modules/Web/Controllers/Account/ViewPassHistoryControllerTest.php
@@ -60,7 +60,7 @@ class ViewPassHistoryControllerTest extends IntegrationTestCase
*/
public function testViewPassHistoryAction()
{
- $this->addDatabaseResolver(
+ $this->addDatabaseMapperResolver(
AccountPassItemWithIdAndName::class,
new QueryResult([
AccountPassItemWithIdAndName::buildFromSimpleModel(
diff --git a/tests/SP/Modules/Web/Controllers/AccountFile/AccountFileTest.php b/tests/SP/Modules/Web/Controllers/AccountFile/AccountFileTest.php
new file mode 100644
index 00000000..77221500
--- /dev/null
+++ b/tests/SP/Modules/Web/Controllers/AccountFile/AccountFileTest.php
@@ -0,0 +1,227 @@
+.
+ */
+
+declare(strict_types=1);
+
+namespace SP\Tests\Modules\Web\Controllers\AccountFile;
+
+use PHPUnit\Framework\Attributes\Group;
+use PHPUnit\Framework\Attributes\Test;
+use PHPUnit\Framework\MockObject\Exception;
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\NotFoundExceptionInterface;
+use SP\Domain\Account\Models\File;
+use SP\Domain\Core\Exceptions\InvalidClassException;
+use SP\Infrastructure\Database\QueryData;
+use SP\Infrastructure\Database\QueryResult;
+use SP\Infrastructure\File\FileException;
+use SP\Mvc\View\OutputHandlerInterface;
+use SP\Tests\Generators\FileDataGenerator;
+use SP\Tests\IntegrationTestCase;
+use Symfony\Component\DomCrawler\Crawler;
+
+/**
+ * Class AccountFileTest
+ */
+#[Group('integration')]
+class AccountFileTest extends IntegrationTestCase
+{
+
+ /**
+ * @throws NotFoundExceptionInterface
+ * @throws Exception
+ * @throws FileException
+ * @throws InvalidClassException
+ * @throws ContainerExceptionInterface
+ */
+ #[Test]
+ public function deleteSingleFile()
+ {
+ $definitions = $this->getModuleDefinitions();
+
+ $container = $this->buildContainer(
+ $definitions,
+ $this->buildRequest('post', 'index.php', ['r' => 'accountFile/delete/100'])
+ );
+
+ $this->runApp($container);
+
+ $this->expectOutputString(
+ '{"status":0,"description":"File deleted","data":[],"messages":[]}'
+ );
+ }
+
+ /**
+ * @throws NotFoundExceptionInterface
+ * @throws Exception
+ * @throws FileException
+ * @throws InvalidClassException
+ * @throws ContainerExceptionInterface
+ */
+ #[Test]
+ public function deleteMultipleFiles()
+ {
+ $this->databaseQueryResolver = function (QueryData $queryData): QueryResult {
+ /** @noinspection SqlWithoutWhere */
+ if (str_starts_with($queryData->getQuery()->getStatement(), 'DELETE FROM `AccountFile`')) {
+ return new QueryResult([], 3);
+ }
+
+ return new QueryResult();
+ };
+
+ $definitions = $this->getModuleDefinitions();
+
+ $container = $this->buildContainer(
+ $definitions,
+ $this->buildRequest('post', 'index.php', ['r' => 'accountFile/delete'], ['items' => [100, 200, 300]])
+ );
+
+ $this->runApp($container);
+
+ $this->expectOutputString(
+ '{"status":0,"description":"Files deleted","data":[],"messages":[]}'
+ );
+ }
+
+ /**
+ * @return void
+ * @throws ContainerExceptionInterface
+ * @throws Exception
+ * @throws FileException
+ * @throws InvalidClassException
+ * @throws NotFoundExceptionInterface
+ */
+ #[Test]
+ public function downloadFile()
+ {
+ $fileData = FileDataGenerator::factory()->buildFileData();
+
+ $this->addDatabaseMapperResolver(
+ File::class,
+ new QueryResult(
+ [File::buildFromSimpleModel($fileData)]
+ )
+ );
+
+ $definitions = $this->getModuleDefinitions();
+
+ $container = $this->buildContainer(
+ $definitions,
+ $this->buildRequest('get', 'index.php', ['r' => 'accountFile/download/100'])
+ );
+
+ $this->runApp($container);
+
+ $this->expectOutputString($fileData['content']);
+ }
+
+ /**
+ * @return void
+ * @throws ContainerExceptionInterface
+ * @throws Exception
+ * @throws FileException
+ * @throws InvalidClassException
+ * @throws NotFoundExceptionInterface
+ */
+ #[Test]
+ public function listFiles()
+ {
+ $fileDataGenerator = FileDataGenerator::factory();
+
+ $this->addDatabaseMapperResolver(
+ File::class,
+ new QueryResult(
+ [
+ File::buildFromSimpleModel($fileDataGenerator->buildFileData()),
+ File::buildFromSimpleModel($fileDataGenerator->buildFileData())
+ ]
+ )
+ );
+
+ $definitions = $this->getModuleDefinitions();
+ $definitions[OutputHandlerInterface::class] = $this->setupOutputHandler(function (string $output): void {
+ $crawler = new Crawler($output);
+ $filter = $crawler->filterXPath(
+ '//div[@id="files-wrap"]/ul//li'
+ )->extract(['class']);
+
+ assert(!empty($output));
+ assert(count($filter) === 2);
+
+ $this->assertTrue(true);
+ });
+
+ $container = $this->buildContainer(
+ $definitions,
+ $this->buildRequest('get', 'index.php', ['r' => 'accountFile/list/100'])
+ );
+
+ $this->runApp($container);
+ }
+
+ /**
+ * @return void
+ * @throws ContainerExceptionInterface
+ * @throws Exception
+ * @throws FileException
+ * @throws InvalidClassException
+ * @throws NotFoundExceptionInterface
+ */
+ #[Test]
+ public function search()
+ {
+ $fileDataGenerator = FileDataGenerator::factory();
+
+ $this->addDatabaseMapperResolver(
+ File::class,
+ QueryResult::withTotalNumRows(
+ [
+ File::buildFromSimpleModel($fileDataGenerator->buildFileData()),
+ File::buildFromSimpleModel($fileDataGenerator->buildFileData())
+ ],
+ 2
+ )
+ );
+
+ $definitions = $this->getModuleDefinitions();
+ $definitions[OutputHandlerInterface::class] = $this->setupOutputHandler(function (string $output): void {
+ $crawler = new Crawler($output);
+ $filter = $crawler->filterXPath('//table/tbody//tr[string-length(@data-item-id) > 0]')
+ ->extract(['class']);
+
+ assert(!empty($output));
+ assert(count($filter) === 2);
+
+ $this->assertTrue(true);
+ });
+
+ $container = $this->buildContainer(
+ $definitions,
+ $this->buildRequest('get', 'index.php', ['r' => 'accountFile/search'])
+ );
+
+ $this->runApp($container);
+ }
+}
diff --git a/lib/SP/Domain/Account/Models/FileExtData.php b/tests/SP/Stubs/ModelStub.php
similarity index 72%
rename from lib/SP/Domain/Account/Models/FileExtData.php
rename to tests/SP/Stubs/ModelStub.php
index c50f0c05..a6d08963 100644
--- a/lib/SP/Domain/Account/Models/FileExtData.php
+++ b/tests/SP/Stubs/ModelStub.php
@@ -1,5 +1,4 @@
.
*/
-namespace SP\Domain\Account\Models;
+declare(strict_types=1);
+
+namespace SP\Tests\Stubs;
+
+use SP\Domain\Common\Models\Model;
/**
- * Class FileExtData
+ * Class ModelStub
*/
-class FileExtData extends File
+final class ModelStub extends Model
{
- protected ?string $clientName = null;
- protected ?string $accountName = null;
+ protected ?int $id = null;
+ protected ?string $name = null;
- public function getClientName(): ?string
+ public function getId(): ?int
{
- return $this->clientName;
+ return $this->id;
}
- public function getAccountName(): ?string
+ public function getName(): ?string
{
- return $this->accountName;
+ return $this->name;
}
}
diff --git a/tests/SP/UnitaryTestCase.php b/tests/SP/UnitaryTestCase.php
index ba741f72..33fe1163 100644
--- a/tests/SP/UnitaryTestCase.php
+++ b/tests/SP/UnitaryTestCase.php
@@ -61,7 +61,7 @@ use SP\Domain\Config\Ports\ConfigFileService;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Events\EventDispatcherInterface;
use SP\Domain\Core\Exceptions\SPException;
-use SP\Domain\User\Dtos\UserDataDto;
+use SP\Domain\User\Dtos\UserDto;
use SP\Domain\User\Models\ProfileData;
use SP\Domain\User\Models\User;
use SP\Tests\Generators\ConfigDataGenerator;
@@ -154,12 +154,12 @@ abstract class UnitaryTestCase extends TestCase
}
/**
- * @return UserDataDto
+ * @return UserDto
* @throws SPException
*/
- private function buildUserDataDto(): UserDataDto
+ private function buildUserDataDto(): UserDto
{
- return new UserDataDto(
+ return UserDto::fromModel(
new User(
[
'login' => self::$faker->userName,