public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array(), $options = array()) { parent::initialize($dispatcher, $parameters, $attributes, $options); if (null === self::$initialPathArrayKeys) { self::$initialPathArrayKeys = array_keys($this->getPathInfoArray()); } $this->resetPathInfoArray(); }
public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array(), $options = array()) { if (isset($options['content_custom_only_for_test'])) { $this->content = $options['content_custom_only_for_test']; unset($options['content_custom_only_for_test']); } parent::initialize($dispatcher, $parameters, $attributes, $options); if (null === self::$initialPathArrayKeys) { self::$initialPathArrayKeys = array_keys($this->getPathInfoArray()); } $this->resetPathInfoArray(); }
$t->diag('->needToRetrieveMobileUID()'); $t->ok($filter->callNeedToRetrieveMobileUID('member', 'configUID'), 'member/configUID redirects user to HTTP'); $t->ok($filter->callNeedToRetrieveMobileUID('member', 'configUID', 0), 'member/configUID does not redirects user to HTTP when it does not retrieve uid'); $t->ok(!$filter->callNeedToRetrieveMobileUID('member', 'home'), 'member/home does not redirect user to HTTP'); $t->ok(!$filter->callNeedToRetrieveMobileUID('member', 'login'), 'member/login does not redirect user to HTTP'); $t->ok($filter->callNeedToRetrieveMobileUID('member', 'login', 1, array('authMode' => 'MobileUID')), 'member/login redirect user to HTTP when the authMode is MobileUID'); $t->diag('->handleSsl()'); sfConfig::set('op_use_ssl', true); myRequest::$isSecure = false; sfConfig::set('sf_app', 'secure_application'); $t->ok($filter->callHandleSsl('anything', 'anything'), 'ssl-required-application redirects user HTTP to HTTPS'); sfConfig::set('sf_app', 'insecure_application'); $t->ok($filter->callHandleSsl('secure', 'login'), 'ssl-required-action redirects user HTTP to HTTPS'); $t->ok(!$filter->callHandleSsl('selectable', 'login'), 'ssl-selectable-action does not redirect user HTTP to HTTPS'); sfConfig::set('sf_app', 'mobile_frontend'); $t->ok(!$filter->callHandleSsl('member', 'configUID'), 'member/configUID does not redirect user HTTP to HTTPS'); $t->ok(!$filter->callHandleSsl('anything', 'anything'), 'no ssl providable action does not redirect user HTTP to HTTPS'); myRequest::$isSecure = true; sfConfig::set('sf_app', 'secure_application'); $t->ok(!$filter->callHandleSsl('anything', 'anything'), 'ssl-required-application does not redirects user HTTPS to HTTP'); sfConfig::set('sf_app', 'insecure_application'); $t->ok(!$filter->callHandleSsl('secure', 'login'), 'ssl-required-action does not redirects user HTTPS to HTTP'); $t->ok(!$filter->callHandleSsl('selectable', 'login'), 'ssl-selectable-action does not redirect user HTTPS to HTTP'); sfConfig::set('sf_app', 'mobile_frontend'); $t->ok($filter->callHandleSsl('member', 'configUID'), 'member/configUID redirect user HTTPS to HTTP'); $t->ok($filter->callHandleSsl('anything', 'anything'), 'no ssl providable action redirect user HTTPS to HTTP'); sfConfig::set('op_use_ssl', false); myRequest::$isSecure = false; $t->ok(!$filter->callHandleSsl('anything', 'anything'), 'action does not redirect user HTTP to HTTPS if op_use_ssl is "false"'); myRequest::$isSecure = true; $t->ok(!$filter->callHandleSsl('anything', 'anything'), 'action does not redirect user HTTPS to HTTP if op_use_ssl is "false"');
{ return $this->dispatcher; } } class fakeRequest { } $t = new lime_test(36); $dispatcher = new sfEventDispatcher(); // ->initialize() $t->diag('->initialize()'); $request = new myRequest($dispatcher); $t->is($dispatcher, $request->getEventDispatcher(), '->initialize() takes a sfEventDispatcher object as its first argument'); $request->initialize($dispatcher, array('foo' => 'bar')); $t->is($request->getParameter('foo'), 'bar', '->initialize() takes an array of parameters as its second argument'); $options = $request->getOptions(); $t->is($options['logging'], false, '->getOptions() returns options for request instance'); // ->getMethod() ->setMethod() $t->diag('->getMethod() ->setMethod()'); $request->setMethod(sfRequest::GET); $t->is($request->getMethod(), sfRequest::GET, '->getMethod() returns the current request method'); try { $request->setMethod('foo');
$t->is(isset($request['foo2']), false, '->offsetExists() returns false if request parameter does not exist'); $t->is($request['foo3'], false, '->offsetGet() returns false if parameter does not exist'); $t->is($request['foo'], 'foo', '->offsetGet() returns parameter by name'); $request['foo2'] = 'foo2'; $t->is($request['foo2'], 'foo2', '->offsetSet() sets parameter by name'); unset($request['foo2']); $t->is(isset($request['foo2']), false, '->offsetUnset() unsets parameter by name'); // ->getOption() $t->diag('->getOption()'); $request = new myRequest($dispatcher, array(), array(), array('val_1' => 'value', 'val_2' => false)); $t->is($request->getOption('val_1'), 'value', '->getOption() returns the option value if exists'); $t->is($request->getOption('val_2'), false, '->getOption() returns the option value if exists'); $t->is($request->getOption('none'), null, '->getOption() returns the option value if not exists'); // ->getOption() $t->diag('->__clone()'); $request = new myRequest($dispatcher); $requestClone = clone $request; $t->ok($request->getParameterHolder() !== $requestClone->getParameterHolder(), '->__clone() clone parameterHolder'); $t->ok($request->getAttributeHolder() !== $requestClone->getAttributeHolder(), '->__clone() clone attributeHolder'); $request = new myRequest($dispatcher); // parameter holder proxy require_once $_test_dir . '/unit/sfParameterHolderTest.class.php'; $pht = new sfParameterHolderProxyTest($t); $pht->launchTests($request, 'parameter'); // attribute holder proxy $pht = new sfParameterHolderProxyTest($t); $pht->launchTests($request, 'attribute'); // new methods via sfEventDispatcher require_once $_test_dir . '/unit/sfEventDispatcherTest.class.php'; $dispatcherTest = new sfEventDispatcherTest($t); $dispatcherTest->launchTests($dispatcher, $request, 'request');
{ public function getCSRFToken($secret = null) { return '==TOKEN=='; } } sfForm::enableCSRFProtection(); $request = new myRequest($dispatcher); try { $request->checkCSRFProtection(); $t->fail('->checkCSRFProtection() throws a validator error if CSRF protection fails'); } catch (sfValidatorErrorSchema $error) { $t->pass('->checkCSRFProtection() throws a validator error if CSRF protection fails'); } $request = new myRequest($dispatcher); $request->setParameter('_csrf_token', '==TOKEN=='); try { $request->checkCSRFProtection(); $t->pass('->checkCSRFProtection() checks token from BaseForm'); } catch (sfValidatorErrorSchema $error) { $t->fail('->checkCSRFProtection() checks token from BaseForm'); } // ->getContentType() $t->diag('->getContentType()'); $_SERVER['CONTENT_TYPE'] = 'text/html'; $request = new myRequest($dispatcher); $t->is($request->getContentType(), 'text/html', '->getContentType() returns the content type'); $_SERVER['CONTENT_TYPE'] = 'text/html; charset=UTF-8'; $request = new myRequest($dispatcher); $t->is($request->getContentType(), 'text/html', '->getContentType() strips the charset information by default'); $t->is($request->getContentType(false), 'text/html; charset=UTF-8', '->getContentType() does not strip the charset information by defaultif you pass false as the first argument');
$_SERVER['HTTPS'] = 'on'; $_SERVER['SERVER_PORT'] = '443'; $_SERVER['HTTP_HOST'] = 'symfony-project.org:443'; $t->is($request->getUriPrefix(), 'https://symfony-project.org', '->getUriPrefix() returns no port for standard https port'); $_SERVER['HTTP_HOST'] = 'symfony-project.org'; $t->is($request->getUriPrefix(), 'https://symfony-project.org', '->getUriPrefix() works fine with no port in HTTP_HOST'); $_SERVER['HTTP_HOST'] = 'symfony-project.org:8043'; $t->is($request->getUriPrefix(), 'https://symfony-project.org:8043', '->getUriPrefix() works for nonstandard https ports'); // ->getRemoteAddress() $t->diag('->getRemoteAddress()'); $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $t->is($request->getRemoteAddress(), '127.0.0.1', '->getRemoteAddress() returns the remote address'); // ->getForwardedRemoteAddress() $t->diag('->getForwardedRemoteAddress()'); $t->is($request->getForwardedRemoteAddress(), null, '->getForwardedRemoteAddress() returns null if the request was not forwarded.'); $_SERVER['HTTP_X_FORWARDED_FOR'] = '10.0.0.1'; $t->is($request->getForwardedRemoteAddress(), '10.0.0.1', '->getForwardedRemoteAddress() returns the value from HTTP_X_FORWARDED_FOR'); // methods $t->diag('methods'); $_SERVER['REQUEST_METHOD'] = 'POST'; $_POST['sf_method'] = 'PUT'; $request = new myRequest($dispatcher); $t->is($request->getMethod(), 'PUT', '->getMethod() returns the "sf_method" parameter value if it exists and if the method is POST'); $_SERVER['REQUEST_METHOD'] = 'GET'; $_POST['sf_method'] = 'PUT'; $request = new myRequest($dispatcher); $t->is($request->getMethod(), 'GET', '->getMethod() returns the "sf_method" parameter value if it exists and if the method is POST'); $_SERVER['REQUEST_METHOD'] = 'POST'; unset($_POST['sf_method']); $request = new myRequest($dispatcher); $t->is($request->getMethod(), 'POST', '->getMethod() returns the "sf_method" parameter value if it exists and if the method is POST');
public function basicGet($url, $data = NULL) { $token = $this->getToken(); if (!$token) { return false; } // $reqUrl = 'https://' . $this->host . $url; $request = new myRequest(); $request->setMethod(myRequest::METHOD_GET); // if ($data) { $request->setParameters($data); } // $request->setHeaders(['Content-type' => 'application/json', 'Authorization' => $token]); $response = $request->sendRequest($reqUrl); if ($response->getStatus() == myResponse::STATUS_FORBIDDEN) { // try to regenerate token $request->setHeaders(['Content-type' => 'application/json', 'Authorization' => $this->generateToken()]); // retry request $response = $request->sendRequest($reqUrl); } return $response->getBody(true); }
* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; class myRequest extends sfRequest { public function getEventDispatcher() { return $this->dispatcher; } } $t = new lime_test(15, new lime_output_color()); $dispatcher = new sfEventDispatcher(); $dispatcher->connect('request.method_not_found', array('sfRequestCompat10', 'call')); $request = new myRequest($dispatcher); // ->setError() ->hasError() ->hasErrors() ->getError() ->removeError() ->getErrorNames() $t->diag('->setError() ->hasError() ->hasErrors() ->getError() ->removeError() ->getErrorNames()'); // single error $key = "test"; $value = "error"; $request->setError($key, $value, '->setError() add an error message for the given parameter'); $t->is($request->hasError($key), true, '->hasError() returns true if an error exists for the given parameter'); $t->is($request->hasErrors(), true, '->hasErrors() returns true if there are some errors'); $t->is($request->getError($key), $value, '->getError() returns the error text for the given parameter'); $t->is($request->removeError($key), $value, '->removeError() removes the error for the given parameter'); $t->is($request->hasError($key), false, '->hasError() returns false if no error exists for the given parameter'); $t->is($request->hasErrors(), false, '->hasErrors() returns false if there is no error'); // multiple errors $key1 = "test1"; $value_key1_1 = "error1_1";
$request = new myRequest($dispatcher); $t->is($request->getPathInfo(), '/test/klaus', '->getPathInfo() returns the url path value'); $_SERVER['SPECIAL'] = '/special'; $request = new myRequest($dispatcher, array(), array(), array('path_info_key' => 'SPECIAL')); $t->is($request->getPathInfo(), '/special', '->getPathInfo() returns the url path value use path_info_key'); unset($_SERVER['SPECIAL']); unset($_SERVER['PATH_INFO']); $_SERVER['SCRIPT_NAME'] = '/frontend_test.php'; $_SERVER['REQUEST_URI'] = '/frontend_test.php/test/klaus2'; $_SERVER['QUERY_STRING'] = ''; $request = new myRequest($dispatcher); $t->is($request->getPathInfo(), '/test/klaus2', '->getPathInfo() returns the url path value if it not exists use default REQUEST_URI'); $_SERVER['QUERY_STRING'] = 'test'; $_SERVER['REQUEST_URI'] = '/frontend_test.php/test/klaus2?test'; $request = new myRequest($dispatcher); $t->is($request->getPathInfo(), '/test/klaus2', '->getPathInfo() returns the url path value if it not exists use default REQUEST_URI without query'); unset($_SERVER['QUERY_STRING']); unset($_SERVER['REQUEST_URI']); $request = new myRequest($dispatcher); $t->is($request->getPathInfo(), '/', '->getPathInfo() returns the url path value if it not exists use default /'); // ->addRequestParameters() ->getRequestParameters() ->fixParameters() $t->diag('getPathInfo'); $request = new myRequest($dispatcher); $t->is($request->getRequestParameters(), array(), '->getRequestParameters() returns the request parameters default array'); $request->addRequestParameters(array('test' => 'test')); $t->is($request->getRequestParameters(), array('test' => 'test'), '->getRequestParameters() returns the request parameters'); $request->addRequestParameters(array('test' => 'test')); $t->is($request->getRequestParameters(), array('test' => 'test'), '->getRequestParameters() returns the request parameters allready exists'); $request->addRequestParameters(array('_sf_ignore_cache' => 1, 'test2' => 'test2')); $t->is($request->getRequestParameters(), array('test' => 'test', 'test2' => 'test2', '_sf_ignore_cache' => 1), '->getRequestParameters() returns the request parameters check fixParameters call for special _sf_ params'); $t->is($request->getAttribute('sf_ignore_cache'), 1, '->getAttribute() check special param is set as attribute');