diff options
Diffstat (limited to 'tests/acceptance/features/bootstrap')
22 files changed, 0 insertions, 4720 deletions
diff --git a/tests/acceptance/features/bootstrap/AppNavigationContext.php b/tests/acceptance/features/bootstrap/AppNavigationContext.php deleted file mode 100644 index ef8cb8cae8b..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/a[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 210e907a9bc..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()->xpath("//label[@for = '$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 747ef3d96b5..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='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'), 2)->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 577b14b7e72..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 ae4eab89ec7..00000000000 --- a/tests/acceptance/features/bootstrap/ContactsMenuContext.php +++ /dev/null @@ -1,146 +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']")-> - describedAs("Contacts menu button"); - } - - /** - * @return Locator - */ - public static function contactsMenu() { - return Locator::forThe()->css(".menu")-> - descendantOf(self::contactsMenuButton())-> - 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 dea9f434bab..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 af8534f012c..00000000000 --- a/tests/acceptance/features/bootstrap/FileListAncestorSetter.php +++ /dev/null @@ -1,65 +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 ce2bd9971e0..00000000000 --- a/tests/acceptance/features/bootstrap/FileListContext.php +++ /dev/null @@ -1,596 +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("#controls .breadcrumb")-> - descendantOf($fileListAncestor)-> - describedAs("Breadcrumbs in file list"); - } - - /** - * @return Locator - */ - public static function createMenuButton($fileListAncestor) { - return Locator::forThe()->css("#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("//*[@id = '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/FilePickerContext.php b/tests/acceptance/features/bootstrap/FilePickerContext.php deleted file mode 100644 index b9d82090eaa..00000000000 --- a/tests/acceptance/features/bootstrap/FilePickerContext.php +++ /dev/null @@ -1,125 +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; - -class FilePickerContext implements Context, ActorAwareInterface { - use ActorAware; - - /** - * @return Locator - */ - public static function dialog() { - return Locator::forThe()->css(".oc-dialog")-> - describedAs("File picker dialog"); - } - - /** - * @return Locator - */ - public static function fileListContainer() { - return Locator::forThe()->css("#oc-dialog-filepicker-content")-> - descendantOf(self::dialog())-> - describedAs("File list container in the file picker dialog"); - } - - /** - * @return Locator - */ - public static function rowForFile($fileName) { - // File names in the file picker are split in two span elements, so - // their texts need to be concatenated to get the full file name. - return Locator::forThe()->xpath("//*[@id = 'picker-filestable']//*[contains(concat(' ', normalize-space(@class), ' '), ' filename-parts ') and concat(span[1], span[2]) = '$fileName']/ancestor::tr")-> - descendantOf(self::fileListContainer())-> - describedAs("Row for file $fileName in the file picker dialog"); - } - - /** - * @return Locator - */ - public static function buttonRow() { - return Locator::forThe()->css(".oc-dialog-buttonrow")-> - descendantOf(self::dialog())-> - describedAs("Button row in the file picker dialog"); - } - - /** - * @return Locator - */ - private static function buttonFor($buttonText) { - // "Copy" and "Move" buttons text is set to "Copy to XXX" and "Move to - // XXX" when a folder is selected. - return Locator::forThe()->xpath("//button[starts-with(normalize-space(), '$buttonText')]")-> - descendantOf(self::buttonRow())-> - describedAs($buttonText . " button in the file picker dialog"); - } - - /** - * @return Locator - */ - public static function copyButton() { - return self::buttonFor("Copy"); - } - - /** - * @return Locator - */ - public static function moveButton() { - return self::buttonFor("Move"); - } - - /** - * @return Locator - */ - public static function chooseButton() { - return self::buttonFor("Choose"); - } - - /** - * @When I select :fileName in the file picker - */ - public function iSelectInTheFilePicker($fileName) { - $this->actor->find(self::rowForFile($fileName), 10)->click(); - } - - /** - * @When I copy to the last selected folder in the file picker - */ - public function iCopyToTheLastSelectedFolderInTheFilePicker() { - $this->actor->find(self::copyButton(), 10)->click(); - } - - /** - * @When I move to the last selected folder in the file picker - */ - public function iMoveToTheLastSelectedFolderInTheFilePicker() { - $this->actor->find(self::moveButton(), 10)->click(); - } - - /** - * @When I choose the last selected file in the file picker - */ - public function iChooseTheLastSelectedFileInTheFilePicker() { - $this->actor->find(self::chooseButton(), 10)->click(); - } -} diff --git a/tests/acceptance/features/bootstrap/FilesAppContext.php b/tests/acceptance/features/bootstrap/FilesAppContext.php deleted file mode 100644 index 31fe864bc36..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()->id("appmenu")-> - describedAs("App menu in header"); - } - - /** - * @return Locator - */ - public static function filesItemInAppMenu() { - return Locator::forThe()->xpath("/li[@data-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(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--star")-> - 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--starred")-> - 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("//li[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 d71b0196dbb..00000000000 --- a/tests/acceptance/features/bootstrap/FilesAppSharingContext.php +++ /dev/null @@ -1,812 +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-input .multiselect__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(".sharing-input .multiselect__content-wrapper")-> - descendantOf(FilesAppContext::detailsView())-> - 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[contains(concat(' ', normalize-space(@class), ' '), ' multiselect__element ')]//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 ')]//h5[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 .trigger")-> - 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.icon-add")-> - 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 .trigger")-> - 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.action-input__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.action-input__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 7502b143718..00000000000 --- a/tests/acceptance/features/bootstrap/LoginPageContext.php +++ /dev/null @@ -1,161 +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; - - /** - * @return Locator - */ - public static function userNameField() { - return Locator::forThe()->field("user")-> - describedAs("User name field in Login page"); - } - - /** - * @return Locator - */ - public static function passwordField() { - return Locator::forThe()->field("password")-> - describedAs("Password field in Login page"); - } - - /** - * @return Locator - */ - public static function loginButton() { - return Locator::forThe()->css(".submit-wrapper .submit-wrapper__input")-> - describedAs("Login button in Login page"); - } - - /** - * @return Locator - */ - public static function wrongPasswordMessage() { - return Locator::forThe()->xpath("//*[@class = 'warning wrongPasswordMsg' 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 = 'warning userDisabledMsg' 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($user, $password) { - $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 15ad6ee90c8..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("//div[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 2895202ed7f..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()->xpath("//*[@class = 'warning' and normalize-space() = 'The password is wrong. Try again.']")-> - 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::assertContains($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 db7aeb90ffe..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 1e0eadd044a..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 1572dea3faa..00000000000 --- a/tests/acceptance/features/bootstrap/SettingsMenuContext.php +++ /dev/null @@ -1,220 +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 = 'settings']")-> - describedAs("Settings menu section in the header"); - } - - /** - * @return Locator - */ - public static function settingsMenuButton() { - return Locator::forThe()->id("expand")-> - descendantOf(self::settingsSectionInHeader())-> - describedAs("Settings menu button"); - } - - /** - * @return Locator - */ - public static function settingsMenu() { - return Locator::forThe()->id("expanddiv")-> - 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 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 d17d9c18109..00000000000 --- a/tests/acceptance/features/bootstrap/ThemingAppContext.php +++ /dev/null @@ -1,164 +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 $('#theming-color')[0].value;")); - $inputBgColor = $this->getRGBArray($actor->getSession()->evaluateScript("return $('#theming-color').css('background-color');")); - if ($colorSelectorValue == $inputBgColor) { - 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 header color is eventually :color - */ - public function iSeeThatTheHeaderColorIsEventually($color) { - $headerColorMatchesCallback = function () use ($color) { - $headerColor = $this->actor->getSession()->evaluateScript("return $('#header').css('background-color');"); - $headerColor = $this->getRGBArray($headerColor); - $color = $this->getRGBArray($color); - - return $headerColor == $color; - }; - - if (!Utils::waitFor($headerColorMatchesCallback, $timeout = 10 * $this->actor->getFindTimeoutMultiplier(), $timeoutStep = 1)) { - Assert::fail("The header color 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 3dc941901c1..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 ce035647104..00000000000 --- a/tests/acceptance/features/bootstrap/UsersSettingsContext.php +++ /dev/null @@ -1,377 +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()->id("new-user")-> - describedAs("New user form in Users Settings"); - } - - /** - * @return Locator - */ - public static function userNameFieldForNewUser() { - return Locator::forThe()->field("newusername")-> - describedAs("User name field for new user in Users Settings"); - } - - /** - * @return Locator - */ - public static function displayNameFieldForNewUser() { - return Locator::forThe()->field("newdisplayname")-> - describedAs("Display name field for new user in Users Settings"); - } - - /** - * @return Locator - */ - public static function passwordFieldForNewUser() { - return Locator::forThe()->field("newuserpassword")-> - 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()->xpath("//form[@id = 'new-user']//button[@type = 'submit']")-> - describedAs("Create user button in Users Settings"); - } - - /** - * @return Locator - */ - public static function rowForUser($user) { - return Locator::forThe()->css("div.user-list-grid div.row[data-id=$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(".multiselect__option--highlight")-> - descendantOf(self::classCellForUser($cell, $user))-> - describedAs("Selected $cell option in $cell input for user $user in Users Settings"); - } - - /** - * @return Locator - */ - public static function actionsMenuOf($user) { - return Locator::forThe()->css(".icon-more")-> - 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[normalize-space() = '$action']")-> - descendantOf(self::rowForUser($user))-> - 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(".multiselect__single")-> - 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(".toggleUserActions button.icon-rename")-> - 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() { - Assert::assertTrue( - $this->actor->find(self::newUserForm(), 10)->isVisible()); - } - - /** - * @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 b07586c4662..00000000000 --- a/tests/acceptance/features/bootstrap/WaitFor.php +++ /dev/null @@ -1,77 +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); - } -} |