public function testGetPostNamedArray() { // Mock $this->mockPost('test', array("one" => "testValue", "two" => "testValue2")); $this->assertEquals('testValue', $this->object->getPost('test', "one")); $this->assertEquals('testValue2', $this->object->getPost('test', "two")); }
/** * Invalid encoding test. * @return void */ public function testInvalidEncoding() { define('INVALID', "vÄž"); define('CONTROL_CHARACTERS', "AB€C"); $_GET = array('invalid' => INVALID, 'control' => CONTROL_CHARACTERS, INVALID => 1, CONTROL_CHARACTERS => 1, 'array' => array(INVALID => 1)); $_POST = array('invalid' => INVALID, 'control' => CONTROL_CHARACTERS, INVALID => 1, CONTROL_CHARACTERS => 1, 'array' => array(INVALID => 1)); $_COOKIE = array('invalid' => INVALID, 'control' => CONTROL_CHARACTERS, INVALID => 1, CONTROL_CHARACTERS => 1, 'array' => array(INVALID => 1)); $_FILES = array(INVALID => array('name' => 'readme.txt', 'type' => 'text/plain', 'tmp_name' => 'C:\\PHP\\temp\\php1D5B.tmp', 'error' => 0, 'size' => 209), CONTROL_CHARACTERS => array('name' => 'readme.txt', 'type' => 'text/plain', 'tmp_name' => 'C:\\PHP\\temp\\php1D5B.tmp', 'error' => 0, 'size' => 209), 'file1' => array('name' => INVALID, 'type' => 'text/plain', 'tmp_name' => 'C:\\PHP\\temp\\php1D5B.tmp', 'error' => 0, 'size' => 209)); $request = new HttpRequest(); $this->assertEquals(INVALID, $request->getQuery('invalid')); $this->assertEquals(CONTROL_CHARACTERS, $request->getQuery('control')); $this->assertEquals('1', $request->getQuery(INVALID)); $this->assertEquals('1', $request->getQuery(CONTROL_CHARACTERS)); $this->assertEquals('1', $request->query['array'][INVALID]); $this->assertEquals(INVALID, $request->getPost('invalid')); $this->assertEquals(CONTROL_CHARACTERS, $request->getPost('control')); $this->assertEquals('1', $request->getPost(INVALID)); $this->assertEquals('1', $request->getPost(CONTROL_CHARACTERS)); $this->assertEquals('1', $request->post['array'][INVALID]); $this->assertEquals(INVALID, $request->getCookie('invalid')); $this->assertEquals(CONTROL_CHARACTERS, $request->getCookie('control')); $this->assertEquals('1', $request->getCookie(INVALID)); $this->assertEquals('1', $request->getCookie(CONTROL_CHARACTERS)); $this->assertEquals('1', $request->cookies['array'][INVALID]); $this->assertType('HttpUploadedFile', $request->getFile(INVALID)); $this->assertType('HttpUploadedFile', $request->getFile(CONTROL_CHARACTERS)); $this->assertType('HttpUploadedFile', $request->files['file1']); // filter data $request->setEncoding('UTF-8'); $this->assertEquals("vž", $request->getQuery('invalid')); $this->assertEquals('ABC', $request->getQuery('control')); $this->assertNull($request->getQuery(INVALID)); $this->assertNull($request->getQuery(CONTROL_CHARACTERS)); $this->assertFalse(isset($request->query['array'][INVALID])); $this->assertEquals("vž", $request->getPost('invalid')); $this->assertEquals('ABC', $request->getPost('control')); $this->assertNull($request->getPost(INVALID)); $this->assertNull($request->getPost(CONTROL_CHARACTERS)); $this->assertFalse(isset($request->post['array'][INVALID])); $this->assertEquals("vž", $request->getCookie('invalid')); $this->assertEquals('ABC', $request->getCookie('control')); $this->assertNull($request->getCookie(INVALID)); $this->assertNull($request->getCookie(CONTROL_CHARACTERS)); $this->assertFalse(isset($request->cookies['array'][INVALID])); $this->assertNull($request->getFile(INVALID)); $this->assertNull($request->getFile(CONTROL_CHARACTERS)); $this->assertType('HttpUploadedFile', $request->files['file1']); $this->assertEquals("vž", $request->files['file1']->name); }
public function chooseAction(HttpRequest $request) { $action = Primitive::choice('action')->setList($this->methodMap); if ($this->getDefaultAction()) { $action->setDefault($this->getDefaultAction()); } Form::create()->add($action)->import($request->getGet())->importMore($request->getPost())->importMore($request->getAttached()); if (!($command = $action->getValue())) { return $action->getDefault(); } return $command; }
public function handleRequest(HttpRequest $request) { $form = Form::create()->add(Primitive::string('username')->setMax(64)->required())->add(Primitive::string('password')->addImportFilter(Filter::hash())->required())->import($request->getPost()); if (!$form->getErrors()) { try { $admin = Administrator::dao()->logIn($form->getValue('username'), $form->getValue('password')); } catch (ObjectNotFoundException $e) { // failed to log in return ModelAndView::create()->setView('error'); } if (!Session::isStarted()) { Session::start(); } Session::assign(Administrator::LABEL, $admin); return ModelAndView::create()->setView(new RedirectToView('main')); } return ModelAndView::create()->setView('login'); }
private function getPostFields(HttpRequest $request) { if ($request->hasBody()) { return $request->getBody(); } else { if ($this->oldUrlConstructor) { return UrlParamsUtils::toStringOneDeepLvl($request->getPost()); } else { $fileList = array_map(array($this, 'fileFilter'), UrlParamsUtils::toParamsList($request->getFiles())); if (empty($fileList)) { return UrlParamsUtils::toString($request->getPost()); } else { $postList = UrlParamsUtils::toParamsList($request->getPost()); if (!is_null($atParam = $this->findAtParamInPost($postList))) { throw new NetworkException('Security excepion: not allowed send post param ' . $atParam . ' which begins from @ in request which contains files'); } return array_merge($postList, $fileList); } } } }
protected function makeHandle(HttpRequest $request, CurlHttpResponse $response) { $handle = curl_init(); Assert::isNotNull($request->getMethod()); $options = array(CURLOPT_WRITEFUNCTION => array($response, 'writeBody'), CURLOPT_HEADERFUNCTION => array($response, 'writeHeader'), CURLOPT_URL => $request->getUrl()->toString(), CURLOPT_USERAGENT => 'onPHP::' . __CLASS__); if ($this->noBody !== null) { $options[CURLOPT_NOBODY] = $this->noBody; } if ($this->followLocation !== null) { $options[CURLOPT_FOLLOWLOCATION] = $this->followLocation; } switch ($request->getMethod()->getId()) { case HttpMethod::GET: $options[CURLOPT_HTTPGET] = true; if ($request->getGet()) { $options[CURLOPT_URL] .= ($request->getUrl()->getQuery() ? '&' : '?') . $this->argumentsToString($request->getGet()); } break; case HttpMethod::POST: $options[CURLOPT_POST] = true; $options[CURLOPT_POSTFIELDS] = $this->argumentsToString($request->getPost()); break; default: $options[CURLOPT_CUSTOMREQUEST] = $request->getMethod()->getName(); break; } $headers = array(); foreach ($request->getHeaderList() as $headerName => $headerValue) { $headers[] = "{$headerName}: {$headerValue}"; } if ($headers) { $options[CURLOPT_HTTPHEADER] = $headers; } if ($request->getCookie()) { $cookies = array(); foreach ($request->getCookie() as $name => $value) { $cookies[] = $name . '=' . urlencode($value); } $options[CURLOPT_COOKIE] = implode('; ', $cookies); } foreach ($this->options as $key => $value) { $options[$key] = $value; } curl_setopt_array($handle, $options); return $handle; }