diff options
author | Matthieu Aubry <matt@piwik.org> | 2015-11-05 04:52:15 +0300 |
---|---|---|
committer | Matthieu Aubry <matt@piwik.org> | 2015-11-05 04:52:15 +0300 |
commit | 98149361910dadb1d47e1d37ac52fd419eb05207 (patch) | |
tree | a2856bdccb58838ecacb3a0388cfb80d478917ca | |
parent | 4aeb7b2acb9778c8bbab89af6759c50612ffd6dc (diff) | |
parent | cddf7e4bc4d1dcba44a64397236915248b16ccc9 (diff) |
Merge pull request #9164 from piwik/mysql_in_tracker
Use MySQL instead of SQLite in tracker tests
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | CHANGELOG.md | 6 | ||||
-rw-r--r-- | js/README.md | 3 | ||||
-rw-r--r-- | tests/README.md | 2 | ||||
-rw-r--r-- | tests/javascript/README.md | 7 | ||||
-rw-r--r-- | tests/javascript/SQLite.php | 70 | ||||
-rw-r--r-- | tests/javascript/index.php | 22 | ||||
-rw-r--r-- | tests/javascript/piwik.php | 72 |
9 files changed, 60 insertions, 125 deletions
diff --git a/.gitignore b/.gitignore index bbc7bd85e0..a1cd27d0cd 100644 --- a/.gitignore +++ b/.gitignore @@ -40,7 +40,6 @@ php_errors.log /.project /.settings /*.buildpath -/tests/javascript/enable_sqlite /tests/javascript/unittest.dbf /tests/javascript/unittest2.dbf /tests/lib/geoip-files/*.dat* diff --git a/.travis.yml b/.travis.yml index d7440d7fb9..420cf43678 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ env: - TEST_SUITE=IntegrationTests MYSQL_ADAPTER=PDO_MYSQL - TEST_SUITE=UnitTests MYSQL_ADAPTER=PDO_MYSQL # Javascript tests - - TEST_SUITE=JavascriptTests MYSQL_ADAPTER=PDO_MYSQL SKIP_COMPOSER_INSTALL=1 + - TEST_SUITE=JavascriptTests MYSQL_ADAPTER=PDO_MYSQL - TEST_SUITE=AngularJSTests MYSQL_ADAPTER=PDO_MYSQL SKIP_COMPOSER_INSTALL=1 # All tests after another - TEST_SUITE=AllTests MYSQL_ADAPTER=PDO_MYSQL diff --git a/CHANGELOG.md b/CHANGELOG.md index 08051f1a2f..2fce96ad8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ This is a changelog for Piwik platform developers. All changes for our HTTP API's, Plugins, Themes, etc will be listed here. +## Piwik 2.15.1 + +### Internal change + * JavaScript Tracker tests no longer require `SQLite`. The existing MySQL configuration for tests is used now. In order to run the tests make sure Piwik is installed and `[database_tests]` is configured in `config/config.ini.php`. + + ## Piwik 2.15.0 ### New commands diff --git a/js/README.md b/js/README.md index 06c7cf0ae3..d24f8d8c9d 100644 --- a/js/README.md +++ b/js/README.md @@ -48,9 +48,6 @@ The js/ folder contains: * In a production environment, the tests/javascript folder is not used and can be removed (if present). - Note: if the file "js/tests/enable_sqlite" exists, additional unit tests - (requires the sqlite extension) are enabled. - * We use /*! to include Piwik's license header in the minified source. Read Stallman's "The JavaScript Trap" for more information. diff --git a/tests/README.md b/tests/README.md index aaa18d6d34..49a4882f01 100644 --- a/tests/README.md +++ b/tests/README.md @@ -31,7 +31,7 @@ To execute the tests: 1. To install PHPUnit, run `php composer.phar install --dev` in the Piwik root directory. -2. Ensure the `[database_tests]` section in `piwik/config/config.php.ini` is set up correctly, +2. Ensure the `[database_tests]` section in `piwik/config/config.ini.php` is set up correctly, i.e. with the correct password to prevent the following error: `SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO)` diff --git a/tests/javascript/README.md b/tests/javascript/README.md index 5852407301..9e34fdff07 100644 --- a/tests/javascript/README.md +++ b/tests/javascript/README.md @@ -1,10 +1,9 @@ # JavaScript Tests ## Setup -Javascript integration tests require sqlite: - * ensure this PHP extension is enabled to make sure you run all tests apt-get install php5-sqlite - * Then please create an empty file `enable_sqlite` in `tests/javascript/enable_sqlite` - * Re-execute the tests and make sure the "missing sqlite" error message does not display +Javascript integration tests require an installed Piwik and ensure the `[database_tests]` section in `piwik/config/config.ini.php` is set up correctly, i.e. with th correct password to prevent the following error: `SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO)` + +The tests will create a database named `tracker_tests` and store several tracking requests in it. ## Execute diff --git a/tests/javascript/SQLite.php b/tests/javascript/SQLite.php deleted file mode 100644 index 5b4a3b3343..0000000000 --- a/tests/javascript/SQLite.php +++ /dev/null @@ -1,70 +0,0 @@ -<?php -/*! - * Piwik - free/libre analytics platform - * - * SQLite shim - * - * @link http://piwik.org - * @license http://www.opensource.org/licenses/bsd-license.php Simplified BSD - */ -if (class_exists('SQLite3')) -{ - class SQLite extends SQLite3 - { - public function __construct($filename) - { - parent::__construct($filename); - - // for backward compatibility - if (version_compare(PHP_VERSION, '5.3.3') > 0) - { - $this->busyTimeout(60000); - } - } - - public function query_array($sql) - { - $result = parent::query($sql); - - $rows = array(); - while ($res = $result->fetchArray(SQLITE3_ASSOC)) - { - $rows[] = $res; - } - return $rows; - } - } -} -else if (extension_loaded('sqlite')) -{ - class SQLite - { - private $handle; - - public function __construct($filename) - { - $this->handle = sqlite_open($filename); - } - - public function query_array($sql) - { - return sqlite_array_query($this->handle, $sql); - } - - public function exec($sql) - { - return sqlite_exec($this->handle, $sql); - } - - public function changes() - { - return sqlite_changes($this->handle); - } - - public function close() - { - sqlite_close($this->handle); - unset($this->handle); - } - } -} diff --git a/tests/javascript/index.php b/tests/javascript/index.php index 702233d622..0cfd028493 100644 --- a/tests/javascript/index.php +++ b/tests/javascript/index.php @@ -5,7 +5,14 @@ <meta charset="utf-8"> <title>piwik.js: Unit Tests</title> <?php -require_once(dirname(__FILE__).'/SQLite.php'); +$root = dirname(__FILE__) . '/../..'; + +try { + $mysql = include_once $root . "/tests/PHPUnit/bootstrap.php"; +} catch (Exception $e) { + echo 'alert("' . $e->getMessage() . '")'; + $mysql = false; +} if(file_exists("stub.tpl")) { echo file_get_contents("stub.tpl"); @@ -22,17 +29,8 @@ function getHeartbeatToken() { return "<?php $token = md5(uniqid(mt_rand(), true)); echo $token; ?>"; } <?php -$sqlite = false; -if (file_exists("enable_sqlite")) { - if (class_exists('SQLite')) { - $sqlite = true; - } -} -if(!$sqlite) { - echo 'alert("WARNING: Javascript integration tests require sqlite, \n1) ensure this PHP extension is enabled to make sure you run all tests \napt-get install php5-sqlite \n2) Then please create an empty file enable_sqlite in tests/javascript/enable_sqlite \n3) Re-execute this page and make sure this popup does not display ");'; -} -if ($sqlite) { +if ($mysql) { echo ' var _paq = _paq || []; @@ -2710,7 +2708,7 @@ function PiwikTest() { }); <?php -if ($sqlite) { +if ($mysql) { ?> module("request", { diff --git a/tests/javascript/piwik.php b/tests/javascript/piwik.php index 73fbedb232..0c38317175 100644 --- a/tests/javascript/piwik.php +++ b/tests/javascript/piwik.php @@ -1,7 +1,31 @@ <?php // piwik.php test harness -require_once(dirname(__FILE__).'/SQLite.php'); +if (!defined('PIWIK_DOCUMENT_ROOT')) { + define('PIWIK_DOCUMENT_ROOT', dirname(__FILE__) . '/../..'); +} + +define('PIWIK_INCLUDE_PATH', PIWIK_DOCUMENT_ROOT); + + +require_once PIWIK_INCLUDE_PATH . '/core/bootstrap.php'; + +$environment = new \Piwik\Application\Environment(null); +$environment->init(); +$dbConfig = Piwik\Config::getInstance()->database_tests; +$dbConfig['dbname'] = 'tracker_tests'; + +try { + Piwik\Db::createDatabaseObject($dbConfig); +} catch (Exception $e) { + $dbInfosConnectOnly = $dbConfig; + $dbInfosConnectOnly['dbname'] = null; + Piwik\Db::createDatabaseObject($dbInfosConnectOnly); + Piwik\DbHelper::createDatabase($dbConfig['dbname']); + Piwik\Db::createDatabaseObject($dbConfig); +} + +$db = Piwik\Db::get(); function sendWebBug() { $trans_gif_64 = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="; @@ -14,25 +38,14 @@ function isPost() return $_SERVER['REQUEST_METHOD'] == 'POST'; } -if (!file_exists("enable_sqlite")) { +if (!Piwik\Db::hasDatabaseObject()) { sendWebBug(); exit; } -if (!class_exists('SQLite')) { - sendWebBug(); - exit; -} - -$sqlite = new SQLite( 'unittest2.dbf' ); -if (!$sqlite) { - header("HTTP/1.0 500 Internal Server Error"); - exit; -} - -function getNextRequestId($sqlite, $token) +function getNextRequestId($db, $token) { - $requests = $sqlite->query_array("SELECT uri FROM requests WHERE token = \"$token\""); + $requests = $db->fetchAll("SELECT uri FROM requests WHERE token = \"$token\""); if (empty($requests)) { return 1; @@ -41,17 +54,14 @@ function getNextRequestId($sqlite, $token) return count($requests) + 1; } -if (filesize(dirname(__FILE__).'/unittest2.dbf') == 0) -{ - try { - $query = @$sqlite->exec( 'CREATE TABLE requests (requestid TEXT, token TEXT, ip TEXT, ts TEXT, uri TEXT, referer TEXT, ua TEXT)' ); - } catch (Exception $e) { - header("HTTP/1.0 500 Internal Server Error"); - exit; - } +try { + $db->query( 'CREATE TABLE IF NOT EXISTS `requests` (requestid TEXT, token TEXT, ip TEXT, ts TEXT, uri TEXT, referer TEXT, ua TEXT) DEFAULT CHARSET=utf8' ); +} catch (Exception $e) { + header("HTTP/1.0 500 Internal Server Error"); + exit; } -function logRequest($sqlite, $uri, $data) { +function logRequest($db, $uri, $data) { $ip = $_SERVER['REMOTE_ADDR']; $ts = $_SERVER['REQUEST_TIME']; @@ -62,9 +72,9 @@ function logRequest($sqlite, $uri, $data) { $token = isset($data['token']) ? $data['token'] : ''; - $id = getNextRequestId($sqlite, $token); + $id = getNextRequestId($db, $token); - $query = $sqlite->exec("INSERT INTO requests (requestid, token, ip, ts, uri, referer, ua) VALUES (\"$id\", \"$token\", \"$ip\", \"$ts\", \"$uri\", \"$referrer\", \"$ua\")"); + $query = $db->query("INSERT INTO requests (requestid, token, ip, ts, uri, referer, ua) VALUES (\"$id\", \"$token\", \"$ip\", \"$ts\", \"$uri\", \"$referrer\", \"$ua\")"); return $query; } @@ -75,8 +85,7 @@ if (isset($_GET['requests'])) { echo "<html><head><title>$token</title></head><body>\n"; -// $result = $sqlite->query_array("SELECT uri FROM requests"); - $result = @$sqlite->query_array("SELECT uri FROM requests WHERE token = \"$token\" AND ua = \"$ua\" ORDER BY ts ASC, requestid ASC"); + $result = @$db->fetchAll("SELECT uri FROM requests WHERE token = \"$token\" AND ua = \"$ua\" ORDER BY ts ASC, requestid ASC"); if ($result !== false) { $nofRows = count($result); echo "<span>$nofRows</span>\n"; @@ -107,7 +116,7 @@ if (isset($_GET['requests'])) { $data = array('token' => $matches[1]); } - $query = $query && logRequest($sqlite, $uri . $request, $data); + $query = $query && logRequest($db, $uri . $request, $data); } } else { @@ -115,16 +124,13 @@ if (isset($_GET['requests'])) { $uri .= '?' . file_get_contents('php://input'); } - $query = logRequest($sqlite, $uri, $data); + $query = logRequest($db, $uri, $data); } if (!$query) { header("HTTP/1.0 500 Internal Server Error"); } else { -// echo 'Number of rows modified: ', $sqlite->changes(); sendWebBug(); } } } - -$sqlite->close(); |