oms-Help/tests/Controller/SearchControllerTest.php
2024-03-20 05:15:59 +00:00

102 lines
3.0 KiB
PHP
Executable File

<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Admin\tests\Controller;
use Model\CoreSettings;
use Modules\Admin\Models\AccountPermission;
use phpOMS\Account\Account;
use phpOMS\Account\AccountManager;
use phpOMS\Account\PermissionType;
use phpOMS\Application\ApplicationAbstract;
use phpOMS\Dispatcher\Dispatcher;
use phpOMS\Event\EventManager;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\HttpResponse;
use phpOMS\Module\ModuleAbstract;
use phpOMS\Module\ModuleManager;
use phpOMS\Router\WebRouter;
use phpOMS\Utils\TestUtils;
/**
* @internal
*/
#[\PHPUnit\Framework\Attributes\CoversClass(\Modules\Help\Controller\SearchController::class)]
#[\PHPUnit\Framework\Attributes\TestDox('Modules\Admin\tests\Controller\SearchControllerTest: Admin api controller')]
final class SearchControllerTest extends \PHPUnit\Framework\TestCase
{
protected ApplicationAbstract $app;
/**
* @var \Modules\Help\Controller\SearchController
*/
protected ModuleAbstract $module;
/**
* {@inheritdoc}
*/
protected function setUp() : void
{
$this->app = new class() extends ApplicationAbstract
{
protected string $appName = 'Search';
};
$this->app->dbPool = $GLOBALS['dbpool'];
$this->app->unitId = 1;
$this->app->accountManager = new AccountManager($GLOBALS['session']);
$this->app->appSettings = new CoreSettings();
$this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules/');
$this->app->dispatcher = new Dispatcher($this->app);
$this->app->eventManager = new EventManager($this->app->dispatcher);
$this->app->eventManager->importFromFile(__DIR__ . '/../../../../Web/Api/Hooks.php');
$account = new Account();
TestUtils::setMember($account, 'id', 1);
$permission = new AccountPermission();
$permission->unit = 1;
$permission->app = 1;
$permission->setPermission(
PermissionType::READ
| PermissionType::CREATE
| PermissionType::MODIFY
| PermissionType::DELETE
| PermissionType::PERMISSION
);
$account->addPermission($permission);
$this->app->accountManager->add($account);
$this->app->router = new WebRouter();
$this->module = $this->app->moduleManager->get('Help');
TestUtils::setMember($this->module, 'app', $this->app);
}
#[\PHPUnit\Framework\Attributes\Group('module')]
public function testHelpSearch() : void
{
$response = new HttpResponse();
$request = new HttpRequest();
$request->header->account = 1;
$request->setData('search', ':help introduction');
$this->module->searchHelp($request, $response);
self::assertGreaterThan(0, \count($response->getData('')));
}
}