-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Test\Core\Controller; | ||
|
||
use OC\Core\Controller\UserController; | ||
use OCP\AppFramework\Http\JSONResponse; | ||
use OCP\IRequest; | ||
use OCP\IUser; | ||
use OCP\IUserManager; | ||
use Test\TestCase; | ||
|
||
class UserControllerTest extends TestCase { | ||
|
||
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ | ||
private $userManager; | ||
|
||
/** @var UserController */ | ||
private $controller; | ||
|
||
public function setUp() { | ||
parent::setUp(); | ||
|
||
$this->userManager = $this->createMock(IUserManager::class); | ||
$this->controller = new UserController( | ||
'core', | ||
$this->createMock(IRequest::class), | ||
$this->userManager | ||
); | ||
} | ||
|
||
public function testGetDisplayNames() { | ||
$user = $this->createMock(IUser::class); | ||
$user->method('getDisplayName') | ||
->willReturn('FooDisplay Name'); | ||
|
||
$this->userManager | ||
->method('get') | ||
->will($this->returnCallback(function ($uid) use ($user) { | ||
if ($uid === 'foo') { | ||
return $user; | ||
} | ||
return null; | ||
})); | ||
|
||
$expected = new JSONResponse([ | ||
'users' => [ | ||
'foo' => 'FooDisplay Name', | ||
'bar' => 'bar', | ||
], | ||
'status' => 'success' | ||
]); | ||
|
||
$result = $this->controller->getDisplayNames(['foo', 'bar']); | ||
$this->assertEquals($expected, $result); | ||
} | ||
} |