mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-22 08:16:51 +01:00
test(IT): Test account delete
Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
@@ -32,12 +32,16 @@ use SP\Core\Events\Event;
|
||||
use SP\Core\Events\EventMessage;
|
||||
use SP\Domain\Account\Ports\AccountService;
|
||||
use SP\Domain\Core\Acl\AclActionsInterface;
|
||||
use SP\Domain\Core\Exceptions\SPException;
|
||||
use SP\Domain\CustomField\Ports\CustomFieldDataService;
|
||||
use SP\Domain\Http\Dtos\JsonMessage;
|
||||
use SP\Modules\Web\Controllers\Traits\JsonTrait;
|
||||
use SP\Mvc\Controller\ItemTrait;
|
||||
use SP\Mvc\Controller\WebControllerHelper;
|
||||
|
||||
use function SP\__u;
|
||||
use function SP\processException;
|
||||
|
||||
/**
|
||||
* Class SaveDeleteController
|
||||
*/
|
||||
@@ -46,46 +50,39 @@ final class SaveDeleteController extends AccountControllerBase
|
||||
use ItemTrait;
|
||||
use JsonTrait;
|
||||
|
||||
private AccountService $accountService;
|
||||
private CustomFieldDataService $customFieldService;
|
||||
|
||||
public function __construct(
|
||||
Application $application,
|
||||
WebControllerHelper $webControllerHelper,
|
||||
AccountService $accountService,
|
||||
CustomFieldDataService $customFieldService
|
||||
Application $application,
|
||||
WebControllerHelper $webControllerHelper,
|
||||
private readonly AccountService $accountService,
|
||||
private readonly CustomFieldDataService $customFieldService
|
||||
) {
|
||||
parent::__construct(
|
||||
$application,
|
||||
$webControllerHelper
|
||||
);
|
||||
|
||||
$this->accountService = $accountService;
|
||||
$this->customFieldService = $customFieldService;
|
||||
parent::__construct($application, $webControllerHelper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves delete action
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @return bool
|
||||
* @throws JsonException
|
||||
* @throws SPException
|
||||
*/
|
||||
public function saveDeleteAction(int $id): bool
|
||||
{
|
||||
try {
|
||||
$accountDetails = $this->accountService->getByIdEnriched($id)->getAccountVData();
|
||||
$accountDetails = $this->accountService->getByIdEnriched($id);
|
||||
|
||||
$this->accountService->delete($id);
|
||||
|
||||
$this->eventDispatcher->notify(
|
||||
'delete.account',
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Account removed'))
|
||||
->addDetail(__u('Account'), $accountDetails->getName())
|
||||
->addDetail(__u('Client'), $accountDetails->getClientName())
|
||||
$this,
|
||||
EventMessage::factory()
|
||||
->addDescription(__u('Account removed'))
|
||||
->addDetail(__u('Account'), $accountDetails->getName())
|
||||
->addDetail(__u('Client'), $accountDetails->getClientName())
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -169,6 +169,10 @@ trait ItemTrait
|
||||
array|int $itemId,
|
||||
CustomFieldDataService $customFieldService
|
||||
): void {
|
||||
if (!is_array($itemId)) {
|
||||
$itemId = [$itemId];
|
||||
}
|
||||
|
||||
$customFieldService->delete($itemId, $moduleId);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
* sysPass is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* sysPass is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SP\Tests\Modules\Web\Controllers\Account;
|
||||
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use PHPUnit\Framework\MockObject\Exception;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use ReflectionClass;
|
||||
use SP\Domain\Config\Ports\ConfigService;
|
||||
use SP\Domain\Core\Exceptions\InvalidClassException;
|
||||
use SP\Infrastructure\Database\QueryData;
|
||||
use SP\Infrastructure\Database\QueryResult;
|
||||
use SP\Infrastructure\File\FileException;
|
||||
use SP\Tests\IntegrationTestCase;
|
||||
|
||||
/**
|
||||
* Class SaveDeleteControllerTest
|
||||
*/
|
||||
#[Group('integration')]
|
||||
class SaveDeleteControllerTest extends IntegrationTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws InvalidClassException
|
||||
* @throws FileException
|
||||
*/
|
||||
public function testSaveDeleteAction()
|
||||
{
|
||||
$configService = self::createStub(ConfigService::class);
|
||||
$configService->method('getByParam')->willReturnArgument(0);
|
||||
|
||||
$definitions = $this->getModuleDefinitions();
|
||||
$definitions[ConfigService::class] = $configService;
|
||||
|
||||
$container = $this->buildContainer(
|
||||
$definitions,
|
||||
$this->buildRequest('post', 'index.php', ['r' => 'account/saveDelete/1'])
|
||||
);
|
||||
|
||||
$this->runApp($container);
|
||||
|
||||
$this->expectOutputString(
|
||||
'{"status":0,"description":"Account removed","data":[],"messages":[]}'
|
||||
);
|
||||
}
|
||||
|
||||
protected function getDatabaseReturn(): callable
|
||||
{
|
||||
return function (QueryData $queryData): QueryResult {
|
||||
if (!empty($queryData->getMapClassName())) {
|
||||
$reflection = new ReflectionClass($queryData->getMapClassName());
|
||||
return new QueryResult([$reflection->newInstance()], 1, 100);
|
||||
}
|
||||
|
||||
return new QueryResult([], 1, 100);
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user