diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2019-03-15 01:24:36 +0300 |
---|---|---|
committer | diosmosis <diosmosis@users.noreply.github.com> | 2019-03-15 01:24:36 +0300 |
commit | 6395855aa7f3813cc7f413a18d31505ea26ba32a (patch) | |
tree | 2a3157954dd3c29cc024bf7093df53b63be94dd6 /tests/resources | |
parent | d7c932710e690d87ea62c3ec94ae65fa5bd05b05 (diff) |
Support multiple plugin paths (#14051)
* do not hard code plugins directory
* remove method that is not needed for now
* use plugins directory in more places
* some work on supporting multiple plugin directories
* use more unique name
* couple fixes
* and another fix
* sort plugins
* adjust languagesmanager
* adjust more usages
* Update Manager.php
* adding a plugin to test
* more tests
* make sure plugin resources can be located in custom directory
* adding more tests
* rewrite image paths
* handle more cases
* add tests
* make sure to load plugin
* trying to fix test
* trying it this way
* load plugin
* fix ui test?
* testing if tests succeed this way
* another test
* load custom dir plugin
* load plugin in ui fixture
* change the update statement
* remove update script
* delete column
* fix ui test
* make it work for tests
* fix some tests
* Fix merge.
Diffstat (limited to 'tests/resources')
20 files changed, 445 insertions, 0 deletions
diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/.gitignore b/tests/resources/custompluginsdir/CustomDirPlugin/.gitignore new file mode 100644 index 0000000000..c8c9480010 --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/.gitignore @@ -0,0 +1 @@ +tests/System/processed/*xml
\ No newline at end of file diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/API.php b/tests/resources/custompluginsdir/CustomDirPlugin/API.php new file mode 100644 index 0000000000..08a0a957c5 --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/API.php @@ -0,0 +1,22 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\CustomDirPlugin; + +class API extends \Piwik\Plugin\API +{ + public function getCustomAnswerToLive($truth = true) + { + if ($truth) { + return 42; + } + + return 24; + } + +} diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/Controller.php b/tests/resources/custompluginsdir/CustomDirPlugin/Controller.php new file mode 100644 index 0000000000..81631f81f2 --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/Controller.php @@ -0,0 +1,23 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\CustomDirPlugin; + +use Piwik\Config; +use Piwik\Container\StaticContainer; + +class Controller extends \Piwik\Plugin\Controller +{ + public function index() + { + return $this->renderTemplate('index', array( + 'answerToLife' => 42, + 'diTest' => StaticContainer::get('customDirPluginTest') + )); + } +} diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/CustomClass.php b/tests/resources/custompluginsdir/CustomDirPlugin/CustomClass.php new file mode 100644 index 0000000000..01d3fe9c49 --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/CustomClass.php @@ -0,0 +1,15 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\CustomDirPlugin; + +class CustomClass +{ + + // to test auto loading +} diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/CustomDirPlugin.php b/tests/resources/custompluginsdir/CustomDirPlugin/CustomDirPlugin.php new file mode 100644 index 0000000000..8ae44b4bd9 --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/CustomDirPlugin.php @@ -0,0 +1,47 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\CustomDirPlugin; + +use Piwik\Common; +use Piwik\Db; + +class CustomDirPlugin extends \Piwik\Plugin +{ + /** + * @see \Piwik\Plugin::registerEvents + */ + public function registerEvents() + { + return array( + 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', + 'AssetManager.getJavaScriptFiles' => 'getJsFiles', + ); + } + + public function getStylesheetFiles(&$stylesheets) + { + $stylesheets[] = "plugins/CustomDirPlugin/stylesheets/test.less"; + } + + public function getJsFiles(&$jsFiles) + { + $jsFiles[] = "tests/resources/custompluginsdir/javascripts/test.js"; + } + + public function postLoad() + { + // we make sure auto loading works for these directories + return new CustomClass(); + } + + public function isTrackerPlugin() + { + return true; + } +} diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/SystemSettings.php b/tests/resources/custompluginsdir/CustomDirPlugin/SystemSettings.php new file mode 100644 index 0000000000..d219451fa9 --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/SystemSettings.php @@ -0,0 +1,34 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\CustomDirPlugin; + +use Piwik\Settings\Setting; +use Piwik\Settings\FieldConfig; +use Piwik\Validators\NotEmpty; + +class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings +{ + /** @var Setting */ + public $custom; + + protected function init() + { + $this->custom = $this->createMetricSetting(); + } + + private function createMetricSetting() + { + return $this->makeSetting('custom', $default = '', FieldConfig::TYPE_STRING, function (FieldConfig $field) { + $field->title = 'Custom setting'; + $field->uiControl = FieldConfig::UI_CONTROL_TEXT; + $field->description = 'Enter some custom text here'; + $field->validators[] = new NotEmpty(); + }); + } +} diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/config/config.php b/tests/resources/custompluginsdir/CustomDirPlugin/config/config.php new file mode 100644 index 0000000000..d546932d91 --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/config/config.php @@ -0,0 +1,4 @@ +<?php +return array( + 'customDirPluginTest' => 'hello world!' +);
\ No newline at end of file diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/images/ok.png b/tests/resources/custompluginsdir/CustomDirPlugin/images/ok.png Binary files differnew file mode 100644 index 0000000000..148319419d --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/images/ok.png diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/lang/en.json b/tests/resources/custompluginsdir/CustomDirPlugin/lang/en.json new file mode 100644 index 0000000000..20927d76ef --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/lang/en.json @@ -0,0 +1,5 @@ +{ + "CustomDirPlugin": { + "CustomName": "Custom Name" + } +}
\ No newline at end of file diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/plugin.json b/tests/resources/custompluginsdir/CustomDirPlugin/plugin.json new file mode 100644 index 0000000000..2d4b3c19a2 --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/plugin.json @@ -0,0 +1,29 @@ +{ + "name": "CustomDirPlugin", + "description": "Custom Plugin located in different directory", + "version": "0.1.0", + "theme": false, + "require": { + "piwik": ">=3.8.1-stable,<4.0.0-b1" + }, + "authors": [ + { + "name": "Matomo", + "email": "", + "homepage": "https://matomo.org" + } + ], + "support": { + "email": "", + "issues": "", + "forum": "", + "irc": "", + "wiki": "", + "source": "", + "docs": "", + "rss": "" + }, + "homepage": "https://matomo.org", + "license": "GPL v3+", + "keywords": [] +}
\ No newline at end of file diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/stylesheets/import.less b/tests/resources/custompluginsdir/CustomDirPlugin/stylesheets/import.less new file mode 100644 index 0000000000..707bfa8e94 --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/stylesheets/import.less @@ -0,0 +1,3 @@ +.customPluginDirImportTest { + color: green; +}
\ No newline at end of file diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/stylesheets/test.less b/tests/resources/custompluginsdir/CustomDirPlugin/stylesheets/test.less new file mode 100644 index 0000000000..d2885913bc --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/stylesheets/test.less @@ -0,0 +1,15 @@ +.fooBarBazCustom { + font-weight: bold; + color: red; +} + +@import "import.less"; + +.customPluginDirBackgroundTestRelative { + background: url('../images/ok.png'); + min-height: 30px; +} +.customPluginDirBackgroundTestPluginRelative { + background: url('plugins/CustomDirPlugin/images/ok.png'); + min-height: 30px; +}
\ No newline at end of file diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/templates/index.twig b/tests/resources/custompluginsdir/CustomDirPlugin/templates/index.twig new file mode 100644 index 0000000000..24bce30dca --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/templates/index.twig @@ -0,0 +1,27 @@ +{% extends 'dashboard.twig' %} + +{% block content %} + <strong>This is our custom plugin!</strong> + <br/> + <span class="fooBarBazCustom"> + The answer to life is {{ answerToLife }} + </span> + <br /> + <h3>Translation test</h3> + <p>This should be translated: {{ 'CustomDirPlugin_CustomName'|translate }}</p> + + <h3>image test</h3> + <p>You should see an image showing a check here: <img src="plugins/CustomDirPlugin/images/ok.png"></p> + + <h3>CSS import test</h3> + <p class="customPluginDirImportTest">this text should appear green!</p> + + <h3>CSS background images test</h3> + <p class="customPluginDirBackgroundTestRelative">This should have a background image relative</p> + + <p class="customPluginDirBackgroundTestPluginRelative">This should have a background image relative to plugins</p> + + <h3>Dependency Injection Test</h3> + <p>You should now see hello world: {{ diTest }}</p> + +{% endblock %}
\ No newline at end of file diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/tests/Fixtures/SimpleFixtureTrackFewVisits.php b/tests/resources/custompluginsdir/CustomDirPlugin/tests/Fixtures/SimpleFixtureTrackFewVisits.php new file mode 100644 index 0000000000..f5d58969d0 --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/tests/Fixtures/SimpleFixtureTrackFewVisits.php @@ -0,0 +1,35 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +namespace Piwik\Plugins\CustomDirPlugin\tests\Fixtures; + +use Piwik\Tests\Framework\Fixture; + +class SimpleFixtureTrackFewVisits extends Fixture +{ + public $dateTime = '2013-01-23 01:23:45'; + public $idSite = 1; + + public function setUp() + { + $this->setUpWebsite(); + } + + public function tearDown() + { + // empty + } + + private function setUpWebsite() + { + if (!self::siteCreated($this->idSite)) { + $idSite = self::createWebsite($this->dateTime, $ecommerce = 1); + $this->assertSame($this->idSite, $idSite); + } + } + +}
\ No newline at end of file diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/tests/Integration/SystemSettingsTest.php b/tests/resources/custompluginsdir/CustomDirPlugin/tests/Integration/SystemSettingsTest.php new file mode 100644 index 0000000000..a9dd935a1e --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/tests/Integration/SystemSettingsTest.php @@ -0,0 +1,49 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\CustomDirPlugin\tests\Integration; + +use Piwik\Plugins\CustomDirPlugin\SystemSettings; +use Piwik\Tests\Framework\TestCase\IntegrationTestCase; + +/** + * @group CustomDirPlugin + * @group SystemSettingsTest + * @group Plugins + */ +class SystemSettingsTest extends IntegrationTestCase +{ + /** + * @var SystemSettings + */ + private $settings; + + public function setUp() + { + parent::setUp(); + + $this->settings = new SystemSettings(); + } + + public function test_get_pluginName() + { + $this->assertSame('CustomDirPlugin', $this->settings->getPluginName()); + } + + public function test_get_default() + { + $this->assertSame('', $this->settings->custom->getValue()); + } + + public function test_set_value() + { + $this->settings->custom->setValue('%'); + $this->assertSame('%', $this->settings->custom->getValue()); + } + +} diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/tests/System/APITest.php b/tests/resources/custompluginsdir/CustomDirPlugin/tests/System/APITest.php new file mode 100644 index 0000000000..11fd73a4f5 --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/tests/System/APITest.php @@ -0,0 +1,44 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\CustomDirPlugin\tests\System; + +use Piwik\API\Request; +use Piwik\Plugins\CustomDirPlugin\tests\Fixtures\SimpleFixtureTrackFewVisits; +use Piwik\Tests\Framework\TestCase\SystemTestCase; + +/** + * @group CustomDirPlugin + * @group APITest + * @group Plugins + */ +class APITest extends SystemTestCase +{ + /** + * @var SimpleFixtureTrackFewVisits + */ + public static $fixture = null; // initialized below class definition + + public function test_api() + { + $this->assertEquals(42, Request::processRequest('CustomDirPlugin.getCustomAnswerToLive')); + } + + public static function getOutputPrefix() + { + return ''; + } + + public static function getPathToTestDirectory() + { + return dirname(__FILE__); + } + +} + +APITest::$fixture = new SimpleFixtureTrackFewVisits();
\ No newline at end of file diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/tests/System/expected/test___API.get_day.xml b/tests/resources/custompluginsdir/CustomDirPlugin/tests/System/expected/test___API.get_day.xml new file mode 100644 index 0000000000..213b91b66a --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/tests/System/expected/test___API.get_day.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <nb_uniq_visitors>2</nb_uniq_visitors> + <nb_visits>2</nb_visits> + <nb_users>0</nb_users> + <nb_actions>4</nb_actions> + <max_actions>2</max_actions> + <bounce_count>0</bounce_count> + <sum_visit_length>1264</sum_visit_length> + <nb_visits_returning>0</nb_visits_returning> + <nb_actions_returning>0</nb_actions_returning> + <nb_uniq_visitors_returning>0</nb_uniq_visitors_returning> + <nb_users_returning>0</nb_users_returning> + <max_actions_returning>0</max_actions_returning> + <bounce_rate_returning>0%</bounce_rate_returning> + <nb_actions_per_visit_returning>0</nb_actions_per_visit_returning> + <avg_time_on_site_returning>0</avg_time_on_site_returning> + <nb_conversions>1</nb_conversions> + <nb_visits_converted>1</nb_visits_converted> + <revenue>2541</revenue> + <conversion_rate>50%</conversion_rate> + <nb_conversions_new_visit>1</nb_conversions_new_visit> + <nb_visits_converted_new_visit>1</nb_visits_converted_new_visit> + <revenue_new_visit>2541</revenue_new_visit> + <conversion_rate_new_visit>50%</conversion_rate_new_visit> + <nb_conversions_returning_visit>0</nb_conversions_returning_visit> + <nb_visits_converted_returning_visit>0</nb_visits_converted_returning_visit> + <revenue_returning_visit>0</revenue_returning_visit> + <conversion_rate_returning_visit>0%</conversion_rate_returning_visit> + <nb_total_overall_bandwidth>0</nb_total_overall_bandwidth> + <nb_total_pageview_bandwidth>0</nb_total_pageview_bandwidth> + <nb_total_download_bandwidth>0</nb_total_download_bandwidth> + <nb_pageviews>3</nb_pageviews> + <nb_uniq_pageviews>3</nb_uniq_pageviews> + <nb_downloads>0</nb_downloads> + <nb_uniq_downloads>0</nb_uniq_downloads> + <nb_outlinks>0</nb_outlinks> + <nb_uniq_outlinks>0</nb_uniq_outlinks> + <nb_searches>1</nb_searches> + <nb_keywords>1</nb_keywords> + <bounce_rate>0%</bounce_rate> + <nb_actions_per_visit>2</nb_actions_per_visit> + <avg_time_on_site>632</avg_time_on_site> +</result>
\ No newline at end of file diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/tests/System/expected/test___Goals.getItemsSku_day.xml b/tests/resources/custompluginsdir/CustomDirPlugin/tests/System/expected/test___Goals.getItemsSku_day.xml new file mode 100644 index 0000000000..ba820ed649 --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/tests/System/expected/test___Goals.getItemsSku_day.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>SKU_ID</label> + <revenue>25641</revenue> + <quantity>33</quantity> + <orders>1</orders> + <avg_price>777</avg_price> + <avg_quantity>33</avg_quantity> + <conversion_rate>0%</conversion_rate> + </row> +</result>
\ No newline at end of file diff --git a/tests/resources/custompluginsdir/CustomDirPlugin/tests/Unit/CustomClassTest.php b/tests/resources/custompluginsdir/CustomDirPlugin/tests/Unit/CustomClassTest.php new file mode 100644 index 0000000000..0018108c66 --- /dev/null +++ b/tests/resources/custompluginsdir/CustomDirPlugin/tests/Unit/CustomClassTest.php @@ -0,0 +1,35 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\CustomDirPlugin\tests\Unit; +use Piwik\Plugins\CustomDirPlugin\CustomClass; + +/** + * @group CustomDirPlugin + * @group CustomClassTest + * @group Plugins + */ +class CustomClassTest extends \PHPUnit_Framework_TestCase +{ + public function setUp() + { + // set up here if needed + } + + public function tearDown() + { + // tear down here if needed + } + + public function test_autoloading_customplugin_works() + { + $customClass = new CustomClass(); + $this->assertTrue($customClass instanceof CustomClass); + } + +} diff --git a/tests/resources/custompluginsdir/javascripts/test.js b/tests/resources/custompluginsdir/javascripts/test.js new file mode 100644 index 0000000000..1b98ac75de --- /dev/null +++ b/tests/resources/custompluginsdir/javascripts/test.js @@ -0,0 +1 @@ +window.fooBarBazBarFoo = 'fooBarBaz';
\ No newline at end of file |