1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JhUserTest; |
4
|
|
|
|
5
|
|
|
use JhUser\Entity\HierarchicalRole; |
6
|
|
|
use JhUser\Entity\User; |
7
|
|
|
use Zend\ServiceManager\ServiceManager; |
8
|
|
|
use JhUser\Module; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ModuleTest |
12
|
|
|
* @package JhUserTest |
13
|
|
|
* @author Aydin Hassan <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class ModuleTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \Zend\Mvc\Application |
20
|
|
|
*/ |
21
|
|
|
protected $application; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var \Zend\EventManager\EventManagerInterface |
25
|
|
|
*/ |
26
|
|
|
protected $eventManager; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var \Zend\EventManager\SharedEventManagerInterface |
30
|
|
|
*/ |
31
|
|
|
protected $sharedEventManager; |
32
|
|
|
|
33
|
|
|
public function testGetConfig() |
34
|
|
|
{ |
35
|
|
|
$module = new Module(); |
36
|
|
|
|
37
|
|
|
$this->assertInternalType('array', $module->getConfig()); |
38
|
|
|
$this->assertSame($module->getConfig(), unserialize(serialize($module->getConfig())), 'Config is serializable'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testDependency() |
42
|
|
|
{ |
43
|
|
|
$module = new Module(); |
44
|
|
|
$dependencies = [ |
45
|
|
|
'DoctrineModule', |
46
|
|
|
'DoctrineORMModule', |
47
|
|
|
'ZfcUser', |
48
|
|
|
'ZfcUserDoctrineORM', |
49
|
|
|
'ScnSocialAuthDoctrineORM', |
50
|
|
|
]; |
51
|
|
|
$this->assertEquals($dependencies, $module->getModuleDependencies()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testConsoleUsage() |
55
|
|
|
{ |
56
|
|
|
$mockConsole = $this->getMock('Zend\Console\Adapter\AdapterInterface'); |
57
|
|
|
$module = new Module(); |
58
|
|
|
|
59
|
|
|
$expected = ['set role <userEmail> <role>' => 'Set a user\'s role']; |
60
|
|
|
$this->assertSame($expected, $module->getConsoleUsage($mockConsole)); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testListenersAreRegistered() |
64
|
|
|
{ |
65
|
|
|
$event = $this->getEvent(true); |
66
|
|
|
|
67
|
|
|
$module = new Module(); |
68
|
|
|
$this->sharedEventManager |
|
|
|
|
69
|
|
|
->expects($this->at(0)) |
70
|
|
|
->method('attach') |
71
|
|
|
->with('ScnSocialAuth\Authentication\Adapter\HybridAuth', 'registerViaProvider', [$module, 'onRegister']); |
72
|
|
|
|
73
|
|
|
$this->sharedEventManager |
|
|
|
|
74
|
|
|
->expects($this->at(1)) |
75
|
|
|
->method('attach') |
76
|
|
|
->with('ZfcUser\Service\User', 'register', [$module, 'onRegister']); |
77
|
|
|
|
78
|
|
|
$module->onBootstrap($event); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testOnRegisterSuccessfullyAddsDefaultRole() |
82
|
|
|
{ |
83
|
|
|
$event = $this->getEvent(); |
84
|
|
|
$mockObjectManager = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); |
85
|
|
|
|
86
|
|
|
$serviceLocator = new ServiceManager(); |
87
|
|
|
$serviceLocator->setService('JhUser\ObjectManager', $mockObjectManager); |
88
|
|
|
|
89
|
|
|
$this->application->expects($this->any()) |
|
|
|
|
90
|
|
|
->method('getServiceManager') |
91
|
|
|
->will($this->returnValue($serviceLocator)); |
92
|
|
|
|
93
|
|
|
$role = new HierarchicalRole(); |
94
|
|
|
$roleRepository = $this->getMock('JhUser\Repository\RoleRepositoryInterface'); |
95
|
|
|
$roleRepository |
96
|
|
|
->expects($this->once()) |
97
|
|
|
->method('findByName') |
98
|
|
|
->with('user') |
99
|
|
|
->will($this->returnValue($role)); |
100
|
|
|
|
101
|
|
|
$serviceLocator->setService('JhUser\Repository\RoleRepository', $roleRepository); |
102
|
|
|
|
103
|
|
|
$mockObjectManager |
104
|
|
|
->expects($this->once()) |
105
|
|
|
->method('flush'); |
106
|
|
|
|
107
|
|
|
$user = $this->getMock('JhUser\Entity\User'); |
108
|
|
|
$user |
109
|
|
|
->expects($this->once()) |
110
|
|
|
->method('addRole') |
111
|
|
|
->with($role) |
112
|
|
|
->will($this->returnSelf()); |
113
|
|
|
|
114
|
|
|
$event |
115
|
|
|
->expects($this->once()) |
116
|
|
|
->method('getParam') |
117
|
|
|
->with('user') |
118
|
|
|
->will($this->returnValue($user)); |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
$module = new Module(); |
122
|
|
|
$module->onRegister($event); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param bool $addEventManager |
127
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
128
|
|
|
*/ |
129
|
|
|
private function getEvent($addEventManager = false) |
130
|
|
|
{ |
131
|
|
|
|
132
|
|
|
$this->eventManager = $this->getMock('Zend\EventManager\EventManagerInterface'); |
133
|
|
|
$this->sharedEventManager = $this->getMock('Zend\EventManager\SharedEventManagerInterface'); |
134
|
|
|
$this->application = $this->getMock('Zend\Mvc\Application', [], [], '', false); |
135
|
|
|
|
136
|
|
|
if ($addEventManager) { |
137
|
|
|
$this->application->expects($this->any()) |
138
|
|
|
->method('getEventManager') |
139
|
|
|
->will($this->returnValue($this->eventManager)); |
140
|
|
|
|
141
|
|
|
$this->eventManager |
142
|
|
|
->expects($this->once()) |
143
|
|
|
->method('getSharedManager') |
144
|
|
|
->will($this->returnValue($this->sharedEventManager)); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
$event = $this->getMock('Zend\EventManager\EventInterface'); |
148
|
|
|
$event->expects($this->any())->method('getTarget')->will($this->returnValue($this->application)); |
149
|
|
|
|
150
|
|
|
return $event; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.