From ff783808607300237473796e4de1e74aaf1c8761 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Mon, 17 Jun 2019 15:44:00 +0545 Subject: [PATCH] test app version after app was updated to new patch version --- .../features/apiMain/appmanagement.feature | 16 +++++ .../bootstrap/AppManagementContext.php | 58 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/tests/acceptance/features/apiMain/appmanagement.feature b/tests/acceptance/features/apiMain/appmanagement.feature index 41c3401521b9..dbb41f877ee1 100644 --- a/tests/acceptance/features/apiMain/appmanagement.feature +++ b/tests/acceptance/features/apiMain/appmanagement.feature @@ -15,3 +15,19 @@ Feature: AppManagement And app "multidirtest" with version "1.0.5" has been put in dir "apps2" When the administrator gets the path for app "multidirtest" using the occ command Then the path to "multidirtest" should be "apps2" + + Scenario: Update of patch version of an app + Given app "updatetest" with version "2.0.0" has been put in dir "apps" + And app "updatetest" has been enabled + And app "updatetest" has been disabled + When the administrator puts app "updatetest" with version "2.0.1" in dir "apps" + And the administrator enables app "updatetest" + Then the installed version of "updatetest" should be "2.0.1" + + Scenario: Update of patch version of an app but update is put in alternative folder + Given app "updatetest" with version "2.0.0" has been put in dir "apps" + And app "updatetest" has been enabled + And app "updatetest" has been disabled + When the administrator puts app "updatetest" with version "2.0.1" in dir "apps2" + And the administrator enables app "updatetest" + Then the installed version of "updatetest" should be "2.0.1" \ No newline at end of file diff --git a/tests/acceptance/features/bootstrap/AppManagementContext.php b/tests/acceptance/features/bootstrap/AppManagementContext.php index 140525441485..a4082bdca443 100644 --- a/tests/acceptance/features/bootstrap/AppManagementContext.php +++ b/tests/acceptance/features/bootstrap/AppManagementContext.php @@ -21,6 +21,7 @@ use Behat\Behat\Context\Context; use Behat\Behat\Hook\Scope\BeforeScenarioScope; +use PHPUnit\Framework\Assert; use TestHelpers\SetupHelper; require __DIR__ . '/../../../../lib/composer/autoload.php'; @@ -42,6 +43,11 @@ class AppManagementContext implements Context { */ private $cmdOutput; + /** + * @var string[] + */ + private $createdApps = []; + /** * * @param array $appsPaths of apps_paths entries @@ -82,6 +88,7 @@ public function setAppDirectories($dir1, $dir2) { /** * @Given app :appId with version :version has been put in dir :dir + * @When the administrator puts app :appId with version :version in dir :dir * * @param string $appId app id * @param string $version app version @@ -119,6 +126,13 @@ public function appHasBeenPutInDir($appId, $version, $dir) { $targetDir = "$dir/$appId/appinfo"; $this->featureContext->mkDirOnServer($targetDir); $this->featureContext->createFileOnServerWithContent("$targetDir/info.xml", $appInfo); + if (!\array_key_exists($appId, $this->createdApps)) { + $this->createdApps[$appId][] = $targetDir; + } else { + if (!\in_array($targetDir, $this->createdApps[$appId])) { + $this->createdApps[$appId][] = $targetDir; + } + } } /** @@ -150,6 +164,21 @@ public function appPathIs($appId, $dir) { ); } + /** + * @Then the installed version of :appId should be :version + * + * @param string $appId + * @param string $version + * + * @return void + */ + public function assertInstalledVersionOfAppIs($appId, $version) { + $cmdOutput = SetupHelper::runOcc( + ['config:app:get', $appId, 'installed_version', '--no-ansi'] + )['stdOut']; + PHPUnit\Framework\Assert::assertEquals($version, \trim($cmdOutput)); + } + /** * This will run before EVERY scenario. * It will set the properties for this object. @@ -192,4 +221,33 @@ public function undoChangingParameters() { $this->setAppsPaths($this->oldAppsPaths); } } + + /** + * @AfterScenario + * + * delete created apps including files and values in DB after each scenario + * + * @return void + * @throws Exception + */ + public function deleteCreatedApps() { + $configJson = SetupHelper::runOcc(['config:list'])['stdOut']; + $configList = \json_decode($configJson, true); + foreach ($this->createdApps as $app => $paths) { + //disable the app + $this->featureContext->appHasBeenDisabled($app, 'disables'); + + //delete config values out of the database + if (\array_key_exists($app, $configList['apps'])) { + foreach ($configList['apps'][$app] as $key => $value) { + SetupHelper::runOcc(['config:app:delete', $app, $key]); + } + } + + //delete the app from the drive + foreach ($paths as $path) { + SetupHelper::rmDirOnServer(\dirname($path)); + } + } + } }