Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/acceptance/features/apiMain/appmanagement.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
58 changes: 58 additions & 0 deletions tests/acceptance/features/bootstrap/AppManagementContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -42,6 +43,11 @@ class AppManagementContext implements Context {
*/
private $cmdOutput;

/**
* @var string[]
*/
private $createdApps = [];

/**
*
* @param array $appsPaths of apps_paths entries
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
}

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}
}
}
}