Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tests-Only] Refactor acceptance tests #394

Merged
merged 1 commit into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions tests/acceptance/features/apiGuests/guests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
And the HTTP status code should be "201"
When user "[email protected]" uploads overwriting file "textfile.txt" from the guests test data folder to "/myfile.txt" with all mechanisms using the WebDAV API
Expand All @@ -28,7 +28,7 @@ Feature: Guests
And as "[email protected]" 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 "[email protected]"
When user "[email protected]" uploads file "textfile.txt" from the guests test data folder asynchronously to "/textfile.txt" in 3 chunks using the WebDAV API
Expand All @@ -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 "[email protected]"
And the HTTP status code should be "201"
Expand All @@ -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 "[email protected]"
And the HTTP status code should be "201"
Expand All @@ -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 "[email protected]"
And the HTTP status code should be "201"
Expand All @@ -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 "[email protected]"
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scenario was not related to guests at all

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
Expand All @@ -198,10 +185,10 @@ Feature: Guests
Given the administrator has created guest user "guest" with email "[email protected]"
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 "[email protected]" using the API
When the administrator attempts to create guest user "guest" with email "[email protected]" 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 "[email protected]"
And the HTTP status code should be "201"
And group "guests_app" has been created
Expand All @@ -218,11 +205,11 @@ Feature: Guests
And user "user0" has created folder "/tmp"
And user "user0" has shared folder "/tmp" with user "[email protected]"
And guest user "guest" registers
When user "[email protected]" has created guest user "guest2" with email "[email protected]"
When user "[email protected]" attempts to create guest user "guest2" with email "[email protected]" 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 "[email protected]"
When the administrator creates these users with skeleton files:
| username | email |
Expand Down
153 changes: 133 additions & 20 deletions tests/acceptance/features/bootstrap/GuestsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
);
}

/**
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
);
}

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
*
Expand Down
36 changes: 6 additions & 30 deletions tests/acceptance/features/bootstrap/WebUIGuestsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,34 +86,6 @@ public function __construct(SetPasswordPage $setPasswordPage, FilesPage $filesPa
$this->filesPage = $filesPage;
}

/**
* @return string|null
*/
public function getGuestGroupName() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function was not used.

$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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function was not used.

$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
*
Expand Down Expand Up @@ -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"
);
}

/**
Expand All @@ -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"
);
}

Expand Down