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>2020-11-30 22:28:25 +0300
committerGitHub <noreply@github.com>2020-11-30 22:28:25 +0300
commitd2eee9bd2b71361b7ad5db9cccf8003eadb7ad9d (patch)
treef28ab7eaf06d0b2d7d0570cb0291a1ce15d03fa0 /tests/Unit
parentcccca2d1525500743493ad9e06e3f84838dec7d0 (diff)
use github CI and PHPUnit (#1257) (#1269)
* use github CI and PHPUnit (#1257) * CommentMapperTest * LogMapperTest * SubscriptionMapperTest * all mappers
Diffstat (limited to 'tests/Unit')
-rw-r--r--tests/Unit/Db/CommentMapperTest.php99
-rw-r--r--tests/Unit/Db/LogMapperTest.php142
-rw-r--r--tests/Unit/Db/OptionMapperTest.php97
-rw-r--r--tests/Unit/Db/PollMapperTest.php70
-rw-r--r--tests/Unit/Db/SubscriptionMapperTest.php93
-rw-r--r--tests/Unit/Db/VoteMapperTest.php139
-rw-r--r--tests/Unit/Factories/CommentFactory.php4
-rw-r--r--tests/Unit/Factories/LogFactory.php39
-rw-r--r--tests/Unit/Factories/OptionFactory.php4
-rw-r--r--tests/Unit/Factories/PollFactory.php9
-rw-r--r--tests/Unit/Factories/PreferencesFactory.php36
-rw-r--r--tests/Unit/Factories/ShareFactory.php33
-rw-r--r--tests/Unit/Factories/VoteFactory.php2
13 files changed, 591 insertions, 176 deletions
diff --git a/tests/Unit/Db/CommentMapperTest.php b/tests/Unit/Db/CommentMapperTest.php
index e78301a4..8cb9d812 100644
--- a/tests/Unit/Db/CommentMapperTest.php
+++ b/tests/Unit/Db/CommentMapperTest.php
@@ -23,23 +23,32 @@
namespace OCA\Polls\Tests\Unit\Db;
+use League\FactoryMuffin\Faker\Facade as Faker;
+use OCP\IDBConnection;
+use OCA\Polls\Tests\Unit\UnitTestCase;
+
use OCA\Polls\Db\Comment;
use OCA\Polls\Db\CommentMapper;
use OCA\Polls\Db\Poll;
use OCA\Polls\Db\PollMapper;
-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 PollMapper */
private $pollMapper;
+ /** @var array */
+ private $polls = [];
+
+ /** @var array */
+ private $comments = [];
+
/**
* {@inheritDoc}
*/
@@ -48,50 +57,70 @@ class CommentMapperTest extends UnitTestCase {
$this->con = \OC::$server->getDatabaseConnection();
$this->commentMapper = new CommentMapper($this->con);
$this->pollMapper = new PollMapper($this->con);
+
+ $this->polls = [
+ $this->fm->instance('OCA\Polls\Db\Poll')
+ ];
+
+ foreach ($this->polls as &$poll) {
+ $poll = $this->pollMapper->insert($poll);
+
+ for ($count=0; $count < 2; $count++) {
+ $comment = $this->fm->instance('OCA\Polls\Db\Comment');
+ $comment->setPollId($poll->getId());
+ array_push($this->comments, $this->commentMapper->insert($comment));
+ }
+ }
+ unset($poll);
}
+ /**
+ * testFind
+ */
+ public function testFind() {
+ foreach ($this->comments as $comment) {
+ $this->assertInstanceOf(Comment::class, $this->commentMapper->find($comment->getId()));
+ }
+ }
+
/**
- * Create some fake data and persist them to the database.
- *
- * @return Comment
+ * testFindByPoll
*/
- public function testCreate() {
- /** @var Poll $poll */
- $poll = $this->fm->instance('OCA\Polls\Db\Poll');
- $this->assertInstanceOf(Poll::class, $this->pollMapper->insert($poll));
-
- /** @var Comment $comment */
- $comment = $this->fm->instance('OCA\Polls\Db\Comment');
- $comment->setPollId($poll->getId());
- $this->assertInstanceOf(Comment::class, $this->commentMapper->insert($comment));
-
- return $comment;
+ public function testFindByPoll() {
+ foreach ($this->polls as $poll) {
+ $this->assertTrue(count($this->commentMapper->findByPoll($poll->getId())) > 0);
+ }
}
/**
- * Update the previously created entry and persist the changes.
- *
- * @depends testCreate
- * @param Comment $comment
- * @return Comment
+ * testUpdate
*/
- public function testUpdate(Comment $comment) {
- $newComment = Faker::paragraph();
- $comment->setComment($newComment());
- $this->commentMapper->update($comment);
+ public function testUpdate() {
+ foreach ($this->comments as &$comment) {
+ $newComment = Faker::paragraph();
+ $comment->setComment($newComment());
+ $this->assertInstanceOf(Comment::class, $this->commentMapper->update($comment));
+ }
+ unset($comment);
+ }
- return $comment;
+ /**
+ * testDelete
+ */
+ public function testDelete() {
+ foreach ($this->comments as $comment) {
+ $this->assertInstanceOf(Comment::class, $this->commentMapper->delete($comment));
+ }
}
/**
- * Delete the previously created entries from the database.
- *
- * @depends testUpdate
- * @param Comment $comment
+ * tearDown
*/
- public function testDelete(Comment $comment) {
- $poll = $this->pollMapper->find($comment->getPollId());
- $this->commentMapper->delete($comment);
- $this->pollMapper->delete($poll);
+ public function tearDown(): void {
+ parent::tearDown();
+ foreach ($this->polls as $poll) {
+ $this->pollMapper->delete($poll);
+ }
}
+
}
diff --git a/tests/Unit/Db/LogMapperTest.php b/tests/Unit/Db/LogMapperTest.php
new file mode 100644
index 00000000..8ec632a5
--- /dev/null
+++ b/tests/Unit/Db/LogMapperTest.php
@@ -0,0 +1,142 @@
+<?php declare(strict_types=1);
+/**
+ * @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\Log;
+use OCA\Polls\Db\LogMapper;
+use OCA\Polls\Db\Poll;
+use OCA\Polls\Db\PollMapper;
+use OCA\Polls\Tests\Unit\UnitTestCase;
+use OCP\IDBConnection;
+use League\FactoryMuffin\Faker\Facade as Faker;
+
+class LogMapperTest extends UnitTestCase {
+
+ /** @var IDBConnection */
+ private $con;
+
+ /** @var LogMapper */
+ private $logMapper;
+
+ /** @var PollMapper */
+ private $pollMapper;
+
+ /** @var array */
+ private $polls = [];
+
+ /** @var array */
+ private $logs = [];
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected function setUp(): void {
+ parent::setUp();
+ $this->con = \OC::$server->getDatabaseConnection();
+ $this->logMapper = new LogMapper($this->con);
+ $this->pollMapper = new PollMapper($this->con);
+
+ $this->polls = [
+ $this->fm->instance('OCA\Polls\Db\Poll')
+ ];
+
+ foreach ($this->polls as &$poll) {
+ $poll = $this->pollMapper->insert($poll);
+
+ for ($count=0; $count < 2; $count++) {
+ $log = $this->fm->instance('OCA\Polls\Db\Log');
+ $log->setPollId($poll->getId());
+ array_push($this->logs, $this->logMapper->insert($log));
+ }
+ }
+ unset($poll);
+ }
+
+ /**
+ * testFindByPollId
+ */
+ public function testFindByPollId() {
+ foreach ($this->polls as $poll) {
+ $this->assertTrue(count($this->logMapper->findByPollId($poll->getId())) > 0);
+ }
+ }
+
+ /**
+ * testFindUnprocessed
+ */
+ public function testFindUnprocessed() {
+ $this->assertTrue(count($this->logMapper->findUnprocessed()) > 0);
+ }
+
+ /**
+ * testFindUnprocessedPolls
+ */
+ public function testFindUnprocessedPolls() {
+ $this->assertTrue(count($this->logMapper->findUnprocessedPolls()) > 0);
+ }
+
+ /**
+ * testGetLastRecord
+ */
+ public function testGetLastRecord() {
+ foreach ($this->polls as $poll) {
+ $this->assertInstanceOf(Log::class, $this->logMapper->getLastRecord($poll->getId()));
+ }
+ }
+
+ /**
+ * testUpdate
+ * includes testFind
+ */
+ public function testUpdate() {
+ foreach ($this->logs as &$log) {
+ $log->setMessageId(Log::MSG_ID_UPDATEPOLL);
+ $this->assertInstanceOf(Log::class, $this->logMapper->update($log));
+ }
+ unset($log);
+ }
+
+
+ /**
+ * testDelete
+ */
+ public function testDelete() {
+ foreach ($this->logs as $log) {
+ $before = $this->logMapper->find($log->getId());
+ $this->assertInstanceOf(Log::class, $this->logMapper->delete($before));
+ }
+ }
+
+ /**
+ * tearDown
+ */
+ public function tearDown(): void {
+ parent::tearDown();
+ foreach ($this->polls as $poll) {
+ $this->pollMapper->delete($poll);
+ }
+ }
+
+}
diff --git a/tests/Unit/Db/OptionMapperTest.php b/tests/Unit/Db/OptionMapperTest.php
index 67344c11..9fce8b18 100644
--- a/tests/Unit/Db/OptionMapperTest.php
+++ b/tests/Unit/Db/OptionMapperTest.php
@@ -21,25 +21,34 @@
*
*/
-namespace OCA\Polls\Tests\Unit\Db;
+namespace OCA\Polls\Db;
+
+use League\FactoryMuffin\Faker\Facade as Faker;
+use OCP\IDBConnection;
+use OCA\Polls\Tests\Unit\UnitTestCase;
use OCA\Polls\Db\Poll;
use OCA\Polls\Db\PollMapper;
use OCA\Polls\Db\Option;
use OCA\Polls\Db\OptionMapper;
-use OCA\Polls\Tests\Unit\UnitTestCase;
-use OCP\IDBConnection;
-use League\FactoryMuffin\Faker\Facade as Faker;
class OptionMapperTest extends UnitTestCase {
/** @var IDBConnection */
private $con;
+
/** @var OptionMapper */
private $optionMapper;
+
/** @var PollMapper */
private $pollMapper;
+ /** @var array */
+ private $polls = [];
+
+ /** @var array */
+ private $options = [];
+
/**
* {@inheritDoc}
*/
@@ -48,50 +57,68 @@ class OptionMapperTest extends UnitTestCase {
$this->con = \OC::$server->getDatabaseConnection();
$this->optionMapper = new OptionMapper($this->con);
$this->pollMapper = new PollMapper($this->con);
+
+ $this->polls = [
+ $this->fm->instance('OCA\Polls\Db\Poll')
+ ];
+
+ foreach ($this->polls as &$poll) {
+ $poll = $this->pollMapper->insert($poll);
+
+ for ($count=0; $count < 2; $count++) {
+ $option = $this->fm->instance('OCA\Polls\Db\Option');
+ $option->setPollId($poll->getId());
+ array_push($this->options, $this->optionMapper->insert($option));
+ }
+ }
+ unset($poll);
}
/**
- * Create some fake data and persist them to the database.
- *
- * @return Option
+ * testFind
*/
- public function testCreate() {
- /** @var Poll $poll */
- $poll = $this->fm->instance('OCA\Polls\Db\Poll');
- $this->assertInstanceOf(Poll::class, $this->pollMapper->insert($poll));
-
- /** @var Option $option */
- $option = $this->fm->instance('OCA\Polls\Db\Option');
- $option->setPollId($poll->getId());
- $this->assertInstanceOf(Option::class, $this->optionMapper->insert($option));
+ public function testFind() {
+ foreach ($this->options as $option) {
+ $this->assertInstanceOf(Option::class, $this->optionMapper->find($option->getId()));
+ }
+ }
- return $option;
+ /**
+ * testFindByPoll
+ */
+ public function testFindByPoll() {
+ foreach ($this->polls as $poll) {
+ $this->assertTrue(count($this->optionMapper->findByPoll($poll->getId())) > 0);
+ }
}
/**
- * Update the previously created entry and persist the changes.
- *
- * @depends testCreate
- * @param Option $option
- * @return Option
+ * testUpdate
+ * includes testFind
*/
- public function testUpdate(Option $option) {
- $newPollOptionText = Faker::text(255);
- $option->setPollOptionText($newPollOptionText());
- $this->optionMapper->update($option);
+ public function testUpdate() {
+ foreach ($this->options as &$option) {
+ $option->setPollOptionText('Changed option');
+ $this->assertInstanceOf(Option::class, $this->optionMapper->update($option));
+ }
+ }
- return $option;
+ /**
+ * testDelete
+ */
+ public function testDelete() {
+ foreach ($this->options as $option) {
+ $this->assertInstanceOf(Option::class, $this->optionMapper->delete($option));
+ }
}
/**
- * Delete the previously created entries from the database.
- *
- * @depends testUpdate
- * @param Option $option
+ * tearDown
*/
- public function testDelete(Option $option) {
- $poll = $this->pollMapper->find($option->getPollId());
- $this->optionMapper->delete($option);
- $this->pollMapper->delete($poll);
+ public function tearDown(): void {
+ parent::tearDown();
+ foreach ($this->polls as $poll) {
+ $this->pollMapper->delete($poll);
+ }
}
}
diff --git a/tests/Unit/Db/PollMapperTest.php b/tests/Unit/Db/PollMapperTest.php
index c91c80c9..203e89b1 100644
--- a/tests/Unit/Db/PollMapperTest.php
+++ b/tests/Unit/Db/PollMapperTest.php
@@ -23,19 +23,24 @@
namespace OCA\Polls\Tests\Unit\Db;
+use League\FactoryMuffin\Faker\Facade as Faker;
+use OCP\IDBConnection;
use OCA\Polls\Db\Poll;
use OCA\Polls\Db\PollMapper;
use OCA\Polls\Tests\Unit\UnitTestCase;
-use OCP\IDBConnection;
-use League\FactoryMuffin\Faker\Facade as Faker;
class PollMapperTest extends UnitTestCase {
/** @var IDBConnection */
private $con;
+
/** @var PollMapper */
private $pollMapper;
+ /** @var array */
+ private $polls = [];
+
+
/**
* {@inheritDoc}
*/
@@ -43,45 +48,54 @@ class PollMapperTest extends UnitTestCase {
parent::setUp();
$this->con = \OC::$server->getDatabaseConnection();
$this->pollMapper = new PollMapper($this->con);
+
+ $this->polls = [
+ $this->fm->instance('OCA\Polls\Db\Poll'),
+ $this->fm->instance('OCA\Polls\Db\Poll'),
+ $this->fm->instance('OCA\Polls\Db\Poll')
+ ];
+ foreach ($this->polls as &$poll) {
+ $poll = $this->pollMapper->insert($poll);
+ }
+ unset($poll);
}
/**
- * Create some fake data and persist them to the database.
- *
- * @return Poll
+ * testFindAll
*/
- public function testCreate() {
- /** @var Poll $poll */
- $poll = $this->fm->instance('OCA\Polls\Db\Poll');
- $this->assertInstanceOf(Poll::class, $this->pollMapper->insert($poll));
-
- return $poll;
+ public function testFindAll() {
+ $this->assertEquals(count($this->pollMapper->findAll()), count($this->polls));
}
/**
- * Update the previously created entry and persist the changes.
- *
- * @depends testCreate
- * @param Poll $poll
- * @return Poll
+ * testUpdate
*/
- public function testUpdate(Poll $poll) {
- $newTitle = Faker::sentence(10);
- $newDescription = Faker::paragraph();
- $poll->setTitle($newTitle());
- $poll->setDescription($newDescription());
- $this->pollMapper->update($poll);
+ public function testUpdate() {
+ foreach ($this->polls as &$poll) {
+ $newTitle = Faker::sentence(10);
+ $newDescription = Faker::paragraph();
+ $poll->setTitle($newTitle());
+ $poll->setDescription($newDescription());
- return $poll;
+ $this->assertInstanceOf(Poll::class, $this->pollMapper->update($poll));
+ }
+ unset($poll);
}
/**
* Delete the previously created entry from the database.
- *
- * @depends testUpdate
- * @param Poll $poll
*/
- public function testDelete(Poll $poll) {
- $this->pollMapper->delete($poll);
+ public function testDelete() {
+ foreach ($this->polls as $poll) {
+ $this->assertInstanceOf(Poll::class, $this->pollMapper->delete($poll));
+ }
+ }
+
+ /**
+ * tearDown
+ */
+ public function tearDown(): void {
+ parent::tearDown();
+ // no tidy neccesary, polls got deleted via testDelete()
}
}
diff --git a/tests/Unit/Db/SubscriptionMapperTest.php b/tests/Unit/Db/SubscriptionMapperTest.php
index 3588ec94..d5a06da3 100644
--- a/tests/Unit/Db/SubscriptionMapperTest.php
+++ b/tests/Unit/Db/SubscriptionMapperTest.php
@@ -23,23 +23,36 @@
namespace OCA\Polls\Tests\Unit\Db;
+use League\FactoryMuffin\Faker\Facade as Faker;
+use OCP\IDBConnection;
+use OCA\Polls\Tests\Unit\UnitTestCase;
+
use OCA\Polls\Db\Poll;
use OCA\Polls\Db\PollMapper;
use OCA\Polls\Db\Subscription;
use OCA\Polls\Db\SubscriptionMapper;
-use OCA\Polls\Tests\Unit\UnitTestCase;
-use OCP\IDBConnection;
-use League\FactoryMuffin\Faker\Facade as Faker;
class SubscriptionMapperTest extends UnitTestCase {
/** @var IDBConnection */
private $con;
+
/** @var SubscriptionMapper */
private $subscriptionMapper;
+
/** @var PollMapper */
private $pollMapper;
+ /** @var array */
+ private $polls = [];
+
+ /** @var array */
+ private $subscriptions = [];
+
+ /** @var array */
+ private $users = [];
+
+
/**
* {@inheritDoc}
*/
@@ -48,50 +61,58 @@ class SubscriptionMapperTest extends UnitTestCase {
$this->con = \OC::$server->getDatabaseConnection();
$this->subscriptionMapper = new SubscriptionMapper($this->con);
$this->pollMapper = new PollMapper($this->con);
- }
- /**
- * Create some fake data and persist them to the database.
- *
- * @return Subscription
- */
- public function testCreate() {
- /** @var Poll $poll */
- $poll = $this->fm->instance('OCA\Polls\Db\Poll');
- $this->assertInstanceOf(Poll::class, $this->pollMapper->insert($poll));
+ $this->polls = [
+ $this->fm->instance('OCA\Polls\Db\Poll')
+ ];
- /** @var Subscription $subscription */
- $subscription = $this->fm->instance('OCA\Polls\Db\Subscription');
- $subscription->setPollId($poll->getId());
- $this->assertInstanceOf(Subscription::class, $this->subscriptionMapper->insert($subscription));
+ foreach ($this->polls as &$poll) {
+ $poll = $this->pollMapper->insert($poll);
- return $subscription;
+ for ($count=0; $count < 2; $count++) {
+ $subscription = $this->fm->instance('OCA\Polls\Db\Subscription');
+ $subscription->setPollId($poll->getId());
+ array_push($this->subscriptions, $this->subscriptionMapper->insert($subscription));
+ }
+ $this->users[$poll->getId()] = $subscription->getUserId();
+ }
+ unset($poll);
}
/**
- * Update the previously created entry and persist the changes.
- *
- * @depends testCreate
- * @param Subscription $subscription
- * @return Subscription
+ * testFindAllByPoll
*/
- public function testUpdate(Subscription $subscription) {
- $newUserId = Faker::firstNameMale();
- $subscription->setUserId($newUserId());
- $this->subscriptionMapper->update($subscription);
+ public function testFindAllByPoll() {
+ foreach ($this->polls as $poll) {
+ $this->assertTrue(count($this->subscriptionMapper->findAllByPoll($poll->getId())) > 0);
+ }
+ }
- return $subscription;
+ /**
+ * testfindByPollAndUser
+ */
+ public function testfindByPollAndUser() {
+ foreach ($this->polls as $poll) {
+ $this->assertInstanceOf(Subscription::class, $this->subscriptionMapper->findByPollAndUser($poll->getId(), $this->users[$poll->getId()]));
+ }
+ }
+ /**
+ * testUnsubscribe
+ */
+ public function testUnsubscribe() {
+ foreach ($this->polls as $poll) {
+ $this->assertTrue($this->subscriptionMapper->unsubscribe($poll->getId(), $this->users[$poll->getId()]));
+ }
}
/**
- * Delete the previously created entries from the database.
- *
- * @depends testUpdate
- * @param Subscription $subscription
+ * tearDown
*/
- public function testDelete(Subscription $subscription) {
- $poll = $this->pollMapper->find($subscription->getPollId());
- $this->subscriptionMapper->delete($subscription);
- $this->pollMapper->delete($poll);
+ public function tearDown(): void {
+ parent::tearDown();
+ foreach ($this->polls as $poll) {
+ $this->pollMapper->delete($poll);
+ }
}
+
}
diff --git a/tests/Unit/Db/VoteMapperTest.php b/tests/Unit/Db/VoteMapperTest.php
index 6904f11e..ab6c21ad 100644
--- a/tests/Unit/Db/VoteMapperTest.php
+++ b/tests/Unit/Db/VoteMapperTest.php
@@ -23,13 +23,16 @@
namespace OCA\Polls\Tests\Unit\Db;
+use League\FactoryMuffin\Faker\Facade as Faker;
+use OCP\IDBConnection;
+use OCA\Polls\Tests\Unit\UnitTestCase;
+
use OCA\Polls\Db\Poll;
use OCA\Polls\Db\PollMapper;
use OCA\Polls\Db\Vote;
use OCA\Polls\Db\VoteMapper;
-use OCA\Polls\Tests\Unit\UnitTestCase;
-use OCP\IDBConnection;
-use League\FactoryMuffin\Faker\Facade as Faker;
+use OCA\Polls\Db\Option;
+use OCA\Polls\Db\OptionMapper;
class VoteMapperTest extends UnitTestCase {
@@ -39,6 +42,21 @@ class VoteMapperTest extends UnitTestCase {
private $voteMapper;
/** @var PollMapper */
private $pollMapper;
+ /** @var OptionMapper */
+ private $optionMapper;
+
+
+ /** @var array */
+ private $polls = [];
+
+ /** @var array */
+ private $options = [];
+
+ /** @var array */
+ private $votes = [];
+
+ /** @var array */
+ private $users = [];
/**
* {@inheritDoc}
@@ -48,52 +66,105 @@ class VoteMapperTest extends UnitTestCase {
$this->con = \OC::$server->getDatabaseConnection();
$this->voteMapper = new VoteMapper($this->con);
$this->pollMapper = new PollMapper($this->con);
+ $this->optionMapper = new OptionMapper($this->con);
+
+ $this->polls = [
+ $this->fm->instance('OCA\Polls\Db\Poll')
+ ];
+
+ foreach ($this->polls as &$poll) {
+ $poll = $this->pollMapper->insert($poll);
+
+ for ($optionsCount=0; $optionsCount < 2; $optionsCount++) {
+ $option = $this->fm->instance('OCA\Polls\Db\Option');
+ $option->setPollId($poll->getId());
+ array_push($this->options, $this->optionMapper->insert($option));
+ $vote = $this->fm->instance('OCA\Polls\Db\Vote');
+ $vote->setPollId($option->getPollId());
+ $vote->setUserId('voter');
+ $vote->setVoteOptionText($option->getPollOptionText());
+ array_push($this->votes, $this->voteMapper->insert($vote));
+ }
+ }
+ unset($poll);
}
+
/**
- * Create some fake data and persist them to the database.
- *
- * @return Vote
+ * testFindByPoll
*/
- public function testCreate() {
- /** @var Poll $poll */
- $poll = $this->fm->instance('OCA\Polls\Db\Poll');
- $this->assertInstanceOf(Poll::class, $this->pollMapper->insert($poll));
+ public function testFindByPoll() {
+ foreach ($this->polls as $poll) {
+ $this->assertTrue(count($this->voteMapper->findByPoll($poll->getId())) > 0);
+ }
+ }
+ /**
+ * testFindByPollAndUser
+ */
+ public function testFindByPollAndUser() {
+ foreach ($this->polls as $poll) {
+ $this->assertTrue(count($this->voteMapper->findByPollAndUser($poll->getId(), 'voter')) > 0);
+ }
+ }
- /** @var Vote $vote */
- $vote = $this->fm->instance('OCA\Polls\Db\Vote');
- $vote->setPollId($poll->getId());
- $vote->setVoteOptionId(1);
- $this->assertInstanceOf(Vote::class, $this->voteMapper->insert($vote));
+ /**
+ * testFindSingleVote
+ */
+ public function testFindSingleVote() {
+ foreach ($this->votes as $vote) {
+ $this->assertInstanceOf(Vote::class, $this->voteMapper->findSingleVote($vote->getPollId(), $vote->getVoteOptionText(), $vote->getUserId()));
+ }
+ }
- return $vote;
+ /**
+ * testParticipantsByPoll
+ */
+ public function testParticipantsByPoll() {
+ foreach ($this->polls as $poll) {
+ $this->assertTrue(count($this->voteMapper->findParticipantsByPoll($poll->getId())) > 0);
+ }
}
/**
- * Update the previously created entry and persist the changes.
- *
- * @depends testCreate
- * @param Vote $vote
- * @return Vote
+ * testParticipantsByPoll
*/
- public function testUpdate(Vote $vote) {
- $newVoteOptionText = Faker::date('Y-m-d H:i:s');
- $vote->setVoteOptionText($newVoteOptionText());
- $this->voteMapper->update($vote);
+ public function testFindParticipantsVotes() {
+ foreach ($this->votes as $vote) {
+ $this->assertTrue(count($this->voteMapper->findParticipantsVotes($vote->getPollId(), $vote->getUserId())) > 0);
+ }
+ }
- return $vote;
+ /**
+ * testUpdate
+ */
+ public function testUpdate() {
+ foreach ($this->votes as &$vote) {
+ $vote->setVoteAnswer('no');
+ $this->assertInstanceOf(Vote::class, $this->voteMapper->update($vote));
+ }
+ unset($vote);
}
/**
- * Delete the previously created entries from the database.
- *
- * @depends testUpdate
- * @param Vote $vote
+ * testDeleteByPollAndUser
*/
- public function testDelete(Vote $vote) {
- $poll = $this->pollMapper->find($vote->getPollId());
- $this->voteMapper->delete($vote);
- $this->pollMapper->delete($poll);
+ public function testDeleteByPollAndUser() {
+ foreach ($this->polls as $poll) {
+ $this->assertTrue($this->voteMapper->deleteByPollAndUser($poll->getId(), 'voter'));
+ }
+ }
+
+ /**
+ * tearDown
+ */
+ public function tearDown(): void {
+ parent::tearDown();
+ foreach ($this->options as $option) {
+ $this->optionMapper->delete($option);
+ }
+ foreach ($this->polls as $poll) {
+ $this->pollMapper->delete($poll);
+ }
}
}
diff --git a/tests/Unit/Factories/CommentFactory.php b/tests/Unit/Factories/CommentFactory.php
index dcd4077a..6a3d1e3e 100644
--- a/tests/Unit/Factories/CommentFactory.php
+++ b/tests/Unit/Factories/CommentFactory.php
@@ -28,11 +28,11 @@ use League\FactoryMuffin\Faker\Facade as Faker;
*/
$fm->define('OCA\Polls\Db\Comment')->setDefinitions([
'userId' => Faker::firstNameMale(),
- 'dt' => function() {
+ 'dt' => function () {
$date = new DateTime('today');
return $date->format('Y-m-d H:i:s');
},
- 'timestamp' => function() {
+ 'timestamp' => function () {
$date = new DateTime('today');
return $date->getTimestamp();
},
diff --git a/tests/Unit/Factories/LogFactory.php b/tests/Unit/Factories/LogFactory.php
new file mode 100644
index 00000000..779d390c
--- /dev/null
+++ b/tests/Unit/Factories/LogFactory.php
@@ -0,0 +1,39 @@
+<?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\Log')->setDefinitions([
+ 'created' => function () {
+ $date = new DateTime('yesterday');
+ return $date->getTimestamp();
+ },
+ 'processed' => 0,
+ 'userId' => Faker::firstNameMale(),
+ 'displayName' => Faker::lastName(),
+ 'messageId' => 'addPoll',
+ 'message' => Faker::text(255)
+]);
diff --git a/tests/Unit/Factories/OptionFactory.php b/tests/Unit/Factories/OptionFactory.php
index e714d67c..07f5f442 100644
--- a/tests/Unit/Factories/OptionFactory.php
+++ b/tests/Unit/Factories/OptionFactory.php
@@ -28,5 +28,7 @@ use League\FactoryMuffin\Faker\Facade as Faker;
*/
$fm->define('OCA\Polls\Db\Option')->setDefinitions([
'pollOptionText' => Faker::text(255),
- 'timestamp' => 0
+ 'timestamp' => 0,
+ 'order' => 0,
+ 'confirmed' => 0
]);
diff --git a/tests/Unit/Factories/PollFactory.php b/tests/Unit/Factories/PollFactory.php
index 1cb6fad3..e2e0de33 100644
--- a/tests/Unit/Factories/PollFactory.php
+++ b/tests/Unit/Factories/PollFactory.php
@@ -31,15 +31,15 @@ $fm->define('OCA\Polls\Db\Poll')->setDefinitions([
'title' => Faker::text(124),
'description' => Faker::text(255),
'owner' => Faker::firstNameMale(),
- 'created' => function() {
+ 'created' => function () {
$date = new DateTime('today');
return $date->getTimestamp();
},
- 'expire' => function() {
+ 'expire' => function () {
$date = new DateTime('tomorrow');
return $date->getTimestamp();
},
- 'deleted' => function() {
+ 'deleted' => function () {
$date = new DateTime('+1 month');
return $date->getTimestamp();
},
@@ -51,5 +51,6 @@ $fm->define('OCA\Polls\Db\Poll')->setDefinitions([
'settings' => '{"someJSON":0}',
'voteLimit' => 0,
'showResults' => 'always',
- 'adminAccess' => 0
+ 'adminAccess' => 0,
+ 'important' => 0
]);
diff --git a/tests/Unit/Factories/PreferencesFactory.php b/tests/Unit/Factories/PreferencesFactory.php
new file mode 100644
index 00000000..68a71a46
--- /dev/null
+++ b/tests/Unit/Factories/PreferencesFactory.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 poll model.
+ */
+$fm->define('OCA\Polls\Db\Preferences')->setDefinitions([
+ 'type' => 'textPoll',
+ 'timestamp' => function () {
+ $date = new DateTime('today');
+ return $date->getTimestamp();
+ },
+ 'preferences' => '{"someJSON":0}'
+]);
diff --git a/tests/Unit/Factories/ShareFactory.php b/tests/Unit/Factories/ShareFactory.php
new file mode 100644
index 00000000..389ea222
--- /dev/null
+++ b/tests/Unit/Factories/ShareFactory.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 poll model.
+ */
+$fm->define('OCA\Polls\Db\Share')->setDefinitions([
+ 'userId' => Faker::firstNameMale(),
+ 'emailAddress' => Faker::safeEmail(),
+ 'displayName' => Faker::lastName()
+]);
diff --git a/tests/Unit/Factories/VoteFactory.php b/tests/Unit/Factories/VoteFactory.php
index 5e5828fa..eee744b2 100644
--- a/tests/Unit/Factories/VoteFactory.php
+++ b/tests/Unit/Factories/VoteFactory.php
@@ -27,7 +27,7 @@ use League\FactoryMuffin\Faker\Facade as Faker;
* General factory for the vote model.
*/
$fm->define('OCA\Polls\Db\Vote')->setDefinitions([
- 'voteOptionText' => Faker::text(255),
'userId' => Faker::firstNameMale(),
+ 'voteOptionText' => Faker::text(255),
'voteAnswer' => 'yes'
]);