diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-07-19 22:38:30 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-07-19 22:38:30 -0400 |
commit | 390082aa41cb81610089163b1cc3a256f3b3c513 (patch) | |
tree | 1ada3964702ee536fe1486f34230f8e30a95d82e /tests/units/EventBuilder | |
parent | d9d37882228771bca0c7f53f5ffcef90ba7ac1c5 (diff) |
Refactoring of internal task events
Diffstat (limited to 'tests/units/EventBuilder')
-rw-r--r-- | tests/units/EventBuilder/TaskEventBuilderTest.php | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/tests/units/EventBuilder/TaskEventBuilderTest.php b/tests/units/EventBuilder/TaskEventBuilderTest.php new file mode 100644 index 00000000..e6334fe2 --- /dev/null +++ b/tests/units/EventBuilder/TaskEventBuilderTest.php @@ -0,0 +1,100 @@ +<?php + +use Kanboard\EventBuilder\TaskEventBuilder; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; + +require_once __DIR__.'/../Base.php'; + +class TaskEventBuilderTest extends Base +{ + public function testWithMissingTask() + { + $taskEventBuilder = new TaskEventBuilder($this->container); + $taskEventBuilder->withTaskId(42); + $this->assertNull($taskEventBuilder->build()); + } + + public function testBuildWithTask() + { + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskEventBuilder = new TaskEventBuilder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'before', 'project_id' => 1))); + + $event = $taskEventBuilder + ->withTaskId(1) + ->withTask(array('title' => 'before')) + ->withChanges(array('title' => 'after')) + ->build(); + + $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event); + $this->assertNotEmpty($event['task']); + $this->assertEquals(1, $event['task_id']); + $this->assertEquals(array('title' => 'after'), $event['changes']); + } + + public function testBuildWithoutChanges() + { + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskEventBuilder = new TaskEventBuilder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); + + $event = $taskEventBuilder->withTaskId(1)->build(); + + $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event); + $this->assertNotEmpty($event['task']); + $this->assertEquals(1, $event['task_id']); + $this->assertArrayNotHasKey('changes', $event); + } + + public function testBuildWithChanges() + { + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskEventBuilder = new TaskEventBuilder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); + + $event = $taskEventBuilder + ->withTaskId(1) + ->withChanges(array('title' => 'new title')) + ->build(); + + $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event); + $this->assertNotEmpty($event['task']); + $this->assertNotEmpty($event['changes']); + $this->assertEquals('new title', $event['changes']['title']); + } + + public function testBuildWithChangesAndValues() + { + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskEventBuilder = new TaskEventBuilder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); + + $event = $taskEventBuilder + ->withTaskId(1) + ->withChanges(array('title' => 'new title', 'project_id' => 1)) + ->withValues(array('key' => 'value')) + ->build(); + + $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event); + $this->assertNotEmpty($event['task']); + $this->assertNotEmpty($event['changes']); + $this->assertNotEmpty($event['key']); + $this->assertEquals('value', $event['key']); + + $this->assertCount(1, $event['changes']); + $this->assertEquals('new title', $event['changes']['title']); + } +} |