diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2019-05-16 12:50:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-16 12:50:10 +0300 |
commit | 03ca65180e488847c3faec1167b1c82ac7cc9722 (patch) | |
tree | 8d61ccbb0c246d049f074e520f93ea3456c7243d /tests/PHPUnit/Fixtures | |
parent | ed823e9c1521a6a5aada6fc1572433845322967f (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/PHPUnit/Fixtures')
-rw-r--r-- | tests/PHPUnit/Fixtures/LatestStableInstall.php | 172 | ||||
-rw-r--r-- | tests/PHPUnit/Fixtures/LatestStableInstall/GitCommitReleaseChannel.php | 30 |
2 files changed, 202 insertions, 0 deletions
diff --git a/tests/PHPUnit/Fixtures/LatestStableInstall.php b/tests/PHPUnit/Fixtures/LatestStableInstall.php new file mode 100644 index 0000000000..d9ff051fb9 --- /dev/null +++ b/tests/PHPUnit/Fixtures/LatestStableInstall.php @@ -0,0 +1,172 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ + +namespace Piwik\Tests\Fixtures; + +use Piwik\Config; +use Piwik\Filesystem; +use Piwik\Http; +use Piwik\Plugins\CoreUpdater\ReleaseChannel\LatestStable; +use Piwik\Tests\Framework\Fixture; +use Piwik\Unzip; + +class LatestStableInstall extends Fixture +{ + const DOWNLOAD_TIMEOUT = 900; + + /** + * @var string + */ + private $subdirToInstall; + + public function __construct($subdirToInstall = 'latestStableInstall') + { + $this->subdirToInstall = $subdirToInstall; + } + + public function setUp() + { + $this->removeLatestStableInstall(); + + // create new package from git contents + $this->generateMatomoPackageFromGit(); + + // install latest stable + $this->downloadAndUnzipLatestStable(); + $tokenAuth = $this->installSubdirectoryInstall(); + $this->verifyInstall($tokenAuth); + } + + private function removeLatestStableInstall() + { + $installSubdirectory = $this->getInstallSubdirectoryPath(); + Filesystem::mkdir($installSubdirectory); + + if (file_exists($installSubdirectory)) { + Filesystem::unlinkRecursive($installSubdirectory, true); + } + + $latestStableZip = $this->getArchiveDestPath(); + if (file_exists($latestStableZip)) { + unlink($latestStableZip); + } + } + + private function downloadAndUnzipLatestStable() + { + $latestStableChannel = new LatestStable(); + $url = 'http' . $latestStableChannel->getDownloadUrlWithoutScheme(null); + + $archiveFile = $this->getArchiveDestPath(); + Http::fetchRemoteFile($url, $archiveFile, 0, self::DOWNLOAD_TIMEOUT); + + $installSubdirectory = $this->getInstallSubdirectoryPath(); + Filesystem::mkdir($installSubdirectory); + + $archive = Unzip::factory('PclZip', $archiveFile); + $archiveFiles = $archive->extract($installSubdirectory); + + if (0 == $archiveFiles + || 0 == count($archiveFiles) + ) { + throw new \Exception("Failed to extract matomo build ZIP archive."); + } + + shell_exec('mv "' . $installSubdirectory . '"/piwik/* "' . $installSubdirectory . '"'); + } + + private function installSubdirectoryInstall() + { + $installScript = PIWIK_INCLUDE_PATH . '/tests/resources/install-matomo.php'; + + $host = parse_url(Fixture::getRootUrl(), PHP_URL_HOST); + $port = parse_url(Fixture::getRootUrl(), PHP_URL_PORT); + if (!empty($port)) { + $host .= ':' . $port; + } + + $command = "php " . $installScript . " " . $this->subdirToInstall . ' "' . addslashes($this->getDbConfigJson()) . '" ' . $host; + + $output = shell_exec($command); + $lines = explode("\n", $output); + $tokenAuth = trim(end($lines)); + if (strlen($tokenAuth) != 32) { + throw new \Exception("Failed to install new matomo, output: $output"); + } + + return $tokenAuth; + } + + private function verifyInstall($tokenAuth) + { + $url = Fixture::getRootUrl() . '/' . $this->subdirToInstall + . '/index.php?module=API&method=API.get&idSite=1&date=yesterday&period=day&format=json&token_auth=' . $tokenAuth; + $response = Http::sendHttpRequest($url, 30); + + $response = json_decode($response, true); + $this->assertEquals(0, $response['nb_visits']); + } + + private function getArchiveDestPath() + { + return PIWIK_INCLUDE_PATH . DIRECTORY_SEPARATOR . 'test_latest_stable.zip'; + } + + private function getInstallSubdirectoryPath() + { + return PIWIK_INCLUDE_PATH . DIRECTORY_SEPARATOR . $this->subdirToInstall; + } + + private function getDbConfigJson() + { + $dbConfig = Config::getInstance()->database; + $dbConfig = json_encode($dbConfig); + return $dbConfig; + } + + private function generateMatomoPackageFromGit() + { + $this->cloneMatomoPackageRepo(); + $this->runMatomoPackage(); + } + + private function cloneMatomoPackageRepo() + { + $pathToMatomoPackage = PIWIK_INCLUDE_PATH . '/../matomo-package'; + if (file_exists($pathToMatomoPackage)) { + Filesystem::unlinkRecursive($pathToMatomoPackage, true); + } + + $command = 'git clone https://github.com/matomo-org/matomo-package.git --depth=1 "' . $pathToMatomoPackage . '"'; + exec($command, $output, $returnCode); + + if ($returnCode != 0) { + throw new \Exception("Could not clone matomo-package repo: " . implode("\n", $output)); + } + } + + private function runMatomoPackage() + { + $matomoBuildPath = PIWIK_INCLUDE_PATH . '/matomo-build.zip'; + if (file_exists($matomoBuildPath)) { + unlink($matomoBuildPath); + } + + $command = 'cd "' . PIWIK_INCLUDE_PATH . '/../matomo-package" && '; + $command .= './scripts/build-package.sh "' . PIWIK_INCLUDE_PATH . '" piwik true'; + + exec($command, $output, $returnCode); + if ($returnCode != 0) { + throw new \Exception("matomo-package failed: " . implode("\n", $output)); + } + + $path = PIWIK_INCLUDE_PATH . '/../matomo-package/piwik-build.zip'; + rename($path, $matomoBuildPath); + } +}
\ No newline at end of file diff --git a/tests/PHPUnit/Fixtures/LatestStableInstall/GitCommitReleaseChannel.php b/tests/PHPUnit/Fixtures/LatestStableInstall/GitCommitReleaseChannel.php new file mode 100644 index 0000000000..67e7a2b546 --- /dev/null +++ b/tests/PHPUnit/Fixtures/LatestStableInstall/GitCommitReleaseChannel.php @@ -0,0 +1,30 @@ +<?php + + +namespace Piwik\Plugins\CoreUpdater\ReleaseChannel; + +use Piwik\UpdateCheck\ReleaseChannel; +use Piwik\Url; + +class GitCommitReleaseChannel extends ReleaseChannel +{ + public function getId() + { + return 'git_commit'; + } + + public function getName() + { + return 'Test Release Channel'; + } + + public function getUrlToCheckForLatestAvailableVersion() + { + return 'http://' . Url::getHost(false) . '/tests/resources/one-click-update-version.php'; + } + + public function getDownloadUrlWithoutScheme($version) + { + return '://' . Url::getHost(false) . '/matomo-build.zip'; + } +} |