Skip to content

Commit

Permalink
use Cake\Http\ServerRequest on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saeideng committed Mar 23, 2017
1 parent d43f03c commit 69dcc12
Show file tree
Hide file tree
Showing 47 changed files with 316 additions and 320 deletions.
18 changes: 9 additions & 9 deletions tests/TestCase/Auth/BasicAuthenticateTest.php
Expand Up @@ -17,9 +17,9 @@
use Cake\Auth\BasicAuthenticate;
use Cake\Controller\ComponentRegistry;
use Cake\Http\Response;
use Cake\Http\ServerRequest;
use Cake\I18n\Time;
use Cake\Network\Exception\UnauthorizedException;
use Cake\Network\Request;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;

Expand Down Expand Up @@ -79,7 +79,7 @@ public function testConstructor()
*/
public function testAuthenticateNoData()
{
$request = new Request('posts/index');
$request = new ServerRequest('posts/index');

$this->response->expects($this->never())
->method('header');
Expand All @@ -94,7 +94,7 @@ public function testAuthenticateNoData()
*/
public function testAuthenticateNoUsername()
{
$request = new Request([
$request = new ServerRequest([
'url' => 'posts/index',
'environment' => ['PHP_AUTH_PW' => 'foobar']
]);
Expand All @@ -109,7 +109,7 @@ public function testAuthenticateNoUsername()
*/
public function testAuthenticateNoPassword()
{
$request = new Request([
$request = new ServerRequest([
'url' => 'posts/index',
'environment' => ['PHP_AUTH_USER' => 'mariano']
]);
Expand All @@ -124,7 +124,7 @@ public function testAuthenticateNoPassword()
*/
public function testAuthenticateInjection()
{
$request = new Request([
$request = new ServerRequest([
'url' => 'posts/index',
'environment' => [
'PHP_AUTH_USER' => '> 1',
Expand All @@ -147,7 +147,7 @@ public function testAuthenticateUsernameZero()
$User = TableRegistry::get('Users');
$User->updateAll(['username' => '0'], ['username' => 'mariano']);

$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->data = ['User' => [
'user' => '0',
'password' => 'password'
Expand All @@ -171,7 +171,7 @@ public function testAuthenticateUsernameZero()
*/
public function testAuthenticateChallenge()
{
$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->addParams(['pass' => []]);

try {
Expand All @@ -192,7 +192,7 @@ public function testAuthenticateChallenge()
*/
public function testAuthenticateSuccess()
{
$request = new Request([
$request = new ServerRequest([
'url' => 'posts/index',
'environment' => [
'PHP_AUTH_USER' => 'mariano',
Expand Down Expand Up @@ -221,7 +221,7 @@ public function testAuthenticateSuccess()
public function testAuthenticateFailReChallenge()
{
$this->auth->config('scope.username', 'nate');
$request = new Request([
$request = new ServerRequest([
'url' => 'posts/index',
'environment' => [
'PHP_AUTH_USER' => 'mariano',
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Auth/ControllerAuthorizeTest.php
Expand Up @@ -19,7 +19,7 @@
use Cake\Auth\ControllerAuthorize;
use Cake\Controller\ComponentRegistry;
use Cake\Controller\Controller;
use Cake\Network\Request;
use Cake\Http\ServerRequest;
use Cake\TestSuite\TestCase;

/**
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testControllerErrorOnMissingMethod()
public function testAuthorizeFailure()
{
$user = [];
$request = new Request('/posts/index');
$request = new ServerRequest('/posts/index');
$this->assertFalse($this->auth->authorize($user, $request));
}

Expand All @@ -77,7 +77,7 @@ public function testAuthorizeFailure()
public function testAuthorizeSuccess()
{
$user = ['User' => ['username' => 'mark']];
$request = new Request('/posts/index');
$request = new ServerRequest('/posts/index');

$this->controller->expects($this->once())
->method('isAuthorized')
Expand Down
22 changes: 11 additions & 11 deletions tests/TestCase/Auth/DigestAuthenticateTest.php
Expand Up @@ -20,9 +20,9 @@
use Cake\Controller\ComponentRegistry;
use Cake\Core\Configure;
use Cake\Http\Response;
use Cake\Http\ServerRequest;
use Cake\I18n\Time;
use Cake\Network\Exception\UnauthorizedException;
use Cake\Network\Request;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;

Expand Down Expand Up @@ -87,7 +87,7 @@ public function testConstructor()
*/
public function testAuthenticateNoData()
{
$request = new Request('posts/index');
$request = new ServerRequest('posts/index');

$this->response->expects($this->never())
->method('header');
Expand All @@ -104,7 +104,7 @@ public function testAuthenticateNoData()
*/
public function testAuthenticateWrongUsername()
{
$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->addParams(['pass' => []]);

$data = [
Expand All @@ -129,7 +129,7 @@ public function testAuthenticateWrongUsername()
*/
public function testAuthenticateChallenge()
{
$request = new Request([
$request = new ServerRequest([
'url' => 'posts/index',
'environment' => ['REQUEST_METHOD' => 'GET']
]);
Expand All @@ -156,7 +156,7 @@ public function testAuthenticateChallenge()
*/
public function testAuthenticateChallengeIncludesStaleAttributeOnStaleNonce()
{
$request = new Request([
$request = new ServerRequest([
'url' => 'posts/index',
'environment' => ['REQUEST_METHOD' => 'GET']
]);
Expand Down Expand Up @@ -188,7 +188,7 @@ public function testAuthenticateChallengeIncludesStaleAttributeOnStaleNonce()
*/
public function testAuthenticateFailsOnStaleNonce()
{
$request = new Request([
$request = new ServerRequest([
'url' => 'posts/index',
'environment' => ['REQUEST_METHOD' => 'GET']
]);
Expand All @@ -214,7 +214,7 @@ public function testAuthenticateFailsOnStaleNonce()
*/
public function testAuthenticateValidUsernamePasswordNoNonce()
{
$request = new Request([
$request = new ServerRequest([
'url' => 'posts/index',
'environment' => ['REQUEST_METHOD' => 'GET']
]);
Expand Down Expand Up @@ -242,7 +242,7 @@ public function testAuthenticateValidUsernamePasswordNoNonce()
*/
public function testAuthenticateSuccess()
{
$request = new Request([
$request = new ServerRequest([
'url' => 'posts/index',
'environment' => ['REQUEST_METHOD' => 'GET']
]);
Expand Down Expand Up @@ -275,7 +275,7 @@ public function testAuthenticateSuccess()
*/
public function testAuthenticateSuccessSimulatedRequestMethod()
{
$request = new Request([
$request = new ServerRequest([
'url' => 'posts/index',
'post' => ['_method' => 'PUT'],
'environment' => ['REQUEST_METHOD' => 'GET']
Expand Down Expand Up @@ -313,7 +313,7 @@ public function testAuthenticateSuccessSimulatedRequestMethod()
public function testAuthenticateFailReChallenge()
{
$this->auth->config('scope.username', 'nate');
$request = new Request([
$request = new ServerRequest([
'url' => 'posts/index',
'environment' => ['REQUEST_METHOD' => 'GET']
]);
Expand All @@ -339,7 +339,7 @@ public function testAuthenticateFailReChallenge()
*/
public function testLoginHeaders()
{
$request = new Request([
$request = new ServerRequest([
'environment' => ['SERVER_NAME' => 'localhost']
]);
$this->auth = new DigestAuthenticate($this->Collection, [
Expand Down
32 changes: 16 additions & 16 deletions tests/TestCase/Auth/FormAuthenticateTest.php
Expand Up @@ -18,8 +18,8 @@
use Cake\Controller\ComponentRegistry;
use Cake\Core\Plugin;
use Cake\Http\Response;
use Cake\Http\ServerRequest;
use Cake\I18n\Time;
use Cake\Network\Request;
use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
Expand Down Expand Up @@ -86,7 +86,7 @@ public function testConstructor()
*/
public function testAuthenticateNoData()
{
$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->data = [];
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
Expand All @@ -98,7 +98,7 @@ public function testAuthenticateNoData()
*/
public function testAuthenticateNoUsername()
{
$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->data = ['password' => 'foobar'];
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
Expand All @@ -110,7 +110,7 @@ public function testAuthenticateNoUsername()
*/
public function testAuthenticateNoPassword()
{
$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->data = ['username' => 'mariano'];
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
Expand All @@ -122,7 +122,7 @@ public function testAuthenticateNoPassword()
*/
public function testAuthenticatePasswordIsFalse()
{
$request = new Request('posts/index', false);
$request = new ServerRequest('posts/index', false);
$request->data = [
'username' => 'mariano',
'password' => null
Expand All @@ -138,7 +138,7 @@ public function testAuthenticatePasswordIsFalse()
*/
public function testAuthenticatePasswordIsEmptyString()
{
$request = new Request('posts/index', false);
$request = new ServerRequest('posts/index', false);
$request->data = [
'username' => 'mariano',
'password' => ''
Expand Down Expand Up @@ -167,7 +167,7 @@ public function testAuthenticatePasswordIsEmptyString()
*/
public function testAuthenticateFieldsAreNotString()
{
$request = new Request('posts/index', false);
$request = new ServerRequest('posts/index', false);
$request->data = [
'username' => ['mariano', 'phpnut'],
'password' => 'my password'
Expand All @@ -188,7 +188,7 @@ public function testAuthenticateFieldsAreNotString()
*/
public function testAuthenticateInjection()
{
$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->data = [
'username' => '> 1',
'password' => "' OR 1 = 1"
Expand All @@ -203,7 +203,7 @@ public function testAuthenticateInjection()
*/
public function testAuthenticateSuccess()
{
$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->data = [
'username' => 'mariano',
'password' => 'password'
Expand All @@ -228,7 +228,7 @@ public function testAuthenticateIncludesVirtualFields()
$users = TableRegistry::get('Users');
$users->entityClass('TestApp\Model\Entity\VirtualUser');

$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->data = [
'username' => 'mariano',
'password' => 'password'
Expand Down Expand Up @@ -261,7 +261,7 @@ public function testPluginModel()

$this->auth->config('userModel', 'TestPlugin.AuthUsers');

$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->data = [
'username' => 'gwoo',
'password' => 'cake'
Expand All @@ -285,7 +285,7 @@ public function testPluginModel()
*/
public function testFinder()
{
$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->data = [
'username' => 'mariano',
'password' => 'password'
Expand Down Expand Up @@ -323,7 +323,7 @@ public function testFinder()
*/
public function testFinderOptions()
{
$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->data = [
'username' => 'mariano',
'password' => 'password'
Expand Down Expand Up @@ -376,7 +376,7 @@ public function testPasswordHasherSettings()
['username' => 'mariano']
);

$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->data = [
'username' => 'mariano',
'password' => 'mypass'
Expand Down Expand Up @@ -414,7 +414,7 @@ public function testPasswordHasherSettings()
*/
public function testAuthenticateNoRehash()
{
$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->data = [
'username' => 'mariano',
'password' => 'password'
Expand All @@ -439,7 +439,7 @@ public function testAuthenticateRehash()
$password = $this->auth->passwordHasher()->hash('password');
TableRegistry::get('Users')->updateAll(['password' => $password], []);

$request = new Request('posts/index');
$request = new ServerRequest('posts/index');
$request->data = [
'username' => 'mariano',
'password' => 'password'
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Auth/Storage/SessionStorageTest.php
Expand Up @@ -16,7 +16,7 @@

use Cake\Auth\Storage\SessionStorage;
use Cake\Http\Response;
use Cake\Network\Request;
use Cake\Http\ServerRequest;
use Cake\Network\Session;
use Cake\TestSuite\TestCase;

Expand All @@ -36,7 +36,7 @@ public function setUp()
parent::setUp();

$this->session = $this->getMockBuilder(Session::class)->getMock();
$this->request = new Request(['session' => $this->session]);
$this->request = new ServerRequest(['session' => $this->session]);
$this->response = new Response();
$this->storage = new SessionStorage($this->request, $this->response, ['key' => 'Auth.AuthUser']);
$this->user = ['id' => 1];
Expand Down

0 comments on commit 69dcc12

Please sign in to comment.