Skip to content
Extraits de code Groupes Projets
Valider e706eb20 rédigé par Benaka's avatar Benaka
Parcourir les fichiers

Merge pull request #7814 from piwik/fix-7795

Fix report date to load by default, make sure default period is set using actual user preference and not using date inferred from user preference.
parents 4f24a59a 13fa0858
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -106,10 +106,10 @@ class UserPreferences ...@@ -106,10 +106,10 @@ class UserPreferences
private function getDefaultDateAndPeriod($defaultDate = null) private function getDefaultDateAndPeriod($defaultDate = null)
{ {
$defaultPeriod = $this->getDefaultPeriodWithoutValidation($defaultDate);
if (! $defaultDate) { if (! $defaultDate) {
$defaultDate = $this->getDefaultDateWithoutValidation(); $defaultDate = $this->getDefaultDateWithoutValidation();
} }
$defaultPeriod = $this->getDefaultPeriodWithoutValidation($defaultDate);
$periodValidator = new PeriodValidator(); $periodValidator = new PeriodValidator();
if (! $periodValidator->isPeriodAllowedForUI($defaultPeriod)) { if (! $periodValidator->isPeriodAllowedForUI($defaultPeriod)) {
......
...@@ -90,22 +90,26 @@ class UserPreferencesTest extends IntegrationTestCase ...@@ -90,22 +90,26 @@ class UserPreferencesTest extends IntegrationTestCase
$this->assertEquals(1, $this->userPreferences->getDefaultWebsiteId()); $this->assertEquals(1, $this->userPreferences->getDefaultWebsiteId());
} }
public function test_getDefaultPeriod_ShouldReturnDayIfToday() /**
{ * @dataProvider provideDefaultDates
$this->setDefaultDate('today'); */
$this->assertEquals('day', $this->userPreferences->getDefaultPeriod()); public function test_getDefaultDateAndPeriod($defaultDate, $expectedDate, $expectedPeriod)
}
public function test_getDefaultPeriod_ShouldReturnDayIfYesterday()
{ {
$this->setDefaultDate('yesterday'); $this->setDefaultDate($defaultDate);
$this->assertEquals('day', $this->userPreferences->getDefaultPeriod()); $this->assertEquals($expectedDate, $this->userPreferences->getDefaultDate());
$this->assertEquals($expectedPeriod, $this->userPreferences->getDefaultPeriod());
} }
public function test_getDefaultDate() public function provideDefaultDates()
{ {
$this->setDefaultDate('today'); return array(
$this->assertEquals('today', $this->userPreferences->getDefaultDate()); 'today' => array('today', 'today', 'day'),
'yesterday' => array('yesterday', 'yesterday', 'day'),
'month' => array('month', 'today', 'month'),
'week' => array('week', 'today', 'week'),
'last7' => array('last7', 'last7', 'range'),
'last30' => array('last30', 'last30', 'range'),
);
} }
public function test_getDefaultPeriod_ShouldOnlyReturnAllowedPeriods() public function test_getDefaultPeriod_ShouldOnlyReturnAllowedPeriods()
...@@ -113,8 +117,12 @@ class UserPreferencesTest extends IntegrationTestCase ...@@ -113,8 +117,12 @@ class UserPreferencesTest extends IntegrationTestCase
// Only allow for week period // Only allow for week period
Config::getInstance()->General['enabled_periods_UI'] = 'week'; Config::getInstance()->General['enabled_periods_UI'] = 'week';
Config::getInstance()->General['default_period'] = 'week'; Config::getInstance()->General['default_period'] = 'week';
Config::getInstance()->General['default_day'] = 'yesterday';
$this->setDefaultDate('today'); $this->setDefaultDate('today');
// Should be system defaults
$this->assertEquals('week', $this->userPreferences->getDefaultPeriod()); $this->assertEquals('week', $this->userPreferences->getDefaultPeriod());
$this->assertEquals('yesterday', $this->userPreferences->getDefaultDate());
} }
public function test_getDefaultDate_ShouldOnlyReturnDateInAllowedPeriods() public function test_getDefaultDate_ShouldOnlyReturnDateInAllowedPeriods()
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter