Add more unit testing

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2017-05-29 00:08:22 +02:00
parent 57f74c98db
commit 19a90809f9
12 changed files with 317 additions and 10 deletions

View File

@@ -23,6 +23,7 @@
namespace OCA\Deck\Db;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUserManager;
use Test\AppFramework\Db\MapperTestUtility;
@@ -32,10 +33,15 @@ use Test\AppFramework\Db\MapperTestUtility;
*/
class BoardMapperTest extends MapperTestUtility {
/** @var IDBConnection */
private $dbConnection;
/** @var AclMapper|\PHPUnit_Framework_MockObject_MockObject */
private $aclMapper;
/** @var BoardMapper */
private $boardMapper;
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
private $groupManager;
// Data
@@ -96,7 +102,6 @@ class BoardMapperTest extends MapperTestUtility {
$board = new Board();
$board->setTitle($title);
$board->setOwner($owner);
$board->setShared(1);
return $board;
}
@@ -122,11 +127,31 @@ class BoardMapperTest extends MapperTestUtility {
}
}
public function testFindAll() {
$actual = $this->boardMapper->findAll();
$this->assertAttributeEquals($this->boards[0]->getId(), 'id', $actual[0]);
$this->assertAttributeEquals($this->boards[1]->getId(), 'id', $actual[1]);
$this->assertAttributeEquals($this->boards[2]->getId(), 'id', $actual[2]);
}
public function testFindAllToDelete() {
$this->boards[0]->setDeletedAt(1);
$this->boards[0] = $this->boardMapper->update($this->boards[0]);
$actual = $this->boardMapper->findToDelete();
$this->boards[0]->resetUpdatedFields();
$this->assertEquals([$this->boards[0]], $actual);
$this->boards[0]->setDeletedAt(0);
$this->boardMapper->update($this->boards[0]);
}
public function testFindWithLabels() {
$actual = $this->boardMapper->find($this->boards[0]->getId(), true, false);
$expected = $this->boards[0];
$this->assertEquals($expected, $actual);
}
public function testFindWithAcl() {
$actual = $this->boardMapper->find($this->boards[0]->getId(), false, true);
$expected = [

View File

@@ -2,7 +2,9 @@
namespace OCA\Deck\Db;
class BoardTest extends \PHPUnit_Framework_TestCase {
use PHPUnit\Framework\TestCase;
class BoardTest extends TestCase {
private function createBoard() {
$board = new Board();
$board->setId(1);

View File

@@ -0,0 +1,58 @@
<?php
/**
* @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
*
* @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 OCP\IGroup;
class GroupTest extends \Test\TestCase {
public function testGroupObjectSerialize() {
/** @var IGroup $group */
$group = $this->createMock(IGroup::class);
$group->expects($this->any())
->method('getGID')
->willReturn('mygroup');
$groupRelationalObject = new Group($group);
$expected = [
'uid' => 'mygroup',
'displayname' => 'mygroup'
];
$this->assertEquals($expected, $groupRelationalObject->getObjectSerialization());
}
public function testGroupJSONSerialize() {
/** @var IGroup $group */
$group = $this->createMock(IGroup::class);
$group->expects($this->any())
->method('getGID')
->willReturn('mygroup');
$groupRelationalObject = new Group($group);
$expected = [
'uid' => 'mygroup',
'displayname' => 'mygroup',
'primaryKey' => 'mygroup'
];
$this->assertEquals($expected, $groupRelationalObject->jsonSerialize());
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
*
* @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 OCP\IUser;
class UserTest extends \Test\TestCase {
public function testGroupObjectSerialize() {
/** @var IUser $user */
$user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->willReturn('myuser');
$user->expects($this->any())
->method('getDisplayName')
->willReturn('myuser displayname');
$userRelationalObject = new User($user);
$expected = [
'uid' => 'myuser',
'displayname' => 'myuser displayname'
];
$this->assertEquals($expected, $userRelationalObject->getObjectSerialization());
}
public function testGroupJSONSerialize() {
/** @var IUser $user */
$user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->willReturn('myuser');
$user->expects($this->any())
->method('getDisplayName')
->willReturn('myuser displayname');
$userRelationalObject = new User($user);
$expected = [
'uid' => 'myuser',
'displayname' => 'myuser displayname',
'primaryKey' => 'myuser'
];
$this->assertEquals($expected, $userRelationalObject->jsonSerialize());
}
}