private function initComponents() { /*{{{*/ $factory = new \Vine\Component\Http\RequestFactory(); $request = $factory->make(); $router = new \Vine\Component\Routing\Router(); $this->container->setRequest($request)->setRouter($router)->setErrorControllerName('error')->setErrorActionName('index'); }
public function testHttpRequestDetector() { // Setup environment $_SERVER = array('HTTPS' => 'On', 'HTTP_HOST' => 'vine.org:8080', 'QUERY_STRING' => 'x param=val.&pa%%72am=val2¶m3=v%20a%26l%3Du%2Be', 'REMOTE_ADDR' => '192.168.188.66', 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/file.php?x param=val.&pa%%72am=val2"es\\"=\\"¶m3=v%20a%26l%3Du%2Be', 'SCRIPT_NAME' => '/file.php'); $factory = new \Vine\Component\Http\RequestFactory(); $httpRequest = $factory->make(); $this->assertEquals('GET', $httpRequest->getMethod()); $this->assertTrue($httpRequest->isSecured()); $this->assertEquals('192.168.188.66', $httpRequest->getRemoteAddress()); $this->assertEquals('val.', $httpRequest->getQuery('x_param')); // $this->assertEquals('val.', $httpRequest->getParam('x_param')); }
public function testHttpValidatorParseRequestDetector() { $name = 'app_name'; $requestFactory = new \Vine\Component\Http\RequestFactory(); $request = $requestFactory->make(); $validator = new \Vine\Component\Validator\Validator(); $conf = $validator->getConf(); $conf->setParamType($name, \Vine\Component\Validator\Validator::TYPE_STR); $conf->setParamDefaultValue($name, 'name'); $conf->setParamCheckFunc($name, array('\\Vine\\Component\\Http\\Validator\\Checker', 'strNotNull'), array("maxLen" => 12, "minLen" => 5)); $conf->setParamExceptionParams($name, 'app_name不正确', 1003); $_GET = array('appdesc' => 'framework', 'app_name' => 'vine'); $originParams = $request->getParam(); $validator->filterParams($originParams); $this->assertEquals(array('app_name' => 'vine'), $validator->getFilterParams()); $this->assertArrayHasKey('app_name', $validator->getFilterParams()); $this->assertArrayNotHasKey('app_desc', $validator->getFilterParams()); $originParams = array('appdesc' => 'framework', 'app_name' => 'vine-framework'); $validator->filterParams($originParams); $this->assertEquals(array('app_name' => 'vine-framework'), $validator->getFilterParams()); }