1010
1111class UserTest extends RESTFunctionalTestCase
1212{
13+ private const HEADER_LOCATION = 'Location ' ;
14+
1315 /**
1416 * Covers GET /user/groups/root.
1517 */
@@ -59,9 +61,9 @@ public function testCreateUserGroup()
5961 $ response = $ this ->sendHttpRequest ($ request );
6062
6163 self ::assertHttpResponseCodeEquals ($ response , 201 );
62- self ::assertHttpResponseHasHeader ($ response , ' Location ' );
64+ self ::assertHttpResponseHasHeader ($ response , self :: HEADER_LOCATION );
6365
64- $ href = $ response ->getHeader (' Location ' )[0 ];
66+ $ href = $ response ->getHeader (self :: HEADER_LOCATION )[0 ];
6567 $ this ->addCreatedElement ($ href );
6668
6769 return $ href ;
@@ -153,9 +155,9 @@ public function testCreateUser($userGroupHref)
153155 $ response = $ this ->sendHttpRequest ($ request );
154156
155157 self ::assertHttpResponseCodeEquals ($ response , 201 );
156- self ::assertHttpResponseHasHeader ($ response , ' Location ' );
158+ self ::assertHttpResponseHasHeader ($ response , self :: HEADER_LOCATION );
157159
158- $ href = $ response ->getHeader (' Location ' )[0 ];
160+ $ href = $ response ->getHeader (self :: HEADER_LOCATION )[0 ];
159161 $ this ->addCreatedElement ($ href );
160162
161163 return $ href ;
@@ -174,6 +176,28 @@ public function testLoadUser($userHref)
174176 self ::assertHttpResponseCodeEquals ($ response , 200 );
175177 }
176178
179+ public function testRedirectToCurrentUser (): void
180+ {
181+ $ request = $ this ->createHttpRequest ('GET ' , '/api/ibexa/v2/user/current ' );
182+
183+ $ response = $ this ->sendHttpRequest ($ request );
184+
185+ self ::assertHttpResponseCodeEquals ($ response , 307 );
186+ self ::assertHttpResponseHasHeader ($ response , self ::HEADER_LOCATION , '/api/ibexa/v2/user/users/14 ' );
187+ }
188+
189+ public function testRedirectToCurrentUserWhenNotLoggedIn (): void
190+ {
191+ $ request = $ this
192+ ->createHttpRequest ('GET ' , '/api/ibexa/v2/user/current ' )
193+ ->withoutHeader ('Cookie ' );
194+
195+ $ response = $ this ->sendHttpRequest ($ request );
196+
197+ self ::assertHttpResponseCodeEquals ($ response , 401 );
198+ self ::assertFalse ($ response ->hasHeader (self ::HEADER_LOCATION ));
199+ }
200+
177201 /**
178202 * @depends testCreateUser
179203 * Covers PATCH /user/users/{userId}
@@ -394,9 +418,9 @@ public function testCreateSession()
394418 $ response = $ this ->sendHttpRequest ($ request );
395419
396420 self ::assertHttpResponseCodeEquals ($ response , 201 );
397- self ::assertHttpResponseHasHeader ($ response , ' Location ' );
421+ self ::assertHttpResponseHasHeader ($ response , self :: HEADER_LOCATION );
398422
399- $ href = $ response ->getHeader (' Location ' )[0 ];
423+ $ href = $ response ->getHeader (self :: HEADER_LOCATION )[0 ];
400424 $ this ->addCreatedElement ($ href );
401425
402426 return $ href ;
0 commit comments