|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JhFlexiTimeTest\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Zend\Http\Request; |
|
6
|
|
|
use Zend\Http\Response; |
|
7
|
|
|
use Zend\Mvc\MvcEvent; |
|
8
|
|
|
use Zend\Mvc\Router\RouteMatch; |
|
9
|
|
|
use Zend\Mvc\Router\Http\TreeRouteStack as HttpRouter; |
|
10
|
|
|
use JhFlexiTimeTest\Util\ServiceManagerFactory; |
|
11
|
|
|
use JhFlexiTime\Controller\SettingsController; |
|
12
|
|
|
use JhFlexiTime\Options\BookingOptions; |
|
13
|
|
|
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class SettingsControllerTest |
|
17
|
|
|
* @package JhFlexiTimeTest\Controller |
|
18
|
|
|
* @author Aydin Hassan <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
class SettingsControllerTest extends AbstractHttpControllerTestCase |
|
21
|
|
|
{ |
|
22
|
|
|
protected $controller; |
|
23
|
|
|
protected $routeMatch; |
|
24
|
|
|
protected $event; |
|
25
|
|
|
protected $request; |
|
26
|
|
|
protected $response; |
|
27
|
|
|
protected $user; |
|
28
|
|
|
|
|
29
|
|
|
public function setUp() |
|
30
|
|
|
{ |
|
31
|
|
|
$options = new BookingOptions([ |
|
32
|
|
|
'min_start_time' => '07:00', |
|
33
|
|
|
'max_start_time' => '10:00', |
|
34
|
|
|
'min_end_time' => '16:00', |
|
35
|
|
|
'max_end_time' => '17:00', |
|
36
|
|
|
]); |
|
37
|
|
|
$this->controller = new SettingsController($options); |
|
38
|
|
|
|
|
39
|
|
|
$this->request = new Request(); |
|
40
|
|
|
$this->routeMatch = new RouteMatch(['controller' => 'settings']); |
|
41
|
|
|
$this->event = new MvcEvent(); |
|
42
|
|
|
|
|
43
|
|
|
$serviceManager = ServiceManagerFactory::getServiceManager(); |
|
44
|
|
|
$config = $serviceManager->get('Config'); |
|
45
|
|
|
$routerConfig = isset($config['router']) ? $config['router'] : []; |
|
46
|
|
|
$router = HttpRouter::factory($routerConfig); |
|
47
|
|
|
$this->event->setRouter($router); |
|
48
|
|
|
$this->event->setRouteMatch($this->routeMatch); |
|
49
|
|
|
$this->controller->setEvent($this->event); |
|
50
|
|
|
|
|
51
|
|
|
$this->mockAuth(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function mockAuth() |
|
55
|
|
|
{ |
|
56
|
|
|
$ZfcUserMock = $this->getMock('ZfcUser\Entity\UserInterface'); |
|
57
|
|
|
|
|
58
|
|
|
$ZfcUserMock->expects($this->any()) |
|
59
|
|
|
->method('getId') |
|
60
|
|
|
->will($this->returnValue('1')); |
|
61
|
|
|
|
|
62
|
|
|
$authMock = $this->getMock('ZfcUser\Controller\Plugin\ZfcUserAuthentication'); |
|
63
|
|
|
|
|
64
|
|
|
$authMock->expects($this->any()) |
|
65
|
|
|
->method('hasIdentity') |
|
66
|
|
|
-> will($this->returnValue(true)); |
|
67
|
|
|
|
|
68
|
|
|
$authMock->expects($this->any()) |
|
69
|
|
|
->method('getIdentity') |
|
70
|
|
|
->will($this->returnValue($ZfcUserMock)); |
|
71
|
|
|
|
|
72
|
|
|
$this->controller->getPluginManager() |
|
73
|
|
|
->setService('zfcUserAuthentication', $authMock); |
|
74
|
|
|
|
|
75
|
|
|
$this->user = $ZfcUserMock; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testGetActionCanBeAccessed() |
|
79
|
|
|
{ |
|
80
|
|
|
$this->routeMatch->setParam('action', 'get'); |
|
81
|
|
|
$result = $this->controller->dispatch($this->request); |
|
82
|
|
|
$response = $this->controller->getResponse(); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
|
85
|
|
|
$this->assertInstanceOf('Zend\View\Model\JsonModel', $result); |
|
86
|
|
|
$this->assertTrue(isset($result->success)); |
|
87
|
|
|
$this->assertTrue(isset($result->settings)); |
|
88
|
|
|
|
|
89
|
|
|
$expectedSettings = [ |
|
90
|
|
|
'min_start_time' => '07:00', |
|
91
|
|
|
'max_start_time' => '10:00', |
|
92
|
|
|
'min_end_time' => '16:00', |
|
93
|
|
|
'max_end_time' => '17:00', |
|
94
|
|
|
]; |
|
95
|
|
|
$this->assertEquals($result->settings->toArray(), $expectedSettings); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|