diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 6ce3ab5ccb7..2923f016bdd 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -343,7 +343,7 @@ public function adminHasDeletedGroupUsingTheGraphApi(string $group): void { * @param string $user username is used as the id * @param string|null $byUser * - * @return void + * @return ResponseInterface * @throws GuzzleException */ public function adminDeletesUserUsingTheGraphApi(string $user, ?string $byUser = null): ResponseInterface { diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 462c4458a2c..c618504ba45 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -1524,15 +1524,15 @@ public function theAdministratorHasChangedTheirOwnEmailAddressTo(?string $email) * @param string $targetUser * @param string $email * - * @return void + * @return ResponseInterface * @throws JsonException */ public function userChangesUserEmailUsingProvisioningApi( string $requestingUser, string $targetUser, string $email - ):void { - $this->response = UserHelper::editUser( + ):ResponseInterface { + return UserHelper::editUser( $this->getBaseUrl(), $this->getActualUsername($targetUser), 'email', @@ -1585,7 +1585,7 @@ public function userTriesToChangeTheEmailOfUserUsingTheProvisioningApi( ):void { $requestingUser = $this->getActualUsername($requestingUser); $targetUser = $this->getActualUsername($targetUser); - $this->userChangesUserEmailUsingProvisioningApi( + $this->response = $this->userChangesUserEmailUsingProvisioningApi( $requestingUser, $targetUser, $email @@ -1625,12 +1625,12 @@ public function userHasChangedTheEmailOfUserUsingTheProvisioningApi( $updatedUserData['mail'], ); } else { - $this->userChangesUserEmailUsingProvisioningApi( + $response = $this->userChangesUserEmailUsingProvisioningApi( $requestingUser, $targetUser, $email ); - $this->theHTTPStatusCodeShouldBeSuccess(); + $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); } $this->rememberUserEmailAddress($targetUser, $email); } @@ -1708,8 +1708,11 @@ public function adminHasChangedTheDisplayNameOfUser( $this->getAdminPassword(), $this->getStepLineRef() ); - $this->setResponse($response); - $this->theDisplayNameReturnedByTheApiShouldBe($displayName); + $actualDisplayName = $this->getDisplayNameFromResponse($response); + Assert::assertEquals( + $displayName, + $actualDisplayName + ); } $this->rememberUserDisplayName($user, $displayName); } @@ -1734,7 +1737,7 @@ public function adminChangesTheDisplayOfUserUsingTheProvisioningApi( string $displayName ):void { $user = $this->getActualUsername($user); - $this->adminChangesTheDisplayNameOfUserUsingKey( + $this->response = $this->adminChangesTheDisplayNameOfUserUsingKey( $user, 'display', $displayName @@ -1748,14 +1751,14 @@ public function adminChangesTheDisplayOfUserUsingTheProvisioningApi( * @param string $key * @param string $displayName * - * @return void + * @return ResponseInterface * @throws Exception */ public function adminChangesTheDisplayNameOfUserUsingKey( string $user, string $key, string $displayName - ):void { + ):ResponseInterface { $result = UserHelper::editUser( $this->getBaseUrl(), $this->getActualUsername($user), @@ -1766,13 +1769,7 @@ public function adminChangesTheDisplayNameOfUserUsingKey( $this->getStepLineRef(), $this->ocsApiVersion ); - $this->response = $result; - if ($result->getStatusCode() !== 200) { - throw new Exception( - __METHOD__ . " could not change display name of user using key $key " - . $result->getStatusCode() . " " . $result->getBody() - ); - } + return $result; } /** @@ -1827,7 +1824,7 @@ public function userTriesToChangeTheDisplayNameOfUserUsingTheProvisioningApi( ):void { $requestingUser = $this->getActualUsername($requestingUser); $targetUser = $this->getActualUsername($targetUser); - $this->userChangesTheDisplayNameOfUserUsingKey( + $this->response = $this->userChangesTheDisplayNameOfUserUsingKey( $requestingUser, $targetUser, 'displayname', @@ -1902,13 +1899,14 @@ public function userHasChangedTheDisplayNameOfUserUsingTheProvisioningApi( $updatedUserData['displayName'] ); } else { - $this->userChangesTheDisplayNameOfUserUsingKey( + $response = $this->userChangesTheDisplayNameOfUserUsingKey( $requestingUser, $targetUser, 'displayname', $displayName ); $this->theHTTPStatusCodeShouldBeSuccess(); + $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); } $this->rememberUserDisplayName($targetUser, $displayName); } @@ -1919,15 +1917,15 @@ public function userHasChangedTheDisplayNameOfUserUsingTheProvisioningApi( * @param string $key * @param string $displayName * - * @return void + * @return ResponseInterface */ public function userChangesTheDisplayNameOfUserUsingKey( string $requestingUser, string $targetUser, string $key, string $displayName - ):void { - $result = UserHelper::editUser( + ):ResponseInterface { + return UserHelper::editUser( $this->getBaseUrl(), $this->getActualUsername($targetUser), $key, @@ -1937,7 +1935,6 @@ public function userChangesTheDisplayNameOfUserUsingKey( $this->getStepLineRef(), $this->ocsApiVersion ); - $this->response = $result; } /** @@ -1993,14 +1990,14 @@ public function adminHasChangedTheQuotaOfUserTo( * @param string $targetUser * @param string $quota * - * @return void + * @return ResponseInterface */ public function userChangeQuotaOfUserUsingProvisioningApi( string $requestingUser, string $targetUser, string $quota - ):void { - $result = UserHelper::editUser( + ):ResponseInterface { + return UserHelper::editUser( $this->getBaseUrl(), $this->getActualUsername($targetUser), 'quota', @@ -2010,7 +2007,6 @@ public function userChangeQuotaOfUserUsingProvisioningApi( $this->getStepLineRef(), $this->ocsApiVersion ); - $this->response = $result; } /** @@ -2027,7 +2023,7 @@ public function userChangesTheQuotaOfUserUsingTheProvisioningApi( string $targetUser, string $quota ):void { - $this->userChangeQuotaOfUserUsingProvisioningApi( + $this->response = $this->userChangeQuotaOfUserUsingProvisioningApi( $requestingUser, $targetUser, $quota @@ -2049,24 +2045,24 @@ public function userHasChangedTheQuotaOfUserUsingTheProvisioningApi( string $targetUser, string $quota ):void { - $this->userChangeQuotaOfUserUsingProvisioningApi( + $response = $this->userChangeQuotaOfUserUsingProvisioningApi( $requestingUser, $targetUser, $quota ); - $this->theHTTPStatusCodeShouldBeSuccess(); + $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); } /** * @param string $user * - * @return void + * @return ResponseInterface * @throws JsonException */ public function retrieveUserInformationAsAdminUsingProvisioningApi( string $user - ):void { - $result = UserHelper::getUser( + ):ResponseInterface { + return UserHelper::getUser( $this->getBaseUrl(), $this->getActualUsername($user), $this->getAdminUsername(), @@ -2074,7 +2070,6 @@ public function retrieveUserInformationAsAdminUsingProvisioningApi( $this->getStepLineRef(), $this->ocsApiVersion ); - $this->response = $result; } /** @@ -2813,18 +2808,18 @@ public function userShouldNotBelongToGroup(string $user, string $group):void { $this->graphContext->userShouldNotBeMemberInGroupUsingTheGraphApi($user, $group); } else { $fullUrl = $this->getBaseUrl() . "/ocs/v2.php/cloud/users/$user/groups"; - $this->response = HttpRequestHelper::get( + $response = HttpRequestHelper::get( $fullUrl, $this->getStepLineRef(), $this->getAdminUsername(), $this->getAdminPassword() ); - $respondedArray = $this->getArrayOfGroupsResponded($this->response); + $respondedArray = $this->getArrayOfGroupsResponded($response); \sort($respondedArray); Assert::assertNotContains($group, $respondedArray); Assert::assertEquals( 200, - $this->response->getStatusCode() + $response->getStatusCode() ); } } @@ -2856,13 +2851,13 @@ public function theTheFollowingUserShouldNotBelongToTheFollowingGroup(TableNode public function groupShouldNotContainUser(string $group, string $username):void { $username = $this->getActualUsername($username); $fullUrl = $this->getBaseUrl() . "/ocs/v2.php/cloud/groups/$group"; - $this->response = HttpRequestHelper::get( + $response = HttpRequestHelper::get( $fullUrl, $this->getStepLineRef(), $this->getAdminUsername(), $this->getAdminPassword() ); - $this->theUsersReturnedByTheApiShouldNotInclude($username); + Assert::assertNotContains($username, $this->getArrayOfUsersResponded($response)); } /** @@ -4089,13 +4084,13 @@ public function theAppsShouldNotInclude(?TableNode $appList):void { */ public function appShouldNotBeInTheAppsList(string $appName):void { $fullUrl = $this->getBaseUrl() . "/ocs/v2.php/cloud/apps"; - $this->response = HttpRequestHelper::get( + $response = HttpRequestHelper::get( $fullUrl, $this->getStepLineRef(), $this->getAdminUsername(), $this->getAdminPassword() ); - $respondedArray = $this->getArrayOfAppsResponded($this->response); + $respondedArray = $this->getArrayOfAppsResponded($response); Assert::assertNotContains($appName, $respondedArray); } @@ -4139,6 +4134,15 @@ public function userShouldNotBeASubadminOfGroup(string $user, string $group):voi ); } + /** + * @param ResponseInterface $response + * + * @return string + */ + public function getDisplayNameFromResponse(ResponseInterface $response): string { + return (string) $this->getResponseXml($response, __METHOD__)->data[0]->displayname; + } + /** * @Then /^the display name returned by the API should be "([^"]*)"$/ * @@ -4166,8 +4170,12 @@ public function theDisplayNameReturnedByTheApiShouldBe(string $expectedDisplayNa */ public function theDisplayNameOfUserShouldBe(string $user, string $displayname):void { $actualUser = $this->getActualUsername($user); - $this->retrieveUserInformationAsAdminUsingProvisioningApi($actualUser); - $this->theDisplayNameReturnedByTheApiShouldBe($displayname); + $response = $this->retrieveUserInformationAsAdminUsingProvisioningApi($actualUser); + $actualDisplayName = $this->getDisplayNameFromResponse($response, $displayname); + Assert::assertEquals( + $displayname, + $actualDisplayName + ); } /** @@ -4411,17 +4419,17 @@ public function getArrayOfAppInfoResponded(ResponseInterface $resp):array { public function appShouldBeDisabled(string $app):void { $fullUrl = $this->getBaseUrl() . "/ocs/v2.php/cloud/apps?filter=disabled"; - $this->response = HttpRequestHelper::get( + $response = HttpRequestHelper::get( $fullUrl, $this->getStepLineRef(), $this->getAdminUsername(), $this->getAdminPassword() ); - $respondedArray = $this->getArrayOfAppsResponded($this->response); + $respondedArray = $this->getArrayOfAppsResponded($response); Assert::assertContains($app, $respondedArray); Assert::assertEquals( 200, - $this->response->getStatusCode() + $response->getStatusCode() ); } @@ -4435,17 +4443,17 @@ public function appShouldBeDisabled(string $app):void { */ public function appShouldBeEnabled(string $app):void { $fullUrl = $this->getBaseUrl() . "/ocs/v2.php/cloud/apps?filter=enabled"; - $this->response = HttpRequestHelper::get( + $response = HttpRequestHelper::get( $fullUrl, $this->getStepLineRef(), $this->getAdminUsername(), $this->getAdminPassword() ); - $respondedArray = $this->getArrayOfAppsResponded($this->response); + $respondedArray = $this->getArrayOfAppsResponded($response); Assert::assertContains($app, $respondedArray); Assert::assertEquals( 200, - $this->response->getStatusCode() + $response->getStatusCode() ); } @@ -4459,7 +4467,7 @@ public function appShouldBeEnabled(string $app):void { */ public function theInformationForAppShouldHaveAValidVersion(string $app):void { $fullUrl = $this->getBaseUrl() . "/ocs/v2.php/cloud/apps/$app"; - $this->response = HttpRequestHelper::get( + $response = HttpRequestHelper::get( $fullUrl, $this->getStepLineRef(), $this->getAdminUsername(), @@ -4467,9 +4475,9 @@ public function theInformationForAppShouldHaveAValidVersion(string $app):void { ); Assert::assertEquals( 200, - $this->response->getStatusCode() + $response->getStatusCode() ); - $respondedArray = $this->getArrayOfAppInfoResponded($this->response); + $respondedArray = $this->getArrayOfAppInfoResponded($response); Assert::assertArrayHasKey( 'version', $respondedArray, @@ -4494,7 +4502,7 @@ public function userShouldBeDisabled(string $user):void { $user = $this->getActualUsername($user); $fullUrl = $this->getBaseUrl() . "/ocs/v$this->ocsApiVersion.php/cloud/users/$user"; - $this->response = HttpRequestHelper::get( + $response = HttpRequestHelper::get( $fullUrl, $this->getStepLineRef(), $this->getAdminUsername(), @@ -4502,7 +4510,7 @@ public function userShouldBeDisabled(string $user):void { ); Assert::assertEquals( "false", - $this->getResponseXml(null, __METHOD__)->data[0]->enabled + $this->getResponseXml($response, __METHOD__)->data[0]->enabled ); } @@ -4534,7 +4542,7 @@ public function userShouldBeEnabled(string $user):void { $user = $this->getActualUsername($user); $fullUrl = $this->getBaseUrl() . "/ocs/v$this->ocsApiVersion.php/cloud/users/$user"; - $this->response = HttpRequestHelper::get( + $response = HttpRequestHelper::get( $fullUrl, $this->getStepLineRef(), $this->getAdminUsername(), @@ -4542,7 +4550,7 @@ public function userShouldBeEnabled(string $user):void { ); Assert::assertEquals( "true", - $this->getResponseXml(null, __METHOD__)->data[0]->enabled + $this->getResponseXml($response, __METHOD__)->data[0]->enabled ); }