From 04ac70e0cbf8b7a5ff3d5de66fc0825ace4b0b71 Mon Sep 17 00:00:00 2001 From: Stefan Giehl Date: Thu, 24 Dec 2020 06:21:02 +0100 Subject: Fix report showing data of wrong date (#17008) * Use timezone in period factory only for magic keywords * add test * use better timezone * add non-timezone date Co-authored-by: diosmosis --- tests/PHPUnit/Integration/Period/FactoryTest.php | 29 +++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/PHPUnit/Integration/Period/FactoryTest.php b/tests/PHPUnit/Integration/Period/FactoryTest.php index 9ff978a646..ba1ee78164 100644 --- a/tests/PHPUnit/Integration/Period/FactoryTest.php +++ b/tests/PHPUnit/Integration/Period/FactoryTest.php @@ -9,6 +9,7 @@ namespace Piwik\Tests\Integration\Period; use Piwik\Config; +use Piwik\Date; use Piwik\Period; use Piwik\Period\Day; use Piwik\Period\Month; @@ -62,11 +63,37 @@ class MockPluginManager extends \Piwik\Plugin\Manager class FactoryTest extends IntegrationTestCase { + /** + * @dataProvider getTestDataForMakePeriodFromQueryParams + */ + public function test_makePeriodFromQueryParams_appliesTimezoneProperly($period, $date, $expectedLabel, $expectedRange) + { + Date::$now = strtotime('2020-12-24 03:37:00'); + + $factory = Period\Factory::makePeriodFromQueryParams('America/Chicago', $period, $date); + $this->assertEquals($expectedLabel, $factory->getLabel()); + $this->assertEquals($expectedRange, $factory->getRangeString()); + } + + public function getTestDataForMakePeriodFromQueryParams() + { + return [ + ['day', 'now', 'day', '2020-12-23,2020-12-23'], + ['day', 'today', 'day', '2020-12-23,2020-12-23'], + ['day', 'yesterday', 'day', '2020-12-22,2020-12-22'], + ['day', 'yesterdaySameTime', 'day', '2020-12-22,2020-12-22'], + ['day', 'last-week', 'day', '2020-12-16,2020-12-16'], + ['day', 'last-month', 'day', '2020-11-23,2020-11-23'], + ['day', 'last-year', 'day', '2019-12-23,2019-12-23'], + ['day', '2020-12-23', 'day', '2020-12-23,2020-12-23'], + ]; + } + /** * @dataProvider getBuildTestData */ public function test_build_CreatesCorrectPeriodInstances($strPeriod, $date, $timezone, $expectedPeriodClass, - $expectedRangeString) + $expectedRangeString) { $period = Period\Factory::build($strPeriod, $date, $timezone); $this->assertInstanceOf($expectedPeriodClass, $period); -- cgit v1.2.3