|
@@ 188-201 (lines=14) @@
|
| 185 |
|
* Tests that when an action returns a string, the string is rendered |
| 186 |
|
* without going through the view engine. |
| 187 |
|
*/ |
| 188 |
|
public function testActionReturnsString() |
| 189 |
|
{ |
| 190 |
|
$options = array( |
| 191 |
|
Config::KEY_CONTROLLERS => array( |
| 192 |
|
'TestController' => 'Vectorface\\SnappyRouterTests\\Controller\\TestDummyController' |
| 193 |
|
), |
| 194 |
|
ControllerHandler::KEY_VIEWS => array( |
| 195 |
|
ControllerHandler::KEY_VIEWS_PATH => __DIR__.'/../Controller/Views' |
| 196 |
|
) |
| 197 |
|
); |
| 198 |
|
$handler = new ControllerHandler($options); |
| 199 |
|
$this->assertTrue($handler->isAppropriate('/test/test', array(), array(), 'GET')); |
| 200 |
|
$this->assertEquals('This is a test service.', $handler->performRoute()); |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
/** |
| 204 |
|
* Tests that when an action returns an array, the twig view is rendered |
|
@@ 207-220 (lines=14) @@
|
| 204 |
|
* Tests that when an action returns an array, the twig view is rendered |
| 205 |
|
* with the array values as the variables in the view. |
| 206 |
|
*/ |
| 207 |
|
public function testActionReturnsArray() |
| 208 |
|
{ |
| 209 |
|
$options = array( |
| 210 |
|
Config::KEY_CONTROLLERS => array( |
| 211 |
|
'TestController' => 'Vectorface\\SnappyRouterTests\\Controller\\TestDummyController' |
| 212 |
|
), |
| 213 |
|
ControllerHandler::KEY_VIEWS => array( |
| 214 |
|
ControllerHandler::KEY_VIEWS_PATH => __DIR__.'/../Controller/Views' |
| 215 |
|
) |
| 216 |
|
); |
| 217 |
|
$handler = new ControllerHandler($options); |
| 218 |
|
$this->assertTrue($handler->isAppropriate('/test/array', array(), array(), 'GET')); |
| 219 |
|
$this->assertEquals('This is a test service.', $handler->performRoute()); |
| 220 |
|
} |
| 221 |
|
|
| 222 |
|
/** |
| 223 |
|
* Tests that an action can render a different view that its default. |
|
@@ 225-238 (lines=14) @@
|
| 222 |
|
/** |
| 223 |
|
* Tests that an action can render a different view that its default. |
| 224 |
|
*/ |
| 225 |
|
public function testActionRendersNonDefaultView() |
| 226 |
|
{ |
| 227 |
|
$options = array( |
| 228 |
|
Config::KEY_CONTROLLERS => array( |
| 229 |
|
'TestController' => 'Vectorface\\SnappyRouterTests\\Controller\\TestDummyController' |
| 230 |
|
), |
| 231 |
|
ControllerHandler::KEY_VIEWS => array( |
| 232 |
|
ControllerHandler::KEY_VIEWS_PATH => __DIR__.'/../Controller/Views' |
| 233 |
|
) |
| 234 |
|
); |
| 235 |
|
$handler = new ControllerHandler($options); |
| 236 |
|
$this->assertTrue($handler->isAppropriate('/test/otherView', array(), array(), 'GET')); |
| 237 |
|
$this->assertEquals('This is a test service.', $handler->performRoute()); |
| 238 |
|
} |
| 239 |
|
|
| 240 |
|
/** |
| 241 |
|
* Tests that an exception is thrown if we "renderView" with a NullEncoder |
|
@@ 245-259 (lines=15) @@
|
| 242 |
|
* @expectedException Exception |
| 243 |
|
* @expectedExceptionMessage The current encoder does not support the render view method. |
| 244 |
|
*/ |
| 245 |
|
public function testExceptionForNullEncoderRenderView() |
| 246 |
|
{ |
| 247 |
|
$options = array( |
| 248 |
|
Config::KEY_CONTROLLERS => array( |
| 249 |
|
'TestController' => 'Vectorface\\SnappyRouterTests\\Controller\\TestDummyController' |
| 250 |
|
), |
| 251 |
|
ControllerHandler::KEY_VIEWS => array( |
| 252 |
|
ControllerHandler::KEY_VIEWS_PATH => __DIR__.'/../Controller/Views' |
| 253 |
|
) |
| 254 |
|
); |
| 255 |
|
$handler = new ControllerHandler($options); |
| 256 |
|
$this->assertTrue($handler->isAppropriate('/test/otherView', array(), array(), 'GET')); |
| 257 |
|
$handler->setEncoder(new NullEncoder()); |
| 258 |
|
$handler->performRoute(); |
| 259 |
|
} |
| 260 |
|
|
| 261 |
|
/** |
| 262 |
|
* Tests that we can use namespace provisioning to retrieve a controller. |
|
@@ 264-277 (lines=14) @@
|
| 261 |
|
/** |
| 262 |
|
* Tests that we can use namespace provisioning to retrieve a controller. |
| 263 |
|
*/ |
| 264 |
|
public function testNamespaceProvisioning() |
| 265 |
|
{ |
| 266 |
|
$options = array( |
| 267 |
|
Config::KEY_NAMESPACES => array( |
| 268 |
|
'Vectorface\\SnappyRouterTests\\Controller' |
| 269 |
|
), |
| 270 |
|
ControllerHandler::KEY_VIEWS => array( |
| 271 |
|
ControllerHandler::KEY_VIEWS_PATH => __DIR__.'/../Controller/Views' |
| 272 |
|
) |
| 273 |
|
); |
| 274 |
|
$handler = new ControllerHandler($options); |
| 275 |
|
$this->assertTrue($handler->isAppropriate('/testDummy/test', array(), array(), 'GET')); |
| 276 |
|
$this->assertEquals('This is a test service.', $handler->performRoute()); |
| 277 |
|
} |
| 278 |
|
|
| 279 |
|
/** |
| 280 |
|
* Tests that we can use folder provisioning to retrieve a controller. |
|
@@ 282-295 (lines=14) @@
|
| 279 |
|
/** |
| 280 |
|
* Tests that we can use folder provisioning to retrieve a controller. |
| 281 |
|
*/ |
| 282 |
|
public function testFolderProvisioning() |
| 283 |
|
{ |
| 284 |
|
$options = array( |
| 285 |
|
Config::KEY_FOLDERS => array( |
| 286 |
|
realpath(__DIR__.'/../Controller') |
| 287 |
|
), |
| 288 |
|
ControllerHandler::KEY_VIEWS => array( |
| 289 |
|
ControllerHandler::KEY_VIEWS_PATH => __DIR__.'/../Controller/Views' |
| 290 |
|
) |
| 291 |
|
); |
| 292 |
|
$handler = new ControllerHandler($options); |
| 293 |
|
$this->assertTrue($handler->isAppropriate('/nonNamespaced/test', array(), array(), 'GET')); |
| 294 |
|
$this->assertEquals('This is a test string.', $handler->performRoute()); |
| 295 |
|
} |
| 296 |
|
} |
| 297 |
|
|