From c85cf943885997274bea26982195c9f9237d1de8 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 14 Mar 2020 14:16:42 +0100 Subject: [PATCH] add tests --- tests/Admin/AdminTest.php | 26 +++ tests/BackendControllerTest.php | 92 ++++++++++ tests/ControllerTest.php | 232 ++++++++++++++++++++++++ tests/Models/AccountRelationTest.php | 49 +++++ tests/Models/GroupRelationTest.php | 49 +++++ tests/Models/TaskElementTest.php | 107 +++++++++++ tests/Models/TaskMapperTest.php | 261 +++++++++++++++++++++++++++ tests/Models/TaskTest.php | 179 ++++++++++++++++++ tests/Tasks.side | 195 ++++++++++++++++++++ 9 files changed, 1190 insertions(+) create mode 100644 tests/Admin/AdminTest.php create mode 100644 tests/BackendControllerTest.php create mode 100644 tests/ControllerTest.php create mode 100644 tests/Models/AccountRelationTest.php create mode 100644 tests/Models/GroupRelationTest.php create mode 100644 tests/Models/TaskElementTest.php create mode 100644 tests/Models/TaskMapperTest.php create mode 100644 tests/Models/TaskTest.php create mode 100644 tests/Tasks.side diff --git a/tests/Admin/AdminTest.php b/tests/Admin/AdminTest.php new file mode 100644 index 0000000..e691fe3 --- /dev/null +++ b/tests/Admin/AdminTest.php @@ -0,0 +1,26 @@ +app = new class() extends ApplicationAbstract + { + protected string $appName = 'Backend'; + }; + + $this->app->dbPool = $GLOBALS['dbpool']; + $this->app->orgId = 1; + $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/Backend/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('Tasks'); + + TestUtils::setMember($this->module, 'app', $this->app); + } + + public function testNavigation() : void + { + self::assertEquals(0, $this->module->openNav(999)); + + /** + * @todo Orange-Management/Modules#206 + * Implement has seen feature + * In order to allow a "user has seen task x" feature every task should have a user/account status for the different users (creator, cc, receiver). + */ + // self::assertGreaterThan(0, $this->module->openNav(1)); + } +} diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php new file mode 100644 index 0000000..a8d7ae8 --- /dev/null +++ b/tests/ControllerTest.php @@ -0,0 +1,232 @@ +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->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('Tasks'); + + TestUtils::setMember($this->module, 'app', $this->app); + } + + /** + * @covers Modules\Tasks\Controller\ApiController + * @group module + */ + public function testCreateTask() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->getHeader()->setAccount(1); + $request->setData('title', 'Controller Test Title'); + $request->setData('plain', 'Controller Test Description'); + $request->setData('due', (new \DateTime())->format('Y-m-d H:i:s')); + + $this->module->apiTaskCreate($request, $response); + + self::assertEquals('Controller Test Title', $response->get('')['response']->getTitle()); + self::assertGreaterThan(0, $response->get('')['response']->getId()); + } + + /** + * @covers Modules\Tasks\Controller\ApiController + * @group module + */ + public function testApiTaskGet() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->getHeader()->setAccount(1); + $request->setData('id', '1'); + + $this->module->apiTaskGet($request, $response); + + self::assertEquals(1, $response->get('')['response']->getId()); + } + + /** + * @covers Modules\Tasks\Controller\ApiController + * @group module + */ + public function testApiTaskSet() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->getHeader()->setAccount(1); + $request->setData('id', 1); + $request->setData('title', 'New Title'); + $request->setData('description', 'New Content here'); + + $this->module->apiTaskSet($request, $response); + $this->module->apiTaskGet($request, $response); + + self::assertEquals('New Title', $response->get('')['response']->getTitle()); + } + + /** + * @covers Modules\Tasks\Controller\ApiController + * @group module + */ + public function testCreateTaskElement() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->getHeader()->setAccount(1); + $request->setData('due', (new \DateTime())->format('Y-m-d H:i:s')); + $request->setData('priority', TaskPriority::HIGH); + $request->setData('status', TaskStatus::DONE); + $request->setData('task', 1); + $request->setData('plain', 'Controller Test'); + + $this->module->apiTaskElementCreate($request, $response); + + self::assertEquals('Controller Test', $response->get('')['response']->getDescriptionRaw()); + self::assertGreaterThan(0, $response->get('')['response']->getId()); + } + + /** + * @covers Modules\Tasks\Controller\ApiController + * @group module + */ + public function testApiTaskElementGet() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->getHeader()->setAccount(1); + $request->setData('id', '1'); + + $this->module->apiTaskElementGet($request, $response); + + self::assertEquals(1, $response->get('')['response']->getId()); + } + + /** + * @covers Modules\Tasks\Controller\ApiController + * @group module + */ + public function testApiTaskElementSet() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->getHeader()->setAccount(1); + $request->setData('id', 1); + $request->setData('plain', 'This is a changed description'); + + $this->module->apiTaskElementSet($request, $response); + $this->module->apiTaskElementGet($request, $response); + + self::assertEquals('This is a changed description', $response->get('')['response']->getDescriptionRaw()); + } + + public function testInvalidTaskCreate() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->getHeader()->setAccount(1); + $request->setData('plain', 'Controller Test Description'); + $request->setData('due', (new \DateTime())->format('Y-m-d H:i:s')); + + $this->module->apiTaskCreate($request, $response); + + self::assertNotEquals([], $response->get('')); + } + + /** + * @covers Modules\Tasks\Controller\ApiController + * @group module + */ + public function testInvalidTaskElementCreate() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->getHeader()->setAccount(1); + $request->setData('due', (new \DateTime())->format('Y-m-d H:i:s')); + $request->setData('priority', TaskPriority::HIGH); + $request->setData('status', TaskStatus::DONE); + $request->setData('plain', 'Controller Test'); + + $this->module->apiTaskElementCreate($request, $response); + + self::assertNotEquals([], $response->get('')); + } +} diff --git a/tests/Models/AccountRelationTest.php b/tests/Models/AccountRelationTest.php new file mode 100644 index 0000000..a89dde3 --- /dev/null +++ b/tests/Models/AccountRelationTest.php @@ -0,0 +1,49 @@ +getId()); + self::assertEquals(0, $obj->getRelation()); + self::assertEquals(DutyType::TO, $obj->getDuty()); + } + + public function testSetGet() : void + { + $obj = new AccountRelation(1, DutyType::CC); + self::assertEquals(1, $obj->getRelation()); + self::assertEquals(DutyType::CC, $obj->getDuty()); + + self::assertEquals([ + 'id' => 0, + 'duty' => DutyType::CC, + 'relation' => 1, + ], $obj->toArray()); + self::assertEquals($obj->toArray(), $obj->jsonSerialize()); + + $obj->setDuty(DutyType::TO); + self::assertEquals(DutyType::TO, $obj->getDuty()); + } +} diff --git a/tests/Models/GroupRelationTest.php b/tests/Models/GroupRelationTest.php new file mode 100644 index 0000000..12af168 --- /dev/null +++ b/tests/Models/GroupRelationTest.php @@ -0,0 +1,49 @@ +getId()); + self::assertEquals(0, $obj->getRelation()); + self::assertEquals(DutyType::TO, $obj->getDuty()); + } + + public function testSetGet() : void + { + $obj = new GroupRelation(1, DutyType::CC); + self::assertEquals(1, $obj->getRelation()); + self::assertEquals(DutyType::CC, $obj->getDuty()); + + self::assertEquals([ + 'id' => 0, + 'duty' => DutyType::CC, + 'relation' => 1, + ], $obj->toArray()); + self::assertEquals($obj->toArray(), $obj->jsonSerialize()); + + $obj->setDuty(DutyType::TO); + self::assertEquals(DutyType::TO, $obj->getDuty()); + } +} diff --git a/tests/Models/TaskElementTest.php b/tests/Models/TaskElementTest.php new file mode 100644 index 0000000..a3fad66 --- /dev/null +++ b/tests/Models/TaskElementTest.php @@ -0,0 +1,107 @@ +getId()); + self::assertEquals(0, $task->getCreatedBy()->getId()); + self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $task->getCreatedAt()->format('Y-m-d')); + self::assertEquals((new \DateTime('now'))->modify('+1 day')->format('Y-m-d'), $task->getDue()->format('Y-m-d')); + self::assertEquals(TaskStatus::OPEN, $task->getStatus()); + self::assertEquals('', $task->getDescription()); + self::assertEquals('', $task->getDescriptionRaw()); + self::assertEquals([], $task->getTo()); + self::assertEquals([], $task->getCC()); + self::assertEquals(0, $task->getTask()); + self::assertEquals(TaskPriority::NONE, $task->getPriority()); + } + + public function testSetGet() : void + { + $task = new TaskElement(); + + $task->setCreatedBy(new NullAccount(1)); + self::assertEquals(1, $task->getCreatedBy()->getId()); + + $task->setDue($date = new \DateTime('2000-05-07')); + self::assertEquals($date->format('Y-m-d'), $task->getDue()->format('Y-m-d')); + + $task->setStatus(TaskStatus::DONE); + self::assertEquals(TaskStatus::DONE, $task->getStatus()); + + $task->setPriority(TaskPriority::MEDIUM); + self::assertEquals(TaskPriority::MEDIUM, $task->getPriority()); + + $task->setDescription('Description'); + self::assertEquals('Description', $task->getDescription()); + + $task->setDescriptionRaw('DescriptionRaw'); + self::assertEquals('DescriptionRaw', $task->getDescriptionRaw()); + + $task->setTask(2); + self::assertEquals(2, $task->getTask()); + + $task->addTo(new NullAccount(3)); + $task->addTo(new NullAccount(3)); // test duplicate + self::assertTrue($task->isToAccount(3)); + + $task->addGroupTo(new NullGroup(4)); + $task->addGroupTo(new NullGroup(4)); // test duplicate + self::assertTrue($task->isToGroup(4)); + + $task->addCC(new NullAccount(5)); + $task->addCC(new NullAccount(5)); // test duplicate + self::assertTrue($task->isCCAccount(5)); + + $task->addGroupCC(new NullGroup(6)); + $task->addGroupCC(new NullGroup(6)); // test duplicate + self::assertTrue($task->isCCGroup(6)); + + self::assertFalse($task->isToAccount(7)); + self::assertFalse($task->isCCAccount(8)); + self::assertFalse($task->isToGroup(9)); + self::assertFalse($task->isCCGroup(10)); + } + + public function testInvalidStatus() : void + { + self::expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class); + + $task = new TaskElement(); + $task->setStatus(9999); + } + + public function testInvalidPriority() : void + { + self::expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class); + + $task = new TaskElement(); + $task->setPriority(9999); + } +} diff --git a/tests/Models/TaskMapperTest.php b/tests/Models/TaskMapperTest.php new file mode 100644 index 0000000..27229ca --- /dev/null +++ b/tests/Models/TaskMapperTest.php @@ -0,0 +1,261 @@ +setCreatedBy(new NullAccount(1)); + $task->getSchedule()->setCreatedBy(new NullAccount(1)); + $task->setStart(new \DateTime('2005-05-05')); + $task->setTitle('Task Test'); + $task->setStatus(TaskStatus::OPEN); + $task->setClosable(false); + $task->setPriority(TaskPriority::HIGH); + $task->setDescription('Description'); + $task->setDescriptionRaw('DescriptionRaw'); + $task->setDone(new \DateTime('2000-05-06')); + $task->setDue(new \DateTime('2000-05-05')); + + $taskElement1 = new TaskElement(); + $taskElement1->setDescription('Desc1'); + $taskElement1->setCreatedBy(new NullAccount(1)); + $taskElement1->setStatus($task->getStatus()); + $task->addElement($taskElement1); + + $media = new Media(); + $media->setCreatedBy(new NullAccount(1)); + $media->setDescription('desc'); + $media->setPath('some/path'); + $media->setSize(11); + $media->setExtension('png'); + $media->setName('Task Element Media'); + $taskElement1->addMedia($media); + + $taskElement2 = new TaskElement(); + $taskElement2->setDescription('Desc2'); + $taskElement2->setCreatedBy(new NullAccount(1)); + $taskElement2->setStatus($task->getStatus()); + $taskElement2->addAccountTo(new NullAccount(1)); + $taskElement2->addAccountCC(new NullAccount(1)); + $taskElement2->addGroupTo(new NullGroup(1)); + $taskElement2->addGroupCC(new NullGroup(1)); + $task->addElement($taskElement2); + + $media = new Media(); + $media->setCreatedBy(new NullAccount(1)); + $media->setDescription('desc'); + $media->setPath('some/path'); + $media->setSize(11); + $media->setExtension('png'); + $media->setName('Task Media'); + $task->addMedia($media); + + $id = TaskMapper::create($task); + self::assertGreaterThan(0, $task->getId()); + self::assertEquals($id, $task->getId()); + + $taskR = TaskMapper::get($task->getId()); + self::assertEquals($task->getCreatedAt()->format('Y-m-d'), $taskR->getCreatedAt()->format('Y-m-d')); + self::assertEquals($task->getStart()->format('Y-m-d'), $taskR->getStart()->format('Y-m-d')); + self::assertEquals($task->getCreatedBy()->getId(), $taskR->getCreatedBy()->getId()); + self::assertEquals($task->getDescription(), $taskR->getDescription()); + self::assertEquals($task->getDescriptionRaw(), $taskR->getDescriptionRaw()); + self::assertEquals($task->getTitle(), $taskR->getTitle()); + self::assertEquals($task->getStatus(), $taskR->getStatus()); + self::assertEquals($task->isClosable(), $taskR->isClosable()); + self::assertEquals($task->getType(), $taskR->getType()); + self::assertEquals($task->getDone()->format('Y-m-d'), $taskR->getDone()->format('Y-m-d')); + self::assertEquals($task->getDue()->format('Y-m-d'), $taskR->getDue()->format('Y-m-d')); + self::assertGreaterThan(0, TaskMapper::countUnread(1)); + + $expected = $task->getMedia(); + $actual = $taskR->getMedia(); + self::assertEquals(\end($expected)->getName(), \end($actual)->getName()); + + $expected = $task->getTaskElements(); + $actual = $taskR->getTaskElements(); + + $expectedMedia = \reset($expected)->getMedia(); + $actualMedia = \reset($actual)->getMedia(); + + self::assertEquals(\end($expected)->getDescription(), \end($actual)->getDescription()); + self::assertEquals(\end($expectedMedia)->getName(), \end($actualMedia)->getName()); + + self::assertTrue(\end($actual)->isToAccount(1)); + self::assertTrue(\end($actual)->isToGroup(1)); + self::assertTrue(\end($actual)->isCCAccount(1)); + self::assertTrue(\end($actual)->isCCGroup(1)); + + self::assertCount(2, \end($actual)->getTo()); + self::assertCount(2, \end($actual)->getCC()); + } + + /** + * @covers Modules\Tasks\Models\TaskMapper + * @group module + */ + public function testNewest() : void + { + $newest = TaskMapper::getNewest(1); + + self::assertCount(1, $newest); + } + + /** + * @group volume + * @group module + * @coversNothing + */ + public function testCreatedByMeForMe() : void + { + $text = new Text(); + + $taskStatus = TaskStatus::getConstants(); + + foreach ($taskStatus as $status) { + $task = new Task(); + + $task->setCreatedBy(new NullAccount(1)); + $task->getSchedule()->setCreatedBy(new NullAccount(1)); + $task->setStart(new \DateTime('2005-05-05')); + $task->setTitle($text->generateText(\mt_rand(1, 5))); + $task->setStatus($status); + $task->setDescription($text->generateText(\mt_rand(10, 30))); + $task->setDone(new \DateTime('2000-05-06')); + $task->setDue(new \DateTime('2000-05-05')); + + $taskElement1 = new TaskElement(); + $taskElement1->setDescription($text->generateText(\mt_rand(3, 20))); + $taskElement1->setCreatedBy(new NullAccount(1)); + $taskElement1->setStatus($status); + $task->addElement($taskElement1); + + $taskElement2 = new TaskElement(); + $taskElement2->setDescription('Desc2'); + $taskElement2->setCreatedBy(new NullAccount(1)); + $taskElement2->setStatus($status); + $task->addElement($taskElement2); + + $id = TaskMapper::create($task); + } + + self::assertGreaterThan(0, TaskMapper::countUnread(1)); + } + + /** + * @group volume + * @group module + * @coversNothing + */ + public function testCreatedByMeForOther() : void + { + $text = new Text(); + + $taskStatus = TaskStatus::getConstants(); + + foreach ($taskStatus as $status) { + $task = new Task(); + + $task->setCreatedBy(new NullAccount(1)); + $task->getSchedule()->setCreatedBy(new NullAccount(1)); + $task->setTitle($text->generateText(\mt_rand(1, 5))); + $task->setStatus($status); + $task->setClosable(true); + $task->setDescription($text->generateText(\mt_rand(10, 30))); + $task->setDone(new \DateTime('2000-05-06')); + $task->setDue(new \DateTime('2000-05-05')); + + $taskElement1 = new TaskElement(); + $taskElement1->setDescription($text->generateText(\mt_rand(3, 20))); + $taskElement1->setCreatedBy(new NullAccount(1)); + $taskElement1->setStatus($status); + $task->addElement($taskElement1); + + $taskElement2 = new TaskElement(); + $taskElement2->setDescription($text->generateText(\mt_rand(3, 20))); + $taskElement2->setCreatedBy(new NullAccount(1)); + $taskElement2->setStatus($status); + $task->addElement($taskElement2); + + $id = TaskMapper::create($task); + } + } + + /** + * @group volume + * @group module + * @coversNothing + */ + public function testCreatedByOtherForMe() : void + { + $text = new Text(); + + $taskStatus = TaskStatus::getConstants(); + + foreach ($taskStatus as $status) { + $task = new Task(); + + $task->setCreatedBy(new NullAccount(1)); + $task->getSchedule()->setCreatedBy(new NullAccount(1)); + $task->setTitle($text->generateText(\mt_rand(1, 5))); + $task->setStatus($status); + $task->setClosable(true); + $task->setDescription($text->generateText(\mt_rand(10, 30))); + $task->setDone(new \DateTime('2000-05-06')); + $task->setDue(new \DateTime('2000-05-05')); + + $taskElement1 = new TaskElement(); + $taskElement1->setDescription($text->generateText(\mt_rand(3, 20))); + $taskElement1->setCreatedBy(new NullAccount(1)); + $taskElement1->setStatus($status); + $task->addElement($taskElement1); + + $taskElement2 = new TaskElement(); + $taskElement2->setDescription($text->generateText(\mt_rand(3, 20))); + $taskElement2->setCreatedBy(new NullAccount(1)); + $taskElement2->setStatus($status); + $task->addElement($taskElement2); + + $id = TaskMapper::create($task); + } + } +} diff --git a/tests/Models/TaskTest.php b/tests/Models/TaskTest.php new file mode 100644 index 0000000..6b0990b --- /dev/null +++ b/tests/Models/TaskTest.php @@ -0,0 +1,179 @@ +getId()); + self::assertEquals(0, $task->getCreatedBy()->getId()); + self::assertEquals('', $task->getTitle()); + self::assertFalse($task->isToAccount(0)); + self::assertFalse($task->isCCAccount(0)); + self::assertFalse($task->isToGroup(0)); + self::assertFalse($task->isCCGroup(0)); + self::assertTrue($task->isEditable()); + self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $task->getCreatedAt()->format('Y-m-d')); + self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $task->getStart()->format('Y-m-d')); + self::assertNull($task->getDone()); + self::assertEquals((new \DateTime('now'))->modify('+1 day')->format('Y-m-d'), $task->getDue()->format('Y-m-d')); + self::assertEquals(TaskStatus::OPEN, $task->getStatus()); + self::assertTrue($task->isClosable()); + self::assertEquals(TaskPriority::NONE, $task->getPriority()); + self::assertEquals(TaskType::SINGLE, $task->getType()); + self::assertEquals([], $task->getTaskElements()); + self::assertEquals('', $task->getDescription()); + self::assertEquals('', $task->getDescriptionRaw()); + self::assertInstanceOf('\Modules\Tasks\Models\NullTaskElement', $task->getTaskElement(1)); + } + + public function testSetGet() : void + { + $task = new Task(); + + $task->setCreatedBy(new NullAccount(1)); + self::assertEquals(1, $task->getCreatedBy()->getId()); + + $task->setStart($date = new \DateTime('2005-05-05')); + self::assertEquals($date->format('Y-m-d'), $task->getStart()->format('Y-m-d')); + + $task->setTitle('Title'); + self::assertEquals('Title', $task->getTitle()); + + $task->setDone($date = new \DateTime('2000-05-06')); + self::assertEquals($date->format('Y-m-d'), $task->getDone()->format('Y-m-d')); + + $task->setDue($date = new \DateTime('2000-05-07')); + self::assertEquals($date->format('Y-m-d'), $task->getDue()->format('Y-m-d')); + + $task->setStatus(TaskStatus::DONE); + self::assertEquals(TaskStatus::DONE, $task->getStatus()); + + $task->setClosable(false); + self::assertFalse($task->isClosable()); + + $task->setPriority(TaskPriority::LOW); + self::assertEquals(TaskPriority::LOW, $task->getPriority()); + + $taskElement1 = new TaskElement(); + $taskElement1->addTo(new NullAccount(2)); + $taskElement1->addGroupTo(new NullGroup(4)); + $taskElement1->addCC(new NullAccount(6)); + $taskElement1->addGroupCC(new NullGroup(8)); + + $taskElement2 = new TaskElement(); + $taskElement2->addTo(new NullAccount(3)); + $taskElement2->addGroupTo(new NullGroup(5)); + $taskElement2->addCC(new NullAccount(7)); + $taskElement2->addGroupCC(new NullGroup(9)); + + $id = []; + $id[] = $task->addElement($taskElement1); + $id[] = $task->addElement($taskElement2); + + self::assertTrue($task->isToAccount(2)); + self::assertTrue($task->isToAccount(3)); + self::assertTrue($task->isToGroup(4)); + self::assertTrue($task->isToGroup(5)); + + self::assertTrue($task->isCCAccount(6)); + self::assertTrue($task->isCCAccount(7)); + self::assertTrue($task->isCCGroup(8)); + self::assertTrue($task->isCCGroup(9)); + + $success = $task->removeElement(99); + self::assertFalse($success); + + $success = $task->removeElement($id[1]); + self::assertTrue($success); + + self::assertEquals(0, $task->getTaskElements()[0]->getId()); + self::assertEquals(0, $task->getTaskElement(0)->getId()); + + $task->setDescription('Description'); + self::assertEquals('Description', $task->getDescription()); + + $task->setDescriptionRaw('DescriptionRaw'); + self::assertEquals('DescriptionRaw', $task->getDescriptionRaw()); + + $task->setEditable(false); + self::assertFalse($task->isEditable()); + + self::assertInstanceOf('\Modules\Tasks\Models\TaskElement', $task->getTaskElement(1)); + + $arr = [ + 'id' => 0, + 'createdBy' => $task->getCreatedBy(), + 'createdAt' => $task->getCreatedAt(), + 'title' => $task->getTitle(), + 'description' => $task->getDescription(), + 'status' => $task->getStatus(), + 'type' => $task->getType(), + 'priority' => $task->getPriority(), + 'due' => $task->getDue(), + 'done' => $task->getDone(), + ]; + + $isSubset = true; + $parent = $task->toArray(); + foreach ($arr as $key => $value) { + if (!isset($parent[$key]) || $parent[$key] !== $value) { + $isSubset = false; + break; + } + } + self::assertTrue($isSubset); + + $isSubset = true; + $parent = $task->jsonSerialize(); + foreach ($arr as $key => $value) { + if (!isset($parent[$key]) || $parent[$key] !== $value) { + $isSubset = false; + break; + } + } + self::assertTrue($isSubset); + } + + public function testInvalidStatus() : void + { + self::expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class); + + $task = new Task(); + $task->setStatus(9999); + } + + public function testInvalidPriority() : void + { + self::expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class); + + $task = new Task(); + $task->setPriority(9999); + } +} diff --git a/tests/Tasks.side b/tests/Tasks.side new file mode 100644 index 0000000..9fd27db --- /dev/null +++ b/tests/Tasks.side @@ -0,0 +1,195 @@ +{ + "id": "3043757f-163e-49bd-ab5b-b7eb855956f4", + "version": "2.0", + "name": "Tasks", + "url": "http://127.0.0.1", + "tests": [{ + "id": "40f10400-f840-463e-8112-a9464e20239b", + "name": "Create Task", + "commands": [{ + "id": "069531fb-c35a-4de0-a830-3180c8910f7a", + "comment": "", + "command": "open", + "target": "/", + "targets": [], + "value": "" + }, { + "id": "51c7fc32-f3c0-49d7-b613-3a2d8c5c97aa", + "comment": "", + "command": "setWindowSize", + "target": "1218x855", + "targets": [], + "value": "" + }, { + "id": "55379c1d-b200-4460-953d-a735e5a5bf16", + "comment": "", + "command": "click", + "target": "css=#t-nav a[href=\"task/dashboard\"]", + "targets": [ + ["css=li:nth-child(4) .link", "css:finder"], + ["xpath=//ul[@id='t-nav']/li[4]/a/span", "xpath:idRelative"], + ["xpath=//li[4]/a/span", "xpath:position"], + ["xpath=//span[contains(.,'Tasks')]", "xpath:innerText"] + ], + "value": "" + }, { + "id": "76d882d5-e4af-48fa-9152-41780a63594c", + "comment": "", + "command": "click", + "target": "linkText=Create", + "targets": [ + ["linkText=Create", "linkText"], + ["css=.nav-top > li:nth-child(2) > a", "css:finder"], + ["xpath=//a[contains(text(),'Create')]", "xpath:link"], + ["xpath=//div[@id='content']/div/div/ul/li[2]/a", "xpath:idRelative"], + ["xpath=//a[contains(@href, 'task/create')]", "xpath:href"], + ["xpath=//div/div/ul/li[2]/a", "xpath:position"], + ["xpath=//a[contains(.,'Create')]", "xpath:innerText"] + ], + "value": "" + }, { + "id": "73a875a4-a72f-4654-a217-fe2ca4b781a4", + "comment": "", + "command": "click", + "target": "id=iiReceiver", + "targets": [ + ["id=iiReceiver", "id"], + ["css=#iiReceiver", "css:finder"], + ["xpath=//input[@id='iiReceiver']", "xpath:attributes"], + ["xpath=//div[@id='iReceiver']/input", "xpath:idRelative"], + ["xpath=//div/input", "xpath:position"] + ], + "value": "" + }, { + "id": "3909e97f-9cd3-4d3a-9e8f-cbfdd3f367f9", + "comment": "", + "command": "type", + "target": "id=iiReceiver", + "targets": [ + ["id=iiReceiver", "id"], + ["css=#iiReceiver", "css:finder"], + ["xpath=//input[@id='iiReceiver']", "xpath:attributes"], + ["xpath=//div[@id='iReceiver']/input", "xpath:idRelative"], + ["xpath=//div/input", "xpath:position"] + ], + "value": "admin" + }, { + "id": "c6380adf-878a-41ba-a177-d46c252ac820", + "comment": "", + "command": "click", + "target": "css=tbody > tr:nth-child(1) > td:nth-child(3)", + "targets": [ + ["css=tbody > tr:nth-child(1) > td:nth-child(3)", "css:finder"], + ["xpath=//div[@id='iReceiver-dropdown']/table/tbody/tr/td[3]", "xpath:idRelative"], + ["xpath=//tbody/tr/td[3]", "xpath:position"] + ], + "value": "" + }, { + "id": "92956ab4-b9e3-4e71-9422-eedde614a809", + "comment": "", + "command": "click", + "target": "id=iTitle", + "targets": [ + ["id=iTitle", "id"], + ["name=title", "name"], + ["css=#iTitle", "css:finder"], + ["xpath=//input[@id='iTitle']", "xpath:attributes"], + ["xpath=//form[@id='fTask']/table/tbody/tr[10]/td/input", "xpath:idRelative"], + ["xpath=//tr[10]/td/input", "xpath:position"] + ], + "value": "" + }, { + "id": "8576812f-223a-42c5-86c2-20e59322fcc6", + "comment": "", + "command": "type", + "target": "id=iTitle", + "targets": [ + ["id=iTitle", "id"], + ["name=title", "name"], + ["css=#iTitle", "css:finder"], + ["xpath=//input[@id='iTitle']", "xpath:attributes"], + ["xpath=//form[@id='fTask']/table/tbody/tr[10]/td/input", "xpath:idRelative"], + ["xpath=//tr[10]/td/input", "xpath:position"] + ], + "value": "Selenium Task" + }, { + "id": "fa370c1c-9c4d-4d8c-a443-bd67350d2d61", + "comment": "", + "command": "click", + "target": "name=plain", + "targets": [ + ["name=plain", "name"], + ["css=textarea", "css:finder"], + ["xpath=//textarea[@name='plain']", "xpath:attributes"], + ["xpath=//div[@id='task-editor']/div/div/textarea", "xpath:idRelative"], + ["xpath=//textarea", "xpath:position"] + ], + "value": "" + }, { + "id": "1e6d7a03-c619-41bf-a9db-281fdcfc34f7", + "comment": "", + "command": "type", + "target": "name=plain", + "targets": [ + ["name=plain", "name"], + ["css=textarea", "css:finder"], + ["xpath=//textarea[@name='plain']", "xpath:attributes"], + ["xpath=//div[@id='task-editor']/div/div/textarea", "xpath:idRelative"], + ["xpath=//textarea", "xpath:position"] + ], + "value": " This is a Selenium Task" + }, { + "id": "48330cc9-770c-4767-bfaa-e5b31302899e", + "comment": "", + "command": "click", + "target": "id=iCreateSubmit", + "targets": [ + ["css=tr:nth-child(14) input:nth-child(1)", "css:finder"], + ["xpath=//input[@value='Create']", "xpath:attributes"], + ["xpath=//form[@id='fTask']/table/tbody/tr[14]/td/input", "xpath:idRelative"], + ["xpath=//tr[14]/td/input", "xpath:position"] + ], + "value": "" + }, { + "id": "0438a34f-26fd-4f27-8f40-89340422c887", + "comment": "", + "command": "click", + "target": "linkText=List", + "targets": [ + ["linkText=List", "linkText"], + ["css=.nav-top > li:nth-child(1) > a", "css:finder"], + ["xpath=//a[contains(text(),'List')]", "xpath:link"], + ["xpath=//div[@id='content']/div/div/ul/li/a", "xpath:idRelative"], + ["xpath=(//a[contains(@href, 'task/dashboard')])[2]", "xpath:href"], + ["xpath=//div/div/ul/li/a", "xpath:position"], + ["xpath=//a[contains(.,'List')]", "xpath:innerText"] + ], + "value": "" + }, { + "id": "e6a56bed-7447-4e63-abf4-365361b942ee", + "comment": "", + "command": "click", + "target": "linkText=Selenium Task", + "targets": [ + ["linkText=2019-06-15 13:29", "linkText"], + ["css=tr:nth-child(1) > td:nth-child(2) > a", "css:finder"], + ["xpath=//a[contains(text(),'2019-06-15 13:29')]", "xpath:link"], + ["xpath=//table[@id='taskList']/tbody/tr/td[2]/a", "xpath:idRelative"], + ["xpath=(//a[contains(@href, 'task/single?id=40')])[2]", "xpath:href"], + ["xpath=//td[2]/a", "xpath:position"], + ["xpath=//a[contains(.,'2019-06-15 13:29')]", "xpath:innerText"] + ], + "value": "" + }] + }], + "suites": [{ + "id": "b6e138a0-7972-48bc-8b42-589aa6617b9e", + "name": "Default Suite", + "persistSession": false, + "parallel": false, + "timeout": 300, + "tests": ["40f10400-f840-463e-8112-a9464e20239b"] + }], + "urls": ["http://127.0.0.1/"], + "plugins": [] +} \ No newline at end of file