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
diff options
context:
space:
mode:
-rw-r--r--core/Period/Factory.php5
-rw-r--r--tests/PHPUnit/Integration/Period/FactoryTest.php35
2 files changed, 24 insertions, 16 deletions
diff --git a/core/Period/Factory.php b/core/Period/Factory.php
index b316bebefa..7c804df611 100644
--- a/core/Period/Factory.php
+++ b/core/Period/Factory.php
@@ -168,10 +168,9 @@ abstract class Factory
} else {
if (!($date instanceof Date)) {
if (preg_match('/^(now|today|yesterday|yesterdaySameTime|last[ -]?(?:week|month|year))$/i', $date)) {
- $date = Date::factory($date, $timezone);
- } else {
- $date = Date::factory($date);
+ $date = Date::factoryInTimezone($date, $timezone);
}
+ $date = Date::factory($date);
}
$oPeriod = Factory::build($period, $date);
}
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'],
];
}