1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JhFlexiTimeTest\Listener; |
4
|
|
|
|
5
|
|
|
use JhFlexiTime\Entity\UserSettings; |
6
|
|
|
use JhFlexiTime\Listener\BookingSaveListener; |
7
|
|
|
use JhFlexiTime\Options\ModuleOptions; |
8
|
|
|
use JhFlexiTime\Entity\RunningBalance; |
9
|
|
|
use JhUser\Entity\User; |
10
|
|
|
use ZfcUser\Entity\UserInterface; |
11
|
|
|
use Zend\EventManager\Event; |
12
|
|
|
use JhFlexiTime\Entity\Booking; |
13
|
|
|
use JhFlexiTime\DateTime\DateTime; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class BookingSaveListenerTest |
17
|
|
|
* @package JhFlexiTimeTest\Listener |
18
|
|
|
* @author Aydin Hassan <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class BookingSaveListenerTest extends \PHPUnit_Framework_TestCase |
21
|
|
|
{ |
22
|
|
|
protected $bookingSaveListener; |
23
|
|
|
protected $runningBalanceService; |
24
|
|
|
|
25
|
|
|
public function setUp() |
26
|
|
|
{ |
27
|
|
|
$this->runningBalanceService = $this->getMockBuilder('JhFlexiTime\Service\RunningBalanceService') |
28
|
|
|
->disableOriginalConstructor() |
29
|
|
|
->getMock(); |
30
|
|
|
|
31
|
|
|
$this->bookingSaveListener = new BookingSaveListener( |
32
|
|
|
new DateTime("12 April 2014"), |
33
|
|
|
$this->runningBalanceService |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testAttach() |
38
|
|
|
{ |
39
|
|
|
$eventManager = $this->getMock('Zend\EventManager\EventManagerInterface'); |
40
|
|
|
$sharedManager = $this->getMock('Zend\EventManager\SharedEventManagerInterface'); |
41
|
|
|
|
42
|
|
|
$eventManager |
43
|
|
|
->expects($this->once()) |
44
|
|
|
->method('getSharedManager') |
45
|
|
|
->will($this->returnValue($sharedManager)); |
46
|
|
|
|
47
|
|
|
$sharedManager |
48
|
|
|
->expects($this->at(0)) |
49
|
|
|
->method('attach') |
50
|
|
|
->with( |
51
|
|
|
'JhFlexiTime\Service\BookingService', |
52
|
|
|
'create.post', |
53
|
|
|
[$this->bookingSaveListener, 'reindexBalance'], |
54
|
|
|
100 |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
$sharedManager |
58
|
|
|
->expects($this->at(1)) |
59
|
|
|
->method('attach') |
60
|
|
|
->with( |
61
|
|
|
'JhFlexiTime\Service\BookingService', |
62
|
|
|
'update.post', |
63
|
|
|
[$this->bookingSaveListener, 'reindexBalance'], |
64
|
|
|
100 |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$sharedManager |
68
|
|
|
->expects($this->at(2)) |
69
|
|
|
->method('attach') |
70
|
|
|
->with( |
71
|
|
|
'JhFlexiTime\Service\BookingService', |
72
|
|
|
'delete.post', |
73
|
|
|
[$this->bookingSaveListener, 'reindexBalance'], |
74
|
|
|
100 |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
$this->bookingSaveListener->attach($eventManager); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testIfBookingHasDateInPreviousMonthReIndexerIsCalled() |
81
|
|
|
{ |
82
|
|
|
$user = new User; |
83
|
|
|
$booking = new Booking; |
84
|
|
|
$booking->setDate(new DateTime('11 March 2014')); |
85
|
|
|
$booking->setUser($user); |
86
|
|
|
|
87
|
|
|
$this->runningBalanceService |
88
|
|
|
->expects($this->once()) |
89
|
|
|
->method('reIndexIndividualUserRunningBalance') |
90
|
|
|
->with($user); |
91
|
|
|
|
92
|
|
|
$e = new Event(); |
93
|
|
|
$e->setParam('booking', $booking); |
94
|
|
|
|
95
|
|
|
$this->bookingSaveListener->reindexBalance($e); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|