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:
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
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
-rw-r--r--.editorconfig2
-rw-r--r--.gitignore7
-rw-r--r--.scrutinizer.yml20
-rw-r--r--.scss-lint.yml6
-rw-r--r--.travis.yml5
-rw-r--r--Makefile5
-rw-r--r--README.md7
-rwxr-xr-xappinfo/info.xml6
-rw-r--r--composer.json11
-rw-r--r--img/app.svg (renamed from img/app-logo-polls.svg)0
-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
-rw-r--r--phpunit.xml5
-rw-r--r--screenshots/new-poll-oc.pngbin0 -> 34472 bytes
-rw-r--r--screenshots/overview-oc.pngbin0 -> 34386 bytes
-rw-r--r--screenshots/vote-oc.pngbin0 -> 35905 bytes
-rw-r--r--tests/Integration/AppTest.php4
-rw-r--r--tests/Unit/Controller/PageControllerTest.php18
-rw-r--r--tests/Unit/Db/CommentMapperTest.php97
-rw-r--r--tests/Unit/Db/DateMapperTest.php97
-rw-r--r--tests/Unit/Db/EventMapperTest.php87
-rw-r--r--tests/Unit/Db/NotificationMapperTest.php97
-rw-r--r--tests/Unit/Db/ParticipationMapperTest.php97
-rw-r--r--tests/Unit/Db/ParticipationTextMapperTest.php97
-rw-r--r--tests/Unit/Db/TextMapperTest.php97
-rw-r--r--tests/Unit/Factories/CommentFactory.php36
-rw-r--r--tests/Unit/Factories/DateFactory.php32
-rw-r--r--tests/Unit/Factories/EventFactory.php46
-rw-r--r--tests/Unit/Factories/NotificationFactory.php31
-rw-r--r--tests/Unit/Factories/ParticipationFactory.php36
-rw-r--r--tests/Unit/Factories/ParticipationTextFactory.php33
-rw-r--r--tests/Unit/Factories/TextFactory.php31
-rw-r--r--tests/Unit/UnitTestCase.php42
-rw-r--r--tests/bootstrap.php14
44 files changed, 1124 insertions, 95 deletions
diff --git a/.editorconfig b/.editorconfig
index 1e61cd2f..b71a69eb 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -20,6 +20,6 @@ trim_trailing_whitespace = true
max_line_length = 80
# 2 space indentation for .travis.yml
-[.travis.yml]
+[.*.yml]
indent_style = space
indent_size = 2
diff --git a/.gitignore b/.gitignore
index f861fb09..eb6a6e9d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,8 @@
-/.project
+build/
+vendor/
+.project/
.idea/
+*.lock
*.iml
+.DS_Store
+Thumbs.db
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
index a546f6e4..4d5f84ad 100644
--- a/.scrutinizer.yml
+++ b/.scrutinizer.yml
@@ -1,13 +1,17 @@
filter:
- excluded_paths:
- - 'l10n/*'
- - 'js/vendor/*'
+ excluded_paths:
+ - 'l10n/*'
+ - 'js/vendor/*'
imports:
- - javascript
- - php
+ - javascript
+ - php
+
+tools:
+ external_code_coverage:
+ timeout: 1000
build:
- tests:
- override:
- - jshint-run --config js/.jshintrc
+ tests:
+ override:
+ - jshint-run --config js/.jshintrc
diff --git a/.scss-lint.yml b/.scss-lint.yml
index 958ad170..01e0396d 100644
--- a/.scss-lint.yml
+++ b/.scss-lint.yml
@@ -1,4 +1,4 @@
build:
- tests:
- override:
- - scss-lint-run /css
+ tests:
+ override:
+ - scss-lint-run /css
diff --git a/.travis.yml b/.travis.yml
index 8dc5d7ca..01349c8e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -51,5 +51,10 @@ script:
# Execute tests
- make test
+after_success:
+ # Generate Code Coverage
+ - wget https://scrutinizer-ci.com/ocular.phar
+ - php ocular.phar code-coverage:upload --format=php-clover clover.xml
+
after_failure:
- cat ../../data/${CLOUD}.log
diff --git a/Makefile b/Makefile
index 0a281a06..a2953bac 100644
--- a/Makefile
+++ b/Makefile
@@ -129,6 +129,9 @@ else
--exclude="css/*.scss" \
./ $(build_source_directory)/$(app_name)
+ # We need to replace Nc screenshot urls with the oC ones
+ sed -i -E "s~(<screenshot>)([^<]*).(png|jpg|jpeg)(</screenshot>)~\1\2-oc.\3\4~" $(build_source_directory)/$(app_name)/appinfo/info.xml
+
@if [ -f $(oc_cert_directory)/$(app_name).key ]; then \
echo "Creating integrity file..."; \
php ../../occ integrity:sign-app --privateKey="$(oc_cert_directory)/$(app_name).key" --certificate="$(oc_cert_directory)/$(app_name).crt" --path "$(build_source_directory)/$(app_name)"; \
@@ -144,5 +147,5 @@ endif
.PHONY: test
test: composer
- $(CURDIR)/vendor/phpunit/phpunit/phpunit -c phpunit.xml
+ $(CURDIR)/vendor/phpunit/phpunit/phpunit --coverage-clover clover.xml -c phpunit.xml
$(CURDIR)/vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml
diff --git a/README.md b/README.md
index 70d831c1..8f5aa6ad 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,9 @@
# Polls
-[![Build Status](https://travis-ci.org/nextcloud/polls.svg?branch=master)](https://travis-ci.org/nextcloud/polls)
+[![Build Status](https://img.shields.io/travis/nextcloud/polls.svg?style=flat-square)](https://travis-ci.org/nextcloud/polls)
+[![Scrutinizer](https://img.shields.io/scrutinizer/g/nextcloud/polls.svg?style=flat-square)](https://scrutinizer-ci.com/g/nextcloud/polls)
+[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/nextcloud/polls.svg?style=flat-square)](https://scrutinizer-ci.com/g/nextcloud/polls)
+[![Software License](https://img.shields.io/badge/license-AGPL-brightgreen.svg?style=flat-square)](LICENSE)
This is a poll app, similar to doodle or dudle, for Nextcloud / ownCloud written in PHP and JS / jQuery.
It is a rework of the already existing [polls app](https://github.com/raduvatav/polls) written by @raduvatav.
@@ -16,7 +19,9 @@ It is a rework of the already existing [polls app](https://github.com/raduvatav/
### Screenshots
![Overview](https://github.com/nextcloud/polls/blob/master/screenshots/overview.png)
+
![Vote](https://github.com/nextcloud/polls/blob/master/screenshots/vote.png)
+
![New poll](https://github.com/nextcloud/polls/blob/master/screenshots/new-poll.png)
## Installation / Update
diff --git a/appinfo/info.xml b/appinfo/info.xml
index f6330b70..e5d735cc 100755
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -8,6 +8,8 @@
<version>0.8.0</version>
<licence>agpl</licence>
<author>Vinzenz Rosenkranz</author>
+ <author>René Gieling</author>
+ <author>Kai Schröer</author>
<documentation>
<admin>https://github.com/nextcloud/polls/blob/master/README.md</admin>
</documentation>
@@ -15,9 +17,11 @@
<website>https://github.com/nextcloud/polls</website>
<bugs>https://github.com/nextcloud/polls/issues</bugs>
<repository type="git">https://github.com/nextcloud/polls.git</repository>
+ <screenshot>https://raw.githubusercontent.com/nextcloud/polls/master/screenshots/overview.png</screenshot>
+ <screenshot>https://raw.githubusercontent.com/nextcloud/polls/master/screenshots/vote.png</screenshot>
<screenshot>https://raw.githubusercontent.com/nextcloud/polls/master/screenshots/new-poll.png</screenshot>
<dependencies>
- <owncloud min-version="8.2" max-version="10.0"/>
+ <owncloud min-version="8.2" max-version="10.0" />
<nextcloud min-version="11" max-version="13" />
</dependencies>
<ocsid>174671</ocsid>
diff --git a/composer.json b/composer.json
index 6874762b..6fd16160 100644
--- a/composer.json
+++ b/composer.json
@@ -1,14 +1,19 @@
{
"name": "polls",
- "description": "This is a poll app, similar to doodle or dudle with the possibility for restrict access (only members, certain groups/users, hidden and public).",
"type": "project",
- "license": "AGPL",
+ "license": "AGPLv3",
"authors": [
{
"name": "Vinzenz Rosenkranz"
+ },
+ {
+ "name": "Kai Schröer"
}
],
"require-dev": {
- "phpunit/phpunit": "^5.4"
+ "christophwurst/nextcloud": "^12.0",
+ "phpunit/phpunit": "^5.4",
+ "league/factory-muffin": "^3.0",
+ "league/factory-muffin-faker": "^2.0"
}
}
diff --git a/img/app-logo-polls.svg b/img/app.svg
index 136e6590..136e6590 100644
--- a/img/app-logo-polls.svg
+++ b/img/app.svg
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;
}
diff --git a/phpunit.xml b/phpunit.xml
index 82c96d6c..ac369548 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,4 +1,9 @@
<phpunit bootstrap="tests/bootstrap.php" colors="true">
+ <filter>
+ <whitelist>
+ <directory suffix=".php">lib</directory>
+ </whitelist>
+ </filter>
<testsuites>
<testsuite name="unit">
<directory>./tests/Unit</directory>
diff --git a/screenshots/new-poll-oc.png b/screenshots/new-poll-oc.png
new file mode 100644
index 00000000..d90fa591
--- /dev/null
+++ b/screenshots/new-poll-oc.png
Binary files differ
diff --git a/screenshots/overview-oc.png b/screenshots/overview-oc.png
new file mode 100644
index 00000000..5c9407cc
--- /dev/null
+++ b/screenshots/overview-oc.png
Binary files differ
diff --git a/screenshots/vote-oc.png b/screenshots/vote-oc.png
new file mode 100644
index 00000000..6b94adbc
--- /dev/null
+++ b/screenshots/vote-oc.png
Binary files differ
diff --git a/tests/Integration/AppTest.php b/tests/Integration/AppTest.php
index 3e07ab3c..346eace3 100644
--- a/tests/Integration/AppTest.php
+++ b/tests/Integration/AppTest.php
@@ -1,8 +1,8 @@
<?php
/**
- * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co>
*
- * @author Kai Schröer <kai@schroeer.co>
+ * @author Kai Schröer <git@schroeer.co>
*
* @license GNU AGPL version 3 or any later version
*
diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php
index 9090d0cf..302d44fe 100644
--- a/tests/Unit/Controller/PageControllerTest.php
+++ b/tests/Unit/Controller/PageControllerTest.php
@@ -1,8 +1,8 @@
<?php
/**
- * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co>
*
- * @author Kai Schröer <kai@schroeer.co>
+ * @author Kai Schröer <git@schroeer.co>
*
* @license GNU AGPL version 3 or any later version
*
@@ -24,14 +24,19 @@
namespace OCA\Polls\Tests\Unit\Controller;
use OCA\Polls\Controller\PageController;
+use OCA\Polls\Tests\Unit\UnitTestCase;
use OCP\AppFramework\Http\TemplateResponse;
-use PHPUnit_Framework_TestCase;
-class PageControllerTest extends PHPUnit_Framework_TestCase {
+class PageControllerTest extends UnitTestCase {
+ /** @var PageController */
private $controller;
+
private $userId = 'john';
+ /**
+ * {@inheritDoc}
+ */
public function setUp() {
$request = $this->getMockBuilder('OCP\IRequest')
->disableOriginalConstructor()
@@ -96,10 +101,13 @@ class PageControllerTest extends PHPUnit_Framework_TestCase {
);
}
+ /**
+ * Basic controller index route test.
+ */
public function testIndex() {
$result = $this->controller->index();
$this->assertEquals('main.tmpl', $result->getTemplateName());
- $this->assertTrue($result instanceof TemplateResponse);
+ $this->assertInstanceOf(TemplateResponse::class, $result);
}
}
diff --git a/tests/Unit/Db/CommentMapperTest.php b/tests/Unit/Db/CommentMapperTest.php
new file mode 100644
index 00000000..7cd845dd
--- /dev/null
+++ b/tests/Unit/Db/CommentMapperTest.php
@@ -0,0 +1,97 @@
+<?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\Comment;
+use OCA\Polls\Db\CommentMapper;
+use OCA\Polls\Db\Event;
+use OCA\Polls\Db\EventMapper;
+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 EventMapper */
+ private $eventMapper;
+
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp() {
+ parent::setUp();
+ $this->con = \OC::$server->getDatabaseConnection();
+ $this->commentMapper = new CommentMapper($this->con);
+ $this->eventMapper = new EventMapper($this->con);
+ }
+
+ /**
+ * Create some fake data and persist them to the database.
+ *
+ * @return Comment
+ */
+ public function testCreate() {
+ /** @var Event $event */
+ $event = $this->fm->instance('OCA\Polls\Db\Event');
+ $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event));
+
+ /** @var Comment $comment */
+ $comment = $this->fm->instance('OCA\Polls\Db\Comment');
+ $comment->setPollId($event->getId());
+ $this->assertInstanceOf(Comment::class, $this->commentMapper->insert($comment));
+
+ return $comment;
+ }
+
+ /**
+ * Update the previously created entry and persist the changes.
+ *
+ * @depends testCreate
+ * @param Comment $comment
+ * @return Comment
+ */
+ public function testUpdate(Comment $comment) {
+ $newComment = Faker::paragraph();
+ $comment->setComment($newComment());
+ $this->commentMapper->update($comment);
+
+ return $comment;
+ }
+
+ /**
+ * Delete the previously created entries from the database.
+ *
+ * @depends testUpdate
+ * @param Comment $comment
+ */
+ public function testDelete(Comment $comment) {
+ $event = $this->eventMapper->find($comment->getPollId());
+ $this->commentMapper->delete($comment);
+ $this->eventMapper->delete($event);
+ }
+}
diff --git a/tests/Unit/Db/DateMapperTest.php b/tests/Unit/Db/DateMapperTest.php
new file mode 100644
index 00000000..7b02b68e
--- /dev/null
+++ b/tests/Unit/Db/DateMapperTest.php
@@ -0,0 +1,97 @@
+<?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\Date;
+use OCA\Polls\Db\DateMapper;
+use OCA\Polls\Db\Event;
+use OCA\Polls\Db\EventMapper;
+use OCA\Polls\Tests\Unit\UnitTestCase;
+use OCP\IDBConnection;
+use League\FactoryMuffin\Faker\Facade as Faker;
+
+class DateMapperTest extends UnitTestCase {
+
+ /** @var IDBConnection */
+ private $con;
+ /** @var DateMapper */
+ private $dateMapper;
+ /** @var EventMapper */
+ private $eventMapper;
+
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp() {
+ parent::setUp();
+ $this->con = \OC::$server->getDatabaseConnection();
+ $this->dateMapper = new DateMapper($this->con);
+ $this->eventMapper = new EventMapper($this->con);
+ }
+
+ /**
+ * Create some fake data and persist them to the database.
+ *
+ * @return Date
+ */
+ 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));
+
+ return $date;
+ }
+
+ /**
+ * Update the previously created entry and persist the changes.
+ *
+ * @depends testCreate
+ * @param Date $date
+ * @return Date
+ */
+ public function testUpdate(Date $date) {
+ $newDt = Faker::date('Y-m-d H:i:s');
+ $date->setDt($newDt());
+ $this->dateMapper->update($date);
+
+ return $date;
+ }
+
+ /**
+ * Delete the previously created entries from the database.
+ *
+ * @depends testUpdate
+ * @param Date $date
+ */
+ public function testDelete(Date $date) {
+ $event = $this->eventMapper->find($date->getPollId());
+ $this->dateMapper->delete($date);
+ $this->eventMapper->delete($event);
+ }
+}
diff --git a/tests/Unit/Db/EventMapperTest.php b/tests/Unit/Db/EventMapperTest.php
new file mode 100644
index 00000000..3c7b1a8f
--- /dev/null
+++ b/tests/Unit/Db/EventMapperTest.php
@@ -0,0 +1,87 @@
+<?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\Tests\Unit\UnitTestCase;
+use OCP\IDBConnection;
+use League\FactoryMuffin\Faker\Facade as Faker;
+
+class EventMapperTest extends UnitTestCase {
+
+ /** @var IDBConnection */
+ private $con;
+ /** @var EventMapper */
+ private $eventMapper;
+
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp() {
+ parent::setUp();
+ $this->con = \OC::$server->getDatabaseConnection();
+ $this->eventMapper = new EventMapper($this->con);
+ }
+
+ /**
+ * Create some fake data and persist them to the database.
+ *
+ * @return Event
+ */
+ public function testCreate() {
+ /** @var Event $event */
+ $event = $this->fm->instance('OCA\Polls\Db\Event');
+ $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event));
+
+ return $event;
+ }
+
+ /**
+ * Update the previously created entry and persist the changes.
+ *
+ * @depends testCreate
+ * @param Event $event
+ * @return Event
+ */
+ public function testUpdate(Event $event) {
+ $newTitle = Faker::sentence(10);
+ $newDescription = Faker::paragraph();
+ $event->setTitle($newTitle());
+ $event->setDescription($newDescription());
+ $this->eventMapper->update($event);
+
+ return $event;
+ }
+
+ /**
+ * Delete the previously created entry from the database.
+ *
+ * @depends testUpdate
+ * @param Event $event
+ */
+ public function testDelete(Event $event) {
+ $this->eventMapper->delete($event);
+ }
+}
diff --git a/tests/Unit/Db/NotificationMapperTest.php b/tests/Unit/Db/NotificationMapperTest.php
new file mode 100644
index 00000000..96d67226
--- /dev/null
+++ b/tests/Unit/Db/NotificationMapperTest.php
@@ -0,0 +1,97 @@
+<?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\Notification;
+use OCA\Polls\Db\NotificationMapper;
+use OCA\Polls\Tests\Unit\UnitTestCase;
+use OCP\IDBConnection;
+use League\FactoryMuffin\Faker\Facade as Faker;
+
+class NotificationMapperTest extends UnitTestCase {
+
+ /** @var IDBConnection */
+ private $con;
+ /** @var NotificationMapper */
+ private $notificationMapper;
+ /** @var EventMapper */
+ private $eventMapper;
+
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp() {
+ parent::setUp();
+ $this->con = \OC::$server->getDatabaseConnection();
+ $this->notificationMapper = new NotificationMapper($this->con);
+ $this->eventMapper = new EventMapper($this->con);
+ }
+
+ /**
+ * Create some fake data and persist them to the database.
+ *
+ * @return Notification
+ */
+ 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));
+
+ return $notification;
+ }
+
+ /**
+ * Update the previously created entry and persist the changes.
+ *
+ * @depends testCreate
+ * @param Notification $notification
+ * @return Notification
+ */
+ public function testUpdate(Notification $notification) {
+ $newUserId = Faker::firstNameMale();
+ $notification->setUserId($newUserId());
+ $this->notificationMapper->update($notification);
+
+ return $notification;
+ }
+
+ /**
+ * Delete the previously created entries from the database.
+ *
+ * @depends testUpdate
+ * @param Notification $notification
+ */
+ public function testDelete(Notification $notification) {
+ $event = $this->eventMapper->find($notification->getPollId());
+ $this->notificationMapper->delete($notification);
+ $this->eventMapper->delete($event);
+ }
+}
diff --git a/tests/Unit/Db/ParticipationMapperTest.php b/tests/Unit/Db/ParticipationMapperTest.php
new file mode 100644
index 00000000..365ce205
--- /dev/null
+++ b/tests/Unit/Db/ParticipationMapperTest.php
@@ -0,0 +1,97 @@
+<?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
new file mode 100644
index 00000000..4d2f46a0
--- /dev/null
+++ b/tests/Unit/Db/ParticipationTextMapperTest.php
@@ -0,0 +1,97 @@
+<?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/TextMapperTest.php
new file mode 100644
index 00000000..690ae3c6
--- /dev/null
+++ b/tests/Unit/Db/TextMapperTest.php
@@ -0,0 +1,97 @@
+<?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\Text;
+use OCA\Polls\Db\TextMapper;
+use OCA\Polls\Tests\Unit\UnitTestCase;
+use OCP\IDBConnection;
+use League\FactoryMuffin\Faker\Facade as Faker;
+
+class TextMapperTest extends UnitTestCase {
+
+ /** @var IDBConnection */
+ private $con;
+ /** @var TextMapper */
+ private $textMapper;
+ /** @var EventMapper */
+ private $eventMapper;
+
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp() {
+ parent::setUp();
+ $this->con = \OC::$server->getDatabaseConnection();
+ $this->textMapper = new TextMapper($this->con);
+ $this->eventMapper = new EventMapper($this->con);
+ }
+
+ /**
+ * Create some fake data and persist them to the database.
+ *
+ * @return Text
+ */
+ 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));
+
+ return $text;
+ }
+
+ /**
+ * Update the previously created entry and persist the changes.
+ *
+ * @depends testCreate
+ * @param Text $text
+ * @return Text
+ */
+ public function testUpdate(Text $text) {
+ $newText = Faker::paragraph();
+ $text->setText($newText());
+ $this->textMapper->update($text);
+
+ return $text;
+ }
+
+ /**
+ * Delete the previously created entries from the database.
+ *
+ * @depends testUpdate
+ * @param Text $text
+ */
+ public function testDelete(Text $text) {
+ $event = $this->eventMapper->find($text->getPollId());
+ $this->textMapper->delete($text);
+ $this->eventMapper->delete($event);
+ }
+}
diff --git a/tests/Unit/Factories/CommentFactory.php b/tests/Unit/Factories/CommentFactory.php
new file mode 100644
index 00000000..3a8fb33c
--- /dev/null
+++ b/tests/Unit/Factories/CommentFactory.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 comment model.
+ */
+$fm->define('OCA\Polls\Db\Comment')->setDefinitions([
+ 'userId' => Faker::firstNameMale(),
+ 'dt' => function () {
+ $date = new DateTime('today');
+ return $date->format('Y-m-d H:i:s');
+ },
+ 'comment' => Faker::paragraph()
+]);
diff --git a/tests/Unit/Factories/DateFactory.php b/tests/Unit/Factories/DateFactory.php
new file mode 100644
index 00000000..fc6d8fe0
--- /dev/null
+++ b/tests/Unit/Factories/DateFactory.php
@@ -0,0 +1,32 @@
+<?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/EventFactory.php b/tests/Unit/Factories/EventFactory.php
new file mode 100644
index 00000000..fa32dd6c
--- /dev/null
+++ b/tests/Unit/Factories/EventFactory.php
@@ -0,0 +1,46 @@
+<?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 event model.
+ */
+$fm->define('OCA\Polls\Db\Event')->setDefinitions([
+ 'type' => 0,
+ 'title' => Faker::sentence(10),
+ 'description' => Faker::paragraph(),
+ 'owner' => Faker::firstNameMale(),
+ 'created' => function () {
+ $date = new DateTime('today');
+ return $date->format('Y-m-d H:i:s');
+ },
+ 'access' => 'registered',
+ 'expire' => function () {
+ $date = new DateTime('tomorrow');
+ return $date->format('Y-m-d H:i:s');
+ },
+ 'hash' => Faker::regexify('[A-Za-z0-9]{16}'),
+ 'isAnonymous' => 0,
+ 'fullAnonymous' => 0
+]);
diff --git a/tests/Unit/Factories/NotificationFactory.php b/tests/Unit/Factories/NotificationFactory.php
new file mode 100644
index 00000000..3416219d
--- /dev/null
+++ b/tests/Unit/Factories/NotificationFactory.php
@@ -0,0 +1,31 @@
+<?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 notification model.
+ */
+$fm->define('OCA\Polls\Db\Notification')->setDefinitions([
+ 'userId' => Faker::firstNameMale(),
+]);
diff --git a/tests/Unit/Factories/ParticipationFactory.php b/tests/Unit/Factories/ParticipationFactory.php
new file mode 100644
index 00000000..1d178dd4
--- /dev/null
+++ b/tests/Unit/Factories/ParticipationFactory.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 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/ParticipationTextFactory.php
new file mode 100644
index 00000000..7b6f16f4
--- /dev/null
+++ b/tests/Unit/Factories/ParticipationTextFactory.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 participation text model.
+ */
+$fm->define('OCA\Polls\Db\ParticipationText')->setDefinitions([
+ 'text' => Faker::paragraph(),
+ 'userId' => Faker::firstNameMale(),
+ 'type' => 0
+]);
diff --git a/tests/Unit/Factories/TextFactory.php b/tests/Unit/Factories/TextFactory.php
new file mode 100644
index 00000000..91702af7
--- /dev/null
+++ b/tests/Unit/Factories/TextFactory.php
@@ -0,0 +1,31 @@
+<?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 text model.
+ */
+$fm->define('OCA\Polls\Db\Text')->setDefinitions([
+ 'text' => Faker::paragraph()
+]);
diff --git a/tests/Unit/UnitTestCase.php b/tests/Unit/UnitTestCase.php
new file mode 100644
index 00000000..7469aff1
--- /dev/null
+++ b/tests/Unit/UnitTestCase.php
@@ -0,0 +1,42 @@
+<?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;
+
+use League\FactoryMuffin\FactoryMuffin;
+use PHPUnit_Framework_TestCase;
+
+abstract class UnitTestCase extends PHPUnit_Framework_TestCase {
+
+ /** @var FactoryMuffin */
+ protected $fm;
+
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp() {
+ parent::setUp();
+ $this->fm = new FactoryMuffin();
+ $this->fm->loadFactories(__DIR__ . '/Factories');
+ }
+}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 64fc285e..f840332b 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -1,8 +1,8 @@
<?php
/**
- * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co>
*
- * @author Kai Schröer <kai@schroeer.co>
+ * @author Kai Schröer <git@schroeer.co>
*
* @license GNU AGPL version 3 or any later version
*
@@ -25,16 +25,14 @@ if (!defined('PHPUNIT_RUN')) {
define('PHPUNIT_RUN', 1);
}
-require_once(__DIR__.'/../../../lib/base.php');
+require_once __DIR__ . '/../../../lib/base.php';
+require_once __DIR__ . '/../vendor/autoload.php';
-// Fix for "Autoload path not allowed: .../tests/lib/testcase.php"
\OC::$loader->addValidRoot(OC::$SERVERROOT . '/tests');
-
-// Fix for "Autoload path not allowed: .../polls/tests/testcase.php"
\OC_App::loadApp('polls');
if (!class_exists('PHPUnit_Framework_TestCase')) {
- require_once('PHPUnit/Autoload.php');
+ require_once 'PHPUnit/Autoload.php';
}
-OC_Hook::clear();
+\OC_Hook::clear();