| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- <?php
- App::uses('CakePlugin', 'Core');
- /**
- * CakePluginTest class
- *
- */
- class CakePluginTest extends CakeTestCase {
- /**
- * Sets the plugins folder for this test
- *
- * @return void
- */
- public function setUp() {
- App::build(array(
- 'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
- ), true);
- App::objects('plugins', null, false);
- }
- /**
- * Reverts the changes done to the environment while testing
- *
- * @return void
- */
- public function tearDown() {
- App::build();
- CakePlugin::unload();
- Configure::delete('CakePluginTest');
- }
- /**
- * Tests loading a single plugin
- *
- * @return void
- */
- public function testLoadSingle() {
- CakePlugin::unload();
- CakePlugin::load('TestPlugin');
- $expected = array('TestPlugin');
- $this->assertEquals($expected, CakePlugin::loaded());
- }
- /**
- * Tests unloading plugins
- *
- * @return void
- */
- public function testUnload() {
- CakePlugin::load('TestPlugin');
- $expected = array('TestPlugin');
- $this->assertEquals($expected, CakePlugin::loaded());
- CakePlugin::unload('TestPlugin');
- $this->assertEquals(array(), CakePlugin::loaded());
- CakePlugin::load('TestPlugin');
- $expected = array('TestPlugin');
- $this->assertEquals($expected, CakePlugin::loaded());
- CakePlugin::unload('TestFakePlugin');
- $this->assertEquals($expected, CakePlugin::loaded());
- }
- /**
- * Tests loading a plugin and its bootstrap file
- *
- * @return void
- */
- public function testLoadSingleWithBootstrap() {
- CakePlugin::load('TestPlugin', array('bootstrap' => true));
- $this->assertTrue(CakePlugin::loaded('TestPlugin'));
- $this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
- }
- /**
- * Tests loading a plugin with bootstrap file and routes file
- *
- * @return void
- */
- public function testLoadSingleWithBootstrapAndRoutes() {
- CakePlugin::load('TestPlugin', array('bootstrap' => true, 'routes' => true));
- $this->assertTrue(CakePlugin::loaded('TestPlugin'));
- $this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
- CakePlugin::routes();
- $this->assertEquals('loaded plugin routes', Configure::read('CakePluginTest.test_plugin.routes'));
- }
- /**
- * Tests loading multiple plugins at once
- *
- * @return void
- */
- public function testLoadMultiple() {
- CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
- $expected = array('TestPlugin', 'TestPluginTwo');
- $this->assertEquals($expected, CakePlugin::loaded());
- }
- /**
- * Tests loading multiple plugins and their bootstrap files
- *
- * @return void
- */
- public function testLoadMultipleWithDefaults() {
- CakePlugin::load(array('TestPlugin', 'TestPluginTwo'), array('bootstrap' => true, 'routes' => false));
- $expected = array('TestPlugin', 'TestPluginTwo');
- $this->assertEquals($expected, CakePlugin::loaded());
- $this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
- $this->assertEquals('loaded plugin two bootstrap', Configure::read('CakePluginTest.test_plugin_two.bootstrap'));
- }
- /**
- * Tests loading multiple plugins with default loading params and some overrides
- *
- * @return void
- */
- public function testLoadMultipleWithDefaultsAndOverride() {
- CakePlugin::load(
- array('TestPlugin', 'TestPluginTwo' => array('routes' => false)),
- array('bootstrap' => true, 'routes' => true)
- );
- $expected = array('TestPlugin', 'TestPluginTwo');
- $this->assertEquals($expected, CakePlugin::loaded());
- $this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
- $this->assertEquals(null, Configure::read('CakePluginTest.test_plugin_two.bootstrap'));
- }
- /**
- * Tests that it is possible to load multiple bootstrap files at once
- *
- * @return void
- */
- public function testMultipleBootstrapFiles() {
- CakePlugin::load('TestPlugin', array('bootstrap' => array('bootstrap', 'custom_config')));
- $this->assertTrue(CakePlugin::loaded('TestPlugin'));
- $this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
- }
- /**
- * Tests that it is possible to load plugin bootstrap by calling a callback function
- *
- * @return void
- */
- public function testCallbackBootstrap() {
- CakePlugin::load('TestPlugin', array('bootstrap' => array($this, 'pluginBootstrap')));
- $this->assertTrue(CakePlugin::loaded('TestPlugin'));
- $this->assertEquals('called plugin bootstrap callback', Configure::read('CakePluginTest.test_plugin.bootstrap'));
- }
- /**
- * Tests that loading a missing routes file throws a warning
- *
- * @return void
- * @expectedException PHPUNIT_FRAMEWORK_ERROR_WARNING
- */
- public function testLoadMultipleWithDefaultsMissingFile() {
- CakePlugin::load(array('TestPlugin', 'TestPluginTwo'), array('bootstrap' => true, 'routes' => true));
- CakePlugin::routes();
- }
- /**
- * Tests that CakePlugin::load() throws an exception on unknown plugin
- *
- * @return void
- * @expectedException MissingPluginException
- */
- public function testLoadNotFound() {
- CakePlugin::load('MissingPlugin');
- }
- /**
- * Tests that CakePlugin::path() returns the correct path for the loaded plugins
- *
- * @return void
- */
- public function testPath() {
- CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
- $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS;
- $this->assertEquals(CakePlugin::path('TestPlugin'), $expected);
- $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPluginTwo' . DS;
- $this->assertEquals(CakePlugin::path('TestPluginTwo'), $expected);
- }
- /**
- * Tests that CakePlugin::path() throws an exception on unknown plugin
- *
- * @return void
- * @expectedException MissingPluginException
- */
- public function testPathNotFound() {
- CakePlugin::path('TestPlugin');
- }
- /**
- * Tests that CakePlugin::loadAll() will load all plgins in the configured folder
- *
- * @return void
- */
- public function testLoadAll() {
- CakePlugin::loadAll();
- $expected = array('PluginJs', 'TestPlugin', 'TestPluginTwo');
- $this->assertEquals($expected, CakePlugin::loaded());
- }
- /**
- * Tests that CakePlugin::loadAll() will load all plgins in the configured folder with bootstrap loading
- *
- * @return void
- */
- public function testLoadAllWithDefaults() {
- $defaults = array('bootstrap' => true);
- CakePlugin::loadAll(array($defaults));
- $expected = array('PluginJs', 'TestPlugin', 'TestPluginTwo');
- $this->assertEquals($expected, CakePlugin::loaded());
- $this->assertEquals('loaded js plugin bootstrap', Configure::read('CakePluginTest.js_plugin.bootstrap'));
- $this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
- $this->assertEquals('loaded plugin two bootstrap', Configure::read('CakePluginTest.test_plugin_two.bootstrap'));
- }
- /**
- * Tests that CakePlugin::loadAll() will load all plgins in the configured folder wit defaults
- * and overrides for a plugin
- *
- * @return void
- */
- public function testLoadAllWithDefaultsAndOverride() {
- CakePlugin::loadAll(array(array('bootstrap' => true), 'TestPlugin' => array('routes' => true)));
- CakePlugin::routes();
- $expected = array('PluginJs', 'TestPlugin', 'TestPluginTwo');
- $this->assertEquals($expected, CakePlugin::loaded());
- $this->assertEquals('loaded js plugin bootstrap', Configure::read('CakePluginTest.js_plugin.bootstrap'));
- $this->assertEquals('loaded plugin routes', Configure::read('CakePluginTest.test_plugin.routes'));
- $this->assertEquals(null, Configure::read('CakePluginTest.test_plugin.bootstrap'));
- $this->assertEquals('loaded plugin two bootstrap', Configure::read('CakePluginTest.test_plugin_two.bootstrap'));
- }
- /**
- * Auxiliary function to test plugin bootstrap callbacks
- *
- * @return void
- */
- public function pluginBootstrap() {
- Configure::write('CakePluginTest.test_plugin.bootstrap', 'called plugin bootstrap callback');
- }
- }
|