cs fixes, bug fixes, code coverage

This commit is contained in:
Dennis Eichhorn 2021-11-16 00:05:43 +01:00
parent a84352440f
commit 59be55da10
3 changed files with 133 additions and 27 deletions

View File

@ -12,9 +12,7 @@ If you have a good idea for improvement feel free to create a new issue with all
### Issues ### Issues
Feel free to grab any open issue implement it and create a new pull request. Most issues can be found in the `Project.md` file in the `Docs` repository. Feel free to grab any open issue implement it and create a new pull request. Most issues can be found in the code marked with `@todo` or in the [PROJECT.md](https://github.com/Orange-Management/Docs/blob/master/Project/PROJECT.md) file.
The issue information can be used to provide additional information such as priority, difficulty and type. For your first issue try to find a issue marked `[d:first]` or `[d:beginner]`.
### Code Style ### Code Style

View File

@ -1,66 +1,67 @@
<?php return [ <?php declare(strict_types=1);
return [
'^:help .*$' => [ '^:help .*$' => [
0 => [ 0 => [
'dest' => '\Modules\Help\Controller\SearchController:searchHelp', 'dest' => '\Modules\Help\Controller\SearchController:searchHelp',
'verb' => 16, 'verb' => 16,
'permission' => [ 'permission' => [
'module' => 'Help', 'module' => 'Help',
'type' => 2, 'type' => 2,
'state' => 2, 'state' => 2,
], ],
], ],
], ],
'^:help :user .*$' => [ '^:help :user .*$' => [
0 => [ 0 => [
'dest' => '\Modules\Help\Controller\SearchController:searchHelp', 'dest' => '\Modules\Help\Controller\SearchController:searchHelp',
'verb' => 16, 'verb' => 16,
'permission' => [ 'permission' => [
'module' => 'Help', 'module' => 'Help',
'type' => 2, 'type' => 2,
'state' => 2, 'state' => 2,
], ],
], ],
], ],
'^:help :dev .*$' => [ '^:help :dev .*$' => [
0 => [ 0 => [
'dest' => '\Modules\Help\Controller\SearchController:searchHelp', 'dest' => '\Modules\Help\Controller\SearchController:searchHelp',
'verb' => 16, 'verb' => 16,
'permission' => [ 'permission' => [
'module' => 'Help', 'module' => 'Help',
'type' => 2, 'type' => 2,
'state' => 3, 'state' => 3,
], ],
], ],
], ],
'^:help :module .*$' => [ '^:help :module .*$' => [
0 => [ 0 => [
'dest' => '\Modules\Help\Controller\SearchController:searchHelp', 'dest' => '\Modules\Help\Controller\SearchController:searchHelp',
'verb' => 16, 'verb' => 16,
'permission' => [ 'permission' => [
'module' => 'Help', 'module' => 'Help',
'type' => 2, 'type' => 2,
'state' => 2, 'state' => 2,
], ],
], ],
], ],
'^:goto .*$' => [ '^:goto .*$' => [
0 => [ 0 => [
'dest' => '\Modules\Navigation\Controller\SearchController:searchGoto', 'dest' => '\Modules\Navigation\Controller\SearchController:searchGoto',
'verb' => 16, 'verb' => 16,
'permission' => [ 'permission' => [
'module' => 'Navigation', 'module' => 'Navigation',
'type' => 2, 'type' => 2,
], ],
], ],
], ],
'^:tag .*$' => [ '^:tag .*$' => [
0 => [ 0 => [
'dest' => '\Modules\Tasks\Controller\SearchController:searchTags', 'dest' => '\Modules\Tasks\Controller\SearchController:searchTags',
'verb' => 16, 'verb' => 16,
'permission' => [ 'permission' => [
'module' => 'Tasks', 'module' => 'Tasks',
'type' => 2, 'type' => 2,
], ],
], ],
], ],
]; ];

View File

@ -0,0 +1,107 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Search\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\DataStorage\Session\HttpSession;
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\Uri\HttpUri;
use phpOMS\Utils\TestUtils;
/**
* @testdox Modules\Search\tests\Controller\ApiControllerTest: Search api controller
*
* @internal
*/
final class ApiControllerTest extends \PHPUnit\Framework\TestCase
{
protected ApplicationAbstract $app;
/**
* @var \Modules\Search\Controller\ApiController
*/
protected ModuleAbstract $module;
/**
* {@inheritdoc}
*/
protected function setUp() : void
{
$this->app = new class() extends ApplicationAbstract
{
protected string $appName = 'Api';
};
$this->app->dbPool = $GLOBALS['dbpool'];
$this->app->orgId = 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');
$this->app->sessionManager = new HttpSession(36000);
$account = new Account();
TestUtils::setMember($account, 'id', 1);
$permission = new AccountPermission();
$permission->setUnit(1);
$permission->setApp('api');
$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('Search');
TestUtils::setMember($this->module, 'app', $this->app);
}
/**
* @covers Modules\Search\Controller\ApiController
* @group module
*/
public function testApiSearch() : void
{
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->header->account = 1;
$request->setData('search', ':help file');
$this->module->routeSearch($request, $response);
self::assertGreaterThan(0, \count($response->get('')));
}
}