]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add integration tests for searching users in contacts menu
authorDaniel Calviño Sánchez <danxuliu@gmail.com>
Sun, 31 Jan 2021 22:10:55 +0000 (23:10 +0100)
committerDaniel Calviño Sánchez <danxuliu@gmail.com>
Fri, 2 Jul 2021 12:27:23 +0000 (14:27 +0200)
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
.drone.yml
build/integration/features/bootstrap/ContactsMenu.php [new file with mode: 0644]
build/integration/features/bootstrap/FeatureContext.php
build/integration/features/contacts-menu.feature [new file with mode: 0644]

index fee6ce6f620ac84a8cd6218bb06f0e27829df050..92d441281784b141b8b36afd95ac37621b926982 100644 (file)
@@ -1164,6 +1164,31 @@ trigger:
     - pull_request
     - push
 
+---
+kind: pipeline
+name: integration-contacts-menu
+
+steps:
+- name: submodules
+  image: docker:git
+  commands:
+    - git submodule update --init
+- name: integration-contacts-menu
+  image: nextcloudci/integration-php7.3:integration-php7.3-2
+  commands:
+    - bash tests/drone-run-integration-tests.sh || exit 0
+    - ./occ maintenance:install --admin-pass=admin --data-dir=/dev/shm/nc_int
+    - cd build/integration
+    - ./run.sh features/contacts-menu.feature
+
+trigger:
+  branch:
+    - master
+    - stable*
+  event:
+    - pull_request
+    - push
+
 ---
 kind: pipeline
 name: integration-favorites
