From 73010596f01b9660899267305fe0cf5064428753 Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Thu, 29 Nov 2018 20:22:15 +1300 Subject: Make matomo.js and matomo.php the default Tracking API endpoints used (#13596) * Make matomo.js and matomo.php the default Tracking API endpoints used * few fixes * fix few tests * update matomo php tracker in composer * make sure to record install version * do not overwrite ever install version * trying to fix test * more tweaks and fix tests * prefer matomo endpoint in the ui, fix some tests * file was still needed * apply review feedback * fix ui tests --- tests/PHPUnit/Fixtures/ManySitesImportedLogs.php | 2 +- tests/PHPUnit/Framework/Fixture.php | 4 +- .../Framework/TestCase/IntegrationTestCase.php | 3 ++ tests/PHPUnit/Integration/DbHelperTest.php | 48 ++++++++++++++++++++++ tests/PHPUnit/Integration/HttpTest.php | 6 +-- tests/PHPUnit/Integration/JsProxyTest.php | 6 +-- tests/PHPUnit/Integration/ReleaseCheckListTest.php | 9 ++++ .../Tracker/TrackerCodeGeneratorTest.php | 30 +++++++------- tests/PHPUnit/System/EnvironmentValidationTest.php | 10 ++--- tests/PHPUnit/System/TrackerTest.php | 4 +- ...etadata_year__SitesManager.getJavascriptTag.xml | 4 +- tests/PHPUnit/Unit/DeprecatedMethodsTest.php | 1 + tests/PHPUnit/proxy/matomo.php | 11 +++++ tests/PHPUnit/proxy/piwik.php | 2 +- 14 files changed, 107 insertions(+), 33 deletions(-) create mode 100644 tests/PHPUnit/proxy/matomo.php (limited to 'tests/PHPUnit') diff --git a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php index 0a9bf260de..c07967c563 100644 --- a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php +++ b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php @@ -266,7 +266,7 @@ class ManySitesImportedLogs extends Fixture } /** - * Logs a couple visit using log entries that are tracking requests to a piwik.php file. + * Logs a couple visit using log entries that are tracking requests to a matomo.php file. * Adds two visits to idSite=1 and two to non-existant sites. * * @param array $additonalOptions diff --git a/tests/PHPUnit/Framework/Fixture.php b/tests/PHPUnit/Framework/Fixture.php index 701f5a1f70..45f200bac5 100644 --- a/tests/PHPUnit/Framework/Fixture.php +++ b/tests/PHPUnit/Framework/Fixture.php @@ -247,6 +247,7 @@ class Fixture extends \PHPUnit_Framework_Assert Db::get()->query("SET wait_timeout=28800;"); DbHelper::createTables(); + DbHelper::recordInstallVersion(); self::getPluginManager()->unloadPlugins(); @@ -410,6 +411,7 @@ class Fixture extends \PHPUnit_Framework_Assert public static function loadAllPlugins(TestingEnvironmentVariables $testEnvironment = null, $testCaseClass = false, $extraPluginsToLoad = array()) { DbHelper::createTables(); + DbHelper::recordInstallVersion(); self::getPluginManager()->loadActivatedPlugins(); } @@ -575,7 +577,7 @@ class Fixture extends \PHPUnit_Framework_Assert */ public static function getTrackerUrl() { - return self::getTestRootUrl() . 'piwik.php'; + return self::getTestRootUrl() . 'matomo.php'; } /** diff --git a/tests/PHPUnit/Framework/TestCase/IntegrationTestCase.php b/tests/PHPUnit/Framework/TestCase/IntegrationTestCase.php index bf4e7f4c19..9e8b2abe07 100644 --- a/tests/PHPUnit/Framework/TestCase/IntegrationTestCase.php +++ b/tests/PHPUnit/Framework/TestCase/IntegrationTestCase.php @@ -11,7 +11,9 @@ namespace Piwik\Tests\Framework\TestCase; use Piwik\Access; use Piwik\Config; use Piwik\Db; +use Piwik\DbHelper; use Piwik\Menu\MenuAbstract; +use Piwik\Option; use Piwik\Tests\Framework\Fixture; use Piwik\Cache as PiwikCache; use Piwik\Tests\Framework\TestingEnvironmentVariables; @@ -91,6 +93,7 @@ abstract class IntegrationTestCase extends SystemTestCase PiwikCache::getEagerCache()->flushAll(); PiwikCache::getTransientCache()->flushAll(); MenuAbstract::clearMenus(); + Option::clearCache(); } /** diff --git a/tests/PHPUnit/Integration/DbHelperTest.php b/tests/PHPUnit/Integration/DbHelperTest.php index f8268f451c..5b88015eab 100644 --- a/tests/PHPUnit/Integration/DbHelperTest.php +++ b/tests/PHPUnit/Integration/DbHelperTest.php @@ -10,7 +10,9 @@ namespace Piwik\Tests\Integration; use Piwik\Db; use Piwik\DbHelper; +use Piwik\Option; use Piwik\Tests\Framework\TestCase\IntegrationTestCase; +use Piwik\Version; class DbHelperTest extends IntegrationTestCase { @@ -22,6 +24,52 @@ class DbHelperTest extends IntegrationTestCase DbHelper::dropDatabase('testdb'); } + public function test_getInstallVersion_isCurrentVersion() + { + $this->assertSame(Version::VERSION, DbHelper::getInstallVersion()); + } + + public function test_recordInstallVersion_setsCurrentVersion() + { + Option::delete(Db\Schema\Mysql::OPTION_NAME_MATOMO_INSTALL_VERSION); + $this->assertNull(DbHelper::getInstallVersion()); + + DbHelper::recordInstallVersion(); + $this->assertSame(Version::VERSION, DbHelper::getInstallVersion()); + } + + public function test_recordInstallVersion_doesNotOverwritePreviouslySetVersion() + { + $this->setInstallVersion('2.1.0'); + DbHelper::recordInstallVersion(); + DbHelper::recordInstallVersion(); + DbHelper::recordInstallVersion(); + $this->assertSame('2.1.0', DbHelper::getInstallVersion()); + } + + public function test_wasMatomoInstalledBeforeVersion_sameVersion() + { + $this->setInstallVersion('2.1.0'); + $this->assertFalse(DbHelper::wasMatomoInstalledBeforeVersion('2.1.0')); + } + + public function test_wasMatomoInstalledBeforeVersion_whenUsedNewerVersion() + { + $this->setInstallVersion('2.1.0'); + $this->assertFalse(DbHelper::wasMatomoInstalledBeforeVersion('2.0.0')); + } + + public function test_wasMatomoInstalledBeforeVersion_whenWasInstalledBeforeThatVersion() + { + $this->setInstallVersion('2.1.0'); + $this->assertTrue(DbHelper::wasMatomoInstalledBeforeVersion('2.2.0')); + } + + private function setInstallVersion($version) + { + Option::set(Db\Schema\Mysql::OPTION_NAME_MATOMO_INSTALL_VERSION, $version); + } + public function test_createDatabase_escapesInputProperly() { $dbName = 'newdb`; create database anotherdb;`'; diff --git a/tests/PHPUnit/Integration/HttpTest.php b/tests/PHPUnit/Integration/HttpTest.php index 1e9a734dc7..d7831f5021 100644 --- a/tests/PHPUnit/Integration/HttpTest.php +++ b/tests/PHPUnit/Integration/HttpTest.php @@ -35,8 +35,8 @@ class HttpTest extends \PHPUnit_Framework_TestCase public function testFetchRemoteFile($method) { $this->assertNotNull(Http::getTransportMethod()); - $result = Http::sendHttpRequestBy($method, Fixture::getRootUrl() . 'piwik.js', 30); - $this->assertTrue(strpos($result, 'Piwik') !== false); + $result = Http::sendHttpRequestBy($method, Fixture::getRootUrl() . 'matomo.js', 30); + $this->assertTrue(strpos($result, 'Matomo') !== false); } public function testFetchApiLatestVersion() @@ -73,7 +73,7 @@ class HttpTest extends \PHPUnit_Framework_TestCase $result = Http::sendHttpRequestBy( $method, - Fixture::getRootUrl() . '/piwik.js', + Fixture::getRootUrl() . '/matomo.js', 30, $userAgent = null, $destinationPath = null, diff --git a/tests/PHPUnit/Integration/JsProxyTest.php b/tests/PHPUnit/Integration/JsProxyTest.php index 17e2430401..c1ff170166 100644 --- a/tests/PHPUnit/Integration/JsProxyTest.php +++ b/tests/PHPUnit/Integration/JsProxyTest.php @@ -22,7 +22,7 @@ class JsProxyTest extends IntegrationTestCase Fixture::createWebsite('2014-01-01 02:03:04'); } - public function testPiwikJs() + public function testMatomoJs() { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getStaticSrvUrl() . '/js/'); @@ -33,7 +33,7 @@ class JsProxyTest extends IntegrationTestCase $this->assertEquals(200, $responseInfo["http_code"], 'Ok response'); - $piwik_js = file_get_contents(PIWIK_PATH_TEST_TO_ROOT . '/piwik.js'); + $piwik_js = file_get_contents(PIWIK_PATH_TEST_TO_ROOT . '/matomo.js'); $this->assertEquals($piwik_js, $fullResponse, 'script content'); } @@ -48,7 +48,7 @@ class JsProxyTest extends IntegrationTestCase $this->assertEquals(200, $responseInfo["http_code"], 'Ok response'); - $piwikJs = file_get_contents(PIWIK_PATH_TEST_TO_ROOT . '/piwik.js'); + $piwikJs = file_get_contents(PIWIK_PATH_TEST_TO_ROOT . '/matomo.js'); $piwikNoCommentJs = substr($piwikJs, strpos($piwikJs, "*/\n") + 3); $this->assertEquals($piwikNoCommentJs, trim($fullResponse), 'script content (if comment shows, $byteStart value in /js/tracker.php)'); } diff --git a/tests/PHPUnit/Integration/ReleaseCheckListTest.php b/tests/PHPUnit/Integration/ReleaseCheckListTest.php index bce8b56c24..0fb62a64c5 100644 --- a/tests/PHPUnit/Integration/ReleaseCheckListTest.php +++ b/tests/PHPUnit/Integration/ReleaseCheckListTest.php @@ -492,6 +492,15 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase ); } + public function test_piwikJs_SameAsMatomoJs() + { + $this->assertFileEquals( + PIWIK_DOCUMENT_ROOT . '/matomo.js', + PIWIK_DOCUMENT_ROOT . '/piwik.js', + '/piwik.js does not match /matomo.js, please re-generate the minified files using instructions in /js/README' + ); + } + public function testTmpDirectoryContainsGitKeep() { $this->assertFileExists(PIWIK_DOCUMENT_ROOT . '/tmp/.gitkeep'); diff --git a/tests/PHPUnit/Integration/Tracker/TrackerCodeGeneratorTest.php b/tests/PHPUnit/Integration/Tracker/TrackerCodeGeneratorTest.php index 3827303374..2e9ee543b3 100644 --- a/tests/PHPUnit/Integration/Tracker/TrackerCodeGeneratorTest.php +++ b/tests/PHPUnit/Integration/Tracker/TrackerCodeGeneratorTest.php @@ -57,13 +57,13 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase _paq.push(['enableLinkTracking']); (function() { var u="//piwik-server/piwik/"; - _paq.push(['setTrackerUrl', u+'piwik.php']); + _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; - g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); + g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script> -<noscript><p><img src="//piwik-server/piwik/piwik.php?idsite=1&amp;rec=1" style="border:0;" alt="" /></p></noscript> +<noscript><p><img src="//piwik-server/piwik/matomo.php?idsite=1&amp;rec=1" style="border:0;" alt="" /></p></noscript> <!-- End Matomo Code --> "; @@ -84,10 +84,10 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase _paq.push(['enableLinkTracking']); (function() { var u="//localhost/piwik/"; - _paq.push(['setTrackerUrl', u+'piwik.php']); + _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; - g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); + g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script> <!-- End Matomo Code --> @@ -131,10 +131,10 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase _paq.push(['enableLinkTracking']); (function() { var u="https://localhost/piwik/"; - _paq.push(['setTrackerUrl', u+'piwik.php']); + _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; - g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); + g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script> <!-- End Matomo Code --> @@ -179,10 +179,10 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase (function() { var u="//localhost/piwik/"; _paq.push(['setAPIUrl', 'http://localhost/statistics']); - _paq.push(['setTrackerUrl', u+'piwik.php']); + _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; - g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); + g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script> <!-- End Matomo Code --> @@ -214,12 +214,12 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase _paq.push(['enableLinkTracking']); (function() { var u="//localhost/piwik/"; - _paq.push(['setTrackerUrl', u+'piwik.php']); + _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); })(); </script> -<script type='text/javascript' src="//localhost/piwik/piwik.js"></script> +<script type='text/javascript' src="//localhost/piwik/matomo.js"></script> <!-- End Matomo Code --> "; @@ -257,10 +257,10 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase _paq.push([\'enableLinkTracking\']); (function() { var u="//abc"def/"; - _paq.push([\'setTrackerUrl\', u+\'piwik.php\']); + _paq.push([\'setTrackerUrl\', u+\'matomo.php\']); _paq.push([\'setSiteId\', \'1\']); var d=document, g=d.createElement(\'script\'), s=d.getElementsByTagName(\'script\')[0]; - g.type=\'text/javascript\'; g.async=true; g.defer=true; g.src=u+\'piwik.js\'; s.parentNode.insertBefore(g,s); + g.type=\'text/javascript\'; g.async=true; g.defer=true; g.src=u+\'matomo.js\'; s.parentNode.insertBefore(g,s); })(); </script> <!-- End Matomo Code --> @@ -284,10 +284,10 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase _paq.push([\'enableLinkTracking\']); (function() { var u="https://localhost/piwik/"; - _paq.push([\'setTrackerUrl\', u+\'piwik.php\']); + _paq.push([\'setTrackerUrl\', u+\'matomo.php\']); _paq.push([\'setSiteId\', \'1\']); var d=document, g=d.createElement(\'script\'), s=d.getElementsByTagName(\'script\')[0]; - g.type=\'text/javascript\'; g.async=true; g.defer=true; g.src=u+\'piwik.js\'; s.parentNode.insertBefore(g,s); + g.type=\'text/javascript\'; g.async=true; g.defer=true; g.src=u+\'matomo.js\'; s.parentNode.insertBefore(g,s); })(); </script> <!-- End Matomo Code --> diff --git a/tests/PHPUnit/System/EnvironmentValidationTest.php b/tests/PHPUnit/System/EnvironmentValidationTest.php index 5c47714f4e..18aa3ab4ad 100644 --- a/tests/PHPUnit/System/EnvironmentValidationTest.php +++ b/tests/PHPUnit/System/EnvironmentValidationTest.php @@ -129,7 +129,7 @@ class EnvironmentValidationTest extends SystemTestCase private function assertOutputContainsBadConfigFileError($output) { - $this->assertRegExp("/Unable to read INI file \\{.*\\/piwik.php\\}:/", $output); + $this->assertRegExp("/Unable to read INI file \\{.*\\/matomo.php\\}:/", $output); $this->assertRegExp("/Your host may have disabled parse_ini_file\\(\\)/", $output); } @@ -158,11 +158,11 @@ class EnvironmentValidationTest extends SystemTestCase $testingEnvironment = new \Piwik\Tests\Framework\TestingEnvironmentVariables(); if ($fileName == 'global.ini.php') { - $testingEnvironment->configFileGlobal = PIWIK_INCLUDE_PATH . '/piwik.php'; + $testingEnvironment->configFileGlobal = PIWIK_INCLUDE_PATH . '/matomo.php'; } else if ($fileName == 'common.config.ini.php') { - $testingEnvironment->configFileCommon = PIWIK_INCLUDE_PATH . '/piwik.php'; + $testingEnvironment->configFileCommon = PIWIK_INCLUDE_PATH . '/matomo.php'; } else { - $testingEnvironment->configFileLocal = PIWIK_INCLUDE_PATH . '/piwik.php'; + $testingEnvironment->configFileLocal = PIWIK_INCLUDE_PATH . '/matomo.php'; } $testingEnvironment->save(); @@ -192,7 +192,7 @@ class EnvironmentValidationTest extends SystemTestCase private function sendRequestToTracker() { - list($response, $info) = $this->curl(Fixture::getRootUrl() . 'tests/PHPUnit/proxy/piwik.php?idsite=1&rec=1&action_name=something'); + list($response, $info) = $this->curl(Fixture::getRootUrl() . 'tests/PHPUnit/proxy/matomo.php?idsite=1&rec=1&action_name=something'); // Check Tracker requests return 200 $this->assertEquals(200, $info["http_code"], 'Ok response'); diff --git a/tests/PHPUnit/System/TrackerTest.php b/tests/PHPUnit/System/TrackerTest.php index 7f43afbe2f..cc627d2cbf 100644 --- a/tests/PHPUnit/System/TrackerTest.php +++ b/tests/PHPUnit/System/TrackerTest.php @@ -224,7 +224,7 @@ class TrackerTest extends IntegrationTestCase protected function issueBulkTrackingRequest($token_auth, $expectTrackingToSucceed) { - $piwikHost = Fixture::getRootUrl() . 'tests/PHPUnit/proxy/piwik.php'; + $piwikHost = Fixture::getRootUrl() . 'tests/PHPUnit/proxy/matomo.php'; $command = 'curl -s -X POST -d \'{"requests":["?idsite=1&url=http://example.org&action_name=Test bulk log Pageview&rec=1","?idsite=1&url=http://example.net/test.htm&action_name=Another bulk page view&rec=1"],"token_auth":"' . $token_auth . '"}\' ' . $piwikHost; @@ -251,7 +251,7 @@ class TrackerTest extends IntegrationTestCase } $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, Fixture::getRootUrl() . 'tests/PHPUnit/proxy/piwik.php' . $url); + curl_setopt($ch, CURLOPT_URL, Fixture::getRootUrl() . 'tests/PHPUnit/proxy/matomo.php' . $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); diff --git a/tests/PHPUnit/System/expected/test_apiGetReportMetadata_year__SitesManager.getJavascriptTag.xml b/tests/PHPUnit/System/expected/test_apiGetReportMetadata_year__SitesManager.getJavascriptTag.xml index 2c0a7d1cf9..17afa1ddc3 100644 --- a/tests/PHPUnit/System/expected/test_apiGetReportMetadata_year__SitesManager.getJavascriptTag.xml +++ b/tests/PHPUnit/System/expected/test_apiGetReportMetadata_year__SitesManager.getJavascriptTag.xml @@ -7,10 +7,10 @@ _paq.push(['enableLinkTracking']); (function() { var u="//example.org/piwik/"; - _paq.push(['setTrackerUrl', u+'piwik.php']); + _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; - g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); + g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script> <!-- End Matomo Code --> diff --git a/tests/PHPUnit/Unit/DeprecatedMethodsTest.php b/tests/PHPUnit/Unit/DeprecatedMethodsTest.php index a0cd9905f0..ff490fe6ab 100644 --- a/tests/PHPUnit/Unit/DeprecatedMethodsTest.php +++ b/tests/PHPUnit/Unit/DeprecatedMethodsTest.php @@ -84,6 +84,7 @@ class DeprecatedMethodsTest extends \PHPUnit_Framework_TestCase // THIS IS A REMINDER FOR PIWIK 4: We need to rename getColumnType() to getDbColumnType() and $columnType to $dbColumnType $this->assertDeprecatedMethodIsRemovedInPiwik4('Piwik\Columns\Dimension', 'getType'); + $this->assertDeprecatedMethodIsRemovedInPiwik4('Piwik\SettingsPiwik', 'isPiwikInstalled'); } diff --git a/tests/PHPUnit/proxy/matomo.php b/tests/PHPUnit/proxy/matomo.php new file mode 100644 index 0000000000..9a425e7d66 --- /dev/null +++ b/tests/PHPUnit/proxy/matomo.php @@ -0,0 +1,11 @@ +getMessage() . "\n" . $ex->getTraceAsString() . "\n"; } -- cgit v1.2.3