From 39a56c7bc165cc782142a0a92fe1ec8423ecfa3d Mon Sep 17 00:00:00 2001 From: David Toledo Date: Mon, 25 Apr 2016 14:00:19 +0000 Subject: [PATCH 1/3] Added favorites integration tests --- .../integration/features/bootstrap/WebDav.php | 40 ++++++++++++++++++- build/integration/features/favorites.feature | 23 +++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 build/integration/features/favorites.feature diff --git a/build/integration/features/bootstrap/WebDav.php b/build/integration/features/bootstrap/WebDav.php index cd9584ad18..a63e2a5921 100644 --- a/build/integration/features/bootstrap/WebDav.php +++ b/build/integration/features/bootstrap/WebDav.php @@ -434,5 +434,43 @@ trait WebDav { $this->response = $ex->getResponse(); } } -} + /* + * @When user "([^"]*)" favorites folder "([^"]*)" + * @param string $user + * @param string $path + * @param \Behat\Gherkin\Node\TableNode|null $propertiesTable + */ + public function userFavoritesFolder($user, $path, $propertiesTable) { + $properties = null; + if ($propertiesTable instanceof \Behat\Gherkin\Node\TableNode) { + foreach ($propertiesTable->getRows() as $row) { + $properties[] = $row[0]; + } + } + $this->response = $this->favFolder($user, $path, 0, $properties); + } + + /*Set the elements of a proppatch, $folderDepth requires 1 to see elements without children*/ + public function favFolder($user, $path, $folderDepth, $properties = null){ + $fullUrl = substr($this->baseUrl, 0, -4); + $settings = array( + 'baseUri' => $fullUrl, + 'userName' => $user, + ); + if ($user === 'admin') { + $settings['password'] = $this->adminUser[1]; + } else { + $settings['password'] = $this->regularUser; + } + $client = new SClient($settings); + if (!$properties) { + $properties = [ + '{http://owncloud.org/ns}favorite' + ]; + } + echo $properties, + $response = $client->proppatch($this->davPath . '/' . ltrim($path, '/'), $properties, $folderDepth); + return $response; + } +} diff --git a/build/integration/features/favorites.feature b/build/integration/features/favorites.feature new file mode 100644 index 0000000000..4b437d13bd --- /dev/null +++ b/build/integration/features/favorites.feature @@ -0,0 +1,23 @@ +Feature: favorite + Background: + Given using api version "1" + + Scenario: Retrieving favorite info of a folder + Given using dav path "remote.php/webdav" + And As an "admin" + And user "user0" exists + When user "user0" favorites folder "/" + |{http://owncloud.org/ns}favorite| + Then As "user0" gets properties of folder "/" with + |{http://owncloud.org/ns}favorite| + And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1" + + Scenario: Retrieving favorite info of a file + Given using dav path "remote.php/webdav" + And As an "admin" + And user "user0" exists + When user "user0" favorites folder "/textfile0.txt" + |{http://owncloud.org/ns}favorite| + Then As "user0" gets properties of folder "/textfile0.txt" with + |{http://owncloud.org/ns}favorite| + And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1" \ No newline at end of file From 4232458652d25afecd19783eb62db4e4d9517c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Bertol=C3=ADn?= Date: Tue, 14 Jun 2016 16:20:40 +0000 Subject: [PATCH 2/3] Fixing the tests --- .../integration/features/bootstrap/WebDav.php | 31 ++++++++++--------- build/integration/features/favorites.feature | 10 +++--- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/build/integration/features/bootstrap/WebDav.php b/build/integration/features/bootstrap/WebDav.php index a63e2a5921..10bd05cbbb 100644 --- a/build/integration/features/bootstrap/WebDav.php +++ b/build/integration/features/bootstrap/WebDav.php @@ -435,20 +435,11 @@ trait WebDav { } } - /* - * @When user "([^"]*)" favorites folder "([^"]*)" - * @param string $user - * @param string $path - * @param \Behat\Gherkin\Node\TableNode|null $propertiesTable + /** + * @When user :user favorites element :path */ - public function userFavoritesFolder($user, $path, $propertiesTable) { - $properties = null; - if ($propertiesTable instanceof \Behat\Gherkin\Node\TableNode) { - foreach ($propertiesTable->getRows() as $row) { - $properties[] = $row[0]; - } - } - $this->response = $this->favFolder($user, $path, 0, $properties); + public function userFavoritesFolder($user, $path){ + $this->response = $this->favFolder($user, $path, 0, null); } /*Set the elements of a proppatch, $folderDepth requires 1 to see elements without children*/ @@ -466,11 +457,21 @@ trait WebDav { $client = new SClient($settings); if (!$properties) { $properties = [ - '{http://owncloud.org/ns}favorite' + '{http://owncloud.org/ns}favorite' => 1 ]; } - echo $properties, + $response = $client->proppatch($this->davPath . '/' . ltrim($path, '/'), $properties, $folderDepth); return $response; } + + /** + * @Then /^as "([^"]*)" gets properties of file "([^"]*)" with$/ + * @param string $user + * @param string $path + * @param \Behat\Gherkin\Node\TableNode|null $propertiesTable + */ + public function asGetsPropertiesOfFileWith($user, $path, $propertiesTable) { + $this->asGetsPropertiesOfFolderWith($user, $path, $propertiesTable); + } } diff --git a/build/integration/features/favorites.feature b/build/integration/features/favorites.feature index 4b437d13bd..8025f0834f 100644 --- a/build/integration/features/favorites.feature +++ b/build/integration/features/favorites.feature @@ -6,9 +6,8 @@ Feature: favorite Given using dav path "remote.php/webdav" And As an "admin" And user "user0" exists - When user "user0" favorites folder "/" - |{http://owncloud.org/ns}favorite| - Then As "user0" gets properties of folder "/" with + When user "user0" favorites element "/FOLDER" + Then as "user0" gets properties of folder "/FOLDER" with |{http://owncloud.org/ns}favorite| And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1" @@ -16,8 +15,7 @@ Feature: favorite Given using dav path "remote.php/webdav" And As an "admin" And user "user0" exists - When user "user0" favorites folder "/textfile0.txt" - |{http://owncloud.org/ns}favorite| - Then As "user0" gets properties of folder "/textfile0.txt" with + When user "user0" favorites element "/textfile0.txt" + Then as "user0" gets properties of file "/textfile0.txt" with |{http://owncloud.org/ns}favorite| And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1" \ No newline at end of file From 19b7ae673a8553621b3544aa57f153cf2b7c8ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Bertol=C3=ADn?= Date: Wed, 15 Jun 2016 10:16:27 +0000 Subject: [PATCH 3/3] Added unfavoriting tests and some rewording --- .../integration/features/bootstrap/WebDav.php | 17 ++++++++---- build/integration/features/favorites.feature | 27 ++++++++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/build/integration/features/bootstrap/WebDav.php b/build/integration/features/bootstrap/WebDav.php index 10bd05cbbb..0abb866773 100644 --- a/build/integration/features/bootstrap/WebDav.php +++ b/build/integration/features/bootstrap/WebDav.php @@ -214,7 +214,7 @@ trait WebDav { } $value = $keys[$key]; - if ($value !== $expectedValue) { + if ($value != $expectedValue) { throw new \Exception("Property \"$key\" found with value \"$value\", expected \"$expectedValue\""); } } @@ -438,12 +438,19 @@ trait WebDav { /** * @When user :user favorites element :path */ - public function userFavoritesFolder($user, $path){ - $this->response = $this->favFolder($user, $path, 0, null); + public function userFavoritesElement($user, $path){ + $this->response = $this->changeFavStateOfAnElement($user, $path, 1, 0, null); + } + + /** + * @When user :user unfavorites element :path + */ + public function userUnfavoritesElement($user, $path){ + $this->response = $this->changeFavStateOfAnElement($user, $path, 0, 0, null); } /*Set the elements of a proppatch, $folderDepth requires 1 to see elements without children*/ - public function favFolder($user, $path, $folderDepth, $properties = null){ + public function changeFavStateOfAnElement($user, $path, $favOrUnfav, $folderDepth, $properties = null){ $fullUrl = substr($this->baseUrl, 0, -4); $settings = array( 'baseUri' => $fullUrl, @@ -457,7 +464,7 @@ trait WebDav { $client = new SClient($settings); if (!$properties) { $properties = [ - '{http://owncloud.org/ns}favorite' => 1 + '{http://owncloud.org/ns}favorite' => $favOrUnfav ]; } diff --git a/build/integration/features/favorites.feature b/build/integration/features/favorites.feature index 8025f0834f..86643fdd1e 100644 --- a/build/integration/features/favorites.feature +++ b/build/integration/features/favorites.feature @@ -2,7 +2,7 @@ Feature: favorite Background: Given using api version "1" - Scenario: Retrieving favorite info of a folder + Scenario: Favorite a folder Given using dav path "remote.php/webdav" And As an "admin" And user "user0" exists @@ -11,11 +11,32 @@ Feature: favorite |{http://owncloud.org/ns}favorite| And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1" - Scenario: Retrieving favorite info of a file + Scenario: Favorite and unfavorite a folder + Given using dav path "remote.php/webdav" + And As an "admin" + And user "user0" exists + When user "user0" favorites element "/FOLDER" + And user "user0" unfavorites element "/FOLDER" + Then as "user0" gets properties of folder "/FOLDER" with + |{http://owncloud.org/ns}favorite| + And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "" + + Scenario: Favorite a file Given using dav path "remote.php/webdav" And As an "admin" And user "user0" exists When user "user0" favorites element "/textfile0.txt" Then as "user0" gets properties of file "/textfile0.txt" with |{http://owncloud.org/ns}favorite| - And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1" \ No newline at end of file + And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1" + + Scenario: Favorite and unfavorite a file + Given using dav path "remote.php/webdav" + And As an "admin" + And user "user0" exists + When user "user0" favorites element "/textfile0.txt" + And user "user0" unfavorites element "/textfile0.txt" + Then as "user0" gets properties of file "/textfile0.txt" with + |{http://owncloud.org/ns}favorite| + And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "" +