From 0ed9f1d4999c0b3404cd2ee50ba524b37f9b2acb Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Sat, 29 Sep 2012 17:11:07 +0100 Subject: [PATCH] adding event tests --- Core/Charts/Lib/ChartsEvents.php | 244 +++++++++--------- .../Charts/Test/Case/Lib/ChartsEventsTest.php | 24 +- Core/Comments/Lib/CommentsEvents.php | 210 +++++++++------ .../Test/Case/Lib/CommentsEventsTest.php | 36 +-- 4 files changed, 279 insertions(+), 235 deletions(-) diff --git a/Core/Charts/Lib/ChartsEvents.php b/Core/Charts/Lib/ChartsEvents.php index 1bde98b10..5095f97a0 100644 --- a/Core/Charts/Lib/ChartsEvents.php +++ b/Core/Charts/Lib/ChartsEvents.php @@ -1,121 +1,131 @@ array( - * 'MyPlugin.Example' - * ) - * // ... - * ) - * } - * - * // or from within a controller method - * - * $this->helpers['Charts.Charts'][] = 'MyPlugin.Example'; - * @endcode - * - * Both examples will look for and include a helper in the folder - * plugins/my_plugin/views/helpers/example_chart_engine.php with and the class - * should lool like this: - * - * @code - * class ExampleChartEngineHelper extends ChartsBaseEngineHelper{ - * // ... - * } - * @endcode - * - * After having done this you will be able to use the charts helper to start - * building charts for what ever data you have. You also have the option of - * making a certain chart globally available by including it with the Event - * system. - * - * A basic example of creating a html chart will look something like below. - * Note that this is almost the format that the charts engine produces, basically - * it will shuffle things around to be more simple to manipulate and allows - * for a few other options like passing size as '900,150' (a string) instead - * of the array format. This is true for all options. - * - * @code - * echo $this->Charts->draw( - * 'bar', - * array( - * 'data' => array(10, 15, 20, 5, 10, 40), - * 'axes' => array( - * 'x' => array('a', 'b', 'c', 'd', 'e', 'f'), - * 'y' => '' - * ), - * 'size' => array(900, 150) - * 'tooltip' => true - * ) - * ); - * @endcode - * - * @section categories-code How it works - * - * When the charts helper is initialized it take the engine that you passed - * and adds it to the helpers array. Pretty basic stuff, its just adding another - * helper. - * - * When you call ChartsHelper::draw() with the params it will take all the - * data passed and make sure its mostly valid and ready for the chart engine - * to process. This makes it really simple to either switch the chart engine - * at a later stage and develop new engines that can be used with ease. - * - * The Charts helper will also take care of caching so times when the data - * has been cached there will be no calls to the actual engine drawing the - * charts. - * - * @section categories-see-also Also see - * @ref EventCore - * @ref GoogleStaticChartHelper - * @ref HtmlChartEngineHelper - */ +/** + * @page Charts-Plugin Charts plugin + * + * @section charts-overview What is it + * + * The Charts plugin is an abstraction of data that uses the Adapter + * design pattern to draw the charts. This make it really simple to extend + * and change. There are some core classes included for some types of charts + * that you can use as is, or as a base to create your own. + * + * @section categories-usage How to use it + * + * To get started creating some charts you will need to include the Charts + * helper in your code, this can be done by adding either of the following + * + * @code + * // could also be within another helper + * class MyController extends MyPluginAppController{ + * public $helpers = array( + * // ... + * 'Charts.Charts' => array( + * 'MyPlugin.Example' + * ) + * // ... + * ) + * } + * + * // or from within a controller method + * + * $this->helpers['Charts.Charts'][] = 'MyPlugin.Example'; + * @endcode + * + * Both examples will look for and include a helper in the folder + * plugins/my_plugin/views/helpers/example_chart_engine.php with and the class + * should lool like this: + * + * @code + * class ExampleChartEngineHelper extends ChartsBaseEngineHelper{ + * // ... + * } + * @endcode + * + * After having done this you will be able to use the charts helper to start + * building charts for what ever data you have. You also have the option of + * making a certain chart globally available by including it with the Event + * system. + * + * A basic example of creating a html chart will look something like below. + * Note that this is almost the format that the charts engine produces, basically + * it will shuffle things around to be more simple to manipulate and allows + * for a few other options like passing size as '900,150' (a string) instead + * of the array format. This is true for all options. + * + * @code + * echo $this->Charts->draw( + * 'bar', + * array( + * 'data' => array(10, 15, 20, 5, 10, 40), + * 'axes' => array( + * 'x' => array('a', 'b', 'c', 'd', 'e', 'f'), + * 'y' => '' + * ), + * 'size' => array(900, 150) + * 'tooltip' => true + * ) + * ); + * @endcode + * + * @section categories-code How it works + * + * When the charts helper is initialized it take the engine that you passed + * and adds it to the helpers array. Pretty basic stuff, its just adding another + * helper. + * + * When you call ChartsHelper::draw() with the params it will take all the + * data passed and make sure its mostly valid and ready for the chart engine + * to process. This makes it really simple to either switch the chart engine + * at a later stage and develop new engines that can be used with ease. + * + * The Charts helper will also take care of caching so times when the data + * has been cached there will be no calls to the actual engine drawing the + * charts. + * + * @section categories-see-also Also see + * @ref EventCore + * @ref GoogleStaticChartHelper + * @ref HtmlChartEngineHelper + */ - /** - * @brief Charts plugin events - * - * The events for the charts plugin allows the plugin to integrate with the - * core code. - * - * @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 ) - * @link http://www.infinitas-cms.org - * @package Infinitas.Charts - * @license http://www.opensource.org/licenses/mit-license.php The MIT License - * @since 0.8a - * - * @author dogmatic69 - * - * Licensed under The MIT License - * Redistributions of files must retain the above copyright notice. - */ +/** + * @brief Charts plugin events + * + * The events for the charts plugin allows the plugin to integrate with the + * core code. + * + * @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 ) + * @link http://www.infinitas-cms.org + * @package Infinitas.Charts + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + * @since 0.8a + * + * @author dogmatic69 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + */ - final class ChartsEvents extends AppEvents { - public function onRequireLibs() { - App::uses('ChartDataManipulation', 'Charts.Lib'); - } +class ChartsEvents extends AppEvents { +/** + * @brief make the required libs available + */ + public function onRequireLibs() { + App::uses('ChartDataManipulation', 'Charts.Lib'); + } - public function onRequireHelpersToLoad($event = null) { - return array( - 'Charts.Charts' => array( - Configure::read('Charts.default_engine') - ) - ); - } - } \ No newline at end of file +/** + * @brief load the default helpers for the chart engine + * + * @param Event $event + * + * @return array + */ + public function onRequireHelpersToLoad(Event $event) { + return array( + 'Charts.Charts' => array( + Configure::read('Charts.default_engine') + ) + ); + } +} \ No newline at end of file diff --git a/Core/Charts/Test/Case/Lib/ChartsEventsTest.php b/Core/Charts/Test/Case/Lib/ChartsEventsTest.php index 607be0fc3..731de5155 100755 --- a/Core/Charts/Test/Case/Lib/ChartsEventsTest.php +++ b/Core/Charts/Test/Case/Lib/ChartsEventsTest.php @@ -1,16 +1,10 @@ Event = EventCore::getInstance(); - } - - public function endTest() { - unset($this->Event); - ClassRegistry::flush(); - } - - public function testLibIsLoaded() { - $this->assertIsA($this->Event, 'EventCore'); - $this->assertTrue(class_exists('ChartDataManipulation')); - } - } \ No newline at end of file +App::uses('InfinitasEventTestCase', 'Events.Test/Lib'); +class ChartsEventsTest extends InfinitasEventTestCase { +/** + * @brief test that the manipulation libs are available + */ + public function testLibIsLoaded() { + $this->assertTrue(class_exists('ChartDataManipulation')); + } +} \ No newline at end of file diff --git a/Core/Comments/Lib/CommentsEvents.php b/Core/Comments/Lib/CommentsEvents.php index 369f0eec0..d53c04c6e 100644 --- a/Core/Comments/Lib/CommentsEvents.php +++ b/Core/Comments/Lib/CommentsEvents.php @@ -1,93 +1,145 @@ 'Comments', - 'description' => 'See what your users have to say', - 'icon' => '/comments/img/icon.png', - 'author' => 'Infinitas', - 'dashboard' => array( - 'plugin' => 'comments', - 'controller' => 'infinitas_comments', - 'action' => 'index' - ) - ); - } +class CommentsEvents extends AppEvents { +/** + * @brief get the plugin information + * + * @return array + */ + public function onPluginRollCall() { + return array( + 'name' => 'Comments', + 'description' => 'See what your users have to say', + 'icon' => '/comments/img/icon.png', + 'author' => 'Infinitas', + 'dashboard' => array( + 'plugin' => 'comments', + 'controller' => 'infinitas_comments', + 'action' => 'index' + ) + ); + } - public function onAdminMenu($event) { - $menu['main'] = array( - 'Comments' => array('plugin' => 'comments', 'controller' => 'infinitas_comments', 'action' => 'index'), - 'Active' => array('plugin' => 'comments', 'controller' => 'infinitas_comments', 'action' => 'index', 'Comment.active' => 1), - 'Pending' => array('plugin' => 'comments', 'controller' => 'infinitas_comments', 'action' => 'index', 'Comment.active' => 0, 'Comment.status' => 'approved'), - 'Spam' => array('plugin' => 'comments', 'controller' => 'infinitas_comments', 'action' => 'index', 'Comment.status' => 'spam') - ); +/** + * @brief get the admin menu + * + * @param Event $event + * + * @return array + */ + public function onAdminMenu(Event $event) { + $menu['main'] = array( + 'Comments' => array('plugin' => 'comments', 'controller' => 'infinitas_comments', 'action' => 'index'), + 'Active' => array('plugin' => 'comments', 'controller' => 'infinitas_comments', 'action' => 'index', 'Comment.active' => 1), + 'Pending' => array('plugin' => 'comments', 'controller' => 'infinitas_comments', 'action' => 'index', 'Comment.active' => 0, 'Comment.status' => 'approved'), + 'Spam' => array('plugin' => 'comments', 'controller' => 'infinitas_comments', 'action' => 'index', 'Comment.status' => 'spam') + ); - return $menu; - } + return $menu; + } - public function onRequireComponentsToLoad($event = null) { - return array( - 'Comments.Comments' - ); - } - - public function onAttachBehaviors($event) { - if(is_subclass_of($event->Handler, 'Model')) { - if ($event->Handler->hasField('comment_count')) { - if(!$event->Handler->Behaviors->enabled('Comments.Commentable')) { - $event->Handler->Behaviors->attach('Comments.Commentable'); - } +/** + * @brief get the required components + * + * @param Event $event + * + * @return array + */ + public function onRequireComponentsToLoad(Event $event) { + return array( + 'Comments.Comments' + ); + } + +/** + * @brief get the behaviors to attach + * + * @param Event $event + */ + public function onAttachBehaviors(Event $event) { + if(is_subclass_of($event->Handler, 'Model')) { + if ($event->Handler->hasField('comment_count')) { + if(!$event->Handler->Behaviors->enabled('Comments.Commentable')) { + $event->Handler->Behaviors->attach('Comments.Commentable'); } } } + } - public function onRequireCssToLoad($event) { - return array( - 'Comments.comment' - ); - } +/** + * @brief get the css to load + * + * @param Event $event + * + * @return array + */ + public function onRequireCssToLoad(Event $event) { + return array( + 'Comments.comment' + ); + } - public function onRequireJavascriptToLoad($event) { - return array( - 'Comments.comment' - ); - } +/** + * @brief get the js to load + * + * @param Event $event + * + * @return array + */ + public function onRequireJavascriptToLoad(Event $event) { + return array( + 'Comments.comment' + ); + } - public function onSiteMapRebuild($event) { - $newestRow = ClassRegistry::init('Comments.Comment')->getNewestRow(); +/** + * @brief get the sitemap information + * + * @param Event $event + * + * @return array + */ + public function onSiteMapRebuild(Event $event) { + $newestRow = ClassRegistry::init('Comments.Comment')->getNewestRow(); - if(!$newestRow) { - return false; - } - - return array( - array( - 'url' => Router::url(array('plugin' => 'comments', 'controller' => 'infinitas_comments', 'action' => 'index', 'admin' => false, 'prefix' => false), true), - 'last_modified' => $newestRow, - 'change_frequency' => ClassRegistry::init('Comments.InfinitasComment')->getChangeFrequency(), - 'priority' => 0.8 - ) - ); + if(!$newestRow) { + return false; } - public function onUserProfile($event) { - return array( - 'element' => 'profile' - ); - } - } \ No newline at end of file + return array( + array( + 'url' => Router::url(array('plugin' => 'comments', 'controller' => 'infinitas_comments', 'action' => 'index', 'admin' => false, 'prefix' => false), true), + 'last_modified' => $newestRow, + 'change_frequency' => ClassRegistry::init('Comments.InfinitasComment')->getChangeFrequency(), + 'priority' => 0.8 + ) + ); + } + +/** + * @brief get the user profile elements to load + * + * @param Event $event + * + * @return array + */ + public function onUserProfile(Event $event) { + return array( + 'element' => 'profile' + ); + } +} \ No newline at end of file diff --git a/Core/Comments/Test/Case/Lib/CommentsEventsTest.php b/Core/Comments/Test/Case/Lib/CommentsEventsTest.php index e427a3f7b..3cfa8c729 100644 --- a/Core/Comments/Test/Case/Lib/CommentsEventsTest.php +++ b/Core/Comments/Test/Case/Lib/CommentsEventsTest.php @@ -1,25 +1,13 @@ Event = EventCore::getInstance(); - } - - public function endTest() { - unset($this->Event); - ClassRegistry::flush(); - } - - public function testGenerateSiteMapData() { - $this->assertInstanceOf('EventCore', $this->Event); - } - } \ No newline at end of file +App::uses('InfinitasEventTestCase', 'Events.Test/Lib'); +class CommentsEventsTest extends InfinitasEventTestCase { + public $fixtures = array( + 'plugin.configs.config', + 'plugin.themes.theme', + 'plugin.routes.route', + 'plugin.view_counter.view_counter_view', + + 'plugin.comments.infinitas_comment', + 'plugin.comments.infinitas_comment_attribute' + ); +} \ No newline at end of file