Skip to content

Commit

Permalink
Adds user controller tests
Browse files Browse the repository at this point in the history
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
  • Loading branch information
rullzer committed Dec 30, 2016
1 parent 0f6dd65 commit 1f45f57
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/Core/Controller/UserControllerTest.php
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);
}
}

0 comments on commit 1f45f57

Please sign in to comment.