Exemplo n.º 1
0
 /**
  * Testing default param values are handled correctly.
  */
 public function testDefaultParamValues()
 {
     $_SERVER['REQUEST_URI'] = '/';
     $front = new FrontController();
     $front->addRoute('/one/{param}', function ($request) {
         return new Response(200, $request->getParam('param'));
     })->value('param', 'blah');
     $request = new Request(array('method' => 'GET', 'URI' => '/one'));
     $response = $front->process($request);
     $this->assertEquals('blah', $response->getBody(), 'Testing default param values are handled correctly');
     $front->addRoute('/two/{param1}/{param2}', function ($request) {
         return new Response(200, $request->getParam('param1') . ' ' . $request->getParam('param2'));
     })->value('param1', 'two')->value('param2', 'params');
     $request = new Request(array('method' => 'GET', 'URI' => '/two'));
     $response = $front->process($request);
     $this->assertEquals('two params', $response->getBody(), 'Testing default param values are handled correctly');
     $request = new Request(array('method' => 'GET', 'URI' => '/two/two'));
     $response = $front->process($request);
     $this->assertEquals('two params', $response->getBody(), 'Testing default param values are handled correctly');
     $front->addRoute('/three/{param1}/params/{param2}/{param3}', function ($request) {
         return new Response(200, $request->getParam('param1') . ' ' . $request->getParam('param2'));
     })->value('param1', 'has')->value('param2', 'three')->value('param3', 'params');
     $request = new Request(array('method' => 'GET', 'URI' => '/three/has/params'));
     $response = $front->process($request);
     $this->assertEquals('has three', $response->getBody(), 'Testing default param values are handled correctly');
 }
Exemplo n.º 2
0
 /**
  * Testing that we can override the HTTP method via X-HTTP-Method-Override or _METHOD.
  */
 public function testHTTPMethodOverride()
 {
     $front = new FrontController();
     $front->addRoute('/image', function ($request) {
         $controller = new ImageController();
         return $controller->process($request);
     });
     $request = new Request(array('method' => 'DELETE', 'URI' => '/image'));
     try {
         $response = $front->process($request);
         $this->fail('Testing that we can override the HTTP method via X-HTTP-Method-Override or _METHOD');
     } catch (\Exception $e) {
         $this->assertEquals('The DELETE method is not supported by this controller', $e->getMessage(), 'Testing that we can override the HTTP method via X-HTTP-Method-Override or _METHOD');
     }
     $_POST['_METHOD'] = 'OPTIONS';
     $request = new Request(array('method' => 'DELETE', 'URI' => '/image'));
     $response = $front->process($request);
     $this->assertEquals(200, $response->getStatus(), 'Testing that we can override the HTTP method via X-HTTP-Method-Override or _METHOD');
     $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'OPTIONS';
     $request = new Request(array('method' => 'DELETE', 'URI' => '/image'));
     $response = $front->process($request);
     $this->assertEquals(200, $response->getStatus(), 'Testing that we can override the HTTP method via X-HTTP-Method-Override or _METHOD');
 }