Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Gieling <github@dartcafe.de>2018-02-04 14:45:37 +0300
committerGitHub <noreply@github.com>2018-02-04 14:45:37 +0300
commit7465dca16fe42661bd2c4d22116cd796756f5be0 (patch)
tree0c32820a2fadabd16c1d1a81e7a7af6c0dc2940c /tests/Unit
parent41eecc4d3dde9fc68b466f99f0ba4c89efffa280 (diff)
[WIP] Migrate particip tables (#293)
* Migration of - text and date into options - Participation and ParticipationText into Votes * Fix delete poll from details view * You voted, you commented
Diffstat (limited to 'tests/Unit')
-rw-r--r--tests/Unit/Controller/PageControllerTest.php16
-rw-r--r--tests/Unit/Db/OptionsMapperTest.php (renamed from tests/Unit/Db/DateMapperTest.php)48
-rw-r--r--tests/Unit/Db/ParticipationMapperTest.php97
-rw-r--r--tests/Unit/Db/ParticipationTextMapperTest.php97
-rw-r--r--tests/Unit/Db/VotesMapperTest.php (renamed from tests/Unit/Db/TextMapperTest.php)52
-rw-r--r--tests/Unit/Factories/DateFactory.php32
-rw-r--r--tests/Unit/Factories/OptionsFactory.php (renamed from tests/Unit/Factories/TextFactory.php)4
-rw-r--r--tests/Unit/Factories/ParticipationFactory.php36
-rw-r--r--tests/Unit/Factories/VotesFactory.php (renamed from tests/Unit/Factories/ParticipationTextFactory.php)8
9 files changed, 63 insertions, 327 deletions
diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php
index 302d44fe..f00b3be1 100644
--- a/tests/Unit/Controller/PageControllerTest.php
+++ b/tests/Unit/Controller/PageControllerTest.php
@@ -62,7 +62,7 @@ class PageControllerTest extends UnitTestCase {
$commentMapper = $this->getMockBuilder('OCA\Polls\Db\CommentMapper')
->disableOriginalConstructor()
->getMock();
- $dateMapper = $this->getMockBuilder('OCA\Polls\Db\DateMapper')
+ $optionsMapper = $this->getMockBuilder('OCA\Polls\Db\OptionsMapper')
->disableOriginalConstructor()
->getMock();
$eventMapper = $this->getMockBuilder('OCA\Polls\Db\EventMapper')
@@ -71,13 +71,7 @@ class PageControllerTest extends UnitTestCase {
$notificationMapper = $this->getMockBuilder('OCA\Polls\Db\NotificationMapper')
->disableOriginalConstructor()
->getMock();
- $participationMapper = $this->getMockBuilder('OCA\Polls\Db\ParticipationMapper')
- ->disableOriginalConstructor()
- ->getMock();
- $participationTextMapper = $this->getMockBuilder('OCA\Polls\Db\ParticipationTextMapper')
- ->disableOriginalConstructor()
- ->getMock();
- $textMapper = $this->getMockBuilder('OCA\Polls\Db\TextMapper')
+ $votesMapper = $this->getMockBuilder('OCA\Polls\Db\VotesMapper')
->disableOriginalConstructor()
->getMock();
@@ -92,12 +86,10 @@ class PageControllerTest extends UnitTestCase {
$urlGenerator,
$this->userId,
$commentMapper,
- $dateMapper,
+ $optionsMapper,
$eventMapper,
$notificationMapper,
- $participationMapper,
- $participationTextMapper,
- $textMapper
+ $votesMapper
);
}
diff --git a/tests/Unit/Db/DateMapperTest.php b/tests/Unit/Db/OptionsMapperTest.php
index 7b02b68e..61654f14 100644
--- a/tests/Unit/Db/DateMapperTest.php
+++ b/tests/Unit/Db/OptionsMapperTest.php
@@ -23,20 +23,20 @@
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\Db\Options;
+use OCA\Polls\Db\OptionsMapper;
use OCA\Polls\Tests\Unit\UnitTestCase;
use OCP\IDBConnection;
use League\FactoryMuffin\Faker\Facade as Faker;
-class DateMapperTest extends UnitTestCase {
+class OptionsMapperTest extends UnitTestCase {
/** @var IDBConnection */
private $con;
- /** @var DateMapper */
- private $dateMapper;
+ /** @var OptionsMapper */
+ private $optionsMapper;
/** @var EventMapper */
private $eventMapper;
@@ -46,52 +46,52 @@ class DateMapperTest extends UnitTestCase {
public function setUp() {
parent::setUp();
$this->con = \OC::$server->getDatabaseConnection();
- $this->dateMapper = new DateMapper($this->con);
+ $this->optionsMapper = new OptionsMapper($this->con);
$this->eventMapper = new EventMapper($this->con);
}
/**
* Create some fake data and persist them to the database.
*
- * @return Date
+ * @return Options
*/
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));
+ /** @var Options $options */
+ $options = $this->fm->instance('OCA\Polls\Db\Options');
+ $options->setPollId($event->getId());
+ $this->assertInstanceOf(Options::class, $this->optionsMapper->insert($options));
- return $date;
+ return $options;
}
/**
* Update the previously created entry and persist the changes.
*
* @depends testCreate
- * @param Date $date
- * @return Date
+ * @param Options $options
+ * @return Options
*/
- public function testUpdate(Date $date) {
- $newDt = Faker::date('Y-m-d H:i:s');
- $date->setDt($newDt());
- $this->dateMapper->update($date);
+ public function testUpdate(Options $options) {
+ $newPollOptionText = Faker::paragraph();
+ $options->setPollOptionText($newPollOptionText());
+ $this->optionsMapper->update($options);
- return $date;
+ return $options;
}
-
+
/**
* Delete the previously created entries from the database.
*
* @depends testUpdate
- * @param Date $date
+ * @param Options $options
*/
- public function testDelete(Date $date) {
- $event = $this->eventMapper->find($date->getPollId());
- $this->dateMapper->delete($date);
+ public function testDelete(Options $options) {
+ $event = $this->eventMapper->find($options->getPollId());
+ $this->optionsMapper->delete($options);
$this->eventMapper->delete($event);
}
}
diff --git a/tests/Unit/Db/ParticipationMapperTest.php b/tests/Unit/Db/ParticipationMapperTest.php
deleted file mode 100644
index 365ce205..00000000
--- a/tests/Unit/Db/ParticipationMapperTest.php
+++ /dev/null
@@ -1,97 +0,0 @@
-<?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
deleted file mode 100644
index 4d2f46a0..00000000
--- a/tests/Unit/Db/ParticipationTextMapperTest.php
+++ /dev/null
@@ -1,97 +0,0 @@
-<?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/VotesMapperTest.php
index 690ae3c6..df8722b6 100644
--- a/tests/Unit/Db/TextMapperTest.php
+++ b/tests/Unit/Db/VotesMapperTest.php
@@ -25,18 +25,22 @@ 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\Db\Options;
+use OCA\Polls\Db\OptionsMapper;
+use OCA\Polls\Db\Votes;
+use OCA\Polls\Db\VotesMapper;
use OCA\Polls\Tests\Unit\UnitTestCase;
use OCP\IDBConnection;
use League\FactoryMuffin\Faker\Facade as Faker;
-class TextMapperTest extends UnitTestCase {
+class VotesMapperTest extends UnitTestCase {
/** @var IDBConnection */
private $con;
- /** @var TextMapper */
- private $textMapper;
+ /** @var OptionsMapper */
+ private $optionsMapper;
+ /** @var VotesMapper */
+ private $votesMapper;
/** @var EventMapper */
private $eventMapper;
@@ -46,52 +50,54 @@ class TextMapperTest extends UnitTestCase {
public function setUp() {
parent::setUp();
$this->con = \OC::$server->getDatabaseConnection();
- $this->textMapper = new TextMapper($this->con);
+ $this->votesMapper = new VotesMapper($this->con);
$this->eventMapper = new EventMapper($this->con);
}
/**
* Create some fake data and persist them to the database.
*
- * @return Text
+ * @return Votes
*/
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));
+
+ /** @var Votes $votes */
+ $votes = $this->fm->instance('OCA\Polls\Db\Votes');
+ $votes->setPollId($event->getId());
+ $votes->setVoteOptionId(1);
+ $this->assertInstanceOf(Votes::class, $this->votesMapper->insert($votes));
- return $text;
+ return $votes;
}
/**
* Update the previously created entry and persist the changes.
*
* @depends testCreate
- * @param Text $text
- * @return Text
+ * @param Votes $votes
+ * @return Votes
*/
- public function testUpdate(Text $text) {
- $newText = Faker::paragraph();
- $text->setText($newText());
- $this->textMapper->update($text);
+ public function testUpdate(Votes $votes) {
+ $newVoteOptionText = Faker::date('Y-m-d H:i:s');
+ $votes->setVoteOptionText($newVoteOptionText());
+ $this->votesMapper->update($votes);
- return $text;
+ return $votes;
}
/**
* Delete the previously created entries from the database.
*
* @depends testUpdate
- * @param Text $text
+ * @param Votes $votes
*/
- public function testDelete(Text $text) {
- $event = $this->eventMapper->find($text->getPollId());
- $this->textMapper->delete($text);
+ public function testDelete(Votes $votes) {
+ $event = $this->eventMapper->find($votes->getPollId());
+ $this->votesMapper->delete($votes);
$this->eventMapper->delete($event);
}
}
diff --git a/tests/Unit/Factories/DateFactory.php b/tests/Unit/Factories/DateFactory.php
deleted file mode 100644
index fc6d8fe0..00000000
--- a/tests/Unit/Factories/DateFactory.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?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/TextFactory.php b/tests/Unit/Factories/OptionsFactory.php
index 28d5675e..d1185a3b 100644
--- a/tests/Unit/Factories/TextFactory.php
+++ b/tests/Unit/Factories/OptionsFactory.php
@@ -26,6 +26,6 @@ use League\FactoryMuffin\Faker\Facade as Faker;
/**
* General factory for the text model.
*/
-$fm->define('OCA\Polls\Db\Text')->setDefinitions([
- 'text' => Faker::text(255)
+$fm->define('OCA\Polls\Db\Options')->setDefinitions([
+ 'pollOptionText' => Faker::text(255)
]);
diff --git a/tests/Unit/Factories/ParticipationFactory.php b/tests/Unit/Factories/ParticipationFactory.php
deleted file mode 100644
index 1d178dd4..00000000
--- a/tests/Unit/Factories/ParticipationFactory.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?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/VotesFactory.php
index 606595ef..4d8f7529 100644
--- a/tests/Unit/Factories/ParticipationTextFactory.php
+++ b/tests/Unit/Factories/VotesFactory.php
@@ -24,10 +24,10 @@
use League\FactoryMuffin\Faker\Facade as Faker;
/**
- * General factory for the participation text model.
+ * General factory for the votes model.
*/
-$fm->define('OCA\Polls\Db\ParticipationText')->setDefinitions([
- 'text' => Faker::text(255),
+$fm->define('OCA\Polls\Db\Votes')->setDefinitions([
+ 'voteOptionText' => Faker::text(255),
'userId' => Faker::firstNameMale(),
- 'type' => 0
+ 'voteAnswer' => 'yes'
]);