| @@ 21-86 (lines=66) @@ | ||
| 18 | ||
| 19 | class AdminFactoryTest extends AdminTestBase |
|
| 20 | { |
|
| 21 | public function testCreateFromRequest() |
|
| 22 | { |
|
| 23 | $resource = $this->getMockWithoutConstructor(AdminResource::class); |
|
| 24 | $resource |
|
| 25 | ->expects($this->atLeastOnce()) |
|
| 26 | ->method('getName') |
|
| 27 | ->willReturn('MyLittleTaunTaun') |
|
| 28 | ; |
|
| 29 | ||
| 30 | $resourceCollection = $this->getMockWithoutConstructor(ResourceCollection::class); |
|
| 31 | $resourceCollection |
|
| 32 | ->expects($this->once()) |
|
| 33 | ->method('has') |
|
| 34 | ->with('MyLittleTaunTaun') |
|
| 35 | ->willReturn(true) |
|
| 36 | ; |
|
| 37 | $resourceCollection |
|
| 38 | ->expects($this->once()) |
|
| 39 | ->method('get') |
|
| 40 | ->with('MyLittleTaunTaun') |
|
| 41 | ->willReturn($resource) |
|
| 42 | ; |
|
| 43 | ||
| 44 | $adminConfiguration = $this->getMockWithoutConstructor(AdminConfiguration::class); |
|
| 45 | $adminConfiguration |
|
| 46 | ->expects($this->once()) |
|
| 47 | ->method('getParameter') |
|
| 48 | ->with('class') |
|
| 49 | ->willReturn(Admin::class) |
|
| 50 | ; |
|
| 51 | ||
| 52 | $configurationFactory = $this->getMockWithoutConstructor(ConfigurationFactory::class); |
|
| 53 | $configurationFactory |
|
| 54 | ->expects($this->once()) |
|
| 55 | ->method('createAdminConfiguration') |
|
| 56 | ->with('MyLittleTaunTaun') |
|
| 57 | ->willReturn($adminConfiguration) |
|
| 58 | ; |
|
| 59 | ||
| 60 | $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class); |
|
| 61 | ||
| 62 | $applicationConfiguration = new ApplicationConfiguration(); |
|
| 63 | $applicationConfigurationStorage = $this->getMockWithoutConstructor(ApplicationConfigurationStorage::class); |
|
| 64 | $applicationConfigurationStorage |
|
| 65 | ->expects($this->once()) |
|
| 66 | ->method('getConfiguration') |
|
| 67 | ->willReturn($applicationConfiguration) |
|
| 68 | ; |
|
| 69 | ||
| 70 | $request = new Request([ |
|
| 71 | '_admin' => 'MyLittleTaunTaun', |
|
| 72 | '_route_params' => [ |
|
| 73 | '_admin' => 'MyLittleTaunTaun', |
|
| 74 | '_action' => 'jump', |
|
| 75 | ], |
|
| 76 | ]); |
|
| 77 | ||
| 78 | $adminFactory = new AdminFactory( |
|
| 79 | $resourceCollection, |
|
| 80 | $eventDispatcher, |
|
| 81 | $configurationFactory, |
|
| 82 | $applicationConfigurationStorage |
|
| 83 | ); |
|
| 84 | ||
| 85 | $adminFactory->createFromRequest($request); |
|
| 86 | } |
|
| 87 | ||
| 88 | public function testCreateFromRequestWithoutRouteParams() |
|
| 89 | { |
|
| @@ 155-221 (lines=67) @@ | ||
| 152 | $adminFactory->createFromRequest($request); |
|
| 153 | } |
|
| 154 | ||
| 155 | public function testCreateFromRequestWithInvalidAdminClass() |
|
| 156 | { |
|
| 157 | $resource = $this->getMockWithoutConstructor(AdminResource::class); |
|
| 158 | $resource |
|
| 159 | ->expects($this->atLeastOnce()) |
|
| 160 | ->method('getName') |
|
| 161 | ->willReturn('MyLittleTaunTaun') |
|
| 162 | ; |
|
| 163 | ||
| 164 | $resourceCollection = $this->getMockWithoutConstructor(ResourceCollection::class); |
|
| 165 | $resourceCollection |
|
| 166 | ->expects($this->once()) |
|
| 167 | ->method('has') |
|
| 168 | ->with('MyLittleTaunTaun') |
|
| 169 | ->willReturn(true) |
|
| 170 | ; |
|
| 171 | $resourceCollection |
|
| 172 | ->expects($this->once()) |
|
| 173 | ->method('get') |
|
| 174 | ->with('MyLittleTaunTaun') |
|
| 175 | ->willReturn($resource) |
|
| 176 | ; |
|
| 177 | ||
| 178 | $adminConfiguration = $this->getMockWithoutConstructor(AdminConfiguration::class); |
|
| 179 | $adminConfiguration |
|
| 180 | ->expects($this->once()) |
|
| 181 | ->method('getParameter') |
|
| 182 | ->with('class') |
|
| 183 | ->willReturn(FakeAdmin::class) |
|
| 184 | ; |
|
| 185 | ||
| 186 | $configurationFactory = $this->getMockWithoutConstructor(ConfigurationFactory::class); |
|
| 187 | $configurationFactory |
|
| 188 | ->expects($this->once()) |
|
| 189 | ->method('createAdminConfiguration') |
|
| 190 | ->with('MyLittleTaunTaun') |
|
| 191 | ->willReturn($adminConfiguration) |
|
| 192 | ; |
|
| 193 | ||
| 194 | $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class); |
|
| 195 | ||
| 196 | $applicationConfiguration = new ApplicationConfiguration(); |
|
| 197 | $applicationConfigurationStorage = $this->getMockWithoutConstructor(ApplicationConfigurationStorage::class); |
|
| 198 | $applicationConfigurationStorage |
|
| 199 | ->expects($this->once()) |
|
| 200 | ->method('getConfiguration') |
|
| 201 | ->willReturn($applicationConfiguration) |
|
| 202 | ; |
|
| 203 | ||
| 204 | $request = new Request([ |
|
| 205 | '_admin' => 'MyLittleTaunTaun', |
|
| 206 | '_route_params' => [ |
|
| 207 | '_admin' => 'MyLittleTaunTaun', |
|
| 208 | '_action' => 'jump', |
|
| 209 | ], |
|
| 210 | ]); |
|
| 211 | ||
| 212 | $adminFactory = new AdminFactory( |
|
| 213 | $resourceCollection, |
|
| 214 | $eventDispatcher, |
|
| 215 | $configurationFactory, |
|
| 216 | $applicationConfigurationStorage |
|
| 217 | ); |
|
| 218 | ||
| 219 | $this->expectException(Exception::class); |
|
| 220 | $adminFactory->createFromRequest($request); |
|
| 221 | } |
|
| 222 | } |
|
| 223 | ||