diff --git a/Core/Assets/Test/Case/Lib/AssetsEventsTest.php b/Core/Assets/Test/Case/Lib/AssetsEventsTest.php index dffb217d4..5622dddcd 100644 --- a/Core/Assets/Test/Case/Lib/AssetsEventsTest.php +++ b/Core/Assets/Test/Case/Lib/AssetsEventsTest.php @@ -5,9 +5,9 @@ class AssetsEventsTest extends InfinitasEventTestCase { *@brief test required helpers load correctly */ public function testRequireHelpers() { - $this->Object->params = array(); + $this->ViewObject->params = array(); $expected = array('requireHelpersToLoad' => array('Assets' => array('Assets.Compress'))); - $result = $this->Event->trigger($this->Object, 'Assets.requireHelpersToLoad'); + $result = $this->Event->trigger($this->ViewObject, 'Assets.requireHelpersToLoad'); $this->assertEquals($expected, $result); } @@ -15,7 +15,7 @@ public function testRequireHelpers() { * @brief test required js loads correctly */ public function testRequireJavascript() { - $this->Object->params = array(); + $this->ViewObject->params = array(); $expected = array('requireJavascriptToLoad' => array('Assets' => array( 'Assets.3rd/jquery', 'Assets.3rd/jquery_ui', @@ -28,10 +28,10 @@ public function testRequireJavascript() { 'Assets.3rd/rater', 'Assets.3rd/moving_boxes' ))); - $result = $this->Event->trigger($this->Object, 'Assets.requireJavascriptToLoad'); + $result = $this->Event->trigger($this->ViewObject, 'Assets.requireJavascriptToLoad'); $this->assertEquals($expected, $result); - $this->Object->params = array( + $this->ViewObject->params = array( 'admin' => true ); $expected = array('requireJavascriptToLoad' => array('Assets' => array( @@ -46,7 +46,7 @@ public function testRequireJavascript() { 'Assets.3rd/date', 'Assets.3rd/image_drop_down' ))); - $result = $this->Event->trigger($this->Object, 'Assets.requireJavascriptToLoad'); + $result = $this->Event->trigger($this->ViewObject, 'Assets.requireJavascriptToLoad'); $this->assertEquals($expected, $result); } } \ No newline at end of file diff --git a/Core/Events/Lib/AppEvents.php b/Core/Events/Lib/AppEvents.php index b6e763bfa..e741faeeb 100644 --- a/Core/Events/Lib/AppEvents.php +++ b/Core/Events/Lib/AppEvents.php @@ -1,13 +1,13 @@ log(), redirect() and other basic methods - * + * * Copyright (c) 2010 Carl Sutton ( dogmatic69 ) - * + * * @filesource * @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 ) * @link http://www.infinitas-cms.org @@ -15,9 +15,9 @@ * @subpackage infinitas.events.app_events * @license http://www.opensource.org/licenses/mit-license.php The MIT License * @since 0.8 - * + * * @author dogmatic69 - * + * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. */ @@ -35,7 +35,7 @@ public function __construct() { if(!empty($this->__events)) { return true; } - + $this->__events = get_class_methods('AppEvents'); foreach($this->__events as $k => $event) { if(substr($event, 0, 2) != 'on') { @@ -54,7 +54,7 @@ public function __construct() { final public function availableEvents() { return $this->__events; } - + /** * test if things are working */ @@ -82,7 +82,7 @@ public function onRequireLibs() {} * They will be loaded when 'AppController' is included, before it runs. */ public function onLoadAppController() {} - + /** * Load up some of your own 'AppModels' so that you can create a base @@ -99,12 +99,12 @@ public function onLoadAppModel() {} * Add database connections from your plugins with this trigger. * Its called in appModel before anything is created, even before default * (which is a reserved value) - * + * * Event should return in the format 'name' => array('configs') * * @param object $event */ - public function onRequireDatabaseConfigs($event) {} + public function onRequireDatabaseConfigs(Event $Event) {} /** * Load the default cache settings. @@ -116,11 +116,11 @@ public function onRequireDatabaseConfigs($event) {} * * @return true */ - public function onSetupCache($event, $data = null) {} + public function onSetupCache(Event $Event, $data = null) {} - public function onSetupConfigStart($event, $data = null) {} - - public function onSetupConfigEnd($event, $data = null) {} + public function onSetupConfigStart(Event $Event, $data = null) {} + + public function onSetupConfigEnd(Event $Event, $data = null) {} /** * Adding routes @@ -128,10 +128,10 @@ public function onSetupConfigEnd($event, $data = null) {} * Add routing to for the app from your plugin by calling Router::connect * This should be used for routes that will not change if your plugin * has routes that can be configured they should be in the database. - * + * * @return nothing, it wont do anything */ - public function onSetupRoutes($event, $data = null) {} + public function onSetupRoutes(Event $Event, $data = null) {} /** * parse extensions @@ -140,7 +140,7 @@ public function onSetupRoutes($event, $data = null) {} * * @return array of extensions that should be registered. */ - public function onSetupExtensions($event) {} + public function onSetupExtensions(Event $Event) {} /** * @brief called when editing a row is canceled @@ -152,12 +152,12 @@ public function onSetupExtensions($event) {} * @param Event $event the event being called * @param string $id */ - public function onEditCanceled($event, $id) {} + public function onEditCanceled(Event $Event, $id) {} /** * */ - public function onAttachBehaviors($event = null) {} + public function onAttachBehaviors(Event $Event = null) {} @@ -191,7 +191,7 @@ public function onAttachBehaviors($event = null) {} * you can use {{templates.foo.phone}} in your views to show your phone * number. */ - public function onRequireGlobalTemplates($event) {} + public function onRequireGlobalTemplates(Event $Event) {} /** * @brief used to build the menus for the admin pages @@ -208,7 +208,7 @@ public function onAdminMenu() {} * * @return mixed string | array like you would use in Controller->helpers */ - public function onRequireHelpersToLoad($event = null) { + public function onRequireHelpersToLoad(Event $Event = null) { return array(); } @@ -217,13 +217,13 @@ public function onRequireHelpersToLoad($event = null) { * * Allows you to include javascript from your plugin that can be loaded * on any page - * + * * called in AppController::beforeRender() * * @param $event some data for the current event * @return mixed string | array() of javascript like HtmlHelper::script() takes */ - public function onRequireJavascriptToLoad($event, $data = null) {} + public function onRequireJavascriptToLoad(Event $Event, $data = null) {} /** * Get vcss files to include @@ -236,7 +236,7 @@ public function onRequireJavascriptToLoad($event, $data = null) {} * @param $event some data for the current event * @return mixed string | array() of css like HtmlHelper::css() takes */ - public function onRequireCssToLoad($event, $data = null) {} + public function onRequireCssToLoad(Event $Event, $data = null) {} /** * Load components @@ -249,7 +249,7 @@ public function onRequireCssToLoad($event, $data = null) {} * @param $event some data for the current event * @return mixed string | array() of css like HtmlHelper::css() takes */ - public function onRequireComponentsToLoad($event = null) { + public function onRequireComponentsToLoad(Event $Event = null) { return array(); } @@ -261,11 +261,11 @@ public function onRequireComponentsToLoad($event = null) { * normally in the form of Model::find(first) that you can use. * */ - public function onSlugUrl($event, $data = null, $type = null) { + public function onSlugUrl(Event $Event, $data = null, $type = null) { if(empty($data) || $type == null) { return false; } - + $plugin = str_replace('Events', '', get_class($this)); $data = Set::flatten($data); @@ -297,19 +297,19 @@ public function onSlugUrl($event, $data = null, $type = null) { * dependancies or configs, new records like pending comments etc. * * @code - * // format should be + * // format should be * $return[0]['name'] = 'something'; * $return[0]['type'] = 'warning|error'; * $return[0]['url'] = array(); * @endcode */ - public function onRequireTodoList($event) {} + public function onRequireTodoList(Event $Event) {} /** * Last event to fire. * * Called after everything is done and finished. should not really be used - * for output unless in debug mode. + * for output unless in debug mode. */ public function onRequestDone() {} @@ -324,7 +324,7 @@ public function onRequestDone() {} * * @access public */ - public function onRunCrons($event) { + public function onRunCrons(Event $Event) { return false; } } \ No newline at end of file diff --git a/Core/Events/Lib/EventCore.php b/Core/Events/Lib/EventCore.php index 91570272b..b2eb0afab 100644 --- a/Core/Events/Lib/EventCore.php +++ b/Core/Events/Lib/EventCore.php @@ -45,7 +45,7 @@ class EventCore { private $__availablePlugins = array(); private $__installedPlugins = array(); - + private $__pluginsMap = array( 'testEvent' => 'all', 'setupRoutes' => 'all', @@ -203,7 +203,7 @@ protected function _loadEventHandlers() { Cache::write('event_handlers', $this->_eventHandlerCache, 'core'); } - + public static function loadEventHandler($plugin) { $_this = self::getInstance(); $filename = App::pluginPath($plugin) . 'Lib' . DS . $plugin . 'Events.php'; @@ -232,12 +232,12 @@ static protected function _dispatchEvent(&$HandlerObject, $scope, $eventName, $d if(isset($_this->_eventHandlerCache[$eventName])) { foreach($_this->_eventHandlerCache[$eventName] as $eventClass) { $pluginName = EventCore::_extractPluginName($eventClass); - + $pluginType = 'loaded'; if(isset($_this->__pluginsMap[$eventName])) { $pluginType = $_this->__pluginsMap[$eventName]; } - + if(!in_array(Inflector::camelize($pluginName), (array)InfinitasPlugin::listPlugins($pluginType))) { continue; } @@ -399,7 +399,7 @@ class Event { * @param string $eventName Name of the Event * @param array $data optional array with k/v data */ - public function __construct($eventName, &$HandlerObject, $pluginName) { + public function __construct($eventName, $HandlerObject, $pluginName) { $this->name = $eventName; $this->Handler = $HandlerObject; $this->plugin = $pluginName; diff --git a/Core/Events/Test/Lib/InfinitasEventTestCase.php b/Core/Events/Test/Lib/InfinitasEventTestCase.php index 6ddfb110a..41bc9c6ba 100644 --- a/Core/Events/Test/Lib/InfinitasEventTestCase.php +++ b/Core/Events/Test/Lib/InfinitasEventTestCase.php @@ -5,18 +5,52 @@ class InfinitasEventTestCase extends CakeTestCase { /** * @brief set up required objects for testing + * + * @todo setup MVC objects to pass in the correct places */ - public function startTest() { - $this->Object = new Object(); + public function setUp() { + parent::setUp(); + $this->_setPlugin(); + + $this->ModelObject = $this->ViewObject = $this->ControllerObject = new Object(); + + $this->ObjectEvent = new Event('TestEvent', new Object(), $this->plugin); + $this->ModelEvent = new Event('ModelEvent', $this->ModelObject, $this->plugin); + $this->ViewtEvent = new Event('ViewtEvent', $this->ViewObject, $this->plugin); + $this->ControllerEvent = new Event('ControllerEvent', $this->ControllerObject, $this->plugin); + $this->Event = EventCore::getInstance(); + + $this->_loadEventClass(); } /** * @brief clear up the enviroment */ - public function endTest() { - unset($this->Event, $this->Object); - ClassRegistry::flush(); + public function tearDown() { + parent::tearDown(); + unset($this->Event, $this->EventClass); + unset($this->ObjectEvent, $this->ControllerEvent, $this->ModelEvent, $this->ViewtEvent); + unset($this->ModelObject, $this->ViewObject, $this->ControllerObject); + } + +/** + * @brief setup the current plugin name + */ + protected function _setPlugin() { + if(!isset($this->plugin)) { + $this->plugin = str_replace('EventsTest', '', get_class($this)); + } + } + +/** + * @brief load and get an instance of the event class being tested + */ + protected function _loadEventClass() { + //App::uses($this->plugin . 'Events', $this->plugin . '.Lib'); + + $this->EventClass = $this->plugin . 'Events'; + $this->EventClass = new $this->EventClass(); } /** @@ -25,4 +59,24 @@ public function endTest() { public function testInstance() { $this->assertInstanceOf('EventCore', $this->Event); } + +/** + * @brief test getting the plugins details + */ + public function testPluginRollCall() { + $expected = array('pluginRollCall' => array($this->EventClass->onPluginRollCall())); + $expected['pluginRollCall'] = array_filter($expected['pluginRollCall']); + $result = $this->Event->trigger(new Object(), $this->plugin . '.pluginRollCall'); + $this->assertEquals($expected, $result); + } + +/** + * @brief test getting additional db configs + */ + public function testRequireDatabaseConfigs() { + $expected = array('requireDatabaseConfigs' => array($this->EventClass->onRequireDatabaseConfigs($this->ModelEvent))); + $expected['requireDatabaseConfigs'] = array_filter($expected['requireDatabaseConfigs']); + $result = $this->Event->trigger(new Object(), $this->plugin . '.requireDatabaseConfigs'); + $this->assertEquals($expected, $result); + } } \ No newline at end of file