diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2020-02-21 06:22:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-21 06:22:56 +0300 |
commit | a3ccdede6f6d6fed000a6de92a7284ba38e14b7f (patch) | |
tree | dd5787269353fdb6cfba22d9fa5b09bd05084da3 /tests/PHPUnit/Fixtures | |
parent | 150e6667e49469f77c73e4c9191963f719c93b6c (diff) |
Add UI test for JavaScript tracking. (#15567)
* Add UI test for JavaScript tracking.
* apply some review feedback
* try to fix UI test on travis
* Add missing screenshot.
* Normalize JSTracker UI test result.
* update screenshot
Diffstat (limited to 'tests/PHPUnit/Fixtures')
-rw-r--r-- | tests/PHPUnit/Fixtures/JSTrackingUIFixture.php | 53 | ||||
-rw-r--r-- | tests/PHPUnit/Fixtures/UITestFixture.php | 12 |
2 files changed, 60 insertions, 5 deletions
diff --git a/tests/PHPUnit/Fixtures/JSTrackingUIFixture.php b/tests/PHPUnit/Fixtures/JSTrackingUIFixture.php new file mode 100644 index 0000000000..73c86fef61 --- /dev/null +++ b/tests/PHPUnit/Fixtures/JSTrackingUIFixture.php @@ -0,0 +1,53 @@ +<?php +/** + * Piwik - 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\Plugins\GeoIp2\LocationProvider\GeoIp2\Php; +use Piwik\Plugins\PrivacyManager\IPAnonymizer; +use Piwik\Plugins\UserCountry\LocationProvider; +use Piwik\Tests\Framework\Fixture; + +class JSTrackingUIFixture extends Fixture +{ + public function setUp() + { + parent::setUp(); + + self::resetPluginsInstalledConfig(); + self::updateDatabase(); + self::installAndActivatePlugins($this->getTestEnvironment()); + self::updateDatabase(); + + // for proper geolocation + LocationProvider::setCurrentProvider(Php::ID); + IPAnonymizer::deactivate(); + + Fixture::createWebsite('2012-02-02 00:00:00'); + } + + public function performSetUp($setupEnvironmentOnly = false) + { + $this->extraTestEnvVars = array( + 'loadRealTranslations' => 1, + ); + $this->extraPluginsToLoad = array( + 'ExampleTracker', + ); + + parent::performSetUp($setupEnvironmentOnly); + + $this->testEnvironment->overlayUrl = UITestFixture::getLocalTestSiteUrl(); + UITestFixture::createOverlayTestSite($idSite = 1); + + $this->testEnvironment->tokenAuth = self::getTokenAuth(); + $this->testEnvironment->pluginsToLoad = $this->extraPluginsToLoad; + $this->testEnvironment->save(); + } +}
\ No newline at end of file diff --git a/tests/PHPUnit/Fixtures/UITestFixture.php b/tests/PHPUnit/Fixtures/UITestFixture.php index 06b4a5650b..e83070eb8f 100644 --- a/tests/PHPUnit/Fixtures/UITestFixture.php +++ b/tests/PHPUnit/Fixtures/UITestFixture.php @@ -17,6 +17,7 @@ use Piwik\DataTable\Row; use Piwik\Date; use Piwik\Db; use Piwik\DbHelper; +use Piwik\Filesystem; use Piwik\FrontController; use Piwik\Option; use Piwik\Piwik; @@ -144,8 +145,8 @@ class UITestFixture extends SqlDump . " WHERE idsite = 2 AND location_latitude IS NOT NULL LIMIT 1")); $this->testEnvironment->forcedIdVisitor = $visitorIdDeterministic; - $this->testEnvironment->overlayUrl = $this->getLocalTestSiteUrl(); - $this->createOverlayTestSite(); + $this->testEnvironment->overlayUrl = self::getLocalTestSiteUrl(); + self::createOverlayTestSite(); $forcedNowTimestamp = Option::get("Tests.forcedNowTimestamp"); if ($forcedNowTimestamp == false) { @@ -237,11 +238,11 @@ class UITestFixture extends SqlDump self::checkBulkTrackingResponse($t->doBulkTrack()); } - private function createOverlayTestSite() + public static function createOverlayTestSite($idSite = 3) { $realDir = PIWIK_INCLUDE_PATH . "/tests/resources/overlay-test-site-real"; if (is_dir($realDir)) { - return; + Filesystem::unlinkRecursive($realDir, true); } $files = array('index.html', 'page-1.html', 'page-2.html', 'page-3.html', 'page-4.html', 'page-5.html', 'page-6.html'); @@ -263,11 +264,12 @@ class UITestFixture extends SqlDump $contents = file_get_contents($path); $contents = str_replace("%trackerBaseUrl%", $url, $contents); + $contents = str_replace("%idSite%", $idSite, $contents); file_put_contents($path, $contents); } } - private function getLocalTestSiteUrl() + public static function getLocalTestSiteUrl() { return self::getRootUrl() . "tests/resources/overlay-test-site-real/"; } |