mirror of
https://github.com/Karaka-Management/oms-Kanban.git
synced 2026-02-14 03:08:41 +00:00
add unit tests
This commit is contained in:
parent
af4956afd3
commit
833503241f
|
|
@ -89,7 +89,7 @@ final class ApiController extends Controller
|
|||
$card->descriptionRaw = (string) ($request->getData('plain') ?? '');
|
||||
$card->description = Markdown::parse((string) ($request->getData('plain') ?? ''));
|
||||
$card->style = (string) ($request->getData('style') ?? '');
|
||||
$card->setColumn((int) $request->getData('column'));
|
||||
$card->column = (int) $request->getData('column');
|
||||
$card->order = (int) ($request->getData('order') ?? 1);
|
||||
$card->ref = (int) ($request->getData('ref') ?? 0);
|
||||
$card->setStatus((int) ($request->getData('status') ?? CardStatus::ACTIVE));
|
||||
|
|
@ -207,7 +207,7 @@ final class ApiController extends Controller
|
|||
$comment = new KanbanCardComment();
|
||||
$comment->description = Markdown::parse((string) ($request->getData('plain') ?? ''));
|
||||
$comment->descriptionRaw = (string) ($request->getData('plain') ?? '');
|
||||
$comment->setCard((int) $request->getData('card'));
|
||||
$comment->card = (int) $request->getData('card');
|
||||
$comment->createdBy = new NullAccount($request->header->account);
|
||||
|
||||
if (!empty($uploadedFiles = $request->getFiles() ?? [])) {
|
||||
|
|
@ -423,7 +423,7 @@ final class ApiController extends Controller
|
|||
{
|
||||
$column = new KanbanColumn();
|
||||
$column->name = (string) $request->getData('title');
|
||||
$column->setBoard((int) $request->getData('board'));
|
||||
$column->board = (int) $request->getData('board');
|
||||
$column->order = (int) ($request->getData('order') ?? 1);
|
||||
|
||||
return $column;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ namespace Modules\Kanban\Models;
|
|||
use Modules\Admin\Models\Account;
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Tag\Models\Tag;
|
||||
use Modules\Tag\Models\NullTag;
|
||||
|
||||
/**
|
||||
* Kanban board class.
|
||||
|
|
@ -191,6 +192,20 @@ class KanbanBoard implements \JsonSerializable
|
|||
$this->tags[] = $tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task elements.
|
||||
*
|
||||
* @param int $id Element id
|
||||
*
|
||||
* @return Tag
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getTag(int $id) : Tag
|
||||
{
|
||||
return $this->tags[$id] ?? new NullTag();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the columns
|
||||
*
|
||||
|
|
@ -240,8 +255,21 @@ class KanbanBoard implements \JsonSerializable
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : array
|
||||
public function toArray() : array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'status' => $this->status,
|
||||
'columns' => $this->columns,
|
||||
'tags' => $this->tags,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ use Modules\Admin\Models\Account;
|
|||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Media\Models\Media;
|
||||
use Modules\Tag\Models\Tag;
|
||||
use Modules\Tag\Models\NullTag;
|
||||
use Modules\Tasks\Models\Task;
|
||||
|
||||
/**
|
||||
|
|
@ -108,7 +109,7 @@ class KanbanCard implements \JsonSerializable
|
|||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private int $column = 0;
|
||||
public int $column = 0;
|
||||
|
||||
/**
|
||||
* Card order/position.
|
||||
|
|
@ -183,32 +184,6 @@ class KanbanCard implements \JsonSerializable
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the column
|
||||
*
|
||||
* @param int $id Id
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setColumn(int $id) : void
|
||||
{
|
||||
$this->column = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the column
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getColumn() : int
|
||||
{
|
||||
return $this->column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status
|
||||
*
|
||||
|
|
@ -355,6 +330,20 @@ class KanbanCard implements \JsonSerializable
|
|||
return $this->tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task elements.
|
||||
*
|
||||
* @param int $id Element id
|
||||
*
|
||||
* @return Tag
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getTag(int $id) : Tag
|
||||
{
|
||||
return $this->tags[$id] ?? new NullTag();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add tag
|
||||
*
|
||||
|
|
@ -372,23 +361,33 @@ class KanbanCard implements \JsonSerializable
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : array
|
||||
public function toArray() : array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->name,
|
||||
'description' => $this->description,
|
||||
'descriptionRaw' => $this->descriptionRaw,
|
||||
'status' => $this->status,
|
||||
'type' => $this->type,
|
||||
'column' => $this->name,
|
||||
'order' => $this->name,
|
||||
'ref' => $this->name,
|
||||
'createdBy' => $this->name,
|
||||
'createdAt' => $this->name,
|
||||
'comments' => $this->name,
|
||||
'media' => $this->name,
|
||||
'column' => $this->column,
|
||||
'order' => $this->order,
|
||||
'ref' => $this->ref,
|
||||
'createdBy' => $this->createdBy,
|
||||
'createdAt' => $this->createdAt,
|
||||
'comments' => $this->comments,
|
||||
'media' => $this->media,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a task from a card
|
||||
*
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class KanbanCardComment implements \JsonSerializable
|
|||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private int $card = 0;
|
||||
public int $card = 0;
|
||||
|
||||
/**
|
||||
* Created by.
|
||||
|
|
@ -106,32 +106,6 @@ class KanbanCardComment implements \JsonSerializable
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the card
|
||||
*
|
||||
* @param int $id Card id
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setCard(int $id) : void
|
||||
{
|
||||
$this->card = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the card
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getCard() : int
|
||||
{
|
||||
return $this->card;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the media files
|
||||
*
|
||||
|
|
@ -161,8 +135,24 @@ class KanbanCardComment implements \JsonSerializable
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : array
|
||||
public function toArray() : array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'description' => $this->description,
|
||||
'descriptionRaw' => $this->descriptionRaw,
|
||||
'card' => $this->card,
|
||||
'createdBy' => $this->createdBy,
|
||||
'createdAt' => $this->createdAt,
|
||||
'media' => $this->media,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class KanbanColumn implements \JsonSerializable
|
|||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private int $board = 0;
|
||||
public int $board = 0;
|
||||
|
||||
/**
|
||||
* Cards.
|
||||
|
|
@ -76,32 +76,6 @@ class KanbanColumn implements \JsonSerializable
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the board this column belongs to
|
||||
*
|
||||
* @param int $board Board
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setBoard(int $board) : void
|
||||
{
|
||||
$this->board = $board;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the board this column belongs to
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getBoard() : int
|
||||
{
|
||||
return $this->board;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cards
|
||||
*
|
||||
|
|
@ -151,8 +125,22 @@ class KanbanColumn implements \JsonSerializable
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : array
|
||||
public function toArray() : array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'order' => $this->order,
|
||||
'board' => $this->board,
|
||||
'cards' => $this->cards,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ final class NullKanbanBoard extends KanbanBoard
|
|||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->id = $id;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
39
Models/NullKanbanCard.php
Normal file
39
Models/NullKanbanCard.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Modules\Kanban\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Kanban\Models;
|
||||
|
||||
/**
|
||||
* Null model
|
||||
*
|
||||
* @package Modules\Kanban\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class NullKanbanCard extends KanbanCard
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->id = $id;
|
||||
}
|
||||
}
|
||||
39
Models/NullKanbanCardComment.php
Normal file
39
Models/NullKanbanCardComment.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Modules\Kanban\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Kanban\Models;
|
||||
|
||||
/**
|
||||
* Null model
|
||||
*
|
||||
* @package Modules\Kanban\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class NullKanbanCardComment extends KanbanCardComment
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->id = $id;
|
||||
}
|
||||
}
|
||||
38
Models/NullKanbanColumn.php
Normal file
38
Models/NullKanbanColumn.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Modules\Kanban\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Kanban\Models;
|
||||
|
||||
/**
|
||||
* Null model
|
||||
*
|
||||
* @package Modules\Kanban\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class NullKanbanColumn extends KanbanColumn
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
}
|
||||
273
tests/Controller/ApiControllerTest.php
Normal file
273
tests/Controller/ApiControllerTest.php
Normal file
|
|
@ -0,0 +1,273 @@
|
|||
<?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\Kanban\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\ModuleManager;
|
||||
use phpOMS\Router\WebRouter;
|
||||
use phpOMS\Uri\HttpUri;
|
||||
use phpOMS\Utils\TestUtils;
|
||||
use phpOMS\Module\ModuleAbstract;
|
||||
use phpOMS\System\MimeType;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected ApplicationAbstract $app;
|
||||
|
||||
/**
|
||||
* @var \Modules\Comments\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');
|
||||
|
||||
$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('Kanban');
|
||||
|
||||
TestUtils::setMember($this->module, 'app', $this->app);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiBoardCU() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('title', 'Controller Test Board');
|
||||
$request->setData('plain', 'Controller Test Description');
|
||||
$request->setData('tags', '[{"title": "TestTitle", "color": "#f0f", "language": "en"}, {"id": 1}]');
|
||||
|
||||
$this->module->apiKanbanBoardCreate($request, $response);
|
||||
|
||||
self::assertEquals('Controller Test Board', $response->get('')['response']->name);
|
||||
self::assertGreaterThan(0, $bId = $response->get('')['response']->getId());
|
||||
|
||||
// update
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('id', $bId);
|
||||
$request->setData('title', 'New Controller Test Board');
|
||||
|
||||
$this->module->apiKanbanBoardUpdate($request, $response);
|
||||
self::assertEquals('New Controller Test Board', $response->get('')['response']->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testCreateColumn() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('title', 'Controller Test Column');
|
||||
$request->setData('board', 1);
|
||||
|
||||
$this->module->apiKanbanColumnCreate($request, $response);
|
||||
|
||||
self::assertEquals('Controller Test Column', $response->get('')['response']->name);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testCreateCard() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('title', 'Controller Test Card');
|
||||
$request->setData('plain', 'Controller Test Description');
|
||||
$request->setData('column', '1');
|
||||
$request->setData('tags', '[{"title": "TestTitle", "color": "#f0f", "language": "en"}, {"id": 1}]');
|
||||
|
||||
if (!\is_file(__DIR__ . '/test_tmp.md')) {
|
||||
\copy(__DIR__ . '/test.md', __DIR__ . '/test_tmp.md');
|
||||
}
|
||||
|
||||
TestUtils::setMember($request, 'files', [
|
||||
'file1' => [
|
||||
'name' => 'test.md',
|
||||
'type' => MimeType::M_TXT,
|
||||
'tmp_name' => __DIR__ . '/test_tmp.md',
|
||||
'error' => \UPLOAD_ERR_OK,
|
||||
'size' => \filesize(__DIR__ . '/test_tmp.md'),
|
||||
],
|
||||
]);
|
||||
|
||||
$request->setData('media', \json_encode([1]));
|
||||
|
||||
$this->module->apiKanbanCardCreate($request, $response);
|
||||
|
||||
self::assertEquals('Controller Test Card', $response->get('')['response']->name);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testCreateCommentCard() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('plain', 'Controller Test Description');
|
||||
$request->setData('card', '1');
|
||||
|
||||
if (!\is_file(__DIR__ . '/test_tmp.md')) {
|
||||
\copy(__DIR__ . '/test.md', __DIR__ . '/test_tmp.md');
|
||||
}
|
||||
|
||||
TestUtils::setMember($request, 'files', [
|
||||
'file1' => [
|
||||
'name' => 'test.md',
|
||||
'type' => MimeType::M_TXT,
|
||||
'tmp_name' => __DIR__ . '/test_tmp.md',
|
||||
'error' => \UPLOAD_ERR_OK,
|
||||
'size' => \filesize(__DIR__ . '/test_tmp.md'),
|
||||
],
|
||||
]);
|
||||
|
||||
$request->setData('media', \json_encode([1]));
|
||||
|
||||
$this->module->apiKanbanCardCommentCreate($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiKanbanBoardCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiKanbanBoardCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiKanbanColumnCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiKanbanColumnCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiKanbanCardCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiKanbanCardCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiKanbanCardCommentCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiKanbanCardCommentCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
}
|
||||
3
tests/Controller/test.md
Normal file
3
tests/Controller/test.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Test Title
|
||||
|
||||
Some **test** text.
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
<?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\Kanban\tests;
|
||||
|
||||
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\ModuleManager;
|
||||
use phpOMS\Router\WebRouter;
|
||||
use phpOMS\Uri\HttpUri;
|
||||
use phpOMS\Utils\TestUtils;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class ControllerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $app = null;
|
||||
|
||||
protected $module = null;
|
||||
|
||||
/**
|
||||
* {@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');
|
||||
|
||||
$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('Kanban');
|
||||
|
||||
TestUtils::setMember($this->module, 'app', $this->app);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testCreateBoard() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('title', 'Controller Test Board');
|
||||
$request->setData('plain', 'Controller Test Description');
|
||||
|
||||
$this->module->apiKanbanBoardCreate($request, $response);
|
||||
|
||||
self::assertEquals('Controller Test Board', $response->get('')['response']->name);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testCreateColumn() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('title', 'Controller Test Column');
|
||||
$request->setData('board', 1);
|
||||
|
||||
$this->module->apiKanbanColumnCreate($request, $response);
|
||||
|
||||
self::assertEquals('Controller Test Column', $response->get('')['response']->name);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testCreateCard() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('title', 'Controller Test Card');
|
||||
$request->setData('plain', 'Controller Test Description');
|
||||
$request->setData('column', '1');
|
||||
|
||||
$this->module->apiKanbanCardCreate($request, $response);
|
||||
|
||||
self::assertEquals('Controller Test Card', $response->get('')['response']->name);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
}
|
||||
|
|
@ -48,23 +48,4 @@ final class KanbanBoardMapperTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($board->createdAt->format('Y-m-d'), $boardR->createdAt->format('Y-m-d'));
|
||||
self::assertEquals($board->getColumns(), $boardR->getColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group volume
|
||||
* @group module
|
||||
* @coversNothing
|
||||
*/
|
||||
public function testVolume() : void
|
||||
{
|
||||
for ($i = 1; $i < 30; ++$i) {
|
||||
$text = new Text();
|
||||
$board = new KanbanBoard();
|
||||
|
||||
$board->name = $text->generateText(\mt_rand(3, 7));
|
||||
$board->description = $text->generateText(\mt_rand(20, 70));
|
||||
$board->createdBy = new NullAccount(1);
|
||||
|
||||
$id = KanbanBoardMapper::create($board);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ final class KanbanColumnMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$column = new KanbanColumn();
|
||||
|
||||
$column->name = 'Some Column';
|
||||
$column->setBoard(1);
|
||||
$column->board = 1;
|
||||
$column->order = 1;
|
||||
|
||||
$id = KanbanColumnMapper::create($column);
|
||||
|
|
@ -41,26 +41,7 @@ final class KanbanColumnMapperTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$columnR = KanbanColumnMapper::get($column->getId());
|
||||
self::assertEquals($column->name, $columnR->name);
|
||||
self::assertEquals($column->getBoard(), $columnR->getBoard());
|
||||
self::assertEquals($column->board, $columnR->board);
|
||||
self::assertEquals($column->order, $columnR->order);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group volume
|
||||
* @group module
|
||||
* @coversNothing
|
||||
*/
|
||||
public function testVolume() : void
|
||||
{
|
||||
for ($i = 1; $i < 4; ++$i) {
|
||||
$text = new Text();
|
||||
$column = new KanbanColumn();
|
||||
|
||||
$column->name = $text->generateText(\mt_rand(3, 7));
|
||||
$column->setBoard(1);
|
||||
$column->order = $i + 1;
|
||||
|
||||
$id = KanbanColumnMapper::create($column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ final class KanbanCardMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$card->setStatus(CardStatus::ACTIVE);
|
||||
$card->setType(CardType::TEXT);
|
||||
$card->order = 1;
|
||||
$card->setColumn(1);
|
||||
$card->column = 1;
|
||||
$card->createdBy = new NullAccount(1);
|
||||
$card->addTag(new Tag());
|
||||
$card->addTag(new Tag());
|
||||
|
|
@ -53,7 +53,7 @@ final class KanbanCardMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$cardR = KanbanCardMapper::get($card->getId());
|
||||
self::assertEquals($card->name, $cardR->name);
|
||||
self::assertEquals($card->description, $cardR->description);
|
||||
self::assertEquals($card->getColumn(), $cardR->getColumn());
|
||||
self::assertEquals($card->column, $cardR->column);
|
||||
self::assertEquals($card->order, $cardR->order);
|
||||
self::assertEquals($card->getStatus(), $cardR->getStatus());
|
||||
self::assertEquals($card->getType(), $cardR->getType());
|
||||
|
|
@ -74,7 +74,7 @@ final class KanbanCardMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$card->setType(CardType::TASK);
|
||||
$card->ref = 1;
|
||||
$card->order = 1;
|
||||
$card->setColumn(1);
|
||||
$card->column = 1;
|
||||
$card->createdBy = new NullAccount(1);
|
||||
$card->addTag(new Tag());
|
||||
$card->addTag(new Tag());
|
||||
|
|
@ -83,29 +83,4 @@ final class KanbanCardMapperTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertGreaterThan(0, $card->getId());
|
||||
self::assertEquals($id, $card->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group volume
|
||||
* @group module
|
||||
* @coversNothing
|
||||
*/
|
||||
public function testVolume() : void
|
||||
{
|
||||
for ($i = 1; $i < 10; ++$i) {
|
||||
$text = new Text();
|
||||
$card = new KanbanCard();
|
||||
|
||||
$card->name = $text->generateText(\mt_rand(3, 7));
|
||||
$card->description = $text->generateText(\mt_rand(20, 100));
|
||||
$card->setStatus(CardStatus::ACTIVE);
|
||||
$card->setType(CardType::TEXT);
|
||||
$card->order = \mt_rand(1, 10);
|
||||
$card->setColumn(\mt_rand(1, 4));
|
||||
$card->createdBy = new NullAccount(1);
|
||||
$card->addTag(new NullTag(1));
|
||||
$card->addTag(new NullTag(2));
|
||||
|
||||
$id = KanbanCardMapper::create($card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ final class KanbanCardCommentMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$comment = new KanbanCardComment();
|
||||
|
||||
$comment->description = 'This is some card description';
|
||||
$comment->setCard(1);
|
||||
$comment->card = 1;
|
||||
$comment->createdBy = new NullAccount(1);
|
||||
|
||||
$id = KanbanCardCommentMapper::create($comment);
|
||||
|
|
@ -42,27 +42,8 @@ final class KanbanCardCommentMapperTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$commentR = KanbanCardCommentMapper::get($comment->getId());
|
||||
self::assertEquals($comment->description, $commentR->description);
|
||||
self::assertEquals($comment->getCard(), $commentR->getCard());
|
||||
self::assertEquals($comment->card, $commentR->card);
|
||||
self::assertEquals($comment->createdBy->getId(), $commentR->createdBy->getId());
|
||||
self::assertEquals($comment->createdAt->format('Y-m-d'), $commentR->createdAt->format('Y-m-d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group volume
|
||||
* @group module
|
||||
* @coversNothing
|
||||
*/
|
||||
public function testVolume() : void
|
||||
{
|
||||
for ($i = 1; $i < 10; ++$i) {
|
||||
$text = new Text();
|
||||
$comment = new KanbanCardComment();
|
||||
|
||||
$comment->description = $text->generateText(\mt_rand(20, 100));
|
||||
$comment->setCard(1);
|
||||
$comment->createdBy = new NullAccount(1);
|
||||
|
||||
$id = KanbanCardCommentMapper::create($comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,47 +17,102 @@ namespace Modules\Kanban\tests\Models;
|
|||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Kanban\Models\BoardStatus;
|
||||
use Modules\Kanban\Models\KanbanBoard;
|
||||
use Modules\Tag\Models\Tag;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class KanbanBoardTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private KanbanBoard $board;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->board = new KanbanBoard();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanBoard
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$board = new KanbanBoard();
|
||||
|
||||
self::assertEquals(0, $board->getId());
|
||||
self::assertEquals(BoardStatus::ACTIVE, $board->getStatus());
|
||||
self::assertEquals('', $board->name);
|
||||
self::assertEquals('', $board->description);
|
||||
self::assertEquals(0, $board->createdBy->getId());
|
||||
self::assertInstanceOf('\DateTimeImmutable', $board->createdAt);
|
||||
self::assertEquals([], $board->getColumns());
|
||||
self::assertEquals(0, $this->board->getId());
|
||||
self::assertEquals(BoardStatus::ACTIVE, $this->board->getStatus());
|
||||
self::assertEquals('', $this->board->name);
|
||||
self::assertEquals('', $this->board->description);
|
||||
self::assertEquals(0, $this->board->createdBy->getId());
|
||||
self::assertInstanceOf('\DateTimeImmutable', $this->board->createdAt);
|
||||
self::assertEquals([], $this->board->getColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanBoard
|
||||
* @group module
|
||||
*/
|
||||
public function testSetGet() : void
|
||||
public function testStatusInputOutput() : void
|
||||
{
|
||||
$board = new KanbanBoard();
|
||||
$this->board->setStatus(BoardStatus::ARCHIVED);
|
||||
self::assertEquals(BoardStatus::ARCHIVED, $this->board->getStatus());
|
||||
}
|
||||
|
||||
$board->name = 'Name';
|
||||
$board->description = 'Description';
|
||||
$board->setStatus(BoardStatus::ARCHIVED);
|
||||
$board->createdBy = new NullAccount(1);
|
||||
$board->addColumn(2);
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanBoard
|
||||
* @group module
|
||||
*/
|
||||
public function testColumnsInputOutput() : void
|
||||
{
|
||||
$this->board->addColumn(2);
|
||||
self::assertEquals([2], $this->board->getColumns());
|
||||
}
|
||||
|
||||
self::assertEquals(BoardStatus::ARCHIVED, $board->getStatus());
|
||||
self::assertEquals('Name', $board->name);
|
||||
self::assertEquals('Description', $board->description);
|
||||
self::assertEquals(1, $board->createdBy->getId());
|
||||
self::assertEquals([2], $board->getColumns());
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanBoard
|
||||
* @group module
|
||||
*/
|
||||
public function testColumnRemove() : void
|
||||
{
|
||||
$this->board->addColumn(2);
|
||||
self::assertTrue($this->board->removeColumn(0));
|
||||
self::assertCount(0, $this->board->getColumns());
|
||||
self::assertFalse($this->board->removeColumn(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanBoard
|
||||
* @group module
|
||||
*/
|
||||
public function testTagInputOutput() : void
|
||||
{
|
||||
$tag = new Tag();
|
||||
$tag->setL11n('Tag');
|
||||
|
||||
$this->board->addTag($tag);
|
||||
self::assertEquals($tag, $this->board->getTag(0));
|
||||
self::assertCount(1, $this->board->getTags());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanBoard
|
||||
* @group module
|
||||
*/
|
||||
public function testSerialize() : void
|
||||
{
|
||||
$this->board->setStatus(BoardStatus::ARCHIVED);
|
||||
|
||||
$serialized = $this->board->jsonSerialize();
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
'id' => 0,
|
||||
'status' => BoardStatus::ARCHIVED,
|
||||
'columns' => [],
|
||||
'tags' => [],
|
||||
],
|
||||
$serialized
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,44 +16,70 @@ namespace Modules\Kanban\tests\Models;
|
|||
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Kanban\Models\KanbanCardComment;
|
||||
use Modules\Media\Models\NullMedia;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class KanbanCardCommentTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private KanbanCardComment $comment;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->comment = new KanbanCardComment();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanCardComment
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$comment = new KanbanCardComment();
|
||||
|
||||
self::assertEquals(0, $comment->getId());
|
||||
self::assertEquals(0, $comment->getCard());
|
||||
self::assertEquals('', $comment->description);
|
||||
self::assertEquals(0, $comment->createdBy->getId());
|
||||
self::assertInstanceOf('\DateTimeImmutable', $comment->createdAt);
|
||||
self::assertEquals([], $comment->getMedia());
|
||||
self::assertEquals(0, $this->comment->getId());
|
||||
self::assertEquals(0, $this->comment->card);
|
||||
self::assertEquals('', $this->comment->description);
|
||||
self::assertEquals(0, $this->comment->createdBy->getId());
|
||||
self::assertInstanceOf('\DateTimeImmutable', $this->comment->createdAt);
|
||||
self::assertEquals([], $this->comment->getMedia());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanCardComment
|
||||
* @group module
|
||||
*/
|
||||
public function testSetGet() : void
|
||||
public function testMediaInputOutput() : void
|
||||
{
|
||||
$comment = new KanbanCardComment();
|
||||
$this->comment->addMedia($m = new NullMedia(7));
|
||||
self::assertCount(1, $this->comment->getMedia());
|
||||
}
|
||||
|
||||
$comment->setCard(2);
|
||||
$comment->description = 'Description';
|
||||
$comment->createdBy = new NullAccount(1);
|
||||
$comment->addMedia(3);
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanCardComment
|
||||
* @group module
|
||||
*/
|
||||
public function testSerialize() : void
|
||||
{
|
||||
$this->comment->description = 'Description';
|
||||
$this->comment->descriptionRaw = 'DescriptionRaw';
|
||||
$this->comment->card = 2;
|
||||
|
||||
self::assertEquals(2, $comment->getCard());
|
||||
self::assertEquals('Description', $comment->description);
|
||||
self::assertEquals(1, $comment->createdBy->getId());
|
||||
self::assertEquals([3], $comment->getMedia());
|
||||
$serialized = $this->comment->jsonSerialize();
|
||||
unset($serialized['createdBy']);
|
||||
unset($serialized['createdAt']);
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
'id' => 0,
|
||||
'description' => 'Description',
|
||||
'descriptionRaw' => 'DescriptionRaw',
|
||||
'card' => 2,
|
||||
'media' => [],
|
||||
],
|
||||
$serialized
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,59 +19,164 @@ use Modules\Kanban\Models\CardStatus;
|
|||
use Modules\Kanban\Models\CardType;
|
||||
use Modules\Kanban\Models\KanbanCard;
|
||||
use Modules\Media\Models\NullMedia;
|
||||
use Modules\Tasks\Models\Task;
|
||||
use Modules\Tag\Models\Tag;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class KanbanCardTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private KanbanCard $card;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->card = new KanbanCard();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanCard
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$card = new KanbanCard();
|
||||
|
||||
self::assertEquals(0, $card->getId());
|
||||
self::assertEquals(CardStatus::ACTIVE, $card->getStatus());
|
||||
self::assertEquals(CardType::TEXT, $card->getType());
|
||||
self::assertEquals('', $card->name);
|
||||
self::assertEquals('', $card->description);
|
||||
self::assertEquals(0, $card->getColumn());
|
||||
self::assertEquals(0, $card->order);
|
||||
self::assertEquals(0, $card->createdBy->getId());
|
||||
self::assertInstanceOf('\DateTimeImmutable', $card->createdAt);
|
||||
self::assertEquals([], $card->getComments());
|
||||
self::assertEquals([], $card->getTags());
|
||||
self::assertEquals([], $card->getMedia());
|
||||
self::assertEquals(0, $this->card->getId());
|
||||
self::assertEquals(CardStatus::ACTIVE, $this->card->getStatus());
|
||||
self::assertEquals(CardType::TEXT, $this->card->getType());
|
||||
self::assertEquals('', $this->card->name);
|
||||
self::assertEquals('', $this->card->description);
|
||||
self::assertEquals(0, $this->card->column);
|
||||
self::assertEquals(0, $this->card->order);
|
||||
self::assertEquals(0, $this->card->createdBy->getId());
|
||||
self::assertInstanceOf('\DateTimeImmutable', $this->card->createdAt);
|
||||
self::assertEquals([], $this->card->getComments());
|
||||
self::assertEquals([], $this->card->getTags());
|
||||
self::assertEquals([], $this->card->getMedia());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanCard
|
||||
* @group module
|
||||
*/
|
||||
public function testSetGet() : void
|
||||
public function testStatusInputOutput() : void
|
||||
{
|
||||
$card = new KanbanCard();
|
||||
$card->setStatus(CardStatus::ARCHIVED);
|
||||
$card->setType(CardType::TASK);
|
||||
$card->name = 'Name';
|
||||
$card->description = 'Description';
|
||||
$card->setColumn(1);
|
||||
$card->order = 2;
|
||||
$card->createdBy = new NullAccount(1);
|
||||
$card->addComment(5);
|
||||
$card->addMedia($m = new NullMedia(7));
|
||||
$this->card->setStatus(CardStatus::ARCHIVED);
|
||||
self::assertEquals(CardStatus::ARCHIVED, $this->card->getStatus());
|
||||
}
|
||||
|
||||
self::assertEquals(CardStatus::ARCHIVED, $card->getStatus());
|
||||
self::assertEquals(CardType::TASK, $card->getType());
|
||||
self::assertEquals('Name', $card->name);
|
||||
self::assertEquals('Description', $card->description);
|
||||
self::assertEquals(1, $card->getColumn());
|
||||
self::assertEquals(2, $card->order);
|
||||
self::assertEquals(1, $card->createdBy->getId());
|
||||
self::assertEquals([5], $card->getComments());
|
||||
self::assertEquals([$m], $card->getMedia());
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanCard
|
||||
* @group module
|
||||
*/
|
||||
public function testTypeInputOutput() : void
|
||||
{
|
||||
$this->card->setType(CardType::TASK);
|
||||
self::assertEquals(CardType::TASK, $this->card->getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanCard
|
||||
* @group module
|
||||
*/
|
||||
public function testColumnInputOutput() : void
|
||||
{
|
||||
$this->card->column = 1;
|
||||
self::assertEquals(1, $this->card->column);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanCard
|
||||
* @group module
|
||||
*/
|
||||
public function testMediaInputOutput() : void
|
||||
{
|
||||
$this->card->addMedia($m = new NullMedia(7));
|
||||
self::assertCount(1, $this->card->getMedia());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanCard
|
||||
* @group module
|
||||
*/
|
||||
public function testCommentInputOutput() : void
|
||||
{
|
||||
$this->card->addComment(5);
|
||||
self::assertEquals([5], $this->card->getComments());
|
||||
self::assertEquals(1, $this->card->getCommentCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanCard
|
||||
* @group module
|
||||
*/
|
||||
public function testTagInputOutput() : void
|
||||
{
|
||||
$tag = new Tag();
|
||||
$tag->setL11n('Tag');
|
||||
|
||||
$this->card->addTag($tag);
|
||||
self::assertEquals($tag, $this->card->getTag(0));
|
||||
self::assertCount(1, $this->card->getTags());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanCard
|
||||
* @group module
|
||||
*/
|
||||
public function testCommentRemove() : void
|
||||
{
|
||||
$this->card->addComment(5);
|
||||
self::assertCount(1, $this->card->getComments());
|
||||
self::assertTrue($this->card->removeComment(0));
|
||||
self::assertCount(0, $this->card->getComments());
|
||||
self::assertFalse($this->card->removeComment(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanCard
|
||||
* @group module
|
||||
*/
|
||||
public function testCreateFromTask() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\Kanban\Models\KanbanCard', $this->card->createFromTask(new Task()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanCard
|
||||
* @group module
|
||||
*/
|
||||
public function testSerialize() : void
|
||||
{
|
||||
$this->card->name = 'Title';
|
||||
$this->card->description = 'Description';
|
||||
$this->card->descriptionRaw = 'DescriptionRaw';
|
||||
$this->card->order = 3;
|
||||
$this->card->column = 2;
|
||||
$this->card->setStatus(CardStatus::ARCHIVED);
|
||||
$this->card->setType(CardType::TASK);
|
||||
|
||||
$serialized = $this->card->jsonSerialize();
|
||||
unset($serialized['createdBy']);
|
||||
unset($serialized['createdAt']);
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
'id' => 0,
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
'descriptionRaw' => 'DescriptionRaw',
|
||||
'status' => CardStatus::ARCHIVED,
|
||||
'type' => CardType::TASK,
|
||||
'column' => 2,
|
||||
'order' => 3,
|
||||
'ref' => 0,
|
||||
'comments' => [],
|
||||
'media' => [],
|
||||
],
|
||||
$serialized
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,36 +22,75 @@ use Modules\Kanban\Models\KanbanColumn;
|
|||
*/
|
||||
final class KanbanColumnTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private KanbanColumn $column;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->column = new KanbanColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanColumn
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$column = new KanbanColumn();
|
||||
|
||||
self::assertEquals(0, $column->getId());
|
||||
self::assertEquals('', $column->name);
|
||||
self::assertEquals(0, $column->order);
|
||||
self::assertEquals(0, $column->getBoard());
|
||||
self::assertEquals([], $column->getCards());
|
||||
self::assertEquals(0, $this->column->getId());
|
||||
self::assertEquals('', $this->column->name);
|
||||
self::assertEquals(0, $this->column->order);
|
||||
self::assertEquals(0, $this->column->board);
|
||||
self::assertEquals([], $this->column->getCards());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanColumn
|
||||
* @group module
|
||||
*/
|
||||
public function testSetGet() : void
|
||||
public function testCardInputOutput() : void
|
||||
{
|
||||
$column = new KanbanColumn();
|
||||
$this->column->addCard(new KanbanCard());
|
||||
self::assertCount(1, $this->column->getCards());
|
||||
}
|
||||
|
||||
$column->name = 'Name';
|
||||
$column->order = 2;
|
||||
$column->setBoard(3);
|
||||
$column->addCard(new KanbanCard());
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanColumn
|
||||
* @group module
|
||||
*/
|
||||
public function testCardRemove() : void
|
||||
{
|
||||
$this->column->addCard(new KanbanCard());
|
||||
self::assertCount(1, $this->column->getCards());
|
||||
self::assertTrue($this->column->removeCard(0));
|
||||
self::assertCount(0, $this->column->getCards());
|
||||
self::assertFalse($this->column->removeCard(0));
|
||||
}
|
||||
|
||||
self::assertEquals('Name', $column->name);
|
||||
self::assertEquals(2, $column->order);
|
||||
self::assertEquals(3, $column->getBoard());
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\KanbanColumn
|
||||
* @group module
|
||||
*/
|
||||
public function testSerialize() : void
|
||||
{
|
||||
$this->column->name = 'Name';
|
||||
$this->column->board = 2;
|
||||
$this->column->order = 3;
|
||||
|
||||
$serialized = $this->column->jsonSerialize();
|
||||
unset($serialized['createdBy']);
|
||||
unset($serialized['createdAt']);
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
'id' => 0,
|
||||
'name' => 'Name',
|
||||
'order' => 3,
|
||||
'board' => 2,
|
||||
'cards' => [],
|
||||
],
|
||||
$serialized
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
42
tests/Models/NullKanbanCardCommentTest.php
Normal file
42
tests/Models/NullKanbanCardCommentTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?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\Kanban\tests\Models;
|
||||
|
||||
use Modules\Kanban\Models\NullKanbanCardComment;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullKanbanCardCommentTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\NullKanbanCardComment
|
||||
* @group framework
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\Kanban\Models\KanbanCardComment', new NullKanbanCardComment());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\NullKanbanCardComment
|
||||
* @group framework
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullKanbanCardComment(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
42
tests/Models/NullKanbanCardTest.php
Normal file
42
tests/Models/NullKanbanCardTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?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\Kanban\tests\Models;
|
||||
|
||||
use Modules\Kanban\Models\NullKanbanCard;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullKanbanCardTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\NullKanbanCard
|
||||
* @group framework
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\Kanban\Models\KanbanCard', new NullKanbanCard());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\NullKanbanCard
|
||||
* @group framework
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullKanbanCard(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
42
tests/Models/NullKanbanColumnTest.php
Normal file
42
tests/Models/NullKanbanColumnTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?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\Kanban\tests\Models;
|
||||
|
||||
use Modules\Kanban\Models\NullKanbanColumn;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullKanbanColumnTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\NullKanbanColumn
|
||||
* @group framework
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\Kanban\Models\KanbanColumn', new NullKanbanColumn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Kanban\Models\NullKanbanColumn
|
||||
* @group framework
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullKanbanColumn(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="Bootstrap.php" colors="true" stopOnError="true" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" beStrictAboutTestsThatDoNotTestAnything="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="Bootstrap.php" colors="true" columns="120" stopOnError="true" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" beStrictAboutTestsThatDoNotTestAnything="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<coverage includeUncoveredFiles="true" processUncoveredFiles="false">
|
||||
<exclude>
|
||||
<directory>*vendor*</directory>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user