From e4f3ea2279fd82802cb7e14f3299950d8ebd0a28 Mon Sep 17 00:00:00 2001 From: Thomas Steur <thomas.steur@gmail.com> Date: Tue, 6 Jan 2015 01:30:02 +0000 Subject: [PATCH] fixing some more bugs and tests, not sure yet how to fix the missing metrics properly --- core/API/DataTablePostProcessor.php | 6 +- plugins/Ecommerce/Reports/Base.php | 12 ++++ plugins/Ecommerce/Widgets.php | 35 ++++++++++++ plugins/Ecommerce/tests/UI/Ecommerce_spec.js | 56 +++++++++++++++++++ plugins/Goals/Widgets.php | 8 --- .../Dimension/ConversionDimensionTest.php | 2 +- 6 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 plugins/Ecommerce/Widgets.php create mode 100644 plugins/Ecommerce/tests/UI/Ecommerce_spec.js diff --git a/core/API/DataTablePostProcessor.php b/core/API/DataTablePostProcessor.php index 352771464e..ba99229db3 100644 --- a/core/API/DataTablePostProcessor.php +++ b/core/API/DataTablePostProcessor.php @@ -68,7 +68,11 @@ class DataTablePostProcessor $this->apiMethod = $apiMethod; $this->request = $request; - $this->report = Report::factory($apiModule, $apiMethod); + foreach (Report::getAllReports() as $report) { + if ($apiMethod === $report->getAction() && $apiModule === $report->getModule()) { + $this->report = $report; + } + } $this->apiInconsistencies = new Inconsistencies(); $this->formatter = new Formatter(); } diff --git a/plugins/Ecommerce/Reports/Base.php b/plugins/Ecommerce/Reports/Base.php index e8c23a4bb2..c2d7f6eada 100644 --- a/plugins/Ecommerce/Reports/Base.php +++ b/plugins/Ecommerce/Reports/Base.php @@ -14,6 +14,7 @@ use Piwik\Piwik; use Piwik\Plugin\Report; use Piwik\Site; use Piwik\ViewDataTable\Factory as ViewDataTableFactory; +use Piwik\WidgetsList; abstract class Base extends Report { @@ -99,4 +100,15 @@ abstract class Base extends Report return $rendered; } + public function configureWidget(WidgetsList $widget) + { + if ($this->widgetTitle) { + $params = array(); + if (!empty($this->widgetParams) && is_array($this->widgetParams)) { + $params = $this->widgetParams; + } + $widget->add($this->category, $this->widgetTitle, 'Ecommerce', $this->action, $params); + } + } + } diff --git a/plugins/Ecommerce/Widgets.php b/plugins/Ecommerce/Widgets.php new file mode 100644 index 0000000000..0a2541473d --- /dev/null +++ b/plugins/Ecommerce/Widgets.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\Ecommerce; + +use Piwik\Common; +use Piwik\Site; +use Piwik\Piwik; + +class Widgets extends \Piwik\Plugin\Widgets +{ + protected $category = 'Goals_Ecommerce'; + + protected function init() + { + $idSite = $this->getIdSite(); + + $site = new Site($idSite); + if ($site->isEcommerceEnabled()) { + $this->addWidget('Goals_EcommerceOverview', 'widgetGoalReport', array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER)); + $this->addWidget('Goals_EcommerceLog', 'getEcommerceLog'); + } + } + + private function getIdSite() + { + return Common::getRequestVar('idSite', null, 'int'); + } + +} diff --git a/plugins/Ecommerce/tests/UI/Ecommerce_spec.js b/plugins/Ecommerce/tests/UI/Ecommerce_spec.js new file mode 100644 index 0000000000..07ff64486b --- /dev/null +++ b/plugins/Ecommerce/tests/UI/Ecommerce_spec.js @@ -0,0 +1,56 @@ +/*! + * Piwik - free/libre analytics platform + * + * GoalsTable screenshot tests. + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +describe("Ecommerce", function () { + this.timeout(0); + + var url = "?module=Widgetize&action=iframe&moduleToWidgetize=Referrers&idSite=1&period=year&date=2012-08-09&" + + "actionToWidgetize=getKeywords&viewDataTable=table&filter_limit=5&isFooterExpandedInDashboard=1"; + + it("should load when the goals icon is clicked", function (done) { + expect.screenshot('initial').to.be.capture(function (page) { + page.load(url); + page.click('.tableIconsGroup a[data-footer-icon-id=tableGoals]'); + }, done); + }); + + it("should show columns for all goals when idGoal is 0", function (done) { + expect.screenshot('goals_table_full').to.be.capture(function (page) { + var url = page.getCurrentUrl().replace(/viewDataTable=[^&]*/, "viewDataTable=tableGoals") + "&idGoal=0"; + page.load(url); + }, done); + }); + + it("should show columns for a single goal when idGoal is 1", function (done) { + expect.screenshot('goals_table_single').to.be.capture(function (page) { + page.load(page.getCurrentUrl().replace(/idGoal=[^&]*/, "idGoal=1")); + }, done); + }); + + it("should show an ecommerce view when idGoal is ecommerceOrder", function (done) { + expect.screenshot('goals_table_ecommerce').to.be.capture(function (page) { + page.load(page.getCurrentUrl().replace(/idGoal=[^&]*/, "idGoal=ecommerceOrder")); + }, done); + }); + + it("should show a special view when idGoal is ecommerceOrder and viewDataTable is ecommerceOrder", function (done) { + expect.screenshot('goals_table_ecommerce_view').to.be.capture(function (page) { + var url = page.getCurrentUrl().replace(/moduleToWidgetize=[^&]*/, "moduleToWidgetize=Ecommerce") + .replace(/actionToWidgetize=[^&]*/, "actionToWidgetize=getItemsSku") + .replace(/viewDataTable=[^&]*/, "viewDataTable=ecommerceOrder"); + page.load(url); + }, done); + }); + + it("should show abandoned carts data when the abandoned carts link is clicked", function (done) { + expect.screenshot('goals_table_abandoned_carts').to.be.capture(function (page) { + page.click('.tableIconsGroup a[data-footer-icon-id=ecommerceAbandonedCart]'); + }, done); + }); +}); \ No newline at end of file diff --git a/plugins/Goals/Widgets.php b/plugins/Goals/Widgets.php index 30c113e9a2..94d91bda5c 100644 --- a/plugins/Goals/Widgets.php +++ b/plugins/Goals/Widgets.php @@ -9,8 +9,6 @@ namespace Piwik\Plugins\Goals; use Piwik\Common; -use Piwik\Site; -use Piwik\Piwik; class Widgets extends \Piwik\Plugin\Widgets { @@ -31,12 +29,6 @@ class Widgets extends \Piwik\Plugin\Widgets $this->addWidget($name, 'widgetGoalReport', $params); } } - - $site = new Site($idSite); - if ($site->isEcommerceEnabled()) { - $this->addWidgetWithCustomCategory('Goals_Ecommerce', 'Goals_EcommerceOverview', 'widgetGoalReport', array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER)); - $this->addWidgetWithCustomCategory('Goals_Ecommerce', 'Goals_EcommerceLog', 'getEcommerceLog'); - } } private function getIdSite() diff --git a/tests/PHPUnit/Unit/Plugin/Dimension/ConversionDimensionTest.php b/tests/PHPUnit/Unit/Plugin/Dimension/ConversionDimensionTest.php index 04fdc37b8e..3b8b2d9049 100644 --- a/tests/PHPUnit/Unit/Plugin/Dimension/ConversionDimensionTest.php +++ b/tests/PHPUnit/Unit/Plugin/Dimension/ConversionDimensionTest.php @@ -155,7 +155,7 @@ class Plugin_ConversionDimensionTest extends \PHPUnit_Framework_TestCase foreach ($dimensions as $dimension) { $this->assertInstanceOf('\Piwik\Plugin\Dimension\ConversionDimension', $dimension); - $this->assertRegExp('/Piwik.Plugins.(ExampleTracker|Goals).Columns/', get_class($dimension)); + $this->assertRegExp('/Piwik.Plugins.(ExampleTracker|Ecommerce|Goals).Columns/', get_class($dimension)); } } } \ No newline at end of file -- GitLab