diff options
author | Stefan Giehl <stefan@matomo.org> | 2020-12-10 05:18:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-10 05:18:07 +0300 |
commit | 7cde69f763f2cbf2b9a27c8a7dcf7bcaa950c3bd (patch) | |
tree | da719a778d96e167ee4ba55c89a529c1c3bb0dce /tests/PHPUnit/Fixtures | |
parent | 06918eea4d2ca01298200348b40f57817433b931 (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/PHPUnit/Fixtures')
-rw-r--r-- | tests/PHPUnit/Fixtures/VisitsInCurrentYear.php | 70 |
1 files changed, 70 insertions, 0 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¶meter=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¶meter=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 |