mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-12-24 14:37:25 +00:00
afa8f6b441
libs always means the Cake lib - so use the CAKE constant
174 lines
5.1 KiB
PHP
174 lines
5.1 KiB
PHP
<?php
|
|
/**
|
|
* ComponentCollectionTest file
|
|
*
|
|
* PHP 5
|
|
*
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
*
|
|
* Licensed under The MIT License
|
|
* Redistributions of files must retain the above copyright notice.
|
|
*
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
|
* @package cake.tests.cases.libs
|
|
* @since CakePHP(tm) v 2.0
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
*/
|
|
|
|
App::uses('CookieComponent', 'Controller/Component');
|
|
App::uses('SecurityComponent', 'Controller/Component');
|
|
App::uses('ComponentCollection', 'Controller');
|
|
|
|
/**
|
|
* Extended CookieComponent
|
|
*/
|
|
class CookieAliasComponent extends CookieComponent {
|
|
}
|
|
|
|
class ComponentCollectionTest extends CakeTestCase {
|
|
/**
|
|
* setup
|
|
*
|
|
* @return void
|
|
*/
|
|
function setup() {
|
|
$this->Components = new ComponentCollection();
|
|
}
|
|
|
|
/**
|
|
* teardown
|
|
*
|
|
* @return void
|
|
*/
|
|
function teardown() {
|
|
unset($this->Components);
|
|
}
|
|
|
|
/**
|
|
* test triggering callbacks on loaded helpers
|
|
*
|
|
* @return void
|
|
*/
|
|
function testLoad() {
|
|
$result = $this->Components->load('Cookie');
|
|
$this->assertInstanceOf('CookieComponent', $result);
|
|
$this->assertInstanceOf('CookieComponent', $this->Components->Cookie);
|
|
|
|
$result = $this->Components->attached();
|
|
$this->assertEquals(array('Cookie'), $result, 'attached() results are wrong.');
|
|
|
|
$this->assertTrue($this->Components->enabled('Cookie'));
|
|
|
|
$result = $this->Components->load('Cookie');
|
|
$this->assertSame($result, $this->Components->Cookie);
|
|
}
|
|
|
|
/**
|
|
* Tests loading as an alias
|
|
*
|
|
* @return void
|
|
*/
|
|
function testLoadWithAlias() {
|
|
$result = $this->Components->load('Cookie', array('className' => 'CookieAlias', 'somesetting' => true));
|
|
$this->assertInstanceOf('CookieAliasComponent', $result);
|
|
$this->assertInstanceOf('CookieAliasComponent', $this->Components->Cookie);
|
|
$this->assertTrue($this->Components->Cookie->settings['somesetting']);
|
|
|
|
$result = $this->Components->attached();
|
|
$this->assertEquals(array('Cookie'), $result, 'attached() results are wrong.');
|
|
|
|
$this->assertTrue($this->Components->enabled('Cookie'));
|
|
|
|
$result = $this->Components->load('Cookie');
|
|
$this->assertInstanceOf('CookieAliasComponent', $result);
|
|
|
|
App::build(array('plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)));
|
|
CakePlugin::load('TestPlugin');
|
|
$result = $this->Components->load('SomeOther', array('className' => 'TestPlugin.OtherComponent'));
|
|
$this->assertInstanceOf('OtherComponentComponent', $result);
|
|
$this->assertInstanceOf('OtherComponentComponent', $this->Components->SomeOther);
|
|
|
|
$result = $this->Components->attached();
|
|
$this->assertEquals(array('Cookie', 'SomeOther'), $result, 'attached() results are wrong.');
|
|
App::build();
|
|
CakePlugin::unload();
|
|
}
|
|
|
|
/**
|
|
* test load and enable = false
|
|
*
|
|
* @return void
|
|
*/
|
|
function testLoadWithEnableFalse() {
|
|
$result = $this->Components->load('Cookie', array('enabled' => false));
|
|
$this->assertInstanceOf('CookieComponent', $result);
|
|
$this->assertInstanceOf('CookieComponent', $this->Components->Cookie);
|
|
|
|
$this->assertFalse($this->Components->enabled('Cookie'), 'Cookie should be disabled');
|
|
}
|
|
/**
|
|
* test missingcomponent exception
|
|
*
|
|
* @expectedException MissingComponentClassException
|
|
* @return void
|
|
*/
|
|
function testLoadMissingComponentFile() {
|
|
$this->Components->load('ThisComponentShouldAlwaysBeMissing');
|
|
}
|
|
|
|
/**
|
|
* test loading a plugin component.
|
|
*
|
|
* @return void
|
|
*/
|
|
function testLoadPluginComponent() {
|
|
App::build(array(
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
|
));
|
|
CakePlugin::load('TestPlugin');
|
|
$result = $this->Components->load('TestPlugin.OtherComponent');
|
|
$this->assertInstanceOf('OtherComponentComponent', $result, 'Component class is wrong.');
|
|
$this->assertInstanceOf('OtherComponentComponent', $this->Components->OtherComponent, 'Class is wrong');
|
|
App::build();
|
|
CakePlugin::unload();
|
|
}
|
|
|
|
/**
|
|
* test unload()
|
|
*
|
|
* @return void
|
|
*/
|
|
function testUnload() {
|
|
$this->Components->load('Cookie');
|
|
$this->Components->load('Security');
|
|
|
|
$result = $this->Components->attached();
|
|
$this->assertEquals(array('Cookie', 'Security'), $result, 'loaded components is wrong');
|
|
|
|
$this->Components->unload('Cookie');
|
|
$this->assertFalse(isset($this->Components->Cookie));
|
|
$this->assertTrue(isset($this->Components->Security));
|
|
|
|
$result = $this->Components->attached();
|
|
$this->assertEquals(array('Security'), $result, 'loaded components is wrong');
|
|
|
|
$result = $this->Components->enabled();
|
|
$this->assertEquals(array('Security'), $result, 'enabled components is wrong');
|
|
}
|
|
|
|
/**
|
|
* test getting the controller out of the collection
|
|
*
|
|
* @return void
|
|
*/
|
|
function testGetController() {
|
|
$controller = $this->getMock('Controller');
|
|
$controller->components = array('Security');
|
|
$this->Components->init($controller);
|
|
$result = $this->Components->getController();
|
|
|
|
$this->assertSame($controller, $result);
|
|
}
|
|
}
|