2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ComponentTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5436
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-06-04 02:39:05 +00:00
|
|
|
|
2010-12-09 05:13:11 +00:00
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('Component', 'Controller');
|
|
|
|
|
2008-06-04 02:39:05 +00:00
|
|
|
/**
|
|
|
|
* ParamTestComponent
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2008-06-04 02:39:05 +00:00
|
|
|
*/
|
2010-07-04 18:58:57 +00:00
|
|
|
class ParamTestComponent extends Component {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @var string 'ParamTest'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'ParamTest';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
2008-06-05 15:20:45 +00:00
|
|
|
* components property
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $components = array('Banana' => array('config' => 'value'));
|
2008-06-04 02:39:05 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ComponentTestController class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-16 04:54:28 +00:00
|
|
|
class ComponentTestController extends Controller {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'ComponentTest'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'ComponentTest';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array();
|
2010-12-16 04:54:28 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* AppleComponent class
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-07-04 18:58:57 +00:00
|
|
|
class AppleComponent extends Component {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* components property
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $components = array('Orange');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testName property
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var mixed null
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $testName = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* startup method
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
|
|
|
* @param mixed $controller
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-11-13 01:43:55 +00:00
|
|
|
public function startup($controller) {
|
2008-06-02 04:57:06 +00:00
|
|
|
$this->testName = $controller->name;
|
2008-05-31 03:54:22 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* OrangeComponent class
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-07-04 18:58:57 +00:00
|
|
|
class OrangeComponent extends Component {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* components property
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $components = array('Banana');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* initialize method
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
|
|
|
* @param mixed $controller
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-11-13 01:43:55 +00:00
|
|
|
public function initialize($controller) {
|
2009-01-02 22:47:38 +00:00
|
|
|
$this->Controller = $controller;
|
2008-06-02 04:57:06 +00:00
|
|
|
$this->Banana->testField = 'OrangeField';
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* startup method
|
|
|
|
*
|
|
|
|
* @param Controller $controller
|
|
|
|
* @return string
|
|
|
|
*/
|
2011-11-13 01:43:55 +00:00
|
|
|
public function startup($controller) {
|
2008-10-15 13:07:46 +00:00
|
|
|
$controller->foo = 'pass';
|
|
|
|
}
|
2008-05-31 03:54:22 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* BananaComponent class
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-07-04 18:58:57 +00:00
|
|
|
class BananaComponent extends Component {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testField property
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'BananaField'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $testField = 'BananaField';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* startup method
|
|
|
|
*
|
|
|
|
* @param Controller $controller
|
|
|
|
* @return string
|
|
|
|
*/
|
2011-11-13 01:43:55 +00:00
|
|
|
public function startup($controller) {
|
2008-10-15 13:07:46 +00:00
|
|
|
$controller->bar = 'fail';
|
|
|
|
}
|
2008-05-31 03:54:22 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-06 16:18:14 +00:00
|
|
|
/**
|
|
|
|
* MutuallyReferencingOneComponent class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2008-06-06 16:18:14 +00:00
|
|
|
*/
|
2010-07-04 18:58:57 +00:00
|
|
|
class MutuallyReferencingOneComponent extends Component {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* components property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $components = array('MutuallyReferencingTwo');
|
2008-06-06 16:18:14 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-06 16:18:14 +00:00
|
|
|
/**
|
|
|
|
* MutuallyReferencingTwoComponent class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2008-06-06 16:18:14 +00:00
|
|
|
*/
|
2010-07-04 18:58:57 +00:00
|
|
|
class MutuallyReferencingTwoComponent extends Component {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* components property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $components = array('MutuallyReferencingOne');
|
2008-06-06 16:18:14 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-01-02 22:47:38 +00:00
|
|
|
/**
|
|
|
|
* SomethingWithEmailComponent class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2009-01-02 22:47:38 +00:00
|
|
|
*/
|
2010-07-04 18:58:57 +00:00
|
|
|
class SomethingWithEmailComponent extends Component {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* components property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $components = array('Email');
|
2009-01-02 22:47:38 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-02-28 06:49:19 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ComponentTest class
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ComponentTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2009-06-07 22:24:10 +00:00
|
|
|
$this->_pluginPaths = App::path('plugins');
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2008-10-15 13:07:46 +00:00
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-21 23:55:39 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build();
|
2009-03-21 23:55:39 +00:00
|
|
|
ClassRegistry::flush();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-04 18:58:57 +00:00
|
|
|
/**
|
|
|
|
* test accessing inner components.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInnerComponentConstruction() {
|
2010-07-04 18:58:57 +00:00
|
|
|
$Collection = new ComponentCollection();
|
|
|
|
$Component = new AppleComponent($Collection);
|
|
|
|
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('OrangeComponent', $Component->Orange, 'class is wrong');
|
2010-07-04 18:58:57 +00:00
|
|
|
}
|
|
|
|
|
2008-06-04 02:39:05 +00:00
|
|
|
/**
|
|
|
|
* test component loading
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNestedComponentLoading() {
|
2010-07-04 18:58:57 +00:00
|
|
|
$Collection = new ComponentCollection();
|
|
|
|
$Apple = new AppleComponent($Collection);
|
2008-05-31 03:54:22 +00:00
|
|
|
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('OrangeComponent', $Apple->Orange, 'class is wrong');
|
|
|
|
$this->assertInstanceOf('BananaComponent', $Apple->Orange->Banana, 'class is wrong');
|
2010-07-04 18:58:57 +00:00
|
|
|
$this->assertTrue(empty($Apple->Session));
|
|
|
|
$this->assertTrue(empty($Apple->Orange->Session));
|
2008-05-31 03:54:22 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-04 02:39:05 +00:00
|
|
|
/**
|
2010-07-04 18:58:57 +00:00
|
|
|
* test that component components are not enabled in the collection.
|
2008-06-04 02:39:05 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInnerComponentsAreNotEnabled() {
|
2010-07-04 18:58:57 +00:00
|
|
|
$Collection = new ComponentCollection();
|
|
|
|
$Apple = $Collection->load('Apple');
|
2008-10-15 13:07:46 +00:00
|
|
|
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('OrangeComponent', $Apple->Orange, 'class is wrong');
|
2010-07-04 18:58:57 +00:00
|
|
|
$result = $Collection->enabled();
|
|
|
|
$this->assertEquals(array('Apple'), $result, 'Too many components enabled.');
|
2010-02-28 06:49:19 +00:00
|
|
|
}
|
|
|
|
|
2008-06-04 02:39:05 +00:00
|
|
|
/**
|
|
|
|
* test a component being used more than once.
|
2008-06-06 16:18:14 +00:00
|
|
|
*
|
2008-06-04 02:39:05 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMultipleComponentInitialize() {
|
2010-07-04 18:58:57 +00:00
|
|
|
$Collection = new ComponentCollection();
|
|
|
|
$Banana = $Collection->load('Banana');
|
|
|
|
$Orange = $Collection->load('Orange');
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-07-04 18:58:57 +00:00
|
|
|
$this->assertSame($Banana, $Orange->Banana, 'Should be references');
|
|
|
|
$Banana->testField = 'OrangeField';
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-07-04 18:58:57 +00:00
|
|
|
$this->assertSame($Banana->testField, $Orange->Banana->testField, 'References are broken');
|
2008-05-31 03:54:22 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-01-02 22:47:38 +00:00
|
|
|
/**
|
|
|
|
* Test mutually referencing components.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSomethingReferencingEmailComponent() {
|
2010-08-12 03:08:46 +00:00
|
|
|
$Controller = new ComponentTestController();
|
2009-01-02 22:47:38 +00:00
|
|
|
$Controller->components = array('SomethingWithEmail');
|
2009-10-31 18:08:56 +00:00
|
|
|
$Controller->uses = false;
|
2009-01-02 22:47:38 +00:00
|
|
|
$Controller->constructClasses();
|
2010-08-12 03:08:46 +00:00
|
|
|
$Controller->Components->trigger('initialize', array(&$Controller));
|
2009-01-02 22:47:38 +00:00
|
|
|
$Controller->beforeFilter();
|
2010-08-12 03:08:46 +00:00
|
|
|
$Controller->Components->trigger('startup', array(&$Controller));
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('SomethingWithEmailComponent', $Controller->SomethingWithEmail);
|
|
|
|
$this->assertInstanceOf('EmailComponent', $Controller->SomethingWithEmail->Email);
|
2009-01-02 22:47:38 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|