mirror of
https://github.com/Karaka-Management/oms-Dashboard.git
synced 2026-02-17 10:48:40 +00:00
get overall coverage to 76%
This commit is contained in:
parent
9ac269c146
commit
35485c1b1e
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Orange Management
|
* Orange Management
|
||||||
*
|
*
|
||||||
|
|
@ -11,7 +10,6 @@
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Modules\Dashboard\Controller;
|
namespace Modules\Dashboard\Controller;
|
||||||
|
|
@ -96,7 +94,7 @@ final class ApiController extends Controller
|
||||||
{
|
{
|
||||||
$board = new DashboardBoard();
|
$board = new DashboardBoard();
|
||||||
$board->title = (string) ($request->getData('title') ?? '');
|
$board->title = (string) ($request->getData('title') ?? '');
|
||||||
$board->setAccount($request->header->account);
|
$board->account = $request->header->account;
|
||||||
$board->setStatus(DashboardBoardStatus::ACTIVE);
|
$board->setStatus(DashboardBoardStatus::ACTIVE);
|
||||||
|
|
||||||
return $board;
|
return $board;
|
||||||
|
|
@ -162,9 +160,9 @@ final class ApiController extends Controller
|
||||||
private function createComponentFromRequest(RequestAbstract $request) : DashboardComponent
|
private function createComponentFromRequest(RequestAbstract $request) : DashboardComponent
|
||||||
{
|
{
|
||||||
$component = new DashboardComponent();
|
$component = new DashboardComponent();
|
||||||
$component->setBoard((int) ($request->getData('board') ?? 0));
|
$component->board = (int) ($request->getData('board') ?? 0);
|
||||||
$component->setOrder((int) ($request->getData('order') ?? 0));
|
$component->order = (int) ($request->getData('order') ?? 0);
|
||||||
$component->setModule((string) ($request->getData('module') ?? ''));
|
$component->module = (string) ($request->getData('module') ?? '');
|
||||||
|
|
||||||
return $component;
|
return $component;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ class DashboardBoard implements \JsonSerializable
|
||||||
* @var null|int
|
* @var null|int
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected $account = null;
|
public ?int $account = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Status.
|
* Status.
|
||||||
|
|
@ -78,32 +78,6 @@ class DashboardBoard implements \JsonSerializable
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get account
|
|
||||||
*
|
|
||||||
* @return null|int
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getAccount()
|
|
||||||
{
|
|
||||||
return $this->account;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set account
|
|
||||||
*
|
|
||||||
* @param mixed $id Account
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setAccount($id) : void
|
|
||||||
{
|
|
||||||
$this->account = $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get status
|
* Get status
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ class DashboardComponent implements \JsonSerializable
|
||||||
* @var int
|
* @var int
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected int $order = 0;
|
public int $order = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Board.
|
* Board.
|
||||||
|
|
@ -46,7 +46,7 @@ class DashboardComponent implements \JsonSerializable
|
||||||
* @var int|DashboardBoard
|
* @var int|DashboardBoard
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected $board = 0;
|
public int | DashboardBoard $board = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module.
|
* Module.
|
||||||
|
|
@ -54,7 +54,7 @@ class DashboardComponent implements \JsonSerializable
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected string $module = '';
|
public string $module = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component.
|
* Component.
|
||||||
|
|
@ -62,7 +62,7 @@ class DashboardComponent implements \JsonSerializable
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected string $component = '';
|
public string $component = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get id
|
* Get id
|
||||||
|
|
@ -76,110 +76,6 @@ class DashboardComponent implements \JsonSerializable
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get order
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getOrder() : int
|
|
||||||
{
|
|
||||||
return $this->order;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set order
|
|
||||||
*
|
|
||||||
* @param int $order Order
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setOrder(int $order) : void
|
|
||||||
{
|
|
||||||
$this->order = $order;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get component
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getComponent() : string
|
|
||||||
{
|
|
||||||
return $this->component;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set component
|
|
||||||
*
|
|
||||||
* @param string $component Component
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setComponent(string $component) : void
|
|
||||||
{
|
|
||||||
$this->component = $component;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get module
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getModule() : string
|
|
||||||
{
|
|
||||||
return $this->module;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set module
|
|
||||||
*
|
|
||||||
* @param string $module Module
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setModule(string $module) : void
|
|
||||||
{
|
|
||||||
$this->module = $module;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get board
|
|
||||||
*
|
|
||||||
* @return int|DashboardBoard
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getBoard()
|
|
||||||
{
|
|
||||||
return $this->board;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set board
|
|
||||||
*
|
|
||||||
* @param mixed $id Board
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setBoard($id) : void
|
|
||||||
{
|
|
||||||
$this->board = $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
159
tests/Controller/ApiControllerTest.php
Normal file
159
tests/Controller/ApiControllerTest.php
Normal file
|
|
@ -0,0 +1,159 @@
|
||||||
|
<?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\Dashboard\tests\Controller;
|
||||||
|
|
||||||
|
use Model\CoreSettings;
|
||||||
|
use Modules\Admin\Models\AccountPermission;
|
||||||
|
use phpOMS\DataStorage\Session\HttpSession;
|
||||||
|
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\Module\ModuleAbstract;
|
||||||
|
use phpOMS\Module\ModuleManager;
|
||||||
|
use phpOMS\Router\WebRouter;
|
||||||
|
use phpOMS\Utils\TestUtils;
|
||||||
|
use phpOMS\Message\Http\HttpRequest;
|
||||||
|
use phpOMS\Message\Http\HttpResponse;
|
||||||
|
use phpOMS\Message\Http\RequestStatusCode;
|
||||||
|
use phpOMS\Uri\HttpUri;
|
||||||
|
use phpOMS\System\MimeType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @testdox Modules\Dashboard\tests\Controller\ApiControllerTest: Dashboard api controller
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
protected ApplicationAbstract $app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Modules\Dashboard\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('backend');
|
||||||
|
$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('Dashboard');
|
||||||
|
|
||||||
|
TestUtils::setMember($this->module, 'app', $this->app);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Dashboard\Controller\ApiController
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testApiBoardCreate() : void
|
||||||
|
{
|
||||||
|
$response = new HttpResponse();
|
||||||
|
$request = new HttpRequest(new HttpUri(''));
|
||||||
|
|
||||||
|
$request->header->account = 1;
|
||||||
|
$request->setData('title', 'TestBoard');
|
||||||
|
|
||||||
|
$this->module->apiBoardCreate($request, $response);
|
||||||
|
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Dashboard\Controller\ApiController
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testApiBoardCreateInvalidData() : void
|
||||||
|
{
|
||||||
|
$response = new HttpResponse();
|
||||||
|
$request = new HttpRequest(new HttpUri(''));
|
||||||
|
|
||||||
|
$request->header->account = 1;
|
||||||
|
$request->setData('invalid', '1');
|
||||||
|
|
||||||
|
$this->module->apiBoardCreate($request, $response);
|
||||||
|
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Dashboard\Controller\ApiController
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testApiComponentCreate() : void
|
||||||
|
{
|
||||||
|
$response = new HttpResponse();
|
||||||
|
$request = new HttpRequest(new HttpUri(''));
|
||||||
|
|
||||||
|
$request->header->account = 1;
|
||||||
|
$request->setData('board', '1');
|
||||||
|
$request->setData('order', '2');
|
||||||
|
$request->setData('module', 'TestModule');
|
||||||
|
|
||||||
|
$this->module->apiComponentCreate($request, $response);
|
||||||
|
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Dashboard\Controller\ApiController
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testApiComponentCreateInvalidData() : void
|
||||||
|
{
|
||||||
|
$response = new HttpResponse();
|
||||||
|
$request = new HttpRequest(new HttpUri(''));
|
||||||
|
|
||||||
|
$request->header->account = 1;
|
||||||
|
$request->setData('invalid', '1');
|
||||||
|
|
||||||
|
$this->module->apiComponentCreate($request, $response);
|
||||||
|
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||||
|
}
|
||||||
|
}
|
||||||
104
tests/Models/DashboardBoardTest.php
Normal file
104
tests/Models/DashboardBoardTest.php
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
<?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\Dashboard\tests\Models;
|
||||||
|
|
||||||
|
use Modules\Dashboard\Models\DashboardBoard;
|
||||||
|
use Modules\Dashboard\Models\DashboardComponent;
|
||||||
|
use Modules\Dashboard\Models\DashboardBoardStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class DashboardBoardTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
private DashboardBoard $board;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() : void
|
||||||
|
{
|
||||||
|
$this->board = new DashboardBoard();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Dashboard\Models\DashboardBoard
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testDefault() : void
|
||||||
|
{
|
||||||
|
self::assertEquals(0, $this->board->getId());
|
||||||
|
self::assertEquals('', $this->board->title);
|
||||||
|
self::assertEquals(null, $this->board->account);
|
||||||
|
self::assertEquals([], $this->board->getComponents());
|
||||||
|
self::assertEquals(DashboardBoardStatus::ACTIVE, $this->board->getStatus());
|
||||||
|
self::assertInstanceOf('\Modules\Dashboard\Models\NullDashboardComponent', $this->board->getComponent(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Dashboard\Models\DashboardBoard
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testStatusInputOutput() : void
|
||||||
|
{
|
||||||
|
$this->board->setStatus(DashboardBoardStatus::INACTIVE);
|
||||||
|
self::assertEquals(DashboardBoardStatus::INACTIVE, $this->board->getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Dashboard\Models\DashboardBoard
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testInvalidStatus() : void
|
||||||
|
{
|
||||||
|
$this->expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
|
||||||
|
$this->board->setStatus(999);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Dashboard\Models\DashboardBoard
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testComponentInputOutput() : void
|
||||||
|
{
|
||||||
|
$id = $this->board->addComponent($temp = new DashboardComponent());
|
||||||
|
self::assertEquals($temp, $this->board->getComponent($id));
|
||||||
|
|
||||||
|
self::assertTrue($this->board->removeComponent($id));
|
||||||
|
self::assertFalse($this->board->removeComponent($id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Dashboard\Models\DashboardBoard
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testSerialize() : void
|
||||||
|
{
|
||||||
|
$this->board->title = 'Title';
|
||||||
|
$this->board->account = 2;
|
||||||
|
$this->board->setStatus(DashboardBoardStatus::INACTIVE);
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
[
|
||||||
|
'id' => 0,
|
||||||
|
'account' => 2,
|
||||||
|
'title' => 'Title',
|
||||||
|
'status' => DashboardBoardStatus::INACTIVE,
|
||||||
|
'components' => [],
|
||||||
|
],
|
||||||
|
$this->board->jsonSerialize()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
69
tests/Models/DashboardComponentTest.php
Normal file
69
tests/Models/DashboardComponentTest.php
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?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\Dashboard\tests\Models;
|
||||||
|
|
||||||
|
use Modules\Dashboard\Models\DashboardComponent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class DashboardComponentTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
private DashboardComponent $component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() : void
|
||||||
|
{
|
||||||
|
$this->component = new DashboardComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Dashboard\Models\DashboardComponent
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testDefault() : void
|
||||||
|
{
|
||||||
|
self::assertEquals(0, $this->component->getId());
|
||||||
|
self::assertEquals(0, $this->component->order);
|
||||||
|
self::assertEquals(0, $this->component->board);
|
||||||
|
self::assertEquals('', $this->component->module);
|
||||||
|
self::assertEquals('', $this->component->component);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Dashboard\Models\DashboardComponent
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testSerialize() : void
|
||||||
|
{
|
||||||
|
$this->component->board = 3;
|
||||||
|
$this->component->order = 2;
|
||||||
|
$this->component->module = 'Test';
|
||||||
|
$this->component->component = 'Component';
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
[
|
||||||
|
'id' => 0,
|
||||||
|
'board' => 3,
|
||||||
|
'order' => 2,
|
||||||
|
'module' => 'Test',
|
||||||
|
'component' => 'Component',
|
||||||
|
],
|
||||||
|
$this->component->jsonSerialize()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user