Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update test case Controller folder
  • Loading branch information
jrbasso committed May 26, 2012
1 parent c031164 commit 1ffadb9
Show file tree
Hide file tree
Showing 23 changed files with 552 additions and 2,211 deletions.
39 changes: 29 additions & 10 deletions lib/Cake/Test/TestCase/Controller/Component/Acl/DbAclTest.php
Expand Up @@ -17,11 +17,15 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('ComponentCollection', 'Controller');
App::uses('AclComponent', 'Controller/Component');
App::uses('DbAcl', 'Controller/Component/Acl');
App::uses('AclNode', 'Model');
App::uses('Permission', 'Model');
namespace Cake\Test\TestCase\Controller\Component\Acl;
use Cake\TestSuite\TestCase,
Cake\TestSuite\Fixture\TestModel,
Cake\Controller\Component\AclComponent,
Cake\Controller\Component\Acl\DbAcl,
Cake\Controller\ComponentCollection,
Cake\Model\AclNode,
Cake\Core\Configure;

require_once dirname(dirname(dirname(dirname(__FILE__)))) . DS . 'Model' . DS . 'models.php';

/**
Expand Down Expand Up @@ -72,7 +76,10 @@ class AroTwoTest extends AclNodeTwoTestBase {
*
* @var array
*/
public $hasAndBelongsToMany = array('AcoTwoTest' => array('with' => 'PermissionTwoTest'));
public $hasAndBelongsToMany = array('AcoTwoTest' => array(
'with' => 'PermissionTwoTest',
'className' => 'Cake\Test\TestCase\Controller\Component\AcoTwoTest'
));
}

/**
Expand Down Expand Up @@ -101,7 +108,10 @@ class AcoTwoTest extends AclNodeTwoTestBase {
*
* @var array
*/
public $hasAndBelongsToMany = array('AroTwoTest' => array('with' => 'PermissionTwoTest'));
public $hasAndBelongsToMany = array('AroTwoTest' => array(
'with' => 'PermissionTwoTest',
'className' => 'Cake\Test\TestCase\Controller\Component\AroTwoTest'
));
}

/**
Expand Down Expand Up @@ -137,7 +147,16 @@ class PermissionTwoTest extends Permission {
*
* @var array
*/
public $belongsTo = array('AroTwoTest' => array('foreignKey' => 'aro_id'), 'AcoTwoTest' => array('foreignKey' => 'aco_id'));
public $belongsTo = array(
'AroTwoTest' => array(
'foreignKey' => 'aro_id',
'className' => 'Cake\Test\TestCase\Controller\Component\AroTwoTest'
),
'AcoTwoTest' => array(
'foreignKey' => 'aco_id',
'className' => 'Cake\Test\TestCase\Controller\Component\AcoTwoTest'
)
);

