Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobocoder <anthon.pang@gmail.com>2012-01-19 09:19:21 +0400
committerrobocoder <anthon.pang@gmail.com>2012-01-19 09:19:21 +0400
commit48a0a3fb4842583fba97401045d86c4f3309dec1 (patch)
treeddef5c768584974757fa3af786b3c513bf15c604 /plugins/ExamplePlugin
parent2a2547aebd5fcaefc5ab0eaa9e67adcb0bb7b433 (diff)
fixes #2781 - add plugin-specific config file loader
Also refactored ExamplePlugin to be a better example. * 1 class per file * add config folder with .htaccess * add tests folder with some unit tests git-svn-id: http://dev.piwik.org/svn/trunk@5684 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'plugins/ExamplePlugin')
-rw-r--r--plugins/ExamplePlugin/Controller.php150
-rw-r--r--plugins/ExamplePlugin/ExamplePlugin.php139
-rw-r--r--plugins/ExamplePlugin/config/.htaccess3
-rw-r--r--plugins/ExamplePlugin/config/local.config.sample.php6
-rw-r--r--plugins/ExamplePlugin/tests/ExamplePlugin.test.php73
5 files changed, 232 insertions, 139 deletions
diff --git a/plugins/ExamplePlugin/Controller.php b/plugins/ExamplePlugin/Controller.php
new file mode 100644
index 0000000000..40b21e98c0
--- /dev/null
+++ b/plugins/ExamplePlugin/Controller.php
@@ -0,0 +1,150 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ * @version $Id$
+ *
+ * @category Piwik_Plugins
+ * @package Piwik_ExamplePlugin
+ */
+
+/**
+ *
+ * @package Piwik_ExamplePlugin
+ */
+class Piwik_ExamplePlugin_Controller extends Piwik_Controller
+{
+ /**
+ * Go to /piwik/?module=ExamplePlugin&action=helloWorld to execute this method
+ *
+ */
+ function helloWorld()
+ {
+ echo "<p>Hello world! <br />";
+ echo "Happy coding with Piwik :)</p>";
+ }
+
+ /**
+ * See the result on piwik/?module=ExamplePlugin&action=exampleWidget
+ * or in the dashboard > Add a new widget
+ *
+ */
+ function exampleWidget()
+ {
+ echo "<p>Hello world! <br /> You can output whatever you want in widgets, and put them on dashboard or everywhere on the web (in your blog, website, etc.).
+ <br />Widgets can include graphs, tables, flash, text, images, etc.
+ <br />It's very easy to create a new plugin and widgets in Piwik. Have a look at this example file (/plugins/ExamplePlugin/ExamplePlugin.php).
+ <div id='happycoding'><i>Happy coding!</i></div>
+ <div id='jsenabled'>You can easily use Jquery in widgets</div>
+ <p>
+ <script type=\"text/javascript\">$('#happycoding').hide().fadeIn(5000);$('#jsenabled').hide().css({'color':'red'}).fadeIn(10000);</script>";
+ }
+
+ /**
+ * Embed Piwik.org blog using widgetbox.com widget code
+ */
+ function blogPiwik()
+ {
+ echo '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash" width="400px" height="343px" id="InsertWidget_0bf84c7c-70b5-41c1-adbc-6f4f823c598c" align="middle"><param name="movie" value="http://widgetserver.com/syndication/flash/wrapper/InsertWidget.swf"/><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="menu" value="false" /><param name="flashvars" value="r=2&appId=0bf84c7c-70b5-41c1-adbc-6f4f823c598c" /> <embed src="http://widgetserver.com/syndication/flash/wrapper/InsertWidget.swf" name="InsertWidget_0bf84c7c-70b5-41c1-adbc-6f4f823c598c" width="400px" height="343px" quality="high" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" align="middle" flashvars="r=2&appId=0bf84c7c-70b5-41c1-adbc-6f4f823c598c" /></object>';
+ }
+
+ function photostreamMatt()
+ {
+ echo '<iframe align=center src=http://www.flickr.com/slideShow/index.gne?user_id=34965144@N00&set_id=72157602308487455 frameBorder=0 width=380 scrolling=no height=500></iframe> ';
+ }
+
+ /**
+ * this widgets shows how to make a remote API request to piwik.org
+ * you find the main JS code in templates/piwikDownloadCount.tpl
+ */
+ function piwikDownloads()
+ {
+ $view = Piwik_View::factory('piwikDownloads');
+ $this->setGeneralVariablesView($view);
+ echo $view->render();
+ }
+
+ /**
+ * This method displays a text containing an help about "How to build plugins for Piwik".
+ * This help is then used on http://piwik.org/docs/plugins/functions
+ *
+ */
+ function index()
+ {
+ $out = '';
+ $out .= '<i>This page aims to list the different functions you can use when programming plugins for Piwik.</i><br />';
+ $out .= '<b>Be careful, the following APIs may change in the near future as Piwik is still in development.</b><br />';
+
+ $out .= '<h2>General</h2>';
+ $out .= '<h3>Accessible from your plugin controller</h3>';
+
+ $out .= '<code>$this->date</code> = current selected <b>Piwik_Date</b> object (<a href="http://dev.piwik.org/trac/browser/trunk/core/Date.php">class</a>)<br />';
+ $out .= '<code>$period = Piwik_Common::getRequestVar("period");</code> - Get the current selected period<br />';
+ $out .= '<code>$idSite = Piwik_Common::getRequestVar("idSite");</code> - Get the selected idSite<br />';
+ $out .= '<code>$site = new Piwik_Site($idSite);</code> - Build the Piwik_Site object (<a href="http://dev.piwik.org/trac/browser/trunk/core/Site.php">class</a>)<br />';
+ $out .= '<code>$this->str_date</code> = current selected date in YYYY-MM-DD format<br />';
+
+ $out .= '<h3>Misc</h3>';
+ $out .= '<code>Piwik_AddMenu( $mainMenuName, $subMenuName, $url );</code> - Adds an entry to the menu in the Piwik interface (See the example in the <a href="http://dev.piwik.org/trac/browser/tags/1.0/plugins/UserCountry/UserCountry.php#L76">UserCountry Plugin file</a>)<br />';
+ $out .= '<code>Piwik_AddWidget( $widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters = array());</code> - Adds a widget that users can add in the dashboard, or export using the Widgets link at the top of the screen. See the example in the <a href="http://dev.piwik.org/trac/browser/tags/1.0/plugins/UserCountry/UserCountry.php#L70">UserCountry Plugin file</a> or any other plugin)<br />';
+ $out .= '<code>Piwik_Common::prefixTable("site")</code> = <b>' . Piwik_Common::prefixTable("site") . '</b><br />';
+
+
+ $out .= '<h2>User access</h2>';
+ $out .= '<code>Piwik::getCurrentUserLogin()</code> = <b>' . Piwik::getCurrentUserLogin() . '</b><br />';
+ $out .= '<code>Piwik::isUserHasSomeAdminAccess()</code> = <b>' . self::boolToString(Piwik::isUserHasSomeAdminAccess()) . '</b><br />';
+ $out .= '<code>Piwik::isUserHasAdminAccess( array $idSites = array(1,2) )</code> = <b>' . self::boolToString(Piwik::isUserHasAdminAccess(array(1,2) )) . '</b><br />';
+ $out .= '<code>Piwik::isUserHasViewAccess( array $idSites = array(1) ) </code> = <b>' . self::boolToString(Piwik::isUserHasViewAccess(array(1))) . '</b><br />';
+ $out .= '<code>Piwik::isUserIsSuperUser()</code> = <b>' . self::boolToString(Piwik::isUserIsSuperUser()) . '</b><br />';
+
+ $out .= '<h2>Execute SQL queries</h2>';
+ $txtQuery = "SELECT token_auth FROM ".Piwik_Common::prefixTable('user')." WHERE login = ?";
+ $result = Piwik_FetchOne($txtQuery, array('anonymous'));
+ $out .= '<code>Piwik_FetchOne("'.$txtQuery.'", array("anonymous"))</code> = <b>' . var_export($result,true) . '</b><br />';
+ $out .= '<br />';
+
+ $query = Piwik_Query($txtQuery, array('anonymous'));
+ $fetched = $query->fetch();
+ $token_auth = $fetched['token_auth'];
+
+ $out .= '<code>$query = Piwik_Query("'.$txtQuery.'", array("anonymous"))</code><br />';
+ $out .= '<code>$fetched = $query->fetch();</code><br />';
+ $out .= 'At this point, we have: <code>$fetched[\'token_auth\'] == <b>'.var_export($token_auth,true) . '</b></code><br />';
+
+ $out .= '<h2>Example Sites information API</h2>';
+ $out .= '<code>Piwik_SitesManager_API::getInstance()->getSitesWithViewAccess()</code> = <b><pre>' .var_export(Piwik_SitesManager_API::getInstance()->getSitesWithViewAccess(),true) . '</pre></b><br />';
+ $out .= '<code>Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess()</code> = <b><pre>' .var_export(Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess(),true) . '</pre></b><br />';
+
+ $out .= '<h2>Example API Users information</h2>';
+ $out .= 'View the list of API methods you can call on <a href="http://piwik.org/docs/analytics-api/reference">API reference</a><br />';
+ $out .= 'For example you can try <code>Piwik_UsersManager_API::getInstance()->getUsersSitesFromAccess("view");</code> or <code>Piwik_UsersManager_API::getInstance()->deleteUser("userToDelete");</code><br />';
+
+ $out .= '<h2>Javascript in Piwik</h2>';
+ $out .= '<h3>i18n internationalization</h3>';
+ $out .= 'In order to translate strings within Javascript code, you can use the javascript function _pk_translate( token );.
+ <ul><li>The "token" parameter is the string unique key found in the translation file. For this token string to be available in Javascript, you must
+ suffix your token by "_js" in the language file. For example, you can add <code>\'Goals_AddGoal_js\' => \'Add Goal\',</code> in the lang/en.php file</li>
+ <li>You then need to instruct Piwik to load your Javascript translations for your plugin; by default, all translation strings are not loaded in Javascript for performance reasons. This can be done by calling a custom-made Smarty modifier before the Javascript code requiring translations, eg.
+ <code>{loadJavascriptTranslations plugins=\'$YOUR_PLUGIN_NAME\'}</code>. In our previous example, the $YOUR_PLUGIN_NAME being Goals, we would write <code>{loadJavascriptTranslations plugins=\'Goals\'}</code>
+ </li><li>You can then print this string from your JS code by doing <code>_pk_translate(\'Goals_AddGoal_js\');</code>.
+ </li></ul>';
+
+ $out .= '<h3>Reload a widget in the dashboard</h3>';
+ $out .= 'It is sometimes useful to reload one widget in the dashboard (for example, every 20 seconds for a real time widget, or after a setting change).
+ You can easily force your widget to reload in the dashboard by calling the helper function <code>piwik.dashboardObject.reloadEnclosingWidget($(this));</code>.';
+
+ $out .= '<h2>Smarty plugins</h2>';
+ $out .= 'There are some builtin plugins for Smarty especially developped for Piwik. <br />
+ You can find them on the <a href="http://dev.piwik.org/trac/browser/trunk/core/SmartyPlugins">SVN at /trunk/core/SmartyPlugins</a>. <br />
+ More documentation to come about smarty plugins.<br />';
+
+ echo $out;
+ }
+
+ static private function boolToString($bool)
+ {
+ return $bool ? "true" : "false";
+ }
+}
diff --git a/plugins/ExamplePlugin/ExamplePlugin.php b/plugins/ExamplePlugin/ExamplePlugin.php
index 1a9c6376ac..2d5e3bafb6 100644
--- a/plugins/ExamplePlugin/ExamplePlugin.php
+++ b/plugins/ExamplePlugin/ExamplePlugin.php
@@ -65,142 +65,3 @@ class Piwik_ExamplePlugin extends Piwik_Plugin
Piwik_AddWidget('ExamplePlugin_exampleWidgets', 'ExamplePlugin_piwikForumVisits', 'ExamplePlugin', 'piwikDownloads');
}
}
-
-/**
- *
- * @package Piwik_ExamplePlugin
- */
-class Piwik_ExamplePlugin_Controller extends Piwik_Controller
-{
- /**
- * Go to /piwik/?module=ExamplePlugin&action=helloWorld to execute this method
- *
- */
- function helloWorld()
- {
- echo "<p>Hello world! <br />";
- echo "Happy coding with Piwik :)</p>";
- }
-
- /**
- * See the result on piwik/?module=ExamplePlugin&action=exampleWidget
- * or in the dashboard > Add a new widget
- *
- */
- function exampleWidget()
- {
- echo "<p>Hello world! <br /> You can output whatever you want in widgets, and put them on dashboard or everywhere on the web (in your blog, website, etc.).
- <br />Widgets can include graphs, tables, flash, text, images, etc.
- <br />It's very easy to create a new plugin and widgets in Piwik. Have a look at this example file (/plugins/ExamplePlugin/ExamplePlugin.php).
- <div id='happycoding'><i>Happy coding!</i></div>
- <div id='jsenabled'>You can easily use Jquery in widgets</div>
- <p>
- <script type=\"text/javascript\">$('#happycoding').hide().fadeIn(5000);$('#jsenabled').hide().css({'color':'red'}).fadeIn(10000);</script>";
- }
-
- /**
- * Embed Piwik.org blog using widgetbox.com widget code
- */
- function blogPiwik()
- {
- echo '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash" width="400px" height="343px" id="InsertWidget_0bf84c7c-70b5-41c1-adbc-6f4f823c598c" align="middle"><param name="movie" value="http://widgetserver.com/syndication/flash/wrapper/InsertWidget.swf"/><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="menu" value="false" /><param name="flashvars" value="r=2&appId=0bf84c7c-70b5-41c1-adbc-6f4f823c598c" /> <embed src="http://widgetserver.com/syndication/flash/wrapper/InsertWidget.swf" name="InsertWidget_0bf84c7c-70b5-41c1-adbc-6f4f823c598c" width="400px" height="343px" quality="high" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" align="middle" flashvars="r=2&appId=0bf84c7c-70b5-41c1-adbc-6f4f823c598c" /></object>';
- }
-
- function photostreamMatt()
- {
- echo '<iframe align=center src=http://www.flickr.com/slideShow/index.gne?user_id=34965144@N00&set_id=72157602308487455 frameBorder=0 width=380 scrolling=no height=500></iframe> ';
- }
-
- /**
- * this widgets shows how to make a remote API request to piwik.org
- * you find the main JS code in templates/piwikDownloadCount.tpl
- */
- function piwikDownloads()
- {
- $view = Piwik_View::factory('piwikDownloads');
- $this->setGeneralVariablesView($view);
- echo $view->render();
- }
-
- /**
- * This method displays a text containing an help about "How to build plugins for Piwik".
- * This help is then used on http://piwik.org/docs/plugins/functions
- *
- */
- function index()
- {
- $out = '';
- $out .= '<i>This page aims to list the different functions you can use when programming plugins for Piwik.</i><br />';
- $out .= '<b>Be careful, the following APIs may change in the near future as Piwik is still in development.</b><br />';
-
- $out .= '<h2>General</h2>';
- $out .= '<h3>Accessible from your plugin controller</h3>';
-
- $out .= '<code>$this->date</code> = current selected <b>Piwik_Date</b> object (<a href="http://dev.piwik.org/trac/browser/trunk/core/Date.php">class</a>)<br />';
- $out .= '<code>$period = Piwik_Common::getRequestVar("period");</code> - Get the current selected period<br />';
- $out .= '<code>$idSite = Piwik_Common::getRequestVar("idSite");</code> - Get the selected idSite<br />';
- $out .= '<code>$site = new Piwik_Site($idSite);</code> - Build the Piwik_Site object (<a href="http://dev.piwik.org/trac/browser/trunk/core/Site.php">class</a>)<br />';
- $out .= '<code>$this->str_date</code> = current selected date in YYYY-MM-DD format<br />';
-
- $out .= '<h3>Misc</h3>';
- $out .= '<code>Piwik_AddMenu( $mainMenuName, $subMenuName, $url );</code> - Adds an entry to the menu in the Piwik interface (See the example in the <a href="http://dev.piwik.org/trac/browser/tags/1.0/plugins/UserCountry/UserCountry.php#L76">UserCountry Plugin file</a>)<br />';
- $out .= '<code>Piwik_AddWidget( $widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters = array());</code> - Adds a widget that users can add in the dashboard, or export using the Widgets link at the top of the screen. See the example in the <a href="http://dev.piwik.org/trac/browser/tags/1.0/plugins/UserCountry/UserCountry.php#L70">UserCountry Plugin file</a> or any other plugin)<br />';
- $out .= '<code>Piwik_Common::prefixTable("site")</code> = <b>' . Piwik_Common::prefixTable("site") . '</b><br />';
-
-
- $out .= '<h2>User access</h2>';
- $out .= '<code>Piwik::getCurrentUserLogin()</code> = <b>' . Piwik::getCurrentUserLogin() . '</b><br />';
- $out .= '<code>Piwik::isUserHasSomeAdminAccess()</code> = <b>' . self::boolToString(Piwik::isUserHasSomeAdminAccess()) . '</b><br />';
- $out .= '<code>Piwik::isUserHasAdminAccess( array $idSites = array(1,2) )</code> = <b>' . self::boolToString(Piwik::isUserHasAdminAccess(array(1,2) )) . '</b><br />';
- $out .= '<code>Piwik::isUserHasViewAccess( array $idSites = array(1) ) </code> = <b>' . self::boolToString(Piwik::isUserHasViewAccess(array(1))) . '</b><br />';
- $out .= '<code>Piwik::isUserIsSuperUser()</code> = <b>' . self::boolToString(Piwik::isUserIsSuperUser()) . '</b><br />';
-
- $out .= '<h2>Execute SQL queries</h2>';
- $txtQuery = "SELECT token_auth FROM ".Piwik_Common::prefixTable('user')." WHERE login = ?";
- $result = Piwik_FetchOne($txtQuery, array('anonymous'));
- $out .= '<code>Piwik_FetchOne("'.$txtQuery.'", array("anonymous"))</code> = <b>' . var_export($result,true) . '</b><br />';
- $out .= '<br />';
-
- $query = Piwik_Query($txtQuery, array('anonymous'));
- $fetched = $query->fetch();
- $token_auth = $fetched['token_auth'];
-
- $out .= '<code>$query = Piwik_Query("'.$txtQuery.'", array("anonymous"))</code><br />';
- $out .= '<code>$fetched = $query->fetch();</code><br />';
- $out .= 'At this point, we have: <code>$fetched[\'token_auth\'] == <b>'.var_export($token_auth,true) . '</b></code><br />';
-
- $out .= '<h2>Example Sites information API</h2>';
- $out .= '<code>Piwik_SitesManager_API::getInstance()->getSitesWithViewAccess()</code> = <b><pre>' .var_export(Piwik_SitesManager_API::getInstance()->getSitesWithViewAccess(),true) . '</pre></b><br />';
- $out .= '<code>Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess()</code> = <b><pre>' .var_export(Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess(),true) . '</pre></b><br />';
-
- $out .= '<h2>Example API Users information</h2>';
- $out .= 'View the list of API methods you can call on <a href="http://piwik.org/docs/analytics-api/reference">API reference</a><br />';
- $out .= 'For example you can try <code>Piwik_UsersManager_API::getInstance()->getUsersSitesFromAccess("view");</code> or <code>Piwik_UsersManager_API::getInstance()->deleteUser("userToDelete");</code><br />';
-
- $out .= '<h2>Javascript in Piwik</h2>';
- $out .= '<h3>i18n internationalization</h3>';
- $out .= 'In order to translate strings within Javascript code, you can use the javascript function _pk_translate( token );.
- <ul><li>The "token" parameter is the string unique key found in the translation file. For this token string to be available in Javascript, you must
- suffix your token by "_js" in the language file. For example, you can add <code>\'Goals_AddGoal_js\' => \'Add Goal\',</code> in the lang/en.php file</li>
- <li>You then need to instruct Piwik to load your Javascript translations for your plugin; by default, all translation strings are not loaded in Javascript for performance reasons. This can be done by calling a custom-made Smarty modifier before the Javascript code requiring translations, eg.
- <code>{loadJavascriptTranslations plugins=\'$YOUR_PLUGIN_NAME\'}</code>. In our previous example, the $YOUR_PLUGIN_NAME being Goals, we would write <code>{loadJavascriptTranslations plugins=\'Goals\'}</code>
- </li><li>You can then print this string from your JS code by doing <code>_pk_translate(\'Goals_AddGoal_js\');</code>.
- </li></ul>';
-
- $out .= '<h3>Reload a widget in the dashboard</h3>';
- $out .= 'It is sometimes useful to reload one widget in the dashboard (for example, every 20 seconds for a real time widget, or after a setting change).
- You can easily force your widget to reload in the dashboard by calling the helper function <code>piwik.dashboardObject.reloadEnclosingWidget($(this));</code>.';
-
- $out .= '<h2>Smarty plugins</h2>';
- $out .= 'There are some builtin plugins for Smarty especially developped for Piwik. <br />
- You can find them on the <a href="http://dev.piwik.org/trac/browser/trunk/core/SmartyPlugins">SVN at /trunk/core/SmartyPlugins</a>. <br />
- More documentation to come about smarty plugins.<br />';
-
- echo $out;
- }
-
- static private function boolToString($bool)
- {
- return $bool ? "true" : "false";
- }
-}
diff --git a/plugins/ExamplePlugin/config/.htaccess b/plugins/ExamplePlugin/config/.htaccess
new file mode 100644
index 0000000000..c59d4d3557
--- /dev/null
+++ b/plugins/ExamplePlugin/config/.htaccess
@@ -0,0 +1,3 @@
+<Files "*">
+Deny from all
+</Files>
diff --git a/plugins/ExamplePlugin/config/local.config.sample.php b/plugins/ExamplePlugin/config/local.config.sample.php
new file mode 100644
index 0000000000..24da8c15be
--- /dev/null
+++ b/plugins/ExamplePlugin/config/local.config.sample.php
@@ -0,0 +1,6 @@
+<?php
+return array(
+ 'id' => 'Example',
+ 'name' => 'ExamplePlugin',
+ 'description' => 'This is an example',
+);
diff --git a/plugins/ExamplePlugin/tests/ExamplePlugin.test.php b/plugins/ExamplePlugin/tests/ExamplePlugin.test.php
new file mode 100644
index 0000000000..ff82417ab0
--- /dev/null
+++ b/plugins/ExamplePlugin/tests/ExamplePlugin.test.php
@@ -0,0 +1,73 @@
+<?php
+if(!defined('PIWIK_CONFIG_TEST_INCLUDED'))
+{
+ require_once dirname(__FILE__)."/../../../tests/config_test.php";
+}
+
+class Test_Piwik_ExamplePlugin extends UnitTestCase
+{
+ function setUp()
+ {
+ $path = dirname(__FILE__).'/../config/local.config.php';
+ if (file_exists($path))
+ {
+ @unlink($path);
+ }
+
+ $this->assertFalse(file_exists($path), 'unable to remove local.config.php');
+ }
+
+ function test_load_with_no_config()
+ {
+ $objectUnderTest = new Piwik_Plugin_Config('ExamplePlugin');
+
+ $this->assertFalse($objectUnderTest->load(), 'load() with no config should fail');
+ }
+
+ function test_load_alternate_path()
+ {
+ $objectUnderTest = new Piwik_Plugin_Config('ExamplePlugin', 'local.config.sample.php');
+ $config = $objectUnderTest->load();
+
+ $this->assertTrue($config !== false);
+ $this->assertTrue($config['id'] === 'Example');
+ $this->assertTrue($config['name'] === 'ExamplePlugin');
+ $this->assertTrue($config['description'] === 'This is an example');
+ }
+
+ function test_load()
+ {
+ $dir = dirname(__FILE__).'/../config';
+ @copy($dir . '/local.config.sample.php', $dir . '/local.config.php');
+
+ $objectUnderTest = new Piwik_Plugin_Config('ExamplePlugin');
+ $config = $objectUnderTest->load();
+
+ $this->assertTrue($config !== false);
+ $this->assertTrue($config['id'] === 'Example');
+ $this->assertTrue($config['name'] === 'ExamplePlugin');
+ $this->assertTrue($config['description'] === 'This is an example');
+ }
+
+ function test_store()
+ {
+ $config = array(
+ 1, 'mixed', array('a'), 'b' => 'c'
+ );
+
+ $objectUnderTest = new Piwik_Plugin_Config('ExamplePlugin');
+ $objectUnderTest->store($config);
+
+ $path = dirname(__FILE__).'/../config/local.config.php';
+ $this->assertTrue(file_exists($path));
+
+ $objectUnderTest = new Piwik_Plugin_Config('ExamplePlugin');
+ $newConfig = $objectUnderTest->load();
+
+ $this->assertTrue($config !== false);
+ $this->assertTrue($config[0] === 1);
+ $this->assertTrue($config[1] === 'mixed');
+ $this->assertTrue(is_array($config[2]) && $config[2][0] === 'a');
+ $this->assertTrue($config['b'] === 'c');
+ }
+}