Skip to content

Commit 1469769

Browse files
drummm1guelpf
authored andcommitted
Add methods for managing emails for users
1 parent 74fbb0c commit 1469769

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

lib/Gitlab/Api/Users.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,36 @@ public function email($id)
263263
return $this->get('user/emails/'.$this->encodePath($id));
264264
}
265265

266+
/**
267+
* @param int $user_id
268+
* @return mixed
269+
*/
270+
public function userEmails($user_id)
271+
{
272+
return $this->get('users/'.$this->encodePath($user_id).'/emails');
273+
}
274+
275+
/**
276+
* @param int $user_id
277+
* @param string $email
278+
* @return mixed
279+
*/
280+
public function createEmailForUser($user_id, $email)
281+
{
282+
return $this->post('users/'.$this->encodePath($user_id).'/emails', array(
283+
'email' => $email,
284+
));
285+
}
286+
287+
/**
288+
* @param int $user_id
289+
* @param int $email_id
290+
* @return mixed
291+
*/
292+
public function removeUserEmail($user_id, $email_id) {
293+
return $this->delete('users/'.$this->encodePath($user_id).'/emails/'.$this->encodePath($email_id));
294+
}
295+
266296
/**
267297
* @param int $user_id
268298
* @param array $params

test/Gitlab/Tests/Api/UsersTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,60 @@ public function shouldGetSpecificUserEmail()
426426
$this->assertEquals($expectedArray, $api->email(1));
427427
}
428428

429+
/**
430+
* @test
431+
*/
432+
public function shouldGetEmailsForUser()
433+
{
434+
$expectedArray = array(
435+
array('id' => 1, 'email' => '[email protected]'),
436+
array('id' => 2, 'email' => '[email protected]'),
437+
);
438+
439+
$api = $this->getApiMock();
440+
$api->expects($this->once())
441+
->method('get')
442+
->with('users/1/emails')
443+
->will($this->returnValue($expectedArray))
444+
;
445+
446+
$this->assertEquals($expectedArray, $api->userEmails(1));
447+
}
448+
449+
/**
450+
* @test
451+
*/
452+
public function shouldCreateEmailForUser()
453+
{
454+
$expectedArray = array('id' => 3, 'email' => '[email protected]');
455+
456+
$api = $this->getApiMock();
457+
$api->expects($this->once())
458+
->method('post')
459+
->with('users/1/emails', array('email' => '[email protected]'))
460+
->will($this->returnValue($expectedArray))
461+
;
462+
463+
$this->assertEquals($expectedArray, $api->createEmailForUser(1, '[email protected]'));
464+
}
465+
466+
/**
467+
* @test
468+
*/
469+
public function shouldDeleteEmailForUser()
470+
{
471+
$expectedBool = true;
472+
473+
$api = $this->getApiMock();
474+
$api->expects($this->once())
475+
->method('delete')
476+
->with('users/1/emails/3')
477+
->will($this->returnValue($expectedBool))
478+
;
479+
480+
$this->assertEquals($expectedBool, $api->removeUserEmail(1, 3));
481+
}
482+
429483
/**
430484
* @test
431485
*/

0 commit comments

Comments
 (0)