1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JhFlexiTimeTest\Options; |
4
|
|
|
|
5
|
|
|
use JhFlexiTime\DateTime\DateTime; |
6
|
|
|
use JhFlexiTime\Options\ModuleOptions; |
7
|
|
|
use Zend\ModuleManager\ModuleManager; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class ModuleOptionsTest |
11
|
|
|
* @package JhFlexiTime\ModuleOptions\ModuleOptionsTest |
12
|
|
|
* @author Aydin Hassan <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class ModuleOptionsTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Test The default options are correct |
18
|
|
|
*/ |
19
|
|
|
public function testDefaults() |
20
|
|
|
{ |
21
|
|
|
$options = new ModuleOptions(); |
22
|
|
|
$this->assertTrue($options->getSkipWeekends(), 'skip_weekends must default to true'); |
23
|
|
|
$this->assertTrue($options->skipWeekends(), 'skip_weekends must default to true'); |
24
|
|
|
$this->assertEquals(7.5, $options->getHoursInDay(), 'hours_in_day must default to 7.5'); |
25
|
|
|
$this->assertEquals(1, $options->getLunchDuration(), 'lunch_duration must default to 1'); |
26
|
|
|
$this->assertFalse($options->getCreditCapEnabled()); |
27
|
|
|
$this->assertFalse($options->creditCapEnabled()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testSetValues() |
31
|
|
|
{ |
32
|
|
|
$options = new ModuleOptions([ |
33
|
|
|
'skip_weekends' => false, |
34
|
|
|
'hours_in_day' => 10, |
35
|
|
|
'lunch_duration' => 0.5, |
36
|
|
|
'credit_cap_enabled' => true, |
37
|
|
|
]); |
38
|
|
|
|
39
|
|
|
$this->assertFalse($options->getSkipWeekends(), 'skip_weekends must be false'); |
40
|
|
|
$this->assertFalse($options->skipWeekends(), 'skip_weekends must be false'); |
41
|
|
|
$this->assertEquals(10, $options->getHoursInDay(), 'hours_in_day must be equal to 10'); |
42
|
|
|
$this->assertEquals(0.5, $options->getLunchDuration(), 'lunch_duration must be equal to 0.5'); |
43
|
|
|
$this->assertTrue($options->getCreditCapEnabled()); |
44
|
|
|
$this->assertTrue($options->creditCapEnabled()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testCreditCaps() |
48
|
|
|
{ |
49
|
|
|
$options = new ModuleOptions; |
50
|
|
|
$this->assertEquals([], $options->getCreditCaps()); |
51
|
|
|
|
52
|
|
|
$options = new ModuleOptions([ |
53
|
|
|
'credit_caps' => [ |
54
|
|
|
'10-2015' => 7.5, |
55
|
|
|
'07-2014' => 20, |
56
|
|
|
'11-2015' => 6, |
57
|
|
|
], |
58
|
|
|
]); |
59
|
|
|
|
60
|
|
|
$expectsCaps = [ |
61
|
|
|
[ |
62
|
|
|
'month' => new DateTime('01-07-2014 00:00:00'), |
63
|
|
|
'limit' => 20, |
64
|
|
|
], |
65
|
|
|
[ |
66
|
|
|
'month' => new DateTime('01-10-2015 00:00:00'), |
67
|
|
|
'limit' => 7.5, |
68
|
|
|
], |
69
|
|
|
[ |
70
|
|
|
'month' => new DateTime('01-11-2015 00:00:00'), |
71
|
|
|
'limit' => 6, |
72
|
|
|
], |
73
|
|
|
]; |
74
|
|
|
|
75
|
|
|
$this->assertEquals($expectsCaps, $options->getCreditCaps()); |
76
|
|
|
|
77
|
|
|
$this->assertEquals(6, $options->getCreditCapForDate(new DateTime("12-12-2015"))); |
78
|
|
|
$this->assertEquals(7.5, $options->getCreditCapForDate(new DateTime("31-10-2015"))); |
79
|
|
|
$this->assertEquals(20, $options->getCreditCapForDate(new DateTime("01-07-2014"))); |
80
|
|
|
$this->assertEquals(20, $options->getCreditCapForDate(new DateTime("30-09-2014"))); |
81
|
|
|
$this->assertEquals(7.5, $options->getCreditCapForDate(new DateTime("01-10-2015"))); |
82
|
|
|
$this->assertNull($options->getCreditCapForDate(new DateTime('01-06-2014'))); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testSetCreditCapsThrowsExceptionIfDateInWrongFormat() |
86
|
|
|
{ |
87
|
|
|
$this->setExpectedException('InvalidArgumentException', 'Date should be in the format m-Y. Given: "lol"'); |
88
|
|
|
$options = new ModuleOptions; |
89
|
|
|
$options->setCreditCaps([ |
90
|
|
|
'lol' => 'lol' |
91
|
|
|
]); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|