Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <diosmosis@users.noreply.github.com>2019-05-16 12:50:10 +0300
committerGitHub <noreply@github.com>2019-05-16 12:50:10 +0300
commit03ca65180e488847c3faec1167b1c82ac7cc9722 (patch)
tree8d61ccbb0c246d049f074e520f93ea3456c7243d /tests/resources/install-matomo.php
parented823e9c1521a6a5aada6fc1572433845322967f (diff)
One Click Install UI test (#14049)
* Add initial fixture and install script for one click install UI test. * Move matomo-package to outside matomo dir. * Create package before getting latest stable install. * More changes to fixture. * Get test releasechannel to work in latest stable version. * Handle build archives w/ matomo folders in one click update. * Fill out one click update UI test and get to pass. * Remove useless use statement. * Try cloning from HTTPS. * Add new screenshots. * Apply pr feedback and remove CoreUpdaterCode UI test. * undo submodule change * re-add line * re-add CoreUpdaterDb png files, need to keep those. * Add cron archiving test to one click update test. * use master branch of matomo-package * Make sure node_modules is accessible in screenshot testing specs. * Fix matomo-package command. * test fixes * Use correct method. * ui test fixes * Couple more test fixes. * some more test fixes * hopefully last ui test fixes * Last fix. * real last fix * Couple more random failure fixes. * Prevent from running outside of cli mode. * More aggresive check.
Diffstat (limited to 'tests/resources/install-matomo.php')
-rw-r--r--tests/resources/install-matomo.php231
1 files changed, 231 insertions, 0 deletions
diff --git a/tests/resources/install-matomo.php b/tests/resources/install-matomo.php
new file mode 100644
index 0000000000..0bedc2b5f2
--- /dev/null
+++ b/tests/resources/install-matomo.php
@@ -0,0 +1,231 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+
+use Piwik\Access;
+use Piwik\Application\Environment;
+use Piwik\Auth\Password;
+use Piwik\Common;
+use Piwik\Container\StaticContainer;
+use Piwik\Date;
+use Piwik\Plugins\UsersManager\UsersManager;
+use Piwik\Plugins\UsersManager\API as UsersManagerAPI;
+use Piwik\Plugins\SitesManager\API as SitesManagerAPI;
+use Piwik\Site;
+use Piwik\Tracker\Cache;
+use Piwik\Config;
+use Piwik\Db;
+use Piwik\DbHelper;
+use Piwik\Option;
+use Piwik\Plugins\LanguagesManager\API as APILanguageManager;
+use Piwik\Updater;
+use Piwik\Plugins\CoreUpdater;
+
+$subdir = str_replace(DIRECTORY_SEPARATOR, '', $argv[1]);
+$dbConfig = json_decode($argv[2], $isAssoc = true);
+$host = $argv[3];
+
+define('PIWIK_DOCUMENT_ROOT', __DIR__ . '/../../' . $subdir);
+define('PIWIK_INCLUDE_PATH', PIWIK_DOCUMENT_ROOT);
+define('PIWIK_TEST_MODE', 1); // for drop database
+
+require_once PIWIK_INCLUDE_PATH . '/core/bootstrap.php';
+
+define('PIWIK_PRINT_ERROR_BACKTRACE', true);
+
+if (!Common::isPhpCliMode()) {
+ print "not available";
+ exit;
+}
+
+function createFreshDatabase($config, $name) {
+ Db::createDatabaseObject(array_merge($config, [
+ 'dbname' => null,
+ ]));
+
+ try {
+ DbHelper::dropDatabase($name);
+ } catch (\Exception $e) {
+ print $e->getMessage() . "\n" . $e->getTraceAsString() . "\n";
+ }
+
+ DbHelper::createDatabase($name);
+ DbHelper::disconnectDatabase();
+
+ print "created database $name...\n";
+}
+
+function updateDatabase() {
+ Cache::deleteTrackerCache();
+ Option::clearCache();
+
+ $updater = new Updater();
+ $componentsWithUpdateFile = $updater->getComponentUpdates();
+ if (empty($componentsWithUpdateFile)) {
+ return false;
+ }
+
+ $result = $updater->updateComponents($componentsWithUpdateFile);
+ if (!empty($result['coreError'])
+ || !empty($result['warnings'])
+ || !empty($result['errors'])
+ ) {
+ throw new \Exception("Failed to update database (errors or warnings found): " . print_r($result, true));
+ }
+
+ return $result;
+}
+
+function createSuperUser() {
+ $passwordHelper = new Password();
+
+ $login = 'superUserLogin';
+ $password = $passwordHelper->hash(UsersManager::getPasswordHash('superUserPass'));
+ $token = UsersManagerAPI::getInstance()->createTokenAuth($login);
+
+ $model = new \Piwik\Plugins\UsersManager\Model();
+ $user = $model->getUser($login);
+
+ if (!empty($user)) {
+ $token = $user['token_auth'];
+ }
+ if (empty($user)) {
+ $model->addUser($login, $password, 'hello@example.org', $login, $token, Date::now()->getDatetime());
+ } else {
+ $model->updateUser($login, $password, 'hello@example.org', $login, $token);
+ }
+
+ $setSuperUser = empty($user) || !empty($user['superuser_access']);
+ $model->setSuperUserAccess($login, $setSuperUser);
+
+ return $model->getUserByTokenAuth($token);
+}
+
+function createWebsite($dateTime)
+{
+ $siteName = 'Test Site Subdir';
+ $idSite = SitesManagerAPI::getInstance()->addSite(
+ $siteName,
+ "http://piwik.net/",
+ $ecommerce = 1,
+ $siteSearch = null, $searchKeywordParameters = null, $searchCategoryParameters = null,
+ $ips = null,
+ $excludedQueryParameters = null,
+ $timezone = null,
+ $currency = null,
+ $group = null,
+ $startDate = null,
+ $excludedUserAgents = null,
+ $keepURLFragments = null,
+ $type = null,
+ $settings = null,
+ $excludeUnknownUrls = 0
+ );
+
+ // Manually set the website creation date to a day earlier than the earliest day we record stats for
+ Db::get()->update(Common::prefixTable("site"),
+ array('ts_created' => Date::factory($dateTime)->subDay(1)->getDatetime()),
+ "idsite = $idSite"
+ );
+
+ // Clear the memory Website cache
+ Site::clearCache();
+ Cache::deleteCacheWebsiteAttributes($idSite);
+
+ return $idSite;
+}
+
+function getTokenAuth()
+{
+ $model = new \Piwik\Plugins\UsersManager\Model();
+ $user = $model->getUser('superUserLogin');
+
+ return $user['token_auth'];
+}
+
+$_SERVER['HTTP_HOST'] = $host;
+$dbConfig['dbname'] = 'latest_stable';
+
+file_put_contents(PIWIK_INCLUDE_PATH . "/config/config.ini.php", '');
+
+@mkdir(PIWIK_INCLUDE_PATH . '/tmp');
+
+$environment = new Environment($environment = null);
+$environment->init();
+
+// create database
+createFreshDatabase($dbConfig, $dbConfig['dbname']);
+
+// setup config
+$config = Config::getInstance();
+$config->database = $dbConfig;
+$config->General['trusted_hosts'] = [
+ $host,
+ 'localhost',
+ '127.0.0.1',
+];
+$config->Cache['backend'] = 'file';
+$config->forceSave();
+
+print "setup config\n";
+
+// setup db tables
+Db::createDatabaseObject();
+DbHelper::createTables();
+
+print "setup tables\n";
+
+// setup plugins
+$pluginsManager = \Piwik\Plugin\Manager::getInstance();
+$pluginsManager->loadActivatedPlugins();
+
+$pluginsManager->installLoadedPlugins();
+foreach($pluginsManager->getLoadedPlugins() as $plugin) {
+ $name = $plugin->getPluginName();
+ if (!$pluginsManager->isPluginActivated($name)) {
+ $pluginsManager->activatePlugin($name);
+ }
+}
+
+$pluginsManager->loadPluginTranslations();
+
+print "setup plugins\n";
+
+// update (required after loading plugins first time)
+$updated = updateDatabase();
+if (empty($updated)) {
+ echo "did not update\n";
+} else {
+ echo "updated db\n";
+}
+
+// create root user
+Access::getInstance()->setSuperUserAccess();
+createSuperUser();
+APILanguageManager::getInstance()->setLanguageForUser('superUserLogin', 'en');
+
+print "created root user\n";
+
+// create website
+createWebsite('2017-01-01 00:00:00');
+
+print "created website\n";
+
+// copy custom release channel
+copy(PIWIK_INCLUDE_PATH . '/../tests/PHPUnit/Fixtures/LatestStableInstall/GitCommitReleaseChannel.php',
+ PIWIK_INCLUDE_PATH . '/plugins/CoreUpdater/ReleaseChannel/GitCommitReleaseChannel.php');
+
+$settings = StaticContainer::get(CoreUpdater\SystemSettings::class);
+$settings->releaseChannel->setValue('git_commit');
+$settings->releaseChannel->save();
+
+print "set release channel\n";
+
+// print token auth (on last line so it can be easily parsed)
+$tokenAuth = getTokenAuth();
+print "$tokenAuth"; \ No newline at end of file