diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2019-06-17 07:42:33 +0300 |
---|---|---|
committer | diosmosis <diosmosis@users.noreply.github.com> | 2019-06-17 07:42:33 +0300 |
commit | ed267097edc29349ec8482fdfac86b47bc23c660 (patch) | |
tree | 1ad560f8fef5219075e33ba5c999241cdc87f94c /plugins/SitesManager/tests | |
parent | 824204a88d80b229df3708d1edcf5416eeb2ea44 (diff) |
fix no data message may not be shown when deleteLogs is enabled (#14526)
* fix no data message may not be shown when deleteLogs is enabled
* apply review feedback making it simpler
* Adding tests.
Diffstat (limited to 'plugins/SitesManager/tests')
-rw-r--r-- | plugins/SitesManager/tests/Integration/SitesManagerTest.php | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/plugins/SitesManager/tests/Integration/SitesManagerTest.php b/plugins/SitesManager/tests/Integration/SitesManagerTest.php index 5676372776..2f62a39c5a 100644 --- a/plugins/SitesManager/tests/Integration/SitesManagerTest.php +++ b/plugins/SitesManager/tests/Integration/SitesManagerTest.php @@ -10,8 +10,12 @@ namespace Piwik\Plugins\SitesManager\tests\Integration; use Piwik\Cache; use Piwik\Archive\ArchiveInvalidator; +use Piwik\Common; use Piwik\Container\StaticContainer; use Piwik\Date; +use Piwik\Db; +use Piwik\Option; +use Piwik\Piwik; use Piwik\Plugins\SitesManager\SitesManager; use Piwik\Tests\Framework\Fixture; use Piwik\Tests\Framework\Mock\FakeAccess; @@ -74,6 +78,106 @@ class SitesManagerTest extends IntegrationTestCase $this->assertEquals($expected, $archive->getRememberedArchivedReportsThatShouldBeInvalidated()); } + /** + * @dataProvider getTestDataForRedirectDashboard + */ + public function test_redirectDashboardToWelcomePage_doesNothingIfModuleActionAreIncorrect($module, $action) + { + $originalModule = $module; + $originalAction = $action; + $params = []; + + Piwik::postEvent('Request.dispatch', [&$module, &$action, &$params]); + + $this->assertEquals($originalModule, $module); + $this->assertEquals($originalAction, $action); + } + + public function getTestDataForRedirectDashboard() + { + return [ + ['CoreHome', 'someothermethod'], + ['SitesManager', 'index'], + ]; + } + + public function test_redirectDashboardToWelcomePage_doesNothingIfThereIsNoIdSiteParam() + { + $module = 'CoreHome'; + $action = 'index'; + $params = []; + + Piwik::postEvent('Request.dispatch', [&$module, &$action, &$params]); + + $this->assertEquals('CoreHome', $module); + $this->assertEquals('index', $action); + } + + public function test_redirectDashboardToWelcomePage_doesNothingIfAVisitWasTrackedInThePast() + { + $module = 'CoreHome'; + $action = 'index'; + $params = []; + + $_GET['idSite'] = $this->siteId; + + $tracker = Fixture::getTracker($this->siteId, '2015-02-04 04:12:35'); + $tracker->setUrl('http://example.com/'); + Fixture::checkResponse($tracker->doTrackPageView('a test title')); + + $this->assertEquals(false, Option::get('SitesManagerHadTrafficInPast_' . $this->siteId)); + + Piwik::postEvent('Request.dispatch', [&$module, &$action, &$params]); + + $this->assertEquals('1', Option::get('SitesManagerHadTrafficInPast_' . $this->siteId)); + + $this->assertEquals('CoreHome', $module); + $this->assertEquals('index', $action); + } + + public function test_redirectDashboardToWelcomePage_doesNothingIfAVisitWasTrackedAndWasLaterPurged() + { + $module = 'CoreHome'; + $action = 'index'; + $params = []; + + $_GET['idSite'] = $this->siteId; + + $tracker = Fixture::getTracker($this->siteId, '2015-02-04 04:12:35'); + $tracker->setUrl('http://example.com/'); + Fixture::checkResponse($tracker->doTrackPageView('a test title')); + + Piwik::postEvent('Request.dispatch', [&$module, &$action, &$params]); + + Db::exec('TRUNCATE ' . Common::prefixTable('log_visit')); + + $module = 'CoreHome'; + $action = 'index'; + + $this->assertEquals('CoreHome', $module); + $this->assertEquals('index', $action); + } + + public function test_redirectDashboardToWelcomePage_redirectsIfThereIsNoDataAndAppropriateParams() + { + $module = 'CoreHome'; + $action = 'index'; + $params = []; + + $_GET['idSite'] = $this->siteId; + + Piwik::postEvent('Request.dispatch', [&$module, &$action, &$params]); + + $this->assertEquals('SitesManager', $module); + $this->assertEquals('siteWithoutData', $action); + } + + protected static function configureFixture($fixture) + { + parent::configureFixture($fixture); + $fixture->createSuperUser = true; + } + public function provideContainerConfig() { return array( |