diff --git a/build/integration/features/bootstrap/ContactsMenu.php b/build/integration/features/bootstrap/ContactsMenu.php
new file mode 100644 (file)
index 0000000..30e1dad
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+/**
+ * @copyright Copyright (c) 2021 Daniel Calviño Sánchez <danxuliu@gmail.com>
+ *
+ * @author 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 PHPUnit\Framework\Assert;
+
+trait ContactsMenu {
+
+       // BasicStructure trait is expected to be used in the class that uses this
+       // trait.
+
+       /**
+        * @When /^searching for contacts matching with "([^"]*)"$/
+        *
+        * @param string $filter
+        */
+       public function searchingForContactsMatchingWith(string $filter) {
+               $url = '/index.php/contactsmenu/contacts';
+
+               $parameters[] = 'filter=' . $filter;
+
+               $url .= '?' . implode('&', $parameters);
+
+               $this->sendingAToWithRequesttoken('POST', $url);
+       }
+
+       /**
+        * @Then /^the list of searched contacts has "(\d+)" contacts$/
+        */
+       public function theListOfSearchedContactsHasContacts(int $count) {
+               $this->theHTTPStatusCodeShouldBe(200);
+
+               $searchedContacts = json_decode($this->response->getBody(), $asAssociativeArray = true)['contacts'];
+
+               Assert::assertEquals($count, count($searchedContacts));
+       }
+
+       /**
+        * @Then /^searched contact "(\d+)" is named "([^"]*)"$/
+        *
+        * @param int $index
+        * @param string $expectedName
+        */
+       public function searchedContactXIsNamed(int $index, string $expectedName) {
+               $searchedContacts = json_decode($this->response->getBody(), $asAssociativeArray = true)['contacts'];
+               $searchedContact = $searchedContacts[$index];
+
+               Assert::assertEquals($expectedName, $searchedContact['fullName']);
+       }
+}
index e9c486daa4dcf8d7db94e0c53bb21e8d108dcbb9..9437b50cd1c7e14898ab0997faa4022f8b28a24b 100644 (file)
@@ -33,6 +33,7 @@ require __DIR__ . '/../../vendor/autoload.php';
  * Features context.
  */
 class FeatureContext implements Context, SnippetAcceptingContext {
+       use ContactsMenu;
        use Search;
        use WebDav;
        use Trashbin;
diff --git a/build/integration/features/contacts-menu.feature b/build/integration/features/contacts-menu.feature
new file mode 100644 (file)
index 0000000..845d4d3
--- /dev/null
@@ -0,0 +1,188 @@
+Feature: contacts-menu
+
+  Scenario: users can be searched by display name
+    Given user "user0" exists
+    And user "user1" exists
+    And As an "admin"
+    And sending "PUT" to "/cloud/users/user1" with
+      | key | displayname |
+      | value | Test name |
+    When Logging in using web as "user0"
+    And searching for contacts matching with "test"
+    Then the list of searched contacts has "1" contacts
+    And searched contact "0" is named "Test name"
+
+  Scenario: users can be searched by email
+    Given user "user0" exists
+    And user "user1" exists
+    And As an "admin"
+    And sending "PUT" to "/cloud/users/user1" with
+      | key | email |
+      | value | test@example.com |
+    When Logging in using web as "user0"
+    And searching for contacts matching with "test"
+    Then the list of searched contacts has "1" contacts
+    And searched contact "0" is named "user1"
+
+  Scenario: users can not be searched by id
+    Given user "user0" exists
+    And user "user1" exists
+    And As an "admin"
+    And sending "PUT" to "/cloud/users/user1" with
+      | key | displayname |
+      | value | Test name |
+    When Logging in using web as "user0"
+    And searching for contacts matching with "user"
+    Then the list of searched contacts has "0" contacts
+
+  Scenario: search several users
+    Given user "user0" exists
+    And user "user1" exists
+    And user "user2" exists
+    And user "user3" exists
+    And user "user4" exists
+    And user "user5" exists
+    And As an "admin"
+    And sending "PUT" to "/cloud/users/user1" with
+      | key | displayname |
+      | value | Test name |
+    And sending "PUT" to "/cloud/users/user2" with
+      | key | email |
+      | value | test@example.com |
+    And sending "PUT" to "/cloud/users/user3" with
+      | key | displayname |
+      | value | Unmatched name |
+    And sending "PUT" to "/cloud/users/user4" with
+      | key | email |
+      | value | unmatched@example.com |
+    And sending "PUT" to "/cloud/users/user5" with
+      | key | displayname |
+      | value | Another test name |
+    And sending "PUT" to "/cloud/users/user5" with
+      | key | email |
+      | value | another_test@example.com |
+    When Logging in using web as "user0"
+    And searching for contacts matching with "test"
+    Then the list of searched contacts has "3" contacts
+    # Results are sorted alphabetically
+    And searched contact "0" is named "Another test name"
+    And searched contact "1" is named "Test name"
+    And searched contact "2" is named "user2"
+
+
+
+  Scenario: users can not be found by display name if visibility is private
+    Given user "user0" exists
+    And user "user1" exists
+    And user "user2" exists
+    And Logging in using web as "user1"
+    And Sending a "PUT" to "/settings/users/user1/settings" with requesttoken
+      | displayname | Test name |
+      | displaynameScope | private |
+    And Logging in using web as "user2"
+    And Sending a "PUT" to "/settings/users/user2/settings" with requesttoken
+      | displayname | Another test name |
+      | displaynameScope | contacts |
+    When Logging in using web as "user0"
+    And searching for contacts matching with "test"
+    Then the list of searched contacts has "1" contacts
+    And searched contact "0" is named "Another test name"
+
+  Scenario: users can not be found by email if visibility is private
+    Given user "user0" exists
+    And user "user1" exists
+    And user "user2" exists
+    And Logging in using web as "user1"
+    And Sending a "PUT" to "/settings/users/user1/settings" with requesttoken
+      | email | test@example.com |
+      | emailScope | private |
+    And Logging in using web as "user2"
+    And Sending a "PUT" to "/settings/users/user2/settings" with requesttoken
+      | email | another_test@example.com |
+      | emailScope | contacts |
+    When Logging in using web as "user0"
+    And searching for contacts matching with "test"
+    Then the list of searched contacts has "1" contacts
+    And searched contact "0" is named "user2"
+
+  Scenario: users can be found by other properties if the visibility of one is private
+    Given user "user0" exists
+    And user "user1" exists
+    And user "user2" exists
+    And Logging in using web as "user1"
+    And Sending a "PUT" to "/settings/users/user1/settings" with requesttoken
+      | displayname | Test name |
+      | displaynameScope | contacts |
+      | email | test@example.com |
+      | emailScope | private |
+    And Logging in using web as "user2"
+    And Sending a "PUT" to "/settings/users/user2/settings" with requesttoken
+      | displayname | Another test name |
+      | displaynameScope | private |
+      | email | another_test@example.com |
+      | emailScope | contacts |
+    When Logging in using web as "user0"
+    And searching for contacts matching with "test"
+    Then the list of searched contacts has "2" contacts
+    And searched contact "0" is named ""
+    And searched contact "1" is named "Test name"
+
+
+
+  Scenario: users can be searched by display name if visibility is increased again
+    Given user "user0" exists
+    And user "user1" exists
+    And Logging in using web as "user1"
+    And Sending a "PUT" to "/settings/users/user1/settings" with requesttoken
+      | displayname | Test name |
+      | displaynameScope | private |
+    And Sending a "PUT" to "/settings/users/user1/settings" with requesttoken
+      | displaynameScope | contacts |
+    When Logging in using web as "user0"
+    And searching for contacts matching with "test"
+    Then the list of searched contacts has "1" contacts
+    And searched contact "0" is named "Test name"
+
+  Scenario: users can be searched by email if visibility is increased again
+    Given user "user0" exists
+    And user "user1" exists
+    And Logging in using web as "user1"
+    And Sending a "PUT" to "/settings/users/user1/settings" with requesttoken
+      | email | test@example.com |
+      | emailScope | private |
+    And Sending a "PUT" to "/settings/users/user1/settings" with requesttoken
+      | emailScope | contacts |
+    When Logging in using web as "user0"
+    And searching for contacts matching with "test"
+    Then the list of searched contacts has "1" contacts
+    And searched contact "0" is named "user1"
+
+
+
+  Scenario: users can not be searched by display name if visibility is private even if updated with provisioning
+    Given user "user0" exists
+    And user "user1" exists
+    And Logging in using web as "user1"
+    And Sending a "PUT" to "/settings/users/user1/settings" with requesttoken
+      | displaynameScope | private |
+    And As an "admin"
+    And sending "PUT" to "/cloud/users/user1" with
+      | key | displayname |
+      | value | Test name |
+    When Logging in using web as "user0"
+    And searching for contacts matching with "test"
+    Then the list of searched contacts has "0" contacts
+
+  Scenario: users can not be searched by email if visibility is private even if updated with provisioning
+    Given user "user0" exists
+    And user "user1" exists
+    And Logging in using web as "user1"
+    And Sending a "PUT" to "/settings/users/user1/settings" with requesttoken
+      | emailScope | private |
+    And As an "admin"
+    And sending "PUT" to "/cloud/users/user1" with
+      | key | email |
+      | value | test@example.com |
+    When Logging in using web as "user0"
+    And searching for contacts matching with "test"
+    Then the list of searched contacts has "0" contacts