diff options
12 files changed, 78 insertions, 22 deletions
diff --git a/core/Period/Range.php b/core/Period/Range.php index a81d2c2781..b2987d509c 100644 --- a/core/Period/Range.php +++ b/core/Period/Range.php @@ -463,14 +463,23 @@ class Range extends Period $period = Common::getRequestVar('period'); } - if (365 == $subXPeriods && 'day' == $period && Date::today()->isLeapYear()) { + if (365 == $subXPeriods && 'day' == $period && Date::factory($date)->isLeapYear()) { $subXPeriods = 366; } + if ($period === 'range') { + $rangePeriod = new Range($period, $date); + $daysDifference = self::getNumDaysDifference($rangePeriod->getDateStart(), $rangePeriod->getDateEnd()); + $end = $rangePeriod->getDateStart()->subDay(1); + $from = $end->subDay($daysDifference); + + return array("$from,$end", false); + } + // can't get the last date for range periods & dates that use lastN/previousN $strLastDate = false; $lastPeriod = false; - if ($period != 'range' && !preg_match('/(last|previous)([0-9]*)/', $date, $regs)) { + if (!preg_match('/(last|previous)([0-9]*)/', $date, $regs)) { if (strpos($date, ',')) { // date in the form of 2011-01-01,2011-02-02 @@ -489,6 +498,13 @@ class Range extends Period return array($strLastDate, $lastPeriod); } + + private static function getNumDaysDifference(Date $date1, Date $date2) + { + $days = (abs($date1->getTimestamp() - $date2->getTimestamp())) / 60 / 60 / 24; + return (int) round($days); + } + /** * Returns a date range string given a period type, end date and number of periods * the range spans over. diff --git a/plugins/CorePluginsAdmin/tests/UI/expected-screenshots/TagManagerTeaser_admin_page_disable.png b/plugins/CorePluginsAdmin/tests/UI/expected-screenshots/TagManagerTeaser_admin_page_disable.png index 04ed00d9a4..6ce75aabc9 100644 --- a/plugins/CorePluginsAdmin/tests/UI/expected-screenshots/TagManagerTeaser_admin_page_disable.png +++ b/plugins/CorePluginsAdmin/tests/UI/expected-screenshots/TagManagerTeaser_admin_page_disable.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:182c8776bdf177945552a5845b8e47fb2473b73e274253190e8682b12c50549e -size 177521 +oid sha256:70fa580ddfa5f39ef368a4650ad3a757f7ee8ec342dcafde8da40d3d1bd82ddb +size 184451 diff --git a/plugins/Dashboard/Dashboard.php b/plugins/Dashboard/Dashboard.php index cf027c6c64..069e6cb969 100644 --- a/plugins/Dashboard/Dashboard.php +++ b/plugins/Dashboard/Dashboard.php @@ -150,9 +150,11 @@ class Dashboard extends \Piwik\Plugin $defaultLayout = $this->getLayoutForUser('', 1); if (empty($defaultLayout)) { + $pluginManager = Plugin\Manager::getInstance(); + $advertisingWidget = ''; $advertising = StaticContainer::get('Piwik\ProfessionalServices\Advertising'); - if ($advertising->areAdsForProfessionalServicesEnabled() && Plugin\Manager::getInstance()->isPluginActivated('ProfessionalServices')) { + if ($advertising->areAdsForProfessionalServicesEnabled() && $pluginManager->isPluginActivated('ProfessionalServices')) { $advertisingWidget = '{"uniqueId":"widgetProfessionalServicespromoServices","parameters":{"module":"ProfessionalServices","action":"promoServices"}},'; } if (Piwik::hasUserSuperUserAccess()) { @@ -160,6 +162,10 @@ class Dashboard extends \Piwik\Plugin } else { $piwikPromoWidget = '{"uniqueId":"widgetCoreHomegetPromoVideo","parameters":{"module":"CoreHome","action":"getPromoVideo"}}'; } + $insightsWidget = ''; + if ($pluginManager->isPluginActivated('Insights')) { + $insightsWidget = '{"uniqueId":"widgetInsightsgetOverallMoversAndShakers","parameters":{"module":"Insights","action":"getOverallMoversAndShakers"}},'; + } $defaultLayout = '[ [ {"uniqueId":"widgetLivewidget","parameters":{"module":"Live","action":"widget"}}, @@ -168,6 +174,7 @@ class Dashboard extends \Piwik\Plugin [ {"uniqueId":"widgetVisitsSummarygetEvolutionGraphforceView1viewDataTablegraphEvolution","parameters":{"forceView":"1","viewDataTable":"graphEvolution","module":"VisitsSummary","action":"getEvolutionGraph"}}, ' . $advertisingWidget . ' + ' . $insightsWidget . ' {"uniqueId":"widgetVisitsSummarygetforceView1viewDataTablesparklines","parameters":{"forceView":"1","viewDataTable":"sparklines","module":"VisitsSummary","action":"get"}} ], [ diff --git a/plugins/Dashboard/tests/UI/expected-screenshots/DashboardManager_create_new.png b/plugins/Dashboard/tests/UI/expected-screenshots/DashboardManager_create_new.png index 0758e86dee..476dd842f2 100644 --- a/plugins/Dashboard/tests/UI/expected-screenshots/DashboardManager_create_new.png +++ b/plugins/Dashboard/tests/UI/expected-screenshots/DashboardManager_create_new.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:dd7a915297b1e0133b9a4ea0f2582e08de7b25dca0d6e31bc6907bb74aebb31a -size 287727 +oid sha256:3fb778b95d00d90336df9679e96014f513ff058df9f76ea502d023a757bf1285 +size 305893 diff --git a/plugins/Dashboard/tests/UI/expected-screenshots/Dashboard_reset.png b/plugins/Dashboard/tests/UI/expected-screenshots/Dashboard_reset.png index 32c1ff560d..dffc459de3 100644 --- a/plugins/Dashboard/tests/UI/expected-screenshots/Dashboard_reset.png +++ b/plugins/Dashboard/tests/UI/expected-screenshots/Dashboard_reset.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:66ce0f6234d80c90741d0e9ff99d871c141b403101fee5616a2257bb945c2cc0 -size 281686 +oid sha256:6718ef832b90b5fc4334fdd9f71769931495b0bdcac16a97a726e6cccf64052d +size 350683 diff --git a/plugins/Insights/tests/Integration/ApiTest.php b/plugins/Insights/tests/Integration/ApiTest.php index fc53973da5..5c3f616513 100644 --- a/plugins/Insights/tests/Integration/ApiTest.php +++ b/plugins/Insights/tests/Integration/ApiTest.php @@ -246,7 +246,7 @@ class ApiTest extends SystemTestCase $this->assertTrue($this->api->canGenerateInsights('2012-12-12', 'month')); $this->assertFalse($this->api->canGenerateInsights('last10', 'day')); - $this->assertFalse($this->api->canGenerateInsights('2012-11-11,2012-12-12', 'range')); + $this->assertTrue($this->api->canGenerateInsights('2012-11-11,2012-12-12', 'range')); } private function requestInsights($requestParams) diff --git a/plugins/Insights/tests/Integration/ModelTest.php b/plugins/Insights/tests/Integration/ModelTest.php index 7c3edbaf15..01643700f8 100644 --- a/plugins/Insights/tests/Integration/ModelTest.php +++ b/plugins/Insights/tests/Integration/ModelTest.php @@ -122,14 +122,6 @@ class ModelTest extends SystemTestCase $this->model->getLastDate('last10', 'day', 1); } - /** - * @expectedException \Exception - */ - public function test_getLastDate_shouldThrowExceptionInCaseOfRangePeriod() - { - $this->model->getLastDate('2012-11-11,2012-12-12', 'range', 1); - } - public function test_getTotalValue_shouldCalculateTotals() { $total = $this->model->getTotalValue(self::$fixture->idSite, 'day', self::$fixture->date1, 'nb_visits', false); diff --git a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_logme_verified.png b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_logme_verified.png index 02c9c00dbc..b23762e59e 100644 --- a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_logme_verified.png +++ b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_logme_verified.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4b837c5b31cc067d7f45970989f6412c2c6d224d12d1e9756e686605aafa20f9 -size 177892 +oid sha256:0eed847c873304a25e3adee98c9ce43c28f8efc1928616e918a6f7b0e707af8f +size 184906 diff --git a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step4.png b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step4.png index 5968874a82..76568db089 100644 --- a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step4.png +++ b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step4.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:65e373f1147fbdbe2f97f4083241c776aac3b18848755a1e83f0ae2e0ca84e53 -size 176964 +oid sha256:8e576f1b42887837fe1b9b30436ccd1c9e9088e8db46459c62acd0829f6d3ec9 +size 183745 diff --git a/tests/PHPUnit/System/expected/test_oneVisitor_oneWebsite_severalDays_DateRange__MultiSites.getAll_range.xml b/tests/PHPUnit/System/expected/test_oneVisitor_oneWebsite_severalDays_DateRange__MultiSites.getAll_range.xml index d758a762ff..22ff810189 100644 --- a/tests/PHPUnit/System/expected/test_oneVisitor_oneWebsite_severalDays_DateRange__MultiSites.getAll_range.xml +++ b/tests/PHPUnit/System/expected/test_oneVisitor_oneWebsite_severalDays_DateRange__MultiSites.getAll_range.xml @@ -6,6 +6,10 @@ <nb_actions>9</nb_actions> <nb_pageviews>9</nb_pageviews> <revenue>0</revenue> + <visits_evolution>200%</visits_evolution> + <actions_evolution>200%</actions_evolution> + <pageviews_evolution>200%</pageviews_evolution> + <revenue_evolution>0%</revenue_evolution> <idsite>1</idsite> <group /> <main_url>http://piwik.net</main_url> @@ -16,6 +20,10 @@ <nb_actions>2</nb_actions> <nb_pageviews>2</nb_pageviews> <revenue>0</revenue> + <visits_evolution>100%</visits_evolution> + <actions_evolution>100%</actions_evolution> + <pageviews_evolution>100%</pageviews_evolution> + <revenue_evolution>0%</revenue_evolution> <idsite>2</idsite> <group /> <main_url>http://piwik.net</main_url> diff --git a/tests/PHPUnit/System/expected/test_oneVisitor_oneWebsite_severalDays_DateRange__MultiSites.getOne_range.xml b/tests/PHPUnit/System/expected/test_oneVisitor_oneWebsite_severalDays_DateRange__MultiSites.getOne_range.xml index 148c3cd10d..e9115ba10c 100644 --- a/tests/PHPUnit/System/expected/test_oneVisitor_oneWebsite_severalDays_DateRange__MultiSites.getOne_range.xml +++ b/tests/PHPUnit/System/expected/test_oneVisitor_oneWebsite_severalDays_DateRange__MultiSites.getOne_range.xml @@ -2,6 +2,10 @@ <result> <nb_visits>6</nb_visits> <nb_actions>9</nb_actions> + <visits_evolution>200%</visits_evolution> + <actions_evolution>200%</actions_evolution> + <pageviews_evolution>200%</pageviews_evolution> + <revenue_evolution>0%</revenue_evolution> <nb_pageviews>9</nb_pageviews> <revenue>0</revenue> </result>
\ No newline at end of file diff --git a/tests/PHPUnit/Unit/Period/RangeTest.php b/tests/PHPUnit/Unit/Period/RangeTest.php index 5ad22916fa..2fb27457df 100644 --- a/tests/PHPUnit/Unit/Period/RangeTest.php +++ b/tests/PHPUnit/Unit/Period/RangeTest.php @@ -21,6 +21,35 @@ use Piwik\Period\Year; */ class RangeTest extends BasePeriodTest { + /** + * @dataProvider getDateXPeriodsAgoProvider + */ + public function testGetDateXPeriodsAgo($expected, $subXPeriods, $date, $period) + { + $result = Range::getDateXPeriodsAgo($subXPeriods, $date, $period); + $day = [$expected,$expected]; + if ($period === 'range') { + $day = [$expected, false]; + } + $this->assertEquals($day, $result); + } + + public function getDateXPeriodsAgoProvider() + { + return [ + ['2019-05-14', '1', '2019-05-15', 'day'], + ['2018-05-15', '1', '2019-05-15', 'year'], + ['2019-05-08', '1', '2019-05-15', 'week'], + ['2019-04-15', '1', '2019-05-15', 'month'], + ['2019-02-15', '3', '2019-05-15', 'month'], + ['2018-05-15', '365', '2019-05-15', 'day'], + ['2018-05-15', '1', '2019-05-15', 'year'], + ['2017-05-15', '2', '2019-05-15', 'year'], + ['2019-06-04,2019-06-09', '1', '2019-06-10,2019-06-15', 'range'], + ['2019-06-10,2019-06-12', '1', '2019-06-13,2019-06-15', 'range'], + ]; + } + // test range 1 public function testRangeToday() { |