diff --git a/README.md b/README.md index bbd04d3..f413523 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ Given as user :user Given user :user exists Given sending :verb to :url Given the response should be a JSON array with the following mandatory values +Given guest :guest exists Given /^set the display name of user "([^"]*)" to "([^"]*)"$/ Given /^set the email of user "([^"]*)" to "([^"]*)"$/ Given sending :verb to ocs :url diff --git a/src/NextcloudApiContext.php b/src/NextcloudApiContext.php index f018f81..e1f2b4f 100644 --- a/src/NextcloudApiContext.php +++ b/src/NextcloudApiContext.php @@ -94,6 +94,19 @@ public function assureUserExists(string $user): void { } } + #[Given('guest :guest exists')] + public function assureGuestExists(string $guest): void { + $response = $this->userExists($guest); + if ($response->getStatusCode() !== 200) { + static::createAnEnvironmentWithValueToBeUsedByOccCommand('OC_PASS', '123456'); + $this->runCommandWithResultCode('guests:add admin ' . $guest . ' --password-from-env', 0); + // Set a display name different than the user ID to be able to + // ensure in the tests that the right value was returned. + $this->setUserDisplayName($guest); + self::$createdUsers[] = $guest; + } + } + protected function userExists(string $user): ResponseInterface { $currentUser = $this->currentUser; $this->setCurrentUser('admin');