44 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
55 * SPDX-License-Identifier: AGPL-3.0-or-later
66 */
7+
8+ use Behat \Gherkin \Node \TableNode ;
79use GuzzleHttp \Client ;
810use GuzzleHttp \Message \ResponseInterface ;
911use PHPUnit \Framework \Assert ;
@@ -124,7 +126,7 @@ public function creatingTheUser($user, $displayname = '') {
124126 * @Then /^user "([^"]*)" has$/
125127 *
126128 * @param string $user
127- * @param \Behat\Gherkin\Node\ TableNode|null $settings
129+ * @param TableNode|null $settings
128130 */
129131 public function userHasSetting ($ user , $ settings ) {
130132 $ fullUrl = $ this ->baseUrl . "v {$ this ->apiVersion }.php/cloud/users/ $ user " ;
@@ -145,12 +147,43 @@ public function userHasSetting($user, $settings) {
145147 if (isset ($ value ['element ' ]) && in_array ($ setting [0 ], ['additional_mail ' , 'additional_mailScope ' ], true )) {
146148 $ expectedValues = explode ('; ' , $ setting [1 ]);
147149 foreach ($ expectedValues as $ expected ) {
148- Assert::assertTrue (in_array ($ expected , $ value ['element ' ], true ));
150+ Assert::assertTrue (in_array ($ expected , $ value ['element ' ], true ), ' Data wrong for field: ' . $ setting [ 0 ] );
149151 }
150152 } elseif (isset ($ value [0 ])) {
151- Assert::assertEqualsCanonicalizing ($ setting [1 ], $ value [0 ]);
153+ Assert::assertEqualsCanonicalizing ($ setting [1 ], $ value [0 ], ' Data wrong for field: ' . $ setting [ 0 ] );
152154 } else {
153- Assert::assertEquals ('' , $ setting [1 ]);
155+ Assert::assertEquals ('' , $ setting [1 ], 'Data wrong for field: ' . $ setting [0 ]);
156+ }
157+ }
158+ }
159+
160+ /**
161+ * @Then /^user "([^"]*)" has the following profile data$/
162+ */
163+ public function userHasProfileData (string $ user , ?TableNode $ settings ): void {
164+ $ fullUrl = $ this ->baseUrl . "v {$ this ->apiVersion }.php/profile/ $ user " ;
165+ $ client = new Client ();
166+ $ options = [];
167+ if ($ this ->currentUser === 'admin ' ) {
168+ $ options ['auth ' ] = $ this ->adminUser ;
169+ } else {
170+ $ options ['auth ' ] = [$ this ->currentUser , $ this ->regularUser ];
171+ }
172+ $ options ['headers ' ] = [
173+ 'OCS-APIREQUEST ' => 'true ' ,
174+ 'Accept ' => 'application/json ' ,
175+ ];
176+
177+ $ response = $ client ->get ($ fullUrl , $ options );
178+ $ body = $ response ->getBody ()->getContents ();
179+ $ data = json_decode ($ body , true );
180+ $ data = $ data ['ocs ' ]['data ' ];
181+ foreach ($ settings ->getRows () as $ setting ) {
182+ Assert::assertArrayHasKey ($ setting [0 ], $ data , 'Profile data field missing: ' . $ setting [0 ]);
183+ if ($ setting [1 ] === 'NULL ' ) {
184+ Assert::assertNull ($ data [$ setting [0 ]], 'Profile data wrong for field: ' . $ setting [0 ]);
185+ } else {
186+ Assert::assertEquals ($ setting [1 ], $ data [$ setting [0 ]], 'Profile data wrong for field: ' . $ setting [0 ]);
154187 }
155188 }
156189 }
@@ -159,7 +192,7 @@ public function userHasSetting($user, $settings) {
159192 * @Then /^group "([^"]*)" has$/
160193 *
161194 * @param string $user
162- * @param \Behat\Gherkin\Node\ TableNode|null $settings
195+ * @param TableNode|null $settings
163196 */
164197 public function groupHasSetting ($ group , $ settings ) {
165198 $ fullUrl = $ this ->baseUrl . "v {$ this ->apiVersion }.php/cloud/groups/details?search= $ group " ;
@@ -191,7 +224,7 @@ public function groupHasSetting($group, $settings) {
191224 * @Then /^user "([^"]*)" has editable fields$/
192225 *
193226 * @param string $user
194- * @param \Behat\Gherkin\Node\ TableNode|null $fields
227+ * @param TableNode|null $fields
195228 */
196229 public function userHasEditableFields ($ user , $ fields ) {
197230 $ fullUrl = $ this ->baseUrl . "v {$ this ->apiVersion }.php/cloud/user/fields " ;
@@ -221,9 +254,9 @@ public function userHasEditableFields($user, $fields) {
221254 * @Then /^search users by phone for region "([^"]*)" with$/
222255 *
223256 * @param string $user
224- * @param \Behat\Gherkin\Node\ TableNode|null $settings
257+ * @param TableNode|null $settings
225258 */
226- public function searchUserByPhone ($ region , \ Behat \ Gherkin \ Node \ TableNode $ searchTable ) {
259+ public function searchUserByPhone ($ region , TableNode $ searchTable ) {
227260 $ fullUrl = $ this ->baseUrl . "v {$ this ->apiVersion }.php/cloud/users/search/by-phone " ;
228261 $ client = new Client ();
229262 $ options = [];
@@ -624,10 +657,10 @@ public function userIsNotSubadminOfGroup($user, $group) {
624657
625658 /**
626659 * @Then /^users returned are$/
627- * @param \Behat\Gherkin\Node\ TableNode|null $usersList
660+ * @param TableNode|null $usersList
628661 */
629662 public function theUsersShouldBe ($ usersList ) {
630- if ($ usersList instanceof \ Behat \ Gherkin \ Node \ TableNode) {
663+ if ($ usersList instanceof TableNode) {
631664 $ users = $ usersList ->getRows ();
632665 $ usersSimplified = $ this ->simplifyArray ($ users );
633666 $ respondedArray = $ this ->getArrayOfUsersResponded ($ this ->response );
@@ -637,10 +670,10 @@ public function theUsersShouldBe($usersList) {
637670
638671 /**
639672 * @Then /^phone matches returned are$/
640- * @param \Behat\Gherkin\Node\ TableNode|null $usersList
673+ * @param TableNode|null $usersList
641674 */
642675 public function thePhoneUsersShouldBe ($ usersList ) {
643- if ($ usersList instanceof \ Behat \ Gherkin \ Node \ TableNode) {
676+ if ($ usersList instanceof TableNode) {
644677 $ users = $ usersList ->getRowsHash ();
645678 $ listCheckedElements = simplexml_load_string ($ this ->response ->getBody ())->data ;
646679 $ respondedArray = json_decode (json_encode ($ listCheckedElements ), true );
@@ -650,10 +683,10 @@ public function thePhoneUsersShouldBe($usersList) {
650683
651684 /**
652685 * @Then /^detailed users returned are$/
653- * @param \Behat\Gherkin\Node\ TableNode|null $usersList
686+ * @param TableNode|null $usersList
654687 */
655688 public function theDetailedUsersShouldBe ($ usersList ) {
656- if ($ usersList instanceof \ Behat \ Gherkin \ Node \ TableNode) {
689+ if ($ usersList instanceof TableNode) {
657690 $ users = $ usersList ->getRows ();
658691 $ usersSimplified = $ this ->simplifyArray ($ users );
659692 $ respondedArray = $ this ->getArrayOfDetailedUsersResponded ($ this ->response );
@@ -664,10 +697,10 @@ public function theDetailedUsersShouldBe($usersList) {
664697
665698 /**
666699 * @Then /^groups returned are$/
667- * @param \Behat\Gherkin\Node\ TableNode|null $groupsList
700+ * @param TableNode|null $groupsList
668701 */
669702 public function theGroupsShouldBe ($ groupsList ) {
670- if ($ groupsList instanceof \ Behat \ Gherkin \ Node \ TableNode) {
703+ if ($ groupsList instanceof TableNode) {
671704 $ groups = $ groupsList ->getRows ();
672705 $ groupsSimplified = $ this ->simplifyArray ($ groups );
673706 $ respondedArray = $ this ->getArrayOfGroupsResponded ($ this ->response );
@@ -677,10 +710,10 @@ public function theGroupsShouldBe($groupsList) {
677710
678711 /**
679712 * @Then /^subadmin groups returned are$/
680- * @param \Behat\Gherkin\Node\ TableNode|null $groupsList
713+ * @param TableNode|null $groupsList
681714 */
682715 public function theSubadminGroupsShouldBe ($ groupsList ) {
683- if ($ groupsList instanceof \ Behat \ Gherkin \ Node \ TableNode) {
716+ if ($ groupsList instanceof TableNode) {
684717 $ groups = $ groupsList ->getRows ();
685718 $ groupsSimplified = $ this ->simplifyArray ($ groups );
686719 $ respondedArray = $ this ->getArrayOfSubadminsResponded ($ this ->response );
@@ -690,10 +723,10 @@ public function theSubadminGroupsShouldBe($groupsList) {
690723
691724 /**
692725 * @Then /^apps returned are$/
693- * @param \Behat\Gherkin\Node\ TableNode|null $appList
726+ * @param TableNode|null $appList
694727 */
695728 public function theAppsShouldBe ($ appList ) {
696- if ($ appList instanceof \ Behat \ Gherkin \ Node \ TableNode) {
729+ if ($ appList instanceof TableNode) {
697730 $ apps = $ appList ->getRows ();
698731 $ appsSimplified = $ this ->simplifyArray ($ apps );
699732 $ respondedArray = $ this ->getArrayOfAppsResponded ($ this ->response );
@@ -703,7 +736,7 @@ public function theAppsShouldBe($appList) {
703736
704737 /**
705738 * @Then /^subadmin users returned are$/
706- * @param \Behat\Gherkin\Node\ TableNode|null $groupsList
739+ * @param TableNode|null $groupsList
707740 */
708741 public function theSubadminUsersShouldBe ($ groupsList ) {
709742 $ this ->theSubadminGroupsShouldBe ($ groupsList );
@@ -882,7 +915,7 @@ public function userIsEnabled($user) {
882915 * @param string $quota
883916 */
884917 public function userHasAQuotaOf ($ user , $ quota ) {
885- $ body = new \ Behat \ Gherkin \ Node \ TableNode ([
918+ $ body = new TableNode ([
886919 0 => ['key ' , 'quota ' ],
887920 1 => ['value ' , $ quota ],
888921 ]);
@@ -950,7 +983,7 @@ public function cleanupGroups() {
950983 /**
951984 * @Then /^user "([^"]*)" has not$/
952985 */
953- public function userHasNotSetting ($ user , \ Behat \ Gherkin \ Node \ TableNode $ settings ) {
986+ public function userHasNotSetting ($ user , TableNode $ settings ) {
954987 $ fullUrl = $ this ->baseUrl . "v {$ this ->apiVersion }.php/cloud/users/ $ user " ;
955988 $ client = new Client ();
956989 $ options = [];
0 commit comments