diff options
author | Lukas Winkler <git@lw1.at> | 2021-03-30 03:00:13 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-30 03:00:13 +0300 |
commit | 3ab0d4ee6af2eccfd3e1e7e0d192a0032f42edcb (patch) | |
tree | 06a7dc42afef26c289543220111df02d706cf394 /plugins/ScheduledReports | |
parent | 2edd9dbf8aba5635063b24517c1dcc9f3fd53db7 (diff) |
fix ScheduledReports.sendReport API (#17402)
* fix ScheduledReports.sendReport API
* add test for change
* slight test improvement
Co-authored-by: dizzy <diosmosis@users.noreply.github.com>
Diffstat (limited to 'plugins/ScheduledReports')
-rw-r--r-- | plugins/ScheduledReports/API.php | 2 | ||||
-rw-r--r-- | plugins/ScheduledReports/tests/Integration/ApiTest.php | 63 |
2 files changed, 64 insertions, 1 deletions
diff --git a/plugins/ScheduledReports/API.php b/plugins/ScheduledReports/API.php index c56854514c..e0934f45b8 100644 --- a/plugins/ScheduledReports/API.php +++ b/plugins/ScheduledReports/API.php @@ -663,7 +663,7 @@ class API extends \Piwik\Plugin\API $reportSubject, $reportTitle, $additionalFiles, - \Piwik\Period\Factory::build($report['period'], $date), + \Piwik\Period\Factory::build($report['period_param'], $date), $force ) ); diff --git a/plugins/ScheduledReports/tests/Integration/ApiTest.php b/plugins/ScheduledReports/tests/Integration/ApiTest.php index 0eab86b3ad..ccfe5976b8 100644 --- a/plugins/ScheduledReports/tests/Integration/ApiTest.php +++ b/plugins/ScheduledReports/tests/Integration/ApiTest.php @@ -9,10 +9,12 @@ namespace Piwik\Plugins\ScheduledReports\tests; use Piwik\API\Proxy; +use Piwik\API\Request; use Piwik\Container\StaticContainer; use Piwik\DataTable; use Piwik\Date; use Piwik\Http\BadRequestException; +use Piwik\Piwik; use Piwik\Plugins\MobileMessaging\API as APIMobileMessaging; use Piwik\Plugins\MobileMessaging\MobileMessaging; use Piwik\Plugins\ScheduledReports\API as APIScheduledReports; @@ -59,6 +61,67 @@ class ApiTest extends IntegrationTestCase APIScheduledReports::$cache = array(); } + public function test_sendReport_overridesParametersCorrectly() + { + $reportIds = [ + 'UserCountry_getCity', + 'DevicesDetection_getType', + ]; + + Piwik::addAction(APIScheduledReports::GET_REPORT_TYPES_EVENT, function (&$reportTypes) { + $reportTypes[] = 'dummyreporttype'; + }); + + Piwik::addAction(APIScheduledReports::GET_REPORT_FORMATS_EVENT, function (&$reportFormats) { + $reportFormats[] = 'dummyreportformat'; + }); + + Piwik::addAction(APIScheduledReports::GET_REPORT_METADATA_EVENT, function (&$availableReportData, $reportType, $idSite) { + if ($reportType == 'dummyreporttype') { + $availableReportData = \Piwik\Plugins\API\API::getInstance()->getReportMetadata($idSite); + } + }); + + Piwik::addAction(APIScheduledReports::GET_RENDERER_INSTANCE_EVENT, function (&$reportRenderer, $reportType, $outputType, $report) { + if ($reportType == 'dummyrepor') { // apparently this gets cut off + $reportRenderer = new class() extends ReportRenderer { + public function setLocale($locale) {} + public function sendToDisk($filename) { + $path = PIWIK_INCLUDE_PATH . '/tmp/' . $filename; + file_put_contents($path, 'dummyreportdata'); + return $path; + } + public function sendToBrowserDownload($filename) {} + public function sendToBrowserInline($filename) {} + public function getRenderedReport() {} + public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment) {} + public function renderReport($processedReport) {} + public function getAttachments($report, $processedReports, $prettyDate) {} + }; + } + }); + + $idReport = APIScheduledReports::getInstance()->addReport( + $this->idSite, 'send report', 'never', 6, 'dummyreporttype', 'dummyreportformat', + $reportIds, [ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_TABLES_ONLY]); + + $eventCalledWith = []; + Piwik::addAction(APIScheduledReports::SEND_REPORT_EVENT, function (&$reportType, $report, $contents, $filename, $prettyDate, $reportSubject, + $reportTitle, $additionalFiles, $period, $force) { + $eventCalledWith[] = [$reportType, $report, $contents, $filename, $prettyDate, $reportSubject, $reportTitle, $additionalFiles, + $period->getLabel() . ' ' . $period->getRangeString(), $force]; + }); + + Request::processRequest('ScheduledReports.sendReport', [ + 'idReport' => $idReport, + 'period' => 'year', + 'date' => '2018-02-04', + ]); + + $expectedEventArgs = []; + $this->assertEquals($expectedEventArgs, $eventCalledWith); + } + /** * @group Plugins */ |