@@ -406,6 +406,77 @@ public function shouldGetSpecificUserEmail()
406
406
$ this ->assertEquals ($ expectedArray , $ api ->email (1 ));
407
407
}
408
408
409
+ /**
410
+ * @test
411
+ */
412
+ public function shouldGetCurrentUserImpersonationTokens ()
413
+ {
414
+ $ expectedArray = array (
415
+ array ('id ' => 1 , 'name ' => 'A Name ' , 'revoked ' => false ),
416
+ array ('id ' => 2 , 'name ' => 'A Name ' , 'revoked ' => false ),
417
+ );
418
+
419
+ $ api = $ this ->getApiMock ();
420
+ $ api ->expects ($ this ->once ())
421
+ ->method ('get ' )
422
+ ->with ('users/1/impersonation_tokens ' )
423
+ ->will ($ this ->returnValue ($ expectedArray ))
424
+ ;
425
+
426
+ $ this ->assertEquals ($ expectedArray , $ api ->userImpersonationTokens (1 ));
427
+ }
428
+
429
+ /**
430
+ * @test
431
+ */
432
+ public function shouldGetUserImpersonationToken ()
433
+ {
434
+ $ expectedArray = array ('id ' => 2 , 'name ' => 'name ' );
435
+
436
+ $ api = $ this ->getApiMock ();
437
+ $ api ->expects ($ this ->once ())
438
+ ->method ('get ' )
439
+ ->with ('users/1/impersonation_tokens/1 ' )
440
+ ->will ($ this ->returnValue ($ expectedArray ))
441
+ ;
442
+
443
+ $ this ->assertEquals ($ expectedArray , $ api ->userImpersonationToken (1 , 1 ));
444
+ }
445
+
446
+ /**
447
+ * @test
448
+ */
449
+ public function shouldCreateImpersonationTokenForUser ()
450
+ {
451
+ $ expectedArray = array ('id ' => 1 , 'name ' => 'name ' );
452
+
453
+ $ api = $ this ->getApiMock ();
454
+ $ api ->expects ($ this ->once ())
455
+ ->method ('post ' )
456
+ ->with ('users/1/impersonation_tokens ' , array ('name ' => 'name ' , 'scopes ' => ['api ' ] ,'expires_at ' => null ))
457
+ ->will ($ this ->returnValue ($ expectedArray ))
458
+ ;
459
+
460
+ $ this ->assertEquals ($ expectedArray , $ api ->createImpersonationToken (1 , 'name ' , ['api ' ]));
461
+ }
462
+
463
+ /**
464
+ * @test
465
+ */
466
+ public function shouldDeleteImpersonationTokenForUser ()
467
+ {
468
+ $ expectedBool = true ;
469
+
470
+ $ api = $ this ->getApiMock ();
471
+ $ api ->expects ($ this ->once ())
472
+ ->method ('delete ' )
473
+ ->with ('users/1/impersonation_tokens/1 ' )
474
+ ->will ($ this ->returnValue ($ expectedBool ))
475
+ ;
476
+
477
+ $ this ->assertEquals ($ expectedBool , $ api ->removeImpersonationToken (1 , 1 ));
478
+ }
479
+
409
480
protected function getApiClass ()
410
481
{
411
482
return 'Gitlab\Api\Users ' ;
0 commit comments