diff --git a/tests/acceptance/features/apiGuests/guests.feature b/tests/acceptance/features/apiGuests/guests.feature index 95222379..aedf0621 100644 --- a/tests/acceptance/features/apiGuests/guests.feature +++ b/tests/acceptance/features/apiGuests/guests.feature @@ -19,7 +19,7 @@ Feature: Guests Then the HTTP status code should be "422" And user "guest" should not exist - Scenario: A guest user cannot upload files + Scenario: A guest user cannot upload files to their own storage Given the administrator has created guest user "guest" with email "guest@example.com" And the HTTP status code should be "201" When user "guest@example.com" uploads overwriting file "textfile.txt" from the guests test data folder to "/myfile.txt" with all mechanisms using the WebDAV API @@ -28,7 +28,7 @@ Feature: Guests And as "guest@example.com" file "/textfile.txt" should not exist And as "user0" file "/textfile.txt" should not exist - Scenario: A guest user cannot upload files (async upload) + Scenario: A guest user cannot upload files to their own storage (async upload) Given the administrator has enabled async operations And the administrator has created guest user "guest" with email "guest@example.com" When user "guest@example.com" uploads file "textfile.txt" from the guests test data folder asynchronously to "/textfile.txt" in 3 chunks using the WebDAV API @@ -37,7 +37,7 @@ Feature: Guests And as "user0" file "/textfile.txt" should not exist @mailhog - Scenario: A guest user can upload files + Scenario: A guest user can upload files to a folder shared with them Given user "user0" has been created with default attributes and skeleton files And the administrator has created guest user "guest" with email "guest@example.com" And the HTTP status code should be "201" @@ -48,7 +48,7 @@ Feature: Guests Then the HTTP status code should be "201" @mailhog - Scenario: A guest user can upload chunked files + Scenario: A guest user can upload chunked files to a folder shared with them Given user "user0" has been created with default attributes and skeleton files And the administrator has created guest user "guest" with email "guest@example.com" And the HTTP status code should be "201" @@ -64,7 +64,7 @@ Feature: Guests And as "user0" file "/tmp/myChunkedFile.txt" should exist @mailhog @issue-279 - Scenario: A guest user can upload files + Scenario: A guest user can upload files to a folder shared with them Given user "user0" has been created with default attributes and skeleton files And the administrator has created guest user "guest" with email "guest@example.com" And the HTTP status code should be "201" @@ -89,7 +89,7 @@ Feature: Guests """ @mailhog - Scenario: A guest user can upload files (async upload) + Scenario: A guest user can upload files to a folder shared with them (async upload) Given the administrator has enabled async operations And user "user0" has been created with default attributes and skeleton files And the administrator has created guest user "guest" with email "guest@example.com" @@ -169,19 +169,6 @@ Feature: Guests Then the OCS status code should be "404" And the HTTP status code should be "200" - Scenario: Check that skeleton is properly set - Given user "user0" has been created with default attributes and skeleton files - Then user "user0" should see the following elements - | /FOLDER/ | - | /PARENT/ | - | /PARENT/parent.txt | - | /textfile0.txt | - | /textfile1.txt | - | /textfile2.txt | - | /textfile3.txt | - | /textfile4.txt | - | /welcome.txt | - @mailhog Scenario: A created guest user can log in Given user "user0" has been created with default attributes and skeleton files @@ -198,10 +185,10 @@ Feature: Guests Given the administrator has created guest user "guest" with email "guest@example.com" And the HTTP status code should be "201" And user "guest" should be a guest user - When the administrator creates guest user "guest" with email "guest@example.com" using the API + When the administrator attempts to create guest user "guest" with email "guest@example.com" using the API Then the HTTP status code should be "422" - Scenario: removing a user from a group + Scenario: removing a guest user from a group Given the administrator has created guest user "guest" with email "guest@example.com" And the HTTP status code should be "201" And group "guests_app" has been created @@ -218,11 +205,11 @@ Feature: Guests And user "user0" has created folder "/tmp" And user "user0" has shared folder "/tmp" with user "guest@example.com" And guest user "guest" registers - When user "guest@example.com" has created guest user "guest2" with email "guest2@example.com" + When user "guest@example.com" attempts to create guest user "guest2" with email "guest2@example.com" using the API Then the HTTP status code should be "403" @mailhog - Scenario: Create a regular user using the same email address of an existing guest user + Scenario: Create a regular user using the same email address as an existing guest user Given the administrator has created guest user "guest" with email "guest@example.com" When the administrator creates these users with skeleton files: | username | email | diff --git a/tests/acceptance/features/bootstrap/GuestsContext.php b/tests/acceptance/features/bootstrap/GuestsContext.php index 03f381ca..3622fd2f 100644 --- a/tests/acceptance/features/bootstrap/GuestsContext.php +++ b/tests/acceptance/features/bootstrap/GuestsContext.php @@ -130,7 +130,20 @@ public function prepareUserNameAsFrontend($guestEmail) { } /** - * @When user :user uploads file :source from the guests test data folder to :destination using the WebDAV API + * @param string $user + * @param string $source + * @param string $destination + * + * @return void + */ + public function userUploadsFileFromGuestsDataFolder( + $user, $source, $destination + ) { + $source = $this->getRelativePathToTestDataFolder() . $source; + $this->featureContext->userUploadsAFileTo($user, $source, $destination); + } + + /** * @Given user :user has uploaded file :source from the guests test data folder to :destination * * @param string $user @@ -139,11 +152,30 @@ public function prepareUserNameAsFrontend($guestEmail) { * * @return void */ + public function userHasUploadedFileFromGuestsDataFolderTo( + $user, $source, $destination + ) { + $this->userUploadsFileFromGuestsDataFolder( + $user, $source, $destination + ); + $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + } + + /** + * @When user :user uploads file :source from the guests test data folder to :destination using the WebDAV API + * + * @param string $user + * @param string $source + * @param string $destination + * + * @return void + */ public function userUploadsFileFromGuestsDataFolderTo( $user, $source, $destination ) { - $source = $this->getRelativePathToTestDataFolder() . $source; - $this->featureContext->userUploadsAFileTo($user, $source, $destination); + $this->userUploadsFileFromGuestsDataFolder( + $user, $source, $destination + ); } /** @@ -216,22 +248,17 @@ public function userUploadsAFileAsyncToWithChunks( } /** - * @When /^user "([^"]*)" (attempts to create|creates) guest user "([^"]*)" with email "([^"]*)" using the API$/ - * @Given /^user "([^"]*)" has (attempted to create|created) guest user "([^"]*)" with email "([^"]*)"$/ - * * @param string $user - * @param string $attemptTo * @param string $guestDisplayName * @param string $guestEmail + * @param bool $shouldExist * * @return void */ public function userCreatesAGuestUser( - $user, $attemptTo, $guestDisplayName, $guestEmail + $user, $guestDisplayName, $guestEmail, $shouldExist ) { $user = $this->featureContext->getActualUsername($user); - $shouldHaveBeenCreated - = (($attemptTo == "creates") || ($attemptTo === "created")); $fullUrl = $this->featureContext->getBaseUrl() . '/index.php/apps/guests/users'; //Replicating frontend behaviour @@ -251,6 +278,11 @@ public function userCreatesAGuestUser( ); $this->featureContext->setResponse($response); + + if ($shouldExist) { + $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + } + $this->createdGuests[$guestDisplayName] = $guestEmail; // Let core acceptance test functionality know the user that has been @@ -260,13 +292,68 @@ public function userCreatesAGuestUser( $this->featureContext->getPasswordForUser($userName), $guestDisplayName, $guestEmail, - $shouldHaveBeenCreated + $shouldExist + ); + } + + /** + * @Given /^user "([^"]*)" has created guest user "([^"]*)" with email "([^"]*)"$/ + * + * @param string $user + * @param string $guestDisplayName + * @param string $guestEmail + * + * @return void + */ + public function userCreatesAGuestUserWithEmail( + $user, $guestDisplayName, $guestEmail + ) { + $this->userCreatesAGuestUser( + $user, $guestDisplayName, $guestEmail, true + ); + } + + /** + * @When /^user "([^"]*)" (attempts to create|creates) guest user "([^"]*)" with email "([^"]*)" using the API$/ + * + * @param string $user + * @param string $attemptTo + * @param string $guestDisplayName + * @param string $guestEmail + * + * @return void + */ + public function userHasCreatedAGuestUserWithEmail( + $user, $attemptTo, $guestDisplayName, $guestEmail + ) { + $shouldExist + = ($attemptTo == "creates"); + $this->userCreatesAGuestUser( + $user, $guestDisplayName, $guestEmail, $shouldExist + ); + } + + /** + * @Given /^the administrator has created guest user "([^"]*)" with email "([^"]*)"$/ + * + * @param string $guestDisplayName + * @param string $guestEmail + * + * @return void + */ + public function theAdministratorHasCreatedAGuestUser( + $guestDisplayName, $guestEmail + ) { + $this->userCreatesAGuestUser( + $this->featureContext->getAdminUsername(), + $guestDisplayName, + $guestEmail, + true ); } /** * @When /^the administrator (attempts to create|creates) guest user "([^"]*)" with email "([^"]*)" using the API$/ - * @Given /^the administrator has (attempted to create|created) guest user "([^"]*)" with email "([^"]*)"$/ * * @param string $attemptTo * @param string $guestDisplayName @@ -277,11 +364,13 @@ public function userCreatesAGuestUser( public function theAdministratorCreatesAGuestUser( $attemptTo, $guestDisplayName, $guestEmail ) { + $shouldExist + = ($attemptTo == "creates"); $this->userCreatesAGuestUser( $this->featureContext->getAdminUsername(), - $attemptTo, $guestDisplayName, - $guestEmail + $guestEmail, + $shouldExist ); } @@ -365,18 +454,13 @@ public function getRegistrationUrl($address) { } /** - * @When guest user :user registers - * @When guest user :user registers and sets password to :password - * @Given guest user :user has registered - * @Given guest user :user has registered and set password to :password - * * @param string $guestDisplayName * @param string $password * * @return void * @throws Exception */ - public function guestUserRegisters($guestDisplayName, $password = null) { + public function registerGuestUser($guestDisplayName, $password = null) { $oldCSRFSetting = $this->disableCSRFFromGuestsScenario(); $userName = $this->prepareUserNameAsFrontend( $this->createdGuests[$guestDisplayName] @@ -424,6 +508,35 @@ public function guestUserRegisters($guestDisplayName, $password = null) { $this->setCSRFDotDisabledFromGuestsScenario($oldCSRFSetting); } + /** + * @Given guest user :user has registered + * @Given guest user :user has registered and set password to :password + * + * @param string $guestDisplayName + * @param string $password + * + * @return void + * @throws Exception + */ + public function guestUserHasRegistered($guestDisplayName, $password = null) { + $this->registerGuestUser($guestDisplayName, $password); + $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + } + + /** + * @When guest user :user registers + * @When guest user :user registers and sets password to :password + * + * @param string $guestDisplayName + * @param string $password + * + * @return void + * @throws Exception + */ + public function guestUserRegisters($guestDisplayName, $password = null) { + $this->registerGuestUser($guestDisplayName, $password); + } + /** * @BeforeScenario * diff --git a/tests/acceptance/features/bootstrap/WebUIGuestsContext.php b/tests/acceptance/features/bootstrap/WebUIGuestsContext.php index b077fba6..84944164 100644 --- a/tests/acceptance/features/bootstrap/WebUIGuestsContext.php +++ b/tests/acceptance/features/bootstrap/WebUIGuestsContext.php @@ -86,34 +86,6 @@ public function __construct(SetPasswordPage $setPasswordPage, FilesPage $filesPa $this->filesPage = $filesPage; } - /** - * @return string|null - */ - public function getGuestGroupName() { - $configkeyList = $this->featureContext->getConfigKeyList('guests'); - foreach ($configkeyList as $config) { - if ($config['configkey'] === 'group') { - return $config['value']; - } - } - return null; - } - - /** - * @Given guest user :user has been created with email :email and password :password - * - * @param string $user - * @param string $email - * @param string $password - * - * @return void - * @throws Exception - */ - public function guestUserHasBeenCreatedWithEmailAndPassword($user, $email, $password) { - $this->featureContext->createUser($user, $password, $user, $email); - $this->featureContext->addUserToGroup($user, $this->getGuestGroupName()); - } - /** * @When guest user :user registers with email :guestEmail and sets password to :password using the webUI * @@ -190,7 +162,11 @@ public function userShouldNotBeDisplayedInTheDropdownAsGuestUser($user) { $sharingDialog = $this->filesPage->getSharingDialog(); $arrayList = $sharingDialog->getAutoCompleteItemsList(); $userAddDialog = \sprintf($this->userAddDialogBoxFramework, $user); - PHPUnit\Framework\Assert::assertNotContains($userAddDialog, $arrayList); + Assert::assertNotContains( + $userAddDialog, + $arrayList, + __METHOD__ . " user $user was displayed in the dropdown as a guest user when it should not be" + ); } /** @@ -207,7 +183,7 @@ public function assertWarningMessage($expectedMessage) { } } Assert::fail( - "could not find message with the text '$expectedMessage'" + "could not find message with the text '$expectedMessage' on the set-password-page" ); }