From 9f591556e4be8f3deb0f5a650aeb04e5af525425 Mon Sep 17 00:00:00 2001 From: Thomas Steur <thomas.steur@gmail.com> Date: Mon, 29 Aug 2016 23:57:25 +0000 Subject: [PATCH] fix tests --- core/API/ApiRenderer.php | 7 +++++++ core/BaseFactory.php | 2 +- core/DataTable/Renderer/Csv.php | 1 - core/ReportRenderer.php | 12 ++++++++++++ core/ReportRenderer/Csv.php | 1 + plugins/API/Renderer/Console.php | 2 -- plugins/API/Renderer/Csv.php | 2 -- plugins/API/Renderer/Html.php | 2 -- plugins/API/Renderer/Json.php | 2 +- plugins/API/Renderer/Php.php | 4 +--- plugins/API/Renderer/Rss.php | 2 -- plugins/API/Renderer/Tsv.php | 2 -- plugins/API/Renderer/Xml.php | 2 -- plugins/SEO/Widgets/GetRank.php | 1 - plugins/ScheduledReports/API.php | 1 + 15 files changed, 24 insertions(+), 19 deletions(-) diff --git a/core/API/ApiRenderer.php b/core/API/ApiRenderer.php index fc1c11d736..a913041514 100644 --- a/core/API/ApiRenderer.php +++ b/core/API/ApiRenderer.php @@ -91,8 +91,15 @@ abstract class ApiRenderer $format = 'json'; } + $idSite = Common::getRequestVar('idSite', 0, 'int', $this->request); + + if (empty($idSite)) { + $idSite = 'all'; + } + $renderer = Renderer::factory($format); $renderer->setTable($dataTable); + $renderer->setIdSite($idSite); $renderer->setRenderSubTables(Common::getRequestVar('expanded', false, 'int', $this->request)); $renderer->setHideIdSubDatableFromResponse(Common::getRequestVar('hideIdSubDatable', false, 'int', $this->request)); diff --git a/core/BaseFactory.php b/core/BaseFactory.php index 32b4090bc2..d240da900f 100644 --- a/core/BaseFactory.php +++ b/core/BaseFactory.php @@ -26,7 +26,7 @@ abstract class BaseFactory * Creates a new instance of a class using a string ID. * * @param string $classId The ID of the class. - * @return BaseFactory + * @return \Piwik\DataTable\Renderer * @throws Exception if $classId is invalid. */ public static function factory($classId) diff --git a/core/DataTable/Renderer/Csv.php b/core/DataTable/Renderer/Csv.php index d9b2ea4fd4..4d55979347 100644 --- a/core/DataTable/Renderer/Csv.php +++ b/core/DataTable/Renderer/Csv.php @@ -12,7 +12,6 @@ use Piwik\Common; use Piwik\DataTable\Renderer; use Piwik\DataTable\Simple; use Piwik\DataTable; -use Piwik\Date; use Piwik\Period; use Piwik\Period\Range; use Piwik\Piwik; diff --git a/core/ReportRenderer.php b/core/ReportRenderer.php index 3fa20aff43..1d290533c1 100644 --- a/core/ReportRenderer.php +++ b/core/ReportRenderer.php @@ -35,12 +35,24 @@ abstract class ReportRenderer extends BaseFactory const PDF_FORMAT = 'pdf'; const CSV_FORMAT = 'csv'; + protected $idSite = 'all'; + private static $availableReportRenderers = array( self::PDF_FORMAT, self::HTML_FORMAT, self::CSV_FORMAT, ); + /** + * Sets the site id + * + * @param int $idSite + */ + public function setIdSite($idSite) + { + $this->idSite = $idSite; + } + protected static function getClassNameFromClassId($rendererType) { return 'Piwik\ReportRenderer\\' . self::normalizeRendererType($rendererType); diff --git a/core/ReportRenderer/Csv.php b/core/ReportRenderer/Csv.php index b76096db44..ef5678b1f7 100644 --- a/core/ReportRenderer/Csv.php +++ b/core/ReportRenderer/Csv.php @@ -141,6 +141,7 @@ class Csv extends ReportRenderer protected function getRenderer(DataTableInterface $table, $uniqueId) { $csvRenderer = new CsvDataTableRenderer(); + $csvRenderer->setIdSite($this->idSite); $csvRenderer->setTable($table); $csvRenderer->setConvertToUnicode(false); $csvRenderer->setApiMethod( diff --git a/plugins/API/Renderer/Console.php b/plugins/API/Renderer/Console.php index 98e3d01d1f..90dc03928e 100644 --- a/plugins/API/Renderer/Console.php +++ b/plugins/API/Renderer/Console.php @@ -10,8 +10,6 @@ namespace Piwik\Plugins\API\Renderer; use Piwik\API\ApiRenderer; use Piwik\Common; -use Piwik\DataTable\Renderer; -use Piwik\DataTable; class Console extends ApiRenderer { diff --git a/plugins/API/Renderer/Csv.php b/plugins/API/Renderer/Csv.php index 77caa50bce..1a01134b56 100644 --- a/plugins/API/Renderer/Csv.php +++ b/plugins/API/Renderer/Csv.php @@ -10,8 +10,6 @@ namespace Piwik\Plugins\API\Renderer; use Piwik\API\ApiRenderer; use Piwik\Common; -use Piwik\DataTable\Renderer; -use Piwik\DataTable; use Piwik\ProxyHttp; class Csv extends ApiRenderer diff --git a/plugins/API/Renderer/Html.php b/plugins/API/Renderer/Html.php index 48acbb355f..1aeab87f51 100644 --- a/plugins/API/Renderer/Html.php +++ b/plugins/API/Renderer/Html.php @@ -10,8 +10,6 @@ namespace Piwik\Plugins\API\Renderer; use Piwik\API\ApiRenderer; use Piwik\Common; -use Piwik\DataTable\Renderer; -use Piwik\DataTable; class Html extends ApiRenderer { diff --git a/plugins/API/Renderer/Json.php b/plugins/API/Renderer/Json.php index 5037b30fbe..8adfdaebe1 100644 --- a/plugins/API/Renderer/Json.php +++ b/plugins/API/Renderer/Json.php @@ -11,7 +11,6 @@ namespace Piwik\Plugins\API\Renderer; use Piwik\API\ApiRenderer; use Piwik\Common; use Piwik\DataTable\Renderer; -use Piwik\DataTable; use Piwik\Piwik; use Piwik\ProxyHttp; @@ -34,6 +33,7 @@ class Json extends ApiRenderer /** * @param $message * @param Exception|\Throwable $exception + * @param \Exception|\Throwable $exception * @return string */ public function renderException($message, $exception) diff --git a/plugins/API/Renderer/Php.php b/plugins/API/Renderer/Php.php index 5823137569..c237074541 100644 --- a/plugins/API/Renderer/Php.php +++ b/plugins/API/Renderer/Php.php @@ -10,8 +10,6 @@ namespace Piwik\Plugins\API\Renderer; use Piwik\API\ApiRenderer; use Piwik\Common; -use Piwik\DataTable\Renderer; -use Piwik\DataTable; use Piwik\Piwik; class Php extends ApiRenderer @@ -25,7 +23,7 @@ class Php extends ApiRenderer /** * @param $message - * @param Exception|\Throwable $exception + * @param \Exception|\Throwable $exception * @return string */ public function renderException($message, $exception) diff --git a/plugins/API/Renderer/Rss.php b/plugins/API/Renderer/Rss.php index 5bbcac78aa..f5ac883b40 100644 --- a/plugins/API/Renderer/Rss.php +++ b/plugins/API/Renderer/Rss.php @@ -10,8 +10,6 @@ namespace Piwik\Plugins\API\Renderer; use Piwik\API\ApiRenderer; use Piwik\Common; -use Piwik\DataTable\Renderer; -use Piwik\DataTable; class Rss extends ApiRenderer { diff --git a/plugins/API/Renderer/Tsv.php b/plugins/API/Renderer/Tsv.php index c5505159e0..85304d29dd 100644 --- a/plugins/API/Renderer/Tsv.php +++ b/plugins/API/Renderer/Tsv.php @@ -9,8 +9,6 @@ namespace Piwik\Plugins\API\Renderer; use Piwik\Common; -use Piwik\DataTable\Renderer; -use Piwik\DataTable; class Tsv extends Csv { diff --git a/plugins/API/Renderer/Xml.php b/plugins/API/Renderer/Xml.php index 4a1f0247d7..dc1a527057 100644 --- a/plugins/API/Renderer/Xml.php +++ b/plugins/API/Renderer/Xml.php @@ -10,8 +10,6 @@ namespace Piwik\Plugins\API\Renderer; use Piwik\API\ApiRenderer; use Piwik\Common; -use Piwik\DataTable\Renderer; -use Piwik\DataTable; class Xml extends ApiRenderer { diff --git a/plugins/SEO/Widgets/GetRank.php b/plugins/SEO/Widgets/GetRank.php index be22d61eec..b22a6683c9 100644 --- a/plugins/SEO/Widgets/GetRank.php +++ b/plugins/SEO/Widgets/GetRank.php @@ -14,7 +14,6 @@ use Piwik\Widget\WidgetConfig; use Piwik\Site; use Piwik\Url; use Piwik\UrlHelper; -use Piwik\View; use Piwik\Plugins\SEO\API; class GetRank extends \Piwik\Widget\Widget diff --git a/plugins/ScheduledReports/API.php b/plugins/ScheduledReports/API.php index 3391b581c8..be34d120fc 100644 --- a/plugins/ScheduledReports/API.php +++ b/plugins/ScheduledReports/API.php @@ -469,6 +469,7 @@ class API extends \Piwik\Plugin\API } // init report renderer + $reportRenderer->setIdSite($idSite); $reportRenderer->setLocale($language); // render report -- GitLab