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
|
<?php
use Kanboard\EventBuilder\SubtaskEventBuilder;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\SubtaskModel;
use Kanboard\Model\TaskCreationModel;
require_once __DIR__.'/../Base.php';
class SubtaskEventBuilderTest extends Base
{
public function testWithMissingSubtask()
{
$subtaskEventBuilder = new SubtaskEventBuilder($this->container);
$subtaskEventBuilder->withSubtaskId(42);
$this->assertNull($subtaskEventBuilder->build());
}
public function testBuildWithoutChanges()
{
$subtaskModel = new SubtaskModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$projectModel = new ProjectModel($this->container);
$subtaskEventBuilder = new SubtaskEventBuilder($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
$this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'test')));
$event = $subtaskEventBuilder->withSubtaskId(1)->build();
$this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
$this->assertNotEmpty($event['subtask']);
$this->assertNotEmpty($event['task']);
$this->assertArrayNotHasKey('changes', $event);
}
public function testBuildWithChanges()
{
$subtaskModel = new SubtaskModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$projectModel = new ProjectModel($this->container);
$subtaskEventBuilder = new SubtaskEventBuilder($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
$this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'test')));
$event = $subtaskEventBuilder
->withSubtaskId(1)
->withValues(array('title' => 'new title', 'user_id' => 1))
->build();
$this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
$this->assertNotEmpty($event['subtask']);
$this->assertNotEmpty($event['task']);
$this->assertNotEmpty($event['changes']);
$this->assertCount(2, $event['changes']);
$this->assertEquals('new title', $event['changes']['title']);
$this->assertEquals(1, $event['changes']['user_id']);
}
}
|