Add BoardControllerTest
This commit is contained in:
@@ -36,25 +36,28 @@ use OCP\IGroupManager;
|
|||||||
class BoardController extends Controller {
|
class BoardController extends Controller {
|
||||||
private $userId;
|
private $userId;
|
||||||
private $boardService;
|
private $boardService;
|
||||||
protected $userManager;
|
private $userManager;
|
||||||
protected $groupManager;
|
private $groupManager;
|
||||||
private $userInfo;
|
private $userInfo;
|
||||||
|
|
||||||
public function __construct($appName,
|
public function __construct($appName,
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
IUserManager $userManager,
|
IUserManager $userManager,
|
||||||
IGroupManager $groupManager,
|
IGroupManager $groupManager,
|
||||||
BoardService $cardService,
|
BoardService $boardService,
|
||||||
$userId) {
|
$userId) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->userManager = $userManager;
|
$this->userManager = $userManager;
|
||||||
$this->groupManager = $groupManager;
|
$this->groupManager = $groupManager;
|
||||||
$this->boardService = $cardService;
|
$this->boardService = $boardService;
|
||||||
$this->userInfo = $this->getBoardPrerequisites();
|
$this->userInfo = $this->getBoardPrerequisites();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getBoardPrerequisites() {
|
private function getBoardPrerequisites() {
|
||||||
$groups = $this->groupManager->getUserGroupIds($this->userManager->get($this->userId));
|
$groups = $this->groupManager->getUserGroupIds(
|
||||||
|
$this->userManager->get($this->userId)
|
||||||
|
);
|
||||||
return [
|
return [
|
||||||
'user' => $this->userId,
|
'user' => $this->userId,
|
||||||
'groups' => $groups
|
'groups' => $groups
|
||||||
@@ -112,16 +115,6 @@ class BoardController extends Controller {
|
|||||||
return $this->boardService->delete($boardId);
|
return $this->boardService->delete($boardId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @NoAdminRequired
|
|
||||||
* @RequireReadPermission
|
|
||||||
* @param $boardId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public function labels($boardId) {
|
|
||||||
return $this->boardService->labels($boardId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @RequireReadPermission
|
* @RequireReadPermission
|
||||||
|
|||||||
@@ -134,6 +134,12 @@ class BoardService {
|
|||||||
return $this->aclMapper->delete($acl);
|
return $this->aclMapper->delete($acl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $boardId
|
||||||
|
* @param $user
|
||||||
|
* @param $permission
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function getPermission($boardId, $user, $permission) {
|
public function getPermission($boardId, $user, $permission) {
|
||||||
$acls = $this->aclMapper->findAll($boardId);
|
$acls = $this->aclMapper->findAll($boardId);
|
||||||
// check for users
|
// check for users
|
||||||
|
|||||||
@@ -4,4 +4,9 @@
|
|||||||
<directory>./tests/integration</directory>
|
<directory>./tests/integration</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
<filter>
|
||||||
|
<whitelist>
|
||||||
|
<directory suffix=".php">./lib</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
@@ -33,11 +33,12 @@ use Test\TestCase;
|
|||||||
class AppTest extends TestCase {
|
class AppTest extends TestCase {
|
||||||
|
|
||||||
private $container;
|
private $container;
|
||||||
|
private $app;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$app = new App('deck');
|
$this->app = new \OCA\Deck\AppInfo\Application();
|
||||||
$this->container = $app->getContainer();
|
$this->container = $this->app->getContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAppInstalled() {
|
public function testAppInstalled() {
|
||||||
@@ -45,4 +46,8 @@ class AppTest extends TestCase {
|
|||||||
$this->assertTrue($appManager->isInstalled('deck'));
|
$this->assertTrue($appManager->isInstalled('deck'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNavigationEntry() {
|
||||||
|
$this->app->registerNavigationEntry();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -23,14 +23,16 @@
|
|||||||
|
|
||||||
namespace OCA\Deck\Controller;
|
namespace OCA\Deck\Controller;
|
||||||
|
|
||||||
use PHPUnit_Framework_TestCase;
|
use OCA\Deck\Db\Acl;
|
||||||
|
|
||||||
class BoardControllerTest extends \PHPUnit_Framework_TestCase {
|
class BoardControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
private $controller;
|
private $controller;
|
||||||
private $request;
|
private $request;
|
||||||
private $l10n;
|
private $userManager;
|
||||||
private $userId = 'john';
|
private $groupManager;
|
||||||
|
private $boardService;
|
||||||
|
private $userId = 'user';
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->l10n = $this->request = $this->getMockBuilder(
|
$this->l10n = $this->request = $this->getMockBuilder(
|
||||||
@@ -41,17 +43,144 @@ class BoardControllerTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'\OCP\IRequest')
|
'\OCP\IRequest')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->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(
|
$this->groupManager->method('getUserGroupIds')
|
||||||
'deck', $this->request, $this->l10n, $this->userId
|
->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() {
|
public function testIndex() {
|
||||||
$response = $this->controller->index();
|
$this->boardService->expects($this->once())
|
||||||
$this->assertEquals('main', $response->getTemplateName());
|
->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