diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2024-03-15 13:03:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-15 13:03:34 +0100 |
commit | 9338ef36ded767f2c35b7ec575b351859420ed09 (patch) | |
tree | 65c53c6a36f300859dc22b2d423275bcf2911367 /tests/acceptance/features | |
parent | 6b09a79227a5dc98aa4620c6e5e15b610a06c806 (diff) | |
parent | df1cd1ba7e6e1f6e66a2b3229b5c082f1b81162e (diff) | |
download | nextcloud-server-9338ef36ded767f2c35b7ec575b351859420ed09.tar.gz nextcloud-server-9338ef36ded767f2c35b7ec575b351859420ed09.zip |
Merge branch 'master' into refactor/OC-Server-getShareManager
Signed-off-by: John Molakvoæ <skjnldsv@users.noreply.github.com>
Diffstat (limited to 'tests/acceptance/features')
40 files changed, 0 insertions, 7205 deletions
diff --git a/tests/acceptance/features/access-levels.feature b/tests/acceptance/features/access-levels.feature deleted file mode 100644 index de34a17baea..00000000000 --- a/tests/acceptance/features/access-levels.feature +++ /dev/null @@ -1,23 +0,0 @@ -Feature: access-levels - - Scenario: regular users cannot see admin-level items in the Settings menu - Given I am logged in - When I open the Settings menu - Then I see that the Settings menu is shown - And I see that the "Settings" item in the Settings menu is shown - And I see that the "Users" item in the Settings menu is not shown - And I see that the "Help" item in the Settings menu is shown - And I see that the "Log out" item in the Settings menu is shown - - Scenario: regular users cannot see admin-level items on the Settings page - Given I am logged in - When I visit the settings page - Then I see that the "Personal info" entry in the settings panel is shown - And I see that the "Personal" settings panel is not shown - And I see that the "Administration" settings panel is not shown - - Scenario: admin users can see admin-level items on the Settings page - Given I am logged in as the admin - When I visit the admin settings page - Then I see that the "Personal" settings panel is shown - And I see that the "Administration" settings panel is shown diff --git a/tests/acceptance/features/app-comments.feature b/tests/acceptance/features/app-comments.feature deleted file mode 100644 index b57883d8ba8..00000000000 --- a/tests/acceptance/features/app-comments.feature +++ /dev/null @@ -1,325 +0,0 @@ -Feature: app-comments - -# Scenario: Writing a comment -# Given I am logged in -# And I open the details view for "welcome.txt" -# And I open the "Comments" tab in the details view -# When I create a new comment with "Hello world" as message -# Then I see a comment with "Hello world" as message - -# Scenario: open the comments for a different file -# Given I am logged in -# And I create a new folder named "Folder" -# And I open the details view for "welcome.txt" -# And I open the "Comments" tab in the details view -# And I create a new comment with "Hello world" as message -# And I see a comment with "Hello world" as message -# When I open the details view for "Folder" - # The "Comments" tab should already be opened -# Then I see that there are no comments - - Scenario: write a comment in a file right after writing a comment in another file - Given I am logged in - And I create a new folder named "Folder" - And I open the details view for "Folder" - And I open the "Comments" tab in the details view - And I create a new comment with "Comment in Folder" as message - And I see a comment with "Comment in Folder" as message - And I open the details view for "welcome.txt" - # The "Comments" tab should already be opened - When I create a new comment with "Comment in welcome.txt" as message - Then I see a comment with "Comment in welcome.txt" as message - And I see that there is no comment with "Comment in Folder" as message - - - - Scenario: read a comment written by the sharer - Given I act as John - And I am logged in as the admin - And I act as Jane - And I am logged in - And I act as John - And I rename "welcome.txt" to "shared.txt" - And I share "shared.txt" with "user0" - And I see that the file is shared with "user0" - # The details view should already be open - And I open the "Comments" tab in the details view - And I create a new comment with "Hello world" as message - And I see a comment with "Hello world" as message - When I act as Jane - # The Files app is open again to reload the file list and the comments - And I open the Files app - And I open the details view for "shared.txt" - And I open the "Comments" tab in the details view - Then I see a comment with "Hello world" as message - - Scenario: read a comment written by the sharee - Given I act as John - And I am logged in as the admin - And I act as Jane - And I am logged in - And I act as John - And I rename "welcome.txt" to "shared.txt" - And I share "shared.txt" with "user0" - And I see that the file is shared with "user0" - And I act as Jane - # The Files app is open again to reload the file list - And I open the Files app - And I open the details view for "shared.txt" - And I open the "Comments" tab in the details view - And I create a new comment with "Hello world" as message - And I see a comment with "Hello world" as message - When I act as John - # The Files app is open again to reload the file list and the comments - And I open the Files app - And I open the details view for "shared.txt" - And I open the "Comments" tab in the details view - Then I see a comment with "Hello world" as message - - - - Scenario: unread comment icon shown for comment written by the sharer in a shared file - Given I act as John - And I am logged in as the admin - And I act as Jane - And I am logged in - And I act as John - And I rename "welcome.txt" to "shared.txt" - And I share "shared.txt" with "user0" - And I see that the file is shared with "user0" - # The details view should already be open - And I open the "Comments" tab in the details view - And I create a new comment with "Hello world" as message - And I see a comment with "Hello world" as message - When I act as Jane - # The Files app is open again to reload the file list and the comments - And I open the Files app - Then I see that "shared.txt" has unread comments - And I open the unread comments for "shared.txt" - And I see that the details view is open - And I see a comment with "Hello world" as message - - Scenario: unread comment icon shown for comment written by the sharee in a shared file - Given I act as John - And I am logged in as the admin - And I act as Jane - And I am logged in - And I act as John - And I rename "welcome.txt" to "shared.txt" - And I share "shared.txt" with "user0" - And I see that the file is shared with "user0" - And I act as Jane - # The Files app is open again to reload the file list - And I open the Files app - And I open the details view for "shared.txt" - And I open the "Comments" tab in the details view - And I create a new comment with "Hello world" as message - And I see a comment with "Hello world" as message - When I act as John - # The Files app is open again to reload the file list and the comments - And I open the Files app - Then I see that "shared.txt" has unread comments - And I open the unread comments for "shared.txt" - And I see that the details view is open - And I see a comment with "Hello world" as message - - Scenario: unread comment icon shown for comment written by the sharer in a shared folder - Given I act as John - And I am logged in as the admin - And I act as Jane - And I am logged in - And I act as John - And I create a new folder named "Folder" - And I share "Folder" with "user0" - And I see that the file is shared with "user0" - # The details view should already be open - And I open the "Comments" tab in the details view - And I create a new comment with "Hello world" as message - And I see a comment with "Hello world" as message - When I act as Jane - # The Files app is open again to reload the file list and the comments - And I open the Files app - Then I see that "Folder" has unread comments - And I open the unread comments for "Folder" - And I see that the details view is open - And I see a comment with "Hello world" as message - - Scenario: unread comment icon shown for comment written by the sharee in a shared folder - Given I act as John - And I am logged in as the admin - And I act as Jane - And I am logged in - And I act as John - And I create a new folder named "Folder" - And I share "Folder" with "user0" - And I see that the file is shared with "user0" - And I act as Jane - # The Files app is open again to reload the file list - And I open the Files app - And I open the details view for "Folder" - And I open the "Comments" tab in the details view - And I create a new comment with "Hello world" as message - And I see a comment with "Hello world" as message - When I act as John - # The Files app is open again to reload the file list and the comments - And I open the Files app - Then I see that "Folder" has unread comments - And I open the unread comments for "Folder" - And I see that the details view is open - And I see a comment with "Hello world" as message - - Scenario: unread comment icon shown for comment written by the sharer in a child folder of a shared folder - Given I act as John - And I am logged in as the admin - And I act as Jane - And I am logged in - And I act as John - And I create a new folder named "Folder" - And I share "Folder" with "user0" - And I see that the file is shared with "user0" - And I enter in the folder named "Folder" - And I create a new folder named "Child folder" - # The details view should already be open - And I open the "Comments" tab in the details view - And I create a new comment with "Hello world" as message - And I see a comment with "Hello world" as message - When I act as Jane - # The Files app is open again to reload the file list and the comments - And I open the Files app - And I enter in the folder named "Folder" - Then I see that "Child folder" has unread comments - And I open the unread comments for "Child folder" - And I see that the details view is open - And I see a comment with "Hello world" as message - - Scenario: unread comment icon shown for comment written by the sharee in a child folder of a shared folder - Given I act as John - And I am logged in as the admin - And I act as Jane - And I am logged in - And I act as John - And I create a new folder named "Folder" - And I share "Folder" with "user0" - And I see that the file is shared with "user0" - And I act as Jane - # The Files app is open again to reload the file list - And I open the Files app - And I enter in the folder named "Folder" - And I create a new folder named "Child folder" - # The details view should already be open - And I open the "Comments" tab in the details view - And I create a new comment with "Hello world" as message - And I see a comment with "Hello world" as message - When I act as John - And I enter in the folder named "Folder" - Then I see that "Child folder" has unread comments - And I open the unread comments for "Child folder" - And I see that the details view is open - And I see a comment with "Hello world" as message - - - - Scenario: search a comment - Given I am logged in - And I open the details view for "welcome.txt" - And I open the "Comments" tab in the details view - And I create a new comment with "Hello world" as message - And I see a comment with "Hello world" as message - When I search for "hello" - # Search results for comments also include the user that wrote the comment. - Then I see that the search result 1 is "user0Hello world" - And I see that the search result 1 was found in "welcome.txt" - - Scenario: search a comment in a child folder - Given I am logged in - And I create a new folder named "Folder" - And I enter in the folder named "Folder" - And I create a new folder named "Child folder" - And I open the details view for "Child folder" - And I open the "Comments" tab in the details view - And I create a new comment with "Hello world" as message - And I see a comment with "Hello world" as message - # The Files app is open again to reload the file list - And I open the Files app - When I search for "hello" - # Search results for comments also include the user that wrote the comment. - Then I see that the search result 1 is "user0Hello world" - And I see that the search result 1 was found in "Folder/Child folder" - - Scenario: search a comment by a another user - Given I act as John - And I am logged in as the admin - And I act as Jane - And I am logged in - And I act as John - And I rename "welcome.txt" to "shared.txt" - And I share "shared.txt" with "user0" - And I see that the file is shared with "user0" - And I act as Jane - # The Files app is open again to reload the file list - And I open the Files app - And I open the details view for "shared.txt" - And I open the "Comments" tab in the details view - And I create a new comment with "Hello world" as message - And I see a comment with "Hello world" as message - When I act as John - And I search for "hello" - # Search results for comments also include the user that wrote the comment. - Then I see that the search result 1 is "user0Hello world" - And I see that the search result 1 was found in "shared.txt" - - Scenario: open a search result for a comment in a file - Given I am logged in - And I open the details view for "welcome.txt" - And I open the "Comments" tab in the details view - And I create a new comment with "Hello world" as message - And I see a comment with "Hello world" as message - # Force the details view to change to a different file before closing it - And I create a new folder named "Folder" - And I close the details view - When I search for "hello" - And I open the search result 1 - Then I see that the details view is open - And I see that the file name shown in the details view is "welcome.txt" - And I see a comment with "Hello world" as message - And I see that the file list is currently in "Home" - And I see that the file list contains a file named "welcome.txt" - - Scenario: open a search result for a comment in a folder named like its child folder - Given I am logged in - And I create a new folder named "Folder" - And I open the details view for "Folder" - And I open the "Comments" tab in the details view - And I create a new comment with "Hello world" as message - And I see a comment with "Hello world" as message - And I enter in the folder named "Folder" - And I create a new folder named "Folder" - # The Files app is open again to reload the file list - And I open the Files app - When I search for "hello" - And I open the search result 1 - Then I see that the details view is open - And I see that the file name shown in the details view is "Folder" - And I see a comment with "Hello world" as message - And I see that the file list is currently in "Home" - And I see that the file list contains a file named "welcome.txt" - And I see that the file list contains a file named "Folder" - - Scenario: open a search result for a comment in a child folder - Given I am logged in - And I create a new folder named "Folder" - And I enter in the folder named "Folder" - And I create a new folder named "Child folder" - And I open the details view for "Child folder" - And I open the "Comments" tab in the details view - And I create a new comment with "Hello world" as message - And I see a comment with "Hello world" as message - # The Files app is open again to reload the file list - And I open the Files app - When I search for "hello" - And I open the search result 1 - Then I see that the details view is open - And I see that the file name shown in the details view is "Child folder" - And I see a comment with "Hello world" as message - And I see that the file list is currently in "Home/Folder" - And I see that the file list contains a file named "Child folder" diff --git a/tests/acceptance/features/apps.feature b/tests/acceptance/features/apps.feature deleted file mode 100644 index 0fc2f2a686d..00000000000 --- a/tests/acceptance/features/apps.feature +++ /dev/null @@ -1,92 +0,0 @@ -@apache -Feature: apps - - Scenario: enable an installed app - Given I act as Jane - And I am logged in as the admin - And I open the Apps management - When I enable the "QA testing" app - Then I see that the "QA testing" app has been enabled - - Scenario: disable a installed app - Given I act as Jane - And I am logged in as the admin - And I open the Apps management - When I disable the "Update notification" app - Then I see that the "Update notification" app has been disabled - - Scenario: Browse enabled apps - Given I act as Jane - And I am logged in as the admin - And I open the Apps management - When I open the "Active apps" section - Then I see that the current section is "Active apps" - And I see that there are only enabled apps - - Scenario: Browse disabled apps - Given I act as Jane - And I am logged in as the admin - And I open the Apps management - When I open the "Disabled apps" section - Then I see that the current section is "Disabled apps" - And I see that there are only disabled apps - - Scenario: Browse app bundles - Given I act as Jane - And I am logged in as the admin - And I open the Apps management - When I open the "App bundles" section - Then I see that the current section is "App bundles" - And I see the app bundles - And I see that the "Enterprise bundle" is disabled - -# Enabling an app bundle fails when not all apps have a matching version available -# Scenario: Enable an app bundle -# Given I act as Jane -# And I am logged in as the admin -# And I open the Apps management -# And I open the "App bundles" section -# When I enable all apps from the "Enterprise bundle" -# Then I see that the "Auditing / Logging" app has been enabled -# And I see that the "LDAP user and group backend" app has been enabled - - Scenario: View app details - Given I act as Jane - And I am logged in as the admin - And I open the Apps management - When I click on the "QA testing" app - Then I see that the app details are shown - - # TODO: Improve testing with app store as external API - # The following scenarios require the files_antivirus and calendar app - # being present in the app store with support for the current server version - # Ideally we would have either a dummy app store endpoint with some test apps - # or even an app store instance running somewhere to properly test this. - # This is also a requirement to properly test updates of apps - - Scenario: Show section from app store - Given I act as Jane - And I am logged in as the admin - And I open the Apps management - And I see that the current section is "Your apps" - #When I open the "Files" section - #Then I see that there some apps listed from the app store - #And I see that the current section is "Files" - -# Scenario: View app details for app store apps -# Given I act as Jane -# And I am logged in as the admin -# And I open the Apps management -# And I open the "Tools" section -# When I click on the "Antivirus for files" app -# Then I see that the app details are shown - -# Scenario: Install an app from the app store -# Given I act as Jane -# And I am logged in as the admin -# And I open the Apps management -# And I open the "Tools" section -# And I click on the "Antivirus for files" app -# And I see that the app details are shown -# Then I download and enable the "Antivirus for files" app -# And I see that the "Antivirus for files" app has been enabled diff --git a/tests/acceptance/features/bootstrap/AppNavigationContext.php b/tests/acceptance/features/bootstrap/AppNavigationContext.php deleted file mode 100644 index 49d664e2333..00000000000 --- a/tests/acceptance/features/bootstrap/AppNavigationContext.php +++ /dev/null @@ -1,154 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; - -class AppNavigationContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function appNavigation() { - return Locator::forThe()->xpath("//*[@id=\"app-navigation\" or contains(@class, 'app-navigation')]")-> - describedAs("App navigation"); - } - - /** - * @return Locator - */ - public static function appNavigationSectionItemFor($sectionText) { - return Locator::forThe()->xpath("//li/*[contains(normalize-space(), '$sectionText')]/..")-> - descendantOf(self::appNavigation())-> - describedAs($sectionText . " section item in App Navigation"); - } - - /** - * @return Locator - */ - public static function appNavigationSectionItemInFor($caption, $sectionText) { - return Locator::forThe()->xpath("//li[normalize-space() = '$caption']/following-sibling::li/a[normalize-space() = '$sectionText']/..")-> - descendantOf(self::appNavigation())-> - describedAs($sectionText . " section item of the $caption group in App Navigation"); - } - - /** - * @return Locator - */ - public static function appNavigationCurrentSectionItem() { - return Locator::forThe()->css(".active")-> - descendantOf(self::appNavigation())-> - describedAs("Current section item in App Navigation"); - } - - /** - * @return Locator - */ - public static function buttonForTheSection($class, $section) { - return Locator::forThe()->css("." . $class)-> - descendantOf(self::appNavigationSectionItemFor($section))-> - describedAs("The $class button on the $section section in App Navigation"); - } - - /** - * @return Locator - */ - public static function counterForTheSection($section) { - return Locator::forThe()->css(".app-navigation-entry-utils-counter")-> - descendantOf(self::appNavigationSectionItemFor($section))-> - describedAs("The counter for the $section section in App Navigation"); - } - - /** - * @Given I open the :section section - */ - public function iOpenTheSection($section) { - $this->actor->find(self::appNavigationSectionItemFor($section), 10)->click(); - } - - /** - * @Given I open the :section section of the :caption group - */ - public function iOpenTheSectionOf($caption, $section) { - $this->actor->find(self::appNavigationSectionItemInFor($caption, $section), 10)->click(); - } - - /** - * @Given I click the :class button on the :section section - */ - public function iClickTheButtonInTheSection($class, $section) { - $this->actor->find(self::buttonForTheSection($class, $section), 10)->click(); - } - - /** - * @Then I see that the current section is :section - */ - public function iSeeThatTheCurrentSectionIs($section) { - Assert::assertEquals($this->actor->find(self::appNavigationCurrentSectionItem(), 10)->getText(), $section); - } - - /** - * @Then I see that the section :section is shown - */ - public function iSeeThatTheSectionIsShown($section) { - if (!WaitFor::elementToBeEventuallyShown( - $this->actor, - self::appNavigationSectionItemFor($section), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The section $section in the app navigation is not shown yet after $timeout seconds"); - } - } - - /** - * @Then I see that the section :section is not shown - */ - public function iSeeThatTheSectionIsNotShown($section) { - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::appNavigationSectionItemFor($section), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The section $section in the app navigation is still shown after $timeout seconds"); - } - } - - /** - * @Then I see that the section :section has a count of :count - */ - public function iSeeThatTheSectionHasACountOf($section, $count) { - Assert::assertEquals($this->actor->find(self::counterForTheSection($section), 10)->getText(), $count); - } - - /** - * @Then I see that the section :section does not have a count - */ - public function iSeeThatTheSectionDoesNotHaveACount($section) { - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::counterForTheSection($section), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The counter for section $section is still shown after $timeout seconds"); - } - } -} diff --git a/tests/acceptance/features/bootstrap/AppSettingsContext.php b/tests/acceptance/features/bootstrap/AppSettingsContext.php deleted file mode 100644 index 785664fa01c..00000000000 --- a/tests/acceptance/features/bootstrap/AppSettingsContext.php +++ /dev/null @@ -1,99 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; - -class AppSettingsContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function appSettings() { - return Locator::forThe()->id("app-settings")-> - describedAs("App settings"); - } - /** - * @return Locator - */ - public static function appSettingsContent() { - return Locator::forThe()->xpath("//div[@id = 'app-settings-content' or @id = 'app-settings__content']")-> - descendantOf(self::appSettings())-> - describedAs("App settings"); - } - - /** - * @return Locator - */ - public static function appSettingsOpenButton() { - return Locator::forThe()->xpath("//div[@id = 'app-settings-header' or @id = 'app-settings__header']/button")-> - descendantOf(self::appSettings())-> - describedAs("The button to open the app settings"); - } - - /** - * @return Locator - */ - public static function checkboxInTheSettings($id) { - return Locator::forThe()->xpath("//input[@id = '$id']")-> - descendantOf(self::appSettingsContent())-> - describedAs("The $id checkbox in the settings"); - } - - /** - * @return Locator - */ - public static function checkboxLabelInTheSettings($id) { - return Locator::forThe()->css("[data-test=\"$id\"]")-> - descendantOf(self::appSettingsContent())-> - describedAs("The label for the $id checkbox in the settings"); - } - - /** - * @Given I open the settings - */ - public function iOpenTheSettings() { - $this->actor->find(self::appSettingsOpenButton(), 10)->click(); - } - - /** - * @Given I toggle the :id checkbox in the settings - */ - public function iToggleTheCheckboxInTheSettingsTo($id) { - $this->actor->find(self::checkboxLabelInTheSettings($id), 10)->click(); - } - - /** - * @Then I see that the settings are opened - */ - public function iSeeThatTheSettingsAreOpened() { - if (!WaitFor::elementToBeEventuallyShown( - $this->actor, - self::appSettingsContent(), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The app settings are not open yet after $timeout seconds"); - } - } -} diff --git a/tests/acceptance/features/bootstrap/AppsManagementContext.php b/tests/acceptance/features/bootstrap/AppsManagementContext.php deleted file mode 100644 index fc8a38c867e..00000000000 --- a/tests/acceptance/features/bootstrap/AppsManagementContext.php +++ /dev/null @@ -1,283 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net> - * - * @author Julius Härtl <jus@bitgrid.net> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; - -class AppsManagementContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function appsList() { - return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@id='apps-list']")-> - describedAs("Apps list in Apps Management"); - } - - /** - * @return Locator - */ - public static function enableButtonForApp($app) { - return Locator::forThe()->button("Enable")-> - descendantOf(self::rowForApp($app))-> - describedAs("Enable button in the app list for $app"); - } - - /** - * @return Locator - */ - public static function enableButtonForAnyApp() { - return Locator::forThe()->button("Enable")-> - descendantOf(self::appsList())-> - describedAs("Enable button in the app list for any app"); - } - - /** - * @return Locator - */ - public static function downloadAndEnableButtonForApp($app) { - return Locator::forThe()->button("Download and enable")-> - descendantOf(self::rowForApp($app))-> - describedAs("Download & enable button in the app list for $app"); - } - - /** - * @return Locator - */ - public static function disableButtonForApp($app) { - return Locator::forThe()->button("Disable")-> - descendantOf(self::rowForApp($app))-> - describedAs("Disable button in the app list for $app"); - } - - /** - * @return Locator - */ - public static function disableButtonForAnyApp() { - return Locator::forThe()->button("Disable")-> - descendantOf(self::appsList())-> - describedAs("Disable button in the app list for any app"); - } - - /** - * @return Locator - */ - public static function enableAllBundleButton($bundle) { - return Locator::forThe()->xpath("//div[@class='apps-header']/h2[normalize-space() = '$bundle']/input[@value='Download and enable all']")-> - descendantOf(self::appsList())-> - describedAs("Button to enable bundles"); - } - - /** - * @return Locator - */ - public static function rowForApp($app) { - return Locator::forThe()->xpath("//div[@class='app-name'][normalize-space() = '$app']/..")-> - descendantOf(self::appsList())-> - describedAs("Row for app $app in Apps Management"); - } - - /** - * @return Locator - */ - public static function emptyAppList() { - return Locator::forThe()->xpath("//div[@id='apps-list-empty']")-> - descendantOf(self::appsList())-> - describedAs("Empty apps list view"); - } - - /** - * @return Locator - */ - public static function appEntries() { - return Locator::forThe()->xpath("//div[@class='section']")-> - descendantOf(self::appsList())-> - describedAs("Entries in apps list"); - } - - /** - * @return Locator - */ - public static function disabledAppEntries() { - return Locator::forThe()->button("Disable")-> - descendantOf(self::appEntries())-> - describedAs("Disable button in the app list"); - } - - /** - * @return Locator - */ - public static function enabledAppEntries() { - return Locator::forThe()->button("Enable")-> - descendantOf(self::appEntries())-> - describedAs("Enable button in the app list"); - } - - /** - * @return Locator - */ - public static function sidebar() { - return Locator::forThe()->xpath("//*[@id=\"app-sidebar\" or contains(@class, 'app-sidebar')]")-> - describedAs("Sidebar in apps management"); - } - - - /** - * @When I enable the :app app - */ - public function iEnableTheApp($app) { - $this->actor->find(self::enableButtonForApp($app), 10)->click(); - } - - /** - * @When I download and enable the :app app - */ - public function iDownloadAndEnableTheApp($app) { - $this->actor->find(self::downloadAndEnableButtonForApp($app), 10)->click(); - } - - /** - * @When I disable the :app app - */ - public function iDisableTheApp($app) { - $this->actor->find(self::disableButtonForApp($app), 10)->click(); - } - - /** - * @Then I see that the :app app has been enabled - */ - public function iSeeThatTheAppHasBeenEnabled($app) { - // TODO: Find a way to check if the enable button is removed - Assert::assertTrue( - $this->actor->find(self::disableButtonForApp($app), 10)->isVisible() - ); - } - - /** - * @Then I see that the :app app has been disabled - */ - public function iSeeThatTheAppHasBeenDisabled($app) { - // TODO: Find a way to check if the disable button is removed - Assert::assertTrue( - $this->actor->find(self::enableButtonForApp($app), 10)->isVisible() - ); - } - - /** - * @Then /^I see that there are no available updates$/ - */ - public function iSeeThatThereAreNoAvailableUpdates() { - Assert::assertTrue( - $this->actor->find(self::emptyAppList(), 10)->isVisible() - ); - } - - /** - * @Then /^I see that there some apps listed from the app store$/ - */ - public function iSeeThatThereSomeAppsListedFromTheAppStore() { - if (!WaitFor::elementToBeEventuallyShown( - $this->actor, - self::appEntries(), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The apps from the app store were not shown yet after $timeout seconds"); - } - } - - /** - * @When /^I click on the "([^"]*)" app$/ - */ - public function iClickOnTheApp($app) { - $this->actor->find(self::rowForApp($app), 10)->click(); - } - - /** - * @Given /^I see that there are only disabled apps$/ - */ - public function iSeeThatThereAreOnlyDisabledApps() { - try { - $this->actor->find(self::disableButtonForAnyApp(), 2); - - Assert::fail("Found enabled apps"); - } catch (NoSuchElementException $exception) { - } - } - - /** - * @Given /^I see that there are only enabled apps$/ - */ - public function iSeeThatThereAreOnlyEnabledApps() { - try { - $this->actor->find(self::enableButtonForAnyApp(), 2); - - Assert::fail("Found disabled apps"); - } catch (NoSuchElementException $exception) { - } - } - - /** - * @Given /^I see the app bundles$/ - */ - public function iSeeTheAppBundles() { - Assert::assertTrue( - $this->actor->find(self::rowForApp('Auditing / Logging'), 10)->isVisible() - ); - Assert::assertTrue( - $this->actor->find(self::rowForApp('LDAP user and group backend'), 2)->isVisible() - ); - } - - /** - * @When /^I enable all apps from the "([^"]*)"$/ - */ - public function iEnableAllAppsFromThe($bundle) { - $this->actor->find(self::enableAllBundleButton($bundle), 2)->click(); - } - - /** - * @Given /^I see that the "([^"]*)" is disabled$/ - */ - public function iSeeThatTheIsDisabled($bundle) { - Assert::assertTrue( - $this->actor->find(self::enableAllBundleButton($bundle), 2)->isVisible() - ); - } - - /** - * @Given /^I see that the app details are shown$/ - */ - public function iSeeThatTheAppDetailsAreShown() { - // The sidebar always exists in the DOM, so it has to be explicitly - // waited for it to be visible instead of relying on the implicit wait - // made to find the element. - if (!WaitFor::elementToBeEventuallyShown( - $this->actor, - self::sidebar(), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The sidebar was not shown yet after $timeout seconds"); - } - } -} diff --git a/tests/acceptance/features/bootstrap/CommentsAppContext.php b/tests/acceptance/features/bootstrap/CommentsAppContext.php deleted file mode 100644 index b193ba9fb33..00000000000 --- a/tests/acceptance/features/bootstrap/CommentsAppContext.php +++ /dev/null @@ -1,113 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; - -class CommentsAppContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function newCommentField() { - return Locator::forThe()->css("div.newCommentRow .message")-> - descendantOf(FilesAppContext::detailsView())-> - describedAs("New comment field in details view in Files app"); - } - - /** - * @return Locator - */ - public static function submitNewCommentButton() { - return Locator::forThe()->css("div.newCommentRow .submit")-> - descendantOf(FilesAppContext::detailsView())-> - describedAs("Submit new comment button in details view in Files app"); - } - - /** - * @return Locator - */ - public static function commentList() { - return Locator::forThe()->css("ul.comments")-> - descendantOf(FilesAppContext::detailsView())-> - describedAs("Comment list in details view in Files app"); - } - - /** - * @return Locator - */ - public static function commentWithText($text) { - return Locator::forThe()->xpath("//div[normalize-space() = '$text']/ancestor::li")-> - descendantOf(self::commentList())-> - describedAs("Comment with text \"$text\" in details view in Files app"); - } - - /** - * @return Locator - */ - public static function emptyContent() { - return Locator::forThe()->css(".emptycontent")-> - descendantOf(FilesAppContext::detailsView())-> - describedAs("Empty content in details view in Files app"); - } - - /** - * @When /^I create a new comment with "([^"]*)" as message$/ - */ - public function iCreateANewCommentWithAsMessage($commentText) { - $this->actor->find(self::newCommentField(), 10)->setValue($commentText); - $this->actor->find(self::submitNewCommentButton())->click(); - } - - /** - * @Then /^I see that there are no comments$/ - */ - public function iSeeThatThereAreNoComments() { - if (!WaitFor::elementToBeEventuallyShown( - $this->actor, - self::emptyContent(), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The no comments message is not visible yet after $timeout seconds"); - } - } - - /** - * @Then /^I see a comment with "([^"]*)" as message$/ - */ - public function iSeeACommentWithAsMessage($commentText) { - Assert::assertTrue( - $this->actor->find(self::commentWithText($commentText), 10)->isVisible()); - } - - /** - * @Then /^I see that there is no comment with "([^"]*)" as message$/ - */ - public function iSeeThatThereIsNoCommentWithAsMessage($commentText) { - try { - Assert::assertFalse( - $this->actor->find(self::commentWithText($commentText))->isVisible()); - } catch (NoSuchElementException $exception) { - } - } -} diff --git a/tests/acceptance/features/bootstrap/ContactsMenuContext.php b/tests/acceptance/features/bootstrap/ContactsMenuContext.php deleted file mode 100644 index 72c33410b28..00000000000 --- a/tests/acceptance/features/bootstrap/ContactsMenuContext.php +++ /dev/null @@ -1,145 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) (skjnldsv@protonmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; - -class ContactsMenuContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function contactsMenuButton() { - return Locator::forThe()->xpath("//*[@id = 'header']//*[@id = 'contactsmenu']//*[@class = 'header-menu__trigger']")-> - describedAs("Contacts menu button"); - } - - /** - * @return Locator - */ - public static function contactsMenu() { - return Locator::forThe()->xpath("//*[@id = 'header']//*[@id = 'contactsmenu']//*[@id = 'contactsmenu-menu']")-> - describedAs("Contacts menu"); - } - - /** - * @return Locator - */ - public static function contactsMenuSearchInput() { - return Locator::forThe()->id("contactsmenu-search")-> - descendantOf(self::contactsMenu())-> - describedAs("Contacts menu search input"); - } - - /** - * @return Locator - */ - public static function noResultsMessage() { - return Locator::forThe()->xpath("//*[@class = 'emptycontent' and normalize-space() = 'No contacts found']")-> - descendantOf(self::contactsMenu())-> - describedAs("No results message in Contacts menu"); - } - - /** - * @return Locator - */ - private static function menuItemFor($contactName) { - return Locator::forThe()->xpath("//*[@class = 'full-name' and normalize-space() = '$contactName']")-> - descendantOf(self::contactsMenu())-> - describedAs($contactName . " contact in Contacts menu"); - } - - /** - * @When I open the Contacts menu - */ - public function iOpenTheContactsMenu() { - $this->actor->find(self::contactsMenuButton(), 10)->click(); - } - - /** - * @When I search for the user :user - */ - public function iSearchForTheUser($user) { - $this->actor->find(self::contactsMenuSearchInput(), 10)->setValue($user); - } - - /** - * @Then I see that the Contacts menu is shown - */ - public function iSeeThatTheContactsMenuIsShown() { - Assert::assertTrue( - $this->actor->find(self::contactsMenu(), 10)->isVisible()); - } - - /** - * @Then I see that the Contacts menu search input is shown - */ - public function iSeeThatTheContactsMenuSearchInputIsShown() { - Assert::assertTrue( - $this->actor->find(self::contactsMenuSearchInput(), 10)->isVisible()); - } - - /** - * @Then I see that the no results message in the Contacts menu is shown - */ - public function iSeeThatTheNoResultsMessageInTheContactsMenuIsShown() { - Assert::assertTrue( - $this->actor->find(self::noResultsMessage(), 10)->isVisible()); - } - - /** - * @Then I see that the contact :contactName in the Contacts menu is shown - */ - public function iSeeThatTheContactInTheContactsMenuIsShown($contactName) { - Assert::assertTrue( - $this->actor->find(self::menuItemFor($contactName), 10)->isVisible()); - } - - /** - * @Then I see that the contact :contactName in the Contacts menu is not shown - */ - public function iSeeThatTheContactInTheContactsMenuIsNotShown($contactName) { - $this->iSeeThatThecontactsMenuIsShown(); - - try { - Assert::assertFalse( - $this->actor->find(self::menuItemFor($contactName))->isVisible()); - } catch (NoSuchElementException $exception) { - } - } - - /** - * @Then I see that the contact :contactName in the Contacts menu is eventually not shown - */ - public function iSeeThatTheContactInTheContactsMenuIsEventuallyNotShown($contactName) { - $this->iSeeThatThecontactsMenuIsShown(); - - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::menuItemFor($contactName), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The $contactName contact in Contacts menu is still shown after $timeout seconds"); - } - } -} diff --git a/tests/acceptance/features/bootstrap/DialogContext.php b/tests/acceptance/features/bootstrap/DialogContext.php deleted file mode 100644 index 3deea2f5ebf..00000000000 --- a/tests/acceptance/features/bootstrap/DialogContext.php +++ /dev/null @@ -1,77 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; - -class DialogContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function theDialog() { - return Locator::forThe()->css(".oc-dialog")-> - describedAs("The dialog"); - } - - /** - * @return Locator - */ - public static function theDialogButton($text) { - return Locator::forThe()->xpath("//button[normalize-space() = \"$text\"]")-> - descendantOf(self::theDialog())-> - describedAs($text . " button of the dialog"); - } - - /** - * @Given I click the :text button of the confirmation dialog - */ - public function iClickTheDialogButton($text) { - $this->actor->find(self::theDialogButton($text), 10)->click(); - } - - /** - * @Then I see that the confirmation dialog is shown - */ - public function iSeeThatTheConfirmationDialogIsShown() { - if (!WaitFor::elementToBeEventuallyShown( - $this->actor, - self::theDialog(), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The confirmation dialog was not shown yet after $timeout seconds"); - } - } - - /** - * @Then I see that the confirmation dialog is not shown - */ - public function iSeeThatTheConfirmationDialogIsNotShown() { - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::theDialog(), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The confirmation dialog is still shown after $timeout seconds"); - } - } -} diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php deleted file mode 100644 index 72798ea98f7..00000000000 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; - -class FeatureContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @When I visit the Home page - */ - public function iVisitTheHomePage() { - $this->actor->getSession()->visit($this->actor->locatePath("/")); - } -} diff --git a/tests/acceptance/features/bootstrap/FileListAncestorSetter.php b/tests/acceptance/features/bootstrap/FileListAncestorSetter.php deleted file mode 100644 index b87d1d7dee3..00000000000 --- a/tests/acceptance/features/bootstrap/FileListAncestorSetter.php +++ /dev/null @@ -1,64 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Hook\Scope\BeforeScenarioScope; - -/** - * Helper trait to set the ancestor of the file list. - * - * The FileListContext provides steps to interact with and check the behaviour - * of a file list. However, the FileListContext does not know the right file - * list ancestor that has to be used by the file list steps; this has to be set - * from other contexts, for example, when the Files app or the public page for a - * shared folder is opened. - * - * Contexts that "know" that certain file list ancestor has to be used by the - * FileListContext steps should use this trait and call - * "setFileListAncestorForActor" when needed. - */ -trait FileListAncestorSetter { - /** - * @var FileListContext - */ - private $fileListContext; - - /** - * @BeforeScenario - */ - public function getSiblingFileListContext(BeforeScenarioScope $scope) { - $environment = $scope->getEnvironment(); - - $this->fileListContext = $environment->getContext("FileListContext"); - } - - /** - * Sets the file list ancestor to be used in the file list steps performed - * by the given actor. - * - * @param null|Locator $fileListAncestor the file list ancestor - * @param Actor $actor the actor - */ - private function setFileListAncestorForActor($fileListAncestor, Actor $actor) { - $this->fileListContext->setFileListAncestorForActor($fileListAncestor, $actor); - } -} diff --git a/tests/acceptance/features/bootstrap/FileListContext.php b/tests/acceptance/features/bootstrap/FileListContext.php deleted file mode 100644 index 501bad73c06..00000000000 --- a/tests/acceptance/features/bootstrap/FileListContext.php +++ /dev/null @@ -1,595 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; - -class FileListContext implements Context, ActorAwareInterface { - /** - * @var Actor - */ - private $actor; - - /** - * @var array - */ - private $fileListAncestorsByActor; - - /** - * @var Locator - */ - private $fileListAncestor; - - /** - * @BeforeScenario - */ - public function initializeFileListAncestors() { - $this->fileListAncestorsByActor = []; - $this->fileListAncestor = null; - } - - /** - * @param Actor $actor - */ - public function setCurrentActor(Actor $actor) { - $this->actor = $actor; - - if (array_key_exists($actor->getName(), $this->fileListAncestorsByActor)) { - $this->fileListAncestor = $this->fileListAncestorsByActor[$actor->getName()]; - } else { - $this->fileListAncestor = null; - } - } - - /** - * Sets the file list ancestor to be used in the steps performed by the - * given actor from that point on (until changed again). - * - * This is meant to be called from other contexts, for example, when the - * Files app or the public page for a shared folder are opened. - * - * The FileListAncestorSetter trait can be used to reduce the boilerplate - * needed to set the file list ancestor from other contexts. - * - * @param null|Locator $fileListAncestor the file list ancestor - * @param Actor $actor the actor - */ - public function setFileListAncestorForActor($fileListAncestor, Actor $actor) { - $this->fileListAncestorsByActor[$actor->getName()] = $fileListAncestor; - } - - /** - * @return Locator - */ - public static function mainWorkingIcon($fileListAncestor) { - return Locator::forThe()->css(".mask.icon-loading")-> - descendantOf($fileListAncestor)-> - describedAs("Main working icon in file list"); - } - - /** - * @return Locator - */ - public static function breadcrumbs($fileListAncestor) { - return Locator::forThe()->css(".files-controls .breadcrumb")-> - descendantOf($fileListAncestor)-> - describedAs("Breadcrumbs in file list"); - } - - /** - * @return Locator - */ - public static function createMenuButton($fileListAncestor) { - return Locator::forThe()->css(".files-controls .button.new")-> - descendantOf($fileListAncestor)-> - describedAs("Create menu button in file list"); - } - - /** - * @return Locator - */ - private static function createMenuItemFor($fileListAncestor, $newType) { - return Locator::forThe()->xpath("//div[contains(concat(' ', normalize-space(@class), ' '), ' newFileMenu ')]//span[normalize-space() = '$newType']/ancestor::li")-> - descendantOf($fileListAncestor)-> - describedAs("Create $newType menu item in file list"); - } - - /** - * @return Locator - */ - public static function createNewFolderMenuItem($fileListAncestor) { - return self::createMenuItemFor($fileListAncestor, "New folder"); - } - - /** - * @return Locator - */ - public static function createNewFolderMenuItemNameInput($fileListAncestor) { - return Locator::forThe()->css(".filenameform input[type=text]")-> - descendantOf(self::createNewFolderMenuItem($fileListAncestor))-> - describedAs("Name input in create new folder menu item in file list"); - } - - /** - * @return Locator - */ - public static function createNewFolderMenuItemConfirmButton($fileListAncestor) { - return Locator::forThe()->css(".filenameform input[type=submit]")-> - descendantOf(self::createNewFolderMenuItem($fileListAncestor))-> - describedAs("Confirm button in create new folder menu item in file list"); - } - - /** - * @return Locator - */ - public static function fileListHeader($fileListAncestor) { - return Locator::forThe()->css("thead")-> - descendantOf($fileListAncestor)-> - describedAs("Header in file list"); - } - - /** - * @return Locator - */ - public static function selectedFilesActionsMenuButton($fileListAncestor) { - return Locator::forThe()->css(".actions-selected")-> - descendantOf(self::fileListHeader($fileListAncestor))-> - describedAs("Selected files actions menu button in file list"); - } - - /** - * @return Locator - */ - public static function selectedFilesActionsMenu() { - return Locator::forThe()->css(".filesSelectMenu")-> - describedAs("Selected files actions menu in file list"); - } - - /** - * @return Locator - */ - private static function selectedFilesActionsMenuItemFor($itemText) { - return Locator::forThe()->xpath("//a[normalize-space() = '$itemText']")-> - descendantOf(self::selectedFilesActionsMenu())-> - describedAs($itemText . " item in selected files actions menu in file list"); - } - - /** - * @return Locator - */ - public static function moveOrCopySelectedFilesMenuItem() { - return self::selectedFilesActionsMenuItemFor("Move or copy"); - } - - /** - * @return Locator - */ - public static function rowForFile($fileListAncestor, $fileName) { - return Locator::forThe()->xpath("//*[@class = 'files-fileList']//span[contains(concat(' ', normalize-space(@class), ' '), ' nametext ') and normalize-space() = '$fileName']/ancestor::tr")-> - descendantOf($fileListAncestor)-> - describedAs("Row for file $fileName in file list"); - } - - /** - * @return Locator - */ - public static function rowForFilePreceding($fileListAncestor, $fileName1, $fileName2) { - return Locator::forThe()->xpath("//preceding-sibling::tr//span[contains(concat(' ', normalize-space(@class), ' '), ' nametext ') and normalize-space() = '$fileName1']/ancestor::tr")-> - descendantOf(self::rowForFile($fileListAncestor, $fileName2))-> - describedAs("Row for file $fileName1 preceding $fileName2 in file list"); - } - - /** - * @return Locator - */ - public static function selectionCheckboxForFile($fileListAncestor, $fileName) { - // Note that the element that the user interacts with is the label, not - // the checbox itself. - return Locator::forThe()->css(".selection label")-> - descendantOf(self::rowForFile($fileListAncestor, $fileName))-> - describedAs("Selection checkbox for file $fileName in file list"); - } - - /** - * @return Locator - */ - public static function selectionCheckboxInputForFile($fileListAncestor, $fileName) { - return Locator::forThe()->css(".selection input[type=checkbox]")-> - descendantOf(self::rowForFile($fileListAncestor, $fileName))-> - describedAs("Selection checkbox input for file $fileName in file list"); - } - - /** - * @return Locator - */ - public static function favoriteMarkForFile($fileListAncestor, $fileName) { - return Locator::forThe()->css(".favorite-mark")-> - descendantOf(self::rowForFile($fileListAncestor, $fileName))-> - describedAs("Favorite mark for file $fileName in file list"); - } - - /** - * @return Locator - */ - public static function notFavoritedStateIconForFile($fileListAncestor, $fileName) { - return Locator::forThe()->css(".icon-star")-> - descendantOf(self::favoriteMarkForFile($fileListAncestor, $fileName))-> - describedAs("Not favorited state icon for file $fileName in file list"); - } - - /** - * @return Locator - */ - public static function favoritedStateIconForFile($fileListAncestor, $fileName) { - return Locator::forThe()->css(".icon-starred")-> - descendantOf(self::favoriteMarkForFile($fileListAncestor, $fileName))-> - describedAs("Favorited state icon for file $fileName in file list"); - } - - /** - * @return Locator - */ - public static function mainLinkForFile($fileListAncestor, $fileName) { - return Locator::forThe()->css(".name")-> - descendantOf(self::rowForFile($fileListAncestor, $fileName))-> - describedAs("Main link for file $fileName in file list"); - } - - /** - * @return Locator - */ - public static function renameInputForFile($fileListAncestor, $fileName) { - return Locator::forThe()->css("input.filename")-> - descendantOf(self::rowForFile($fileListAncestor, $fileName))-> - describedAs("Rename input for file $fileName in file list"); - } - - /** - * @return Locator - */ - public static function commentActionForFile($fileListAncestor, $fileName) { - return Locator::forThe()->css(".action-comment")-> - descendantOf(self::rowForFile($fileListAncestor, $fileName))-> - describedAs("Comment action for file $fileName in file list"); - } - - /** - * @return Locator - */ - public static function shareActionForFile($fileListAncestor, $fileName) { - return Locator::forThe()->css(".action-share")-> - descendantOf(self::rowForFile($fileListAncestor, $fileName))-> - describedAs("Share action for file $fileName in file list"); - } - - /** - * @return Locator - */ - public static function fileActionsMenuButtonForFile($fileListAncestor, $fileName) { - return Locator::forThe()->css(".action-menu")-> - descendantOf(self::rowForFile($fileListAncestor, $fileName))-> - describedAs("File actions menu button for file $fileName in file list"); - } - - /** - * @return Locator - */ - public static function fileActionsMenu() { - return Locator::forThe()->css(".fileActionsMenu")-> - describedAs("File actions menu in file list"); - } - - /** - * @return Locator - */ - private static function fileActionsMenuItemFor($itemText) { - return Locator::forThe()->xpath("//a[normalize-space() = '$itemText']")-> - descendantOf(self::fileActionsMenu())-> - describedAs($itemText . " item in file actions menu in file list"); - } - - /** - * @return Locator - */ - public static function addToFavoritesMenuItem() { - return self::fileActionsMenuItemFor("Add to favorites"); - } - - /** - * @return Locator - */ - public static function removeFromFavoritesMenuItem() { - return self::fileActionsMenuItemFor("Remove from favorites"); - } - - /** - * @return Locator - */ - public static function detailsMenuItem() { - return self::fileActionsMenuItemFor("Details"); - } - - /** - * @return Locator - */ - public static function renameMenuItem() { - return self::fileActionsMenuItemFor("Rename"); - } - - /** - * @return Locator - */ - public static function moveOrCopyMenuItem() { - return self::fileActionsMenuItemFor("Move or copy"); - } - - /** - * @return Locator - */ - public static function viewFileInFolderMenuItem() { - return self::fileActionsMenuItemFor("View in folder"); - } - - /** - * @return Locator - */ - public static function deleteMenuItem() { - return self::fileActionsMenuItemFor("Delete"); - } - - /** - * @Given I create a new folder named :folderName - */ - public function iCreateANewFolderNamed($folderName) { - $this->actor->find(self::createMenuButton($this->fileListAncestor), 10)->click(); - - $this->actor->find(self::createNewFolderMenuItem($this->fileListAncestor), 2)->click(); - $this->actor->find(self::createNewFolderMenuItemNameInput($this->fileListAncestor), 2)->setValue($folderName); - $this->actor->find(self::createNewFolderMenuItemConfirmButton($this->fileListAncestor), 2)->click(); - } - - /** - * @Given I enter in the folder named :folderName - */ - public function iEnterInTheFolderNamed($folderName) { - $this->actor->find(self::mainLinkForFile($this->fileListAncestor, $folderName), 10)->click(); - } - - /** - * @Given I select :fileName - */ - public function iSelect($fileName) { - $this->iSeeThatIsNotSelected($fileName); - - $this->actor->find(self::selectionCheckboxForFile($this->fileListAncestor, $fileName), 10)->click(); - } - - /** - * @Given I start the move or copy operation for the selected files - */ - public function iStartTheMoveOrCopyOperationForTheSelectedFiles() { - $this->actor->find(self::selectedFilesActionsMenuButton($this->fileListAncestor), 10)->click(); - - $this->actor->find(self::moveOrCopySelectedFilesMenuItem(), 2)->click(); - } - - /** - * @Given I open the details view for :fileName - */ - public function iOpenTheDetailsViewFor($fileName) { - $this->openFileActionsMenuForFile($fileName); - - $this->actor->find(self::detailsMenuItem(), 2)->click(); - } - - /** - * @Given I rename :fileName1 to :fileName2 - */ - public function iRenameTo($fileName1, $fileName2) { - $this->openFileActionsMenuForFile($fileName1); - - $this->actor->find(self::renameMenuItem(), 2)->click(); - - // For reference, due to a bug in the Firefox driver of Selenium and/or - // maybe in Firefox itself, as a range is selected in the rename input - // (the name of the file, without its extension) when the value is set - // the window must be in the foreground. Otherwise, if the window is in - // the background, instead of setting the value in the whole field it - // would be set only in the selected range. - // This should not be a problem, though, as the default behaviour is to - // bring the browser window to the foreground when switching to a - // different actor. - $this->actor->find(self::renameInputForFile($this->fileListAncestor, $fileName1), 10)->setValue($fileName2); - } - - /** - * @Given I start the move or copy operation for :fileName - */ - public function iStartTheMoveOrCopyOperationFor($fileName) { - $this->openFileActionsMenuForFile($fileName); - - $this->actor->find(self::moveOrCopyMenuItem(), 2)->click(); - } - - /** - * @Given I mark :fileName as favorite - */ - public function iMarkAsFavorite($fileName) { - $this->iSeeThatIsNotMarkedAsFavorite($fileName); - - $this->openFileActionsMenuForFile($fileName); - - $this->actor->find(self::addToFavoritesMenuItem(), 2)->click(); - } - - /** - * @Given I unmark :fileName as favorite - */ - public function iUnmarkAsFavorite($fileName) { - $this->iSeeThatIsMarkedAsFavorite($fileName); - - $this->openFileActionsMenuForFile($fileName); - - $this->actor->find(self::removeFromFavoritesMenuItem(), 2)->click(); - } - - /** - * @When I view :fileName in folder - */ - public function iViewInFolder($fileName) { - $this->openFileActionsMenuForFile($fileName); - - $this->actor->find(self::viewFileInFolderMenuItem(), 2)->click(); - } - - /** - * @When I delete :fileName - */ - public function iDelete($fileName) { - $this->openFileActionsMenuForFile($fileName); - - $this->actor->find(self::deleteMenuItem(), 2)->click(); - } - - /** - * @When I open the unread comments for :fileName - */ - public function iOpenTheUnreadCommentsFor($fileName) { - $this->actor->find(self::commentActionForFile($this->fileListAncestor, $fileName), 10)->click(); - } - - /** - * @Then I see that the file list is eventually loaded - */ - public function iSeeThatTheFileListIsEventuallyLoaded() { - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::mainWorkingIcon($this->fileListAncestor), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The main working icon for the file list is still shown after $timeout seconds"); - } - } - - /** - * @Then I see that the file list is currently in :path - */ - public function iSeeThatTheFileListIsCurrentlyIn($path) { - // The text of the breadcrumbs is the text of all the crumbs separated - // by white spaces. - Assert::assertEquals( - str_replace('/', ' ', $path), $this->actor->find(self::breadcrumbs($this->fileListAncestor), 10)->getText()); - } - - /** - * @Then I see that it is not possible to create new files - */ - public function iSeeThatItIsNotPossibleToCreateNewFiles() { - // Once a file list is loaded the "Create" menu button is always in the - // DOM, so it is checked if it is visible or not. - Assert::assertFalse($this->actor->find(self::createMenuButton($this->fileListAncestor))->isVisible()); - } - - /** - * @Then I see that the file list contains a file named :fileName - */ - public function iSeeThatTheFileListContainsAFileNamed($fileName) { - Assert::assertNotNull($this->actor->find(self::rowForFile($this->fileListAncestor, $fileName), 10)); - } - - /** - * @Then I see that the file list does not contain a file named :fileName - */ - public function iSeeThatTheFileListDoesNotContainAFileNamed($fileName) { - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::rowForFile($this->fileListAncestor, $fileName), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The file list still contains a file named $fileName after $timeout seconds"); - } - } - - /** - * @Then I see that :fileName1 precedes :fileName2 in the file list - */ - public function iSeeThatPrecedesInTheFileList($fileName1, $fileName2) { - Assert::assertNotNull($this->actor->find(self::rowForFilePreceding($this->fileListAncestor, $fileName1, $fileName2), 10)); - } - - /** - * @Then I see that :fileName is not selected - */ - public function iSeeThatIsNotSelected($fileName) { - Assert::assertFalse($this->actor->find(self::selectionCheckboxInputForFile($this->fileListAncestor, $fileName), 10)->isChecked()); - } - - /** - * @Then I see that :fileName is marked as favorite - */ - public function iSeeThatIsMarkedAsFavorite($fileName) { - Assert::assertNotNull($this->actor->find(self::favoritedStateIconForFile($this->fileListAncestor, $fileName), 10)); - } - - /** - * @Then I see that :fileName is not marked as favorite - */ - public function iSeeThatIsNotMarkedAsFavorite($fileName) { - Assert::assertNotNull($this->actor->find(self::notFavoritedStateIconForFile($this->fileListAncestor, $fileName), 10)); - } - - /** - * @Then I see that :fileName has unread comments - */ - public function iSeeThatHasUnreadComments($fileName) { - Assert::assertTrue($this->actor->find(self::commentActionForFile($this->fileListAncestor, $fileName), 10)->isVisible()); - } - - private function waitForRowForFileToBeFullyOpaque($fileName) { - $actor = $this->actor; - $fileRowXpathExpression = $this->actor->find(self::rowForFile($this->fileListAncestor, $fileName), 10)->getWrappedElement()->getXpath(); - - $fileRowIsFullyOpaqueCallback = function () use ($actor, $fileRowXpathExpression) { - $opacity = $actor->getSession()->evaluateScript("return window.getComputedStyle(document.evaluate(\"" . $fileRowXpathExpression . "\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).opacity;"); - if ($opacity === "1") { - return true; - } - - return false; - }; - - if (!Utils::waitFor($fileRowIsFullyOpaqueCallback, $timeout = 2 * $this->actor->getFindTimeoutMultiplier(), $timeoutStep = 1)) { - Assert::fail("The row for file $fileName in file list is not fully opaque after $timeout seconds"); - } - } - - private function openFileActionsMenuForFile($fileName) { - // When a row is added to the file list the opacity of the file row is - // animated from transparent to fully opaque. As the file actions menu - // is a descendant of the row but overflows it when the row is not fully - // opaque clicks on the menu entries "fall-through" and are received - // instead by the rows behind. Therefore it should be waited until the - // row of the file is fully opaque before using the menu. - $this->waitForRowForFileToBeFullyOpaque($fileName); - - $this->actor->find(self::fileActionsMenuButtonForFile($this->fileListAncestor, $fileName), 10)->click(); - } -} diff --git a/tests/acceptance/features/bootstrap/FilesAppContext.php b/tests/acceptance/features/bootstrap/FilesAppContext.php deleted file mode 100644 index b73b8389c49..00000000000 --- a/tests/acceptance/features/bootstrap/FilesAppContext.php +++ /dev/null @@ -1,416 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; - -class FilesAppContext implements Context, ActorAwareInterface { - use ActorAware; - use FileListAncestorSetter; - - /** - * @return array - */ - public static function sections() { - return [ "All files" => "files", - "Recent" => "recent", - "Favorites" => "favorites", - "Shared with you" => "sharingin", - "Shared with others" => "sharingout", - "Shared by link" => "sharinglinks", - "Tags" => "systemtagsfilter", - "Deleted files" => "trashbin" ]; - } - - /** - * @return Locator - */ - private static function appMenu() { - return Locator::forThe()->css("header nav.app-menu")-> - describedAs("App menu in header"); - } - - /** - * @return Locator - */ - public static function filesItemInAppMenu() { - return Locator::forThe()->xpath("//li[@data-app-id = 'files']")-> - descendantOf(self::appMenu())-> - describedAs("Files item in app menu in header"); - } - - /** - * @return Locator - */ - public static function mainViewForSection($section) { - $sectionId = self::sections()[$section]; - - return Locator::forThe()->id("app-content-$sectionId")-> - describedAs("Main view for section $section in Files app"); - } - - /** - * @return Locator - */ - public static function currentSectionMainView() { - return Locator::forThe()->xpath("//*[starts-with(@id, 'app-content-') and not(@id = 'app-content-vue') and not(contains(concat(' ', normalize-space(@class), ' '), ' hidden '))]")-> - describedAs("Current section main view in Files app"); - } - - /** - * @return Locator - */ - public static function detailsView() { - return Locator::forThe()->xpath("//*[@id=\"app-sidebar\" or contains(@class, 'app-sidebar')]")-> - describedAs("Details view in Files app"); - } - - /** - * @return Locator - */ - public static function closeDetailsViewButton() { - return Locator::forThe()->css(".app-sidebar__close")-> - descendantOf(self::detailsView())-> - describedAs("Close details view in Files app"); - } - - /** - * @return Locator - */ - public static function fileNameInDetailsView() { - return Locator::forThe()->css(".app-sidebar-header__title")-> - descendantOf(self::detailsView())-> - describedAs("File name in details view in Files app"); - } - - /** - * @return Locator - */ - public static function favoriteActionInFileDetailsInDetailsView() { - return Locator::forThe()->css(".app-sidebar-header__star")-> - descendantOf(self::fileDetailsInDetailsView())-> - describedAs("Favorite action in file details in details view in Files app"); - } - - /** - * @return Locator - */ - public static function notFavoritedStateIconInFileDetailsInDetailsView() { - return Locator::forThe()->css(".star-outline-icon")-> - descendantOf(self::favoriteActionInFileDetailsInDetailsView())-> - describedAs("Not favorited state icon in file details in details view in Files app"); - } - - /** - * @return Locator - */ - public static function favoritedStateIconInFileDetailsInDetailsView() { - return Locator::forThe()->css(".star-icon")-> - descendantOf(self::favoriteActionInFileDetailsInDetailsView())-> - describedAs("Favorited state icon in file details in details view in Files app"); - } - - /** - * @return Locator - */ - public static function fileDetailsInDetailsViewWithText($fileDetailsText) { - return Locator::forThe()->xpath("//span[normalize-space() = '$fileDetailsText']")-> - descendantOf(self::fileDetailsInDetailsView())-> - describedAs("File details with text \"$fileDetailsText\" in details view in Files app"); - } - - /** - * @return Locator - */ - private static function fileDetailsInDetailsView() { - return Locator::forThe()->css(".app-sidebar-header__desc")-> - descendantOf(self::detailsView())-> - describedAs("File details in details view in Files app"); - } - - /** - * @return Locator - */ - public static function inputFieldForTagsInDetailsView() { - return Locator::forThe()->css(".systemTagsInfoView")-> - descendantOf(self::detailsView())-> - describedAs("Input field for tags in details view in Files app"); - } - - /** - * @return Locator - */ - public static function itemInInputFieldForTagsInDetailsViewForTag($tag) { - return Locator::forThe()->xpath("//span[normalize-space() = '$tag']")-> - descendantOf(self::inputFieldForTagsInDetailsView())-> - describedAs("Item in input field for tags in details view for tag $tag in Files app"); - } - - /** - * @return Locator - */ - public static function itemInDropdownForTag($tag) { - return Locator::forThe()->xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' select2-result-label ')]//span[normalize-space() = '$tag']/ancestor::li")-> - descendantOf(self::select2Dropdown())-> - describedAs("Item in dropdown for tag $tag in Files app"); - } - - /** - * @return Locator - */ - public static function checkmarkInItemInDropdownForTag($tag) { - return Locator::forThe()->css(".checkmark")-> - descendantOf(self::itemInDropdownForTag($tag))-> - describedAs("Checkmark in item in dropdown for tag $tag in Files app"); - } - - /** - * @return Locator - */ - private static function select2Dropdown() { - return Locator::forThe()->css("#select2-drop")-> - describedAs("Select2 dropdown in Files app"); - } - - /** - * @return Locator - */ - public static function tabHeaderInDetailsViewNamed($tabHeaderName) { - return Locator::forThe()->xpath("//span[contains(@class, 'app-sidebar-tabs__tab') and normalize-space() = '$tabHeaderName']")-> - descendantOf(self::tabHeadersInDetailsView())-> - describedAs("Tab header named $tabHeaderName in details view in Files app"); - } - - /** - * @return Locator - */ - private static function tabHeadersInDetailsView() { - return Locator::forThe()->css(".app-sidebar-tabs__nav")-> - descendantOf(self::detailsView())-> - describedAs("Tab headers in details view in Files app"); - } - - /** - * @return Locator - */ - public static function tabInDetailsViewNamed($tabName) { - return Locator::forThe()->xpath("//div[contains(concat(' ', normalize-space(@class), ' '), ' app-sidebar-tabs__content ')]/section[@aria-labelledby = '$tabName' and @role = 'tabpanel']")-> - descendantOf(self::detailsView())-> - describedAs("Tab named $tabName in details view in Files app"); - } - - /** - * @return Locator - */ - public static function loadingIconForTabInDetailsViewNamed($tabName) { - return Locator::forThe()->css(".icon-loading")-> - descendantOf(self::tabInDetailsViewNamed($tabName))-> - describedAs("Loading icon for tab named $tabName in details view in Files app"); - } - - /** - * @Given I open the Files app - */ - public function iOpenTheFilesApp() { - $this->actor->find(self::filesItemInAppMenu(), 10)->click(); - } - - /** - * @Given I close the details view - */ - public function iCloseTheDetailsView() { - $this->actor->find(self::closeDetailsViewButton(), 10)->click(); - } - - /** - * @Given I open the input field for tags in the details view - */ - public function iOpenTheInputFieldForTagsInTheDetailsView() { - $this->actor->find(self::fileDetailsInDetailsViewWithText("Tags"), 10)->click(); - } - - /** - * @Given I open the :tabName tab in the details view - */ - public function iOpenTheTabInTheDetailsView($tabName) { - $this->actor->find(self::tabHeaderInDetailsViewNamed($tabName), 10)->click(); - } - - /** - * @When I mark the file as favorite in the details view - */ - public function iMarkTheFileAsFavoriteInTheDetailsView() { - $this->iSeeThatTheFileIsNotMarkedAsFavoriteInTheDetailsView(); - - $this->actor->find(self::favoriteActionInFileDetailsInDetailsView(), 10)->click(); - } - - /** - * @When I unmark the file as favorite in the details view - */ - public function iUnmarkTheFileAsFavoriteInTheDetailsView() { - $this->iSeeThatTheFileIsMarkedAsFavoriteInTheDetailsView(); - - $this->actor->find(self::favoriteActionInFileDetailsInDetailsView(), 10)->click(); - } - - /** - * @When I check the tag :tag in the dropdown for tags in the details view - */ - public function iCheckTheTagInTheDropdownForTagsInTheDetailsView($tag) { - $this->iSeeThatTheTagInTheDropdownForTagsInTheDetailsViewIsNotChecked($tag); - - $this->actor->find(self::itemInDropdownForTag($tag), 10)->click(); - } - - /** - * @When I uncheck the tag :tag in the dropdown for tags in the details view - */ - public function iUncheckTheTagInTheDropdownForTagsInTheDetailsView($tag) { - $this->iSeeThatTheTagInTheDropdownForTagsInTheDetailsViewIsChecked($tag); - - $this->actor->find(self::itemInDropdownForTag($tag), 10)->click(); - } - - /** - * @Then I see that the current page is the Files app - */ - public function iSeeThatTheCurrentPageIsTheFilesApp() { - Assert::assertStringStartsWith( - $this->actor->locatePath("/apps/files/"), - $this->actor->getSession()->getCurrentUrl()); - - $this->setFileListAncestorForActor(self::currentSectionMainView(), $this->actor); - } - - /** - * @Then I see that the details view is open - */ - public function iSeeThatTheDetailsViewIsOpen() { - // The sidebar always exists in the DOM, so it has to be explicitly - // waited for it to be visible instead of relying on the implicit wait - // made to find the element. - if (!WaitFor::elementToBeEventuallyShown( - $this->actor, - self::detailsView(), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The details view is not open yet after $timeout seconds"); - } - } - - /** - * @Then I see that the details view is closed - */ - public function iSeeThatTheDetailsViewIsClosed() { - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::detailsView(), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The details view is not closed yet after $timeout seconds"); - } - } - - /** - * @Then I see that the file name shown in the details view is :fileName - */ - public function iSeeThatTheFileNameShownInTheDetailsViewIs($fileName) { - Assert::assertEquals( - $this->actor->find(self::fileNameInDetailsView(), 10)->getText(), $fileName); - } - - /** - * @Then I see that the file is marked as favorite in the details view - */ - public function iSeeThatTheFileIsMarkedAsFavoriteInTheDetailsView() { - Assert::assertNotNull( - $this->actor->find(self::favoritedStateIconInFileDetailsInDetailsView(), 10)); - } - - /** - * @Then I see that the file is not marked as favorite in the details view - */ - public function iSeeThatTheFileIsNotMarkedAsFavoriteInTheDetailsView() { - Assert::assertNotNull( - $this->actor->find(self::notFavoritedStateIconInFileDetailsInDetailsView(), 10)); - } - - /** - * @Then I see that the input field for tags in the details view is shown - */ - public function iSeeThatTheInputFieldForTagsInTheDetailsViewIsShown() { - Assert::assertTrue( - $this->actor->find(self::inputFieldForTagsInDetailsView(), 10)->isVisible()); - } - - /** - * @Then I see that the input field for tags in the details view contains the tag :tag - */ - public function iSeeThatTheInputFieldForTagsInTheDetailsViewContainsTheTag($tag) { - Assert::assertTrue( - $this->actor->find(self::itemInInputFieldForTagsInDetailsViewForTag($tag), 10)->isVisible()); - } - - /** - * @Then I see that the input field for tags in the details view does not contain the tag :tag - */ - public function iSeeThatTheInputFieldForTagsInTheDetailsViewDoesNotContainTheTag($tag) { - $this->iSeeThatTheInputFieldForTagsInTheDetailsViewIsShown(); - - try { - Assert::assertFalse( - $this->actor->find(self::itemInInputFieldForTagsInDetailsViewForTag($tag))->isVisible()); - } catch (NoSuchElementException $exception) { - } - } - - /** - * @Then I see that the tag :tag in the dropdown for tags in the details view is checked - */ - public function iSeeThatTheTagInTheDropdownForTagsInTheDetailsViewIsChecked($tag) { - Assert::assertTrue( - $this->actor->find(self::checkmarkInItemInDropdownForTag($tag), 10)->isVisible()); - } - - /** - * @Then I see that the tag :tag in the dropdown for tags in the details view is not checked - */ - public function iSeeThatTheTagInTheDropdownForTagsInTheDetailsViewIsNotChecked($tag) { - Assert::assertTrue( - $this->actor->find(self::itemInDropdownForTag($tag), 10)->isVisible()); - - Assert::assertFalse( - $this->actor->find(self::checkmarkInItemInDropdownForTag($tag))->isVisible()); - } - - /** - * @When I see that the :tabName tab in the details view is eventually loaded - */ - public function iSeeThatTheTabInTheDetailsViewIsEventuallyLoaded($tabName) { - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::loadingIconForTabInDetailsViewNamed($tabName), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The $tabName tab in the details view has not been loaded after $timeout seconds"); - } - } -} diff --git a/tests/acceptance/features/bootstrap/FilesAppSharingContext.php b/tests/acceptance/features/bootstrap/FilesAppSharingContext.php deleted file mode 100644 index 3c2b4a8633f..00000000000 --- a/tests/acceptance/features/bootstrap/FilesAppSharingContext.php +++ /dev/null @@ -1,811 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; -use WebDriver\Key; - -class FilesAppSharingContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function sharedByLabel() { - return Locator::forThe()->css(".sharing-entry__reshare")-> - descendantOf(FilesAppContext::detailsView())-> - describedAs("Shared by label in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function shareWithInput() { - return Locator::forThe()->css(".sharing-search__input input")-> - descendantOf(FilesAppContext::detailsView())-> - describedAs("Share with input in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function shareWithInputResults() { - return Locator::forThe()->css(".vs__dropdown-menu")-> - describedAs("Share with input results list in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function shareWithInputResult($result) { - return Locator::forThe()->xpath("//li//span[normalize-space() = '$result']/ancestor::li")-> - descendantOf(self::shareWithInputResults())-> - describedAs("Share with input result from the results list in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function shareeList() { - return Locator::forThe()->css(".sharing-sharee-list")-> - descendantOf(FilesAppContext::detailsView())-> - describedAs("Sharee list in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function sharedWithRow($sharedWithName) { - // "username" class is used for any type of share, not only for shares - // with users. - return Locator::forThe()->xpath("//li[contains(concat(' ', normalize-space(@class), ' '), ' sharing-entry ')]//span[normalize-space() = '$sharedWithName']/ancestor::li")-> - descendantOf(self::shareeList())-> - describedAs("Shared with $sharedWithName row in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function shareWithMenuTrigger($sharedWithName) { - return Locator::forThe()->css(".sharing-entry__actions button")-> - descendantOf(self::sharedWithRow($sharedWithName))-> - describedAs("Share with $sharedWithName menu trigger in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function shareWithMenuButton($sharedWithName) { - return Locator::forThe()->css(".action-item__menutoggle")-> - descendantOf(self::shareWithMenuTrigger($sharedWithName))-> - describedAs("Share with $sharedWithName menu button in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function shareWithMenu($sharedWithName, $shareWithMenuTriggerElement) { - return Locator::forThe()->xpath("//*[@id = " . $shareWithMenuTriggerElement->getWrappedElement()->getXpath() . "/@aria-describedby]")-> - describedAs("Share with $sharedWithName menu in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function permissionCheckboxFor($sharedWithName, $shareWithMenuTriggerElement, $itemText) { - // forThe()->checkbox($itemText) can not be used here; that would return - // the checkbox itself, but the element that the user interacts with is - // the label. - return Locator::forThe()->xpath("//label[normalize-space() = '$itemText']")-> - descendantOf(self::shareWithMenu($sharedWithName, $shareWithMenuTriggerElement))-> - describedAs("$itemText checkbox in the share with $sharedWithName menu in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function permissionCheckboxInputFor($sharedWithName, $shareWithMenuTriggerElement, $itemText) { - return Locator::forThe()->checkbox($itemText)-> - descendantOf(self::shareWithMenu($sharedWithName, $shareWithMenuTriggerElement))-> - describedAs("$itemText checkbox input in the share with $sharedWithName menu in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function canEditCheckbox($sharedWithName, $shareWithMenuTriggerElement) { - return self::permissionCheckboxFor($sharedWithName, $shareWithMenuTriggerElement, 'Allow editing'); - } - - /** - * @return Locator - */ - public static function canEditCheckboxInput($sharedWithName, $shareWithMenuTriggerElement) { - return self::permissionCheckboxInputFor($sharedWithName, $shareWithMenuTriggerElement, 'Allow editing'); - } - - /** - * @return Locator - */ - public static function canCreateCheckbox($sharedWithName, $shareWithMenuTriggerElement) { - return self::permissionCheckboxFor($sharedWithName, $shareWithMenuTriggerElement, 'Allow creating'); - } - - /** - * @return Locator - */ - public static function canCreateCheckboxInput($sharedWithName, $shareWithMenuTriggerElement) { - return self::permissionCheckboxInputFor($sharedWithName, $shareWithMenuTriggerElement, 'Allow creating'); - } - - /** - * @return Locator - */ - public static function canReshareCheckbox($sharedWithName, $shareWithMenuTriggerElement) { - return self::permissionCheckboxFor($sharedWithName, $shareWithMenuTriggerElement, 'Allow resharing'); - } - - /** - * @return Locator - */ - public static function canReshareCheckboxInput($sharedWithName, $shareWithMenuTriggerElement) { - return self::permissionCheckboxInputFor($sharedWithName, $shareWithMenuTriggerElement, 'Allow resharing'); - } - - /** - * @return Locator - */ - public static function unshareButton($sharedWithName, $shareWithMenuTriggerElement) { - return Locator::forThe()->xpath("//li[contains(concat(' ', normalize-space(@class), ' '), ' action ')]//button[normalize-space() = 'Unshare']")-> - descendantOf(self::shareWithMenu($sharedWithName, $shareWithMenuTriggerElement))-> - describedAs("Unshare button in the share with $sharedWithName menu in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function shareLinkRow() { - return Locator::forThe()->css(".sharing-link-list .sharing-entry__link:first-child")-> - descendantOf(FilesAppContext::detailsView())-> - describedAs("Share link row in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function shareLinkAddNewButton() { - // When there is no link share the "Add new share" item is shown instead - // of the menu button as a direct child of ".share-menu". - return Locator::forThe()->css(".action-item.new-share-link")-> - descendantOf(self::shareLinkRow())-> - describedAs("Add new share link button in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function copyLinkButton() { - return Locator::forThe()->css("a.sharing-entry__copy")-> - descendantOf(self::shareLinkRow())-> - describedAs("Copy link button in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function shareLinkMenuTrigger() { - return Locator::forThe()->css(".sharing-entry__actions .action-item__menutoggle")-> - descendantOf(self::shareLinkRow())-> - describedAs("Share link menu trigger in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function shareLinkSingleUnshareAction() { - return Locator::forThe()->css(".sharing-entry__actions.icon-close")-> - descendantOf(self::shareLinkRow())-> - describedAs("Unshare link single action in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function shareLinkMenuButton() { - return Locator::forThe()->css(".action-item__menutoggle")-> - descendantOf(self::shareLinkMenuTrigger())-> - describedAs("Share link menu button in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function shareLinkMenu($shareLinkMenuTriggerElement) { - return Locator::forThe()->xpath("//*[@id = " . $shareLinkMenuTriggerElement->getWrappedElement()->getXpath() . "/@aria-describedby]")-> - describedAs("Share link menu in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function hideDownloadCheckbox($shareLinkMenuTriggerElement) { - // forThe()->checkbox("Hide download") can not be used here; that would - // return the checkbox itself, but the element that the user interacts - // with is the label. - return Locator::forThe()->xpath("//label[normalize-space() = 'Hide download']")-> - descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))-> - describedAs("Hide download checkbox in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function hideDownloadCheckboxInput($shareLinkMenuTriggerElement) { - return Locator::forThe()->checkbox("Hide download")-> - descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))-> - describedAs("Hide download checkbox input in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function allowUploadAndEditingRadioButton($shareLinkMenuTriggerElement) { - // forThe()->radio("Allow upload and editing") can not be used here; - // that would return the radio button itself, but the element that the - // user interacts with is the label. - return Locator::forThe()->xpath("//label[normalize-space() = 'Allow upload and editing']")-> - descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))-> - describedAs("Allow upload and editing radio button in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function passwordProtectCheckbox($shareLinkMenuTriggerElement) { - // forThe()->checkbox("Password protect") can not be used here; that - // would return the checkbox itself, but the element that the user - // interacts with is the label. - return Locator::forThe()->xpath("//label[normalize-space() = 'Password protect']")-> - descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))-> - describedAs("Password protect checkbox in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function passwordProtectCheckboxInput($shareLinkMenuTriggerElement) { - return Locator::forThe()->checkbox("Password protect")-> - descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))-> - describedAs("Password protect checkbox input in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function passwordProtectField($shareLinkMenuTriggerElement) { - return Locator::forThe()->css(".share-link-password input.input-field__input")->descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))-> - describedAs("Password protect field in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function disabledPasswordProtectField($shareLinkMenuTriggerElement) { - return Locator::forThe()->css(".share-link-password input.input-field__input[disabled]")->descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))-> - describedAs("Disabled password protect field in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function passwordProtectByTalkCheckbox($shareLinkMenuTriggerElement) { - // forThe()->checkbox("Password protect by Talk") can not be used here; - // that would return the checkbox itself, but the element that the user - // interacts with is the label. - return Locator::forThe()->xpath("//label[normalize-space() = 'Password protect by Talk']")-> - descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))-> - describedAs("Password protect by Talk checkbox in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function passwordProtectByTalkCheckboxInput($shareLinkMenuTriggerElement) { - return Locator::forThe()->checkbox("Password protect by Talk")-> - descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))-> - describedAs("Password protect by Talk checkbox input in the details view in Files app"); - } - - /** - * @return Locator - */ - public static function unshareLinkButton($shareLinkMenuTriggerElement) { - return Locator::forThe()->xpath("//li[contains(concat(' ', normalize-space(@class), ' '), ' action ')]//button[normalize-space() = 'Unshare']")-> - descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))-> - describedAs("Unshare link button in the details view in Files app"); - } - - /** - * @Given I share the link for :fileName - */ - public function iShareTheLinkFor($fileName) { - $this->actor->find(FileListContext::shareActionForFile(FilesAppContext::currentSectionMainView(), $fileName), 10)->click(); - - $this->actor->find(self::shareLinkAddNewButton(), 5)->click(); - } - - /** - * @Given I share :fileName with :shareWithName - */ - public function iShareWith($fileName, $shareWithName) { - $this->actor->find(FileListContext::shareActionForFile(FilesAppContext::currentSectionMainView(), $fileName), 10)->click(); - - $this->actor->find(self::shareWithInput(), 5)->setValue($shareWithName); - // "setValue()" ends sending a tab, which unfocuses the input and causes - // the results to be hidden, so the input needs to be clicked to show - // the results again. - $this->actor->find(self::shareWithInput())->click(); - $this->actor->find(self::shareWithInputResult($shareWithName), 5)->click(); - } - - /** - * @Given I write down the shared link - */ - public function iWriteDownTheSharedLink() { - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2); - - // Close the share link menu if it is open to ensure that it does not - // cover the copy link button. - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::shareLinkMenu($shareLinkMenuTriggerElement), - $timeout = 2 * $this->actor->getFindTimeoutMultiplier())) { - // It may not be possible to click on the menu button (due to the - // menu itself covering it), so "Enter" key is pressed instead. - $this->actor->find(self::shareLinkMenuButton(), 2)->getWrappedElement()->keyPress(13); - } - - $this->actor->find(self::copyLinkButton(), 10)->click(); - - // Clicking on the menu item copies the link to the clipboard, but it is - // not possible to access that value from the acceptance tests. Due to - // this the value of the attribute that holds the URL is used instead. - $this->actor->getSharedNotebook()["shared link"] = $this->actor->find(self::copyLinkButton(), 2)->getWrappedElement()->getAttribute("href"); - } - - /** - * @When I set the download of the shared link as hidden - */ - public function iSetTheDownloadOfTheSharedLinkAsHidden() { - $this->showShareLinkMenuIfNeeded(); - - $this->iSeeThatTheDownloadOfTheLinkShareIsShown(); - - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2); - $this->actor->find(self::hideDownloadCheckbox($shareLinkMenuTriggerElement), 2)->click(); - } - - /** - * @When I set the download of the shared link as shown - */ - public function iSetTheDownloadOfTheSharedLinkAsShown() { - $this->showShareLinkMenuIfNeeded(); - - $this->iSeeThatTheDownloadOfTheLinkShareIsHidden(); - - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2); - $this->actor->find(self::hideDownloadCheckbox($shareLinkMenuTriggerElement), 2)->click(); - } - - /** - * @When I set the shared link as editable - */ - public function iSetTheSharedLinkAsEditable() { - $this->showShareLinkMenuIfNeeded(); - - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2); - $this->actor->find(self::allowUploadAndEditingRadioButton($shareLinkMenuTriggerElement), 2)->click(); - } - - /** - * @When I protect the shared link with the password :password - */ - public function iProtectTheSharedLinkWithThePassword($password) { - $this->showShareLinkMenuIfNeeded(); - - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2); - $this->actor->find(self::passwordProtectCheckbox($shareLinkMenuTriggerElement), 2)->click(); - - $this->actor->find(self::passwordProtectField($shareLinkMenuTriggerElement), 2)->setValue($password . Key::ENTER); - } - - /** - * @When I set the password of the shared link as protected by Talk - */ - public function iSetThePasswordOfTheSharedLinkAsProtectedByTalk() { - $this->showShareLinkMenuIfNeeded(); - - $this->iSeeThatThePasswordOfTheLinkShareIsNotProtectedByTalk(); - - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2); - $this->actor->find(self::passwordProtectByTalkCheckbox($shareLinkMenuTriggerElement), 2)->click(); - } - - /** - * @When I set the password of the shared link as not protected by Talk - */ - public function iSetThePasswordOfTheSharedLinkAsNotProtectedByTalk() { - $this->showShareLinkMenuIfNeeded(); - - $this->iSeeThatThePasswordOfTheLinkShareIsProtectedByTalk(); - - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2); - $this->actor->find(self::passwordProtectByTalkCheckbox($shareLinkMenuTriggerElement), 2)->click(); - } - - /** - * @When I set the share with :shareWithName as not editable - */ - public function iSetTheShareWithAsNotEditable($shareWithName) { - $this->showShareWithMenuIfNeeded($shareWithName); - - $this->iSeeThatCanEditTheShare($shareWithName); - - $shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($shareWithName), 2); - $this->actor->find(self::canEditCheckbox($shareWithName, $shareWithMenuTriggerElement), 2)->click(); - } - - /** - * @When I set the share with :shareWithName as not creatable - */ - public function iSetTheShareWithAsNotCreatable($shareWithName) { - $this->showShareWithMenuIfNeeded($shareWithName); - - $this->iSeeThatCanCreateInTheShare($shareWithName); - - $shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($shareWithName), 2); - $this->actor->find(self::canCreateCheckbox($shareWithName, $shareWithMenuTriggerElement), 2)->click(); - } - - /** - * @When I set the share with :shareWithName as not reshareable - */ - public function iSetTheShareWithAsNotReshareable($shareWithName) { - $this->showShareWithMenuIfNeeded($shareWithName); - - $this->iSeeThatCanReshareTheShare($shareWithName); - - $shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($shareWithName), 2); - $this->actor->find(self::canReshareCheckbox($shareWithName, $shareWithMenuTriggerElement), 2)->click(); - } - - /** - * @When I unshare the share with :shareWithName - */ - public function iUnshareTheFileWith($shareWithName) { - $this->showShareWithMenuIfNeeded($shareWithName); - - $shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($shareWithName), 2); - $this->actor->find(self::unshareButton($shareWithName, $shareWithMenuTriggerElement), 2)->click(); - } - - /** - * @When I unshare the link share - */ - public function iUnshareTheLink() { - try { - $this->actor->find(self::shareLinkSingleUnshareAction(), 2)->click(); - } catch (NoSuchElementException $e) { - $this->showShareLinkMenuIfNeeded(); - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2); - $this->actor->find(self::unshareLinkButton($shareLinkMenuTriggerElement), 2)->click(); - } - } - - /** - * @Then I see that the file is shared with me by :sharedByName - */ - public function iSeeThatTheFileIsSharedWithMeBy($sharedByName) { - Assert::assertEquals( - $this->actor->find(self::sharedByLabel(), 10)->getText(), "Shared with you by $sharedByName"); - } - - /** - * @Then I see that the file is shared with :sharedWithName - */ - public function iSeeThatTheFileIsSharedWith($sharedWithName) { - Assert::assertTrue( - $this->actor->find(self::sharedWithRow($sharedWithName), 10)->isVisible()); - } - - /** - * @Then I see that the file is not shared with :sharedWithName - */ - public function iSeeThatTheFileIsNotSharedWith($sharedWithName) { - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::sharedWithRow($sharedWithName), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The shared with $sharedWithName row is still shown after $timeout seconds"); - } - } - - /** - * @Then I see that resharing the file is not allowed - */ - public function iSeeThatResharingTheFileIsNotAllowed() { - Assert::assertEquals( - $this->actor->find(self::shareWithInput(), 10)->getWrappedElement()->getAttribute("disabled"), "disabled"); - Assert::assertEquals( - $this->actor->find(self::shareWithInput(), 10)->getWrappedElement()->getAttribute("placeholder"), "Resharing is not allowed"); - } - - /** - * @Then I see that resharing the file by link is not available - */ - public function iSeeThatResharingTheFileByLinkIsNotAvailable() { - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::shareLinkAddNewButton(), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The add new share link button is still shown after $timeout seconds"); - } - } - - /** - * @Then I see that :sharedWithName can not be allowed to edit the share - */ - public function iSeeThatCanNotBeAllowedToEditTheShare($sharedWithName) { - $this->showShareWithMenuIfNeeded($sharedWithName); - - $shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10); - Assert::assertEquals( - $this->actor->find(self::canEditCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->getWrappedElement()->getAttribute("disabled"), "disabled"); - } - - /** - * @Then I see that :sharedWithName can edit the share - */ - public function iSeeThatCanEditTheShare($sharedWithName) { - $this->showShareWithMenuIfNeeded($sharedWithName); - - $shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10); - Assert::assertTrue( - $this->actor->find(self::canEditCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->isChecked()); - } - - /** - * @Then I see that :sharedWithName can not edit the share - */ - public function iSeeThatCanNotEditTheShare($sharedWithName) { - $this->showShareWithMenuIfNeeded($sharedWithName); - - $shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10); - Assert::assertFalse( - $this->actor->find(self::canEditCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->isChecked()); - } - - /** - * @Then I see that :sharedWithName can not be allowed to create in the share - */ - public function iSeeThatCanNotBeAllowedToCreateInTheShare($sharedWithName) { - $this->showShareWithMenuIfNeeded($sharedWithName); - - $shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10); - Assert::assertEquals( - $this->actor->find(self::canCreateCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->getWrappedElement()->getAttribute("disabled"), "disabled"); - } - - /** - * @Then I see that :sharedWithName can create in the share - */ - public function iSeeThatCanCreateInTheShare($sharedWithName) { - $this->showShareWithMenuIfNeeded($sharedWithName); - - $shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10); - Assert::assertTrue( - $this->actor->find(self::canCreateCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->isChecked()); - } - - /** - * @Then I see that :sharedWithName can not create in the share - */ - public function iSeeThatCanNotCreateInTheShare($sharedWithName) { - $this->showShareWithMenuIfNeeded($sharedWithName); - - $shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10); - Assert::assertFalse( - $this->actor->find(self::canCreateCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->isChecked()); - } - - /** - * @Then I see that resharing for :sharedWithName is not available - */ - public function iSeeThatResharingForIsNotAvailable($sharedWithName) { - $this->showShareWithMenuIfNeeded($sharedWithName); - - $shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10); - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::canReshareCheckbox($sharedWithName, $shareWithMenuTriggerElement), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The resharing checkbox for $sharedWithName is still shown after $timeout seconds"); - } - } - - /** - * @Then I see that :sharedWithName can reshare the share - */ - public function iSeeThatCanReshareTheShare($sharedWithName) { - $this->showShareWithMenuIfNeeded($sharedWithName); - - $shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10); - Assert::assertTrue( - $this->actor->find(self::canReshareCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->isChecked()); - } - - /** - * @Then I see that :sharedWithName can not reshare the share - */ - public function iSeeThatCanNotReshareTheShare($sharedWithName) { - $this->showShareWithMenuIfNeeded($sharedWithName); - - $shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10); - Assert::assertFalse( - $this->actor->find(self::canReshareCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->isChecked()); - } - - /** - * @Then I see that the download of the link share is hidden - */ - public function iSeeThatTheDownloadOfTheLinkShareIsHidden() { - $this->showShareLinkMenuIfNeeded(); - - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 10); - Assert::assertTrue($this->actor->find(self::hideDownloadCheckboxInput($shareLinkMenuTriggerElement), 10)->isChecked()); - } - - /** - * @Then I see that the download of the link share is shown - */ - public function iSeeThatTheDownloadOfTheLinkShareIsShown() { - $this->showShareLinkMenuIfNeeded(); - - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 10); - Assert::assertFalse($this->actor->find(self::hideDownloadCheckboxInput($shareLinkMenuTriggerElement), 10)->isChecked()); - } - - /** - * @Then I see that the password protect is disabled while loading - */ - public function iSeeThatThePasswordProtectIsDisabledWhileLoading() { - // Due to the additional time needed to find the menu trigger element it - // could happen that the request to modify the password protect was - // completed and the field enabled again even before finding the - // disabled field started. Therefore, if the disabled field could not be - // found it is just assumed that it was already enabled again. - // Nevertheless, this check should be done anyway to ensure that the - // following scenario steps are not executed before the request to the - // server was done. - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 10); - - try { - $this->actor->find(self::disabledPasswordProtectField($shareLinkMenuTriggerElement), 5); - } catch (NoSuchElementException $exception) { - echo "The password protect field was not found disabled after " . (5 * $this->actor->getFindTimeoutMultiplier()) . " seconds, assumming that it was disabled and enabled again before the check started and continuing"; - - return; - } - - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::disabledPasswordProtectField($shareLinkMenuTriggerElement), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The password protect field is still disabled after $timeout seconds"); - } - } - - /** - * @Then I see that the link share is password protected - */ - public function iSeeThatTheLinkShareIsPasswordProtected() { - $this->showShareLinkMenuIfNeeded(); - - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 10); - Assert::assertTrue($this->actor->find(self::passwordProtectCheckboxInput($shareLinkMenuTriggerElement), 10)->isChecked(), "Password protect checkbox is checked"); - Assert::assertTrue($this->actor->find(self::passwordProtectField($shareLinkMenuTriggerElement), 10)->isVisible(), "Password protect field is visible"); - } - - /** - * @Then I see that the password of the link share is protected by Talk - */ - public function iSeeThatThePasswordOfTheLinkShareIsProtectedByTalk() { - $this->showShareLinkMenuIfNeeded(); - - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 10); - Assert::assertTrue($this->actor->find(self::passwordProtectByTalkCheckboxInput($shareLinkMenuTriggerElement), 10)->isChecked()); - } - - /** - * @Then I see that the password of the link share is not protected by Talk - */ - public function iSeeThatThePasswordOfTheLinkShareIsNotProtectedByTalk() { - $this->showShareLinkMenuIfNeeded(); - - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 10); - Assert::assertFalse($this->actor->find(self::passwordProtectByTalkCheckboxInput($shareLinkMenuTriggerElement), 10)->isChecked()); - } - - /** - * @Then I see that the checkbox to protect the password of the link share by Talk is not shown - */ - public function iSeeThatTheCheckboxToProtectThePasswordOfTheLinkShareByTalkIsNotShown() { - $this->showShareLinkMenuIfNeeded(); - - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 10); - try { - Assert::assertFalse( - $this->actor->find(self::passwordProtectByTalkCheckbox($shareLinkMenuTriggerElement))->isVisible()); - } catch (NoSuchElementException $exception) { - } - } - - /** - * @Given I share the link for :fileName protected by the password :password - */ - public function iShareTheLinkForProtectedByThePassword($fileName, $password) { - $this->iShareTheLinkFor($fileName); - $this->iProtectTheSharedLinkWithThePassword($password); - $this->iSeeThatThePasswordProtectIsDisabledWhileLoading(); - } - - private function showShareLinkMenuIfNeeded() { - $shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2); - - // In some cases the share menu is hidden after clicking on an action of - // the menu. Therefore, if the menu is visible, wait a little just in - // case it is in the process of being hidden due to a previous action, - // in which case it is shown again. - if (WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::shareLinkMenu($shareLinkMenuTriggerElement), - $timeout = 2 * $this->actor->getFindTimeoutMultiplier())) { - $this->actor->find(self::shareLinkMenuButton(), 10)->click(); - } - } - - private function showShareWithMenuIfNeeded($shareWithName) { - $shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($shareWithName), 2); - - // In some cases the share menu is hidden after clicking on an action of - // the menu. Therefore, if the menu is visible, wait a little just in - // case it is in the process of being hidden due to a previous action, - // in which case it is shown again. - if (WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::shareWithMenu($shareWithName, $shareWithMenuTriggerElement), - $timeout = 2 * $this->actor->getFindTimeoutMultiplier())) { - $this->actor->find(self::shareWithMenuButton($shareWithName), 10)->click(); - } - } -} diff --git a/tests/acceptance/features/bootstrap/LoginPageContext.php b/tests/acceptance/features/bootstrap/LoginPageContext.php deleted file mode 100644 index fc924bbff80..00000000000 --- a/tests/acceptance/features/bootstrap/LoginPageContext.php +++ /dev/null @@ -1,149 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use Behat\Behat\Hook\Scope\BeforeScenarioScope; -use PHPUnit\Framework\Assert; - -class LoginPageContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @var FeatureContext - */ - private $featureContext; - - /** - * @var FilesAppContext - */ - private $filesAppContext; - - public static function userNameField(): Locator { - return Locator::forThe()->field("user")-> - describedAs("User name field in Login page"); - } - - public static function passwordField(): Locator { - return Locator::forThe()->field("password")-> - describedAs("Password field in Login page"); - } - - public static function loginButton(): Locator { - return Locator::forThe()->css(".button-vue[type='submit']")-> - describedAs("Login button in Login page"); - } - - public static function wrongPasswordMessage(): Locator { - return Locator::forThe()->xpath("//*[@class = 'input-field__helper-text-message input-field__helper-text-message--error' and normalize-space() = 'Wrong username or password.']")-> - describedAs("Wrong password message in Login page"); - } - - /** - * @return Locator - */ - public static function userDisabledMessage() { - return Locator::forThe()->xpath("//*[@class = 'input-field__helper-text-message input-field__helper-text-message--error' and normalize-space() = 'User disabled']")-> - describedAs('User disabled message on login page'); - } - - /** - * @When I log in with user :user and password :password - */ - public function iLogInWithUserAndPassword(string $user, string $password): void { - $this->actor->find(self::userNameField(), 10)->setValue($user); - $this->actor->find(self::passwordField())->setValue($password); - $this->actor->find(self::loginButton())->click(); - } - - /** - * @Then I see that the current page is the Login page - */ - public function iSeeThatTheCurrentPageIsTheLoginPage() { - Assert::assertStringStartsWith( - $this->actor->locatePath("/login"), - $this->actor->getSession()->getCurrentUrl()); - } - - /** - * @Then I see that a wrong password message is shown - */ - public function iSeeThatAWrongPasswordMessageIsShown() { - Assert::assertTrue( - $this->actor->find(self::wrongPasswordMessage(), 10)->isVisible()); - } - - /** - * @Then I see that the disabled user message is shown - */ - public function iSeeThatTheDisabledUserMessageIsShown() { - Assert::assertTrue( - $this->actor->find(self::userDisabledMessage(), 10)->isVisible()); - } - - /** - * @BeforeScenario - */ - public function getOtherRequiredSiblingContexts(BeforeScenarioScope $scope) { - $environment = $scope->getEnvironment(); - - $this->featureContext = $environment->getContext("FeatureContext"); - $this->filesAppContext = $environment->getContext("FilesAppContext"); - } - - /** - * @Given I am logged in - */ - public function iAmLoggedIn() { - $this->featureContext->iVisitTheHomePage(); - $this->iLogInWithUserAndPassword("user0", "123456acb"); - $this->filesAppContext->iSeeThatTheCurrentPageIsTheFilesApp(); - } - - /** - * @Given I am logged in as :userName - */ - public function iAmLoggedInAs($userName) { - $this->featureContext->iVisitTheHomePage(); - $this->iLogInWithUserAndPassword($userName, "123456acb"); - $this->filesAppContext->iSeeThatTheCurrentPageIsTheFilesApp(); - } - - /** - * @Given I am logged in as the admin - */ - public function iAmLoggedInAsTheAdmin() { - $this->featureContext->iVisitTheHomePage(); - $this->iLogInWithUserAndPassword("admin", "admin"); - $this->filesAppContext->iSeeThatTheCurrentPageIsTheFilesApp(); - } - - /** - * @Given I can not log in with user :user and password :password - */ - public function iCanNotLogInWithUserAndPassword($user, $password) { - $this->featureContext->iVisitTheHomePage(); - $this->iLogInWithUserAndPassword($user, $password); - $this->iSeeThatTheCurrentPageIsTheLoginPage(); - $this->iSeeThatAWrongPasswordMessageIsShown(); - } -} diff --git a/tests/acceptance/features/bootstrap/NotificationsContext.php b/tests/acceptance/features/bootstrap/NotificationsContext.php deleted file mode 100644 index fb8ca2a354f..00000000000 --- a/tests/acceptance/features/bootstrap/NotificationsContext.php +++ /dev/null @@ -1,96 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2019, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; - -class NotificationsContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function notificationsButton() { - return Locator::forThe()->css("#header #notifications.notifications-button")-> - describedAs("Notifications button in the header"); - } - - /** - * @return Locator - */ - public static function notificationsContainer() { - return Locator::forThe()->css("#header #notifications .notification-container")-> - describedAs("Notifications container"); - } - - /** - * @return Locator - */ - public static function incomingShareNotificationForFile($fileName) { - return Locator::forThe()->xpath("//li[contains(concat(' ', normalize-space(@class), ' '), ' notification ') and //div[starts-with(normalize-space(), 'You received $fileName as a share by')]]")-> - descendantOf(self::notificationsContainer())-> - describedAs("Notification of incoming share for file $fileName"); - } - - /** - * @return Locator - */ - public static function actionsInIncomingShareNotificationForFile($fileName) { - return Locator::forThe()->css(".notification-actions")-> - descendantOf(self::incomingShareNotificationForFile($fileName))-> - describedAs("Actions in notification of incoming share for file $fileName"); - } - - /** - * @return Locator - */ - public static function actionInIncomingShareNotificationForFile($fileName, $action) { - return Locator::forThe()->xpath("//button[normalize-space() = '$action']")-> - descendantOf(self::actionsInIncomingShareNotificationForFile($fileName))-> - describedAs("$action button in notification of incoming share for file $fileName"); - } - - /** - * @return Locator - */ - public static function acceptButtonInIncomingShareNotificationForFile($fileName) { - return self::actionInIncomingShareNotificationForFile($fileName, 'Accept'); - } - - /** - * @Given I accept the share for :fileName in the notifications - */ - public function iAcceptTheShareForInTheNotifications($fileName) { - $this->actor->find(self::notificationsButton(), 10)->click(); - - // Notifications are refreshed every 30 seconds, so wait a bit longer. - // As the waiting is long enough already the find timeout multiplier is - // capped at 2 when finding notifications. - $findTimeoutMultiplier = $this->actor->getFindTimeoutMultiplier(); - $this->actor->setFindTimeoutMultiplier(min(2, $findTimeoutMultiplier)); - $this->actor->find(self::acceptButtonInIncomingShareNotificationForFile($fileName), 35)->click(); - $this->actor->setFindTimeoutMultiplier($findTimeoutMultiplier); - - // Hide the notifications again - $this->actor->find(self::notificationsButton(), 10)->click(); - } -} diff --git a/tests/acceptance/features/bootstrap/PublicShareContext.php b/tests/acceptance/features/bootstrap/PublicShareContext.php deleted file mode 100644 index ce25afa792b..00000000000 --- a/tests/acceptance/features/bootstrap/PublicShareContext.php +++ /dev/null @@ -1,253 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; - -class PublicShareContext implements Context, ActorAwareInterface { - use ActorAware; - use FileListAncestorSetter; - - /** - * @return Locator - */ - public static function passwordField() { - return Locator::forThe()->field("password")-> - describedAs("Password field in Authenticate page"); - } - - /** - * @return Locator - */ - public static function authenticateButton() { - return Locator::forThe()->id("password-submit")-> - describedAs("Authenticate button in Authenticate page"); - } - - /** - * @return Locator - */ - public static function wrongPasswordMessage() { - return Locator::forThe()->css(".warning .wrongPasswordMsg")-> - describedAs("Wrong password message in Authenticate page"); - } - - /** - * @return Locator - */ - public static function shareMenuButton() { - return Locator::forThe()->id("header-actions-toggle")-> - describedAs("Share menu button in Shared file page"); - } - - /** - * @return Locator - */ - public static function shareMenu() { - return Locator::forThe()->id("header-actions-menu")-> - describedAs("Share menu in Shared file page"); - } - - /** - * @return Locator - */ - public static function downloadItemInShareMenu() { - return Locator::forThe()->id("download")-> - descendantOf(self::shareMenu())-> - describedAs("Download item in Share menu in Shared file page"); - } - - /** - * @return Locator - */ - public static function directLinkItemInShareMenu() { - return Locator::forThe()->id("directLink-container")-> - descendantOf(self::shareMenu())-> - describedAs("Direct link item in Share menu in Shared file page"); - } - - /** - * @return Locator - */ - public static function saveItemInShareMenu() { - return Locator::forThe()->id("save-external-share")-> - descendantOf(self::shareMenu())-> - describedAs("Save item in Share menu in Shared file page"); - } - - /** - * @return Locator - */ - public static function textPreview() { - return Locator::forThe()->css(".text-preview")-> - describedAs("Text preview in Shared file page"); - } - - /** - * @return Locator - */ - public static function downloadButton() { - return Locator::forThe()->id("downloadFile")-> - describedAs("Download button in Shared file page"); - } - - /** - * @When I visit the shared link I wrote down - */ - public function iVisitTheSharedLinkIWroteDown() { - $this->actor->getSession()->visit($this->actor->getSharedNotebook()["shared link"]); - } - - /** - * @When I visit the direct download shared link I wrote down - */ - public function iVisitTheDirectDownloadSharedLinkIWroteDown() { - $this->actor->getSession()->visit($this->actor->getSharedNotebook()["shared link"] . "/download"); - } - - /** - * @When I authenticate with password :password - */ - public function iAuthenticateWithPassword($password) { - $this->actor->find(self::passwordField(), 10)->setValue($password); - $this->actor->find(self::authenticateButton())->click(); - } - - /** - * @When I open the Share menu - */ - public function iOpenTheShareMenu() { - $this->actor->find(self::shareMenuButton(), 10)->click(); - } - - /** - * @Then I see that the current page is the Authenticate page for the shared link I wrote down - */ - public function iSeeThatTheCurrentPageIsTheAuthenticatePageForTheSharedLinkIWroteDown() { - Assert::assertEquals( - $this->actor->getSharedNotebook()["shared link"] . "/authenticate/showShare", - $this->actor->getSession()->getCurrentUrl()); - } - - /** - * @Then I see that the current page is the Authenticate page for the direct download shared link I wrote down - */ - public function iSeeThatTheCurrentPageIsTheAuthenticatePageForTheDirectDownloadSharedLinkIWroteDown() { - Assert::assertEquals( - $this->actor->getSharedNotebook()["shared link"] . "/authenticate/downloadShare", - $this->actor->getSession()->getCurrentUrl()); - } - - /** - * @Then I see that the current page is the shared link I wrote down - */ - public function iSeeThatTheCurrentPageIsTheSharedLinkIWroteDown() { - Assert::assertEquals( - $this->actor->getSharedNotebook()["shared link"], - $this->actor->getSession()->getCurrentUrl()); - - $this->setFileListAncestorForActor(null, $this->actor); - } - - /** - * @Then I see that the current page is the direct download shared link I wrote down - */ - public function iSeeThatTheCurrentPageIsTheDirectDownloadSharedLinkIWroteDown() { - Assert::assertEquals( - $this->actor->getSharedNotebook()["shared link"] . "/download", - $this->actor->getSession()->getCurrentUrl()); - } - - /** - * @Then I see that a wrong password for the shared file message is shown - */ - public function iSeeThatAWrongPasswordForTheSharedFileMessageIsShown() { - Assert::assertTrue( - $this->actor->find(self::wrongPasswordMessage(), 10)->isVisible()); - } - - /** - * @Then I see that the Share menu is shown - */ - public function iSeeThatTheShareMenuIsShown() { - // Unlike other menus, the Share menu is always present in the DOM, so - // the element could be found when it was no made visible yet due to the - // command not having been processed by the browser. - if (!WaitFor::elementToBeEventuallyShown( - $this->actor, self::shareMenu(), $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The Share menu is not visible yet after $timeout seconds"); - } - - // The acceptance tests are run in a window wider than the mobile breakpoint, so the - // download item should not be shown in the menu (although it will be in - // the DOM). - Assert::assertFalse( - $this->actor->find(self::downloadItemInShareMenu())->isVisible(), - "Download item in share menu is visible"); - Assert::assertTrue( - $this->actor->find(self::directLinkItemInShareMenu())->isVisible(), - "Direct link item in share menu is not visible"); - Assert::assertTrue( - $this->actor->find(self::saveItemInShareMenu())->isVisible(), - "Save item in share menu is not visible"); - } - - /** - * @Then I see that the Share menu button is not shown - */ - public function iSeeThatTheShareMenuButtonIsNotShown() { - try { - Assert::assertFalse( - $this->actor->find(self::shareMenuButton())->isVisible()); - } catch (NoSuchElementException $exception) { - } - } - - /** - * @Then I see that the shared file preview shows the text :text - */ - public function iSeeThatTheSharedFilePreviewShowsTheText($text) { - Assert::assertStringContainsString($text, $this->actor->find(self::textPreview(), 10)->getText()); - } - - /** - * @Then I see that the download button is shown - */ - public function iSeeThatTheDownloadButtonIsShown() { - if (!WaitFor::elementToBeEventuallyShown( - $this->actor, self::downloadButton(), $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The download button is not visible yet after $timeout seconds"); - } - } - - /** - * @Then I see that the download button is not shown - */ - public function iSeeThatTheDownloadButtonIsNotShown() { - try { - Assert::assertFalse( - $this->actor->find(self::downloadButton())->isVisible()); - } catch (NoSuchElementException $exception) { - } - } -} diff --git a/tests/acceptance/features/bootstrap/SearchContext.php b/tests/acceptance/features/bootstrap/SearchContext.php deleted file mode 100644 index f776c078c68..00000000000 --- a/tests/acceptance/features/bootstrap/SearchContext.php +++ /dev/null @@ -1,114 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; - -class SearchContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function searchBoxInput() { - return Locator::forThe()->css("#header .searchbox input")-> - describedAs("Search box input in the header"); - } - - /** - * @return Locator - */ - public static function searchResults() { - return Locator::forThe()->css("#searchresults")-> - describedAs("Search results"); - } - - /** - * @return Locator - */ - public static function searchResult($number) { - return Locator::forThe()->xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' result ')][$number]")-> - descendantOf(self::searchResults())-> - describedAs("Search result $number"); - } - - /** - * @return Locator - */ - public static function searchResultName($number) { - return Locator::forThe()->css(".name")-> - descendantOf(self::searchResult($number))-> - describedAs("Name for search result $number"); - } - - /** - * @return Locator - */ - public static function searchResultPath($number) { - // Currently search results for comments misuse the ".path" class to - // dim the user name, so "div.path" needs to be used to find the proper - // path element. - return Locator::forThe()->css("div.path")-> - descendantOf(self::searchResult($number))-> - describedAs("Path for search result $number"); - } - - /** - * @return Locator - */ - public static function searchResultLink($number) { - return Locator::forThe()->css(".link")-> - descendantOf(self::searchResult($number))-> - describedAs("Link for search result $number"); - } - - /** - * @When I search for :query - */ - public function iSearchFor($query) { - $this->actor->find(self::searchBoxInput(), 10)->setValue($query); - } - - /** - * @When I open the search result :number - */ - public function iOpenTheSearchResult($number) { - $this->actor->find(self::searchResultLink($number), 10)->click(); - } - - /** - * @Then I see that the search result :number is :name - */ - public function iSeeThatTheSearchResultIs($number, $name) { - Assert::assertEquals( - $name, $this->actor->find(self::searchResultName($number), 10)->getText()); - } - - /** - * @Then I see that the search result :number was found in :path - */ - public function iSeeThatTheSearchResultWasFoundIn($number, $path) { - Assert::assertEquals( - $path, $this->actor->find(self::searchResultPath($number), 10)->getText()); - } -} diff --git a/tests/acceptance/features/bootstrap/SettingsContext.php b/tests/acceptance/features/bootstrap/SettingsContext.php deleted file mode 100644 index ae1a559a360..00000000000 --- a/tests/acceptance/features/bootstrap/SettingsContext.php +++ /dev/null @@ -1,283 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; - -class SettingsContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function acceptSharesByDefaultCheckbox() { - // forThe()->checkbox("Accept user...") can not be used here; that would - // return the checkbox itself, but the element that the user interacts - // with is the label. - return Locator::forThe()->xpath("//label[normalize-space() = 'Accept user and group shares by default']")-> - describedAs("Accept shares by default checkbox in Sharing section in Personal Sharing Settings"); - } - - /** - * @return Locator - */ - public static function acceptSharesByDefaultCheckboxInput() { - return Locator::forThe()->checkbox("Accept user and group shares by default")-> - describedAs("Accept shares by default checkbox input in Sharing section in Personal Sharing Settings"); - } - - /** - * @return Locator - */ - public static function allowResharingCheckbox() { - // forThe()->checkbox("Allow resharing") can not be used here; that - // would return the checkbox itself, but the element that the user - // interacts with is the label. - return Locator::forThe()->xpath("//label[normalize-space() = 'Allow resharing']")-> - describedAs("Allow resharing checkbox in Sharing section in Administration Sharing Settings"); - } - - /** - * @return Locator - */ - public static function allowResharingCheckboxInput() { - return Locator::forThe()->checkbox("Allow resharing")-> - describedAs("Allow resharing checkbox input in Sharing section in Administration Sharing Settings"); - } - - /** - * @return Locator - */ - public static function restrictUsernameAutocompletionToGroupsCheckbox() { - // forThe()->checkbox("Restrict username...") can not be used here; that - // would return the checkbox itself, but the element that the user - // interacts with is the label. - return Locator::forThe()->xpath("//label[normalize-space() = 'Allow username autocompletion to users within the same groups']")-> - describedAs("Allow username autocompletion to users within the same groups checkbox in Sharing section in Administration Sharing Settings"); - } - - /** - * @return Locator - */ - public static function restrictUsernameAutocompletionToGroupsCheckboxInput() { - return Locator::forThe()->checkbox("Allow username autocompletion to users within the same groups")-> - describedAs("Allow username autocompletion to users within the same groups checkbox input in Sharing section in Administration Sharing Settings"); - } - - /** - * @return Locator - */ - public static function systemTagsSelectTagButton() { - return Locator::forThe()->id("s2id_systemtag")-> - describedAs("Select tag button in system tags section in Administration Settings"); - } - - /** - * @return Locator - */ - public static function systemTagsItemInDropdownForTag($tag) { - return Locator::forThe()->xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' select2-result-label ')]//span[normalize-space() = '$tag']/ancestor::li")-> - descendantOf(self::select2Dropdown())-> - describedAs("Item in dropdown for tag $tag in system tags section in Administration Settings"); - } - - /** - * @return Locator - */ - private static function select2Dropdown() { - return Locator::forThe()->css("#select2-drop")-> - describedAs("Select2 dropdown in Settings"); - } - - /** - * @return Locator - */ - private static function select2DropdownMask() { - return Locator::forThe()->css("#select2-drop-mask")-> - describedAs("Select2 dropdown mask in Settings"); - } - - /** - * @return Locator - */ - public static function systemTagsTagNameInput() { - return Locator::forThe()->id("systemtag_name")-> - describedAs("Tag name input in system tags section in Administration Settings"); - } - - /** - * @return Locator - */ - public static function systemTagsCreateOrUpdateButton() { - return Locator::forThe()->id("systemtag_submit")-> - describedAs("Create/Update button in system tags section in Administration Settings"); - } - - /** - * @return Locator - */ - public static function systemTagsResetButton() { - return Locator::forThe()->id("systemtag_reset")-> - describedAs("Reset button in system tags section in Administration Settings"); - } - - /** - * @When I disable accepting the shares by default - */ - public function iDisableAcceptingTheSharesByDefault() { - $this->iSeeThatSharesAreAcceptedByDefault(); - - $this->actor->find(self::acceptSharesByDefaultCheckbox(), 2)->click(); - } - - /** - * @When I disable resharing - */ - public function iDisableResharing() { - $this->iSeeThatResharingIsEnabled(); - - $this->actor->find(self::allowResharingCheckbox(), 2)->click(); - } - - /** - * @When I enable restricting username autocompletion to groups - */ - public function iEnableRestrictingUsernameAutocompletionToGroups() { - $this->iSeeThatUsernameAutocompletionIsNotRestrictedToGroups(); - - $this->actor->find(self::restrictUsernameAutocompletionToGroupsCheckbox(), 2)->click(); - } - - /** - * @When I create the tag :tag in the settings - */ - public function iCreateTheTagInTheSettings($tag) { - $this->actor->find(self::systemTagsResetButton(), 10)->click(); - $this->actor->find(self::systemTagsTagNameInput())->setValue($tag); - $this->actor->find(self::systemTagsCreateOrUpdateButton())->click(); - } - - /** - * @Then I see that shares are accepted by default - */ - public function iSeeThatSharesAreAcceptedByDefault() { - Assert::assertTrue( - $this->actor->find(self::acceptSharesByDefaultCheckboxInput(), 10)->isChecked()); - } - - /** - * @Then I see that resharing is enabled - */ - public function iSeeThatResharingIsEnabled() { - Assert::assertTrue( - $this->actor->find(self::allowResharingCheckboxInput(), 10)->isChecked()); - } - - /** - * @Then I see that resharing is disabled - */ - public function iSeeThatResharingIsDisabled() { - Assert::assertFalse( - $this->actor->find(self::allowResharingCheckboxInput(), 10)->isChecked()); - } - - /** - * @Then I see that username autocompletion is restricted to groups - */ - public function iSeeThatUsernameAutocompletionIsRestrictedToGroups() { - Assert::assertTrue( - $this->actor->find(self::restrictUsernameAutocompletionToGroupsCheckboxInput(), 10)->isChecked()); - } - - /** - * @Then I see that username autocompletion is not restricted to groups - */ - public function iSeeThatUsernameAutocompletionIsNotRestrictedToGroups() { - Assert::assertFalse( - $this->actor->find(self::restrictUsernameAutocompletionToGroupsCheckboxInput(), 10)->isChecked()); - } - - /** - * @Then I see that shares are not accepted by default - */ - public function iSeeThatSharesAreNotAcceptedByDefault() { - Assert::assertFalse( - $this->actor->find(self::acceptSharesByDefaultCheckboxInput(), 10)->isChecked()); - } - - /** - * @Then I see that the button to select tags is shown - */ - public function iSeeThatTheButtonToSelectTagsIsShown() { - Assert::assertTrue($this->actor->find(self::systemTagsSelectTagButton(), 10)->isVisible()); - } - - /** - * @Then I see that the dropdown for tags in the settings eventually contains the tag :tag - */ - public function iSeeThatTheDropdownForTagsInTheSettingsEventuallyContainsTheTag($tag) { - // When the dropdown is opened it is not automatically updated if new - // tags are added to the server, and when a tag is created, no explicit - // feedback is provided to the user about the completion of that - // operation (that is, when the tag is added to the server). Therefore, - // to verify that creating a tag does in fact add it to the server it is - // necessary to repeatedly open the dropdown until the tag is shown in - // the dropdown (or the limit of tries is reached). - - Assert::assertTrue($this->actor->find(self::systemTagsSelectTagButton(), 10)->isVisible()); - - $actor = $this->actor; - - $tagFoundInDropdownCallback = function () use ($actor, $tag) { - // Open the dropdown to look for the tag. - $actor->find(self::systemTagsSelectTagButton())->click(); - - // When the dropdown is opened it is initially empty, and its - // contents are updated once received from the server. Therefore, a - // timeout must be used when looking for the tags. - try { - $tagFound = $this->actor->find(self::systemTagsItemInDropdownForTag($tag), 10)->isVisible(); - } catch (NoSuchElementException $exception) { - $tagFound = false; - } - - // Close again the dropdown after looking for the tag. When a - // dropdown is opened Select2 creates a special element that masks - // every other element but the dropdown to get all mouse clicks; - // this is used by Select2 to close the dropdown when the user - // clicks outside it. - $actor->find(self::select2DropdownMask())->click(); - - return $tagFound; - }; - - $numberOfTries = 5; - for ($i = 0; $i < $numberOfTries; $i++) { - if ($tagFoundInDropdownCallback()) { - return; - } - } - - Assert::fail("The dropdown in system tags section in Administration Settings does not contain the tag $tag after $numberOfTries tries"); - } -} diff --git a/tests/acceptance/features/bootstrap/SettingsMenuContext.php b/tests/acceptance/features/bootstrap/SettingsMenuContext.php deleted file mode 100644 index dfd090f921a..00000000000 --- a/tests/acceptance/features/bootstrap/SettingsMenuContext.php +++ /dev/null @@ -1,228 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) (skjnldsv@protonmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; - -class SettingsMenuContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function settingsSectionInHeader() { - return Locator::forThe()->xpath("//*[@id = 'header']//*[@id = 'user-menu']")-> - describedAs("Settings menu section in the header"); - } - - /** - * @return Locator - */ - public static function settingsMenuButton() { - return Locator::forThe()->css(".header-menu__trigger")-> - descendantOf(self::settingsSectionInHeader())-> - describedAs("Settings menu button"); - } - - /** - * @return Locator - */ - public static function settingsMenu() { - return Locator::forThe()->css(".user-menu__nav")-> - descendantOf(self::settingsSectionInHeader())-> - describedAs("Settings menu"); - } - - /** - * @return Locator - */ - public static function usersMenuItem() { - return self::menuItemFor("Users"); - } - - /** - * @return Locator - */ - public static function usersAppsItem() { - return self::menuItemFor("Apps"); - } - - /** - * @return Locator - */ - public static function logOutMenuItem() { - return self::menuItemFor("Log out"); - } - - /** - * @return Locator - */ - private static function menuItemFor($itemText) { - return Locator::forThe()->xpath("//a[normalize-space() = '$itemText']")-> - descendantOf(self::settingsMenu())-> - describedAs($itemText . " item in Settings menu"); - } - - /** - * @param string $itemText - * @return Locator - */ - private static function settingsPanelFor($itemText) { - return Locator::forThe()->xpath("//div[@id = 'app-navigation' or contains(@class, 'app-navigation')]//ul//li[@class = 'app-navigation-caption' and normalize-space() = '$itemText']")-> - describedAs($itemText . " item in Settings panel"); - } - - /** - * @param string $itemText - * @return Locator - */ - private static function settingsPanelEntryFor($itemText) { - return Locator::forThe()->xpath("//div[@id = 'app-navigation' or contains(@class, 'app-navigation')]//ul//li[normalize-space() = '$itemText']")-> - describedAs($itemText . " entry in Settings panel"); - } - - /** - * @return array - */ - public function menuItems() { - return $this->actor->find(self::settingsMenu(), 10) - ->getWrappedElement()->findAll('xpath', '//a'); - } - - /** - * @When I open the Settings menu - */ - public function iOpenTheSettingsMenu() { - $this->actor->find(self::settingsMenuButton(), 10)->click(); - } - - /** - * @When I open the User settings - */ - public function iOpenTheUserSettings() { - $this->iOpenTheSettingsMenu(); - - $this->actor->find(self::usersMenuItem(), 2)->click(); - } - - /** - * @When I open the Apps management - */ - public function iOpenTheAppsManagement() { - $this->iOpenTheSettingsMenu(); - - $this->actor->find(self::usersAppsItem(), 2)->click(); - } - - /** - * @When I visit the settings page - */ - public function iVisitTheSettingsPage() { - $this->iOpenTheSettingsMenu(); - $this->actor->find(self::menuItemFor('Settings'), 2)->click(); - } - - /** - * @When I visit the admin settings page - */ - public function iVisitTheAdminSettingsPage() { - $this->iOpenTheSettingsMenu(); - $this->actor->find(self::menuItemFor('Administration settings'), 2)->click(); - } - - /** - * @When I log out - */ - public function iLogOut() { - $this->iOpenTheSettingsMenu(); - - $this->actor->find(self::logOutMenuItem(), 2)->click(); - } - - /** - * @Then I see that the Settings menu is shown - */ - public function iSeeThatTheSettingsMenuIsShown() { - Assert::assertTrue( - $this->actor->find(self::settingsMenu(), 10)->isVisible()); - } - - /** - * @Then I see that the Settings menu has only :items items - */ - public function iSeeThatTheSettingsMenuHasOnlyXItems($items) { - Assert::assertCount(intval($items), self::menuItems()); - } - - /** - * @Then I see that the :itemText item in the Settings menu is shown - */ - public function iSeeThatTheItemInTheSettingsMenuIsShown($itemText) { - Assert::assertTrue( - $this->actor->find(self::menuItemFor($itemText), 10)->isVisible()); - } - - /** - * @Then I see that the :itemText item in the Settings menu is not shown - */ - public function iSeeThatTheItemInTheSettingsMenuIsNotShown($itemText) { - $this->iSeeThatTheSettingsMenuIsShown(); - - try { - Assert::assertFalse( - $this->actor->find(self::menuItemFor($itemText))->isVisible()); - } catch (NoSuchElementException $exception) { - } - } - - /** - * @Then I see that the :itemText settings panel is shown - */ - public function iSeeThatTheItemSettingsPanelIsShown($itemText) { - Assert::assertTrue( - $this->actor->find(self::settingsPanelFor($itemText), 10)->isVisible() - ); - } - - /** - * @Then I see that the :itemText entry in the settings panel is shown - */ - public function iSeeThatTheItemEntryInTheSettingsPanelIsShown($itemText) { - Assert::assertTrue( - $this->actor->find(self::settingsPanelEntryFor($itemText), 10)->isVisible() - ); - } - - /** - * @Then I see that the :itemText settings panel is not shown - */ - public function iSeeThatTheItemSettingsPanelIsNotShown($itemText) { - try { - Assert::assertFalse( - $this->actor->find(self::settingsPanelFor($itemText), 10)->isVisible() - ); - } catch (NoSuchElementException $exception) { - } - } -} diff --git a/tests/acceptance/features/bootstrap/ThemingAppContext.php b/tests/acceptance/features/bootstrap/ThemingAppContext.php deleted file mode 100644 index e680a3ca55c..00000000000 --- a/tests/acceptance/features/bootstrap/ThemingAppContext.php +++ /dev/null @@ -1,186 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; - -class ThemingAppContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function inputFieldFor($parameterName) { - return Locator::forThe()->css("input")-> - descendantOf(self::parameterDivFor($parameterName))-> - describedAs("Input field for $parameterName parameter in Theming app"); - } - - /** - * @return Locator - */ - public static function resetButtonFor($parameterName) { - return Locator::forThe()->css(".theme-undo")-> - descendantOf(self::parameterDivFor($parameterName))-> - describedAs("Reset button for $parameterName parameter in Theming app"); - } - - /** - * @return Locator - */ - private static function parameterDivFor($parameterName) { - return Locator::forThe()->xpath("//*[@id='theming']//label//*[normalize-space() = '$parameterName']/ancestor::div[1]")-> - describedAs("Div for $parameterName parameter in Theming app"); - } - - /** - * @return Locator - */ - public static function statusMessage() { - return Locator::forThe()->id("theming_settings_msg")-> - describedAs("Status message in Theming app"); - } - - /** - * @When I set the :parameterName parameter in the Theming app to :parameterValue - */ - public function iSetTheParameterInTheThemingAppTo($parameterName, $parameterValue) { - $this->actor->find(self::inputFieldFor($parameterName), 10)->setValue($parameterValue); - } - - /** - * @When I reset the :parameterName parameter in the Theming app to its default value - */ - public function iSetTheParameterInTheThemingAppToItsDefaultValue($parameterName) { - // The reset button is not shown when the cursor is outside the input - // field, so ensure that the cursor is on the input field by clicking on - // it. - $this->actor->find(self::inputFieldFor($parameterName), 10)->click(); - - $this->actor->find(self::resetButtonFor($parameterName), 10)->click(); - } - - /** - * @Then I see that the color selector in the Theming app has loaded - */ - public function iSeeThatTheColorSelectorInTheThemingAppHasLoaded() { - // Checking if the color selector has loaded by getting the background color - // of the input element. If the value present in the element matches the - // background of the input element, it means the color element has been - // initialized. - - Assert::assertTrue($this->actor->find(self::inputFieldFor("Color"), 10)->isVisible()); - - $actor = $this->actor; - - $colorSelectorLoadedCallback = function () use ($actor) { - $colorSelectorValue = $this->getRGBArray($actor->getSession()->evaluateScript("return $('#admin-theming-color').text().trim();")); - $inputBgColorRgb = $this->getRGBArray($actor->getSession()->evaluateScript("return $('#admin-theming-color').css('background-color');")); - - $matches = []; - preg_match_all('/\d+/', $inputBgColorRgb, $matches); - $inputBgColorHex = sprintf("#%02x%02x%02x", $matches[0][0], $matches[0][1], $matches[0][2]); - - if ($colorSelectorValue == $inputBgColorHex) { - return true; - } - - return false; - }; - - if (!Utils::waitFor($colorSelectorLoadedCallback, $timeout = 10 * $this->actor->getFindTimeoutMultiplier(), $timeoutStep = 1)) { - Assert::fail("The color selector in Theming app has not been loaded after $timeout seconds"); - } - } - - private function getRGBArray($color) { - if (preg_match("/rgb\(\s*(\d+),\s*(\d+),\s*(\d+)\)/", $color, $matches)) { - // Already an RGB (R, G, B) color - // Convert from "rgb(R, G, B)" string to RGB array - $tmpColor = array_splice($matches, 1); - } elseif ($color[0] === '#') { - $color = substr($color, 1); - // HEX Color, convert to RGB array. - $tmpColor = sscanf($color, "%02X%02X%02X"); - } else { - Assert::fail("The acceptance test does not know how to handle the color string : '$color'. " - . "Please provide # before HEX colors in your features."); - } - return $tmpColor; - } - - /** - * @Then I see that the primary color is eventually :color - */ - public function iSeeThatThePrimaryColorIsEventually($color) { - $primaryColorMatchesCallback = function () use ($color) { - $primaryColor = $this->actor->getSession()->evaluateScript("return getComputedStyle(document.documentElement).getPropertyValue('--color-primary').trim();"); - $primaryColor = $this->getRGBArray($primaryColor); - $color = $this->getRGBArray($color); - - return $primaryColor == $color; - }; - - if (!Utils::waitFor($primaryColorMatchesCallback, $timeout = 10 * $this->actor->getFindTimeoutMultiplier(), $timeoutStep = 1)) { - Assert::fail("The primary color is not $color yet after $timeout seconds"); - } - } - - /** - * @Then I see that the non-plain background color variable is eventually :color - */ - public function iSeeThatTheNonPlainBackgroundColorVariableIsEventually($color) { - $colorVariableMatchesCallback = function () use ($color) { - $colorVariable = $this->actor->getSession()->evaluateScript("return getComputedStyle(document.documentElement).getPropertyValue('--color-primary-default').trim();"); - $colorVariable = $this->getRGBArray($colorVariable); - $color = $this->getRGBArray($color); - - return $colorVariable == $color; - }; - - if (!Utils::waitFor($colorVariableMatchesCallback, $timeout = 10 * $this->actor->getFindTimeoutMultiplier(), $timeoutStep = 1)) { - Assert::fail("The non-plain background color variable is not $color yet after $timeout seconds"); - } - } - - /** - * @Then I see that the parameters in the Theming app are eventually saved - */ - public function iSeeThatTheParametersInTheThemingAppAreEventuallySaved() { - Assert::assertTrue($this->actor->find(self::statusMessage(), 10)->isVisible()); - - $actor = $this->actor; - - $savedStatusMessageShownCallback = function () use ($actor) { - if ($actor->find(self::statusMessage())->getText() !== "Saved") { - return false; - } - - return true; - }; - - if (!Utils::waitFor($savedStatusMessageShownCallback, $timeout = 10 * $this->actor->getFindTimeoutMultiplier(), $timeoutStep = 1)) { - Assert::fail("The 'Saved' status messages in Theming app has not been shown after $timeout seconds"); - } - } -} diff --git a/tests/acceptance/features/bootstrap/ToastContext.php b/tests/acceptance/features/bootstrap/ToastContext.php deleted file mode 100644 index 7ca3df2f47e..00000000000 --- a/tests/acceptance/features/bootstrap/ToastContext.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; - -class ToastContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function toastMessage($message) { - return Locator::forThe()->xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' toastify ') and normalize-space(text()) = '$message']")-> - descendantOf(self::toastContainer())-> - describedAs("$message toast"); - } - - /** - * @return Locator - */ - private static function toastContainer() { - return Locator::forThe()->xpath("//*[@id=\"content\" or contains(@class, 'content')]")-> - describedAs("Toast container"); - } - - /** - * @Then I see that the :message toast is shown - */ - public function iSeeThatTheToastIsShown($message) { - Assert::assertTrue($this->actor->find( - self::toastMessage($message), 10)->isVisible()); - } -} diff --git a/tests/acceptance/features/bootstrap/UsersSettingsContext.php b/tests/acceptance/features/bootstrap/UsersSettingsContext.php deleted file mode 100644 index 3ed74788e7e..00000000000 --- a/tests/acceptance/features/bootstrap/UsersSettingsContext.php +++ /dev/null @@ -1,379 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> - * @copyright Copyright (c) 2019, Greta Doci <gretadoci@gmail.com> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; -use WebDriver\Key; - -class UsersSettingsContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function newUserForm() { - return Locator::forThe()->css('[data-test="form"]')-> - describedAs("New user form in Users Settings"); - } - - /** - * @return Locator - */ - public static function userNameFieldForNewUser() { - return Locator::forThe()->css('[data-test="username"]')-> - describedAs("User name field for new user in Users Settings"); - } - - /** - * @return Locator - */ - public static function displayNameFieldForNewUser() { - return Locator::forThe()->css('[data-test="displayName"]')-> - describedAs("Display name field for new user in Users Settings"); - } - - /** - * @return Locator - */ - public static function passwordFieldForNewUser() { - return Locator::forThe()->css('[data-test="password"]')-> - describedAs("Password field for new user in Users Settings"); - } - - /** - * @return Locator - */ - public static function newUserButton() { - return Locator::forThe()->id("new-user-button")-> - describedAs("New user button in Users Settings"); - } - - /** - * @return Locator - */ - public static function createNewUserButton() { - return Locator::forThe()->css('[data-test="submit"]')-> - describedAs("Create user button in Users Settings"); - } - - /** - * @return Locator - */ - public static function rowForUser($user) { - return Locator::forThe()->xpath("//tbody[contains(@class, 'user-list__body')]/tr[td[@data-test='$user']]")-> - describedAs("Row for user $user in Users Settings"); - } - - /** - * Warning: you need to watch out for the proper classes order - * - * @return Locator - */ - public static function classCellForUser($class, $user) { - return Locator::forThe()->xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' $class ')]")-> - descendantOf(self::rowForUser($user))-> - describedAs("$class cell for user $user in Users Settings"); - } - - /** - * @return Locator - */ - public static function inputForUserInCell($cell, $user) { - return Locator::forThe()->css("input")-> - descendantOf(self::classCellForUser($cell, $user))-> - describedAs("$cell input for user $user in Users Settings"); - } - - /** - * @return Locator - */ - public static function displayNameCellForUser($user) { - return self::inputForUserInCell("displayName", $user); - } - - /** - * @return Locator - */ - public static function optionInInputForUser($cell, $user) { - return Locator::forThe()->css(".vs__dropdown-option--highlight")-> - describedAs("Selected $cell option in $cell input for user $user in Users Settings"); - } - - /** - * @return Locator - */ - public static function actionsMenuOf($user) { - return Locator::forThe()->css(".userActions .action-item:not(.action-item--single)")-> - descendantOf(self::rowForUser($user))-> - describedAs("Actions menu for user $user in Users Settings"); - } - - /** - * @return Locator - */ - public static function theAction($action, $user) { - return Locator::forThe()->xpath("//button[@aria-label = normalize-space('$action')]")-> - describedAs("$action action for the user $user row in Users Settings"); - } - - /** - * @return Locator - */ - public static function theColumn($column) { - return Locator::forThe()->xpath("//div[@class='user-list-grid']//div[normalize-space() = '$column']")-> - describedAs("The $column column in Users Settings"); - } - - /** - * @return Locator - */ - public static function selectedSelectOption($cell, $user) { - return Locator::forThe()->css(".vs__selected .name-parts")-> - descendantOf(self::classCellForUser($cell, $user))-> - describedAs("The selected option of the $cell select for the user $user in Users Settings"); - } - - /** - * @return Locator - */ - public static function editModeToggle($user) { - return Locator::forThe()->css(".userActions .action-items button:first-of-type")-> - descendantOf(self::rowForUser($user))-> - describedAs("The edit toggle button for the user $user in Users Settings"); - } - - /** - * @return Locator - */ - public static function editModeOn($user) { - return Locator::forThe()->css("div.user-list-grid div.row.row--editable[data-id=$user]")-> - describedAs("I see the edit mode is on for the user $user in Users Settings"); - } - - /** - * @When I click the New user button - */ - public function iClickTheNewUserButton() { - $this->actor->find(self::newUserButton(), 10)->click(); - } - - /** - * @When I click the :action action in the :user actions menu - */ - public function iClickTheAction($action, $user) { - $this->actor->find(self::theAction($action, $user), 10)->click(); - } - - /** - * @When I open the actions menu for the user :user - */ - public function iOpenTheActionsMenuOf($user) { - $this->actor->find(self::actionsMenuOf($user), 10)->click(); - } - - /** - * @When I set the user name for the new user to :user - */ - public function iSetTheUserNameForTheNewUserTo($user) { - $this->actor->find(self::userNameFieldForNewUser(), 10)->setValue($user); - } - - /** - * @When I set the display name for the new user to :displayName - */ - public function iSetTheDisplayNameForTheNewUserTo($displayName) { - $this->actor->find(self::displayNameFieldForNewUser(), 10)->setValue($displayName); - } - - /** - * @When I set the password for the new user to :password - */ - public function iSetThePasswordForTheNewUserTo($password) { - $this->actor->find(self::passwordFieldForNewUser(), 10)->setValue($password); - } - - /** - * @When I create the new user - */ - public function iCreateTheNewUser() { - $this->actor->find(self::createNewUserButton(), 10)->click(); - } - - /** - * @When I toggle the edit mode for the user :user - */ - public function iToggleTheEditModeForUser($user) { - $this->actor->find(self::editModeToggle($user), 10)->click(); - } - - /** - * @When I create user :user with password :password - */ - public function iCreateUserWithPassword($user, $password) { - $this->actor->find(self::userNameFieldForNewUser(), 10)->setValue($user); - $this->actor->find(self::passwordFieldForNewUser())->setValue($password); - $this->actor->find(self::createNewUserButton())->click(); - } - - /** - * @When I set the :field for :user to :value - */ - public function iSetTheFieldForUserTo($field, $user, $value) { - $this->actor->find(self::inputForUserInCell($field, $user), 2)->setValue($value . Key::ENTER); - } - - /** - * Assigning/withdrawing is the same action (it toggles). - * - * @When I assign the user :user to the group :group - * @When I withdraw the user :user from the group :group - */ - public function iAssignTheUserToTheGroup($user, $group) { - $this->actor->find(self::inputForUserInCell('groups', $user))->setValue($group); - $this->actor->find(self::optionInInputForUser('groups', $user))->click(); - } - - /** - * @When I set the user :user quota to :quota - */ - public function iSetTheUserQuotaTo($user, $quota) { - $this->actor->find(self::inputForUserInCell('quota', $user))->setValue($quota); - $this->actor->find(self::optionInInputForUser('quota', $user))->click(); - } - - /** - * @Then I see that the list of users contains the user :user - */ - public function iSeeThatTheListOfUsersContainsTheUser($user) { - if (!WaitFor::elementToBeEventuallyShown( - $this->actor, - self::rowForUser($user), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The user $user in the list of users is not shown yet after $timeout seconds"); - } - } - - /** - * @Then I see that the list of users does not contains the user :user - */ - public function iSeeThatTheListOfUsersDoesNotContainsTheUser($user) { - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::rowForUser($user), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The user $user in the list of users is still shown after $timeout seconds"); - } - } - - /** - * @Then I see that the new user form is shown - */ - public function iSeeThatTheNewUserFormIsShown() { - if (!WaitFor::elementToBeEventuallyShown( - $this->actor, - self::newUserForm(), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The new user form is not shown yet after $timeout seconds"); - } - } - - /** - * @Then I see that the :action action in the :user actions menu is shown - */ - public function iSeeTheAction($action, $user) { - Assert::assertTrue( - $this->actor->find(self::theAction($action, $user), 10)->isVisible()); - } - - /** - * @Then I see that the :column column is shown - */ - public function iSeeThatTheColumnIsShown($column) { - Assert::assertTrue( - $this->actor->find(self::theColumn($column), 10)->isVisible()); - } - - /** - * @Then I see that the :field of :user is :value - */ - public function iSeeThatTheFieldOfUserIs($field, $user, $value) { - Assert::assertEquals( - $this->actor->find(self::inputForUserInCell($field, $user), 10)->getValue(), $value); - } - - /** - * @Then I see that the display name for the user :user is :displayName - */ - public function iSeeThatTheDisplayNameForTheUserIs($user, $displayName) { - Assert::assertEquals( - $displayName, $this->actor->find(self::displayNameCellForUser($user), 10)->getValue()); - } - - /** - * @Then I see that the :cell cell for user :user is done loading - */ - public function iSeeThatTheCellForUserIsDoneLoading($cell, $user) { - // It could happen that the cell for the user was done loading and thus - // the loading icon hidden again even before finding the loading icon - // started. Therefore, if the loading icon could not be found it is just - // assumed that it was already hidden again. Nevertheless, this check - // should be done anyway to ensure that the following scenario steps are - // not executed before the cell for the user was done loading. - try { - $this->actor->find(self::classCellForUser($cell . ' icon-loading-small', $user), 1); - } catch (NoSuchElementException $exception) { - echo "The loading icon for user $user was not found after " . (1 * $this->actor->getFindTimeoutMultiplier()) . " seconds, assumming that it was shown and hidden again before the check started and continuing"; - - return; - } - - if (!WaitFor::elementToBeEventuallyNotShown( - $this->actor, - self::classCellForUser($cell . ' icon-loading-small', $user), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The loading icon for user $user is still shown after $timeout seconds"); - } - } - - /** - * @Then I see that the user quota of :user is :quota - */ - public function iSeeThatTheuserQuotaIs($user, $quota) { - Assert::assertEquals( - $this->actor->find(self::selectedSelectOption('quota', $user), 2)->getText(), $quota); - } - - /** - * @Then I see that the edit mode is on for user :user - */ - public function iSeeThatTheEditModeIsOn($user) { - if (!WaitFor::elementToBeEventuallyShown( - $this->actor, - self::editModeOn($user), - $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { - Assert::fail("The edit mode for user $user in the list of users is not on yet after $timeout seconds"); - } - } -} diff --git a/tests/acceptance/features/bootstrap/WaitFor.php b/tests/acceptance/features/bootstrap/WaitFor.php deleted file mode 100644 index 37a268360aa..00000000000 --- a/tests/acceptance/features/bootstrap/WaitFor.php +++ /dev/null @@ -1,76 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/** - * Helper class with common "wait for" functions. - */ -class WaitFor { - /** - * Waits for the element to be visible. - * - * @param Actor $actor the Actor used to find the element. - * @param Locator $elementLocator the locator for the element. - * @param float $timeout the number of seconds (decimals allowed) to wait at - * most for the element to be visible. - * @param float $timeoutStep the number of seconds (decimals allowed) to - * wait before checking the visibility again. - * @return boolean true if the element is visible before (or exactly when) - * the timeout expires, false otherwise. - */ - public static function elementToBeEventuallyShown(Actor $actor, Locator $elementLocator, $timeout = 10, $timeoutStep = 1) { - $elementShownCallback = function () use ($actor, $elementLocator) { - try { - return $actor->find($elementLocator)->isVisible(); - } catch (NoSuchElementException $exception) { - return false; - } - }; - - return Utils::waitFor($elementShownCallback, $timeout, $timeoutStep); - } - - /** - * Waits for the element to be hidden (either not visible or not found in - * the DOM). - * - * @param Actor $actor the Actor used to find the element. - * @param Locator $elementLocator the locator for the element. - * @param float $timeout the number of seconds (decimals allowed) to wait at - * most for the element to be hidden. - * @param float $timeoutStep the number of seconds (decimals allowed) to - * wait before checking the visibility again. - * @return boolean true if the element is hidden before (or exactly when) - * the timeout expires, false otherwise. - */ - public static function elementToBeEventuallyNotShown(Actor $actor, Locator $elementLocator, $timeout = 10, $timeoutStep = 1) { - $elementNotShownCallback = function () use ($actor, $elementLocator) { - try { - return !$actor->find($elementLocator)->isVisible(); - } catch (NoSuchElementException $exception) { - return true; - } - }; - - return Utils::waitFor($elementNotShownCallback, $timeout, $timeoutStep); - } -} diff --git a/tests/acceptance/features/core/Actor.php b/tests/acceptance/features/core/Actor.php deleted file mode 100644 index abe9a390920..00000000000 --- a/tests/acceptance/features/core/Actor.php +++ /dev/null @@ -1,214 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/** - * An actor in a test scenario. - * - * Every Actor object is intended to be used only in a single test scenario. - * An Actor can control its web browser thanks to the Mink Session received when - * it was created, so in each scenario each Actor must have its own Mink - * Session; the same Mink Session can be used by different Actors in different - * scenarios, but never by different Actors in the same scenario. - * - * The test servers used in an scenario can change between different test runs, - * so an Actor stores the base URL for the current test server being used; in - * most cases the tests are specified using relative paths that can be converted - * to the appropriate absolute URL using locatePath() in the step - * implementation. - * - * An Actor can find elements in its Mink Session using its find() method; it is - * a wrapper over the find() method provided by Mink that extends it with - * several features: the element can be looked for based on a Locator object, an - * exception is thrown if the element is not found, and, optionally, it is - * possible to try again to find the element several times before giving up. - * - * The returned object is also a wrapper over the element itself that - * automatically handles common causes of failed commands, like clicking on a - * hidden element; in this case, the wrapper would wait for the element to be - * visible up to the timeout set to find the element. - * - * The amount of time to wait before giving up is specified in each call to - * find(). However, a general multiplier to be applied to every timeout can be - * set using setFindTimeoutMultiplier(); this makes possible to retry longer - * before giving up without modifying the tests themselves. Note that the - * multiplier affects the timeout, but not the timeout step; the rate at which - * find() will try again to find the element does not change. - * - * All actors share a notebook in which data can be annotated. This makes - * possible to share data between different test steps, no matter which Actor - * performs them. - */ -class Actor { - /** - * @var string - */ - private $name; - - /** - * @var \Behat\Mink\Session - */ - private $session; - - /** - * @var string - */ - private $baseUrl; - - /** - * @var float - */ - private $findTimeoutMultiplier; - - /** - * @var array - */ - private $sharedNotebook; - - /** - * Creates a new Actor. - * - * @param string $name the name of the actor. - * @param \Behat\Mink\Session $session the Mink Session used to control its - * web browser. - * @param string $baseUrl the base URL used when solving relative URLs. - * @param array $sharedNotebook the notebook shared between all actors. - */ - public function __construct($name, \Behat\Mink\Session $session, $baseUrl, &$sharedNotebook) { - $this->name = $name; - $this->session = $session; - $this->baseUrl = $baseUrl; - $this->sharedNotebook = &$sharedNotebook; - $this->findTimeoutMultiplier = 1; - } - - /** - * Returns the name of this Actor. - * - * @return string the name of this Actor. - */ - public function getName() { - return $this->name; - } - - /** - * Sets the base URL. - * - * @param string $baseUrl the base URL used when solving relative URLs. - */ - public function setBaseUrl($baseUrl) { - $this->baseUrl = $baseUrl; - } - - /** - * Returns the multiplier for find timeouts. - * - * @return float the multiplier to apply to find timeouts. - */ - public function getFindTimeoutMultiplier() { - return $this->findTimeoutMultiplier; - } - - /** - * Sets the multiplier for find timeouts. - * - * @param float $findTimeoutMultiplier the multiplier to apply to find - * timeouts. - */ - public function setFindTimeoutMultiplier($findTimeoutMultiplier) { - $this->findTimeoutMultiplier = $findTimeoutMultiplier; - } - - /** - * Returns the Mink Session used to control its web browser. - * - * @return \Behat\Mink\Session the Mink Session used to control its web - * browser. - */ - public function getSession() { - return $this->session; - } - - /** - * Returns the full path for the given relative path based on the base URL. - * - * @param string relativePath the relative path. - * @return string the full path. - */ - public function locatePath($relativePath) { - return $this->baseUrl . $relativePath; - } - - /** - * Finds an element in the Mink Session of this Actor. - * - * The given element locator is relative to its ancestor (either another - * locator or an actual element); if it has no ancestor then the base - * document element is used. - * - * Sometimes an element may not be found simply because it has not appeared - * yet; for those cases this method supports trying again to find the - * element several times before giving up. The timeout parameter controls - * how much time to wait, at most, to find the element; the timeoutStep - * parameter controls how much time to wait before trying again to find the - * element. If ancestor locators need to be found the timeout is applied - * individually to each one, that is, if the timeout is 10 seconds the - * method will wait up to 10 seconds to find the ancestor of the ancestor - * and, then, up to 10 seconds to find the ancestor and, then, up to 10 - * seconds to find the element. By default the timeout is 0, so the element - * and its ancestor will be looked for just once; the default time to wait - * before retrying is half a second. If the timeout is not 0 it will be - * affected by the multiplier set using setFindTimeoutMultiplier(), if any. - * - * When found, the element is returned wrapped in an ElementWrapper; the - * ElementWrapper handles common causes of failures when executing commands - * in an element, like clicking on a hidden element. - * - * In any case, if the element, or its ancestors, can not be found a - * NoSuchElementException is thrown. - * - * @param Locator $elementLocator the locator for the element. - * @param float $timeout the number of seconds (decimals allowed) to wait at - * most for the element to appear. - * @param float $timeoutStep the number of seconds (decimals allowed) to - * wait before trying to find the element again. - * @return ElementWrapper an ElementWrapper object for the element. - * @throws NoSuchElementException if the element, or its ancestor, can not - * be found. - */ - public function find(Locator $elementLocator, $timeout = 0, $timeoutStep = 0.5) { - $timeout = $timeout * $this->findTimeoutMultiplier; - - $elementFinder = new ElementFinder($this->session, $elementLocator, $timeout, $timeoutStep); - - return new ElementWrapper($elementFinder); - } - - /** - * Returns the shared notebook of the Actors. - * - * @return array the shared notebook of the Actors. - */ - public function &getSharedNotebook() { - return $this->sharedNotebook; - } -} diff --git a/tests/acceptance/features/core/ActorAware.php b/tests/acceptance/features/core/ActorAware.php deleted file mode 100644 index c734d7e1906..00000000000 --- a/tests/acceptance/features/core/ActorAware.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -trait ActorAware { - /** - * @var Actor - */ - protected $actor; - - /** - * @param Actor $actor - */ - public function setCurrentActor(Actor $actor) { - $this->actor = $actor; - } -} diff --git a/tests/acceptance/features/core/ActorAwareInterface.php b/tests/acceptance/features/core/ActorAwareInterface.php deleted file mode 100644 index 7b855aed4d3..00000000000 --- a/tests/acceptance/features/core/ActorAwareInterface.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -interface ActorAwareInterface { - /** - * @param Actor $actor - */ - public function setCurrentActor(Actor $actor); -} diff --git a/tests/acceptance/features/core/ActorContext.php b/tests/acceptance/features/core/ActorContext.php deleted file mode 100644 index 7f152a1f3eb..00000000000 --- a/tests/acceptance/features/core/ActorContext.php +++ /dev/null @@ -1,194 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Hook\Scope\BeforeStepScope; -use Behat\MinkExtension\Context\RawMinkContext; - -/** - * Behat context to set the actor used in sibling contexts. - * - * This helper context provides a step definition ("I act as XXX") to change the - * current actor of the scenario, which makes possible to use different browser - * sessions in the same scenario. - * - * Sibling contexts that want to have access to the current actor of the - * scenario must implement the ActorAwareInterface; this can be done just by - * using the ActorAware trait. - * - * Besides updating the current actor in sibling contexts the ActorContext also - * propagates its inherited "base_url" Mink parameter to the Actors as needed. - * - * By default no multiplier for the find timeout is set in the Actors. However, - * it can be customized using the "actorTimeoutMultiplier" parameter of the - * ActorContext in "behat.yml". This parameter also affects the overall timeout - * to start a session for an Actor before giving up. - * - * Every actor used in the scenarios must have a corresponding Mink session - * declared in "behat.yml" with the same name as the actor. All used sessions - * are stopped after each scenario is run. - */ -class ActorContext extends RawMinkContext { - /** - * @var array - */ - private $actors; - - /** - * @var array - */ - private $sharedNotebook; - - /** - * @var Actor - */ - private $currentActor; - - /** - * @var float - */ - private $actorTimeoutMultiplier; - - /** - * Creates a new ActorContext. - * - * @param float $actorTimeoutMultiplier the timeout multiplier for Actor - * related timeouts. - */ - public function __construct($actorTimeoutMultiplier = 1) { - $this->actorTimeoutMultiplier = $actorTimeoutMultiplier; - } - - /** - * Sets a Mink parameter. - * - * When the "base_url" parameter is set its value is propagated to all the - * Actors. - * - * @param string $name the name of the parameter. - * @param string $value the value of the parameter. - */ - public function setMinkParameter($name, $value) { - parent::setMinkParameter($name, $value); - - if ($name === "base_url") { - foreach ($this->actors as $actor) { - $actor->setBaseUrl($value); - } - } - } - - /** - * Returns the session with the given name. - * - * If the session is not started it is started before returning it; if the - * session fails to start (typically due to a timeout connecting with the - * web browser) it will be tried again up to $actorTimeoutMultiplier times - * in total (rounded up to the next integer) before giving up. - * - * @param string|null $sname the name of the session to get, or null for the - * default session. - * @return \Behat\Mink\Session the session. - */ - public function getSession($name = null) { - for ($i = 0; $i < ($this->actorTimeoutMultiplier - 1); $i++) { - try { - return parent::getSession($name); - } catch (\Behat\Mink\Exception\DriverException $exception) { - echo "Exception when getting " . ($name == null? "default session": "session '$name'") . ": " . $exception->getMessage() . "\n"; - echo "Trying again\n"; - } - } - - return parent::getSession($name); - } - - /** - * @BeforeScenario - * - * Initializes the Actors for the new Scenario with the default Actor. - * - * Other Actors are added (and their Mink Sessions started) only when they - * are used in an "I act as XXX" step. - */ - public function initializeActors() { - $this->actors = []; - $this->sharedNotebook = []; - - $this->getSession()->start(); - - $this->getSession()->maximizeWindow(); - - $this->actors["default"] = new Actor("default", $this->getSession(), $this->getMinkParameter("base_url"), $this->sharedNotebook); - $this->actors["default"]->setFindTimeoutMultiplier($this->actorTimeoutMultiplier); - - $this->currentActor = $this->actors["default"]; - } - - /** - * @BeforeStep - */ - public function setCurrentActorInSiblingActorAwareContexts(BeforeStepScope $scope) { - $environment = $scope->getEnvironment(); - - foreach ($environment->getContexts() as $context) { - if ($context instanceof ActorAwareInterface) { - $context->setCurrentActor($this->currentActor); - } - } - } - - /** - * @Given I act as :actorName - */ - public function iActAs($actorName) { - if (!array_key_exists($actorName, $this->actors)) { - $this->getSession($actorName)->start(); - - $this->getSession($actorName)->maximizeWindow(); - - $this->actors[$actorName] = new Actor($actorName, $this->getSession($actorName), $this->getMinkParameter("base_url"), $this->sharedNotebook); - $this->actors[$actorName]->setFindTimeoutMultiplier($this->actorTimeoutMultiplier); - } - - $this->currentActor = $this->actors[$actorName]; - - // Ensure that the browser window of the actor is the one in the - // foreground; this works around a bug in the Firefox driver of Selenium - // and/or maybe in Firefox itself when interacting with a window in the - // background, but also reflects better how the user would interact with - // the browser in real life. - $session = $this->actors[$actorName]->getSession(); - $session->switchToWindow($session->getWindowName()); - } - - /** - * @AfterScenario - * - * Stops all the Mink Sessions used in the last Scenario. - */ - public function cleanUpSessions() { - foreach ($this->actors as $actor) { - $actor->getSession()->stop(); - } - } -} diff --git a/tests/acceptance/features/core/ElementFinder.php b/tests/acceptance/features/core/ElementFinder.php deleted file mode 100644 index 714b100bfa2..00000000000 --- a/tests/acceptance/features/core/ElementFinder.php +++ /dev/null @@ -1,203 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/** - * Command object to find Mink elements. - * - * The element locator is relative to its ancestor (either another locator or an - * actual element); if it has no ancestor then the base document element is - * used. - * - * Sometimes an element may not be found simply because it has not appeared yet; - * for those cases ElementFinder supports trying again to find the element - * several times before giving up. The timeout parameter controls how much time - * to wait, at most, to find the element; the timeoutStep parameter controls how - * much time to wait before trying again to find the element. If ancestor - * locators need to be found the timeout is applied individually to each one, - * that is, if the timeout is 10 seconds the method will wait up to 10 seconds - * to find the ancestor of the ancestor and, then, up to 10 seconds to find the - * ancestor and, then, up to 10 seconds to find the element. By default the - * timeout is 0, so the element and its ancestor will be looked for just once; - * the default time to wait before retrying is half a second. - * - * In any case, if the element, or its ancestors, can not be found a - * NoSuchElementException is thrown. - */ -class ElementFinder { - /** - * Finds an element in the given Mink Session. - * - * @see ElementFinder - */ - private static function findInternal(\Behat\Mink\Session $session, Locator $elementLocator, $timeout, $timeoutStep) { - $element = null; - $selector = $elementLocator->getSelector(); - $locator = $elementLocator->getLocator(); - $ancestorElement = self::findAncestorElement($session, $elementLocator, $timeout, $timeoutStep); - - $findCallback = function () use (&$element, $selector, $locator, $ancestorElement) { - $element = $ancestorElement->find($selector, $locator); - - return $element !== null; - }; - if (!Utils::waitFor($findCallback, $timeout, $timeoutStep)) { - $message = $elementLocator->getDescription() . " could not be found"; - if ($timeout > 0) { - $message = $message . " after $timeout seconds"; - } - throw new NoSuchElementException($message); - } - - return $element; - } - - /** - * Returns the ancestor element from which the given locator will be looked - * for. - * - * If the ancestor of the given locator is another locator the element for - * the ancestor locator is found and returned. If the ancestor of the given - * locator is already an element that element is the one returned. If the - * given locator has no ancestor then the base document element is returned. - * - * The timeout is used only when finding the element for the ancestor - * locator; if the timeout expires a NoSuchElementException is thrown. - * - * @param \Behat\Mink\Session $session the Mink Session to get the ancestor - * element from. - * @param Locator $elementLocator the locator for the element to get its - * ancestor. - * @param float $timeout the number of seconds (decimals allowed) to wait at - * most for the ancestor element to appear. - * @param float $timeoutStep the number of seconds (decimals allowed) to - * wait before trying to find the ancestor element again. - * @return \Behat\Mink\Element\Element the ancestor element found. - * @throws NoSuchElementException if the ancestor element can not be found. - */ - private static function findAncestorElement(\Behat\Mink\Session $session, Locator $elementLocator, $timeout, $timeoutStep) { - $ancestorElement = $elementLocator->getAncestor(); - if ($ancestorElement instanceof Locator) { - try { - $ancestorElement = self::findInternal($session, $ancestorElement, $timeout, $timeoutStep); - } catch (NoSuchElementException $exception) { - // Little hack to show the stack of ancestor elements that could - // not be found, as Behat only shows the message of the last - // exception in the chain. - $message = $exception->getMessage() . "\n" . - $elementLocator->getDescription() . " could not be found"; - if ($timeout > 0) { - $message = $message . " after $timeout seconds"; - } - throw new NoSuchElementException($message, $exception); - } - } - - if ($ancestorElement === null) { - $ancestorElement = $session->getPage(); - } - - return $ancestorElement; - } - - /** - * @var \Behat\Mink\Session - */ - private $session; - - /** - * @param Locator - */ - private $elementLocator; - - /** - * @var float - */ - private $timeout; - - /** - * @var float - */ - private $timeoutStep; - - /** - * Creates a new ElementFinder. - * - * @param \Behat\Mink\Session $session the Mink Session to get the element - * from. - * @param Locator $elementLocator the locator for the element. - * @param float $timeout the number of seconds (decimals allowed) to wait at - * most for the element to appear. - * @param float $timeoutStep the number of seconds (decimals allowed) to - * wait before trying to find the element again. - */ - public function __construct(\Behat\Mink\Session $session, Locator $elementLocator, $timeout, $timeoutStep) { - $this->session = $session; - $this->elementLocator = $elementLocator; - $this->timeout = $timeout; - $this->timeoutStep = $timeoutStep; - } - - /** - * Returns the description of the element to find. - * - * @return string the description of the element to find. - */ - public function getDescription() { - return $this->elementLocator->getDescription(); - } - - /** - * Returns the timeout. - * - * @return float the number of seconds (decimals allowed) to wait at most - * for the element to appear. - */ - public function getTimeout() { - return $this->timeout; - } - - /** - * Returns the timeout step. - * - * @return float the number of seconds (decimals allowed) to wait before - * trying to find the element again. - */ - public function getTimeoutStep() { - return $this->timeoutStep; - } - - /** - * Finds an element using the parameters set in the constructor of this - * ElementFinder. - * - * If the element, or its ancestors, can not be found a - * NoSuchElementException is thrown. - * - * @return \Behat\Mink\Element\Element the element found. - * @throws NoSuchElementException if the element, or its ancestor, can not - * be found. - */ - public function find() { - return self::findInternal($this->session, $this->elementLocator, $this->timeout, $this->timeoutStep); - } -} diff --git a/tests/acceptance/features/core/ElementWrapper.php b/tests/acceptance/features/core/ElementWrapper.php deleted file mode 100644 index 6ac9a6b8e8f..00000000000 --- a/tests/acceptance/features/core/ElementWrapper.php +++ /dev/null @@ -1,358 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/** - * Wrapper to automatically handle failed commands on Mink elements. - * - * Commands executed on Mink elements may fail for several reasons. The - * ElementWrapper frees the caller of the commands from handling the most common - * reasons of failure. - * - * StaleElementReference exceptions are thrown when the command is executed on - * an element that is no longer attached to the DOM. This can happen even in - * a chained call like "$actor->find($locator)->click()"; in the milliseconds - * between finding the element and clicking it the element could have been - * removed from the page (for example, if a previous interaction with the page - * started an asynchronous update of the DOM). Every command executed through - * the ElementWrapper is guarded against StaleElementReference exceptions; if - * the element is stale it is found again using the same parameters to find it - * in the first place. - * - * NoSuchElement exceptions are sometimes thrown instead of - * StaleElementReference exceptions. This can happen when the Selenium2 driver - * for Mink performs an action on an element through the WebDriver session - * instead of directly through the WebDriver element. In that case, if the - * element with the given ID does not exist, a NoSuchElement exception would be - * thrown instead of a StaleElementReference exception, so those cases are - * handled like StaleElementReference exceptions. - * - * ElementNotVisible exceptions are thrown when the command requires the element - * to be visible but the element is not. Finding an element only guarantees that - * (at that time) the element is attached to the DOM, but it does not provide - * any guarantee regarding its visibility. Due to that, a call like - * "$actor->find($locator)->click()" can fail if the element was hidden and - * meant to be made visible by a previous interaction with the page, but that - * interaction triggered an asynchronous update that was not finished when the - * click command is executed. All commands executed through the ElementWrapper - * that require the element to be visible are guarded against ElementNotVisible - * exceptions; if the element is not visible it is waited for it to be visible - * up to the timeout set to find it. - * - * MoveTargetOutOfBounds exceptions are sometimes thrown instead of - * ElementNotVisible exceptions. This can happen when the Selenium2 driver for - * Mink moves the cursor on an element using the "moveto" method of the - * WebDriver session, for example, before clicking on an element. In that case, - * if the element is not visible, "moveto" would throw a MoveTargetOutOfBounds - * exception instead of an ElementNotVisible exception, so those cases are - * handled like ElementNotVisible exceptions. - * - * ElementNotInteractable exceptions are thrown in Selenium 3 when the command - * needs to interact with an element but that is not possible. This could be a - * transitive situation (for example, due to an animation), so the command is - * executed again after a small timeout. - * - * Despite the automatic handling it is possible for the commands to throw those - * exceptions when they are executed again; this class does not handle cases - * like an element becoming stale several times in a row (uncommon) or an - * element not becoming visible before the timeout expires (which would mean - * that the timeout is too short or that the test has to, indeed, fail). In a - * similar way, MoveTargetOutOfBounds exceptions would be thrown again if - * originally they were thrown because the element was visible but "out of - * reach". ElementNotInteractable exceptions would be thrown again if it is not - * possible to interact yet with the element after the wait (which could mean - * that the test has to, indeed, fail, although it could mean too that the - * automatic handling needs to be improved). - * - * If needed, automatically handling failed commands can be disabled calling - * "doNotHandleFailedCommands()"; as it returns the ElementWrapper it can be - * chained with the command to execute (but note that automatically handling - * failed commands will still be disabled if further commands are executed on - * the ElementWrapper). - */ -class ElementWrapper { - /** - * @var ElementFinder - */ - private $elementFinder; - - /** - * @var \Behat\Mink\Element\Element - */ - private $element; - - /** - * @param boolean - */ - private $handleFailedCommands; - - /** - * Creates a new ElementWrapper. - * - * The wrapped element is found in the constructor itself using the - * ElementFinder. - * - * @param ElementFinder $elementFinder the command object to find the - * wrapped element. - * @throws NoSuchElementException if the element, or its ancestor, can not - * be found. - */ - public function __construct(ElementFinder $elementFinder) { - $this->elementFinder = $elementFinder; - $this->element = $elementFinder->find(); - $this->handleFailedCommands = true; - } - - /** - * Returns the raw Mink element. - * - * @return \Behat\Mink\Element\Element the wrapped element. - */ - public function getWrappedElement() { - return $this->element; - } - - /** - * Prevents the automatic handling of failed commands. - * - * @return ElementWrapper this ElementWrapper. - */ - public function doNotHandleFailedCommands() { - $this->handleFailedCommands = false; - - return $this; - } - - /** - * Returns whether the wrapped element is visible or not. - * - * @return bool true if the wrapped element is visible, false otherwise. - */ - public function isVisible() { - $commandCallback = function () { - return $this->element->isVisible(); - }; - return $this->executeCommand($commandCallback, "visibility could not be got"); - } - - /** - * Returns whether the wrapped element is checked or not. - * - * @return bool true if the wrapped element is checked, false otherwise. - */ - public function isChecked() { - $commandCallback = function () { - return $this->element->isChecked(); - }; - return $this->executeCommand($commandCallback, "check state could not be got"); - } - - /** - * Returns the text of the wrapped element. - * - * If the wrapped element is not visible the returned text is an empty - * string. - * - * @return string the text of the wrapped element, or an empty string if it - * is not visible. - */ - public function getText() { - $commandCallback = function () { - return $this->element->getText(); - }; - return $this->executeCommand($commandCallback, "text could not be got"); - } - - /** - * Returns the value of the wrapped element. - * - * The value can be got even if the wrapped element is not visible. - * - * @return string the value of the wrapped element. - */ - public function getValue() { - $commandCallback = function () { - return $this->element->getValue(); - }; - return $this->executeCommand($commandCallback, "value could not be got"); - } - - /** - * Sets the given value on the wrapped element. - * - * If automatically waits for the wrapped element to be visible (up to the - * timeout set when finding it). - * - * @param string $value the value to set. - */ - public function setValue($value) { - $commandCallback = function () use ($value) { - $this->element->setValue($value); - }; - $this->executeCommandOnVisibleElement($commandCallback, "value could not be set"); - } - - /** - * Clicks on the wrapped element. - * - * If automatically waits for the wrapped element to be visible (up to the - * timeout set when finding it). - */ - public function click() { - $commandCallback = function () { - $this->element->click(); - }; - $this->executeCommandOnVisibleElement($commandCallback, "could not be clicked"); - } - - /** - * Check the wrapped element. - * - * If automatically waits for the wrapped element to be visible (up to the - * timeout set when finding it). - */ - public function check() { - $commandCallback = function () { - $this->element->check(); - }; - $this->executeCommand($commandCallback, "could not be checked"); - } - - /** - * uncheck the wrapped element. - * - * If automatically waits for the wrapped element to be visible (up to the - * timeout set when finding it). - */ - public function uncheck() { - $commandCallback = function () { - $this->element->uncheck(); - }; - $this->executeCommand($commandCallback, "could not be unchecked"); - } - - /** - * Executes the given command. - * - * If a StaleElementReference or a NoSuchElement exception is thrown the - * wrapped element is found again and, then, the command is executed again. - * - * @param \Closure $commandCallback the command to execute. - * @param string $errorMessage an error message that describes the failed - * command (appended to the description of the element). - */ - private function executeCommand(\Closure $commandCallback, $errorMessage) { - if (!$this->handleFailedCommands) { - return $commandCallback(); - } - - try { - return $commandCallback(); - } catch (\WebDriver\Exception\StaleElementReference $exception) { - $this->printFailedCommandMessage($exception, $errorMessage); - } catch (\WebDriver\Exception\NoSuchElement $exception) { - $this->printFailedCommandMessage($exception, $errorMessage); - } - - $this->element = $this->elementFinder->find(); - - return $commandCallback(); - } - - /** - * Executes the given command on a visible element. - * - * If a StaleElementReference or a NoSuchElement exception is thrown the - * wrapped element is found again and, then, the command is executed again. - * If an ElementNotVisible or a MoveTargetOutOfBounds exception is thrown it - * is waited for the wrapped element to be visible and, then, the command is - * executed again. - * If an ElementNotInteractable exception is thrown it is also waited for - * the wrapped element to be visible. It is very likely that the element was - * visible already, but it is not possible to easily check if the element - * can be interacted with, retrying will be only useful if it was a - * transitive situation that resolves itself with a wait (for example, due - * to an animation) and waiting for the element to be visible will always - * start with a wait. - * - * @param \Closure $commandCallback the command to execute. - * @param string $errorMessage an error message that describes the failed - * command (appended to the description of the element). - */ - private function executeCommandOnVisibleElement(\Closure $commandCallback, $errorMessage) { - if (!$this->handleFailedCommands) { - return $commandCallback(); - } - - try { - return $this->executeCommand($commandCallback, $errorMessage); - } catch (\WebDriver\Exception\ElementNotVisible $exception) { - $this->printFailedCommandMessage($exception, $errorMessage); - } catch (\WebDriver\Exception\MoveTargetOutOfBounds $exception) { - $this->printFailedCommandMessage($exception, $errorMessage); - } catch (\Exception $exception) { - // The "ElementNotInteractable" exception is not available yet in - // the current "instaclick/php-webdriver" version, so it is thrown - // as a generic exception with a specific message. - if (stripos($exception->getMessage(), "element not interactable") === false) { - throw $exception; - } - $this->printFailedCommandMessage($exception, $errorMessage); - } - - $this->waitForElementToBeVisible(); - - return $commandCallback(); - } - - /** - * Prints information about the failed command. - * - * @param \Exception exception the exception thrown by the command. - * @param string $errorMessage an error message that describes the failed - * command (appended to the description of the locator of the element). - */ - private function printFailedCommandMessage(\Exception $exception, $errorMessage) { - echo $this->elementFinder->getDescription() . " " . $errorMessage . "\n"; - echo "Exception message: " . $exception->getMessage() . "\n"; - echo "Trying again\n"; - } - - /** - * Waits for the wrapped element to be visible. - * - * This method waits up to the timeout used when finding the wrapped - * element; therefore, it may return when the element is still not visible. - * - * @return boolean true if the element is visible after the wait, false - * otherwise. - */ - private function waitForElementToBeVisible() { - $isVisibleCallback = function () { - return $this->isVisible(); - }; - $timeout = $this->elementFinder->getTimeout(); - $timeoutStep = $this->elementFinder->getTimeoutStep(); - - return Utils::waitFor($isVisibleCallback, $timeout, $timeoutStep); - } -} diff --git a/tests/acceptance/features/core/Locator.php b/tests/acceptance/features/core/Locator.php deleted file mode 100644 index 1b933399e6b..00000000000 --- a/tests/acceptance/features/core/Locator.php +++ /dev/null @@ -1,313 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/** - * Data object for the information needed to locate an element in a web page - * using Mink. - * - * Locators can be created directly using the constructor, or through a more - * fluent interface with Locator::forThe(). - */ -class Locator { - /** - * @var string - */ - private $description; - - /** - * @var string - */ - private $selector; - - /** - * @var string|array - */ - private $locator; - - /** - * @var null|Locator|\Behat\Mink\Element\ElementInterface - */ - private $ancestor; - - /** - * Starting point for the fluent interface to create Locators. - * - * @return LocatorBuilder - */ - public static function forThe() { - return new LocatorBuilder(); - } - - /** - * @param string $description - * @param string $selector - * @param string|array $locator - * @param null|Locator|\Behat\Mink\Element\ElementInterface $ancestor - */ - public function __construct($description, $selector, $locator, $ancestor = null) { - $this->description = $description; - $this->selector = $selector; - $this->locator = $locator; - $this->ancestor = $ancestor; - } - - /** - * @return string - */ - public function getDescription() { - return $this->description; - } - - /** - * @return string - */ - public function getSelector() { - return $this->selector; - } - - /** - * @return string|array - */ - public function getLocator() { - return $this->locator; - } - - /** - * @return null|Locator|\Behat\Mink\Element\ElementInterface - */ - public function getAncestor() { - return $this->ancestor; - } -} - -class LocatorBuilder { - /** - * @param string $selector - * @param string|array $locator - * @return LocatorBuilderSecondStep - */ - public function customSelector($selector, $locator) { - return new LocatorBuilderSecondStep($selector, $locator); - } - - /** - * @param string $cssExpression - * @return LocatorBuilderSecondStep - */ - public function css($cssExpression) { - return $this->customSelector("css", $cssExpression); - } - - /** - * @param string $xpathExpression - * @return LocatorBuilderSecondStep - */ - public function xpath($xpathExpression) { - return $this->customSelector("xpath", $xpathExpression); - } - - /** - * @param string $value - * @return LocatorBuilderSecondStep - */ - public function id($value) { - return $this->customSelector("named_exact", ["id", $value]); - } - - /** - * @param string $value - * @return LocatorBuilderSecondStep - */ - public function idOrName($value) { - return $this->customSelector("named_exact", ["id_or_name", $value]); - } - - /** - * @param string $value - * @return LocatorBuilderSecondStep - */ - public function link($value) { - return $this->customSelector("named_exact", ["link", $value]); - } - - /** - * @param string $value - * @return LocatorBuilderSecondStep - */ - public function button($value) { - return $this->customSelector("named_exact", ["button", $value]); - } - - /** - * @param string $value - * @return LocatorBuilderSecondStep - */ - public function linkOrButton($value) { - return $this->customSelector("named_exact", ["link_or_button", $value]); - } - - /** - * @param string $value - * @return LocatorBuilderSecondStep - */ - public function field($value) { - return $this->customSelector("named_exact", ["field", $value]); - } - - /** - * @param string $value - * @return LocatorBuilderSecondStep - */ - public function selectField($value) { - return $this->customSelector("named_exact", ["select", $value]); - } - - /** - * @param string $value - * @return LocatorBuilderSecondStep - */ - public function checkbox($value) { - return $this->customSelector("named_exact", ["checkbox", $value]); - } - - /** - * @param string $value - * @return LocatorBuilderSecondStep - */ - public function radioButton($value) { - return $this->customSelector("named_exact", ["radio", $value]); - } - - /** - * @param string $value - * @return LocatorBuilderSecondStep - */ - public function fileInput($value) { - return $this->customSelector("named_exact", ["file", $value]); - } - - /** - * @param string $value - * @return LocatorBuilderSecondStep - */ - public function optionGroup($value) { - return $this->customSelector("named_exact", ["optgroup", $value]); - } - - /** - * @param string $value - * @return LocatorBuilderSecondStep - */ - public function option($value) { - return $this->customSelector("named_exact", ["option", $value]); - } - - /** - * @param string $value - * @return LocatorBuilderSecondStep - */ - public function fieldSet($value) { - return $this->customSelector("named_exact", ["fieldset", $value]); - } - - /** - * @param string $value - * @return LocatorBuilderSecondStep - */ - public function table($value) { - return $this->customSelector("named_exact", ["table", $value]); - } -} - -class LocatorBuilderSecondStep { - /** - * @var string - */ - private $selector; - - /** - * @var string|array - */ - private $locator; - - /** - * @param string $selector - * @param string|array $locator - */ - public function __construct($selector, $locator) { - $this->selector = $selector; - $this->locator = $locator; - } - - /** - * @param Locator|\Behat\Mink\Element\ElementInterface $ancestor - * @return LocatorBuilderThirdStep - */ - public function descendantOf($ancestor) { - return new LocatorBuilderThirdStep($this->selector, $this->locator, $ancestor); - } - - /** - * @param string $description - * @return Locator - */ - public function describedAs($description) { - return new Locator($description, $this->selector, $this->locator); - } -} - -class LocatorBuilderThirdStep { - /** - * @var string - */ - private $selector; - - /** - * @var string|array - */ - private $locator; - - /** - * @var Locator|\Behat\Mink\Element\ElementInterface - */ - private $ancestor; - - /** - * @param string $selector - * @param string|array $locator - * @param Locator|\Behat\Mink\Element\ElementInterface $ancestor - */ - public function __construct($selector, $locator, $ancestor) { - $this->selector = $selector; - $this->locator = $locator; - $this->ancestor = $ancestor; - } - - /** - * @param string $description - * @return Locator - */ - public function describedAs($description) { - return new Locator($description, $this->selector, $this->locator, $this->ancestor); - } -} diff --git a/tests/acceptance/features/core/NextcloudTestServerContext.php b/tests/acceptance/features/core/NextcloudTestServerContext.php deleted file mode 100644 index d0dc0c32181..00000000000 --- a/tests/acceptance/features/core/NextcloudTestServerContext.php +++ /dev/null @@ -1,126 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -use Behat\Behat\Context\Context; -use Behat\Behat\Hook\Scope\BeforeScenarioScope; - -/** - * Behat context to run each scenario against a clean Nextcloud server. - * - * Before each scenario is run, this context sets up a fresh Nextcloud server - * with predefined data and configuration. Thanks to this every scenario is - * independent from the others and they all know the initial state of the - * server. - * - * This context is expected to be used along with RawMinkContext contexts (or - * subclasses). As the server address can be different for each scenario, this - * context automatically sets the "base_url" parameter of all its sibling - * RawMinkContexts; just add NextcloudTestServerContext to the context list of a - * suite in "behat.yml". - * - * The Nextcloud server is provided by an instance of NextcloudTestServerHelper; - * its class must be specified when this context is created. By default, - * "NextcloudTestServerLocalBuiltInHelper" is used, although that can be - * customized using the "nextcloudTestServerHelper" parameter in "behat.yml". In - * the same way, the parameters to be passed to the helper when it is created - * can be customized using the "nextcloudTestServerHelperParameters" parameter, - * which is an array (without keys) with the value of the parameters in the same - * order as in the constructor of the helper class (by default, [ ]). - * - * Example of custom parameters in "behat.yml": - * default: - * suites: - * default: - * contexts: - * - NextcloudTestServerContext: - * nextcloudTestServerHelper: NextcloudTestServerCustomHelper - * nextcloudTestServerHelperParameters: - * - first-parameter-value - * - second-parameter-value - */ -class NextcloudTestServerContext implements Context { - /** - * @var NextcloudTestServerHelper - */ - private $nextcloudTestServerHelper; - - /** - * Creates a new NextcloudTestServerContext. - * - * @param string $nextcloudTestServerHelper the name of the - * NextcloudTestServerHelper implementing class to use. - * @param array $nextcloudTestServerHelperParameters the parameters for the - * constructor of the $nextcloudTestServerHelper class. - */ - public function __construct($nextcloudTestServerHelper = "NextcloudTestServerLocalBuiltInHelper", - $nextcloudTestServerHelperParameters = [ ]) { - $nextcloudTestServerHelperClass = new ReflectionClass($nextcloudTestServerHelper); - - if ($nextcloudTestServerHelperParameters === null) { - $nextcloudTestServerHelperParameters = []; - } - - $this->nextcloudTestServerHelper = $nextcloudTestServerHelperClass->newInstanceArgs($nextcloudTestServerHelperParameters); - } - - /** - * @BeforeScenario - * - * Sets up the Nextcloud test server before each scenario. - * - * Once the Nextcloud test server is set up, the "base_url" parameter of the - * sibling RawMinkContexts is set to the base URL of the Nextcloud test - * server. - * - * @param \Behat\Behat\Hook\Scope\BeforeScenarioScope $scope the - * BeforeScenario hook scope. - * @throws \Exception if the Nextcloud test server can not be set up or its - * base URL got. - */ - public function setUpNextcloudTestServer(BeforeScenarioScope $scope) { - $this->nextcloudTestServerHelper->setUp(); - - $this->setBaseUrlInSiblingRawMinkContexts($scope, $this->nextcloudTestServerHelper->getBaseUrl()); - } - - /** - * @AfterScenario - * - * Cleans up the Nextcloud test server after each scenario. - * - * @throws \Exception if the Nextcloud test server can not be cleaned up. - */ - public function cleanUpNextcloudTestServer() { - $this->nextcloudTestServerHelper->cleanUp(); - } - - private function setBaseUrlInSiblingRawMinkContexts(BeforeScenarioScope $scope, $baseUrl) { - $environment = $scope->getEnvironment(); - - foreach ($environment->getContexts() as $context) { - if ($context instanceof Behat\MinkExtension\Context\RawMinkContext) { - $context->setMinkParameter("base_url", $baseUrl); - } - } - } -} diff --git a/tests/acceptance/features/core/NextcloudTestServerHelper.php b/tests/acceptance/features/core/NextcloudTestServerHelper.php deleted file mode 100644 index 69b8ce70505..00000000000 --- a/tests/acceptance/features/core/NextcloudTestServerHelper.php +++ /dev/null @@ -1,71 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/** - * Interface for classes that manage a Nextcloud server during acceptance tests. - * - * A NextcloudTestServerHelper takes care of setting up a Nextcloud server to be - * used in acceptance tests through its "setUp" method. It does not matter - * wheter the server is a fresh new server just started or an already running - * server; in any case, the state of the server must comply with the initial - * state expected by the tests (like having performed the Nextcloud installation - * or having an admin user with certain password). - * - * As the IP address and thus its the base URL of the server is not known - * beforehand, the NextcloudTestServerHelper must provide it through its - * "getBaseUrl" method. Note that this must be the base URL from the point of - * view of the Selenium server, which may be a different value than the base URL - * from the point of view of the acceptance tests themselves. - * - * Once the Nextcloud test server is no longer needed the "cleanUp" method will - * be called; depending on how the Nextcloud test server was set up it may not - * need to do anything. - * - * All the methods throw an exception if they fail to execute; as, due to the - * current use of this interface, it is just a warning for the test runner and - * nothing to be explicitly catched a plain base Exception is used. - */ -interface NextcloudTestServerHelper { - /** - * Sets up the Nextcloud test server. - * - * @throws \Exception if the Nextcloud test server can not be set up. - */ - public function setUp(); - - /** - * Cleans up the Nextcloud test server. - * - * @throws \Exception if the Nextcloud test server can not be cleaned up. - */ - public function cleanUp(); - - /** - * Returns the base URL of the Nextcloud test server (from the point of view - * of the Selenium server). - * - * @return string the base URL of the Nextcloud test server. - * @throws \Exception if the base URL can not be determined. - */ - public function getBaseUrl(); -} diff --git a/tests/acceptance/features/core/NextcloudTestServerLocalApacheHelper.php b/tests/acceptance/features/core/NextcloudTestServerLocalApacheHelper.php deleted file mode 100644 index 367e950931d..00000000000 --- a/tests/acceptance/features/core/NextcloudTestServerLocalApacheHelper.php +++ /dev/null @@ -1,128 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/** - * Helper to manage a Nextcloud test server started directly by the acceptance - * tests themselves using the Apache web server. - * - * The Nextcloud test server is executed using the Apache web server; the - * default Apache directory is expected to have been set to the root directory - * of the Nextcloud server (for example, by linking "var/www/html" to it); in - * any case, note that the acceptance tests must be run from the acceptance - * tests directory. The "setUp" method resets the Nextcloud server to its - * initial state and starts it, while the "cleanUp" method stops it. To be able - * to reset the Nextcloud server to its initial state a Git repository must be - * provided in the root directory of the Nextcloud server; the last commit in - * that Git repository must provide the initial state for the Nextcloud server - * expected by the acceptance tests. When the Nextcloud server is reset the - * owner of "apps", "config" and "data" must be set to the user that Apache - * server is run as; it is assumed that Apache is run as "www-data". - * - * The Nextcloud server is available at "$nextcloudServerDomain", which can be - * optionally specified when the NextcloudTestServerLocalApacheHelper is - * created; if no value is given "127.0.0.1" is used by default. In any case, - * the value of "$nextcloudServerDomain" must be seen as a trusted domain by the - * Nextcloud server (which would be the case for "127.0.0.1" if it was installed - * by running "occ maintenance:install"). The base URL to access the Nextcloud - * server can be got from "getBaseUrl". - */ -class NextcloudTestServerLocalApacheHelper implements NextcloudTestServerHelper { - /** - * @var string - */ - private $nextcloudServerDomain; - - /** - * Creates a new NextcloudTestServerLocalApacheHelper. - */ - public function __construct($nextcloudServerDomain = "127.0.0.1") { - $this->nextcloudServerDomain = $nextcloudServerDomain; - } - - /** - * Sets up the Nextcloud test server. - * - * It resets the Nextcloud test server restoring its last saved Git state - * and then waits for the Nextcloud test server to start again; if the - * server can not be reset or if it does not start again after some time an - * exception is thrown (as it is just a warning for the test runner and - * nothing to be explicitly catched a plain base Exception is used). - * - * @throws \Exception if the Nextcloud test server can not be reset or - * started again. - */ - public function setUp(): void { - // Ensure that previous Apache server is not running (as cleanUp may not - // have been called). - $this->stopApacheServer(); - - $this->execOrException("cd ../../ && git reset --hard HEAD"); - $this->execOrException("cd ../../ && git clean -d --force"); - $this->execOrException("cd ../../ && chown -R www-data:www-data apps config data"); - - $this->execOrException("service apache2 start"); - - $timeout = 60; - if (!Utils::waitForServer($this->getBaseUrl(), $timeout)) { - throw new Exception("Nextcloud test server could not be started"); - } - } - - /** - * Cleans up the Nextcloud test server. - * - * It stops the running Nextcloud test server, if any. - */ - public function cleanUp() { - $this->stopApacheServer(); - } - - /** - * Returns the base URL of the Nextcloud test server. - * - * @return string the base URL of the Nextcloud test server. - */ - public function getBaseUrl() { - return "http://" . $this->nextcloudServerDomain . "/index.php"; - } - - /** - * Executes the given command, throwing an Exception if it fails. - * - * @param string $command the command to execute. - * @throws \Exception if the command fails to execute. - */ - private function execOrException($command) { - exec($command . " 2>&1", $output, $returnValue); - if ($returnValue != 0) { - throw new Exception("'$command' could not be executed: " . implode("\n", $output)); - } - } - - /** - * Stops the Apache server started in setUp, if any. - */ - private function stopApacheServer() { - $this->execOrException("service apache2 stop"); - } -} diff --git a/tests/acceptance/features/core/NextcloudTestServerLocalBuiltInHelper.php b/tests/acceptance/features/core/NextcloudTestServerLocalBuiltInHelper.php deleted file mode 100644 index a1ab1f8720a..00000000000 --- a/tests/acceptance/features/core/NextcloudTestServerLocalBuiltInHelper.php +++ /dev/null @@ -1,142 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/** - * Helper to manage a Nextcloud test server started directly by the acceptance - * tests themselves using the PHP built-in web server. - * - * The Nextcloud test server is executed using the PHP built-in web server - * directly from the grandparent directory of the acceptance tests directory - * (that is, the root directory of the Nextcloud server); note that the - * acceptance tests must be run from the acceptance tests directory. The "setUp" - * method resets the Nextcloud server to its initial state and starts it, while - * the "cleanUp" method stops it. To be able to reset the Nextcloud server to - * its initial state a Git repository must be provided in the root directory of - * the Nextcloud server; the last commit in that Git repository must provide the - * initial state for the Nextcloud server expected by the acceptance tests. - * - * The Nextcloud server is available at "$nextcloudServerDomain", which can be - * optionally specified when the NextcloudTestServerLocalBuiltInHelper is - * created; if no value is given "127.0.0.1" is used by default. In any case, - * the value of "$nextcloudServerDomain" must be seen as a trusted domain by the - * Nextcloud server (which would be the case for "127.0.0.1" if it was installed - * by running "occ maintenance:install"). The base URL to access the Nextcloud - * server can be got from "getBaseUrl". - */ -class NextcloudTestServerLocalBuiltInHelper implements NextcloudTestServerHelper { - /** - * @var string - */ - private $nextcloudServerDomain; - - /** - * @var string - */ - private $phpServerPid; - - /** - * Creates a new NextcloudTestServerLocalBuiltInHelper. - */ - public function __construct($nextcloudServerDomain = "127.0.0.1") { - $this->nextcloudServerDomain = $nextcloudServerDomain; - - $this->phpServerPid = ""; - } - - /** - * Sets up the Nextcloud test server. - * - * It resets the Nextcloud test server restoring its last saved Git state - * and then waits for the Nextcloud test server to start again; if the - * server can not be reset or if it does not start again after some time an - * exception is thrown (as it is just a warning for the test runner and - * nothing to be explicitly catched a plain base Exception is used). - * - * @throws \Exception if the Nextcloud test server can not be reset or - * started again. - */ - public function setUp(): void { - // Ensure that previous PHP server is not running (as cleanUp may not - // have been called). - $this->killPhpServer(); - - $this->execOrException("cd ../../ && git reset --hard HEAD"); - $this->execOrException("cd ../../ && git clean -d --force"); - - // execOrException is not used because the server is started in the - // background, so the command will always succeed even if the server - // itself fails. - $this->phpServerPid = exec("php -S " . $this->nextcloudServerDomain . ":80 -t ../../ >/dev/null 2>&1 & echo $!"); - - $timeout = 60; - if (!Utils::waitForServer($this->getBaseUrl(), $timeout)) { - throw new Exception("Nextcloud test server could not be started"); - } - } - - /** - * Cleans up the Nextcloud test server. - * - * It kills the running Nextcloud test server, if any. - */ - public function cleanUp() { - $this->killPhpServer(); - } - - /** - * Returns the base URL of the Nextcloud test server. - * - * @return string the base URL of the Nextcloud test server. - */ - public function getBaseUrl() { - return "http://" . $this->nextcloudServerDomain . "/index.php"; - } - - /** - * Executes the given command, throwing an Exception if it fails. - * - * @param string $command the command to execute. - * @throws \Exception if the command fails to execute. - */ - private function execOrException($command) { - exec($command . " 2>&1", $output, $returnValue); - if ($returnValue != 0) { - throw new Exception("'$command' could not be executed: " . implode("\n", $output)); - } - } - - /** - * Kills the PHP built-in web server started in setUp, if any. - */ - private function killPhpServer() { - if ($this->phpServerPid == "") { - return; - } - - // execOrException is not used because the PID may no longer exist when - // trying to kill it. - exec("kill " . $this->phpServerPid); - - $this->phpServerPid = ""; - } -} diff --git a/tests/acceptance/features/core/NoSuchElementException.php b/tests/acceptance/features/core/NoSuchElementException.php deleted file mode 100644 index 35583c7e63f..00000000000 --- a/tests/acceptance/features/core/NoSuchElementException.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/** - * Exception to signal that the element looked for could not be found. - */ -class NoSuchElementException extends \Exception { - /** - * @param string $message - * @param null|\Exception $previous - */ - public function __construct($message, \Exception $previous = null) { - parent::__construct($message, 0, $previous); - } -} diff --git a/tests/acceptance/features/core/Utils.php b/tests/acceptance/features/core/Utils.php deleted file mode 100644 index eb7c65e993a..00000000000 --- a/tests/acceptance/features/core/Utils.php +++ /dev/null @@ -1,88 +0,0 @@ -<?php - -/** - * - * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -class Utils { - /** - * Waits at most $timeout seconds for the given condition to be true, - * checking it again every $timeoutStep seconds. - * - * Note that the timeout is no longer taken into account when a condition is - * met; that is, true will be returned if the condition is met before the - * timeout expires, but also if it is met exactly when the timeout expires. - * For example, even if the timeout is set to 0, the condition will be - * checked at least once, and true will be returned in that case if the - * condition was met. - * - * @param \Closure $conditionCallback the condition to wait for, as a - * function that returns a boolean. - * @param float $timeout the number of seconds (decimals allowed) to wait at - * most for the condition to be true. - * @param float $timeoutStep the number of seconds (decimals allowed) to - * wait before checking the condition again. - * @return boolean true if the condition is met before (or exactly when) the - * timeout expires, false otherwise. - */ - public static function waitFor($conditionCallback, $timeout, $timeoutStep) { - $elapsedTime = 0; - $conditionMet = false; - - while (!($conditionMet = $conditionCallback()) && $elapsedTime < $timeout) { - usleep($timeoutStep * 1000000); - - $elapsedTime += $timeoutStep; - } - - return $conditionMet; - } - - /** - * Waits at most $timeout seconds for the server at the given URL to be up, - * checking it again every $timeoutStep seconds. - * - * Note that it does not verify whether the URL returns a valid HTTP status - * or not; it simply checks that the server at the given URL is accessible. - * - * @param string $url the URL for the server to check. - * @param float $timeout the number of seconds (decimals allowed) to wait at - * most for the server. - * @param float $timeoutStep the number of seconds (decimals allowed) to - * wait before checking the server again; by default, 0.5 seconds. - * @return boolean true if the server was found, false otherwise. - */ - public static function waitForServer($url, $timeout, $timeoutStep = 0.5) { - $isServerUpCallback = function () use ($url) { - $curlHandle = curl_init($url); - - // Returning the transfer as the result of curl_exec prevents the - // transfer from being written to the output. - curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); - - $transfer = curl_exec($curlHandle); - - curl_close($curlHandle); - - return $transfer !== false; - }; - return self::waitFor($isServerUpCallback, $timeout, $timeoutStep); - } -} diff --git a/tests/acceptance/features/header.feature b/tests/acceptance/features/header.feature deleted file mode 100644 index 1d120e66b34..00000000000 --- a/tests/acceptance/features/header.feature +++ /dev/null @@ -1,86 +0,0 @@ -@apache -Feature: header - - Scenario: admin users can see admin-level items in the Settings menu - Given I am logged in as the admin - When I open the Settings menu - Then I see that the Settings menu is shown - And I see that the Settings menu has only 9 items - And I see that the "Set status" item in the Settings menu is shown - And I see that the "Appearance and accessibility" item in the Settings menu is shown - And I see that the "Personal settings" item in the Settings menu is shown - And I see that the "Administration settings" item in the Settings menu is shown - And I see that the "Apps" item in the Settings menu is shown - And I see that the "Users" item in the Settings menu is shown - And I see that the "Help" item in the Settings menu is shown - And I see that the "Log out" item in the Settings menu is shown - - Scenario: normal users can see basic items in the Settings menu - Given I am logged in - When I open the Settings menu - Then I see that the Settings menu is shown - And I see that the Settings menu has only 6 items - And I see that the "Set status" item in the Settings menu is shown - And I see that the "Appearance and accessibility" item in the Settings menu is shown - And I see that the "Settings" item in the Settings menu is shown - And I see that the "Help" item in the Settings menu is shown - And I see that the "Log out" item in the Settings menu is shown - - Scenario: other users are seen in the contacts menu - Given I am logged in as the admin - When I open the Contacts menu - Then I see that the Contacts menu is shown - And I see that the contact "user0" in the Contacts menu is shown - And I see that the contact "admin" in the Contacts menu is not shown - -# Scenario: users from other groups are not seen in the contacts menu when autocompletion is restricted within the same group -# Given I am logged in as the admin -# And I visit the admin settings page -# And I open the "Sharing" section of the "Administration" group -# And I enable restricting username autocompletion to groups -# And I see that username autocompletion is restricted to groups -# When I open the Contacts menu -# Then I see that the Contacts menu is shown -# And I see that the contact "user0" in the Contacts menu is not shown -# And I see that the contact "admin" in the Contacts menu is not shown - - Scenario: just added users are seen in the contacts menu - Given I am logged in as the admin - And I open the User settings - And I click the New user button - And I see that the new user form is shown - And I create user user2 with password 123456acb - # And I see that the list of users contains the user user2 - When I open the Contacts menu - Then I see that the Contacts menu is shown - And I see that the contact "user0" in the Contacts menu is shown - And I see that the contact "user1" in the Contacts menu is shown - And I see that the contact "user2" in the Contacts menu is shown - And I see that the contact "admin" in the Contacts menu is not shown - - Scenario: search for other users in the contacts menu - Given I am logged in as the admin - And I open the Contacts menu - And I see that the Contacts menu is shown - And I see that the contact "user0" in the Contacts menu is shown - And I see that the contact "user1" in the Contacts menu is shown - And I see that the Contacts menu search input is shown - When I search for the user "user0" - # First check that "user1" is no longer shown to ensure that the search was - # made; checking that "user0" is shown or that "admin" is not shown does not - # guarantee that (as they were already being shown and not being shown, - # respectively, before the search started). - Then I see that the contact "user1" in the Contacts menu is eventually not shown - And I see that the contact "user0" in the Contacts menu is shown - And I see that the contact "admin" in the Contacts menu is not shown - - Scenario: search for unknown users in the contacts menu - Given I am logged in as the admin - And I open the Contacts menu - And I see that the Contacts menu is shown - And I see that the contact "user0" in the Contacts menu is shown - And I see that the Contacts menu search input is shown - When I search for the user "unknownuser" - Then I see that the no results message in the Contacts menu is shown - And I see that the contact "user0" in the Contacts menu is not shown - And I see that the contact "admin" in the Contacts menu is not shown diff --git a/tests/acceptance/features/login.feature b/tests/acceptance/features/login.feature deleted file mode 100644 index 1022ec26aec..00000000000 --- a/tests/acceptance/features/login.feature +++ /dev/null @@ -1,55 +0,0 @@ -@apache -Feature: login - - Scenario: log in with valid user and password - Given I visit the Home page - When I log in with user user0 and password 123456acb - Then I see that the current page is the Files app - - Scenario: try to log in with valid user and invalid password - Given I visit the Home page - When I log in with user user0 and password 654321 - Then I see that the current page is the Login page - And I see that a wrong password message is shown - -# Scenario: log in with valid user and invalid password once fixed by admin -# Given I act as John -# And I can not log in with user user0 and password 654231 -# When I act as Jane -# And I am logged in as the admin -# And I open the User settings -# And I set the password for user0 to 654321 -# And I act as John -# And I log in with user user0 and password 654321 -# Then I see that the current page is the Files app - - Scenario: try to log in with invalid user - Given I visit the Home page - When I log in with user unknownUser and password 123456acb - Then I see that the current page is the Login page - And I see that a wrong password message is shown - - Scenario: try to log in as disabled user - Given I visit the Home page - When I log in with user disabledUser and password 123456acb - Then I see that the current page is the Login page - And I see that the disabled user message is shown - - Scenario: log in with invalid user once fixed by admin - Given I act as John - And I can not log in with user unknownUser and password 123456acb - When I act as Jane - And I am logged in as the admin - And I open the User settings - And I click the New user button - And I see that the new user form is shown - And I create user unknownUser with password 123456acb - # And I see that the list of users contains the user unknownUser - And I act as John - And I log in with user unknownUser and password 123456acb - Then I see that the current page is the Files app - - Scenario: log out - Given I am logged in - When I log out - Then I see that the current page is the Login page diff --git a/tests/acceptance/features/users.feature b/tests/acceptance/features/users.feature deleted file mode 100644 index 0f32819c027..00000000000 --- a/tests/acceptance/features/users.feature +++ /dev/null @@ -1,77 +0,0 @@ -@apache -Feature: users - - Scenario: assign user to a group - Given I act as Jane - And I am logged in as the admin - And I open the User settings - # And I see that the list of users contains the user user0 - # When I toggle the edit mode for the user user0 - # Then I see that the edit mode is on for user user0 - # disabled because we need the TAB patch: - # https://github.com/minkphp/MinkSelenium2Driver/pull/244 - # When I assign the user user0 to the group admin - # Then I see that the section Admins is shown - # And I see that the section Admins has a count of 2 - - Scenario: create and delete a group - Given I act as Jane - And I am logged in as the admin - And I open the User settings - # And I see that the list of users contains the user user0 - # disabled because we need the TAB patch: - # https://github.com/minkphp/MinkSelenium2Driver/pull/244 - # And I assign the user user0 to the group Group1 - # And I see that the section Group1 is shown - # And I click the "icon-delete" button on the Group1 section - # And I see that the confirmation dialog is shown - # When I click the "Yes" button of the confirmation dialog - # Then I see that the section Group1 is not shown - - Scenario: delete an empty group - Given I act as Jane - And I am logged in as the admin - And I open the User settings - # disabled because we need the TAB patch: - # https://github.com/minkphp/MinkSelenium2Driver/pull/244 - # And I assign the user user0 to the group Group1 - # And I see that the section Group1 is shown - # And I withdraw the user user0 from the group Group1 - # And I see that the section Group1 does not have a count - # And I click the "icon-delete" button on the Group1 section - # And I see that the confirmation dialog is shown - # When I click the "Yes" button of the confirmation dialog - # Then I see that the section Group1 is not shown - -# Scenario: change email -# Given I act as Jane -# And I am logged in as the admin -# And I open the User settings -# And I see that the list of users contains the user user0 -# And I see that the mailAddress of user0 is "" -# When I set the mailAddress for user0 to "test@nextcloud.com" -# And I see that the mailAddress cell for user user0 is done loading -# Then I see that the mailAddress of user0 is "test@nextcloud.com" - - Scenario: change user quota - Given I act as Jane - And I am logged in as the admin - And I open the User settings - # And I see that the list of users contains the user user0 - # When I toggle the edit mode for the user user0 - # Then I see that the edit mode is on for user user0 - # And I see that the user quota of user0 is Unlimited - # disabled because we need the TAB patch: - # https://github.com/minkphp/MinkSelenium2Driver/pull/244 - # When I set the user user0 quota to 1GB - # And I see that the quota cell for user user0 is done loading - # Then I see that the user quota of user0 is "1 GB" - # When I set the user user0 quota to Unlimited - # And I see that the quota cell for user user0 is done loading - # Then I see that the user quota of user0 is Unlimited - # When I set the user user0 quota to 0 - # And I see that the quota cell for user user0 is done loading - # Then I see that the user quota of user0 is "0 B" - # When I set the user user0 quota to Default - # And I see that the quota cell for user user0 is done loading - # Then I see that the user quota of user0 is "Default quota" |