test: Extract function to get apps with certain enabled state

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2025-10-04 01:35:13 +02:00
parent 6a4865b90a
commit e30875742b

View file

@ -802,13 +802,8 @@ trait Provisioning {
return $extractedElementsArray;
}
/**
* @Given /^app "([^"]*)" is disabled$/
* @param string $app
*/
public function appIsDisabled($app) {
$fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=disabled';
private function getAppsWithFilter($filter) {
$fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=' . $filter;
$client = new Client();
$options = [];
if ($this->currentUser === 'admin') {
@ -819,7 +814,15 @@ trait Provisioning {
];
$this->response = $client->get($fullUrl, $options);
$respondedArray = $this->getArrayOfAppsResponded($this->response);
return $this->getArrayOfAppsResponded($this->response);
}
/**
* @Given /^app "([^"]*)" is disabled$/
* @param string $app
*/
public function appIsDisabled($app) {
$respondedArray = $this->getAppsWithFilter('disabled');
Assert::assertContains($app, $respondedArray);
Assert::assertEquals(200, $this->response->getStatusCode());
}
@ -829,18 +832,7 @@ trait Provisioning {
* @param string $app
*/
public function appIsEnabled($app) {
$fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=enabled';
$client = new Client();
$options = [];
if ($this->currentUser === 'admin') {
$options['auth'] = $this->adminUser;
}
$options['headers'] = [
'OCS-APIREQUEST' => 'true',
];
$this->response = $client->get($fullUrl, $options);
$respondedArray = $this->getArrayOfAppsResponded($this->response);
$respondedArray = $this->getAppsWithFilter('enabled');
Assert::assertContains($app, $respondedArray);
Assert::assertEquals(200, $this->response->getStatusCode());
}
@ -853,18 +845,7 @@ trait Provisioning {
* @param string $app
*/
public function appIsNotEnabled($app) {
$fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=enabled';
$client = new Client();
$options = [];
if ($this->currentUser === 'admin') {
$options['auth'] = $this->adminUser;
}
$options['headers'] = [
'OCS-APIREQUEST' => 'true',
];
$this->response = $client->get($fullUrl, $options);
$respondedArray = $this->getArrayOfAppsResponded($this->response);
$respondedArray = $this->getAppsWithFilter('enabled');
Assert::assertNotContains($app, $respondedArray);
Assert::assertEquals(200, $this->response->getStatusCode());
}