Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorStefan Giehl <stefan@matomo.org>2021-01-28 02:09:46 +0300
committerGitHub <noreply@github.com>2021-01-28 02:09:46 +0300
commit43c920cb44eb606bc8c16d2344ecec762a20ca21 (patch)
treedce12c50e4f9d0b9c4774d56a0110a54ed35703f /tests
parentca9a0a523e75d3d10acfc0a0114d3d71287cd9ef (diff)
Fix timezone issue when using magic date keywords (#17144)
* Fix timezone issue when using magic date keywords * improve readability * use Date::factoryInTimezone
Diffstat (limited to 'tests')
-rw-r--r--tests/PHPUnit/Integration/Period/FactoryTest.php35
1 files changed, 22 insertions, 13 deletions
diff --git a/tests/PHPUnit/Integration/Period/FactoryTest.php b/tests/PHPUnit/Integration/Period/FactoryTest.php
index ba1ee78164..a825c37240 100644
--- a/tests/PHPUnit/Integration/Period/FactoryTest.php
+++ b/tests/PHPUnit/Integration/Period/FactoryTest.php
@@ -16,7 +16,7 @@ use Piwik\Period\Month;
use Piwik\Period\Range;
use Piwik\Period\Week;
use Piwik\Period\Year;
-use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+use Piwik\Tests\Framework\TestCase\UnitTestCase;
class TestPeriod
{
@@ -61,16 +61,19 @@ class MockPluginManager extends \Piwik\Plugin\Manager
}
}
-class FactoryTest extends IntegrationTestCase
+/**
+ * @group PeriodFactoryTest
+ */
+class FactoryTest extends UnitTestCase
{
/**
* @dataProvider getTestDataForMakePeriodFromQueryParams
*/
- public function test_makePeriodFromQueryParams_appliesTimezoneProperly($period, $date, $expectedLabel, $expectedRange)
+ public function test_makePeriodFromQueryParams_appliesTimezoneProperly($now, $timezone, $period, $date, $expectedLabel, $expectedRange)
{
- Date::$now = strtotime('2020-12-24 03:37:00');
+ Date::$now = strtotime($now);
- $factory = Period\Factory::makePeriodFromQueryParams('America/Chicago', $period, $date);
+ $factory = Period\Factory::makePeriodFromQueryParams($timezone, $period, $date);
$this->assertEquals($expectedLabel, $factory->getLabel());
$this->assertEquals($expectedRange, $factory->getRangeString());
}
@@ -78,14 +81,20 @@ class FactoryTest extends IntegrationTestCase
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'],
+ ['2020-12-24 03:37:00', 'America/Chicago', 'day', 'now', 'day', '2020-12-23,2020-12-23'],
+ ['2020-12-24 03:37:00', 'America/Chicago', 'day', 'today', 'day', '2020-12-23,2020-12-23'],
+ ['2020-12-24 16:37:00', 'America/Chicago', 'day', 'today', 'day', '2020-12-24,2020-12-24'],
+ ['2020-12-24 22:37:00', 'UTC+5', 'day', 'today', 'day', '2020-12-25,2020-12-25'],
+ ['2020-12-24 03:37:00', 'America/Chicago', 'day', 'yesterday', 'day', '2020-12-22,2020-12-22'],
+ ['2020-12-24 03:37:00', 'UTC+5', 'day', 'yesterday', 'day', '2020-12-23,2020-12-23'],
+ ['2020-12-24 16:37:00', 'UTC+12', 'day', 'yesterday', 'day', '2020-12-24,2020-12-24'],
+ ['2020-12-24 03:37:00', 'America/Chicago', 'day', 'yesterdaySameTime', 'day', '2020-12-22,2020-12-22'],
+ ['2020-12-24 03:37:00', 'America/Chicago', 'day', 'last-week', 'day', '2020-12-16,2020-12-16'],
+ ['2020-12-24 03:37:00', 'America/Chicago', 'day', 'last-month', 'day', '2020-11-23,2020-11-23'],
+ ['2020-12-24 03:37:00', 'UTC', 'week', 'last-month', 'week', '2020-11-23,2020-11-29'],
+ ['2020-12-23 03:37:00', 'America/Chicago', 'week', 'last-month', 'week', '2020-11-16,2020-11-22'],
+ ['2020-12-24 03:37:00', 'America/Chicago', 'day', 'last-year', 'day', '2019-12-23,2019-12-23'],
+ ['2020-12-24 03:37:00', 'America/Chicago', 'day', '2020-12-23', 'day', '2020-12-23,2020-12-23'],
];
}