File size: 4,034 Bytes
e4f4821 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
<?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->buildEvent());
}
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'))
->buildEvent();
$this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
$this->assertNotEmpty($event['task']);
$this->assertEquals(1, $event['task_id']);
$this->assertEquals(1, $event->getTaskId());
$this->assertEquals(1, $event->getProjectId());
$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)->buildEvent();
$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'))
->buildEvent();
$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'))
->buildEvent();
$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']);
}
}
|