1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \Wicked\Timely\Entities\TaskTest |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Bernhard Wick <[email protected]> |
15
|
|
|
* @copyright 2016 Bernhard Wick |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/wick-ed/timely |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Wicked\Timely\Entities; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Unit-Test class for the "Task" entity |
24
|
|
|
* |
25
|
|
|
* @author Bernhard Wick <[email protected]> |
26
|
|
|
* @copyright 2016 Bernhard Wick |
27
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
28
|
|
|
* @link https://github.com/wick-ed/timely |
29
|
|
|
*/ |
30
|
|
|
class TaskTest extends \PHPUnit_Framework_TestCase |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Basic test for the constructor |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public function testConstructor() |
39
|
|
|
{ |
40
|
|
|
$this->assertInstanceOf( |
41
|
|
|
'\Wicked\Timely\Entities\Task', |
42
|
|
|
new Task( |
43
|
|
|
new Booking('test for a start booking'), |
44
|
|
|
new Booking('test for an end booking'), |
45
|
|
|
array() |
46
|
|
|
) |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Data provider for the testGetDurationWithNoSpecialCase method |
52
|
|
|
* |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
|
|
public function getDurationWithNoSpecialCaseProvider() |
56
|
|
|
{ |
57
|
|
|
return array( |
58
|
|
|
array(1465128900, 1465128998, 98), |
59
|
|
|
array(1465125998, 1465128998, 3000), |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Testing if the duration is calculated and returned correctly |
65
|
|
|
* |
66
|
|
|
* @param integer $startTime Start time in seconds |
67
|
|
|
* @param integer $endTime End time in seconds |
68
|
|
|
* @param integer $duration Duration in seconds |
69
|
|
|
* |
70
|
|
|
* @return void |
71
|
|
|
* |
72
|
|
|
* @dataProvider getDurationWithNoSpecialCaseProvider |
73
|
|
|
*/ |
74
|
|
|
public function testGetDurationWithNoSpecialCase($startTime, $endTime, $duration) |
75
|
|
|
{ |
76
|
|
|
// get two bookings to make up the task |
77
|
|
|
$startBooking = new Booking( |
78
|
|
|
'test for a start booking', |
79
|
|
|
'TEST-1', |
80
|
|
|
date(Booking::DEFAULT_DATE_FORMAT, $startTime) |
81
|
|
|
); |
82
|
|
|
$endBooking = new Booking( |
83
|
|
|
'test for a end booking', |
84
|
|
|
'TEST-1', |
85
|
|
|
date(Booking::DEFAULT_DATE_FORMAT, $endTime) |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
// make the assertion |
89
|
|
|
$testTask = new Task($startBooking, $endBooking, array()); |
90
|
|
|
$this->assertEquals($duration, $testTask->getDuration()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Testing if the duration is calculated and returned correctly |
95
|
|
|
* |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
|
|
public function testGetDurationWithOneIntermediateTask() |
99
|
|
|
{ |
100
|
|
|
// get two bookings to make up the task |
101
|
|
|
$startBooking = new Booking( |
102
|
|
|
'test for a start booking', |
103
|
|
|
'TEST-1', |
104
|
|
|
date(Booking::DEFAULT_DATE_FORMAT, 1465125998) |
105
|
|
|
); |
106
|
|
|
$endBooking = new Booking( |
107
|
|
|
'test for an end booking', |
108
|
|
|
'TEST-1', |
109
|
|
|
date(Booking::DEFAULT_DATE_FORMAT, 1465128998) |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
// create two intermediate bookings to simulate a pause |
113
|
|
|
$pauseStart = new Pause('pause start', false, 1465126998); |
114
|
|
|
$pauseEnd = new Pause('pause end', true, 1465127998); |
115
|
|
|
|
116
|
|
|
// make the assertion |
117
|
|
|
$testTask = new Task($startBooking, $endBooking, array($pauseEnd, $pauseStart)); |
118
|
|
|
$this->assertEquals(2000, $testTask->getDuration()); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Testing if the duration is calculated and returned correctly |
123
|
|
|
* |
124
|
|
|
* @return void |
125
|
|
|
*/ |
126
|
|
|
public function testGetDurationWithTwoIntermediateTasks() |
127
|
|
|
{ |
128
|
|
|
// get two bookings to make up the task |
129
|
|
|
$startBooking = new Booking( |
130
|
|
|
'test for a start booking', |
131
|
|
|
'TEST-1', |
132
|
|
|
date(Booking::DEFAULT_DATE_FORMAT, 1465122998) |
133
|
|
|
); |
134
|
|
|
$endBooking = new Booking( |
135
|
|
|
'test for an end booking', |
136
|
|
|
'TEST-1', |
137
|
|
|
date(Booking::DEFAULT_DATE_FORMAT, 1465128998) |
138
|
|
|
); |
139
|
|
|
|
140
|
|
|
// create two intermediate bookings to simulate a pause |
141
|
|
|
$pauseStart1 = new Pause('pause start', false, 1465123998); |
142
|
|
|
$pauseEnd1 = new Pause('pause end', true, 1465124498); |
143
|
|
|
$pauseStart2 = new Pause('pause start', false, 1465125998); |
144
|
|
|
$pauseEnd2 = new Pause('pause end', true, 1465126998); |
145
|
|
|
|
146
|
|
|
// make the assertion |
147
|
|
|
$testTask = new Task($startBooking, $endBooking, array($pauseEnd1, $pauseStart1, $pauseEnd2, $pauseStart2)); |
148
|
|
|
$this->assertEquals(4500, $testTask->getDuration()); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|