diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2019-08-16 04:41:56 +0300 |
---|---|---|
committer | diosmosis <diosmosis@users.noreply.github.com> | 2019-08-16 04:41:56 +0300 |
commit | 9ed5c2ca7735eb265660b90930f6ef1b5e5c4e23 (patch) | |
tree | 70022ca571a06ec3347fe2f601264f46584b8bac /plugins/Live/tests/Integration | |
parent | fe5760730ac3c06d6df595b4d3ec523ffcc3a502 (diff) |
Tweak live queries when they query current week, month, or year where end date is in the future (#14759)
Diffstat (limited to 'plugins/Live/tests/Integration')
-rw-r--r-- | plugins/Live/tests/Integration/ModelTest.php | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/plugins/Live/tests/Integration/ModelTest.php b/plugins/Live/tests/Integration/ModelTest.php index 9691583903..2132c9434d 100644 --- a/plugins/Live/tests/Integration/ModelTest.php +++ b/plugins/Live/tests/Integration/ModelTest.php @@ -32,6 +32,51 @@ class ModelTest extends IntegrationTestCase Fixture::createWebsite('2010-01-01'); } + public function test_getStandAndEndDate_usesNowWhenDateOutOfRange() + { + $model = new Model(); + list($dateStart, $dateEnd) = $model->getStartAndEndDate($idSite = 1, 'year', '2025-01-01'); + + $validDates = $this->getValidNowDates(); + + $this->assertTrue(in_array($dateStart->getDatetime(), $validDates)); + $this->assertTrue(in_array($dateEnd->getDatetime(), $validDates)); + $this->assertNotEquals($dateStart->getDatetime(), $dateEnd->getDatetime()); + } + + public function test_getStandAndEndDate_usesNowWhenEndDateOutOfRange() + { + $model = new Model(); + list($dateStart, $dateEnd) = $model->getStartAndEndDate($idSite = 1, 'year', date('Y').'-01-01'); + + $validDates = $this->getValidNowDates(); + + $this->assertEquals(date('Y') . '-01-01 00:00:00', $dateStart->getDatetime()); + $this->assertTrue(in_array($dateEnd->getDatetime(), $validDates)); + $this->assertNotEquals($dateStart->getDatetime(), $dateEnd->getDatetime()); + } + + private function getValidNowDates() + { + $now = Date::now(); + $validDates = [$now->getDatetime()]; + $validDates[] = $now->subSeconds(1)->getDatetime(); + $validDates[] = $now->subSeconds(2)->getDatetime(); + $validDates[] = $now->addPeriod(1, 'second')->getDatetime(); + $validDates[] = $now->addPeriod(2, 'second')->getDatetime(); + + return $validDates; + } + + public function test_getStandAndEndDate() + { + $model = new Model(); + list($dateStart, $dateEnd) = $model->getStartAndEndDate($idSite = 1, 'year', '2018-02-01'); + + $this->assertEquals('2018-01-01 00:00:00', $dateStart->getDatetime()); + $this->assertEquals('2019-01-01 00:00:00', $dateEnd->getDatetime()); + } + public function test_makeLogVisitsQueryString() { $model = new Model(); |