Fix php cs issues

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-04-22 19:57:19 +02:00
parent 7ad5daabeb
commit 52febb396c
130 changed files with 1068 additions and 1424 deletions

View File

@@ -91,7 +91,9 @@ class ActivityManagerTest extends TestCase {
$managerClass = new \ReflectionClass(ActivityManager::class);
$this->l10n->expects($this->any())
->method('t')
->will($this->returnCallback(function ($s) { return $s; }));
->will($this->returnCallback(function ($s) {
return $s;
}));
foreach ($managerClass->getConstants() as $constant => $value) {
if (strpos($constant, 'SUBJECT') === 0) {
@@ -111,7 +113,6 @@ class ActivityManagerTest extends TestCase {
}
}
}
}
public function testCreateEvent() {
@@ -342,12 +343,10 @@ class ActivityManagerTest extends TestCase {
], $this->invokePrivate($this->activityManager, 'findDetailsForAttachment', [777]));
}
public function invokePrivate(&$object, $methodName, array $parameters = array())
{
public function invokePrivate(&$object, $methodName, array $parameters = []) {
$reflection = new \ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);
return $method->invokeArgs($object, $parameters);
}
}

View File

@@ -25,9 +25,7 @@ namespace OCA\Deck\Activity;
use PHPUnit\Framework\TestCase;
class ChangeSetTest extends TestCase {
public function setUp(): void {
}
@@ -54,5 +52,4 @@ class ChangeSetTest extends TestCase {
$changeSet->enableDiff();
$this->assertTrue($changeSet->getDiff());
}
}

View File

@@ -23,27 +23,12 @@
namespace OCA\Deck\Activity;
use OCA\Deck\Db\AclMapper;
use OCA\Deck\Db\AssignedUsers;
use OCA\Deck\Db\Attachment;
use OCA\Deck\Db\AttachmentMapper;
use OCA\Deck\Db\Board;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\Label;
use OCA\Deck\Db\Stack;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\Notification\NotificationHelper;
use OCA\Deck\Service\PermissionService;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\Comments\CommentsEvent;
use OCP\Comments\IComment;
use OCP\IL10N;
use OCP\IUser;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
class CommentEventHandlerTest extends TestCase {
@@ -109,12 +94,10 @@ class CommentEventHandlerTest extends TestCase {
$this->commentEventHandler->handle($commentsEvent);
}
public function invokePrivate(&$object, $methodName, array $parameters = array())
{
public function invokePrivate(&$object, $methodName, array $parameters = []) {
$reflection = new \ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);
return $method->invokeArgs($object, $parameters);
}
}

View File

