Example #1
0
$request->setRequestFormat('css');
$t->is($request->getRequestFormat(), 'css', '->setRequestFormat() sets the request format');
// ->getFormat() ->setFormat()
$t->diag('->getFormat() ->setFormat()');
$request->setFormat('js', 'application/x-javascript');
$t->is($request->getFormat('application/x-javascript'), 'js', '->getFormat() returns the format for the given mime type');
$request->setFormat('js', array('application/x-javascript', 'text/js'));
$t->is($request->getFormat('text/js'), 'js', '->setFormat() can take an array of mime types');
$t->is($request->getFormat('foo/bar'), null, '->getFormat() returns null if the mime type does not exist');
// ->getMimeType()
$t->diag('->getMimeType()');
$t->is($request->getMimeType('js'), 'application/x-javascript', '->getMimeType() returns the first mime type for the given format');
$t->is($request->getMimeType('foo'), null, '->getMimeType() returns null if the format does not exist');
// ->isSecure()
$t->diag('->isSecure()');
$t->is($request->isSecure(), false, '->isSecure() returns false if request is not secure');
$_SERVER['HTTPS'] = 'ON';
$t->is($request->isSecure(), true, '->isSecure() checks the "HTTPS" environment variable');
$_SERVER['HTTPS'] = 'on';
$t->is($request->isSecure(), true, '->isSecure() checks the "HTTPS" environment variable');
$_SERVER['HTTPS'] = '1';
$t->is($request->isSecure(), true, '->isSecure() checks the "HTTPS" environment variable');
$request->resetPathInfoArray();
$_SERVER['HTTP_SSL_HTTPS'] = 'ON';
$t->is($request->isSecure(), true, '->isSecure() checks the "HTTP_SSL_HTTPS" environment variable');
$_SERVER['HTTP_SSL_HTTPS'] = 'on';
$t->is($request->isSecure(), true, '->isSecure() checks the "HTTP_SSL_HTTPS" environment variable');
$_SERVER['HTTP_SSL_HTTPS'] = '1';
$t->is($request->isSecure(), true, '->isSecure() checks the "HTTP_SSL_HTTPS" environment variable');
$request->resetPathInfoArray();
$_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https';
$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"');
Example #3
0
// ->getFormat() ->setFormat()
$t->diag('->getFormat() ->setFormat()');
$customRequest = new myRequest($dispatcher, array(), array(), array('formats' => array('custom' => 'application/custom')));
$t->is($customRequest->getFormat('application/custom'), 'custom', '->getFormat() returns the format for the given mime type if when is set as initialisation option');
$request->setFormat('js', 'application/x-javascript');
$t->is($request->getFormat('application/x-javascript'), 'js', '->getFormat() returns the format for the given mime type');
$request->setFormat('js', array('application/x-javascript', 'text/js'));
$t->is($request->getFormat('text/js'), 'js', '->setFormat() can take an array of mime types');
$t->is($request->getFormat('foo/bar'), null, '->getFormat() returns null if the mime type does not exist');
// ->getMimeType()
$t->diag('->getMimeType()');
$t->is($request->getMimeType('js'), 'application/x-javascript', '->getMimeType() returns the first mime type for the given format');
$t->is($request->getMimeType('foo'), null, '->getMimeType() returns null if the format does not exist');
// ->isSecure()
$t->diag('->isSecure()');
$t->is($request->isSecure(), false, '->isSecure() returns false if request is not secure');
$_SERVER['HTTPS'] = 'ON';
$t->is($request->isSecure(), true, '->isSecure() checks the "HTTPS" environment variable');
$_SERVER['HTTPS'] = 'on';
$t->is($request->isSecure(), true, '->isSecure() checks the "HTTPS" environment variable');
$_SERVER['HTTPS'] = '1';
$t->is($request->isSecure(), true, '->isSecure() checks the "HTTPS" environment variable');
$request->resetPathInfoArray();
$_SERVER['HTTP_SSL_HTTPS'] = 'ON';
$t->is($request->isSecure(), true, '->isSecure() checks the "HTTP_SSL_HTTPS" environment variable');
$_SERVER['HTTP_SSL_HTTPS'] = 'on';
$t->is($request->isSecure(), true, '->isSecure() checks the "HTTP_SSL_HTTPS" environment variable');
$_SERVER['HTTP_SSL_HTTPS'] = '1';
$t->is($request->isSecure(), true, '->isSecure() checks the "HTTP_SSL_HTTPS" environment variable');
$request->resetPathInfoArray();
$_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https';