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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
class DummyAction extends Kanboard\Action\Base
{
public function getDescription()
{
return 'Dummy Action';
}
public function getCompatibleEvents()
{
return array('my.event');
}
public function getActionRequiredParameters()
{
return array('p1' => 'Param 1');
}
public function getEventRequiredParameters()
{
return array('p1', 'p2', 'p3' => array('p4'));
}
public function doAction(array $data)
{
return true;
}
public function hasRequiredCondition(array $data)
{
return $data['p1'] == $this->getParam('p1');
}
}
class BaseActionTest extends Base
{
public function testGetName()
{
$dummyAction = new DummyAction($this->container);
$this->assertEquals('\\DummyAction', $dummyAction->getName());
}
public function testGetDescription()
{
$dummyAction = new DummyAction($this->container);
$this->assertEquals('Dummy Action', $dummyAction->getDescription());
}
public function testGetActionRequiredParameters()
{
$dummyAction = new DummyAction($this->container);
$this->assertEquals(array('p1' => 'Param 1'), $dummyAction->getActionRequiredParameters());
}
public function testGetEventRequiredParameters()
{
$dummyAction = new DummyAction($this->container);
$this->assertEquals(array('p1', 'p2', 'p3' => array('p4')), $dummyAction->getEventRequiredParameters());
}
public function testGetCompatibleEvents()
{
$dummyAction = new DummyAction($this->container);
$this->assertEquals(array('my.event'), $dummyAction->getCompatibleEvents());
}
public function testHasRequiredCondition()
{
$dummyAction = new DummyAction($this->container);
$dummyAction->setParam('p1', 123);
$this->assertTrue($dummyAction->hasRequiredCondition(array('p1' => 123)));
$this->assertFalse($dummyAction->hasRequiredCondition(array('p1' => 456)));
}
public function testProjectId()
{
$dummyAction = new DummyAction($this->container);
$this->assertInstanceOf('DummyAction', $dummyAction->setProjectId(123));
$this->assertEquals(123, $dummyAction->getProjectId());
}
public function testParam()
{
$dummyAction = new DummyAction($this->container);
$this->assertInstanceOf('DummyAction', $dummyAction->setParam('p1', 123));
$this->assertEquals(123, $dummyAction->getParam('p1'));
}
public function testHasCompatibleEvents()
{
$dummyAction = new DummyAction($this->container);
$this->assertTrue($dummyAction->hasCompatibleEvent('my.event'));
$this->assertFalse($dummyAction->hasCompatibleEvent('foobar'));
}
public function testHasRequiredProject()
{
$dummyAction = new DummyAction($this->container);
$dummyAction->setProjectId(1234);
$this->assertTrue($dummyAction->hasRequiredProject(array('project_id' => 1234)));
$this->assertFalse($dummyAction->hasRequiredProject(array('project_id' => 1)));
$this->assertFalse($dummyAction->hasRequiredProject(array()));
}
public function testHasRequiredParameters()
{
$dummyAction = new DummyAction($this->container);
$dummyAction->setProjectId(1234);
$this->assertTrue($dummyAction->hasRequiredParameters(array('p1' => 12, 'p2' => 34, 'p3' => array('p4' => 'foobar'))));
$this->assertFalse($dummyAction->hasRequiredParameters(array('p1' => 12)));
$this->assertFalse($dummyAction->hasRequiredParameters(array()));
}
public function testAddEvent()
{
$dummyAction = new DummyAction($this->container);
$dummyAction->addEvent('foobar', 'FooBar');
$dummyAction->addEvent('my.event', 'My Event Overrided');
$events = $dummyAction->getEvents();
$this->assertCount(2, $events);
$this->assertEquals(array('my.event', 'foobar'), $events);
}
public function testExecuteOnlyOnce()
{
$dummyAction = new DummyAction($this->container);
$dummyAction->setProjectId(1234);
$dummyAction->setParam('p1', 'something');
$dummyAction->addEvent('foobar', 'FooBar');
$event = new GenericEvent(array('project_id' => 1234, 'p1' => 'something', 'p2' => 'abc', 'p3' => array('p4' => 'a')));
$this->assertTrue($dummyAction->execute($event, 'foobar'));
$this->assertFalse($dummyAction->execute($event, 'foobar'));
}
public function testExecuteSameActionSeveralTimesWithDifferentEvents()
{
$dummyAction = new DummyAction($this->container);
$dummyAction->setProjectId(1234);
$dummyAction->setParam('p1', 'something');
$dummyAction->addEvent('foobar', 'FooBar');
$event1 = new GenericEvent(array('project_id' => 1234, 'p1' => 'something', 'p2' => 'abc', 'p3' => array('p4' => 'a')));
$event2 = new GenericEvent(array('project_id' => 1234, 'p1' => 'something', 'p2' => 'abc', 'p3' => array('p4' => 'b')));
$this->assertTrue($dummyAction->execute($event1, 'foobar'));
$this->assertTrue($dummyAction->execute($event2, 'foobar'));
}
}
|