2011-04-26 05:26:19 +00:00
|
|
|
<?php
|
2011-10-10 21:18:48 +00:00
|
|
|
/**
|
|
|
|
* CakePluginTest file.
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2012-03-13 02:46:07 +00:00
|
|
|
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2011-10-10 21:18:48 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2012-03-13 02:46:07 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2011-10-10 21:18:48 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
|
|
|
* @package Cake.Test.Case.Core
|
|
|
|
* @since CakePHP(tm) v 2.0
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
2011-04-26 05:26:19 +00:00
|
|
|
|
|
|
|
App::uses('CakePlugin', 'Core');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CakePluginTest class
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class CakePluginTest extends CakeTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the plugins folder for this test
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setUp() {
|
2012-04-16 02:20:34 +00:00
|
|
|
parent::setUp();
|
2011-04-26 05:26:19 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2011-05-19 19:52:09 +00:00
|
|
|
App::objects('plugins', null, false);
|
2011-04-26 05:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverts the changes done to the environment while testing
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function tearDown() {
|
2012-04-16 02:20:34 +00:00
|
|
|
parent::tearDown();
|
2011-05-09 03:55:32 +00:00
|
|
|
CakePlugin::unload();
|
2011-04-26 05:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests loading a single plugin
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLoadSingle() {
|
2011-05-19 20:26:49 +00:00
|
|
|
CakePlugin::unload();
|
2011-04-26 05:26:19 +00:00
|
|
|
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());
|
2011-05-15 16:53:53 +00:00
|
|
|
|
2011-04-26 05:26:19 +00:00
|
|
|
CakePlugin::unload('TestPlugin');
|
|
|
|
$this->assertEquals(array(), CakePlugin::loaded());
|
|
|
|
|
|
|
|
CakePlugin::load('TestPlugin');
|
|
|
|
$expected = array('TestPlugin');
|
|
|
|
$this->assertEquals($expected, CakePlugin::loaded());
|
2011-05-15 16:53:53 +00:00
|
|
|
|
2011-04-26 05:26:19 +00:00
|
|
|
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));
|
2011-05-09 03:49:00 +00:00
|
|
|
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
|
2011-04-26 05:26:19 +00:00
|
|
|
$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));
|
2011-05-09 03:49:00 +00:00
|
|
|
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
|
2011-04-26 05:26:19 +00:00
|
|
|
$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
|
2011-05-23 02:20:56 +00:00
|
|
|
|
|
|
|
CakePlugin::routes();
|
2011-04-26 05:26:19 +00:00
|
|
|
$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')));
|
2011-05-09 03:49:00 +00:00
|
|
|
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
|
2011-04-26 05:26:19 +00:00
|
|
|
$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
|
|
|
|
}
|
|
|
|
|
2011-04-29 16:53:11 +00:00
|
|
|
/**
|
|
|
|
* Tests that it is possible to load plugin bootstrap by calling a callback function
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-04-26 05:26:19 +00:00
|
|
|
public function testCallbackBootstrap() {
|
|
|
|
CakePlugin::load('TestPlugin', array('bootstrap' => array($this, 'pluginBootstrap')));
|
2011-05-09 03:49:00 +00:00
|
|
|
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
|
2011-04-26 05:26:19 +00:00
|
|
|
$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));
|
2011-05-23 02:20:56 +00:00
|
|
|
CakePlugin::routes();
|
2011-04-26 05:26:19 +00:00
|
|
|
}
|
|
|
|
|
2011-04-29 16:53:11 +00:00
|
|
|
/**
|
|
|
|
* 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'));
|
2011-05-15 16:53:53 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS;
|
2011-04-29 16:53:11 +00:00
|
|
|
$this->assertEquals(CakePlugin::path('TestPlugin'), $expected);
|
|
|
|
|
2011-05-15 16:53:53 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPluginTwo' . DS;
|
2011-04-29 16:53:11 +00:00
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
2011-05-06 05:23:30 +00:00
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* Tests that CakePlugin::loadAll() will load all plugins in the configured folder
|
2011-05-06 05:23:30 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLoadAll() {
|
|
|
|
CakePlugin::loadAll();
|
|
|
|
$expected = array('PluginJs', 'TestPlugin', 'TestPluginTwo');
|
|
|
|
$this->assertEquals($expected, CakePlugin::loaded());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* Tests that CakePlugin::loadAll() will load all plugins in the configured folder with bootstrap loading
|
2011-05-06 05:23:30 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLoadAllWithDefaults() {
|
2011-07-15 05:35:53 +00:00
|
|
|
$defaults = array('bootstrap' => true);
|
|
|
|
CakePlugin::loadAll(array($defaults));
|
2011-05-06 05:23:30 +00:00
|
|
|
$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'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* Tests that CakePlugin::loadAll() will load all plugins in the configured folder wit defaults
|
2011-05-06 05:23:30 +00:00
|
|
|
* and overrides for a plugin
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLoadAllWithDefaultsAndOverride() {
|
2011-07-15 05:35:53 +00:00
|
|
|
CakePlugin::loadAll(array(array('bootstrap' => true), 'TestPlugin' => array('routes' => true)));
|
2011-05-23 02:20:56 +00:00
|
|
|
CakePlugin::routes();
|
|
|
|
|
2011-05-06 05:23:30 +00:00
|
|
|
$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'));
|
|
|
|
}
|
|
|
|
|
2011-04-26 05:26:19 +00:00
|
|
|
/**
|
|
|
|
* Auxiliary function to test plugin bootstrap callbacks
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function pluginBootstrap() {
|
|
|
|
Configure::write('CakePluginTest.test_plugin.bootstrap', 'called plugin bootstrap callback');
|
|
|
|
}
|
2011-05-15 16:53:53 +00:00
|
|
|
}
|