From c2fdc705ce8a425e368e4253da83e0c90821fafb Mon Sep 17 00:00:00 2001 From: paurakhsharma Date: Thu, 11 Oct 2018 10:30:26 +0545 Subject: [PATCH] Add tests for getUsers --- .../features/bootstrap/OccContext.php | 24 +++++++++++++++++-- .../features/cliProvisioning/getUsers.feature | 15 ++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/acceptance/features/bootstrap/OccContext.php b/tests/acceptance/features/bootstrap/OccContext.php index f1ffab44a5cf..8485b93d79ba 100644 --- a/tests/acceptance/features/bootstrap/OccContext.php +++ b/tests/acceptance/features/bootstrap/OccContext.php @@ -201,6 +201,17 @@ public function theAdministratorSendsAUserDeletionRequestForUserUsingTheOccComma ); } + /** + * @When the administrator retrieves all the users using the occ command + * + * @return void + */ + public function theAdministratorRetrievesAllTheUsersUsingTheOccCommand() { + $this->featureContext->invokingTheCommand( + "user:list --output=json" + ); + } + /** * @When the administrator retrieves the information of user :username using the occ command * @@ -425,9 +436,18 @@ public function theAppsReturnedByTheOccCommandShouldInclude(TableNode $appListTa public function theUsersReturnedByTheOccCommandShouldBe(TableNode $useridTable) { $lastOutput = $this->featureContext->getStdOutOfOccCommand(); $lastOutputUsers = \json_decode($lastOutput, true); + $result = []; + // check if an array is a multi-dimensional array with inner array key 'displayName' + if (\array_column($lastOutputUsers, 'displayName')) { + foreach ($lastOutputUsers as $key => $value) { + $result[$key] = $value['displayName']; + } + } else { + $result = $lastOutputUsers; + } foreach ($useridTable as $row) { - PHPUnit_Framework_Assert::assertArrayHasKey($row['uid'], $lastOutputUsers); - PHPUnit_Framework_Assert::assertContains($row['display name'], $lastOutputUsers); + PHPUnit_Framework_Assert::assertArrayHasKey($row['uid'], $result); + PHPUnit_Framework_Assert::assertContains($row['display name'], $result); } } diff --git a/tests/acceptance/features/cliProvisioning/getUsers.feature b/tests/acceptance/features/cliProvisioning/getUsers.feature index e69de29bb2d1..529a781a302d 100644 --- a/tests/acceptance/features/cliProvisioning/getUsers.feature +++ b/tests/acceptance/features/cliProvisioning/getUsers.feature @@ -0,0 +1,15 @@ +@cli @skipOnLDAP +Feature: get users + As an admin + I want to be able to list the users that exist + So that I can see who has access to ownCloud + + Scenario: admin gets all users + Given this user has been created using the occ command: + | username | displayname | email | + | brand-new-user | Just A User | justauser@example.com | + When the administrator retrieves all the users using the occ command + Then the command should have been successful + And the users returned by the occ command should be + | uid | display name | + | brand-new-user | Just A User | \ No newline at end of file