Add tests for entities
This commit is contained in:
9
Makefile
9
Makefile
@@ -169,9 +169,10 @@ ifeq (, $(shell which phpunit 2> /dev/null))
|
||||
@echo "No phpunit command available, downloading a copy from the web"
|
||||
mkdir -p $(build_tools_directory)
|
||||
curl -sSL https://phar.phpunit.de/phpunit.phar -o $(build_tools_directory)/phpunit.phar
|
||||
php $(build_tools_directory)/phpunit.phar -c phpunit.xml
|
||||
php $(build_tools_directory)/phpunit.phar -c phpunit.integration.xml
|
||||
php $(build_tools_directory)/phpunit.phar -c phpunit.xml --coverage-clover build/php-unit.clover --coverage-html build/html/
|
||||
php $(build_tools_directory)/phpunit.phar -c phpunit.integration.xml --coverage-clover build/php-unit.clover --coverage-html build/html/
|
||||
|
||||
else
|
||||
phpunit -c phpunit.xml
|
||||
phpunit -c phpunit.integration.xml
|
||||
phpunit -c phpunit.xml --coverage-clover build/php-unit.clover.xml --coverage-html build/html
|
||||
phpunit -c phpunit.integration.xml --coverage-clover build/php-unit.integration.clover.xml --coverage-html build/html-integration
|
||||
endif
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
use JsonSerializable;
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
|
||||
class Stack extends Entity implements JsonSerializable {
|
||||
|
||||
|
||||
@@ -4,4 +4,9 @@
|
||||
<directory>./tests/unit</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">./</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
88
tests/unit/Db/AclTest.php
Normal file
88
tests/unit/Db/AclTest.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 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;
|
||||
|
||||
class AclTest extends \PHPUnit_Framework_TestCase {
|
||||
private function createAclUser() {
|
||||
$acl = new Acl();
|
||||
$acl->setId(1);
|
||||
$acl->setParticipant("admin");
|
||||
$acl->setType("user");
|
||||
$acl->setBoardId(1);
|
||||
$acl->setPermissionWrite(1);
|
||||
$acl->setPermissionInvite(1);
|
||||
$acl->setPermissionManage(1);
|
||||
return $acl;
|
||||
}
|
||||
private function createAclGroup() {
|
||||
$acl = new Acl();
|
||||
$acl->setId(1);
|
||||
$acl->setParticipant("administrators");
|
||||
$acl->setType("group");
|
||||
$acl->setBoardId(1);
|
||||
$acl->setPermissionWrite(1);
|
||||
$acl->setPermissionInvite(1);
|
||||
$acl->setPermissionManage(1);
|
||||
return $acl;
|
||||
}
|
||||
public function testJsonSerialize() {
|
||||
$acl = $this->createAclUser();
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'participant' => 'admin',
|
||||
'type' => 'user',
|
||||
'boardId' => 1,
|
||||
'permissionWrite' => 1,
|
||||
'permissionInvite' => 1,
|
||||
'permissionManage' => 1,
|
||||
'owner' => 0
|
||||
], $acl->jsonSerialize());
|
||||
$acl = $this->createAclGroup();
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'participant' => 'administrators',
|
||||
'type' => 'group',
|
||||
'boardId' => 1,
|
||||
'permissionWrite' => 1,
|
||||
'permissionInvite' => 1,
|
||||
'permissionManage' => 1,
|
||||
'owner' => 0
|
||||
], $acl->jsonSerialize());
|
||||
}
|
||||
public function testSetOwner() {
|
||||
$acl = $this->createAclUser();
|
||||
$acl->setOwner(1);
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'participant' => 'admin',
|
||||
'type' => 'user',
|
||||
'boardId' => 1,
|
||||
'permissionWrite' => 1,
|
||||
'permissionInvite' => 1,
|
||||
'permissionManage' => 1,
|
||||
'owner' => 1
|
||||
], $acl->jsonSerialize());
|
||||
}
|
||||
|
||||
}
|
||||
61
tests/unit/Db/BoardTest.php
Normal file
61
tests/unit/Db/BoardTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
class BoardTest extends \PHPUnit_Framework_TestCase {
|
||||
private function createBoard() {
|
||||
$board = new Board();
|
||||
$board->setId(1);
|
||||
$board->setTitle("My Board");
|
||||
$board->setOwner("admin");
|
||||
$board->setColor("000000");
|
||||
$board->setArchived(false);
|
||||
// TODO: relation shared labels acl
|
||||
return $board;
|
||||
}
|
||||
public function testJsonSerialize() {
|
||||
$board = $this->createBoard();
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'title' => "My Board",
|
||||
'owner' => "admin",
|
||||
'color' => "000000",
|
||||
'labels' => null,
|
||||
'acl' => null
|
||||
], $board->jsonSerialize());
|
||||
}
|
||||
|
||||
public function testSetLabels() {
|
||||
$board = $this->createBoard();
|
||||
$board->setLabels(array("foo", "bar"));
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'title' => "My Board",
|
||||
'owner' => "admin",
|
||||
'color' => "000000",
|
||||
'labels' => array("foo", "bar"),
|
||||
'acl' => null
|
||||
], $board->jsonSerialize());
|
||||
}
|
||||
public function testSetAcl() {
|
||||
$acl = new Acl();
|
||||
$acl->setId(1);
|
||||
$board = $this->createBoard();
|
||||
$board->setAcl(array($acl));
|
||||
$result = $board->getAcl()[1];
|
||||
$this->assertEquals($acl, $result);
|
||||
}
|
||||
public function testSetShared() {
|
||||
$board = $this->createBoard();
|
||||
$board->setShared(1);
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'title' => "My Board",
|
||||
'owner' => "admin",
|
||||
'color' => "000000",
|
||||
'labels' => null,
|
||||
'acl' => null,
|
||||
'shared' => 1,
|
||||
], $board->jsonSerialize());
|
||||
}
|
||||
}
|
||||
76
tests/unit/Db/CardTest.php
Normal file
76
tests/unit/Db/CardTest.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 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;
|
||||
|
||||
class CardTest extends \PHPUnit_Framework_TestCase {
|
||||
private function createCard() {
|
||||
$card = new Card();
|
||||
$card->setId(1);
|
||||
$card->setTitle("My Card");
|
||||
$card->setDescription("a long description");
|
||||
$card->setStackId(1);
|
||||
$card->setType('text');
|
||||
$card->setLastModified(234);
|
||||
$card->setCreatedAt(123);
|
||||
$card->setOwner("admin");
|
||||
$card->setOrder(12);
|
||||
$card->setArchived(false);
|
||||
// TODO: relation shared labels acl
|
||||
return $card;
|
||||
}
|
||||
public function testJsonSerialize() {
|
||||
$card = $this->createCard();
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'title' => "My Card",
|
||||
'description' => "a long description",
|
||||
'type' => 'text',
|
||||
'lastModified' => 234,
|
||||
'createdAt' => 123,
|
||||
'owner' => 'admin',
|
||||
'order' => 12,
|
||||
'stackId' => 1,
|
||||
'labels' => null,
|
||||
'archived' => false,
|
||||
], $card->jsonSerialize());
|
||||
}
|
||||
public function testJsonSerializeLabels() {
|
||||
$card = $this->createCard();
|
||||
$card->setLabels(array());
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'title' => "My Card",
|
||||
'description' => "a long description",
|
||||
'type' => 'text',
|
||||
'lastModified' => 234,
|
||||
'createdAt' => 123,
|
||||
'owner' => 'admin',
|
||||
'order' => 12,
|
||||
'stackId' => 1,
|
||||
'labels' => array(),
|
||||
'archived' => false,
|
||||
], $card->jsonSerialize());
|
||||
}
|
||||
|
||||
}
|
||||
43
tests/unit/Db/EntityTest.php
Normal file
43
tests/unit/Db/EntityTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 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;
|
||||
|
||||
class EntityTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testRelation() {
|
||||
$entity = new Entity();
|
||||
$entity->foo = null;
|
||||
$entity->addRelation('foo');
|
||||
$entity->setFoo('test');
|
||||
$this->assertEquals([], $entity->getUpdatedFields());
|
||||
}
|
||||
|
||||
public function testWithoutRelation() {
|
||||
$entity = new Entity();
|
||||
$entity->foo = null;
|
||||
$entity->setFoo('test');
|
||||
$this->assertEquals(['foo'=>true], $entity->getUpdatedFields());
|
||||
}
|
||||
|
||||
}
|
||||
60
tests/unit/Db/LabelTest.php
Normal file
60
tests/unit/Db/LabelTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 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;
|
||||
|
||||
class LabelTest extends \PHPUnit_Framework_TestCase {
|
||||
private function createLabel() {
|
||||
$label = new Label();
|
||||
$label->setId(1);
|
||||
$label->setTitle("My Label");
|
||||
$label->setColor("000000");
|
||||
return $label;
|
||||
}
|
||||
public function testJsonSerializeBoard() {
|
||||
$label = $this->createLabel();
|
||||
$label->setBoardId(123);
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'title' => 'My Label',
|
||||
'boardId' => 123,
|
||||
'cardId' => null,
|
||||
'color' => '000000'
|
||||
], $label->jsonSerialize());
|
||||
|
||||
}
|
||||
public function testJsonSerializeCard() {
|
||||
$label = $this->createLabel();
|
||||
$label->setCardId(123);
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'title' => 'My Label',
|
||||
'boardId' => null,
|
||||
'cardId' => 123,
|
||||
'color' => '000000'
|
||||
], $label->jsonSerialize());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
57
tests/unit/Db/StackTest.php
Normal file
57
tests/unit/Db/StackTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 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;
|
||||
|
||||
class StackTest extends \PHPUnit_Framework_TestCase {
|
||||
private function createStack() {
|
||||
$board = new Stack();
|
||||
$board->setId(1);
|
||||
$board->setTitle("My Stack");
|
||||
$board->setBoardId(1);
|
||||
$board->setOrder(1);
|
||||
return $board;
|
||||
}
|
||||
public function testJsonSerialize() {
|
||||
$board = $this->createStack();
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'title' => "My Stack",
|
||||
'order' => 1,
|
||||
'boardId' => 1,
|
||||
'cards' => array(),
|
||||
], $board->jsonSerialize());
|
||||
}
|
||||
public function testJsonSerializeWithCards() {
|
||||
$cards = array("foo", "bar");
|
||||
$board = $this->createStack();
|
||||
$board->setCards($cards);
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'title' => "My Stack",
|
||||
'order' => 1,
|
||||
'boardId' => 1,
|
||||
'cards' => array("foo", "bar"),
|
||||
], $board->jsonSerialize());
|
||||
}
|
||||
}
|
||||
57
tests/unit/controller/BoardControllerTest.php
Normal file
57
tests/unit/controller/BoardControllerTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 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\Controller;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
class BoardControllerTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $controller;
|
||||
private $request;
|
||||
private $l10n;
|
||||
private $userId = 'john';
|
||||
|
||||
public function setUp() {
|
||||
$this->l10n = $this->request = $this->getMockBuilder(
|
||||
'\OCP\IL10n')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->request = $this->getMockBuilder(
|
||||
'\OCP\IRequest')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->controller = new PageController(
|
||||
'deck', $this->request, $this->l10n, $this->userId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testIndex() {
|
||||
$response = $this->controller->index();
|
||||
$this->assertEquals('main', $response->getTemplateName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user