@@ -81,20 +81,20 @@ class DeckProviderTest extends TestCase {
$event->expects($this->any())->method('getObjectName')->willReturn($objectName);
$event->expects($this->any())->method('getAuthor')->willReturn('admin');
$event->expects($this->any())->method('getMessage')->willReturn('');
$event->expects($this->any())->method('setIcon')->will($this->returnCallback(function($icon) use (&$data, $event) {
$event->expects($this->any())->method('setIcon')->will($this->returnCallback(function ($icon) use (&$data, $event) {
$data['icon'] = $icon;
return $event;
}));
$event->expects($this->any())->method('setParsedSubject')->will($this->returnCallback(function($subject) use (&$data, $event) {
$event->expects($this->any())->method('setParsedSubject')->will($this->returnCallback(function ($subject) use (&$data, $event) {
$data['parsedSubject'] = $subject;
return $event;
}));
$event->expects($this->any())->method('setRichSubject')->will($this->returnCallback(function($subject) use (&$data, $event) {
$event->expects($this->any())->method('setRichSubject')->will($this->returnCallback(function ($subject) use (&$data, $event) {
$data['richSubject'] = $subject;
return $event;
}));
$event->expects($this->any())->method('getIcon')->will(
$this->returnCallback(function() use (&$data) {
$this->returnCallback(function () use (&$data) {
return array_key_exists('icon', $data) ? $data['icon'] : 'noicon';
})
);
@@ -133,12 +133,12 @@ class DeckProviderTest extends TestCase {
->willReturn('test string {board}');
$this->urlGenerator->expects($this->any())
->method('imagePath')
->will($this->returnCallback(function($a, $i) {
->will($this->returnCallback(function ($a, $i) {
return $a . '/' . $i;
}));
$this->urlGenerator->expects($this->any())
->method('getAbsoluteURL')
->will($this->returnCallback(function($url) {
->will($this->returnCallback(function ($url) {
return $url;
}));
$this->provider->parse('en_US', $event);
@@ -159,7 +159,7 @@ class DeckProviderTest extends TestCase {
public function testParseObjectTypeBoard() {
$this->urlGenerator->expects($this->any())
->method('imagePath')
->will($this->returnCallback(function($a, $i) {
->will($this->returnCallback(function ($a, $i) {
return $a . '/' . $i;
}));
$this->activityManager->expects($this->once())
@@ -200,7 +200,7 @@ class DeckProviderTest extends TestCase {
public function testParseObjectTypeCard() {
$this->urlGenerator->expects($this->any())
->method('imagePath')
->will($this->returnCallback(function($a, $i) {
->will($this->returnCallback(function ($a, $i) {
return $a . '/' . $i;
}));
$this->activityManager->expects($this->once())
@@ -238,13 +238,12 @@ class DeckProviderTest extends TestCase {
$this->assertEquals('test string Card', $event->getParsedSubject());
$this->assertEquals('test string {card}', $event->getRichSubject());
$this->assertEquals('', $event->getMessage());
}
public function testParseObjectTypeCardWithDiff() {
$this->urlGenerator->expects($this->any())
->method('imagePath')
->will($this->returnCallback(function($a, $i) {
->will($this->returnCallback(function ($a, $i) {
return $a . '/' . $i;
}));
$this->activityManager->expects($this->once())
@@ -496,8 +495,7 @@ class DeckProviderTest extends TestCase {
$this->assertEquals($expected, $actual);
}
public function invokePrivate(&$object, $methodName, array $parameters = array())
{
public function invokePrivate(&$object, $methodName, array $parameters = []) {
$reflection = new \ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);

View File

@@ -77,5 +77,4 @@ class FilterTest extends TestCase {
public function testAllowedApps() {
$this->assertEquals(['deck'], $this->filter->allowedApps());
}
}

View File

@@ -35,7 +35,9 @@ class SettingTest extends TestCase {
public function setUp(): void {
$this->l10n = $this->createMock(IL10N::class);
$this->l10n->expects($this->any())->method('t')->will($this->returnCallback(function ($s) { return $s; }));
$this->l10n->expects($this->any())->method('t')->will($this->returnCallback(function ($s) {
return $s;
}));
$this->setting = new Setting($this->l10n);
}
@@ -66,5 +68,4 @@ class SettingTest extends TestCase {
public function testIsDefaultEnabledMail() {
$this->assertFalse($this->setting->isDefaultEnabledMail());
}
}

View File

@@ -24,26 +24,19 @@
namespace OCA\Deck\Command;
use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Attachment;
use OCA\Deck\Db\AttachmentMapper;
use OCA\Deck\Db\Board;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\Stack;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\InvalidAttachmentType;
use OCA\Deck\Service\AttachmentService;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\IAttachmentService;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class UserExportTest extends \Test\TestCase {
protected $boardMapper;
protected $boardService;
protected $stackMapper;

View File

@@ -23,8 +23,6 @@
namespace OCA\Deck\Cron;
use OCA\Deck\Db\Board;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Notification\NotificationHelper;

View File

@@ -30,9 +30,8 @@ use Test\AppFramework\Db\MapperTestUtility;
/**
* @group DB
*/
class AclMapperTest extends MapperTestUtility {
private $dbConnection;
class AclMapperTest extends MapperTestUtility {
private $dbConnection;
private $aclMapper;
private $boardMapper;
private $userManager;
@@ -46,33 +45,33 @@ class AclMapperTest extends MapperTestUtility {
parent::setUp();
$this->dbConnection = \OC::$server->getDatabaseConnection();
$this->aclMapper = new AclMapper($this->dbConnection);
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->boardMapper = new BoardMapper(
$this->dbConnection,
\OC::$server->query(LabelMapper::class),
$this->aclMapper,
\OC::$server->query(StackMapper::class),
$this->aclMapper = new AclMapper($this->dbConnection);
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->boardMapper = new BoardMapper(
$this->dbConnection,
\OC::$server->query(LabelMapper::class),
$this->aclMapper,
\OC::$server->query(StackMapper::class),
$this->userManager,
$this->groupManager
);
$this->boards = [
$this->boardMapper->insert($this->getBoard('MyBoard 1', 'user1')),
$this->boardMapper->insert($this->getBoard('MyBoard 2', 'user2')),
$this->boardMapper->insert($this->getBoard('MyBoard 3', 'user3'))
];
$this->boards = [
$this->boardMapper->insert($this->getBoard('MyBoard 1', 'user1')),
$this->boardMapper->insert($this->getBoard('MyBoard 2', 'user2')),
$this->boardMapper->insert($this->getBoard('MyBoard 3', 'user3'))
];
$this->acls = [
$this->aclMapper->insert($this->getAcl('user','user1', false, false, false, $this->boards[1]->getId())),
$this->aclMapper->insert($this->getAcl('user','user2', true, false, false, $this->boards[0]->getId())),
$this->aclMapper->insert($this->getAcl('user','user3', true, true, false, $this->boards[0]->getId())),
$this->aclMapper->insert($this->getAcl('user','user1', false, false, false, $this->boards[2]->getId()))
];
$this->aclMapper->insert($this->getAcl('user','user1', false, false, false, $this->boards[1]->getId())),
$this->aclMapper->insert($this->getAcl('user','user2', true, false, false, $this->boards[0]->getId())),
$this->aclMapper->insert($this->getAcl('user','user3', true, true, false, $this->boards[0]->getId())),
$this->aclMapper->insert($this->getAcl('user','user1', false, false, false, $this->boards[2]->getId()))
];
foreach ($this->acls as $acl) {
$acl->resetUpdatedFields();
}
foreach ($this->acls as $acl) {
$acl->resetUpdatedFields();
}
}
/** @return Acl */
public function getAcl($type='user', $participant='admin', $edit=false, $share=false, $manage=false, $boardId=123) {
@@ -88,39 +87,38 @@ class AclMapperTest extends MapperTestUtility {
/** @return Board */
public function getBoard($title, $owner) {
$board = new Board();
$board->setTitle($title);
$board->setOwner($owner);
return $board;
}
$board = new Board();
$board->setTitle($title);
$board->setOwner($owner);
return $board;
}
public function testFindAllDatabase() {
$actual = $this->aclMapper->findAll($this->boards[0]->getId());
$expected = [$this->acls[1], $this->acls[2]];
$this->assertEquals($expected, $actual);
}
public function testIsOwnerDatabase() {
$this->assertTrue($this->aclMapper->isOwner('user2', $this->acls[0]->getId()));
$this->assertTrue($this->aclMapper->isOwner('user1', $this->acls[1]->getId()));
$this->assertTrue($this->aclMapper->isOwner('user1', $this->acls[2]->getId()));
$this->assertTrue($this->aclMapper->isOwner('user3', $this->acls[3]->getId()));
$this->assertFalse($this->aclMapper->isOwner('user3', $this->acls[0]->getId()));
$this->assertFalse($this->aclMapper->isOwner('user1', $this->acls[0]->getId()));
}
$actual = $this->aclMapper->findAll($this->boards[0]->getId());
$expected = [$this->acls[1], $this->acls[2]];
$this->assertEquals($expected, $actual);
}
public function testIsOwnerDatabase() {
$this->assertTrue($this->aclMapper->isOwner('user2', $this->acls[0]->getId()));
$this->assertTrue($this->aclMapper->isOwner('user1', $this->acls[1]->getId()));
$this->assertTrue($this->aclMapper->isOwner('user1', $this->acls[2]->getId()));
$this->assertTrue($this->aclMapper->isOwner('user3', $this->acls[3]->getId()));
$this->assertFalse($this->aclMapper->isOwner('user3', $this->acls[0]->getId()));
$this->assertFalse($this->aclMapper->isOwner('user1', $this->acls[0]->getId()));
}
public function testFindBoardIdDatabase() {
$this->assertEquals($this->boards[0]->getId(), $this->aclMapper->findBoardId($this->acls[1]->getId()));
}
public function testFindBoardIdDatabase() {
$this->assertEquals($this->boards[0]->getId(), $this->aclMapper->findBoardId($this->acls[1]->getId()));
}
public function tearDown(): void {
parent::tearDown();
foreach ($this->acls as $acl) {
$this->aclMapper->delete($acl);
}
foreach ($this->boards as $board) {
$this->boardMapper->delete($board);
}
}
public function tearDown(): void {
parent::tearDown();
foreach ($this->acls as $acl) {
$this->aclMapper->delete($acl);
}
foreach ($this->boards as $board) {
$this->boardMapper->delete($board);
}
}
}

View File

@@ -5,26 +5,25 @@
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
namespace OCA\Deck\Db;
class AclTest extends \Test\TestCase {
private function createAclUser() {
$acl = new Acl();
$acl->setId(1);
@@ -103,7 +102,6 @@ class AclTest extends \Test\TestCase {
$this->assertEquals(false, $acl->getPermission(Acl::PERMISSION_EDIT));
$this->assertEquals(false, $acl->getPermission(Acl::PERMISSION_MANAGE));
$this->assertEquals(false, $acl->getPermission(Acl::PERMISSION_SHARE));
$this->assertEquals(false, $acl->getPermission(5));
$this->assertEquals(false, $acl->getPermission(5));
}
}
}

View File

@@ -25,17 +25,16 @@ namespace OCA\Deck\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUserManager;
use Test\AppFramework\Db\MapperTestUtility;
/**
* @group DB
*/
class AttachmentMapperTest extends MapperTestUtility {
class AttachmentMapperTest extends MapperTestUtility {
/** @var IDBConnection */
private $dbConnection;
private $dbConnection;
/** @var AttachmentMapper */
private $attachmentMapper;
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
@@ -54,13 +53,13 @@ class AttachmentMapperTest extends MapperTestUtility {
$this->cardMapper = $this->createMock(CardMapper::class);
$this->dbConnection = \OC::$server->getDatabaseConnection();
$this->attachmentMapper = new AttachmentMapper(
$this->dbConnection,
$this->cardMapper,
$this->attachmentMapper = new AttachmentMapper(
$this->dbConnection,
$this->cardMapper,
$this->userManager
);
$this->attachments = [
$this->createAttachmentEntity(1, 'deck_file', 'file1.pdf'),
);
$this->attachments = [
$this->createAttachmentEntity(1, 'deck_file', 'file1.pdf'),
$this->createAttachmentEntity(1, 'deck_file', 'file2.pdf'),
$this->createAttachmentEntity(2, 'deck_file', 'file3.pdf'),
$this->createAttachmentEntity(3, 'deck_file', 'file4.pdf')
@@ -138,11 +137,10 @@ class AttachmentMapperTest extends MapperTestUtility {
}
}
public function tearDown(): void {
parent::tearDown();
foreach ($this->attachments as $attachment) {
$this->attachmentMapper->delete($attachment);
}
}
public function tearDown(): void {
parent::tearDown();
foreach ($this->attachments as $attachment) {
$this->attachmentMapper->delete($attachment);
}
}
}

View File

@@ -18,7 +18,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
namespace OCA\Deck\Db;
@@ -48,4 +48,4 @@ class AttachmentTest extends \Test\TestCase {
], $board->jsonSerialize());
}
}
}

View File

@@ -31,11 +31,11 @@ use Test\AppFramework\Db\MapperTestUtility;
/**
* @group DB
*/
class BoardMapperTest extends MapperTestUtility {
class BoardMapperTest extends MapperTestUtility {
/** @var IDBConnection */
private $dbConnection;
/** @var AclMapper|\PHPUnit\Framework\MockObject\MockObject */
private $dbConnection;
/** @var AclMapper|\PHPUnit\Framework\MockObject\MockObject */
private $aclMapper;
/** @var BoardMapper */
private $boardMapper;
@@ -55,35 +55,35 @@ class BoardMapperTest extends MapperTestUtility {
$this->groupManager = $this->createMock(IGroupManager::class);
$this->dbConnection = \OC::$server->getDatabaseConnection();
$this->boardMapper = new BoardMapper(
$this->dbConnection,
\OC::$server->query(LabelMapper::class),
\OC::$server->query(AclMapper::class),
\OC::$server->query(StackMapper::class),
$this->boardMapper = new BoardMapper(
$this->dbConnection,
\OC::$server->query(LabelMapper::class),
\OC::$server->query(AclMapper::class),
\OC::$server->query(StackMapper::class),
$this->userManager,
$this->groupManager
);
$this->aclMapper = \OC::$server->query(AclMapper::class);
$this->labelMapper = \OC::$server->query(LabelMapper::class);
);
$this->aclMapper = \OC::$server->query(AclMapper::class);
$this->labelMapper = \OC::$server->query(LabelMapper::class);
$this->boards = [
$this->boardMapper->insert($this->getBoard('MyBoard 1', 'user1')),
$this->boardMapper->insert($this->getBoard('MyBoard 2', 'user2')),
$this->boardMapper->insert($this->getBoard('MyBoard 3', 'user3'))
];
$this->boards = [
$this->boardMapper->insert($this->getBoard('MyBoard 1', 'user1')),
$this->boardMapper->insert($this->getBoard('MyBoard 2', 'user2')),
$this->boardMapper->insert($this->getBoard('MyBoard 3', 'user3'))
];
$this->acls = [
$this->aclMapper->insert($this->getAcl('user','user1', false, false, false, $this->boards[1]->getId())),
$this->aclMapper->insert($this->getAcl('user','user2', true, false, false, $this->boards[0]->getId())),
$this->aclMapper->insert($this->getAcl('user','user3', true, true, false, $this->boards[0]->getId())),
$this->aclMapper->insert($this->getAcl('user','user1', false, false, false, $this->boards[2]->getId()))
];
$this->aclMapper->insert($this->getAcl('user','user1', false, false, false, $this->boards[1]->getId())),
$this->aclMapper->insert($this->getAcl('user','user2', true, false, false, $this->boards[0]->getId())),
$this->aclMapper->insert($this->getAcl('user','user3', true, true, false, $this->boards[0]->getId())),
$this->aclMapper->insert($this->getAcl('user','user1', false, false, false, $this->boards[2]->getId()))
];
foreach ($this->acls as $acl) {
$acl->resetUpdatedFields();
}
foreach ($this->boards as $board) {
$board->resetUpdatedFields();
}
$acl->resetUpdatedFields();
}
foreach ($this->boards as $board) {
$board->resetUpdatedFields();
}
}
/** @return Acl */
public function getAcl($type='user', $participant='admin', $edit=false, $share=false, $manage=false, $boardId=123) {
@@ -99,20 +99,20 @@ class BoardMapperTest extends MapperTestUtility {
/** @return Board */
public function getBoard($title, $owner) {
$board = new Board();
$board->setTitle($title);
$board->setOwner($owner);
return $board;
}
$board = new Board();
$board->setTitle($title);
$board->setOwner($owner);
return $board;
}
public function testFind() {
$actual = $this->boardMapper->find($this->boards[0]->getId());
/** @var Board $expected */
$expected = clone $this->boards[0];
$expected->setShared(-1);
$expected->resetUpdatedFields();
$this->assertEquals($expected, $actual);
}
$actual = $this->boardMapper->find($this->boards[0]->getId());
/** @var Board $expected */
$expected = clone $this->boards[0];
$expected->setShared(-1);
$expected->resetUpdatedFields();
$this->assertEquals($expected, $actual);
}
public function testFindAllByUser() {
$actual = $this->boardMapper->findAllByUser('user1');
@@ -123,7 +123,7 @@ class BoardMapperTest extends MapperTestUtility {
];
foreach ($expected as $e) {
foreach ($actual as $a) {
if($e->getId() === $a->getId()) {
if ($e->getId() === $a->getId()) {
$this->assertEquals($e->getTitle(), $a->getTitle());
}
}
@@ -149,27 +149,26 @@ class BoardMapperTest extends MapperTestUtility {
$this->boardMapper->update($this->boards[0]);
}
public function testFindWithLabels() {
$actual = $this->boardMapper->find($this->boards[0]->getId(), true, false);
public function testFindWithLabels() {
$actual = $this->boardMapper->find($this->boards[0]->getId(), true, false);
/** @var Board $expected */
$expected = $this->boards[0];
$this->assertEquals($expected->getLabels(), $actual->getLabels());
}
$this->assertEquals($expected->getLabels(), $actual->getLabels());
}
public function testFindWithAcl() {
$actual = $this->boardMapper->find($this->boards[0]->getId(), false, true);
$expected = [$this->acls[1], $this->acls[2]];
$this->assertEquals($expected, $actual->getAcl());
}
public function tearDown(): void {
parent::tearDown();
foreach ($this->acls as $acl) {
$this->aclMapper->delete($acl);
}
foreach ($this->boards as $board) {
$this->boardMapper->delete($board);
}
}
public function testFindWithAcl() {
$actual = $this->boardMapper->find($this->boards[0]->getId(), false, true);
$expected = [$this->acls[1], $this->acls[2]];
$this->assertEquals($expected, $actual->getAcl());
}
public function tearDown(): void {
parent::tearDown();
foreach ($this->acls as $acl) {
$this->aclMapper->delete($acl);
}
foreach ($this->boards as $board) {
$this->boardMapper->delete($board);
}
}
}

View File

@@ -23,12 +23,12 @@ class BoardTest extends TestCase {
'title' => "My Board",
'owner' => "admin",
'color' => "000000",
'labels' => array(),
'labels' => [],
'permissions' => [],
'stacks' => [],
'deletedAt' => 0,
'lastModified' => 0,
'acl' => array(),
'acl' => [],
'archived' => false,
'users' => ['user1', 'user2'],
], $board->jsonSerialize());
@@ -36,18 +36,18 @@ class BoardTest extends TestCase {
public function testSetLabels() {
$board = $this->createBoard();
$board->setLabels(array("foo", "bar"));
$board->setLabels(["foo", "bar"]);
$this->assertEquals([
'id' => 1,
'title' => "My Board",
'owner' => "admin",
'color' => "000000",
'labels' => array("foo", "bar"),
'labels' => ["foo", "bar"],
'permissions' => [],
'stacks' => [],
'deletedAt' => 0,
'lastModified' => 0,
'acl' => array(),
'acl' => [],
'archived' => false,
'users' => [],
], $board->jsonSerialize());
@@ -56,7 +56,7 @@ class BoardTest extends TestCase {
$acl = new Acl();
$acl->setId(1);
$board = $this->createBoard();
$board->setAcl(array($acl));
$board->setAcl([$acl]);
$result = $board->getAcl()[0];
$this->assertEquals($acl, $result);
}
@@ -68,12 +68,12 @@ class BoardTest extends TestCase {
'title' => "My Board",
'owner' => "admin",
'color' => "000000",
'labels' => array(),
'labels' => [],
'permissions' => [],
'stacks' => [],
'deletedAt' => 0,
'lastModified' => 0,
'acl' => array(),
'acl' => [],
'archived' => false,
'shared' => 1,
'users' => [],

View File

@@ -88,7 +88,7 @@ class CardTest extends TestCase {
}
public function testJsonSerializeLabels() {
$card = $this->createCard();
$card->setLabels(array());
$card->setLabels([]);
$this->assertEquals([
'id' => 1,
'title' => "My Card",
@@ -99,7 +99,7 @@ class CardTest extends TestCase {
'owner' => 'admin',
'order' => 12,
'stackId' => 1,
'labels' => array(),
'labels' => [],
'duedate' => null,
'overdue' => 0,
'archived' => false,
@@ -123,7 +123,7 @@ class CardTest extends TestCase {
public function testJsonSerializeAsignedUsers() {
$card = $this->createCard();
$card->setAssignedUsers([ 'user1' ]);
$card->setLabels(array());
$card->setLabels([]);
$this->assertEquals([
'id' => 1,
'title' => "My Card",
@@ -134,7 +134,7 @@ class CardTest extends TestCase {
'owner' => 'admin',
'order' => 12,
'stackId' => 1,
'labels' => array(),
'labels' => [],
'duedate' => null,
'overdue' => 0,
'archived' => false,
@@ -146,5 +146,4 @@ class CardTest extends TestCase {
'lastEditor' => null,
], $card->jsonSerialize());
}
}

View File

@@ -26,7 +26,6 @@ namespace OCA\Deck\Db;
use OCP\IGroup;
class GroupTest extends \Test\TestCase {
public function testGroupObjectSerialize() {
/** @var IGroup $group */
$group = $this->createMock(IGroup::class);

View File

@@ -5,20 +5,20 @@
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
namespace OCA\Deck\Db;
@@ -37,14 +37,13 @@ class LabelTest extends TestCase {
$label = $this->createLabel();
$label->setBoardId(123);
$this->assertEquals([
'id' => 1,
'title' => 'My Label',
'boardId' => 123,
'cardId' => null,
'lastModified' => null,
'color' => '000000'
], $label->jsonSerialize());
'id' => 1,
'title' => 'My Label',
'boardId' => 123,
'cardId' => null,
'lastModified' => null,
'color' => '000000'
], $label->jsonSerialize());
}
public function testJsonSerializeCard() {
$label = $this->createLabel();
@@ -57,8 +56,5 @@ class LabelTest extends TestCase {
'lastModified' => null,
'color' => '000000'
], $label->jsonSerialize());
}
}

View File

@@ -5,26 +5,25 @@
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
namespace OCA\Deck\Db;
class RelationalEntityTest extends \Test\TestCase {
public function testRelation() {
$entity = new RelationalEntity();
$entity->foo = null;
@@ -48,5 +47,4 @@ class RelationalEntityTest extends \Test\TestCase {
];
$this->assertEquals($json, $entity->jsonSerialize());
}
}
}

View File

@@ -44,7 +44,7 @@ class StackTest extends \Test\TestCase {
], $board->jsonSerialize());
}
public function testJsonSerializeWithCards() {
$cards = array("foo", "bar");
$cards = ["foo", "bar"];
$board = $this->createStack();
$board->setCards($cards);
$this->assertEquals([
@@ -52,7 +52,7 @@ class StackTest extends \Test\TestCase {
'title' => "My Stack",
'order' => 1,
'boardId' => 1,
'cards' => array("foo", "bar"),
'cards' => ["foo", "bar"],
'deletedAt' => 0,
'lastModified' => 0,
], $board->jsonSerialize());

View File

@@ -26,7 +26,6 @@ namespace OCA\Deck\Db;
use OCP\IUser;
class UserTest extends \Test\TestCase {
public function testGroupObjectSerialize() {
/** @var IUser $user */
$user = $this->createMock(IUser::class);

View File

@@ -5,33 +5,31 @@
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
namespace OCA\Deck\Db;
use OCA\Deck\ArchivedItemException;
use OCA\Deck\Controller\PageController;
use OCA\Deck\InvalidAttachmentType;
use OCA\Deck\NoPermissionException;
use OCA\Deck\NotFoundException;
use OCA\Deck\StatusException;
class ExceptionsTest extends \Test\TestCase {
public function testNoPermissionException() {
$c = new \stdClass();
$e = new NoPermissionException('not allowed', $c, 'mymethod');
@@ -60,5 +58,4 @@ class ExceptionsTest extends \Test\TestCase {
$this->assertEquals('foo', $e->getMessage());
$this->assertEquals(500, $e->getStatus());
}
}
}

View File

@@ -35,7 +35,6 @@ use OCP\ILogger;
use OCP\IConfig;
use OCP\IRequest;
class ExceptionMiddlewareTest extends \Test\TestCase {
/** @var ILogger */
@@ -87,7 +86,5 @@ class ExceptionMiddlewareTest extends \Test\TestCase {
$result = $this->exceptionMiddleware->afterException($boardController, 'bar', new \Exception('failed hard'));
$this->assertEquals('failed hard', $result->getData()['message']);
$this->assertEquals(500, $result->getData()['status']);
}
}

View File

@@ -23,7 +23,6 @@
namespace OCA\Deck\Notification;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\Board;
use OCA\Deck\Db\BoardMapper;
@@ -71,7 +70,6 @@ class NotificationHelperTest extends \Test\TestCase {
$this->groupManager,
$this->currentUser
);
}
public function testSendCardDuedateAlreadyNotified() {
@@ -101,7 +99,7 @@ class NotificationHelperTest extends \Test\TestCase {
->method('__call')
->with('getId', [])
->willReturn(123);
for($i=0; $i<3; $i++) {
for ($i=0; $i<3; $i++) {
$card->expects($this->at($i*3+2))
->method('__call')
->with('getId', [])
@@ -351,6 +349,4 @@ class NotificationHelperTest extends \Test\TestCase {
$this->notificationHelper->sendMention($comment);
}
}

View File

@@ -31,9 +31,6 @@ use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
use OCP\RichObjectStrings\Definitions;
class NotifierTest extends \Test\TestCase {
@@ -124,7 +121,6 @@ class NotifierTest extends \Test\TestCase {
$actualNotification = $this->notifier->prepare($notification, 'en_US');
$this->assertEquals($notification, $actualNotification);
}
public function testPrepareCardCommentMentioned() {
@@ -171,7 +167,6 @@ class NotifierTest extends \Test\TestCase {
$actualNotification = $this->notifier->prepare($notification, 'en_US');
$this->assertEquals($notification, $actualNotification);
}
public function dataPrepareCardAssigned() {
@@ -313,5 +308,4 @@ class NotifierTest extends \Test\TestCase {
$this->assertEquals($notification, $actualNotification);
}
}

View File

@@ -23,30 +23,18 @@
namespace OCA\Deck\Service;
use OCA\Deck\Activity\ActivityManager;
use OCA\Deck\BadRequestException;
use OCA\Deck\Db\AclMapper;
use OCA\Deck\Db\AssignedUsers;
use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\LabelMapper;
use OCA\Deck\NotFoundException;
use OCA\Deck\Notification\NotificationHelper;
use OCA\Deck\StatusException;
use OCP\Activity\IEvent;
use OCP\Comments\ICommentsManager;
use OCP\EventDispatcher\ABroadcastedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
class AssignmentServiceTest extends TestCase {
@@ -231,6 +219,4 @@ class AssignmentServiceTest extends TestCase {
$this->expectException(NotFoundException::class);
$actual = $this->assignmentService->unassignUser(123, 'user');
}
}

View File

@@ -23,7 +23,6 @@
namespace OCA\Deck\Service;
use OCA\Deck\Activity\ActivityManager;
use OCA\Deck\AppInfo\Application;
use OCA\Deck\Db\Acl;
@@ -44,13 +43,20 @@ use Test\TestCase;
/** @internal Just for testing the service registration */
class MyAttachmentService {
public function extendData(Attachment $attachment) {}
public function display(Attachment $attachment) {}
public function create(Attachment $attachment) {}
public function update(Attachment $attachment) {}
public function delete(Attachment $attachment) {}
public function allowUndo() {}
public function markAsDeleted(Attachment $attachment) {}
public function extendData(Attachment $attachment) {
}
public function display(Attachment $attachment) {
}
public function create(Attachment $attachment) {
}
public function update(Attachment $attachment) {
}
public function delete(Attachment $attachment) {
}
public function allowUndo() {
}
public function markAsDeleted(Attachment $attachment) {
}
}
class AttachmentServiceTest extends TestCase {
@@ -106,10 +112,10 @@ class AttachmentServiceTest extends TestCase {
$this->l10n = $this->createMock(IL10N::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $this->application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager);
}
$this->attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $this->application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager);
}
public function testRegisterAttachmentService() {
public function testRegisterAttachmentService() {
$application = $this->createMock(Application::class);
$appContainer = $this->createMock(IAppContainer::class);
$fileServiceMock = $this->createMock(FileService::class);
@@ -227,7 +233,9 @@ class AttachmentServiceTest extends TestCase {
->willReturn($attachment);
$this->attachmentServiceImpl->expects($this->once())
->method('extendData')
->willReturnCallback(function($a) { $a->setExtendedData(['mime' => 'image/jpeg']); });
->willReturnCallback(function ($a) {
$a->setExtendedData(['mime' => 'image/jpeg']);
});
$actual = $this->attachmentService->create(123, 'deck_file', 'file_name.jpg');
@@ -282,7 +290,9 @@ class AttachmentServiceTest extends TestCase {
->willReturn($attachment);
$this->attachmentServiceImpl->expects($this->once())
->method('extendData')
->willReturnCallback(function($a) { $a->setExtendedData(['mime' => 'image/jpeg']); });
->willReturnCallback(function ($a) {
$a->setExtendedData(['mime' => 'image/jpeg']);
});
$actual = $this->attachmentService->update(123, 1, 'file_name.jpg');
@@ -326,7 +336,9 @@ class AttachmentServiceTest extends TestCase {
->willReturn(true);
$this->attachmentServiceImpl->expects($this->once())
->method('markAsDeleted')
->willReturnCallback(function($a) { $a->setDeletedAt(23); });
->willReturnCallback(function ($a) {
$a->setDeletedAt(23);
});
$this->attachmentMapper->expects($this->once())
->method('update')
->willReturn($attachment);
@@ -370,5 +382,4 @@ class AttachmentServiceTest extends TestCase {
->willReturn(false);
$actual = $this->attachmentService->restore(123, 1);
}
}

View File

@@ -162,9 +162,9 @@ class BoardServiceTest extends TestCase {
public function testCreate() {
$board = new Board();
$board->setTitle('MyBoard');
$board->setOwner('admin');
$board->setColor('00ff00');
$board->setTitle('MyBoard');
$board->setOwner('admin');
$board->setColor('00ff00');
$this->boardMapper->expects($this->once())
->method('insert')
->willReturn($board);
@@ -247,7 +247,7 @@ class BoardServiceTest extends TestCase {
$acl->setPermissionEdit(true);
$acl->setPermissionShare(true);
$acl->setPermissionManage(true);
$acl->resolveRelation('participant', function($participant) use (&$user) {
$acl->resolveRelation('participant', function ($participant) use (&$user) {
return null;
});
$this->notificationHelper->expects($this->once())
@@ -333,7 +333,7 @@ class BoardServiceTest extends TestCase {
$acl->setPermissionEdit($resultingAcl[0]);
$acl->setPermissionShare($resultingAcl[1]);
$acl->setPermissionManage($resultingAcl[2]);
$acl->resolveRelation('participant', function($participant) use (&$user) {
$acl->resolveRelation('participant', function ($participant) use (&$user) {
return null;
});
$this->notificationHelper->expects($this->once())
@@ -373,7 +373,6 @@ class BoardServiceTest extends TestCase {
$this->assertFalse($result->getPermissionEdit());
$this->assertFalse($result->getPermissionShare());
$this->assertFalse($result->getPermissionManage());
}
public function testDeleteAcl() {

View File

@@ -23,10 +23,7 @@
namespace OCA\Deck\Service;
use OCA\Deck\Activity\ActivityManager;
use OCA\Deck\BadRequestException;
use OCA\Deck\Db\AssignedUsers;
use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper;
@@ -34,13 +31,10 @@ use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\LabelMapper;
use OCA\Deck\NotFoundException;
use OCA\Deck\Notification\NotificationHelper;
use OCA\Deck\StatusException;
use OCP\Activity\IEvent;
use OCP\Comments\ICommentsManager;
use OCP\EventDispatcher\ABroadcastedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
use OCP\IUserManager;
@@ -81,7 +75,7 @@ class CardServiceTest extends TestCase {
private $changeHelper;
public function setUp(): void {
parent::setUp();
parent::setUp();
$this->cardMapper = $this->createMock(CardMapper::class);
$this->stackMapper = $this->createMock(StackMapper::class);
$this->boardMapper = $this->createMock(BoardMapper::class);
@@ -184,7 +178,9 @@ class CardServiceTest extends TestCase {
$card->setTitle('title');
$card->setArchived(false);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->once())->method('update')->willReturnCallback(function($c) { return $c; });
$this->cardMapper->expects($this->once())->method('update')->willReturnCallback(function ($c) {
return $c;
});
$actual = $this->cardService->update(123, 'newtitle', 234, 'text', 999, 'foo', 'admin', '2017-01-01 00:00:00', null);
$this->assertEquals('newtitle', $actual->getTitle());
$this->assertEquals(234, $actual->getStackId());
@@ -209,7 +205,9 @@ class CardServiceTest extends TestCase {
$card->setTitle('title');
$card->setArchived(false);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->once())->method('update')->willReturnCallback(function($c) { return $c; });
$this->cardMapper->expects($this->once())->method('update')->willReturnCallback(function ($c) {
return $c;
});
$actual = $this->cardService->rename(123, 'newtitle');
$this->assertEquals('newtitle', $actual->getTitle());
}
@@ -224,31 +222,31 @@ class CardServiceTest extends TestCase {
$this->cardService->rename(123, 'newtitle');
}
public function dataReorder() {
return [
[0, 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]],
[0, 9, [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]],
[1, 3, [0, 2, 3, 1, 4, 5, 6, 7, 8, 9]]
];
}
/** @dataProvider dataReorder */
public function testReorder($cardId, $newPosition, $order) {
$cards = $this->getCards();
$cardsTmp = [];
$this->cardMapper->expects($this->once())->method('findAll')->willReturn($cards);
$card = new Card();
$card->setStackId(123);
public function dataReorder() {
return [
[0, 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]],
[0, 9, [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]],
[1, 3, [0, 2, 3, 1, 4, 5, 6, 7, 8, 9]]
];
}
/** @dataProvider dataReorder */
public function testReorder($cardId, $newPosition, $order) {
$cards = $this->getCards();
$cardsTmp = [];
$this->cardMapper->expects($this->once())->method('findAll')->willReturn($cards);
$card = new Card();
$card->setStackId(123);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$result = $this->cardService->reorder($cardId, 123, $newPosition);
foreach ($result as $card) {
$actual[$card->getOrder()] = $card->getId();
}
$this->assertEquals($order, $actual);
}
$result = $this->cardService->reorder($cardId, 123, $newPosition);
foreach ($result as $card) {
$actual[$card->getOrder()] = $card->getId();
}
$this->assertEquals($order, $actual);
}
private function getCards() {
$cards = [];
for($i=0; $i<10; $i++) {
for ($i=0; $i<10; $i++) {
$cards[$i] = new Card();
$cards[$i]->setTitle($i);
$cards[$i]->setOrder($i);
@@ -257,35 +255,37 @@ class CardServiceTest extends TestCase {
return $cards;
}
public function testReorderArchived() {
$card = new Card();
$card->setTitle('title');
$card->setArchived(true);
public function testReorderArchived() {
$card = new Card();
$card->setTitle('title');
$card->setArchived(true);
$card->setStackId(123);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->never())->method('update')->willReturnCallback(function($c) { return $c; });
$this->expectException(StatusException::class);
$actual = $this->cardService->reorder(123, 234, 1);
}
public function testArchive() {
$card = new Card();
$this->assertFalse($card->getArchived());
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->once())->method('update')->willReturnCallback(function($c) {
return $c;
});
$this->assertTrue($this->cardService->archive(123)->getArchived());
}
public function testUnarchive() {
$card = new Card();
$card->setArchived(true);
$this->assertTrue($card->getArchived());
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->once())->method('update')->willReturnCallback(function($c) {
return $c;
});
$this->assertFalse($this->cardService->unarchive(123)->getArchived());
}
$this->cardMapper->expects($this->never())->method('update')->willReturnCallback(function ($c) {
return $c;
});
$this->expectException(StatusException::class);
$actual = $this->cardService->reorder(123, 234, 1);
}
public function testArchive() {
$card = new Card();
$this->assertFalse($card->getArchived());
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->once())->method('update')->willReturnCallback(function ($c) {
return $c;
});
$this->assertTrue($this->cardService->archive(123)->getArchived());
}
public function testUnarchive() {
$card = new Card();
$card->setArchived(true);
$this->assertTrue($card->getArchived());
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->once())->method('update')->willReturnCallback(function ($c) {
return $c;
});
$this->assertFalse($this->cardService->unarchive(123)->getArchived());
}
public function testAssignLabel() {
$card = new Card();
@@ -320,5 +320,4 @@ class CardServiceTest extends TestCase {
$this->expectException(StatusException::class);
$this->cardService->removeLabel(123, 999);
}
}

View File

@@ -27,10 +27,6 @@ use OCA\Deck\Db\Card;
use OCA\Deck\Db\Board;
use OCA\Deck\Db\Stack;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Service\DefaultBoardService;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\StackService;
use OCA\Deck\Service\CardService;
use OCP\IConfig;
use OCP\IL10N;
use \Test\TestCase;
@@ -135,7 +131,9 @@ class DefaultBoardServiceTest extends TestCase {
$this->l10n->expects($this->any())
->method('t')
->willReturnCallback(function($text) { return $text; });
->willReturnCallback(function ($text) {
return $text;
});
$stackToDoId = '123';
$stackToDo = $this->assembleTestStack('To do', $stackToDoId, $boardId);

View File

@@ -23,7 +23,6 @@
namespace OCA\Deck\Service;
use OCA\Deck\Db\Attachment;
use OCA\Deck\Db\AttachmentMapper;
use OCP\AppFramework\Http\ContentSecurityPolicy;
@@ -69,9 +68,9 @@ class FileServiceTest extends TestCase {
$this->config = $this->createMock(IConfig::class);
$this->attachmentMapper = $this->createMock(AttachmentMapper::class);
$this->fileService = new FileService($this->l10n, $this->appData, $this->request, $this->logger, $this->rootFolder, $this->config, $this->attachmentMapper);
}
}
public function mockGetFolder($cardId) {
public function mockGetFolder($cardId) {
$folder = $this->createMock(ISimpleFolder::class);
$this->appData->expects($this->once())
->method('getFolder')

View File

@@ -23,7 +23,6 @@
namespace OCA\Deck\Service;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\Label;
use OCA\Deck\Db\LabelMapper;
@@ -31,84 +30,83 @@ use Test\TestCase;
class LabelServiceTest extends TestCase {
/** @var LabelMapper|\PHPUnit\Framework\MockObject\MockObject */
private $labelMapper;
/** @var PermissionService|\PHPUnit\Framework\MockObject\MockObject */
private $permissionService;
/** @var LabelService */
private $labelService;
/** @var LabelMapper|\PHPUnit\Framework\MockObject\MockObject */
private $labelMapper;
/** @var PermissionService|\PHPUnit\Framework\MockObject\MockObject */
private $permissionService;
/** @var LabelService */
private $labelService;
/** @var BoardService|\PHPUnit\Framework\MockObject\MockObject */
private $boardService;
/** @var ChangeHelper|\PHPUnit\Framework\MockObject\MockObject */
private $changeHelper;
public function setUp(): void {
public function setUp(): void {
parent::setUp();
$this->labelMapper = $this->getMockBuilder(LabelMapper::class)
->disableOriginalConstructor()->getMock();
$this->permissionService = $this->getMockBuilder(PermissionService::class)
->disableOriginalConstructor()->getMock();
$this->boardService = $this->createMock(BoardService::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->labelService = new LabelService(
$this->labelMapper,
$this->permissionService,
$this->labelMapper = $this->getMockBuilder(LabelMapper::class)
->disableOriginalConstructor()->getMock();
$this->permissionService = $this->getMockBuilder(PermissionService::class)
->disableOriginalConstructor()->getMock();
$this->boardService = $this->createMock(BoardService::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->labelService = new LabelService(
$this->labelMapper,
$this->permissionService,
$this->boardService,
$this->changeHelper
);
}
);
}
public function testFind() {
$this->labelMapper->expects($this->once())->method('find')->willReturn(true);
$this->assertTrue($this->labelService->find(123));
}
public function testFind() {
$this->labelMapper->expects($this->once())->method('find')->willReturn(true);
$this->assertTrue($this->labelService->find(123));
}
public function testCreate() {
$label = new Label();
$label->setTitle('Label title');
$label->setBoardId(123);
$label->setColor('00ff00');
$this->labelMapper->expects($this->once())
->method('insert')
->willReturn($label);
$b = $this->labelService->create('Label title', '00ff00', 123);
public function testCreate() {
$label = new Label();
$label->setTitle('Label title');
$label->setBoardId(123);
$label->setColor('00ff00');
$this->labelMapper->expects($this->once())
->method('insert')
->willReturn($label);
$b = $this->labelService->create('Label title', '00ff00', 123);
$this->assertEquals($b->getTitle(), 'Label title');
$this->assertEquals($b->getBoardId(), 123);
$this->assertEquals($b->getColor(), '00ff00');
}
$this->assertEquals($b->getTitle(), 'Label title');
$this->assertEquals($b->getBoardId(), 123);
$this->assertEquals($b->getColor(), '00ff00');
}
public function testUpdate() {
$label = new Label();
$label->setTitle('Title');
$label->setBoardId(123);
$label->setColor('00ff00');
$this->labelMapper->expects($this->once())
->method('find')
->with(1)
->willReturn($label);
$this->labelMapper->expects($this->once())
->method('update')
->with($label)
->willReturn($label);
$b = $this->labelService->update(1, 'NewTitle', 'ffffff');
public function testUpdate() {
$label = new Label();
$label->setTitle('Title');
$label->setBoardId(123);
$label->setColor('00ff00');
$this->labelMapper->expects($this->once())
->method('find')
->with(1)
->willReturn($label);
$this->labelMapper->expects($this->once())
->method('update')
->with($label)
->willReturn($label);
$b = $this->labelService->update(1, 'NewTitle', 'ffffff');
$this->assertEquals($b->getTitle(), 'NewTitle');
$this->assertEquals($b->getBoardId(), 123);
$this->assertEquals($b->getColor(), 'ffffff');
}
$this->assertEquals($b->getTitle(), 'NewTitle');
$this->assertEquals($b->getBoardId(), 123);
$this->assertEquals($b->getColor(), 'ffffff');
}
public function testDelete() {
public function testDelete() {
$label = new Label();
$label->setId(1);
$this->labelMapper->expects($this->once())
->method('find')
->willReturn($label);
$this->labelMapper->expects($this->once())
->method('delete')
->willReturn($label);
$this->assertEquals($label, $this->labelService->delete(1));
}
$this->labelMapper->expects($this->once())
->method('find')
->willReturn($label);
$this->labelMapper->expects($this->once())
->method('delete')
->willReturn($label);
$this->assertEquals($label, $this->labelService->delete(1));
}
}

View File

@@ -43,15 +43,15 @@ class PermissionServiceTest extends \Test\TestCase {
/** @var PermissionService*/
private $service;
/** @var ILogger */
/** @var ILogger */
private $logger;
/** @var AclMapper */
private $aclMapper;
/** @var BoardMapper */
private $boardMapper;
/** @var IUserManager */
private $userManager;
/** @var IGroupManager */
/** @var BoardMapper */
private $boardMapper;
/** @var IUserManager */
private $userManager;
/** @var IGroupManager */
private $groupManager;
/** @var IManager */
private $shareManager;
@@ -176,135 +176,133 @@ class PermissionServiceTest extends \Test\TestCase {
$this->assertEquals($canEdit, $this->service->userCan($acls, Acl::PERMISSION_EDIT));
$this->assertEquals($canShare, $this->service->userCan($acls, Acl::PERMISSION_SHARE));
$this->assertEquals($canManage, $this->service->userCan($acls, Acl::PERMISSION_MANAGE));
}
}
public function testUserCanFail() {
$this->assertFalse($this->service->userCan([], Acl::PERMISSION_EDIT));
}
public function dataCheckPermission() {
return [
// see getAcls() for set permissions
[1, Acl::PERMISSION_READ, true],
[1, Acl::PERMISSION_EDIT, false],
[1, Acl::PERMISSION_MANAGE, false],
[1, Acl::PERMISSION_SHARE, false],
public function dataCheckPermission() {
return [
// see getAcls() for set permissions
[1, Acl::PERMISSION_READ, true],
[1, Acl::PERMISSION_EDIT, false],
[1, Acl::PERMISSION_MANAGE, false],
[1, Acl::PERMISSION_SHARE, false],
[2, Acl::PERMISSION_READ, true],
[2, Acl::PERMISSION_EDIT, true],
[2, Acl::PERMISSION_MANAGE, false],
[2, Acl::PERMISSION_SHARE, false],
[2, Acl::PERMISSION_READ, true],
[2, Acl::PERMISSION_EDIT, true],
[2, Acl::PERMISSION_MANAGE, false],
[2, Acl::PERMISSION_SHARE, false],
[3, Acl::PERMISSION_READ, true],
[3, Acl::PERMISSION_EDIT, false],
[3, Acl::PERMISSION_MANAGE, true],
[3, Acl::PERMISSION_SHARE, false],
[3, Acl::PERMISSION_READ, true],
[3, Acl::PERMISSION_EDIT, false],
[3, Acl::PERMISSION_MANAGE, true],
[3, Acl::PERMISSION_SHARE, false],
[4, Acl::PERMISSION_READ, true],
[4, Acl::PERMISSION_EDIT, false],
[4, Acl::PERMISSION_MANAGE, false],
[4, Acl::PERMISSION_SHARE, true],
[4, Acl::PERMISSION_READ, true],
[4, Acl::PERMISSION_EDIT, false],
[4, Acl::PERMISSION_MANAGE, false],
[4, Acl::PERMISSION_SHARE, true],
[null, Acl::PERMISSION_READ, false],
[6, Acl::PERMISSION_READ, false],
[null, Acl::PERMISSION_READ, false],
[6, Acl::PERMISSION_READ, false],
[1, Acl::PERMISSION_READ, true, 'admin'],
[1, Acl::PERMISSION_EDIT, true, 'admin'],
[1, Acl::PERMISSION_MANAGE, true, 'admin'],
[1, Acl::PERMISSION_SHARE, true, 'admin'],
];
}
[1, Acl::PERMISSION_READ, true, 'admin'],
[1, Acl::PERMISSION_EDIT, true, 'admin'],
[1, Acl::PERMISSION_MANAGE, true, 'admin'],
[1, Acl::PERMISSION_SHARE, true, 'admin'],
];
}
/** @dataProvider dataCheckPermission */
public function testCheckPermission($boardId, $permission, $result, $owner='foo') {
// Setup mapper
$mapper = $this->getMockBuilder(IPermissionMapper::class)->getMock();
// Setup mapper
$mapper = $this->getMockBuilder(IPermissionMapper::class)->getMock();
// board owner
$mapper->expects($this->once())->method('findBoardId')->willReturn($boardId);
$board = new Board();
$board->setId($boardId);
$board->setOwner($owner);
$this->boardMapper->expects($this->any())->method('find')->willReturn($board);
// board owner
$mapper->expects($this->once())->method('findBoardId')->willReturn($boardId);
$board = new Board();
$board->setId($boardId);
$board->setOwner($owner);
$this->boardMapper->expects($this->any())->method('find')->willReturn($board);
// acl check
$acls = $this->getAcls($boardId);
$this->aclMapper->expects($this->any())->method('findAll')->willReturn($acls);
// acl check
$acls = $this->getAcls($boardId);
$this->aclMapper->expects($this->any())->method('findAll')->willReturn($acls);
$this->shareManager->expects($this->any())
$this->shareManager->expects($this->any())
->method('sharingDisabledForUser')
->willReturn(false);
if($result) {
$actual = $this->service->checkPermission($mapper, 1234, $permission);
$this->assertTrue($actual);
} else {
$this->expectException(NoPermissionException::class);
$this->service->checkPermission($mapper, 1234, $permission);
}
if ($result) {
$actual = $this->service->checkPermission($mapper, 1234, $permission);
$this->assertTrue($actual);
} else {
$this->expectException(NoPermissionException::class);
$this->service->checkPermission($mapper, 1234, $permission);
}
}
}
/** @dataProvider dataCheckPermission */
public function testCheckPermissionWithoutMapper($boardId, $permission, $result, $owner='foo') {
$mapper = null;
$board = new Board();
$board->setId($boardId);
$board->setOwner($owner);
if($boardId === null) {
$this->boardMapper->expects($this->any())->method('find')->willThrowException(new DoesNotExistException('not found'));
} else {
$this->boardMapper->expects($this->any())->method('find')->willReturn($board);
}
$acls = $this->getAcls($boardId);
$this->aclMapper->expects($this->any())->method('findAll')->willReturn($acls);
/** @dataProvider dataCheckPermission */
public function testCheckPermissionWithoutMapper($boardId, $permission, $result, $owner='foo') {
$mapper = null;
$board = new Board();
$board->setId($boardId);
$board->setOwner($owner);
if ($boardId === null) {
$this->boardMapper->expects($this->any())->method('find')->willThrowException(new DoesNotExistException('not found'));
} else {
$this->boardMapper->expects($this->any())->method('find')->willReturn($board);
}
$acls = $this->getAcls($boardId);
$this->aclMapper->expects($this->any())->method('findAll')->willReturn($acls);
if($result) {
$actual = $this->service->checkPermission($mapper, 1234, $permission);
$this->assertTrue($actual);
} else {
$this->expectException(NoPermissionException::class);
$this->service->checkPermission($mapper, 1234, $permission);
}
if ($result) {
$actual = $this->service->checkPermission($mapper, 1234, $permission);
$this->assertTrue($actual);
} else {
$this->expectException(NoPermissionException::class);
$this->service->checkPermission($mapper, 1234, $permission);
}
}
}
public function testCheckPermissionNotFound() {
$mapper = $this->getMockBuilder(IPermissionMapper::class)->getMock();
$mapper->expects($this->once())->method('findBoardId')->willThrowException(new NoPermissionException(null));
public function testCheckPermissionNotFound() {
$mapper = $this->getMockBuilder(IPermissionMapper::class)->getMock();
$mapper->expects($this->once())->method('findBoardId')->willThrowException(new NoPermissionException(null));
$this->expectException(NoPermissionException::class);
$this->service->checkPermission($mapper, 1234, Acl::PERMISSION_READ);
}
$this->service->checkPermission($mapper, 1234, Acl::PERMISSION_READ);
}
private function generateAcl($boardId, $type, $participant, $edit, $manage, $share) {
$acl = new Acl();
$acl->setParticipant($participant);
$acl->setBoardId($boardId);
$acl->setType($type);
$acl->setPermissionEdit($edit);
$acl->setPermissionShare($share);
$acl->setPermissionManage($manage);
return $acl;
}
private function generateAcl($boardId, $type, $participant, $edit, $manage, $share) {
$acl = new Acl();
$acl->setParticipant($participant);
$acl->setBoardId($boardId);
$acl->setType($type);
$acl->setPermissionEdit($edit);
$acl->setPermissionShare($share);
$acl->setPermissionManage($manage);
return $acl;
}
private function getAcls($boardId) {
$acls = [
$this->generateAcl(1, 'user', 'admin', false, false, false),
$this->generateAcl(2, 'user', 'admin', true, false, false),
$this->generateAcl(3, 'user', 'admin', false, true, false),
$this->generateAcl(4, 'user', 'admin', false, false, true),
$this->generateAcl(5, 'group', 'admin', false, false, false),
$this->generateAcl(6, 'user', 'foo', false, false, false)
];
$result = [];
foreach ($acls as $acl) {
if($acl->getBoardId() === $boardId) {
$result[] = $acl;
}
}
return $result;
}
private function getAcls($boardId) {
$acls = [
$this->generateAcl(1, 'user', 'admin', false, false, false),
$this->generateAcl(2, 'user', 'admin', true, false, false),
$this->generateAcl(3, 'user', 'admin', false, true, false),
$this->generateAcl(4, 'user', 'admin', false, false, true),
$this->generateAcl(5, 'group', 'admin', false, false, false),
$this->generateAcl(6, 'user', 'foo', false, false, false)
];
$result = [];
foreach ($acls as $acl) {
if ($acl->getBoardId() === $boardId) {
$result[] = $acl;
}
}
return $result;
}
public function testFindUsersFail() {
$this->boardMapper->expects($this->once())
@@ -374,5 +372,4 @@ class PermissionServiceTest extends \Test\TestCase {
'user3' => new User($user3),
], $users);
}
}

View File

@@ -23,8 +23,6 @@
namespace OCA\Deck\Service;
use OCA\Deck\Activity\ActivityManager;
use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Card;
@@ -46,17 +44,17 @@ use \Test\TestCase;
*/
class StackServiceTest extends TestCase {
/** @var StackService */
/** @var StackService */
private $stackService;
/** @var \PHPUnit\Framework\MockObject\MockObject|StackMapper */
/** @var \PHPUnit\Framework\MockObject\MockObject|StackMapper */
private $stackMapper;
/** @var \PHPUnit\Framework\MockObject\MockObject|CardMapper */
/** @var \PHPUnit\Framework\MockObject\MockObject|CardMapper */
private $cardMapper;
/** @var \PHPUnit\Framework\MockObject\MockObject|BoardMapper */
/** @var \PHPUnit\Framework\MockObject\MockObject|BoardMapper */
private $boardMapper;
/** @var \PHPUnit\Framework\MockObject\MockObject|LabelMapper */
/** @var \PHPUnit\Framework\MockObject\MockObject|LabelMapper */
private $labelMapper;
/** @var \PHPUnit\Framework\MockObject\MockObject|PermissionService */
/** @var \PHPUnit\Framework\MockObject\MockObject|PermissionService */
private $permissionService;
/** @var AssignedUsersMapper|\PHPUnit\Framework\MockObject\MockObject */
private $assignedUsersMapper;
@@ -105,89 +103,89 @@ class StackServiceTest extends TestCase {
}
public function testFindAll() {
$this->permissionService->expects($this->once())->method('checkPermission');
$this->stackMapper->expects($this->once())->method('findAll')->willReturn($this->getStacks());
$this->cardService->expects($this->atLeastOnce())->method('enrich')->will(
$this->permissionService->expects($this->once())->method('checkPermission');
$this->stackMapper->expects($this->once())->method('findAll')->willReturn($this->getStacks());
$this->cardService->expects($this->atLeastOnce())->method('enrich')->will(
$this->returnCallback(
function($card) {
function ($card) {
$card->setLabels($this->getLabels()[$card->getId()]);
}
)
);
$this->cardMapper->expects($this->any())->method('findAll')->willReturn($this->getCards(222));
$this->cardMapper->expects($this->any())->method('findAll')->willReturn($this->getCards(222));
$actual = $this->stackService->findAll(123);
for($stackId=0; $stackId<3; $stackId++) {
for ($cardId=0;$cardId<10;$cardId++) {
$this->assertEquals($actual[0]->getCards()[$cardId]->getId(), $cardId);
$this->assertEquals($actual[0]->getCards()[$cardId]->getStackId(), 222);
$this->assertEquals($actual[0]->getCards()[$cardId]->getLabels(), $this->getLabels()[$cardId]);
}
}
}
$actual = $this->stackService->findAll(123);
for ($stackId=0; $stackId<3; $stackId++) {
for ($cardId=0;$cardId<10;$cardId++) {
$this->assertEquals($actual[0]->getCards()[$cardId]->getId(), $cardId);
$this->assertEquals($actual[0]->getCards()[$cardId]->getStackId(), 222);
$this->assertEquals($actual[0]->getCards()[$cardId]->getLabels(), $this->getLabels()[$cardId]);
}
}
}
public function testFindAllArchived() {
$this->permissionService->expects($this->once())->method('checkPermission');
$this->stackMapper->expects($this->once())->method('findAll')->willReturn($this->getStacks());
$this->labelMapper->expects($this->once())->method('getAssignedLabelsForBoard')->willReturn($this->getLabels());
$this->cardMapper->expects($this->any())->method('findAllArchived')->willReturn($this->getCards(222));
public function testFindAllArchived() {
$this->permissionService->expects($this->once())->method('checkPermission');
$this->stackMapper->expects($this->once())->method('findAll')->willReturn($this->getStacks());
$this->labelMapper->expects($this->once())->method('getAssignedLabelsForBoard')->willReturn($this->getLabels());
$this->cardMapper->expects($this->any())->method('findAllArchived')->willReturn($this->getCards(222));
$actual = $this->stackService->findAllArchived(123);
for($stackId=0; $stackId<3; $stackId++) {
for ($cardId=0;$cardId<10;$cardId++) {
$this->assertEquals($actual[0]->getCards()[$cardId]->getId(), $cardId);
$this->assertEquals($actual[0]->getCards()[$cardId]->getStackId(), 222);
$this->assertEquals($actual[0]->getCards()[$cardId]->getLabels(), $this->getLabels()[$cardId]);
}
}
}
$actual = $this->stackService->findAllArchived(123);
for ($stackId=0; $stackId<3; $stackId++) {
for ($cardId=0;$cardId<10;$cardId++) {
$this->assertEquals($actual[0]->getCards()[$cardId]->getId(), $cardId);
$this->assertEquals($actual[0]->getCards()[$cardId]->getStackId(), 222);
$this->assertEquals($actual[0]->getCards()[$cardId]->getLabels(), $this->getLabels()[$cardId]);
}
}
}
private function getLabels() {
for ($i=0;$i<10;$i++) {
$label1 = new Label();
$label1->setTitle('Important');
$label1->setCardId(1);
$label2 = new Label();
$label2->setTitle('Maybe');
$label2->setCardId(2);
$labels[$i] = [
$label1,
$label2
];
}
return $labels;
}
private function getStacks() {
$s1 = new Stack();
$s1->setId(222);
$s1->setBoardId(1);
$s2 = new Stack();
$s2->setId(223);
$s1->setBoardId(1);
return [$s1, $s2];
}
private function getCards($stackId=0) {
$cards = [];
for ($i=0;$i<10;$i++) {
$cards[$i] = new Card();
$cards[$i]->setId($i);
$cards[$i]->setStackId($stackId);
}
return $cards;
}
private function getLabels() {
for ($i=0;$i<10;$i++) {
$label1 = new Label();
$label1->setTitle('Important');
$label1->setCardId(1);
$label2 = new Label();
$label2->setTitle('Maybe');
$label2->setCardId(2);
$labels[$i] = [
$label1,
$label2
];
}
return $labels;
}
private function getStacks() {
$s1 = new Stack();
$s1->setId(222);
$s1->setBoardId(1);
$s2 = new Stack();
$s2->setId(223);
$s1->setBoardId(1);
return [$s1, $s2];
}
private function getCards($stackId=0) {
$cards = [];
for ($i=0;$i<10;$i++) {
$cards[$i] = new Card();
$cards[$i]->setId($i);
$cards[$i]->setStackId($stackId);
}
return $cards;
}
public function testCreate() {
$this->permissionService->expects($this->once())->method('checkPermission');
$stack = new Stack();
$stack->setId(123);
$stack->setTitle('Foo');
$stack->setBoardId(2);
$stack->setOrder(1);
$this->stackMapper->expects($this->once())->method('insert')->willReturn($stack);
$result = $this->stackService->create('Foo', 2, 1);
$this->assertEquals($stack, $result);
}
public function testCreate() {
$this->permissionService->expects($this->once())->method('checkPermission');
$stack = new Stack();
$stack->setId(123);
$stack->setTitle('Foo');
$stack->setBoardId(2);
$stack->setOrder(1);
$this->stackMapper->expects($this->once())->method('insert')->willReturn($stack);
$result = $this->stackService->create('Foo', 2, 1);
$this->assertEquals($stack, $result);
}
public function testDelete() {
$this->permissionService->expects($this->once())->method('checkPermission');
@@ -199,26 +197,25 @@ class StackServiceTest extends TestCase {
$this->stackService->delete(123);
$this->assertTrue($stackToBeDeleted->getDeletedAt() <= time(), "deletedAt is in the past");
$this->assertTrue($stackToBeDeleted->getDeletedAt() > 0, "deletedAt is set");
}
public function testUpdate() {
$this->permissionService->expects($this->once())->method('checkPermission');
$stack = new Stack();
$this->stackMapper->expects($this->once())->method('find')->willReturn($stack);
$this->stackMapper->expects($this->once())->method('update')->willReturn($stack);
$stack->setId(123);
$stack->setTitle('Foo');
$stack->setBoardId(2);
$stack->setOrder(1);
$result = $this->stackService->update(123, 'Foo', 2, 1, null);
$this->assertEquals($stack, $result);
}
public function testUpdate() {
$this->permissionService->expects($this->once())->method('checkPermission');
$stack = new Stack();
$this->stackMapper->expects($this->once())->method('find')->willReturn($stack);
$this->stackMapper->expects($this->once())->method('update')->willReturn($stack);
$stack->setId(123);
$stack->setTitle('Foo');
$stack->setBoardId(2);
$stack->setOrder(1);
$result = $this->stackService->update(123, 'Foo', 2, 1, null);
$this->assertEquals($stack, $result);
}
/**
* @group DB
*/
public function testReorder() {
public function testReorder() {
$this->permissionService->expects($this->once())->method('checkPermission');
$a = $this->createStack(1, 0);
$b = $this->createStack(2, 1);
@@ -245,5 +242,4 @@ class StackServiceTest extends TestCase {
$stack->setOrder($order);
return $stack;
}
}

View File

@@ -30,143 +30,139 @@ use OCA\Deck\Service\AttachmentService;
use OCA\Deck\Db\Attachment;
class AttachmentApiControllerTest extends \Test\TestCase {
private $appName = 'deck';
private $controller;
private $request;
private $attachmentExample;
private $cardId;
private $attachmentService;
private $appName = 'deck';
private $controller;
private $request;
private $attachmentExample;
private $cardId;
private $attachmentService;
public function setUp(): void {
parent::setUp();
$this->attachmentExample = new Attachment();
$this->attachmentExample->setId(1);
$this->cardId = 1;
$this->request = $this->createMock(IRequest::class);
$this->attachmentService = $this->createMock(AttachmentService::class);
$this->controller = new AttachmentApiController(
$this->appName,
$this->request,
$this->attachmentService
);
}
public function setUp(): void {
parent::setUp();
$this->attachmentExample = new Attachment();
$this->attachmentExample->setId(1);
$this->cardId = 1;
$this->request = $this->createMock(IRequest::class);
$this->attachmentService = $this->createMock(AttachmentService::class);
$this->controller = new AttachmentApiController(
$this->appName,
$this->request,
$this->attachmentService
);
}
public function testGetAll() {
$allAttachments = [$this->attachmentExample];
public function testGetAll() {
$this->attachmentService->expects($this->once())
->method('findAll')
->willReturn($allAttachments);
$allAttachments = [$this->attachmentExample];
$this->request->expects($this->once())
->method('getParam')
->with('cardId')
->willReturn($allAttachments);
$this->attachmentService->expects($this->once())
->method('findAll')
->willReturn($allAttachments);
$expected = new DataResponse($allAttachments, HTTP::STATUS_OK);
$actual = $this->controller->getAll();
$this->assertEquals($expected, $actual);
}
$this->request->expects($this->once())
->method('getParam')
->with('cardId')
->willReturn($allAttachments);
public function testDisplay() {
$this->attachmentService->expects($this->once())
->method('display')
->willReturn($this->attachmentExample);
$expected = new DataResponse($allAttachments, HTTP::STATUS_OK);
$actual = $this->controller->getAll();
$this->assertEquals($expected, $actual);
}
$this->request->expects($this->exactly(2))
->method('getParam')
->withConsecutive(
['cardId'],
['attachmentId']
)->willReturnonConsecutiveCalls(
$this->cardId,
$this->attachmentExample->getId());
public function testDisplay() {
$expected = $this->attachmentExample;
$actual = $this->controller->display();
$this->assertEquals($expected, $actual);
}
$this->attachmentService->expects($this->once())
->method('display')
->willReturn($this->attachmentExample);
public function testCreate() {
$type = 'not null';
$data = ['not null'];
$this->request->expects($this->exactly(2))
->method('getParam')
->withConsecutive(
['cardId'],
['attachmentId']
)->willReturnonConsecutiveCalls(
$this->cardId,
$this->attachmentExample->getId());
$this->attachmentService->expects($this->once())
->method('create')
->willReturn($this->attachmentExample);
$expected = $this->attachmentExample;
$actual = $this->controller->display();
$this->assertEquals($expected, $actual);
}
$this->request->expects($this->once())
->method('getParam')
->with('cardId')
->willReturn($this->cardId);
public function testCreate() {
$expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK);
$actual = $this->controller->create($type, $data);
$this->assertEquals($expected, $actual);
}
$type = 'not null';
$data = ['not null'];
public function testUpdate() {
$this->attachmentService->expects($this->once())
->method('create')
->willReturn($this->attachmentExample);
// FIXME: what is data supposed to be in this context?
$data = ['not empty data'];
$this->request->expects($this->once())
->method('getParam')
->with('cardId')
->willReturn($this->cardId);
$this->attachmentService->expects($this->once())
->method('update')
->willReturn($this->attachmentExample);
$expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK);
$actual = $this->controller->create($type, $data);
$this->assertEquals($expected, $actual);
}
$this->request->expects($this->exactly(2))
->method('getParam')
->withConsecutive(
['cardId'],
['attachmentId']
)->willReturnonConsecutiveCalls(
$this->cardId,
$this->attachmentExample->getId());
public function testUpdate() {
$expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK);
$actual = $this->controller->update($data);
$this->assertEquals($expected, $actual);
}
// FIXME: what is data supposed to be in this context?
$data = ['not empty data'];
public function testDelete() {
$this->attachmentService->expects($this->once())
->method('delete')
->willReturn($this->attachmentExample);
$this->attachmentService->expects($this->once())
->method('update')
->willReturn($this->attachmentExample);
$this->request->expects($this->exactly(2))
->method('getParam')
->withConsecutive(
['cardId'],
['attachmentId']
)->willReturnonConsecutiveCalls(
$this->cardId,
$this->attachmentExample->getId());
$this->request->expects($this->exactly(2))
->method('getParam')
->withConsecutive(
['cardId'],
['attachmentId']
)->willReturnonConsecutiveCalls(
$this->cardId,
$this->attachmentExample->getId());
$expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK);
$actual = $this->controller->delete();
$this->assertEquals($expected, $actual);
}
$expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK);
$actual = $this->controller->update($data);
$this->assertEquals($expected, $actual);
}
public function testRestore() {
$this->attachmentService->expects($this->once())
->method('restore')
->willReturn($this->attachmentExample);
public function testDelete() {
$this->attachmentService->expects($this->once())
->method('delete')
->willReturn($this->attachmentExample);
$this->request->expects($this->exactly(2))
->method('getParam')
->withConsecutive(
['cardId'],
['attachmentId']
)->willReturnonConsecutiveCalls(
$this->cardId,
$this->attachmentExample->getId());
$this->request->expects($this->exactly(2))
->method('getParam')
->withConsecutive(
['cardId'],
['attachmentId']
)->willReturnonConsecutiveCalls(
$this->cardId,
$this->attachmentExample->getId());
$expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK);
$actual = $this->controller->delete();
$this->assertEquals($expected, $actual);
}
public function testRestore() {
$this->attachmentService->expects($this->once())
->method('restore')
->willReturn($this->attachmentExample);
$this->request->expects($this->exactly(2))
->method('getParam')
->withConsecutive(
['cardId'],
['attachmentId']
)->willReturnonConsecutiveCalls(
$this->cardId,
$this->attachmentExample->getId());
$expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK);
$actual = $this->controller->restore();
$this->assertEquals($expected, $actual);
}
$expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK);
$actual = $this->controller->restore();
$this->assertEquals($expected, $actual);
}
}

View File

@@ -23,21 +23,17 @@
namespace OCA\Deck\Controller;
use OCA\Deck\Db\Acl;
use OCA\Deck\Service\AttachmentService;
use OCA\Deck\Service\CardService;
use OCA\Deck\Service\LabelService;
use OCA\Deck\Service\StackService;
use OCP\AppFramework\Controller;
use OCP\IRequest;
class AttachmentControllerTest extends \Test\TestCase {
/** @var Controller|\PHPUnit\Framework\MockObject\MockObject */
/** @var Controller|\PHPUnit\Framework\MockObject\MockObject */
private $controller;
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
private $request;
/** @var AttachmentService|\PHPUnit\Framework\MockObject\MockObject */
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
private $request;
/** @var AttachmentService|\PHPUnit\Framework\MockObject\MockObject */
private $attachmentService;
/** @var string */
private $userId = 'user';
@@ -49,19 +45,19 @@ class AttachmentControllerTest extends \Test\TestCase {
'deck',
$this->request,
$this->attachmentService,
$this->userId
);
$this->userId
);
}
public function testGetAll() {
$this->attachmentService->expects($this->once())->method('findAll')->with(1);
$this->controller->getAll(1);
}
public function testGetAll() {
$this->attachmentService->expects($this->once())->method('findAll')->with(1);
$this->controller->getAll(1);
}
public function testDisplay() {
$this->attachmentService->expects($this->once())->method('display')->with(1, 2);
$this->controller->display(1, 2);
}
public function testDisplay() {
$this->attachmentService->expects($this->once())->method('display')->with(1, 2);
$this->controller->display(1, 2);
}
public function testCreate() {
$this->request->expects($this->exactly(2))
@@ -101,5 +97,4 @@ class AttachmentControllerTest extends \Test\TestCase {
->willReturn(1);
$this->assertEquals(1, $this->controller->restore(123, 234));
}
}

View File

@@ -30,7 +30,6 @@ use OCA\Deck\Service\BoardService;
use OCA\Deck\Db\Board;
class BoardApiControllerTest extends \Test\TestCase {
private $appName = 'deck';
private $userId = 'admin';
private $controller;

View File

@@ -27,7 +27,6 @@ use OCA\Deck\Db\Acl;
use OCP\IUser;
class BoardControllerTest extends \Test\TestCase {
private $controller;
private $request;
private $userManager;

View File

@@ -31,7 +31,6 @@ use OCA\Deck\Db\Card;
use OCA\Deck\Service\CardService;
class CardApiControllerTest extends \Test\TestCase {
private $controller;
private $request;
private $cardService;
@@ -50,7 +49,7 @@ class CardApiControllerTest extends \Test\TestCase {
$this->cardExample['id'] = 1;
$this->stackExample['id'] = 1;
$this->controller = new CardApiController (
$this->controller = new CardApiController(
$appName = 'deck',
$this->request,
$this->cardService,
@@ -78,7 +77,6 @@ class CardApiControllerTest extends \Test\TestCase {
}
public function testCreate() {
$card = new Card();
$card->setId($this->cardExample['id']);
$card->setStackId($this->stackExample['id']);
@@ -121,7 +119,6 @@ class CardApiControllerTest extends \Test\TestCase {
}
public function testDelete() {
$card = new Card();
$card->setId($this->cardExample['id']);
@@ -138,5 +135,4 @@ class CardApiControllerTest extends \Test\TestCase {
$actual = $this->controller->delete();
$this->assertEquals($expected, $actual);
}
}

View File

@@ -31,11 +31,11 @@ use Test\TestCase;
class CardControllerTest extends TestCase {
/** @var CardController|MockObject */
/** @var CardController|MockObject */
private $controller;
/** @var IRequest|MockObject */
private $request;
/** @var CardService|MockObject */
/** @var IRequest|MockObject */
private $request;
/** @var CardService|MockObject */
private $cardService;
/** @var AssignmentService|MockObject */
private $assignmentService;
@@ -89,31 +89,31 @@ class CardControllerTest extends TestCase {
}
public function testArchive() {
$this->cardService->expects($this->once())->method('archive')->willReturn(true);
$this->controller->archive(1);
}
public function testUnarchive() {
$this->cardService->expects($this->once())->method('unarchive');
$this->controller->unarchive(1);
}
public function testAssignLabel() {
$this->cardService->expects($this->once())->method('assignLabel');
$this->controller->assignLabel(1,2);
}
public function testRemoveLabel() {
$this->cardService->expects($this->once())->method('removeLabel');
$this->controller->removeLabel(1,2);
}
$this->cardService->expects($this->once())->method('archive')->willReturn(true);
$this->controller->archive(1);
}
public function testUnarchive() {
$this->cardService->expects($this->once())->method('unarchive');
$this->controller->unarchive(1);
}
public function testAssignLabel() {
$this->cardService->expects($this->once())->method('assignLabel');
$this->controller->assignLabel(1,2);
}
public function testRemoveLabel() {
$this->cardService->expects($this->once())->method('removeLabel');
$this->controller->removeLabel(1,2);
}
public function testReorder() {
$this->cardService->expects($this->once())->method('reorder');
$this->controller->reorder(1, 2, 3);
}
public function testReorder() {
$this->cardService->expects($this->once())->method('reorder');
$this->controller->reorder(1, 2, 3);
}
public function testRename() {
$this->cardService->expects($this->once())->method('rename');
$this->controller->rename(1, 'test');
}
public function testRename() {
$this->cardService->expects($this->once())->method('rename');
$this->controller->rename(1, 'test');
}
public function testAssignUser() {
$this->assignmentService->expects($this->once())->method('assignUser');
@@ -124,5 +124,4 @@ class CardControllerTest extends TestCase {
$this->assignmentService->expects($this->once())->method('unassignUser');
$this->controller->unassignUser(1, 'admin');
}
}

View File

@@ -30,7 +30,6 @@ use OCA\Deck\Db\Label;
use OCA\Deck\Service\LabelService;
class LabelApiControllerTest extends \Test\TestCase {
private $controller;
private $request;
private $labelService;
@@ -69,7 +68,6 @@ class LabelApiControllerTest extends \Test\TestCase {
}
public function testCreate() {
$label = new Label();
$label->setId($this->exampleLabel['id']);
@@ -88,7 +86,6 @@ class LabelApiControllerTest extends \Test\TestCase {
}
public function testUpdate() {
$label = new Label();
$label->setId($this->exampleLabel['id']);
@@ -107,7 +104,6 @@ class LabelApiControllerTest extends \Test\TestCase {
}
public function testDelete() {
$label = new Label();
$label->setId($this->exampleLabel['id']);
@@ -124,5 +120,4 @@ class LabelApiControllerTest extends \Test\TestCase {
$actual = $this->controller->delete();
$this->assertEquals($expected, $actual);
}
}

View File

@@ -23,19 +23,17 @@
namespace OCA\Deck\Controller;
use OCA\Deck\Db\Acl;
use OCA\Deck\Service\CardService;
use OCA\Deck\Service\LabelService;
use OCP\AppFramework\Controller;
use OCP\IRequest;
class LabelControllerTest extends \Test\TestCase {
/** @var Controller|\PHPUnit\Framework\MockObject\MockObject */
/** @var Controller|\PHPUnit\Framework\MockObject\MockObject */
private $controller;
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
private $request;
/** @var LabelService|\PHPUnit\Framework\MockObject\MockObject */
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
private $request;
/** @var LabelService|\PHPUnit\Framework\MockObject\MockObject */
private $labelService;
/** @var string */
private $userId = 'user';
@@ -53,7 +51,7 @@ class LabelControllerTest extends \Test\TestCase {
'deck',
$this->request,
$this->labelService
);
);
}
@@ -80,5 +78,4 @@ class LabelControllerTest extends \Test\TestCase {
->willReturn(1);
$this->assertEquals(1, $this->controller->delete(123));
}
}

View File

@@ -28,13 +28,10 @@ use OCA\Deck\Service\PermissionService;
use OCP\IInitialStateService;
use OCP\IL10N;
use OCP\IRequest;
use PHPUnit_Framework_TestCase;
use OCA\Deck\Service\DefaultBoardService;
use OCA\Deck\Db\Board;
use OCP\IConfig;
class PageControllerTest extends \Test\TestCase {
private $controller;
private $request;
private $l10n;
@@ -56,7 +53,6 @@ class PageControllerTest extends \Test\TestCase {
}
public function testIndex() {
$board = new Board();
$board->setTitle('Personal');
$board->setOwner($this->userId);
@@ -69,5 +65,4 @@ class PageControllerTest extends \Test\TestCase {
$response = $this->controller->index();
$this->assertEquals('main', $response->getTemplateName());
}
}

View File

@@ -28,11 +28,9 @@ use OCP\IRequest;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\StackService;
use OCA\Deck\Db\Board;
use OCA\Deck\Db\Stack;
class StackApiControllerTest extends \Test\TestCase {
private $appName = 'deck';
private $userId = 'admin';
private $controller;
@@ -104,7 +102,6 @@ class StackApiControllerTest extends \Test\TestCase {
}
public function testCreate() {
$this->request->expects($this->any())
->method('getParam')
->with('boardId')
@@ -126,7 +123,6 @@ class StackApiControllerTest extends \Test\TestCase {
}
public function testUpdate() {
$this->request->expects($this->exactly(2))
->method('getParam')
->withConsecutive(
@@ -151,7 +147,6 @@ class StackApiControllerTest extends \Test\TestCase {
}
public function testDelete() {
$stack = new Stack();
$stack->setId($this->exampleStack['id']);
$stack->setBoardId($this->exampleStack['boardId']);

View File

@@ -23,20 +23,17 @@
namespace OCA\Deck\Controller;
use OCA\Deck\Db\Acl;
use OCA\Deck\Service\CardService;
use OCA\Deck\Service\LabelService;
use OCA\Deck\Service\StackService;
use OCP\AppFramework\Controller;
use OCP\IRequest;
class StackControllerTest extends \Test\TestCase {
/** @var Controller|\PHPUnit\Framework\MockObject\MockObject */
/** @var Controller|\PHPUnit\Framework\MockObject\MockObject */
private $controller;
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
private $request;
/** @var StackService|\PHPUnit\Framework\MockObject\MockObject */
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
private $request;
/** @var StackService|\PHPUnit\Framework\MockObject\MockObject */
private $stackService;
/** @var string */
private $userId = 'user';
@@ -54,19 +51,19 @@ class StackControllerTest extends \Test\TestCase {
'deck',
$this->request,
$this->stackService,
$this->userId
);
$this->userId
);
}
public function testIndex() {
$this->stackService->expects($this->once())->method('findAll');
$this->controller->index(1);
}
public function testIndex() {
$this->stackService->expects($this->once())->method('findAll');
$this->controller->index(1);
}
public function testArchived() {
$this->stackService->expects($this->once())->method('findAllArchived');
$this->controller->archived(1);
}
public function testArchived() {
$this->stackService->expects($this->once())->method('findAllArchived');
$this->controller->archived(1);
}
public function testCreate() {
$this->stackService->expects($this->once())
@@ -99,5 +96,4 @@ class StackControllerTest extends \Test\TestCase {
->willReturn(1);
$this->assertEquals(1, $this->controller->delete(123));
}
}