diff options
author | dartcafe <github@dartcafe.de> | 2019-12-21 23:01:06 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2019-12-21 23:01:06 +0300 |
commit | 923fe1897f3f6962d95a94577b2d03ae5bc512ad (patch) | |
tree | 5c9031d3dfdf4969d98c2377767045e2294a9c35 | |
parent | 9d015be1fa920e002a2f9cbacdfdafacbe807357 (diff) |
Prepare mail notification and update tests
-rw-r--r-- | lib/Db/Notice.php | 68 | ||||
-rw-r--r-- | lib/Db/NoticeMapper.php | 60 | ||||
-rw-r--r-- | lib/Migration/Version0010Date20191221183157.php | 104 | ||||
-rw-r--r-- | tests/Unit/Controller/PageControllerTest.php | 4 | ||||
-rw-r--r-- | tests/Unit/Db/SubscriptionMapperTest.php (renamed from tests/Unit/Db/NotificationMapperTest.php) | 44 | ||||
-rw-r--r-- | tests/Unit/Factories/SubscriptionFactory.php (renamed from tests/Unit/Factories/NotificationFactory.php) | 4 |
6 files changed, 258 insertions, 26 deletions
diff --git a/lib/Db/Notice.php b/lib/Db/Notice.php new file mode 100644 index 00000000..2ddbac13 --- /dev/null +++ b/lib/Db/Notice.php @@ -0,0 +1,68 @@ +<?php +/** + * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com> + * + * @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com> + * @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\Db; + +use JsonSerializable; + +use OCP\AppFramework\Db\Entity; + +/** + * @method integer getPollId() + * @method void setPollId(integer $value) + * @method integer getChannel() + * @method void setChannel(integer $value) + * @method integer getUserId() + * @method void setUserId(integer $value) + * @method integer getUserEmail() + * @method void setUserEmail(integer $value) + * @method integer getDisplayName() + * @method void setDisplayName(integer $value) + * @method integer getMessageId() + * @method void setMessageId(integer $value) + * @method string getMessage() + * @method void setMessage(string $value) + */ +class Notice extends Entity implements JsonSerializable { + protected $pollId; + protected $channel; + protected $userId; + protected $userEmail; + protected $displayName; + protected $messageId; + protected $message; + + public function jsonSerialize() { + return [ + 'id' => $this->id, + 'pollId' => $this->pollId, + 'channel' => $this->channel, + 'userId' => $this->userId, + 'userEmail' => $this->userEmail, + 'displayName' => $this->displayName, + 'message_id' => $this->messageId, + 'message' => $this->message + ]; + } +} diff --git a/lib/Db/NoticeMapper.php b/lib/Db/NoticeMapper.php new file mode 100644 index 00000000..0b75edb1 --- /dev/null +++ b/lib/Db/NoticeMapper.php @@ -0,0 +1,60 @@ +<?php +/** + * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com> + * + * @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com> + * @author René Gieling <github@dartcafe.de> +* + * @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\Db; + +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IDBConnection; +use OCP\AppFramework\Db\QBMapper; + +class NoticeMapper extends QBMapper { + + /** + * NotificationMapper constructor. + * @param IDBConnection $db + */ + public function __construct(IDBConnection $db) { + parent::__construct($db, 'polls_notice', '\OCA\Polls\Db\Notice'); + } + + /** + * @param int $pollId + * @throws \OCP\AppFramework\Db\DoesNotExistException if not found + * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result + * @return array + */ + + public function findAllByPoll($pollId) { + $qb = $this->db->getQueryBuilder(); + + $qb->select('*') + ->from($this->getTableName()) + ->where( + $qb->expr()->eq('poll_id', $qb->createNamedParameter($pollId, IQueryBuilder::PARAM_INT)) + ); + + return $this->findEntities($qb); + } + +} diff --git a/lib/Migration/Version0010Date20191221183157.php b/lib/Migration/Version0010Date20191221183157.php new file mode 100644 index 00000000..98b26af5 --- /dev/null +++ b/lib/Migration/Version0010Date20191221183157.php @@ -0,0 +1,104 @@ +<?php +/** + * @copyright Copyright (c) 2017 René Gieling <github@dartcafe.de> + * + * @author René Gieling <github@dartcafe.de> + * + * @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\Migration; + +// use Doctrine\DBAL\Exception\TableNotFoundException; +// use Doctrine\DBAL\Platforms\PostgreSqlPlatform; +use Doctrine\DBAL\Types\Type; +use OCP\DB\ISchemaWrapper; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Migration\SimpleMigrationStep; +use OCP\Migration\IOutput; +use OCP\Security\ISecureRandom; + +/** + * Installation class for the polls app. + * Initial db creation + */ +class Version0010Date20191221183157 extends SimpleMigrationStep { + + /** @var IDBConnection */ + protected $connection; + + /** @var IConfig */ + protected $config; + + /** + * @param IDBConnection $connection + * @param IConfig $config + */ + public function __construct(IDBConnection $connection, IConfig $config) { + $this->connection = $connection; + $this->config = $config; + } + + /** + * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + * @since 13.0.0 + */ + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + if (!$schema->hasTable('polls_send_mail')) { + $table = $schema->createTable('polls_send_mail'); + $table->addColumn('id', Type::INTEGER, [ + 'autoincrement' => true, + 'notnull' => true, + ]); + $table->addColumn('poll_id', Type::INTEGER, [ + 'notnull' => true + ]); + $table->addColumn('user_id', Type::STRING, [ + 'notnull' => false, + 'length' => 1024 + ]); + $table->addColumn('user_email', Type::STRING, [ + 'notnull' => false, + 'length' => 1024 + ]); + $table->addColumn('display_name', Type::STRING, [ + 'notnull' => false, + 'length' => 64 + ]); + $table->addColumn('message_id', Type::STRING, [ + 'notnull' => false, + 'length' => 64 + ]); + $table->addColumn('message', Type::STRING, [ + 'notnull' => false, + 'length' => 1024 + ]); + $table->setPrimaryKey(['id']); + } + + return $schema; + } + +} diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index e73f8c0a..cbf14159 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -80,7 +80,7 @@ class PageControllerTest extends UnitTestCase { $eventMapper = $this->getMockBuilder('OCA\Polls\Db\EventMapper') ->disableOriginalConstructor() ->getMock(); - $notificationMapper = $this->getMockBuilder('OCA\Polls\Db\NotificationMapper') + $subscriptionMapper = $this->getMockBuilder('OCA\Polls\Db\SubscriptionMapper') ->disableOriginalConstructor() ->getMock(); $voteMapper = $this->getMockBuilder('OCA\Polls\Db\VoteMapper') @@ -102,7 +102,7 @@ class PageControllerTest extends UnitTestCase { $commentMapper, $optionMapper, $eventMapper, - $notificationMapper, + $subscriptionMapper, $voteMapper, $mailer ); diff --git a/tests/Unit/Db/NotificationMapperTest.php b/tests/Unit/Db/SubscriptionMapperTest.php index 6f07eb50..4a2c64d2 100644 --- a/tests/Unit/Db/NotificationMapperTest.php +++ b/tests/Unit/Db/SubscriptionMapperTest.php @@ -25,18 +25,18 @@ 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\Db\Subscription; +use OCA\Polls\Db\SubscriptionMapper; use OCA\Polls\Tests\Unit\UnitTestCase; use OCP\IDBConnection; use League\FactoryMuffin\Faker\Facade as Faker; -class NotificationMapperTest extends UnitTestCase { +class SubscriptionMapperTest extends UnitTestCase { /** @var IDBConnection */ private $con; - /** @var NotificationMapper */ - private $notificationMapper; + /** @var SubscriptionMapper */ + private $subscriptionMapper; /** @var EventMapper */ private $eventMapper; @@ -46,52 +46,52 @@ class NotificationMapperTest extends UnitTestCase { protected function setUp(): void { parent::setUp(); $this->con = \OC::$server->getDatabaseConnection(); - $this->notificationMapper = new NotificationMapper($this->con); + $this->subscriptionMapper = new SubscriptionMapper($this->con); $this->eventMapper = new EventMapper($this->con); } /** * Create some fake data and persist them to the database. * - * @return Notification + * @return Subscription */ 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)); + /** @var Subscription $subscription */ + $subscription = $this->fm->instance('OCA\Polls\Db\Subscription'); + $subscription->setPollId($event->getId()); + $this->assertInstanceOf(Subscription::class, $this->subscriptionMapper->insert($subscription)); - return $notification; + return $subscription; } /** * Update the previously created entry and persist the changes. * * @depends testCreate - * @param Notification $notification - * @return Notification + * @param Subscription $subscription + * @return Subscription */ - public function testUpdate(Notification $notification) { + public function testUpdate(Subscription $subscription) { $newUserId = Faker::firstNameMale(); - $notification->setUserId($newUserId()); - $this->notificationMapper->update($notification); + $subscription->setUserId($newUserId()); + $this->subscriptionMapper->update($subscription); - return $notification; + return $subscription; } /** * Delete the previously created entries from the database. * * @depends testUpdate - * @param Notification $notification + * @param Subscription $subscription */ - public function testDelete(Notification $notification) { - $event = $this->eventMapper->find($notification->getPollId()); - $this->notificationMapper->delete($notification); + public function testDelete(Subscription $subscription) { + $event = $this->eventMapper->find($subscription->getPollId()); + $this->subscriptionMapper->delete($subscription); $this->eventMapper->delete($event); } } diff --git a/tests/Unit/Factories/NotificationFactory.php b/tests/Unit/Factories/SubscriptionFactory.php index 6db9d60b..4e97f153 100644 --- a/tests/Unit/Factories/NotificationFactory.php +++ b/tests/Unit/Factories/SubscriptionFactory.php @@ -24,8 +24,8 @@ use League\FactoryMuffin\Faker\Facade as Faker; /** - * General factory for the notification model. + * General factory for the Subscription model. */ -$fm->define('OCA\Polls\Db\Notification')->setDefinitions([ +$fm->define('OCA\Polls\Db\Subscription')->setDefinitions([ 'userId' => Faker::firstNameMale() ]); |