Skip to content

Commit cee2492

Browse files
committed
test: Extract function to get apps with certain enabled state
Signed-off-by: Daniel Calviño Sánchez <[email protected]>
1 parent c1b475b commit cee2492

File tree

1 file changed

+13
-32
lines changed

1 file changed

+13
-32
lines changed

build/integration/features/bootstrap/Provisioning.php

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -803,13 +803,8 @@ public function getArrayOfSubadminsResponded($resp) {
803803
return $extractedElementsArray;
804804
}
805805

806-
807-
/**
808-
* @Given /^app "([^"]*)" is disabled$/
809-
* @param string $app
810-
*/
811-
public function appIsDisabled($app) {
812-
$fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=disabled';
806+
private function getAppsWithFilter($filter) {
807+
$fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=' . $filter;
813808
$client = new Client();
814809
$options = [];
815810
if ($this->currentUser === 'admin') {
@@ -820,7 +815,15 @@ public function appIsDisabled($app) {
820815
];
821816

822817
$this->response = $client->get($fullUrl, $options);
823-
$respondedArray = $this->getArrayOfAppsResponded($this->response);
818+
return $this->getArrayOfAppsResponded($this->response);
819+
}
820+
821+
/**
822+
* @Given /^app "([^"]*)" is disabled$/
823+
* @param string $app
824+
*/
825+
public function appIsDisabled($app) {
826+
$respondedArray = $this->getAppsWithFilter('disabled');
824827
Assert::assertContains($app, $respondedArray);
825828
Assert::assertEquals(200, $this->response->getStatusCode());
826829
}
@@ -830,18 +833,7 @@ public function appIsDisabled($app) {
830833
* @param string $app
831834
*/
832835
public function appIsEnabled($app) {
833-
$fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=enabled';
834-
$client = new Client();
835-
$options = [];
836-
if ($this->currentUser === 'admin') {
837-
$options['auth'] = $this->adminUser;
838-
}
839-
$options['headers'] = [
840-
'OCS-APIREQUEST' => 'true',
841-
];
842-
843-
$this->response = $client->get($fullUrl, $options);
844-
$respondedArray = $this->getArrayOfAppsResponded($this->response);
836+
$respondedArray = $this->getAppsWithFilter('enabled');
845837
Assert::assertContains($app, $respondedArray);
846838
Assert::assertEquals(200, $this->response->getStatusCode());
847839
}
@@ -854,18 +846,7 @@ public function appIsEnabled($app) {
854846
* @param string $app
855847
*/
856848
public function appIsNotEnabled($app) {
857-
$fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=enabled';
858-
$client = new Client();
859-
$options = [];
860-
if ($this->currentUser === 'admin') {
861-
$options['auth'] = $this->adminUser;
862-
}
863-
$options['headers'] = [
864-
'OCS-APIREQUEST' => 'true',
865-
];
866-
867-
$this->response = $client->get($fullUrl, $options);
868-
$respondedArray = $this->getArrayOfAppsResponded($this->response);
849+
$respondedArray = $this->getAppsWithFilter('enabled');
869850
Assert::assertNotContains($app, $respondedArray);
870851
Assert::assertEquals(200, $this->response->getStatusCode());
871852
}

0 commit comments

Comments
 (0)