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>2020-12-10 05:18:07 +0300
committerGitHub <noreply@github.com>2020-12-10 05:18:07 +0300
commit7cde69f763f2cbf2b9a27c8a7dcf7bcaa950c3bd (patch)
treeda719a778d96e167ee4ba55c89a529c1c3bb0dce /tests
parent06918eea4d2ca01298200348b40f57817433b931 (diff)
Allow using last (week|month|year) as date param (#16830)
* Allow using last (week|month|year) as date param * Adds some unit tests * improve tests * Make it possible to use last (week|month|year) for api requests * improve test
Diffstat (limited to 'tests')
-rw-r--r--tests/PHPUnit/Fixtures/VisitsInCurrentYear.php70
-rw-r--r--tests/PHPUnit/Framework/TestRequest/Collection.php3
-rw-r--r--tests/PHPUnit/System/SpecialDateParamsTest.php78
-rw-r--r--tests/PHPUnit/System/expected/test_specialDateParams_lastmonth__Actions.getPageTitles_day.xml27
-rw-r--r--tests/PHPUnit/System/expected/test_specialDateParams_lastmonth__VisitsSummary.getVisits_day.xml2
-rw-r--r--tests/PHPUnit/System/expected/test_specialDateParams_lastweek__Actions.getPageTitles_day.xml27
-rw-r--r--tests/PHPUnit/System/expected/test_specialDateParams_lastweek__VisitsSummary.getVisits_day.xml2
-rw-r--r--tests/PHPUnit/System/expected/test_specialDateParams_lastyear__Actions.getPageTitles_day.xml27
-rw-r--r--tests/PHPUnit/System/expected/test_specialDateParams_lastyear__VisitsSummary.getVisits_day.xml2
-rw-r--r--tests/PHPUnit/System/expected/test_specialDateParams_range__Actions.getPageTitles_range.xml75
-rw-r--r--tests/PHPUnit/System/expected/test_specialDateParams_range__VisitsSummary.getVisits_range.xml2
-rw-r--r--tests/PHPUnit/Unit/DateTest.php119
12 files changed, 388 insertions, 46 deletions
diff --git a/tests/PHPUnit/Fixtures/VisitsInCurrentYear.php b/tests/PHPUnit/Fixtures/VisitsInCurrentYear.php
new file mode 100644
index 0000000000..b77c361dbb
--- /dev/null
+++ b/tests/PHPUnit/Fixtures/VisitsInCurrentYear.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Matomo - free/libre analytics platform
+ *
+ * @link https://matomo.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+namespace Piwik\Tests\Fixtures;
+
+use Piwik\Common;
+use Piwik\Date;
+use Piwik\Db;
+use Piwik\Plugins\Goals\API as APIGoals;
+use Piwik\Plugins\SitesManager\API as APISitesManager;
+use Piwik\Tests\Framework\Fixture;
+use Piwik\Tracker\Cache;
+
+/**
+ * This fixture adds one website and tracks two visits by one visitor.
+ */
+class VisitsInCurrentYear extends Fixture
+{
+ public $idSite = 1;
+
+ public function setUp(): void
+ {
+ $this->setUpWebsite();
+ $this->trackVisits();
+ }
+
+ public function tearDown(): void
+ {
+ // empty
+ }
+
+ private function setUpWebsite()
+ {
+ if (!self::siteCreated($idSite = 1)) {
+ self::createWebsite('2018-01-01 15:00:00');
+ }
+ }
+
+ private function trackVisits()
+ {
+ $idSite = $this->idSite;
+
+ // Record 1st visit today
+ $t = self::getTracker($idSite, date('Y-m-d H:i:s'), $defaultInit = true);
+ $t->setUrl('http://example.org/index.htm?excluded_Parameter=SHOULD_NOT_DISPLAY&parameter=Should display');
+ $t->setUrlReferrer('http://referrer.com/page.htm?param=valuewith some spaces');
+ self::checkResponse($t->doTrackPageView('incredible title!'));
+
+ // Record 2nd visit 7 days ago
+ $t = self::getTracker($idSite, date('Y-m-d H:i:s', strtotime('-7days')), $defaultInit = true);
+ $t->setUrl('http://example.org/index.htm?excluded_Parameter=SHOULD_NOT_DISPLAY&parameter=Should display');
+ $t->setUrlReferrer('http://referrer.com/page.htm');
+ self::checkResponse($t->doTrackPageView('incredible!'));
+
+ // Record 3rd visit 1 month ago
+ $t = self::getTracker($idSite, date('Y-m-d H:i:s', strtotime('-1month')), $defaultInit = true);
+ $t->setUrl('http://example.org/store/purchase.htm');
+ $t->setUrlReferrer('http://search.yahoo.com/search?p=purchase');
+ self::checkResponse($t->doTrackPageView('Checkout/Purchasing...'));
+
+ // Record 4th visit 1 year ago
+ $t = self::getTracker($idSite, date('Y-m-d H:i:s', strtotime('-1year')), $defaultInit = true);
+ $t->setUrl('http://example.org/shop/product.htm');
+ self::checkResponse($t->doTrackPageView('Visit product'));
+ }
+} \ No newline at end of file
diff --git a/tests/PHPUnit/Framework/TestRequest/Collection.php b/tests/PHPUnit/Framework/TestRequest/Collection.php
index 0510b7df4b..1a7310f78b 100644
--- a/tests/PHPUnit/Framework/TestRequest/Collection.php
+++ b/tests/PHPUnit/Framework/TestRequest/Collection.php
@@ -11,6 +11,7 @@ namespace Piwik\Tests\Framework\TestRequest;
use Piwik\API\DocumentationGenerator;
use Piwik\API\Proxy;
use Piwik\API\Request;
+use Piwik\Date;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
use Piwik\Url;
use Piwik\UrlHelper;
@@ -109,7 +110,7 @@ class Collection
{
$parametersToSet = array(
'idSite' => $this->testConfig->idSite,
- 'date' => ($this->testConfig->periods == array('range') || strpos($this->testConfig->date, ',') !== false) ?
+ 'date' => ($this->testConfig->periods == array('range') || strpos($this->testConfig->date, ',') !== false || preg_match('/last[ -]?(week|month|year)/i', $this->testConfig->date)) ?
$this->testConfig->date : date('Y-m-d', strtotime($this->testConfig->date)),
'expanded' => '1',
'piwikUrl' => 'http://example.org/piwik/',
diff --git a/tests/PHPUnit/System/SpecialDateParamsTest.php b/tests/PHPUnit/System/SpecialDateParamsTest.php
new file mode 100644
index 0000000000..f3508c2223
--- /dev/null
+++ b/tests/PHPUnit/System/SpecialDateParamsTest.php
@@ -0,0 +1,78 @@
+<?php
+/**
+ * Matomo - free/libre analytics platform
+ *
+ * @link https://matomo.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+namespace Piwik\Tests\System;
+
+use Piwik\Tests\Fixtures\VisitsInCurrentYear;
+use Piwik\Tests\Framework\TestCase\SystemTestCase;
+
+/**
+ * @group SpecialDateParams
+ * @group Core
+ */
+class SpecialDateParamsTest extends SystemTestCase
+{
+ public static $fixture = null; // initialized below class definition
+
+ /**
+ * @dataProvider getApiForTesting
+ */
+ public function testApi($api, $params)
+ {
+ $this->runApiTests($api, $params);
+ }
+
+ public function getApiForTesting()
+ {
+ return [
+ [
+ ['VisitsSummary.getVisits', 'Actions.getPageTitles'],
+ [
+ 'idSite' => self::$fixture->idSite,
+ 'date' => 'last week',
+ 'periods' => ['day'],
+ 'testSuffix' => '_lastweek',
+ ],
+ ],
+ [
+ ['VisitsSummary.getVisits', 'Actions.getPageTitles'],
+ [
+ 'idSite' => self::$fixture->idSite,
+ 'date' => 'last month',
+ 'periods' => ['day'],
+ 'testSuffix' => '_lastmonth',
+ ],
+ ],
+ [
+ ['VisitsSummary.getVisits', 'Actions.getPageTitles'],
+ [
+ 'idSite' => self::$fixture->idSite,
+ 'date' => 'lastyear',
+ 'periods' => ['day'],
+ 'testSuffix' => '_lastyear',
+ ],
+ ],
+ [
+ ['VisitsSummary.getVisits', 'Actions.getPageTitles'],
+ [
+ 'idSite' => self::$fixture->idSite,
+ 'date' => 'last-year,lastWeek',
+ 'periods' => ['range'],
+ 'testSuffix' => '_range',
+ ],
+ ],
+ ];
+ }
+
+ public static function getOutputPrefix()
+ {
+ return 'specialDateParams';
+ }
+}
+
+SpecialDateParamsTest::$fixture = new VisitsInCurrentYear(); \ No newline at end of file
diff --git a/tests/PHPUnit/System/expected/test_specialDateParams_lastmonth__Actions.getPageTitles_day.xml b/tests/PHPUnit/System/expected/test_specialDateParams_lastmonth__Actions.getPageTitles_day.xml
new file mode 100644
index 0000000000..f5bc869511
--- /dev/null
+++ b/tests/PHPUnit/System/expected/test_specialDateParams_lastmonth__Actions.getPageTitles_day.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+ <row>
+ <label> Checkout/Purchasing...</label>
+ <nb_visits>1</nb_visits>
+ <nb_uniq_visitors>1</nb_uniq_visitors>
+ <nb_hits>1</nb_hits>
+ <sum_time_spent>0</sum_time_spent>
+ <sum_bandwidth>0</sum_bandwidth>
+ <nb_hits_with_bandwidth>0</nb_hits_with_bandwidth>
+ <min_bandwidth />
+ <max_bandwidth />
+ <entry_nb_uniq_visitors>1</entry_nb_uniq_visitors>
+ <entry_nb_visits>1</entry_nb_visits>
+ <entry_nb_actions>1</entry_nb_actions>
+ <entry_sum_visit_length>0</entry_sum_visit_length>
+ <entry_bounce_count>1</entry_bounce_count>
+ <exit_nb_uniq_visitors>1</exit_nb_uniq_visitors>
+ <exit_nb_visits>1</exit_nb_visits>
+ <avg_bandwidth>0</avg_bandwidth>
+ <avg_page_load_time>0</avg_page_load_time>
+ <avg_time_on_page>0</avg_time_on_page>
+ <bounce_rate>100%</bounce_rate>
+ <exit_rate>100%</exit_rate>
+ <segment>pageTitle==Checkout%252FPurchasing...</segment>
+ </row>
+</result> \ No newline at end of file
diff --git a/tests/PHPUnit/System/expected/test_specialDateParams_lastmonth__VisitsSummary.getVisits_day.xml b/tests/PHPUnit/System/expected/test_specialDateParams_lastmonth__VisitsSummary.getVisits_day.xml
new file mode 100644
index 0000000000..606fbb5241
--- /dev/null
+++ b/tests/PHPUnit/System/expected/test_specialDateParams_lastmonth__VisitsSummary.getVisits_day.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>1</result> \ No newline at end of file
diff --git a/tests/PHPUnit/System/expected/test_specialDateParams_lastweek__Actions.getPageTitles_day.xml b/tests/PHPUnit/System/expected/test_specialDateParams_lastweek__Actions.getPageTitles_day.xml
new file mode 100644
index 0000000000..0cbcf088c9
--- /dev/null
+++ b/tests/PHPUnit/System/expected/test_specialDateParams_lastweek__Actions.getPageTitles_day.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+ <row>
+ <label> incredible!</label>
+ <nb_visits>1</nb_visits>
+ <nb_uniq_visitors>1</nb_uniq_visitors>
+ <nb_hits>1</nb_hits>
+ <sum_time_spent>0</sum_time_spent>
+ <sum_bandwidth>0</sum_bandwidth>
+ <nb_hits_with_bandwidth>0</nb_hits_with_bandwidth>
+ <min_bandwidth />
+ <max_bandwidth />
+ <entry_nb_uniq_visitors>1</entry_nb_uniq_visitors>
+ <entry_nb_visits>1</entry_nb_visits>
+ <entry_nb_actions>1</entry_nb_actions>
+ <entry_sum_visit_length>0</entry_sum_visit_length>
+ <entry_bounce_count>1</entry_bounce_count>
+ <exit_nb_uniq_visitors>1</exit_nb_uniq_visitors>
+ <exit_nb_visits>1</exit_nb_visits>
+ <avg_bandwidth>0</avg_bandwidth>
+ <avg_page_load_time>0</avg_page_load_time>
+ <avg_time_on_page>0</avg_time_on_page>
+ <bounce_rate>100%</bounce_rate>
+ <exit_rate>100%</exit_rate>
+ <segment>pageTitle==incredible%2521</segment>
+ </row>
+</result> \ No newline at end of file
diff --git a/tests/PHPUnit/System/expected/test_specialDateParams_lastweek__VisitsSummary.getVisits_day.xml b/tests/PHPUnit/System/expected/test_specialDateParams_lastweek__VisitsSummary.getVisits_day.xml
new file mode 100644
index 0000000000..606fbb5241
--- /dev/null
+++ b/tests/PHPUnit/System/expected/test_specialDateParams_lastweek__VisitsSummary.getVisits_day.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>1</result> \ No newline at end of file
diff --git a/tests/PHPUnit/System/expected/test_specialDateParams_lastyear__Actions.getPageTitles_day.xml b/tests/PHPUnit/System/expected/test_specialDateParams_lastyear__Actions.getPageTitles_day.xml
new file mode 100644
index 0000000000..2a3ee0717b
--- /dev/null
+++ b/tests/PHPUnit/System/expected/test_specialDateParams_lastyear__Actions.getPageTitles_day.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+ <row>
+ <label> Visit product</label>
+ <nb_visits>1</nb_visits>
+ <nb_uniq_visitors>1</nb_uniq_visitors>
+ <nb_hits>1</nb_hits>
+ <sum_time_spent>0</sum_time_spent>
+ <sum_bandwidth>0</sum_bandwidth>
+ <nb_hits_with_bandwidth>0</nb_hits_with_bandwidth>
+ <min_bandwidth />
+ <max_bandwidth />
+ <entry_nb_uniq_visitors>1</entry_nb_uniq_visitors>
+ <entry_nb_visits>1</entry_nb_visits>
+ <entry_nb_actions>1</entry_nb_actions>
+ <entry_sum_visit_length>0</entry_sum_visit_length>
+ <entry_bounce_count>1</entry_bounce_count>
+ <exit_nb_uniq_visitors>1</exit_nb_uniq_visitors>
+ <exit_nb_visits>1</exit_nb_visits>
+ <avg_bandwidth>0</avg_bandwidth>
+ <avg_page_load_time>0</avg_page_load_time>
+ <avg_time_on_page>0</avg_time_on_page>
+ <bounce_rate>100%</bounce_rate>
+ <exit_rate>100%</exit_rate>
+ <segment>pageTitle==Visit%2Bproduct</segment>
+ </row>
+</result> \ No newline at end of file
diff --git a/tests/PHPUnit/System/expected/test_specialDateParams_lastyear__VisitsSummary.getVisits_day.xml b/tests/PHPUnit/System/expected/test_specialDateParams_lastyear__VisitsSummary.getVisits_day.xml
new file mode 100644
index 0000000000..606fbb5241
--- /dev/null
+++ b/tests/PHPUnit/System/expected/test_specialDateParams_lastyear__VisitsSummary.getVisits_day.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>1</result> \ No newline at end of file
diff --git a/tests/PHPUnit/System/expected/test_specialDateParams_range__Actions.getPageTitles_range.xml b/tests/PHPUnit/System/expected/test_specialDateParams_range__Actions.getPageTitles_range.xml
new file mode 100644
index 0000000000..759d5c3392
--- /dev/null
+++ b/tests/PHPUnit/System/expected/test_specialDateParams_range__Actions.getPageTitles_range.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+ <row>
+ <label> Checkout/Purchasing...</label>
+ <nb_visits>1</nb_visits>
+ <nb_hits>1</nb_hits>
+ <sum_time_spent>0</sum_time_spent>
+ <sum_bandwidth>0</sum_bandwidth>
+ <nb_hits_with_bandwidth>0</nb_hits_with_bandwidth>
+ <min_bandwidth />
+ <max_bandwidth />
+ <entry_nb_visits>1</entry_nb_visits>
+ <entry_nb_actions>1</entry_nb_actions>
+ <entry_sum_visit_length>0</entry_sum_visit_length>
+ <entry_bounce_count>1</entry_bounce_count>
+ <exit_nb_visits>1</exit_nb_visits>
+ <sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors>
+ <sum_daily_entry_nb_uniq_visitors>1</sum_daily_entry_nb_uniq_visitors>
+ <sum_daily_exit_nb_uniq_visitors>1</sum_daily_exit_nb_uniq_visitors>
+ <avg_bandwidth>0</avg_bandwidth>
+ <avg_page_load_time>0</avg_page_load_time>
+ <avg_time_on_page>0</avg_time_on_page>
+ <bounce_rate>100%</bounce_rate>
+ <exit_rate>100%</exit_rate>
+ <segment>pageTitle==Checkout%252FPurchasing...</segment>
+ </row>
+ <row>
+ <label> incredible!</label>
+ <nb_visits>1</nb_visits>
+ <nb_hits>1</nb_hits>
+ <sum_time_spent>0</sum_time_spent>
+ <sum_bandwidth>0</sum_bandwidth>
+ <nb_hits_with_bandwidth>0</nb_hits_with_bandwidth>
+ <min_bandwidth />
+ <max_bandwidth />
+ <entry_nb_visits>1</entry_nb_visits>
+ <entry_nb_actions>1</entry_nb_actions>
+ <entry_sum_visit_length>0</entry_sum_visit_length>
+ <entry_bounce_count>1</entry_bounce_count>
+ <exit_nb_visits>1</exit_nb_visits>
+ <sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors>
+ <sum_daily_entry_nb_uniq_visitors>1</sum_daily_entry_nb_uniq_visitors>
+ <sum_daily_exit_nb_uniq_visitors>1</sum_daily_exit_nb_uniq_visitors>
+ <avg_bandwidth>0</avg_bandwidth>
+ <avg_page_load_time>0</avg_page_load_time>
+ <avg_time_on_page>0</avg_time_on_page>
+ <bounce_rate>100%</bounce_rate>
+ <exit_rate>100%</exit_rate>
+ <segment>pageTitle==incredible%2521</segment>
+ </row>
+ <row>
+ <label> Visit product</label>
+ <nb_visits>1</nb_visits>
+ <nb_hits>1</nb_hits>
+ <sum_time_spent>0</sum_time_spent>
+ <sum_bandwidth>0</sum_bandwidth>
+ <nb_hits_with_bandwidth>0</nb_hits_with_bandwidth>
+ <min_bandwidth />
+ <max_bandwidth />
+ <entry_nb_visits>1</entry_nb_visits>
+ <entry_nb_actions>1</entry_nb_actions>
+ <entry_sum_visit_length>0</entry_sum_visit_length>
+ <entry_bounce_count>1</entry_bounce_count>
+ <exit_nb_visits>1</exit_nb_visits>
+ <sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors>
+ <sum_daily_entry_nb_uniq_visitors>1</sum_daily_entry_nb_uniq_visitors>
+ <sum_daily_exit_nb_uniq_visitors>1</sum_daily_exit_nb_uniq_visitors>
+ <avg_bandwidth>0</avg_bandwidth>
+ <avg_page_load_time>0</avg_page_load_time>
+ <avg_time_on_page>0</avg_time_on_page>
+ <bounce_rate>100%</bounce_rate>
+ <exit_rate>100%</exit_rate>
+ <segment>pageTitle==Visit%2Bproduct</segment>
+ </row>
+</result> \ No newline at end of file
diff --git a/tests/PHPUnit/System/expected/test_specialDateParams_range__VisitsSummary.getVisits_range.xml b/tests/PHPUnit/System/expected/test_specialDateParams_range__VisitsSummary.getVisits_range.xml
new file mode 100644
index 0000000000..15ef03fb49
--- /dev/null
+++ b/tests/PHPUnit/System/expected/test_specialDateParams_range__VisitsSummary.getVisits_range.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>3</result> \ No newline at end of file
diff --git a/tests/PHPUnit/Unit/DateTest.php b/tests/PHPUnit/Unit/DateTest.php
index 2a328b6717..bf6da99863 100644
--- a/tests/PHPUnit/Unit/DateTest.php
+++ b/tests/PHPUnit/Unit/DateTest.php
@@ -15,6 +15,8 @@ use Piwik\SettingsServer;
use Piwik\Tests\Framework\Fixture;
/**
+ * @group Core
+ * @group DateTest
*/
class DateTest extends \PHPUnit\Framework\TestCase
{
@@ -36,8 +38,6 @@ class DateTest extends \PHPUnit\Framework\TestCase
/**
* create today object check that timestamp is correct (midnight)
- *
- * @group Core
*/
public function testToday()
{
@@ -52,29 +52,70 @@ class DateTest extends \PHPUnit\Framework\TestCase
/**
* create tomorrow object check that timestamp is correct (midnight)
- *
- * @group Core
*/
public function testTomorrow()
{
+ Date::$now = strtotime('2020-05-05 17:00:00'); // 1588698000
$date = Date::tomorrow();
- $this->assertEquals(strtotime(date("Y-m-d ", strtotime('+1day')) . " 00:00:00"), $date->getTimestamp());
+ $this->assertEquals("2020-05-06 00:00:00", $date->getDatetime());
+ $this->assertEquals(1588723200, $date->getTimestamp());
}
/**
* create today object check that timestamp is correct (midnight)
- *
- * @group Core
*/
public function testYesterday()
{
+ Date::$now = strtotime('2020-05-05 17:00:00'); // 1588698000
$date = Date::yesterday();
- $this->assertEquals(strtotime(date("Y-m-d", strtotime('-1day')) . " 00:00:00"), $date->getTimestamp());
+ $this->assertEquals("2020-05-04 00:00:00", $date->getDatetime());
+ $this->assertEquals(1588550400, $date->getTimestamp());
}
/**
- * @group Core
+ * create today object check that timestamp is correct (same time)
*/
+ public function testYesterdaySameTime()
+ {
+ Date::$now = strtotime('2020-05-05 17:00:00'); // 1588698000
+ $date = Date::yesterdaySameTime();
+ $this->assertEquals("2020-05-04 17:00:00", $date->getDatetime());
+ $this->assertEquals(1588611600, $date->getTimestamp());
+ }
+
+ /**
+ * create last week object check that timestamp is correct (midnight)
+ */
+ public function testLastWeek()
+ {
+ Date::$now = strtotime('2020-05-05 17:00:00'); // 1588698000
+ $date = Date::lastWeek();
+ $this->assertEquals("2020-04-28 00:00:00", $date->getDatetime());
+ $this->assertEquals(1588032000, $date->getTimestamp());
+ }
+
+ /**
+ * create last month object check that timestamp is correct (midnight)
+ */
+ public function testLastMonth()
+ {
+ Date::$now = strtotime('2020-05-05 17:00:00'); // 1588698000
+ $date = Date::lastMonth();
+ $this->assertEquals("2020-04-05 00:00:00", $date->getDatetime());
+ $this->assertEquals(1586044800, $date->getTimestamp());
+ }
+
+ /**
+ * create last year object check that timestamp is correct (midnight)
+ */
+ public function testLastYear()
+ {
+ Date::$now = strtotime('2020-05-05 17:00:00'); // 1588698000
+ $date = Date::lastYear();
+ $this->assertEquals("2019-05-05 00:00:00", $date->getDatetime());
+ $this->assertEquals(1557014400, $date->getTimestamp());
+ }
+
public function testInvalidDateThrowsException()
{
$this->expectException(Exception::class);
@@ -94,8 +135,6 @@ class DateTest extends \PHPUnit\Framework\TestCase
}
/**
- * @group Core
- * @group DateTest
* @dataProvider getTimezoneOffsets
*/
public function testGetUtcOffset($timezone, $expectedOffset)
@@ -104,9 +143,6 @@ class DateTest extends \PHPUnit\Framework\TestCase
$this->assertEquals($expectedOffset, $offset);
}
- /**
- * @group Core
- */
public function testFactoryTimezone()
{
// now in UTC converted to UTC+10 means adding 10 hours
@@ -158,9 +194,6 @@ class DateTest extends \PHPUnit\Framework\TestCase
$this->assertSame('19', $hour);
}
- /**
- * @group Core
- */
public function testSetTimezoneDayInUTC()
{
$date = Date::factory('2010-01-01');
@@ -208,9 +241,6 @@ class DateTest extends \PHPUnit\Framework\TestCase
}
}
- /**
- * @group Core
- */
public function testModifyDateWithTimezone()
{
$date = Date::factory('2010-01-01');
@@ -229,9 +259,6 @@ class DateTest extends \PHPUnit\Framework\TestCase
}
}
- /**
- * @group Core
- */
public function testGetDateStartUTCEndDuringDstTimezone()
{
if (SettingsServer::isTimezoneSupportEnabled()) {
@@ -246,9 +273,6 @@ class DateTest extends \PHPUnit\Framework\TestCase
}
}
- /**
- * @group Core
- */
public function testAddHour()
{
// add partial hours less than 1
@@ -270,9 +294,6 @@ class DateTest extends \PHPUnit\Framework\TestCase
$this->assertEquals($dayExpected, $date->getDatetime());
}
- /**
- * @group Core
- */
public function testAddHourLongHours()
{
$dateTime = '2010-01-03 11:22:33';
@@ -281,9 +302,6 @@ class DateTest extends \PHPUnit\Framework\TestCase
$this->assertEquals($dateTime, Date::factory($dateTime)->addHour(48.1)->subHour(48.1)->getDatetime());
}
- /**
- * @group Core
- */
public function testAddPeriod()
{
$date = Date::factory('2010-01-01');
@@ -297,9 +315,6 @@ class DateTest extends \PHPUnit\Framework\TestCase
$this->assertEquals($dateExpected->getTimestamp(), $date->getTimestamp());
}
- /**
- * @group Core
- */
public function testSubPeriod()
{
$date = Date::factory('2010-03-01');
@@ -313,9 +328,6 @@ class DateTest extends \PHPUnit\Framework\TestCase
$this->assertEquals($dateExpected->getTimestamp(), $date->getTimestamp());
}
- /**
- * @group Core
- */
public function testSubSeconds()
{
$date = Date::factory('2010-03-01 00:01:25');
@@ -330,9 +342,6 @@ class DateTest extends \PHPUnit\Framework\TestCase
$this->assertSame($dateExpected->getTimestamp(), $date->getTimestamp());
}
- /**
- * @group Core
- */
public function testAddPeriodMonthRespectsMaxDaysInMonth()
{
$date = Date::factory('2014-07-31');
@@ -352,9 +361,6 @@ class DateTest extends \PHPUnit\Framework\TestCase
$this->assertEquals($dateExpected->toString(), $dateActual->toString());
}
- /**
- * @group Core
- */
public function testIsLeapYear()
{
$date = Date::factory('2011-03-01');
@@ -395,7 +401,6 @@ class DateTest extends \PHPUnit\Framework\TestCase
}
/**
- * @group Core
* @dataProvider getLocalizedLongStrings
*/
public function testGetLocalizedTimeFormats($language, $use12HourClock, $time, $shouldBe)
@@ -441,6 +446,18 @@ class DateTest extends \PHPUnit\Framework\TestCase
['yesterdaySameTime', 'UTC-5', '2012-12-30 20:00:00', '2013-01-01 01:00:00'],
['yesterdaySameTime', 'UTC-5', '2012-12-31 01:00:00', '2013-01-01 06:00:00'],
['yesterdaySameTime', 'America/Toronto', '2012-12-31 01:00:00', '2013-01-01 06:00:00'],
+ ['lastWeek', 'America/Toronto', '2012-12-24 00:00:00', '2013-01-01 01:00:00'],
+ ['lastweek', 'UTC-5', '2012-12-24 00:00:00', '2013-01-01 01:00:00'],
+ ['last week', 'UTC-5', '2012-12-25 00:00:00', '2013-01-01 06:00:00'],
+ ['last-week', 'America/Toronto', '2012-12-25 00:00:00', '2013-01-01 06:00:00'],
+ ['lastMonth', 'America/Toronto', '2012-12-01 00:00:00', '2013-01-01 01:00:00'],
+ ['lastmonth', 'UTC-5', '2012-12-01 00:00:00', '2013-01-01 01:00:00'],
+ ['last month', 'UTC-5', '2012-12-01 00:00:00', '2013-01-01 06:00:00'],
+ ['last-month', 'America/Toronto', '2012-12-01 00:00:00', '2013-01-01 06:00:00'],
+ ['lastYear', 'America/Toronto', '2011-12-31 00:00:00', '2013-01-01 01:00:00'],
+ ['lastyear', 'UTC-5', '2011-12-31 00:00:00', '2013-01-01 01:00:00'],
+ ['last year', 'UTC-5', '2012-01-01 00:00:00', '2013-01-01 06:00:00'],
+ ['last-year', 'America/Toronto', '2012-01-01 00:00:00', '2013-01-01 06:00:00'],
// UTC+5
['now', 'Antarctica/Mawson', '2012-12-31 19:00:00', '2012-12-31 14:00:00'],
@@ -459,6 +476,18 @@ class DateTest extends \PHPUnit\Framework\TestCase
['yesterdaySameTime', 'UTC+5', '2012-12-30 19:00:00', '2012-12-31 14:00:00'],
['yesterdaySameTime', 'UTC+5', '2012-12-31 01:00:00', '2012-12-31 20:00:00'],
['yesterdaySameTime', 'Antarctica/Mawson', '2012-12-31 01:00:00', '2012-12-31 20:00:00'],
+ ['lastWeek', 'Antarctica/Mawson', '2012-12-24 00:00:00', '2012-12-31 14:00:00'],
+ ['lastweek', 'UTC+5', '2012-12-24 00:00:00', '2012-12-31 14:00:00'],
+ ['last week', 'UTC+5', '2012-12-25 00:00:00', '2012-12-31 19:00:00'],
+ ['last-week', 'Antarctica/Mawson', '2012-12-25 00:00:00', '2012-12-31 19:00:00'],
+ ['lastMonth', 'Antarctica/Mawson', '2012-12-01 00:00:00', '2012-12-31 14:00:00'],
+ ['lastmonth', 'UTC+5', '2012-12-01 00:00:00', '2012-12-31 14:00:00'],
+ ['last month', 'UTC+5', '2012-12-01 00:00:00', '2012-12-31 19:00:00'],
+ ['last-month', 'Antarctica/Mawson', '2012-12-01 00:00:00', '2012-12-31 19:00:00'],
+ ['lastYear', 'Antarctica/Mawson', '2011-12-31 00:00:00', '2012-12-31 14:00:00'],
+ ['lastyear', 'UTC+5', '2011-12-31 00:00:00', '2012-12-31 14:00:00'],
+ ['last year', 'UTC+5', '2012-01-01 00:00:00', '2012-12-31 19:00:00'],
+ ['last-year', 'Antarctica/Mawson', '2012-01-01 00:00:00', '2012-12-31 19:00:00'],
];
}