diff options
author | René Gieling <github@dartcafe.de> | 2020-11-30 22:28:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-30 22:28:25 +0300 |
commit | d2eee9bd2b71361b7ad5db9cccf8003eadb7ad9d (patch) | |
tree | f28ab7eaf06d0b2d7d0570cb0291a1ce15d03fa0 /tests | |
parent | cccca2d1525500743493ad9e06e3f84838dec7d0 (diff) |
use github CI and PHPUnit (#1257) (#1269)
* use github CI and PHPUnit (#1257)
* CommentMapperTest
* LogMapperTest
* SubscriptionMapperTest
* all mappers
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Integration/app/AppTest.php (renamed from tests/Integration/AppTest.php) | 0 | ||||
-rw-r--r-- | tests/Unit/Db/CommentMapperTest.php | 99 | ||||
-rw-r--r-- | tests/Unit/Db/LogMapperTest.php | 142 | ||||
-rw-r--r-- | tests/Unit/Db/OptionMapperTest.php | 97 | ||||
-rw-r--r-- | tests/Unit/Db/PollMapperTest.php | 70 | ||||
-rw-r--r-- | tests/Unit/Db/SubscriptionMapperTest.php | 93 | ||||
-rw-r--r-- | tests/Unit/Db/VoteMapperTest.php | 139 | ||||
-rw-r--r-- | tests/Unit/Factories/CommentFactory.php | 4 | ||||
-rw-r--r-- | tests/Unit/Factories/LogFactory.php | 39 | ||||
-rw-r--r-- | tests/Unit/Factories/OptionFactory.php | 4 | ||||
-rw-r--r-- | tests/Unit/Factories/PollFactory.php | 9 | ||||
-rw-r--r-- | tests/Unit/Factories/PreferencesFactory.php | 36 | ||||
-rw-r--r-- | tests/Unit/Factories/ShareFactory.php | 33 | ||||
-rw-r--r-- | tests/Unit/Factories/VoteFactory.php | 2 | ||||
-rw-r--r-- | tests/bootstrap.php | 12 | ||||
-rw-r--r-- | tests/phpunit.integration.xml | 12 | ||||
-rw-r--r-- | tests/phpunit.xml | 12 |
17 files changed, 616 insertions, 187 deletions
diff --git a/tests/Integration/AppTest.php b/tests/Integration/app/AppTest.php index 3255b35e..3255b35e 100644 --- a/tests/Integration/AppTest.php +++ b/tests/Integration/app/AppTest.php 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' ]); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 0e518521..5ef2f4c0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -21,15 +21,5 @@ * */ -if (!defined('PHPUNIT_RUN')) { - define('PHPUNIT_RUN', 1); -} - -require_once __DIR__ . '/../../../lib/base.php'; +require_once __DIR__ . '/../../../tests/bootstrap.php'; require_once __DIR__ . '/../vendor/autoload.php'; - -\OC::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); -\OC_App::loadApp('polls'); - - -\OC_Hook::clear(); diff --git a/tests/phpunit.integration.xml b/tests/phpunit.integration.xml new file mode 100644 index 00000000..e664e029 --- /dev/null +++ b/tests/phpunit.integration.xml @@ -0,0 +1,12 @@ +<phpunit bootstrap="bootstrap.php" colors="true"> + <testsuites> + <testsuite name="integration-app"> + <directory>./integration/app</directory> + </testsuite> + </testsuites> + <filter> + <whitelist> + <directory suffix=".php">./../lib</directory> + </whitelist> + </filter> +</phpunit> diff --git a/tests/phpunit.xml b/tests/phpunit.xml new file mode 100644 index 00000000..b12b942a --- /dev/null +++ b/tests/phpunit.xml @@ -0,0 +1,12 @@ +<phpunit bootstrap="../../../tests/bootstrap.php" colors="true"> + <filter> + <whitelist> + <directory suffix=".php">lib</directory> + </whitelist> + </filter> + <testsuites> + <testsuite name="unit"> + <directory>./Unit</directory> + </testsuite> + </testsuites> +</phpunit> |