diff options
author | Kai Schröer <splitt3r@users.noreply.github.com> | 2017-11-07 17:43:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-07 17:43:45 +0300 |
commit | 6e11d77656cbc9387f275d0b71de73fbafda16fa (patch) | |
tree | 5effb3b584aac3e61f68ae0bf7377b3f9aac0d9d /tests/Unit | |
parent | 12511a1ba45a0ba457af48a8b26d8cb271ad0827 (diff) |
Added Unit tests (#224)
* Added first unit test
* Fixed user constraint problem
* Fix tests
* Update CommentMapperTest.php
* Fixed FactoryMuffin + unit tests
* Fixed PHP 5.6 error
* Started adding scrutinizer coverage
* Added UnitTestCase class
* Added badges to README
* Changed app logo name
The icon is showing up in the app list now.
* Added screenshot replacement to Makefile
* Added oC branded screenshots
* Added test skeletons
* Added further factories
* Added all basic crud unit tests
* Fixed @depends in unit tests
* Small doc block update
Diffstat (limited to 'tests/Unit')
-rw-r--r-- | tests/Unit/Controller/PageControllerTest.php | 18 | ||||
-rw-r--r-- | tests/Unit/Db/CommentMapperTest.php | 97 | ||||
-rw-r--r-- | tests/Unit/Db/DateMapperTest.php | 97 | ||||
-rw-r--r-- | tests/Unit/Db/EventMapperTest.php | 87 | ||||
-rw-r--r-- | tests/Unit/Db/NotificationMapperTest.php | 97 | ||||
-rw-r--r-- | tests/Unit/Db/ParticipationMapperTest.php | 97 | ||||
-rw-r--r-- | tests/Unit/Db/ParticipationTextMapperTest.php | 97 | ||||
-rw-r--r-- | tests/Unit/Db/TextMapperTest.php | 97 | ||||
-rw-r--r-- | tests/Unit/Factories/CommentFactory.php | 36 | ||||
-rw-r--r-- | tests/Unit/Factories/DateFactory.php | 32 | ||||
-rw-r--r-- | tests/Unit/Factories/EventFactory.php | 46 | ||||
-rw-r--r-- | tests/Unit/Factories/NotificationFactory.php | 31 | ||||
-rw-r--r-- | tests/Unit/Factories/ParticipationFactory.php | 36 | ||||
-rw-r--r-- | tests/Unit/Factories/ParticipationTextFactory.php | 33 | ||||
-rw-r--r-- | tests/Unit/Factories/TextFactory.php | 31 | ||||
-rw-r--r-- | tests/Unit/UnitTestCase.php | 42 |
16 files changed, 969 insertions, 5 deletions
diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index 9090d0cf..302d44fe 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -1,8 +1,8 @@ <?php /** - * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com> + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> * - * @author Kai Schröer <kai@schroeer.co> + * @author Kai Schröer <git@schroeer.co> * * @license GNU AGPL version 3 or any later version * @@ -24,14 +24,19 @@ namespace OCA\Polls\Tests\Unit\Controller; use OCA\Polls\Controller\PageController; +use OCA\Polls\Tests\Unit\UnitTestCase; use OCP\AppFramework\Http\TemplateResponse; -use PHPUnit_Framework_TestCase; -class PageControllerTest extends PHPUnit_Framework_TestCase { +class PageControllerTest extends UnitTestCase { + /** @var PageController */ private $controller; + private $userId = 'john'; + /** + * {@inheritDoc} + */ public function setUp() { $request = $this->getMockBuilder('OCP\IRequest') ->disableOriginalConstructor() @@ -96,10 +101,13 @@ class PageControllerTest extends PHPUnit_Framework_TestCase { ); } + /** + * Basic controller index route test. + */ public function testIndex() { $result = $this->controller->index(); $this->assertEquals('main.tmpl', $result->getTemplateName()); - $this->assertTrue($result instanceof TemplateResponse); + $this->assertInstanceOf(TemplateResponse::class, $result); } } diff --git a/tests/Unit/Db/CommentMapperTest.php b/tests/Unit/Db/CommentMapperTest.php new file mode 100644 index 00000000..7cd845dd --- /dev/null +++ b/tests/Unit/Db/CommentMapperTest.php @@ -0,0 +1,97 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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\Polls\Tests\Unit\Db; + +use OCA\Polls\Db\Comment; +use OCA\Polls\Db\CommentMapper; +use OCA\Polls\Db\Event; +use OCA\Polls\Db\EventMapper; +use OCA\Polls\Tests\Unit\UnitTestCase; +use OCP\IDBConnection; +use League\FactoryMuffin\Faker\Facade as Faker; + +class CommentMapperTest extends UnitTestCase { + + /** @var IDBConnection */ + private $con; + /** @var CommentMapper */ + private $commentMapper; + /** @var EventMapper */ + private $eventMapper; + + /** + * {@inheritDoc} + */ + public function setUp() { + parent::setUp(); + $this->con = \OC::$server->getDatabaseConnection(); + $this->commentMapper = new CommentMapper($this->con); + $this->eventMapper = new EventMapper($this->con); + } + + /** + * Create some fake data and persist them to the database. + * + * @return Comment + */ + public function testCreate() { + /** @var Event $event */ + $event = $this->fm->instance('OCA\Polls\Db\Event'); + $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); + + /** @var Comment $comment */ + $comment = $this->fm->instance('OCA\Polls\Db\Comment'); + $comment->setPollId($event->getId()); + $this->assertInstanceOf(Comment::class, $this->commentMapper->insert($comment)); + + return $comment; + } + + /** + * Update the previously created entry and persist the changes. + * + * @depends testCreate + * @param Comment $comment + * @return Comment + */ + public function testUpdate(Comment $comment) { + $newComment = Faker::paragraph(); + $comment->setComment($newComment()); + $this->commentMapper->update($comment); + + return $comment; + } + + /** + * Delete the previously created entries from the database. + * + * @depends testUpdate + * @param Comment $comment + */ + public function testDelete(Comment $comment) { + $event = $this->eventMapper->find($comment->getPollId()); + $this->commentMapper->delete($comment); + $this->eventMapper->delete($event); + } +} diff --git a/tests/Unit/Db/DateMapperTest.php b/tests/Unit/Db/DateMapperTest.php new file mode 100644 index 00000000..7b02b68e --- /dev/null +++ b/tests/Unit/Db/DateMapperTest.php @@ -0,0 +1,97 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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\Polls\Tests\Unit\Db; + +use OCA\Polls\Db\Date; +use OCA\Polls\Db\DateMapper; +use OCA\Polls\Db\Event; +use OCA\Polls\Db\EventMapper; +use OCA\Polls\Tests\Unit\UnitTestCase; +use OCP\IDBConnection; +use League\FactoryMuffin\Faker\Facade as Faker; + +class DateMapperTest extends UnitTestCase { + + /** @var IDBConnection */ + private $con; + /** @var DateMapper */ + private $dateMapper; + /** @var EventMapper */ + private $eventMapper; + + /** + * {@inheritDoc} + */ + public function setUp() { + parent::setUp(); + $this->con = \OC::$server->getDatabaseConnection(); + $this->dateMapper = new DateMapper($this->con); + $this->eventMapper = new EventMapper($this->con); + } + + /** + * Create some fake data and persist them to the database. + * + * @return Date + */ + public function testCreate() { + /** @var Event $event */ + $event = $this->fm->instance('OCA\Polls\Db\Event'); + $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); + + /** @var Date $date */ + $date = $this->fm->instance('OCA\Polls\Db\Date'); + $date->setPollId($event->getId()); + $this->assertInstanceOf(Date::class, $this->dateMapper->insert($date)); + + return $date; + } + + /** + * Update the previously created entry and persist the changes. + * + * @depends testCreate + * @param Date $date + * @return Date + */ + public function testUpdate(Date $date) { + $newDt = Faker::date('Y-m-d H:i:s'); + $date->setDt($newDt()); + $this->dateMapper->update($date); + + return $date; + } + + /** + * Delete the previously created entries from the database. + * + * @depends testUpdate + * @param Date $date + */ + public function testDelete(Date $date) { + $event = $this->eventMapper->find($date->getPollId()); + $this->dateMapper->delete($date); + $this->eventMapper->delete($event); + } +} diff --git a/tests/Unit/Db/EventMapperTest.php b/tests/Unit/Db/EventMapperTest.php new file mode 100644 index 00000000..3c7b1a8f --- /dev/null +++ b/tests/Unit/Db/EventMapperTest.php @@ -0,0 +1,87 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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\Polls\Tests\Unit\Db; + +use OCA\Polls\Db\Event; +use OCA\Polls\Db\EventMapper; +use OCA\Polls\Tests\Unit\UnitTestCase; +use OCP\IDBConnection; +use League\FactoryMuffin\Faker\Facade as Faker; + +class EventMapperTest extends UnitTestCase { + + /** @var IDBConnection */ + private $con; + /** @var EventMapper */ + private $eventMapper; + + /** + * {@inheritDoc} + */ + public function setUp() { + parent::setUp(); + $this->con = \OC::$server->getDatabaseConnection(); + $this->eventMapper = new EventMapper($this->con); + } + + /** + * Create some fake data and persist them to the database. + * + * @return Event + */ + public function testCreate() { + /** @var Event $event */ + $event = $this->fm->instance('OCA\Polls\Db\Event'); + $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); + + return $event; + } + + /** + * Update the previously created entry and persist the changes. + * + * @depends testCreate + * @param Event $event + * @return Event + */ + public function testUpdate(Event $event) { + $newTitle = Faker::sentence(10); + $newDescription = Faker::paragraph(); + $event->setTitle($newTitle()); + $event->setDescription($newDescription()); + $this->eventMapper->update($event); + + return $event; + } + + /** + * Delete the previously created entry from the database. + * + * @depends testUpdate + * @param Event $event + */ + public function testDelete(Event $event) { + $this->eventMapper->delete($event); + } +} diff --git a/tests/Unit/Db/NotificationMapperTest.php b/tests/Unit/Db/NotificationMapperTest.php new file mode 100644 index 00000000..96d67226 --- /dev/null +++ b/tests/Unit/Db/NotificationMapperTest.php @@ -0,0 +1,97 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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\Polls\Tests\Unit\Db; + +use OCA\Polls\Db\Event; +use OCA\Polls\Db\EventMapper; +use OCA\Polls\Db\Notification; +use OCA\Polls\Db\NotificationMapper; +use OCA\Polls\Tests\Unit\UnitTestCase; +use OCP\IDBConnection; +use League\FactoryMuffin\Faker\Facade as Faker; + +class NotificationMapperTest extends UnitTestCase { + + /** @var IDBConnection */ + private $con; + /** @var NotificationMapper */ + private $notificationMapper; + /** @var EventMapper */ + private $eventMapper; + + /** + * {@inheritDoc} + */ + public function setUp() { + parent::setUp(); + $this->con = \OC::$server->getDatabaseConnection(); + $this->notificationMapper = new NotificationMapper($this->con); + $this->eventMapper = new EventMapper($this->con); + } + + /** + * Create some fake data and persist them to the database. + * + * @return Notification + */ + public function testCreate() { + /** @var Event $event */ + $event = $this->fm->instance('OCA\Polls\Db\Event'); + $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); + + /** @var Notification $notification */ + $notification = $this->fm->instance('OCA\Polls\Db\Notification'); + $notification->setPollId($event->getId()); + $this->assertInstanceOf(Notification::class, $this->notificationMapper->insert($notification)); + + return $notification; + } + + /** + * Update the previously created entry and persist the changes. + * + * @depends testCreate + * @param Notification $notification + * @return Notification + */ + public function testUpdate(Notification $notification) { + $newUserId = Faker::firstNameMale(); + $notification->setUserId($newUserId()); + $this->notificationMapper->update($notification); + + return $notification; + } + + /** + * Delete the previously created entries from the database. + * + * @depends testUpdate + * @param Notification $notification + */ + public function testDelete(Notification $notification) { + $event = $this->eventMapper->find($notification->getPollId()); + $this->notificationMapper->delete($notification); + $this->eventMapper->delete($event); + } +} diff --git a/tests/Unit/Db/ParticipationMapperTest.php b/tests/Unit/Db/ParticipationMapperTest.php new file mode 100644 index 00000000..365ce205 --- /dev/null +++ b/tests/Unit/Db/ParticipationMapperTest.php @@ -0,0 +1,97 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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\Polls\Tests\Unit\Db; + +use OCA\Polls\Db\Event; +use OCA\Polls\Db\EventMapper; +use OCA\Polls\Db\Participation; +use OCA\Polls\Db\ParticipationMapper; +use OCA\Polls\Tests\Unit\UnitTestCase; +use OCP\IDBConnection; +use League\FactoryMuffin\Faker\Facade as Faker; + +class ParticipationMapperTest extends UnitTestCase { + + /** @var IDBConnection */ + private $con; + /** @var ParticipationMapper */ + private $participationMapper; + /** @var EventMapper */ + private $eventMapper; + + /** + * {@inheritDoc} + */ + public function setUp() { + parent::setUp(); + $this->con = \OC::$server->getDatabaseConnection(); + $this->participationMapper = new ParticipationMapper($this->con); + $this->eventMapper = new EventMapper($this->con); + } + + /** + * Create some fake data and persist them to the database. + * + * @return Participation + */ + public function testCreate() { + /** @var Event $event */ + $event = $this->fm->instance('OCA\Polls\Db\Event'); + $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); + + /** @var Participation $participation */ + $participation = $this->fm->instance('OCA\Polls\Db\Participation'); + $participation->setPollId($event->getId()); + $this->assertInstanceOf(Participation::class, $this->participationMapper->insert($participation)); + + return $participation; + } + + /** + * Update the previously created entry and persist the changes. + * + * @depends testCreate + * @param Participation $participation + * @return Participation + */ + public function testUpdate(Participation $participation) { + $newDt = Faker::date('Y-m-d H:i:s'); + $participation->setDt($newDt()); + $this->participationMapper->update($participation); + + return $participation; + } + + /** + * Delete the previously created entries from the database. + * + * @depends testUpdate + * @param Participation $participation + */ + public function testDelete(Participation $participation) { + $event = $this->eventMapper->find($participation->getPollId()); + $this->participationMapper->delete($participation); + $this->eventMapper->delete($event); + } +} diff --git a/tests/Unit/Db/ParticipationTextMapperTest.php b/tests/Unit/Db/ParticipationTextMapperTest.php new file mode 100644 index 00000000..4d2f46a0 --- /dev/null +++ b/tests/Unit/Db/ParticipationTextMapperTest.php @@ -0,0 +1,97 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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\Polls\Tests\Unit\Db; + +use OCA\Polls\Db\Event; +use OCA\Polls\Db\EventMapper; +use OCA\Polls\Db\ParticipationText; +use OCA\Polls\Db\ParticipationTextMapper; +use OCA\Polls\Tests\Unit\UnitTestCase; +use OCP\IDBConnection; +use League\FactoryMuffin\Faker\Facade as Faker; + +class ParticipationTextMapperTest extends UnitTestCase { + + /** @var IDBConnection */ + private $con; + /** @var ParticipationTextMapper */ + private $participationTextMapper; + /** @var EventMapper */ + private $eventMapper; + + /** + * {@inheritDoc} + */ + public function setUp() { + parent::setUp(); + $this->con = \OC::$server->getDatabaseConnection(); + $this->participationTextMapper = new ParticipationTextMapper($this->con); + $this->eventMapper = new EventMapper($this->con); + } + + /** + * Create some fake data and persist them to the database. + * + * @return ParticipationText + */ + public function testCreate() { + /** @var Event $event */ + $event = $this->fm->instance('OCA\Polls\Db\Event'); + $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); + + /** @var ParticipationText $participationText */ + $participationText = $this->fm->instance('OCA\Polls\Db\ParticipationText'); + $participationText->setPollId($event->getId()); + $this->assertInstanceOf(ParticipationText::class, $this->participationTextMapper->insert($participationText)); + + return $participationText; + } + + /** + * Update the previously created entry and persist the changes. + * + * @depends testCreate + * @param ParticipationText $participationText + * @return ParticipationText + */ + public function testUpdate(ParticipationText $participationText) { + $newText = Faker::paragraph(); + $participationText->setText($newText()); + $this->participationTextMapper->update($participationText); + + return $participationText; + } + + /** + * Delete the previously created entries from the database. + * + * @depends testUpdate + * @param ParticipationText $participationText + */ + public function testDelete(ParticipationText $participationText) { + $event = $this->eventMapper->find($participationText->getPollId()); + $this->participationTextMapper->delete($participationText); + $this->eventMapper->delete($event); + } +} diff --git a/tests/Unit/Db/TextMapperTest.php b/tests/Unit/Db/TextMapperTest.php new file mode 100644 index 00000000..690ae3c6 --- /dev/null +++ b/tests/Unit/Db/TextMapperTest.php @@ -0,0 +1,97 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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\Polls\Tests\Unit\Db; + +use OCA\Polls\Db\Event; +use OCA\Polls\Db\EventMapper; +use OCA\Polls\Db\Text; +use OCA\Polls\Db\TextMapper; +use OCA\Polls\Tests\Unit\UnitTestCase; +use OCP\IDBConnection; +use League\FactoryMuffin\Faker\Facade as Faker; + +class TextMapperTest extends UnitTestCase { + + /** @var IDBConnection */ + private $con; + /** @var TextMapper */ + private $textMapper; + /** @var EventMapper */ + private $eventMapper; + + /** + * {@inheritDoc} + */ + public function setUp() { + parent::setUp(); + $this->con = \OC::$server->getDatabaseConnection(); + $this->textMapper = new TextMapper($this->con); + $this->eventMapper = new EventMapper($this->con); + } + + /** + * Create some fake data and persist them to the database. + * + * @return Text + */ + public function testCreate() { + /** @var Event $event */ + $event = $this->fm->instance('OCA\Polls\Db\Event'); + $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); + + /** @var Text $text */ + $text = $this->fm->instance('OCA\Polls\Db\Text'); + $text->setPollId($event->getId()); + $this->assertInstanceOf(Text::class, $this->textMapper->insert($text)); + + return $text; + } + + /** + * Update the previously created entry and persist the changes. + * + * @depends testCreate + * @param Text $text + * @return Text + */ + public function testUpdate(Text $text) { + $newText = Faker::paragraph(); + $text->setText($newText()); + $this->textMapper->update($text); + + return $text; + } + + /** + * Delete the previously created entries from the database. + * + * @depends testUpdate + * @param Text $text + */ + public function testDelete(Text $text) { + $event = $this->eventMapper->find($text->getPollId()); + $this->textMapper->delete($text); + $this->eventMapper->delete($event); + } +} diff --git a/tests/Unit/Factories/CommentFactory.php b/tests/Unit/Factories/CommentFactory.php new file mode 100644 index 00000000..3a8fb33c --- /dev/null +++ b/tests/Unit/Factories/CommentFactory.php @@ -0,0 +1,36 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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/>. + * + */ + +use League\FactoryMuffin\Faker\Facade as Faker; + +/** + * General factory for the comment model. + */ +$fm->define('OCA\Polls\Db\Comment')->setDefinitions([ + 'userId' => Faker::firstNameMale(), + 'dt' => function () { + $date = new DateTime('today'); + return $date->format('Y-m-d H:i:s'); + }, + 'comment' => Faker::paragraph() +]); diff --git a/tests/Unit/Factories/DateFactory.php b/tests/Unit/Factories/DateFactory.php new file mode 100644 index 00000000..fc6d8fe0 --- /dev/null +++ b/tests/Unit/Factories/DateFactory.php @@ -0,0 +1,32 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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/>. + * + */ + +/** + * General factory for the date model. + */ +$fm->define('OCA\Polls\Db\Date')->setDefinitions([ + 'dt' => function () { + $date = new DateTime('today'); + return $date->format('Y-m-d H:i:s'); + } +]); diff --git a/tests/Unit/Factories/EventFactory.php b/tests/Unit/Factories/EventFactory.php new file mode 100644 index 00000000..fa32dd6c --- /dev/null +++ b/tests/Unit/Factories/EventFactory.php @@ -0,0 +1,46 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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/>. + * + */ + +use League\FactoryMuffin\Faker\Facade as Faker; + +/** + * General factory for the event model. + */ +$fm->define('OCA\Polls\Db\Event')->setDefinitions([ + 'type' => 0, + 'title' => Faker::sentence(10), + 'description' => Faker::paragraph(), + 'owner' => Faker::firstNameMale(), + 'created' => function () { + $date = new DateTime('today'); + return $date->format('Y-m-d H:i:s'); + }, + 'access' => 'registered', + 'expire' => function () { + $date = new DateTime('tomorrow'); + return $date->format('Y-m-d H:i:s'); + }, + 'hash' => Faker::regexify('[A-Za-z0-9]{16}'), + 'isAnonymous' => 0, + 'fullAnonymous' => 0 +]); diff --git a/tests/Unit/Factories/NotificationFactory.php b/tests/Unit/Factories/NotificationFactory.php new file mode 100644 index 00000000..3416219d --- /dev/null +++ b/tests/Unit/Factories/NotificationFactory.php @@ -0,0 +1,31 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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/>. + * + */ + +use League\FactoryMuffin\Faker\Facade as Faker; + +/** + * General factory for the notification model. + */ +$fm->define('OCA\Polls\Db\Notification')->setDefinitions([ + 'userId' => Faker::firstNameMale(), +]); diff --git a/tests/Unit/Factories/ParticipationFactory.php b/tests/Unit/Factories/ParticipationFactory.php new file mode 100644 index 00000000..1d178dd4 --- /dev/null +++ b/tests/Unit/Factories/ParticipationFactory.php @@ -0,0 +1,36 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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/>. + * + */ + +use League\FactoryMuffin\Faker\Facade as Faker; + +/** + * General factory for the participation model. + */ +$fm->define('OCA\Polls\Db\Participation')->setDefinitions([ + 'userId' => Faker::firstNameMale(), + 'dt' => function () { + $date = new DateTime('today'); + return $date->format('Y-m-d H:i:s'); + }, + 'type' => 0 +]); diff --git a/tests/Unit/Factories/ParticipationTextFactory.php b/tests/Unit/Factories/ParticipationTextFactory.php new file mode 100644 index 00000000..7b6f16f4 --- /dev/null +++ b/tests/Unit/Factories/ParticipationTextFactory.php @@ -0,0 +1,33 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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/>. + * + */ + +use League\FactoryMuffin\Faker\Facade as Faker; + +/** + * General factory for the participation text model. + */ +$fm->define('OCA\Polls\Db\ParticipationText')->setDefinitions([ + 'text' => Faker::paragraph(), + 'userId' => Faker::firstNameMale(), + 'type' => 0 +]); diff --git a/tests/Unit/Factories/TextFactory.php b/tests/Unit/Factories/TextFactory.php new file mode 100644 index 00000000..91702af7 --- /dev/null +++ b/tests/Unit/Factories/TextFactory.php @@ -0,0 +1,31 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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/>. + * + */ + +use League\FactoryMuffin\Faker\Facade as Faker; + +/** + * General factory for the text model. + */ +$fm->define('OCA\Polls\Db\Text')->setDefinitions([ + 'text' => Faker::paragraph() +]); diff --git a/tests/Unit/UnitTestCase.php b/tests/Unit/UnitTestCase.php new file mode 100644 index 00000000..7469aff1 --- /dev/null +++ b/tests/Unit/UnitTestCase.php @@ -0,0 +1,42 @@ +<?php +/** + * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co> + * + * @author Kai Schröer <git@schroeer.co> + * + * @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\Polls\Tests\Unit; + +use League\FactoryMuffin\FactoryMuffin; +use PHPUnit_Framework_TestCase; + +abstract class UnitTestCase extends PHPUnit_Framework_TestCase { + + /** @var FactoryMuffin */ + protected $fm; + + /** + * {@inheritDoc} + */ + public function setUp() { + parent::setUp(); + $this->fm = new FactoryMuffin(); + $this->fm->loadFactories(__DIR__ . '/Factories'); + } +} |