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
104
105
106
107
108
109
110
111
112
|
<?php
require_once __DIR__.'/Base.php';
use Model\Config;
use Model\Task;
use Model\TaskCreation;
use Model\TaskModification;
use Model\Project;
use Model\Comment;
use Subscriber\WebhookSubscriber;
class WebhookTest extends Base
{
public function testTaskCreation()
{
$c = new Config($this->container);
$p = new Project($this->container);
$tc = new TaskCreation($this->container);
$this->container['dispatcher']->addSubscriber(new WebhookSubscriber($this->container));
$c->save(array('webhook_url' => 'http://localhost/?task-creation'));
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
$this->assertStringStartsWith('http://localhost/?task-creation&token=', $this->container['httpClient']->getUrl());
$event = $this->container['httpClient']->getData();
$this->assertNotEmpty($event);
$this->assertArrayHasKey('event_name', $event);
$this->assertArrayHasKey('event_data', $event);
$this->assertEquals('task.create', $event['event_name']);
$this->assertNotEmpty($event['event_data']);
$this->assertArrayHasKey('project_id', $event['event_data']);
$this->assertArrayHasKey('task_id', $event['event_data']);
$this->assertArrayHasKey('title', $event['event_data']);
$this->assertArrayHasKey('column_id', $event['event_data']);
$this->assertArrayHasKey('color_id', $event['event_data']);
$this->assertArrayHasKey('swimlane_id', $event['event_data']);
$this->assertArrayHasKey('date_creation', $event['event_data']);
$this->assertArrayHasKey('date_modification', $event['event_data']);
$this->assertArrayHasKey('date_moved', $event['event_data']);
$this->assertArrayHasKey('position', $event['event_data']);
}
public function testTaskModification()
{
$c = new Config($this->container);
$p = new Project($this->container);
$tc = new TaskCreation($this->container);
$tm = new TaskModification($this->container);
$this->container['dispatcher']->addSubscriber(new WebhookSubscriber($this->container));
$c->save(array('webhook_url' => 'http://localhost/modif/'));
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
$this->assertTrue($tm->update(array('id' => 1, 'title' => 'test update')));
$this->assertStringStartsWith('http://localhost/modif/?token=', $this->container['httpClient']->getUrl());
$event = $this->container['httpClient']->getData();
$this->assertNotEmpty($event);
$this->assertArrayHasKey('event_name', $event);
$this->assertArrayHasKey('event_data', $event);
$this->assertEquals('task.update', $event['event_name']);
$this->assertNotEmpty($event['event_data']);
$this->assertArrayHasKey('project_id', $event['event_data']);
$this->assertArrayHasKey('task_id', $event['event_data']);
$this->assertArrayHasKey('title', $event['event_data']);
$this->assertArrayHasKey('column_id', $event['event_data']);
$this->assertArrayHasKey('color_id', $event['event_data']);
$this->assertArrayHasKey('swimlane_id', $event['event_data']);
$this->assertArrayHasKey('date_creation', $event['event_data']);
$this->assertArrayHasKey('date_modification', $event['event_data']);
$this->assertArrayHasKey('date_moved', $event['event_data']);
$this->assertArrayHasKey('position', $event['event_data']);
}
public function testCommentCreation()
{
$c = new Config($this->container);
$p = new Project($this->container);
$tc = new TaskCreation($this->container);
$cm = new Comment($this->container);
$this->container['dispatcher']->addSubscriber(new WebhookSubscriber($this->container));
$c->save(array('webhook_url' => 'http://localhost/comment'));
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
$this->assertEquals(1, $cm->create(array('task_id' => 1, 'comment' => 'test comment', 'user_id' => 1)));
$this->assertStringStartsWith('http://localhost/comment?token=', $this->container['httpClient']->getUrl());
$event = $this->container['httpClient']->getData();
$this->assertNotEmpty($event);
$this->assertArrayHasKey('event_name', $event);
$this->assertArrayHasKey('event_data', $event);
$this->assertEquals('comment.create', $event['event_name']);
$this->assertNotEmpty($event['event_data']);
$this->assertArrayHasKey('task_id', $event['event_data']);
$this->assertArrayHasKey('user_id', $event['event_data']);
$this->assertArrayHasKey('comment', $event['event_data']);
$this->assertArrayHasKey('id', $event['event_data']);
$this->assertEquals('test comment', $event['event_data']['comment']);
}
}
|