| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- /**
- * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
- * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
- * @since 1.2.0
- * @license http://www.opensource.org/licenses/mit-license.php MIT License
- */
- namespace Cake\Test\TestCase\Controller;
- use Cake\Controller\Component;
- use Cake\Controller\ComponentRegistry;
- use Cake\Controller\Controller;
- use Cake\Core\App;
- use Cake\Core\Configure;
- use Cake\TestSuite\TestCase;
- use Cake\Utility\ClassRegistry;
- use TestApp\Controller\ComponentTestController;
- use TestApp\Controller\Component\AppleComponent;
- use TestApp\Controller\Component\OrangeComponent;
- /**
- * ComponentTest class
- *
- */
- class ComponentTest extends TestCase {
- /**
- * setUp method
- *
- * @return void
- */
- public function setUp() {
- parent::setUp();
- Configure::write('App.namespace', 'TestApp');
- $this->_pluginPaths = App::path('Plugin');
- }
- /**
- * test accessing inner components.
- *
- * @return void
- */
- public function testInnerComponentConstruction() {
- $Collection = new ComponentRegistry();
- $Component = new AppleComponent($Collection);
- $this->assertInstanceOf('TestApp\Controller\Component\OrangeComponent', $Component->Orange, 'class is wrong');
- }
- /**
- * test component loading
- *
- * @return void
- */
- public function testNestedComponentLoading() {
- $Collection = new ComponentRegistry();
- $Apple = new AppleComponent($Collection);
- $this->assertInstanceOf('TestApp\Controller\Component\OrangeComponent', $Apple->Orange, 'class is wrong');
- $this->assertInstanceOf('TestApp\Controller\Component\BananaComponent', $Apple->Orange->Banana, 'class is wrong');
- $this->assertTrue(empty($Apple->Session));
- $this->assertTrue(empty($Apple->Orange->Session));
- }
- /**
- * test that component components are not enabled in the collection.
- *
- * @return void
- */
- public function testInnerComponentsAreNotEnabled() {
- $mock = $this->getMock('Cake\Event\EventManager');
- $controller = new Controller();
- $controller->eventManager($mock);
- $mock->expects($this->once())
- ->method('attach')
- ->with($this->isInstanceOf('TestApp\Controller\Component\AppleComponent'));
- $Collection = new ComponentRegistry($controller);
- $Apple = $Collection->load('Apple');
- $this->assertInstanceOf('TestApp\Controller\Component\OrangeComponent', $Apple->Orange, 'class is wrong');
- }
- /**
- * test a component being used more than once.
- *
- * @return void
- */
- public function testMultipleComponentInitialize() {
- $Collection = new ComponentRegistry();
- $Banana = $Collection->load('Banana');
- $Orange = $Collection->load('Orange');
- $this->assertSame($Banana, $Orange->Banana, 'Should be references');
- $Banana->testField = 'OrangeField';
- $this->assertSame($Banana->testField, $Orange->Banana->testField, 'References are broken');
- }
- /**
- * Test mutually referencing components.
- *
- * @return void
- */
- public function testSomethingReferencingCookieComponent() {
- $Controller = new ComponentTestController();
- $Controller->components = array('SomethingWithCookie');
- $Controller->uses = false;
- $Controller->constructClasses();
- $Controller->startupProcess();
- $this->assertInstanceOf('TestApp\Controller\Component\SomethingWithCookieComponent', $Controller->SomethingWithCookie);
- $this->assertInstanceOf('Cake\Controller\Component\CookieComponent', $Controller->SomethingWithCookie->Cookie);
- }
- }
|