* 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
This commit is contained in:
Kai Schröer 2017-11-07 15:43:45 +01:00 коммит произвёл GitHub
Родитель 12511a1ba4
Коммит 6e11d77656
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
44 изменённых файлов: 1124 добавлений и 95 удалений

Просмотреть файл

@ -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

7
.gitignore поставляемый
Просмотреть файл

@ -1,3 +1,8 @@
/.project
build/
vendor/
.project/
.idea/
*.lock
*.iml
.DS_Store
Thumbs.db

Просмотреть файл

@ -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

Просмотреть файл

@ -1,4 +1,4 @@
build:
tests:
override:
- scss-lint-run /css
tests:
override:
- scss-lint-run /css

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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>

Просмотреть файл

@ -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"
}
}

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 2.2 KiB

После

Ширина:  |  Высота:  |  Размер: 2.2 KiB

Просмотреть файл

@ -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')
];
});

Просмотреть файл

@ -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);

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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) {

39
lib/Db/Model.php Normal file
Просмотреть файл

@ -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]);
}
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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 = ?';

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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>

Двоичные данные
screenshots/new-poll-oc.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 34 KiB

Двоичные данные
screenshots/overview-oc.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 34 KiB

Двоичные данные
screenshots/vote-oc.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 35 KiB

Просмотреть файл

@ -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
*

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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()
]);

Просмотреть файл

@ -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');
}
]);

Просмотреть файл

@ -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
]);

Просмотреть файл

@ -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(),
]);

Просмотреть файл

@ -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
]);

Просмотреть файл

@ -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
]);

Просмотреть файл

@ -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()
]);

Просмотреть файл

@ -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');
}
}

Просмотреть файл

@ -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();