/**
* actsAs property
Expand Down Expand Up @@ -177,7 +196,7 @@ public function __construct() {
*
* @package Cake.Test.Case.Controller.Component.Acl
*/
class DbAclTest extends CakeTestCase {
class DbAclTest extends TestCase {

/**
* fixtures property
Expand All @@ -193,7 +212,7 @@ class DbAclTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
Configure::write('Acl.classname', 'DbAclTwoTest');
Configure::write('Acl.classname', __NAMESPACE__ . '\DbAclTwoTest');
Configure::write('Acl.database', 'test');
$Collection = new ComponentCollection();
$this->Acl = new AclComponent($Collection);
Expand Down
11 changes: 7 additions & 4 deletions lib/Cake/Test/TestCase/Controller/Component/Acl/IniAclTest.php
Expand Up @@ -16,22 +16,25 @@
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('IniAcl', 'Controller/Component/Acl');
namespace Cake\Test\TestCase\Controller\Component;
use Cake\TestSuite\TestCase,
Cake\Controller\Component\AclComponent,
Cake\Controller\Component\Acl\IniAcl;

/**
* Test case for the IniAcl implementation
*
* @package Cake.Test.Case.Controller.Component.Acl
*/
class IniAclTest extends CakeTestCase {
class IniAclTest extends TestCase {

/**
* testIniCheck method
*
* @return void
*/
public function testCheck() {
$iniFile = CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'acl.ini.php';
$iniFile = CAKE . 'Test' . DS . 'TestApp' . DS . 'Config' . DS . 'acl.ini.php';

$Ini = new IniAcl();
$Ini->config = $Ini->readConfigFile($iniFile);
Expand All @@ -54,7 +57,7 @@ public function testCheck() {
* @return void
*/
public function testCheckArray() {
$iniFile = CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'acl.ini.php';
$iniFile = CAKE . 'Test' . DS . 'TestApp' . DS . 'Config' . DS . 'acl.ini.php';

$Ini = new IniAcl();
$Ini->config = $Ini->readConfigFile($iniFile);
Expand Down
Expand Up @@ -35,7 +35,7 @@ public function setUp() {
$this->PhpAcl = new PhpAcl();
$this->Acl = new AclComponent($Collection, array(
'adapter' => array(
'config' => CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'acl.php',
'config' => CAKE . 'Test' . DS . 'TestApp' . DS . 'Config' . DS . 'acl.php',
),
));
}
Expand Down
21 changes: 12 additions & 9 deletions lib/Cake/Test/TestCase/Controller/Component/AclComponentTest.php
Expand Up @@ -16,15 +16,18 @@
* @since CakePHP(tm) v 1.2.0.5435
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('AclComponent', 'Controller/Component');
class_exists('AclComponent');
namespace Cake\Test\TestCase\Controller\Component;
use Cake\TestSuite\TestCase,
Cake\Controller\Component\AclComponent,
Cake\Controller\ComponentCollection,
Cake\Core\Configure;

/**
* Test Case for AclComponent
*
* @package Cake.Test.Case.Controller.Component
*/
class AclComponentTest extends CakeTestCase {
class AclComponentTest extends TestCase {

/**
* setUp method
Expand All @@ -34,9 +37,9 @@ class AclComponentTest extends CakeTestCase {
public function setUp() {
parent::setUp();
if (!class_exists('MockAclImplementation', false)) {
$this->getMock('AclInterface', array(), array(), 'MockAclImplementation');
$this->getMock('Cake\Controller\Component\Acl\AclInterface', array(), array(), 'MockAclImplementation');
}
Configure::write('Acl.classname', 'MockAclImplementation');
Configure::write('Acl.classname', '\MockAclImplementation');
$Collection = new ComponentCollection();
$this->Acl = new AclComponent($Collection);
}
Expand All @@ -55,7 +58,7 @@ public function tearDown() {
* test that constructor throws an exception when Acl.classname is a
* non-existent class
*
* @expectedException CakeException
* @expectedException Cake\Error\Exception
* @return void
*/
public function testConstrutorException() {
Expand All @@ -70,7 +73,7 @@ public function testConstrutorException() {
* @return void
*/
public function testAdapter() {
$implementation = new MockAclImplementation();
$implementation = new \MockAclImplementation();
$implementation->expects($this->once())->method('initialize')->with($this->Acl);
$this->assertNull($this->Acl->adapter($implementation));

Expand All @@ -80,11 +83,11 @@ public function testAdapter() {
/**
* test that adapter() whines when the class is not an AclBase
*
* @expectedException CakeException
* @expectedException Cake\Error\Exception
* @return void
*/
public function testAdapterException() {
$thing = new StdClass();
$thing = new \StdClass();
$this->Acl->adapter($thing);
}

Expand Down
Expand Up @@ -16,14 +16,12 @@
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Test\TestCase\Controller\Component\Auth;
use Cake\TestSuite\TestCase,
Cake\Controller\Component\Auth\ActionsAuthorize,
Cake\Network\Request;

App::uses('ActionsAuthorize', 'Controller/Component/Auth');
App::uses('ComponentCollection', 'Controller');
App::uses('AclComponent', 'Controller/Component');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');

class ActionsAuthorizeTest extends CakeTestCase {
class ActionsAuthorizeTest extends TestCase {

/**
* setUp
Expand All @@ -32,9 +30,9 @@ class ActionsAuthorizeTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
$this->controller = $this->getMock('Controller', array(), array(), '', false);
$this->Acl = $this->getMock('AclComponent', array(), array(), '', false);
$this->Collection = $this->getMock('ComponentCollection');
$this->controller = $this->getMock('Cake\Controller\Controller', array(), array(), '', false);
$this->Acl = $this->getMock('Cake\Controller\Component\AclComponent', array(), array(), '', false);
$this->Collection = $this->getMock('Cake\Controller\ComponentCollection');

$this->auth = new ActionsAuthorize($this->Collection);
$this->auth->settings['actionPath'] = '/controllers';
Expand Down Expand Up @@ -64,7 +62,7 @@ public function testAuthorizeFailure() {
'user' => 'mariano'
)
);
$request = new CakeRequest('/posts/index', false);
$request = new Request('/posts/index', false);
$request->addParams(array(
'plugin' => null,
'controller' => 'posts',
Expand Down Expand Up @@ -93,7 +91,7 @@ public function testAuthorizeSuccess() {
'user' => 'mariano'
)
);
$request = new CakeRequest('/posts/index', false);
$request = new Request('/posts/index', false);
$request->addParams(array(
'plugin' => null,
'controller' => 'posts',
Expand All @@ -116,7 +114,7 @@ public function testAuthorizeSuccess() {
* @return void
*/
public function testAuthorizeSettings() {
$request = new CakeRequest('/posts/index', false);
$request = new Request('/posts/index', false);
$request->addParams(array(
'plugin' => null,
'controller' => 'posts',
Expand Down Expand Up @@ -146,7 +144,7 @@ public function testAuthorizeSettings() {
* @return void
*/
public function testActionMethod() {
$request = new CakeRequest('/posts/index', false);
$request = new Request('/posts/index', false);
$request->addParams(array(
'plugin' => null,
'controller' => 'posts',
Expand Down Expand Up @@ -179,7 +177,7 @@ public function testActionNoDoubleSlash() {
* @return void
*/
public function testActionWithPlugin() {
$request = new CakeRequest('/debug_kit/posts/index', false);
$request = new Request('/debug_kit/posts/index', false);
$request->addParams(array(
'plugin' => 'debug_kit',
'controller' => 'posts',
Expand Down
Expand Up @@ -16,22 +16,21 @@
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Test\TestCase\Controller\Component\Auth;
use Cake\TestSuite\TestCase,
Cake\Controller\Component\Auth\BasicAuthenticate,
Cake\Network\Request,
Cake\Utility\ClassRegistry,
Cake\Utility\Security;

App::uses('AuthComponent', 'Controller/Component');
App::uses('BasicAuthenticate', 'Controller/Component/Auth');
App::uses('AppModel', 'Model');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');


require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php';
require_once CAKE . 'Test' . DS . 'TestCase' . DS . 'Model' . DS . 'models.php';

/**
* Test case for BasicAuthentication
*
* @package Cake.Test.Case.Controller.Component.Auth
*/
class BasicAuthenticateTest extends CakeTestCase {
class BasicAuthenticateTest extends TestCase {

public $fixtures = array('core.user', 'core.auth_user');

Expand All @@ -42,7 +41,7 @@ class BasicAuthenticateTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
$this->Collection = $this->getMock('ComponentCollection');
$this->Collection = $this->getMock('Cake\Controller\ComponentCollection');
$this->auth = new BasicAuthenticate($this->Collection, array(
'fields' => array('username' => 'user', 'password' => 'password'),
'userModel' => 'User',
Expand All @@ -53,7 +52,7 @@ public function setUp() {
$password = Security::hash('password', null, true);
$User = ClassRegistry::init('User');
$User->updateAll(array('password' => $User->getDataSource()->value($password)));
$this->response = $this->getMock('CakeResponse');
$this->response = $this->getMock('Cake\Network\Response');
}

/**
Expand Down Expand Up @@ -86,7 +85,7 @@ public function testConstructor() {
* @return void
*/
public function testAuthenticateNoData() {
$request = new CakeRequest('posts/index', false);
$request = new Request('posts/index', false);

$this->response->expects($this->once())
->method('header')
Expand All @@ -101,7 +100,7 @@ public function testAuthenticateNoData() {
* @return void
*/
public function testAuthenticateNoUsername() {
$request = new CakeRequest('posts/index', false);
$request = new Request('posts/index', false);
$_SERVER['PHP_AUTH_PW'] = 'foobar';

$this->response->expects($this->once())
Expand All @@ -117,7 +116,7 @@ public function testAuthenticateNoUsername() {
* @return void
*/
public function testAuthenticateNoPassword() {
$request = new CakeRequest('posts/index', false);
$request = new Request('posts/index', false);
$_SERVER['PHP_AUTH_USER'] = 'mariano';
$_SERVER['PHP_AUTH_PW'] = null;

Expand All @@ -134,7 +133,7 @@ public function testAuthenticateNoPassword() {
* @return void
*/
public function testAuthenticateInjection() {
$request = new CakeRequest('posts/index', false);
$request = new Request('posts/index', false);
$request->addParams(array('pass' => array(), 'named' => array()));

$_SERVER['PHP_AUTH_USER'] = '> 1';
Expand All @@ -149,7 +148,7 @@ public function testAuthenticateInjection() {
* @return void
*/
public function testAuthenticateChallenge() {
$request = new CakeRequest('posts/index', false);
$request = new Request('posts/index', false);
$request->addParams(array('pass' => array(), 'named' => array()));

$this->response->expects($this->at(0))
Expand All @@ -169,7 +168,7 @@ public function testAuthenticateChallenge() {
* @return void
*/
public function testAuthenticateSuccess() {
$request = new CakeRequest('posts/index', false);
$request = new Request('posts/index', false);
$request->addParams(array('pass' => array(), 'named' => array()));

$_SERVER['PHP_AUTH_USER'] = 'mariano';
Expand All @@ -192,7 +191,7 @@ public function testAuthenticateSuccess() {
*/
public function testAuthenticateFailReChallenge() {
$this->auth->settings['scope'] = array('user' => 'nate');
$request = new CakeRequest('posts/index', false);
$request = new Request('posts/index', false);
$request->addParams(array('pass' => array(), 'named' => array()));

$_SERVER['PHP_AUTH_USER'] = 'mariano';
Expand Down

0 comments on commit 1ffadb9

Please sign in to comment.