split up tests

This commit is contained in:
Dennis Eichhorn 2020-07-05 22:08:29 +02:00
parent 33b3d4c637
commit b0aa05ed89
2 changed files with 186 additions and 9 deletions

View File

@ -42,50 +42,123 @@ class TaskElementTest extends \PHPUnit\Framework\TestCase
self::assertEquals(TaskPriority::NONE, $task->getPriority());
}
public function testSetGet() : void
public function testCreatedByInputOutput() : void
{
$task = new TaskElement();
$task->setCreatedBy(new NullAccount(1));
self::assertEquals(1, $task->getCreatedBy()->getId());
}
public function testDueInputOutput() : void
{
$task = new TaskElement();
$task->setDue($date = new \DateTime('2000-05-07'));
self::assertEquals($date->format('Y-m-d'), $task->getDue()->format('Y-m-d'));
}
public function testStatusInputOutput() : void
{
$task = new TaskElement();
$task->setStatus(TaskStatus::DONE);
self::assertEquals(TaskStatus::DONE, $task->getStatus());
}
public function testPriorityInputOutput() : void
{
$task = new TaskElement();
$task->setPriority(TaskPriority::MEDIUM);
self::assertEquals(TaskPriority::MEDIUM, $task->getPriority());
}
public function testDescriptionInputOutput() : void
{
$task = new TaskElement();
$task->setDescription('Description');
self::assertEquals('Description', $task->getDescription());
}
public function testDescriptionRawInputOutput() : void
{
$task = new TaskElement();
$task->setDescriptionRaw('DescriptionRaw');
self::assertEquals('DescriptionRaw', $task->getDescriptionRaw());
}
public function testTaskInputOutput() : void
{
$task = new TaskElement();
$task->setTask(2);
self::assertEquals(2, $task->getTask());
}
public function testAccountToInputOutput() : void
{
$task = new TaskElement();
$task->addTo(new NullAccount(3));
$task->addTo(new NullAccount(3)); // test duplicate
self::assertTrue($task->isToAccount(3));
}
public function testGroupToInputOutput() : void
{
$task = new TaskElement();
$task->addGroupTo(new NullGroup(4));
$task->addGroupTo(new NullGroup(4)); // test duplicate
self::assertTrue($task->isToGroup(4));
}
public function testAccountCCInputOutput() : void
{
$task = new TaskElement();
$task->addCC(new NullAccount(5));
$task->addCC(new NullAccount(5)); // test duplicate
self::assertTrue($task->isCCAccount(5));
}
public function testGroupCCInputOutput() : void
{
$task = new TaskElement();
$task->addGroupCC(new NullGroup(6));
$task->addGroupCC(new NullGroup(6)); // test duplicate
self::assertTrue($task->isCCGroup(6));
}
public function testInvalidAccountTo() : void
{
$task = new TaskElement();
self::assertFalse($task->isToAccount(7));
}
public function testInvalidAccountCC() : void
{
$task = new TaskElement();
self::assertFalse($task->isCCAccount(8));
}
public function testInvalidGroupTo() : void
{
$task = new TaskElement();
self::assertFalse($task->isToGroup(9));
}
public function testInvalidGroupCC() : void
{
$task = new TaskElement();
self::assertFalse($task->isCCGroup(10));
}

View File

@ -53,33 +53,73 @@ class TaskTest extends \PHPUnit\Framework\TestCase
self::assertInstanceOf('\Modules\Tasks\Models\NullTaskElement', $task->getTaskElement(1));
}
public function testSetGet() : void
public function testCreatedByInputOutput() : void
{
$task = new Task();
$task->setCreatedBy(new NullAccount(1));
self::assertEquals(1, $task->getCreatedBy()->getId());
}
public function testStartInputOutput() : void
{
$task = new Task();
$task->setStart($date = new \DateTime('2005-05-05'));
self::assertEquals($date->format('Y-m-d'), $task->getStart()->format('Y-m-d'));
}
public function testTitleInputOutput() : void
{
$task = new Task();
$task->setTitle('Title');
self::assertEquals('Title', $task->getTitle());
}
public function testDoneInputOutput() : void
{
$task = new Task();
$task->setDone($date = new \DateTime('2000-05-06'));
self::assertEquals($date->format('Y-m-d'), $task->getDone()->format('Y-m-d'));
}
public function testDueInputOutput() : void
{
$task = new Task();
$task->setDue($date = new \DateTime('2000-05-07'));
self::assertEquals($date->format('Y-m-d'), $task->getDue()->format('Y-m-d'));
}
public function testStatusInputOutput() : void
{
$task = new Task();
$task->setStatus(TaskStatus::DONE);
self::assertEquals(TaskStatus::DONE, $task->getStatus());
}
public function testClosableInputOutput() : void
{
$task = new Task();
$task->setClosable(false);
self::assertFalse($task->isClosable());
}
public function testPriority() : void
{
$task = new Task();
$task->setPriority(TaskPriority::LOW);
self::assertEquals(TaskPriority::LOW, $task->getPriority());
}
public function testElementInputOutput() : void
{
$task = new Task();
$taskElement1 = new TaskElement();
$taskElement1->addTo(new NullAccount(2));
@ -107,25 +147,71 @@ class TaskTest extends \PHPUnit\Framework\TestCase
self::assertTrue($task->isCCGroup(8));
self::assertTrue($task->isCCGroup(9));
$success = $task->removeElement(99);
self::assertFalse($success);
self::assertEquals(0, $task->getTaskElements()[0]->getId());
self::assertEquals(0, $task->getTaskElement(0)->getId());
}
public function testElementRemoval() : void
{
$task = new Task();
$task = new Task();
$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);
$success = $task->removeElement($id[1]);
self::assertTrue($success);
}
self::assertEquals(0, $task->getTaskElements()[0]->getId());
self::assertEquals(0, $task->getTaskElement(0)->getId());
public function testInvalidElementRemoval() : void
{
$task = new Task();
$success = $task->removeElement(99);
self::assertFalse($success);
}
public function testDescriptionInputOutput() : void
{
$task = new Task();
$task->setDescription('Description');
self::assertEquals('Description', $task->getDescription());
}
public function testDescriptionRawInputOutput() : void
{
$task = new Task();
$task->setDescriptionRaw('DescriptionRaw');
self::assertEquals('DescriptionRaw', $task->getDescriptionRaw());
}
public function testEditableInputOutput() : void
{
$task = new Task();
$task->setEditable(false);
self::assertFalse($task->isEditable());
}
self::assertInstanceOf('\Modules\Tasks\Models\TaskElement', $task->getTaskElement(1));
public function testToArray() : void
{
$task = new Task();
$arr = [
'id' => 0,
@ -143,17 +229,35 @@ class TaskTest extends \PHPUnit\Framework\TestCase
$isSubset = true;
$parent = $task->toArray();
foreach ($arr as $key => $value) {
if (!isset($parent[$key]) || $parent[$key] !== $value) {
if (!\array_key_exists($key, $parent) || $parent[$key] !== $value) {
$isSubset = false;
break;
}
}
self::assertTrue($isSubset);
}
public function testToJson() : void
{
$task = new Task();
$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->jsonSerialize();
foreach ($arr as $key => $value) {
if (!isset($parent[$key]) || $parent[$key] !== $value) {
if (!\array_key_exists($key, $parent) || $parent[$key] !== $value) {
$isSubset = false;
break;
}