diff options
Diffstat (limited to 'build/integration/features/bootstrap/FeatureContext.php')
-rw-r--r-- | build/integration/features/bootstrap/FeatureContext.php | 128 |
1 files changed, 124 insertions, 4 deletions
diff --git a/build/integration/features/bootstrap/FeatureContext.php b/build/integration/features/bootstrap/FeatureContext.php index caff517a16d..e05015301f3 100644 --- a/build/integration/features/bootstrap/FeatureContext.php +++ b/build/integration/features/bootstrap/FeatureContext.php @@ -34,6 +34,7 @@ class FeatureContext extends BehatContext { // Initialize your context here $this->baseUrl = $parameters['baseUrl']; $this->adminUser = $parameters['admin']; + $this->regularUser = $parameters['regular_user_password']; // in case of ci deployment we take the server url from the environment $testServerUrl = getenv('TEST_SERVER_URL'); @@ -76,14 +77,32 @@ class FeatureContext extends BehatContext { } /** + * Parses the xml answer to get the array of subadmins returned. + */ + public function getArrayOfSubadminsResponded($resp) { + $listCheckedElements = $resp->xml()->data[0]->element; + $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1); + return $extractedElementsArray; + } + + /** + * This function is needed to use a vertical fashion in the gherkin tables. + */ + public function simplifyArray($arrayOfArrays){ + $a = array_map(function($subArray) { return $subArray[0]; }, $arrayOfArrays); + return $a; + } + + /** * @Then /^users returned are$/ * @param \Behat\Gherkin\Node\TableNode|null $formData */ public function theUsersShouldBe($usersList) { if ($usersList instanceof \Behat\Gherkin\Node\TableNode) { - $users = $usersList->getRows()[0]; + $users = $usersList->getRows(); + $usersSimplified = $this->simplifyArray($users); $respondedArray = $this->getArrayOfUsersResponded($this->response); - PHPUnit_Framework_Assert::assertEquals(asort($users), asort($respondedArray)); + PHPUnit_Framework_Assert::assertEquals($usersSimplified, $respondedArray, "", 0.0, 10, true); } } @@ -94,14 +113,37 @@ class FeatureContext extends BehatContext { */ public function theGroupsShouldBe($groupsList) { if ($groupsList instanceof \Behat\Gherkin\Node\TableNode) { - $groups = $groupsList->getRows()[0]; + $groups = $groupsList->getRows(); + $groupsSimplified = $this->simplifyArray($groups); $respondedArray = $this->getArrayOfGroupsResponded($this->response); - PHPUnit_Framework_Assert::assertEquals(asort($groups), asort($respondedArray)); + PHPUnit_Framework_Assert::assertEquals($groupsSimplified, $respondedArray, "", 0.0, 10, true); } } /** + * @Then /^subadmin groups returned are$/ + * @param \Behat\Gherkin\Node\TableNode|null $formData + */ + public function theSubadminGroupsShouldBe($groupsList) { + if ($groupsList instanceof \Behat\Gherkin\Node\TableNode) { + $groups = $groupsList->getRows(); + $groupsSimplified = $this->simplifyArray($groups); + $respondedArray = $this->getArrayOfSubadminsResponded($this->response); + PHPUnit_Framework_Assert::assertEquals($groupsSimplified, $respondedArray, "", 0.0, 10, true); + } + + } + + /** + * @Then /^subadmin users returned are$/ + * @param \Behat\Gherkin\Node\TableNode|null $formData + */ + public function theSubadminUsersShouldBe($groupsList) { + $this->theSubadminGroupsShouldBe($groupsList); + } + + /** * @Then /^the OCS status code should be "([^"]*)"$/ */ public function theOCSStatusCodeShouldBe($statusCode) { @@ -145,6 +187,82 @@ class FeatureContext extends BehatContext { } /** + * @Given /^user "([^"]*)" belongs to group "([^"]*)"$/ + */ + public function userBelongsToGroup($user, $group) { + $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } + + $this->response = $client->get($fullUrl, $options); + $groups = array($group); + $respondedArray = $this->getArrayOfGroupsResponded($this->response); + PHPUnit_Framework_Assert::assertEquals($groups, $respondedArray, "", 0.0, 10, true); + PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + } + + /** + * @Given /^user "([^"]*)" does not belong to group "([^"]*)"$/ + */ + public function userDoesNotBelongToGroup($user, $group) { + $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } + + $this->response = $client->get($fullUrl, $options); + $groups = array($group); + $respondedArray = $this->getArrayOfGroupsResponded($this->response); + PHPUnit_Framework_Assert::assertNotEquals($groups, $respondedArray, "", 0.0, 10, true); + PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + } + + + /** + * @Given /^user "([^"]*)" is subadmin of group "([^"]*)"$/ + */ + public function userIsSubadminOfGroup($user, $group) { + $fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group/subadmins"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } + + $this->response = $client->get($fullUrl, $options); + $subadmins = array($user); + $respondedArray = $this->getArrayOfSubadminsResponded($this->response); + sort($respondedArray); + PHPUnit_Framework_Assert::assertContains($user, $respondedArray); + PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + } + + /** + * @Given /^user "([^"]*)" is not a subadmin of group "([^"]*)"$/ + */ + public function userIsNotSubadminOfGroup($user, $group) { + $fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group/subadmins"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } + + $this->response = $client->get($fullUrl, $options); + $subadmins = array($user); + $respondedArray = $this->getArrayOfSubadminsResponded($this->response); + sort($respondedArray); + PHPUnit_Framework_Assert::assertNotContains($user, $respondedArray); + PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + } + + + /** * @Given /^user "([^"]*)" does not exist$/ */ public function userDoesNotExist($user) { @@ -233,6 +351,8 @@ class FeatureContext extends BehatContext { $options = []; if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; + } else { + $options['auth'] = $this->regularUser; } if ($body instanceof \Behat\Gherkin\Node\TableNode) { $fd = $body->getRowsHash(); |