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
path: root/lib
diff options
context:
space:
mode:
authorKai Schröer <splitt3r@users.noreply.github.com>2017-11-07 17:43:45 +0300
committerGitHub <noreply@github.com>2017-11-07 17:43:45 +0300
commit6e11d77656cbc9387f275d0b71de73fbafda16fa (patch)
tree5effb3b584aac3e61f68ae0bf7377b3f9aac0d9d /lib
parent12511a1ba45a0ba457af48a8b26d8cb271ad0827 (diff)
Added Unit tests (#224)
* Added first unit test * Fixed user constraint problem * Fix tests * Update CommentMapperTest.php * Fixed FactoryMuffin + unit tests * Fixed PHP 5.6 error * Started adding scrutinizer coverage * Added UnitTestCase class * Added badges to README * Changed app logo name The icon is showing up in the app list now. * Added screenshot replacement to Makefile * Added oC branded screenshots * Added test skeletons * Added further factories * Added all basic crud unit tests * Fixed @depends in unit tests * Small doc block update
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php2
-rw-r--r--lib/Controller/PageController.php6
-rw-r--r--lib/Db/Comment.php12
-rw-r--r--lib/Db/Date.php12
-rw-r--r--lib/Db/Event.php32
-rw-r--r--lib/Db/EventMapper.php2
-rw-r--r--lib/Db/Model.php39
-rw-r--r--lib/Db/Notification.php8
-rw-r--r--lib/Db/NotificationMapper.php4
-rw-r--r--lib/Db/Participation.php16
-rw-r--r--lib/Db/ParticipationText.php12
-rw-r--r--lib/Db/Text.php8
12 files changed, 92 insertions, 61 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 810362d7..7febc09d 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -158,7 +158,7 @@ class Application extends App {
'id' => 'polls',
'order' => 77,
'href' => $urlGenerator->linkToRoute('polls.page.index'),
- 'icon' => $urlGenerator->imagePath('polls', 'app-logo-polls.svg'),
+ 'icon' => $urlGenerator->imagePath('polls', 'app.svg'),
'name' => $l10n->t('Polls')
];
});
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index a24673f8..d878a9d9 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -432,10 +432,12 @@ class PageController extends Controller {
$event->setDescription(htmlspecialchars($pollDesc));
$event->setOwner($userId);
$event->setCreated(date('Y-m-d H:i:s'));
- $event->setHash(\OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(16,
+ $event->setHash(\OC::$server->getSecureRandom()->generate(
+ 16,
ISecureRandom::CHAR_DIGITS .
ISecureRandom::CHAR_LOWER .
- ISecureRandom::CHAR_UPPER));
+ ISecureRandom::CHAR_UPPER
+ ));
$event->setIsAnonymous($isAnonymous ? 1 : 0);
$event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0);
diff --git a/lib/Db/Comment.php b/lib/Db/Comment.php
index 28b5ae35..bbfb5403 100644
--- a/lib/Db/Comment.php
+++ b/lib/Db/Comment.php
@@ -23,8 +23,6 @@
namespace OCA\Polls\Db;
-use OCP\AppFramework\Db\Entity;
-
/**
* @method string getUserId()
* @method void setUserId(string $value)
@@ -35,9 +33,9 @@ use OCP\AppFramework\Db\Entity;
* @method integer getPollId()
* @method void setPollId(integer $value)
*/
-class Comment extends Entity {
- public $userId;
- public $dt;
- public $comment;
- public $pollId;
+class Comment extends Model {
+ protected $userId;
+ protected $dt;
+ protected $comment;
+ protected $pollId;
}
diff --git a/lib/Db/Date.php b/lib/Db/Date.php
index d34a9a41..5363ec6a 100644
--- a/lib/Db/Date.php
+++ b/lib/Db/Date.php
@@ -23,15 +23,13 @@
namespace OCA\Polls\Db;
-use OCP\AppFramework\Db\Entity;
-
/**
- * @method timestamp getDt()
- * @method void setDt(timestamp $value)
+ * @method string getDt()
+ * @method void setDt(string $value)
* @method integer getPollId()
* @method void setPollId(integer $value)
*/
-class Date extends Entity {
- public $dt;
- public $pollId;
+class Date extends Model {
+ protected $dt;
+ protected $pollId;
}
diff --git a/lib/Db/Event.php b/lib/Db/Event.php
index df4c1ca8..f422f0b6 100644
--- a/lib/Db/Event.php
+++ b/lib/Db/Event.php
@@ -23,8 +23,6 @@
namespace OCA\Polls\Db;
-use OCP\AppFramework\Db\Entity;
-
/**
* @method integer getType()
* @method void setType(integer $value)
@@ -34,12 +32,12 @@ use OCP\AppFramework\Db\Entity;
* @method void setDescription(string $value)
* @method string getOwner()
* @method void setOwner(string $value)
- * @method timestamp getCreated()
- * @method void setCreated(timestamp $value)
+ * @method string getCreated()
+ * @method void setCreated(string $value)
* @method string getAccess()
* @method void setAccess(string $value)
- * @method timestamp getExpire()
- * @method void setExpire(timestamp $value)
+ * @method string getExpire()
+ * @method void setExpire(string $value)
* @method string getHash()
* @method void setHash(string $value)
* @method integer getIsAnonymous()
@@ -47,15 +45,15 @@ use OCP\AppFramework\Db\Entity;
* @method integer getFullAnonymous()
* @method void setFullAnonymous(integer $value)
*/
-class Event extends Entity {
- public $type;
- public $title;
- public $description;
- public $owner;
- public $created;
- public $access;
- public $expire;
- public $hash;
- public $isAnonymous;
- public $fullAnonymous;
+class Event extends Model {
+ protected $type;
+ protected $title;
+ protected $description;
+ protected $owner;
+ protected $created;
+ protected $access;
+ protected $expire;
+ protected $hash;
+ protected $isAnonymous;
+ protected $fullAnonymous;
}
diff --git a/lib/Db/EventMapper.php b/lib/Db/EventMapper.php
index 44ed6a84..dabb28ac 100644
--- a/lib/Db/EventMapper.php
+++ b/lib/Db/EventMapper.php
@@ -51,6 +51,8 @@ class EventMapper extends Mapper {
* @param $hash
* @param int $limit
* @param int $offset
+ * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
+ * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Event
*/
public function findByHash($hash, $limit = null, $offset = null) {
diff --git a/lib/Db/Model.php b/lib/Db/Model.php
new file mode 100644
index 00000000..087f4842
--- /dev/null
+++ b/lib/Db/Model.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/>.
+ *
+ */
+
+namespace OCA\Polls\Db;
+
+use OCP\AppFramework\Db\Entity;
+
+abstract class Model extends Entity {
+ /**
+ * FactoryMuffin checks for the existence of setters with method_exists($obj, $attr) but that returns false.
+ * By overwriting the __set() magic method we can trigger the changed flag on $obj->attr assignment.
+ *
+ * @param $name
+ * @param $value
+ */
+ public function __set($name, $value) {
+ $this->setter($name, [$value]);
+ }
+}
diff --git a/lib/Db/Notification.php b/lib/Db/Notification.php
index eb5c2180..53d717dc 100644
--- a/lib/Db/Notification.php
+++ b/lib/Db/Notification.php
@@ -23,15 +23,13 @@
namespace OCA\Polls\Db;
-use OCP\AppFramework\Db\Entity;
-
/**
* @method string getUserId()
* @method void setUserId(string $value)
* @method string getPollId()
* @method void setPollId(string $value)
*/
-class Notification extends Entity {
- public $userId;
- public $pollId;
+class Notification extends Model {
+ protected $userId;
+ protected $pollId;
}
diff --git a/lib/Db/NotificationMapper.php b/lib/Db/NotificationMapper.php
index c5ee3b38..38b73b74 100644
--- a/lib/Db/NotificationMapper.php
+++ b/lib/Db/NotificationMapper.php
@@ -80,7 +80,9 @@ class NotificationMapper extends Mapper {
/**
* @param string $pollId
* @param string $userId
- * @return Notification if not found
+ * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
+ * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
+ * @return Notification
*/
public function findByUserAndPoll($pollId, $userId) {
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
diff --git a/lib/Db/Participation.php b/lib/Db/Participation.php
index a8494c86..317561dc 100644
--- a/lib/Db/Participation.php
+++ b/lib/Db/Participation.php
@@ -23,11 +23,9 @@
namespace OCA\Polls\Db;
-use OCP\AppFramework\Db\Entity;
-
/**
- * @method timestamp getDt()
- * @method void setDt(timestamp $value)
+ * @method string getDt()
+ * @method void setDt(string $value)
* @method string getUserId()
* @method void setUserId(string $value)
* @method integer getPollId()
@@ -35,9 +33,9 @@ use OCP\AppFramework\Db\Entity;
* @method integer getType()
* @method void setType(integer $value)
*/
-class Participation extends Entity {
- public $dt;
- public $userId;
- public $pollId;
- public $type;
+class Participation extends Model {
+ protected $dt;
+ protected $userId;
+ protected $pollId;
+ protected $type;
}
diff --git a/lib/Db/ParticipationText.php b/lib/Db/ParticipationText.php
index 6fd05cca..064c50d3 100644
--- a/lib/Db/ParticipationText.php
+++ b/lib/Db/ParticipationText.php
@@ -23,8 +23,6 @@
namespace OCA\Polls\Db;
-use OCP\AppFramework\Db\Entity;
-
/**
* @method text getText()
* @method void setText(text $value)
@@ -35,9 +33,9 @@ use OCP\AppFramework\Db\Entity;
* @method integer getType()
* @method void setType(integer $value)
*/
-class ParticipationText extends Entity {
- public $text;
- public $userId;
- public $pollId;
- public $type;
+class ParticipationText extends Model {
+ protected $text;
+ protected $userId;
+ protected $pollId;
+ protected $type;
}
diff --git a/lib/Db/Text.php b/lib/Db/Text.php
index 792e4caf..c888dbdc 100644
--- a/lib/Db/Text.php
+++ b/lib/Db/Text.php
@@ -23,15 +23,13 @@
namespace OCA\Polls\Db;
-use OCP\AppFramework\Db\Entity;
-
/**
* @method string getText()
* @method void setText(string $value)
* @method integer getPollId()
* @method void setPollId(integer $value)
*/
-class Text extends Entity {
- public $text;
- public $pollId;
+class Text extends Model {
+ protected $text;
+ protected $pollId;
}