Add BoardControllerTest
This commit is contained in:
@@ -36,25 +36,28 @@ use OCP\IGroupManager;
|
||||
class BoardController extends Controller {
|
||||
private $userId;
|
||||
private $boardService;
|
||||
protected $userManager;
|
||||
protected $groupManager;
|
||||
private $userManager;
|
||||
private $groupManager;
|
||||
private $userInfo;
|
||||
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
IUserManager $userManager,
|
||||
IGroupManager $groupManager,
|
||||
BoardService $cardService,
|
||||
BoardService $boardService,
|
||||
$userId) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->userId = $userId;
|
||||
$this->userManager = $userManager;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->boardService = $cardService;
|
||||
$this->boardService = $boardService;
|
||||
$this->userInfo = $this->getBoardPrerequisites();
|
||||
}
|
||||
|
||||
private function getBoardPrerequisites() {
|
||||
$groups = $this->groupManager->getUserGroupIds($this->userManager->get($this->userId));
|
||||
$groups = $this->groupManager->getUserGroupIds(
|
||||
$this->userManager->get($this->userId)
|
||||
);
|
||||
return [
|
||||
'user' => $this->userId,
|
||||
'groups' => $groups
|
||||
@@ -112,16 +115,6 @@ class BoardController extends Controller {
|
||||
return $this->boardService->delete($boardId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @RequireReadPermission
|
||||
* @param $boardId
|
||||
* @return
|
||||
*/
|
||||
public function labels($boardId) {
|
||||
return $this->boardService->labels($boardId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @RequireReadPermission
|
||||
|
||||
@@ -134,6 +134,12 @@ class BoardService {
|
||||
return $this->aclMapper->delete($acl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $boardId
|
||||
* @param $user
|
||||
* @param $permission
|
||||
* @return bool
|
||||
*/
|
||||
public function getPermission($boardId, $user, $permission) {
|
||||
$acls = $this->aclMapper->findAll($boardId);
|
||||
// check for users
|
||||
|
||||
@@ -4,4 +4,9 @@
|
||||
<directory>./tests/integration</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">./lib</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
@@ -33,11 +33,12 @@ use Test\TestCase;
|
||||
class AppTest extends TestCase {
|
||||
|
||||
private $container;
|
||||
private $app;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$app = new App('deck');
|
||||
$this->container = $app->getContainer();
|
||||
$this->app = new \OCA\Deck\AppInfo\Application();
|
||||
$this->container = $this->app->getContainer();
|
||||
}
|
||||
|
||||
public function testAppInstalled() {
|
||||
@@ -45,4 +46,8 @@ class AppTest extends TestCase {
|
||||
$this->assertTrue($appManager->isInstalled('deck'));
|
||||
}
|
||||
|
||||
public function testNavigationEntry() {
|
||||
$this->app->registerNavigationEntry();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,14 +23,16 @@
|
||||
|
||||
namespace OCA\Deck\Controller;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use OCA\Deck\Db\Acl;
|
||||
|
||||
class BoardControllerTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $controller;
|
||||
private $request;
|
||||
private $l10n;
|
||||
private $userId = 'john';
|
||||
private $userManager;
|
||||
private $groupManager;
|
||||
private $boardService;
|
||||
private $userId = 'user';
|
||||
|
||||
public function setUp() {
|
||||
$this->l10n = $this->request = $this->getMockBuilder(
|
||||
@@ -41,17 +43,144 @@ class BoardControllerTest extends \PHPUnit_Framework_TestCase {
|
||||
'\OCP\IRequest')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->userManager = $this->getMockBuilder(
|
||||
'\OCP\IUserManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->groupManager = $this->getMockBuilder(
|
||||
'\OCP\IGroupManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->boardService = $this->getMockBuilder(
|
||||
'\OCA\Deck\Service\BoardService')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->controller = new PageController(
|
||||
'deck', $this->request, $this->l10n, $this->userId
|
||||
$this->groupManager->method('getUserGroupIds')
|
||||
->willReturn(['admin', 'group1', 'group2']);
|
||||
$this->userManager->method('get')
|
||||
->with($this->userId)
|
||||
->willReturn('user');
|
||||
|
||||
$this->controller = new BoardController(
|
||||
'deck',
|
||||
$this->request,
|
||||
$this->userManager,
|
||||
$this->groupManager,
|
||||
$this->boardService,
|
||||
$this->userId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testIndex() {
|
||||
$response = $this->controller->index();
|
||||
$this->assertEquals('main', $response->getTemplateName());
|
||||
$this->boardService->expects($this->once())
|
||||
->method('findAll')
|
||||
->willReturn([1, 2, 3]);
|
||||
|
||||
$actual = $this->controller->index();
|
||||
$this->assertEquals([1, 2, 3], $actual);
|
||||
}
|
||||
|
||||
|
||||
public function testRead() {
|
||||
$this->boardService->expects($this->once())
|
||||
->method('find')
|
||||
->with(123)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->read(123));
|
||||
}
|
||||
|
||||
public function testCreate() {
|
||||
$this->boardService->expects($this->once())
|
||||
->method('create')
|
||||
->with(1, 'user', 3)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->create(1, 3));
|
||||
}
|
||||
|
||||
public function testUpdate() {
|
||||
$this->boardService->expects($this->once())
|
||||
->method('update')
|
||||
->with(1, 2, 3)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->update(1, 2, 3));
|
||||
}
|
||||
|
||||
public function testDelete() {
|
||||
$this->boardService->expects($this->once())
|
||||
->method('delete')
|
||||
->with(123)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->delete(123));
|
||||
}
|
||||
|
||||
public function testGetUserPermissions() {
|
||||
$board = $this->getMockBuilder(\OCA\Deck\Db\Board::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getOwner'])
|
||||
->getMock();
|
||||
$this->boardService->expects($this->once())
|
||||
->method('find')
|
||||
->with(123)
|
||||
->willReturn($board);
|
||||
$board->expects($this->once())
|
||||
->method('getOwner')
|
||||
->willReturn('user');
|
||||
$expected = [
|
||||
'PERMISSION_READ' => true,
|
||||
'PERMISSION_EDIT' => true,
|
||||
'PERMISSION_MANAGE' => true,
|
||||
'PERMISSION_SHARE' => true,
|
||||
];
|
||||
$this->assertEquals($expected, $this->controller->getUserPermissions(123));
|
||||
}
|
||||
|
||||
public function testGetUserPermissionsNotOwner() {
|
||||
$board = $this->getMockBuilder(\OCA\Deck\Db\Board::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getOwner'])
|
||||
->getMock();
|
||||
$this->boardService->expects($this->once())
|
||||
->method('find')
|
||||
->with(123)
|
||||
->willReturn($board);
|
||||
$board->expects($this->once())
|
||||
->method('getOwner')
|
||||
->willReturn('someoneelse');
|
||||
$this->boardService->expects($this->exactly(4))
|
||||
->method('getPermission')
|
||||
->withConsecutive([123, 'user', Acl::PERMISSION_READ])
|
||||
->will($this->onConsecutiveCalls(1, 2, 3, 4));
|
||||
$expected = [
|
||||
'PERMISSION_READ' => 1,
|
||||
'PERMISSION_EDIT' => 2,
|
||||
'PERMISSION_MANAGE' => 3,
|
||||
'PERMISSION_SHARE' => 4,
|
||||
];
|
||||
$this->assertEquals($expected, $this->controller->getUserPermissions(123));
|
||||
}
|
||||
|
||||
public function testAddAcl() {
|
||||
$this->boardService->expects($this->once())
|
||||
->method('addAcl')
|
||||
->with(1, 2, 3, 4, 5, 6)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->addAcl(1, 2, 3, 4, 5, 6));
|
||||
}
|
||||
|
||||
public function testUpdateAcl() {
|
||||
$this->boardService->expects($this->once())
|
||||
->method('updateAcl')
|
||||
->with(1, 2, 3, 4)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->updateAcl(1, 2, 3, 4));
|
||||
}
|
||||
|
||||
public function testDeleteAcl() {
|
||||
$this->boardService->expects($this->once())
|
||||
->method('deleteAcl')
|
||||
->with(1)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->deleteAcl(1));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user