From 1690b62a999c26acb01d6a4cc15a9510b725ce91 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 14 Mar 2020 14:15:21 +0100 Subject: [PATCH] add tests --- tests/Admin/AdminTest.php | 26 ++++ tests/ControllerTest.php | 140 ++++++++++++++++++ tests/Models/1KanbanBoardMapperTest.php | 66 +++++++++ tests/Models/3KanbanColumnMapperTest.php | 62 ++++++++ tests/Models/4KanbanCardMapperTest.php | 101 +++++++++++++ tests/Models/5KanbanCardCommentMapperTest.php | 64 ++++++++ tests/Models/KanbanBoardTest.php | 55 +++++++ tests/Models/KanbanCardCommentTest.php | 51 +++++++ tests/Models/KanbanCardTest.php | 68 +++++++++ tests/Models/KanbanColumnTest.php | 49 ++++++ 10 files changed, 682 insertions(+) create mode 100644 tests/Admin/AdminTest.php create mode 100644 tests/ControllerTest.php create mode 100644 tests/Models/1KanbanBoardMapperTest.php create mode 100644 tests/Models/3KanbanColumnMapperTest.php create mode 100644 tests/Models/4KanbanCardMapperTest.php create mode 100644 tests/Models/5KanbanCardCommentMapperTest.php create mode 100644 tests/Models/KanbanBoardTest.php create mode 100644 tests/Models/KanbanCardCommentTest.php create mode 100644 tests/Models/KanbanCardTest.php create mode 100644 tests/Models/KanbanColumnTest.php diff --git a/tests/Admin/AdminTest.php b/tests/Admin/AdminTest.php new file mode 100644 index 0000000..3c2896e --- /dev/null +++ b/tests/Admin/AdminTest.php @@ -0,0 +1,26 @@ +app = new class() extends ApplicationAbstract + { + protected string $appName = 'Api'; + }; + + $this->app->dbPool = $GLOBALS['dbpool']; + $this->app->orgId = 1; + $this->app->appName = 'Backend'; + $this->app->accountManager = new AccountManager($GLOBALS['session']); + $this->app->appSettings = new CoreSettings($this->app->dbPool->get()); + $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->getHeader()->setAccount(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']->getName()); + 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->getHeader()->setAccount(1); + $request->setData('title', 'Controller Test Column'); + $request->setData('board', 1); + + $this->module->apiKanbanColumnCreate($request, $response); + + self::assertEquals('Controller Test Column', $response->get('')['response']->getName()); + 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->getHeader()->setAccount(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']->getName()); + self::assertGreaterThan(0, $response->get('')['response']->getId()); + } +} diff --git a/tests/Models/1KanbanBoardMapperTest.php b/tests/Models/1KanbanBoardMapperTest.php new file mode 100644 index 0000000..355ac61 --- /dev/null +++ b/tests/Models/1KanbanBoardMapperTest.php @@ -0,0 +1,66 @@ +setName('Test Board 0'); + $board->setDescription('This is some description'); + $board->setCreatedBy(new NullAccount(1)); + + $id = KanbanBoardMapper::create($board); + self::assertGreaterThan(0, $board->getId()); + self::assertEquals($id, $board->getId()); + + $boardR = KanbanBoardMapper::get($board->getId()); + self::assertEquals($board->getName(), $boardR->getName()); + self::assertEquals($board->getStatus(), $boardR->getStatus()); + self::assertEquals($board->getDescription(), $boardR->getDescription()); + self::assertEquals($board->getCreatedBy()->getId(), $boardR->getCreatedBy()->getId()); + self::assertEquals($board->getCreatedAt()->format('Y-m-d'), $boardR->getCreatedAt()->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->setName($text->generateText(\mt_rand(3, 7))); + $board->setDescription($text->generateText(\mt_rand(20, 70))); + $board->setCreatedBy(new NullAccount(1)); + + $id = KanbanBoardMapper::create($board); + } + } +} diff --git a/tests/Models/3KanbanColumnMapperTest.php b/tests/Models/3KanbanColumnMapperTest.php new file mode 100644 index 0000000..3c97788 --- /dev/null +++ b/tests/Models/3KanbanColumnMapperTest.php @@ -0,0 +1,62 @@ +setName('Some Column'); + $column->setBoard(1); + $column->setOrder(1); + + $id = KanbanColumnMapper::create($column); + self::assertGreaterThan(0, $column->getId()); + self::assertEquals($id, $column->getId()); + + $columnR = KanbanColumnMapper::get($column->getId()); + self::assertEquals($column->getName(), $columnR->getName()); + self::assertEquals($column->getBoard(), $columnR->getBoard()); + self::assertEquals($column->getOrder(), $columnR->getOrder()); + } + + /** + * @group volume + * @group module + * @coversNothing + */ + public function testVolume() : void + { + for ($i = 1; $i < 4; ++$i) { + $text = new Text(); + $column = new KanbanColumn(); + + $column->setName($text->generateText(\mt_rand(3, 7))); + $column->setBoard(1); + $column->setOrder($i + 1); + + $id = KanbanColumnMapper::create($column); + } + } +} diff --git a/tests/Models/4KanbanCardMapperTest.php b/tests/Models/4KanbanCardMapperTest.php new file mode 100644 index 0000000..8378895 --- /dev/null +++ b/tests/Models/4KanbanCardMapperTest.php @@ -0,0 +1,101 @@ +setName('Some Card name'); + $card->setDescription('This is some card description'); + $card->setStatus(CardStatus::ACTIVE); + $card->setType(CardType::TEXT); + $card->setOrder(1); + $card->setColumn(1); + $card->setCreatedBy(new NullAccount(1)); + $card->addLabel(1); + $card->addLabel(2); + + $id = KanbanCardMapper::create($card); + self::assertGreaterThan(0, $card->getId()); + self::assertEquals($id, $card->getId()); + + $cardR = KanbanCardMapper::get($card->getId()); + self::assertEquals($card->getName(), $cardR->getName()); + self::assertEquals($card->getDescription(), $cardR->getDescription()); + self::assertEquals($card->getColumn(), $cardR->getColumn()); + self::assertEquals($card->getOrder(), $cardR->getOrder()); + self::assertEquals($card->getStatus(), $cardR->getStatus()); + self::assertEquals($card->getType(), $cardR->getType()); + self::assertEquals($card->getCreatedBy()->getId(), $cardR->getCreatedBy()->getId()); + self::assertEquals($card->getCreatedAt()->format('Y-m-d'), $cardR->getCreatedAt()->format('Y-m-d')); + self::assertEquals($card->getRef(), $cardR->getRef()); + } + + public function testTaskCard() : void + { + $card = new KanbanCard(); + + $card->setStatus(CardStatus::ACTIVE); + $card->setType(CardType::TASK); + $card->setRef(1); + $card->setOrder(1); + $card->setColumn(1); + $card->setCreatedBy(new NullAccount(1)); + $card->addLabel(1); + $card->addLabel(2); + + $id = KanbanCardMapper::create($card); + 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->setName($text->generateText(\mt_rand(3, 7))); + $card->setDescription($text->generateText(\mt_rand(20, 100))); + $card->setStatus(CardStatus::ACTIVE); + $card->setType(CardType::TEXT); + $card->setOrder(\mt_rand(1, 10)); + $card->setColumn(\mt_rand(1, 4)); + $card->setCreatedBy(new NullAccount(1)); + $card->addLabel(2); + $card->addLabel(3); + + $id = KanbanCardMapper::create($card); + } + } +} diff --git a/tests/Models/5KanbanCardCommentMapperTest.php b/tests/Models/5KanbanCardCommentMapperTest.php new file mode 100644 index 0000000..f109cbd --- /dev/null +++ b/tests/Models/5KanbanCardCommentMapperTest.php @@ -0,0 +1,64 @@ +setDescription('This is some card description'); + $comment->setCard(1); + $comment->setCreatedBy(new NullAccount(1)); + + $id = KanbanCardCommentMapper::create($comment); + self::assertGreaterThan(0, $comment->getId()); + self::assertEquals($id, $comment->getId()); + + $commentR = KanbanCardCommentMapper::get($comment->getId()); + self::assertEquals($comment->getDescription(), $commentR->getDescription()); + self::assertEquals($comment->getCard(), $commentR->getCard()); + self::assertEquals($comment->getCreatedBy()->getId(), $commentR->getCreatedBy()->getId()); + self::assertEquals($comment->getCreatedAt()->format('Y-m-d'), $commentR->getCreatedAt()->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->setDescription($text->generateText(\mt_rand(20, 100))); + $comment->setCard(1); + $comment->setCreatedBy(new NullAccount(1)); + + $id = KanbanCardCommentMapper::create($comment); + } + } +} diff --git a/tests/Models/KanbanBoardTest.php b/tests/Models/KanbanBoardTest.php new file mode 100644 index 0000000..70d071b --- /dev/null +++ b/tests/Models/KanbanBoardTest.php @@ -0,0 +1,55 @@ +getId()); + self::assertEquals(BoardStatus::ACTIVE, $board->getStatus()); + self::assertEquals('', $board->getName()); + self::assertEquals('', $board->getDescription()); + self::assertEquals(0, $board->getCreatedBy()->getId()); + self::assertInstanceOf('\DateTime', $board->getCreatedAt()); + self::assertEquals([], $board->getColumns()); + } + + public function testSetGet() : void + { + $board = new KanbanBoard(); + + $board->setName('Name'); + $board->setDescription('Description'); + $board->setStatus(BoardStatus::ARCHIVED); + $board->setCreatedBy(new NullAccount(1)); + $board->addColumn(2); + + self::assertEquals(BoardStatus::ARCHIVED, $board->getStatus()); + self::assertEquals('Name', $board->getName()); + self::assertEquals('Description', $board->getDescription()); + self::assertEquals(1, $board->getCreatedBy()->getId()); + self::assertEquals([2], $board->getColumns()); + } +} diff --git a/tests/Models/KanbanCardCommentTest.php b/tests/Models/KanbanCardCommentTest.php new file mode 100644 index 0000000..c885f2b --- /dev/null +++ b/tests/Models/KanbanCardCommentTest.php @@ -0,0 +1,51 @@ +getId()); + self::assertEquals(0, $comment->getCard()); + self::assertEquals('', $comment->getDescription()); + self::assertEquals(0, $comment->getCreatedBy()->getId()); + self::assertInstanceOf('\DateTime', $comment->getCreatedAt()); + self::assertEquals([], $comment->getMedia()); + } + + public function testSetGet() : void + { + $comment = new KanbanCardComment(); + + $comment->setCard(2); + $comment->setDescription('Description'); + $comment->setCreatedBy(new NullAccount(1)); + $comment->addMedia(3); + + self::assertEquals(2, $comment->getCard()); + self::assertEquals('Description', $comment->getDescription()); + self::assertEquals(1, $comment->getCreatedBy()->getId()); + self::assertEquals([3], $comment->getMedia()); + } +} diff --git a/tests/Models/KanbanCardTest.php b/tests/Models/KanbanCardTest.php new file mode 100644 index 0000000..b052f0a --- /dev/null +++ b/tests/Models/KanbanCardTest.php @@ -0,0 +1,68 @@ +getId()); + self::assertEquals(CardStatus::ACTIVE, $card->getStatus()); + self::assertEquals(CardType::TEXT, $card->getType()); + self::assertEquals('', $card->getName()); + self::assertEquals('', $card->getDescription()); + self::assertEquals(0, $card->getColumn()); + self::assertEquals(0, $card->getOrder()); + self::assertEquals(0, $card->getCreatedBy()->getId()); + self::assertInstanceOf('\DateTime', $card->getCreatedAt()); + self::assertEquals([], $card->getComments()); + self::assertEquals([], $card->getLabels()); + self::assertEquals([], $card->getMedia()); + } + + public function testSetGet() : void + { + $card = new KanbanCard(); + $card->setStatus(CardStatus::ARCHIVED); + $card->setType(CardType::TASK); + $card->setName('Name'); + $card->setDescription('Description'); + $card->setColumn(1); + $card->setOrder(2); + $card->setCreatedBy(new NullAccount(1)); + $card->addComment(5); + $card->addMedia(7); + + self::assertEquals(CardStatus::ARCHIVED, $card->getStatus()); + self::assertEquals(CardType::TASK, $card->getType()); + self::assertEquals('Name', $card->getName()); + self::assertEquals('Description', $card->getDescription()); + self::assertEquals(1, $card->getColumn()); + self::assertEquals(2, $card->getOrder()); + self::assertEquals(1, $card->getCreatedBy()->getId()); + self::assertEquals([5], $card->getComments()); + self::assertEquals([7], $card->getMedia()); + } +} diff --git a/tests/Models/KanbanColumnTest.php b/tests/Models/KanbanColumnTest.php new file mode 100644 index 0000000..053f924 --- /dev/null +++ b/tests/Models/KanbanColumnTest.php @@ -0,0 +1,49 @@ +getId()); + self::assertEquals('', $column->getName()); + self::assertEquals(0, $column->getOrder()); + self::assertEquals(0, $column->getBoard()); + self::assertEquals([], $column->getCards()); + } + + public function testSetGet() : void + { + $column = new KanbanColumn(); + + $column->setName('Name'); + $column->setOrder(2); + $column->setBoard(3); + $column->addCard(new KanbanCard()); + + self::assertEquals('Name', $column->getName()); + self::assertEquals(2, $column->getOrder()); + self::assertEquals(3, $column->getBoard()); + } +}