Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2018-02-19 18:58:57 +0300
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2018-03-09 14:26:58 +0300
commit05fd72937bb8e976b8c040c4508df8fefbaf3494 (patch)
tree1dc82440efddc53e9527ff53a975fc0a9d3b0d56 /tests
parent7ebbd666a80e2054746b376fde9e662a9e405fac (diff)
Generalize file list steps so a specific ancestor can be used
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, so until now the file list steps were explicitly wired to the Files app and they could be used only in that case. Instead of duplicating the steps with a slightly different name (for example, "I create a new folder named :folderName in the public shared folder" instead of "I create a new folder named :folderName") the steps were generalized; now contexts that "know" that certain file list ancestor has to be used by the FileListContext steps performed by certain actor from that point on (until changed again) set it explicitly. For example, when the current page is the Files app then the ancestor of the file list is the main view of the current section of the Files app, but when the current page is a shared link then the ancestor is set to null (because there will be just one file list, and thus its ancestor is not relevant to differentiate between instances) A helper trait, "FileListAncestorSetter", was introduced to reduce the boilerplate needed to set the file list ancestor from other contexts. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/acceptance/features/bootstrap/FileListAncestorSetter.php67
-rw-r--r--tests/acceptance/features/bootstrap/FileListContext.php45
-rw-r--r--tests/acceptance/features/bootstrap/FilesAppContext.php3
-rw-r--r--tests/acceptance/features/bootstrap/FilesSharingAppContext.php3
4 files changed, 115 insertions, 3 deletions
diff --git a/tests/acceptance/features/bootstrap/FileListAncestorSetter.php b/tests/acceptance/features/bootstrap/FileListAncestorSetter.php
new file mode 100644
index 00000000000..2f8d3ad00e5
--- /dev/null
+++ b/tests/acceptance/features/bootstrap/FileListAncestorSetter.php
@@ -0,0 +1,67 @@
+<?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 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
index d15e8ba40f4..236adafcbf8 100644
--- a/tests/acceptance/features/bootstrap/FileListContext.php
+++ b/tests/acceptance/features/bootstrap/FileListContext.php
@@ -25,7 +25,15 @@ use Behat\Behat\Context\Context;
class FileListContext implements Context, ActorAwareInterface {
- use ActorAware;
+ /**
+ * @var Actor
+ */
+ private $actor;
+
+ /**
+ * @var array
+ */
+ private $fileListAncestorsByActor;
/**
* @var Locator
@@ -35,8 +43,39 @@ class FileListContext implements Context, ActorAwareInterface {
/**
* @BeforeScenario
*/
- public function initializeFileListAncestor() {
- $this->fileListAncestor = FilesAppContext::currentSectionMainView();
+ public function initializeFileListAncestors() {
+ $this->fileListAncestorsByActor = array();
+ $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;
}
/**
diff --git a/tests/acceptance/features/bootstrap/FilesAppContext.php b/tests/acceptance/features/bootstrap/FilesAppContext.php
index 81ba7b69844..a9bb8a619e2 100644
--- a/tests/acceptance/features/bootstrap/FilesAppContext.php
+++ b/tests/acceptance/features/bootstrap/FilesAppContext.php
@@ -26,6 +26,7 @@ use Behat\Behat\Context\Context;
class FilesAppContext implements Context, ActorAwareInterface {
use ActorAware;
+ use FileListAncestorSetter;
/**
* @return array
@@ -321,6 +322,8 @@ class FilesAppContext implements Context, ActorAwareInterface {
PHPUnit_Framework_Assert::assertStringStartsWith(
$this->actor->locatePath("/apps/files/"),
$this->actor->getSession()->getCurrentUrl());
+
+ $this->setFileListAncestorForActor(self::currentSectionMainView(), $this->actor);
}
/**
diff --git a/tests/acceptance/features/bootstrap/FilesSharingAppContext.php b/tests/acceptance/features/bootstrap/FilesSharingAppContext.php
index f3386b46db9..f9a328038c7 100644
--- a/tests/acceptance/features/bootstrap/FilesSharingAppContext.php
+++ b/tests/acceptance/features/bootstrap/FilesSharingAppContext.php
@@ -26,6 +26,7 @@ use Behat\Behat\Context\Context;
class FilesSharingAppContext implements Context, ActorAwareInterface {
use ActorAware;
+ use FileListAncestorSetter;
/**
* @return Locator
@@ -140,6 +141,8 @@ class FilesSharingAppContext implements Context, ActorAwareInterface {
PHPUnit_Framework_Assert::assertEquals(
$this->actor->getSharedNotebook()["shared link"],
$this->actor->getSession()->getCurrentUrl());
+
+ $this->setFileListAncestorForActor(null, $this->actor);
}
/**