From 689e3a502d02801f99f8d44676268c499972c909 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 2 Dec 2020 16:03:54 +0100 Subject: Add an integration test for the phone search API Signed-off-by: Joas Schilling --- .../features/bootstrap/Provisioning.php | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'build/integration/features/bootstrap') diff --git a/build/integration/features/bootstrap/Provisioning.php b/build/integration/features/bootstrap/Provisioning.php index 56d75c058aa..a856e47ef2b 100644 --- a/build/integration/features/bootstrap/Provisioning.php +++ b/build/integration/features/bootstrap/Provisioning.php @@ -173,6 +173,37 @@ trait Provisioning { } } + /** + * @Then /^search users by phone for region "([^"]*)" with$/ + * + * @param string $user + * @param \Behat\Gherkin\Node\TableNode|null $settings + */ + public function searchUserByPhone($region, \Behat\Gherkin\Node\TableNode $searchTable) { + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/search/by-phone"; + $client = new Client(); + $options = []; + $options['auth'] = $this->adminUser; + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; + + $search = []; + foreach ($searchTable->getRows() as $row) { + if (!isset($search[$row[0]])) { + $search[$row[0]] = []; + } + $search[$row[0]][] = $row[1]; + } + + $options['form_params'] = [ + 'location' => $region, + 'search' => $search, + ]; + + $this->response = $client->post($fullUrl, $options); + } + public function createUser($user) { $previous_user = $this->currentUser; $this->currentUser = "admin"; @@ -560,6 +591,19 @@ trait Provisioning { } } + /** + * @Then /^phone matches returned are$/ + * @param \Behat\Gherkin\Node\TableNode|null $usersList + */ + public function thePhoneUsersShouldBe($usersList) { + if ($usersList instanceof \Behat\Gherkin\Node\TableNode) { + $users = $usersList->getRowsHash(); + $listCheckedElements = simplexml_load_string($this->response->getBody())->data; + $respondedArray = json_decode(json_encode($listCheckedElements), true); + Assert::assertEquals($users, $respondedArray); + } + } + /** * @Then /^detailed users returned are$/ * @param \Behat\Gherkin\Node\TableNode|null $usersList -- cgit v1.2.3