diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2018-07-25 17:46:52 +0200 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2018-07-25 18:53:45 +0200 |
commit | 1e16f7ecd9f6aa28af73545b4a53feeae2f8056d (patch) | |
tree | 76d1c21ecfc53ef68074807de690cdb09c085b2d /build/integration | |
parent | 8c7969e7301cb88dc6a94565ef8903c70117e750 (diff) | |
download | nextcloud-server-1e16f7ecd9f6aa28af73545b4a53feeae2f8056d.tar.gz nextcloud-server-1e16f7ecd9f6aa28af73545b4a53feeae2f8056d.zip |
Add integration tests for searching files by comments
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'build/integration')
-rw-r--r-- | build/integration/features/bootstrap/FeatureContext.php | 1 | ||||
-rw-r--r-- | build/integration/features/bootstrap/Search.php | 90 | ||||
-rw-r--r-- | build/integration/features/comments-search.feature | 266 |
3 files changed, 357 insertions, 0 deletions
diff --git a/build/integration/features/bootstrap/FeatureContext.php b/build/integration/features/bootstrap/FeatureContext.php index 6b0b199ec6e..5a6cab235e5 100644 --- a/build/integration/features/bootstrap/FeatureContext.php +++ b/build/integration/features/bootstrap/FeatureContext.php @@ -32,5 +32,6 @@ require __DIR__ . '/../../vendor/autoload.php'; * Features context. */ class FeatureContext implements Context, SnippetAcceptingContext { + use Search; use WebDav; } diff --git a/build/integration/features/bootstrap/Search.php b/build/integration/features/bootstrap/Search.php new file mode 100644 index 00000000000..e42cde19126 --- /dev/null +++ b/build/integration/features/bootstrap/Search.php @@ -0,0 +1,90 @@ +<?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\Gherkin\Node\TableNode; +use PHPUnit\Framework\Assert; + +trait Search { + + // BasicStructure trait is expected to be used in the class that uses this + // trait. + + /** + * @When /^searching for "([^"]*)"$/ + * @param string $query + */ + public function searchingFor(string $query) { + $this->searchForInApp($query, ''); + } + + /** + * @When /^searching for "([^"]*)" in app "([^"]*)"$/ + * @param string $query + * @param string $app + */ + public function searchingForInApp(string $query, string $app) { + $url = '/index.php/core/search'; + + $parameters[] = 'query=' . $query; + $parameters[] = 'inApps[]=' . $app; + + $url .= '?' . implode('&', $parameters); + + $this->sendingAToWithRequesttoken('GET', $url); + } + + /** + * @Then /^the list of search results has "(\d+)" results$/ + */ + public function theListOfSearchResultsHasResults(int $count) { + $this->theHTTPStatusCodeShouldBe(200); + + $searchResults = json_decode($this->response->getBody()); + + Assert::assertEquals($count, count($searchResults)); + } + + /** + * @Then /^search result "(\d+)" contains$/ + * + * @param int $number + * @param TableNode $body + */ + public function searchResultXContains(int $number, TableNode $body) { + if (!($body instanceof TableNode)) { + return; + } + + $searchResults = json_decode($this->response->getBody(), $asAssociativeArray = true); + $searchResult = $searchResults[$number]; + + foreach ($body->getRowsHash() as $expectedField => $expectedValue) { + if (!array_key_exists($expectedField, $searchResult)) { + Assert::fail("$expectedField was not found in response"); + } + + Assert::assertEquals($expectedValue, $searchResult[$expectedField], "Field '$expectedField' does not match ({$searchResult[$expectedField]})"); + } + } + +} diff --git a/build/integration/features/comments-search.feature b/build/integration/features/comments-search.feature new file mode 100644 index 00000000000..1886cb531b9 --- /dev/null +++ b/build/integration/features/comments-search.feature @@ -0,0 +1,266 @@ +Feature: comments-search + + Scenario: Search my own comment on a file belonging to myself + Given user "user0" exists + And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt" + And "user0" posts a comment with content "My first comment" on the file named "/myFileToComment.txt" it should return "201" + When Logging in using web as "user0" + And searching for "first" in app "files" + Then the list of search results has "1" results + And search result "0" contains + | type | comment | + | comment | My first comment | + | authorId | user0 | + | authorName | user0 | + | path | myFileToComment.txt | + | fileName | myFileToComment.txt | + | name | My first comment | + + Scenario: Search my own comment on a file shared by someone with me + Given user "user0" exists + And user "user1" exists + And User "user1" uploads file "data/textfile.txt" to "/sharedFileToComment.txt" + And As "user1" sending "POST" to "/apps/files_sharing/api/v1/shares" with + | path | sharedFileToComment.txt | + | shareWith | user0 | + | shareType | 0 | + And "user0" posts a comment with content "My first comment" on the file named "/sharedFileToComment.txt" it should return "201" + When Logging in using web as "user0" + And searching for "first" in app "files" + Then the list of search results has "1" results + And search result "0" contains + | type | comment | + | comment | My first comment | + | authorId | user0 | + | authorName | user0 | + | path | sharedFileToComment.txt | + | fileName | sharedFileToComment.txt | + | name | My first comment | + + Scenario: Search other user's comment on a file shared by me + Given user "user0" exists + And user "user1" exists + And User "user0" uploads file "data/textfile.txt" to "/mySharedFileToComment.txt" + And As "user0" sending "POST" to "/apps/files_sharing/api/v1/shares" with + | path | mySharedFileToComment.txt | + | shareWith | user1 | + | shareType | 0 | + And "user1" posts a comment with content "Other's first comment" on the file named "/mySharedFileToComment.txt" it should return "201" + When Logging in using web as "user0" + And searching for "first" in app "files" + Then the list of search results has "1" results + And search result "0" contains + | type | comment | + | comment | Other's first comment | + | authorId | user1 | + | authorName | user1 | + | path | mySharedFileToComment.txt | + | fileName | mySharedFileToComment.txt | + | name | Other's first comment | + + Scenario: Search other user's comment on a file shared by someone with me + Given user "user0" exists + And user "user1" exists + And User "user1" uploads file "data/textfile.txt" to "/sharedFileToComment.txt" + And As "user1" sending "POST" to "/apps/files_sharing/api/v1/shares" with + | path | sharedFileToComment.txt | + | shareWith | user0 | + | shareType | 0 | + And "user1" posts a comment with content "Other's first comment" on the file named "/sharedFileToComment.txt" it should return "201" + When Logging in using web as "user0" + And searching for "first" in app "files" + Then the list of search results has "1" results + And search result "0" contains + | type | comment | + | comment | Other's first comment | + | authorId | user1 | + | authorName | user1 | + | path | sharedFileToComment.txt | + | fileName | sharedFileToComment.txt | + | name | Other's first comment | + + Scenario: Search several comments on a file belonging to myself + Given user "user0" exists + And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt" + And "user0" posts a comment with content "My first comment to be found" on the file named "/myFileToComment.txt" it should return "201" + And "user0" posts a comment with content "The second comment should not be found" on the file named "/myFileToComment.txt" it should return "201" + And "user0" posts a comment with content "My third comment to be found" on the file named "/myFileToComment.txt" it should return "201" + When Logging in using web as "user0" + And searching for "comment to be found" in app "files" + Then the list of search results has "2" results + And search result "0" contains + | type | comment | + | comment | My third comment to be found | + | authorId | user0 | + | authorName | user0 | + | path | myFileToComment.txt | + | fileName | myFileToComment.txt | + | name | My third comment to be found | + And search result "1" contains + | type | comment | + | comment | My first comment to be found | + | authorId | user0 | + | authorName | user0 | + | path | myFileToComment.txt | + | fileName | myFileToComment.txt | + | name | My first comment to be found | + + Scenario: Search comment with a large message ellipsized on the right + Given user "user0" exists + And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt" + And "user0" posts a comment with content "A very verbose message that is meant to be used to test the ellipsized message returned when searching for long comments" on the file named "/myFileToComment.txt" it should return "201" + When Logging in using web as "user0" + And searching for "verbose" in app "files" + Then the list of search results has "1" results + And search result "0" contains + | type | comment | + | comment | A very verbose message that is meant to… | + | authorId | user0 | + | authorName | user0 | + | path | myFileToComment.txt | + | fileName | myFileToComment.txt | + | name | A very verbose message that is meant to be used to test the ellipsized message returned when searching for long comments | + + Scenario: Search comment with a large message ellipsized on the left + Given user "user0" exists + And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt" + And "user0" posts a comment with content "A very verbose message that is meant to be used to test the ellipsized message returned when searching for long comments" on the file named "/myFileToComment.txt" it should return "201" + When Logging in using web as "user0" + And searching for "searching" in app "files" + Then the list of search results has "1" results + And search result "0" contains + | type | comment | + | comment | …ed message returned when searching for long comments | + | authorId | user0 | + | authorName | user0 | + | path | myFileToComment.txt | + | fileName | myFileToComment.txt | + | name | A very verbose message that is meant to be used to test the ellipsized message returned when searching for long comments | + + Scenario: Search comment with a large message ellipsized on both ends + Given user "user0" exists + And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt" + And "user0" posts a comment with content "A very verbose message that is meant to be used to test the ellipsized message returned when searching for long comments" on the file named "/myFileToComment.txt" it should return "201" + When Logging in using web as "user0" + And searching for "ellipsized" in app "files" + Then the list of search results has "1" results + And search result "0" contains + | type | comment | + | comment | …t to be used to test the ellipsized message returned when se… | + | authorId | user0 | + | authorName | user0 | + | path | myFileToComment.txt | + | fileName | myFileToComment.txt | + | name | A very verbose message that is meant to be used to test the ellipsized message returned when searching for long comments | + + Scenario: Search comment on a file in a subfolder + Given user "user0" exists + And user "user0" created a folder "/subfolder" + And User "user0" uploads file "data/textfile.txt" to "/subfolder/myFileToComment.txt" + And "user0" posts a comment with content "My first comment" on the file named "/subfolder/myFileToComment.txt" it should return "201" + When Logging in using web as "user0" + And searching for "first" in app "files" + Then the list of search results has "1" results + And search result "0" contains + | type | comment | + | comment | My first comment | + | authorId | user0 | + | authorName | user0 | + | path | subfolder/myFileToComment.txt | + | fileName | myFileToComment.txt | + | name | My first comment | + + Scenario: Search several comments + Given user "user0" exists + And user "user1" exists + And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt" + And User "user0" uploads file "data/textfile.txt" to "/mySharedFileToComment.txt" + And As "user0" sending "POST" to "/apps/files_sharing/api/v1/shares" with + | path | mySharedFileToComment.txt | + | shareWith | user1 | + | shareType | 0 | + And User "user1" uploads file "data/textfile.txt" to "/sharedFileToComment.txt" + And As "user1" sending "POST" to "/apps/files_sharing/api/v1/shares" with + | path | sharedFileToComment.txt | + | shareWith | user0 | + | shareType | 0 | + And "user0" posts a comment with content "My first comment to be found" on the file named "/myFileToComment.txt" it should return "201" + And "user0" posts a comment with content "The second comment should not be found" on the file named "/myFileToComment.txt" it should return "201" + And "user0" posts a comment with content "My first comment to be found" on the file named "/mySharedFileToComment.txt" it should return "201" + And "user1" posts a comment with content "Other's first comment that should not be found" on the file named "/mySharedFileToComment.txt" it should return "201" + And "user1" posts a comment with content "Other's second comment to be found" on the file named "/mySharedFileToComment.txt" it should return "201" + And "user0" posts a comment with content "My first comment that should not be found" on the file named "/sharedFileToComment.txt" it should return "201" + And "user1" posts a comment with content "Other's first comment to be found" on the file named "/sharedFileToComment.txt" it should return "201" + And "user0" posts a comment with content "My second comment to be found that happens to be more verbose than the others and thus should be ellipsized" on the file named "/sharedFileToComment.txt" it should return "201" + And "user0" posts a comment with content "My third comment to be found" on the file named "/myFileToComment.txt" it should return "201" + When Logging in using web as "user0" + And searching for "comment to be found" in app "files" + Then the list of search results has "6" results + And search result "0" contains + | type | comment | + | comment | My third comment to be found | + | authorId | user0 | + | authorName | user0 | + | path | myFileToComment.txt | + | fileName | myFileToComment.txt | + | name | My third comment to be found | + And search result "1" contains + | type | comment | + | comment | My second comment to be found that happens to be more … | + | authorId | user0 | + | authorName | user0 | + | path | sharedFileToComment.txt | + | fileName | sharedFileToComment.txt | + | name | My second comment to be found that happens to be more verbose than the others and thus should be ellipsized | + And search result "2" contains + | type | comment | + | comment | Other's first comment to be found | + | authorId | user1 | + | authorName | user1 | + | path | sharedFileToComment.txt | + | fileName | sharedFileToComment.txt | + | name | Other's first comment to be found | + And search result "3" contains + | type | comment | + | comment | Other's second comment to be found | + | authorId | user1 | + | authorName | user1 | + | path | mySharedFileToComment.txt | + | fileName | mySharedFileToComment.txt | + | name | Other's second comment to be found | + And search result "4" contains + | type | comment | + | comment | My first comment to be found | + | authorId | user0 | + | authorName | user0 | + | path | mySharedFileToComment.txt | + | fileName | mySharedFileToComment.txt | + | name | My first comment to be found | + And search result "5" contains + | type | comment | + | comment | My first comment to be found | + | authorId | user0 | + | authorName | user0 | + | path | myFileToComment.txt | + | fileName | myFileToComment.txt | + | name | My first comment to be found | + + Scenario: Search comment with a query that also matches a file name + Given user "user0" exists + And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt" + And "user0" posts a comment with content "A comment in myFileToComment.txt" on the file named "/myFileToComment.txt" it should return "201" + When Logging in using web as "user0" + And searching for "myFileToComment" in app "files" + Then the list of search results has "2" results + And search result "0" contains + | type | file | + | path | /myFileToComment.txt | + | name | myFileToComment.txt | + And search result "1" contains + | type | comment | + | comment | A comment in myFileToComment.txt | + | authorId | user0 | + | authorName | user0 | + | path | myFileToComment.txt | + | fileName | myFileToComment.txt | + | name | A comment in myFileToComment.txt | |