Version 1.0.3
This commit is contained in:
parent
da21b60ef0
commit
1fce2a39fb
30 changed files with 174 additions and 1006 deletions
|
|
@ -1,120 +0,0 @@
|
|||
<?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\Forms\Tests\Unit\Controller;
|
||||
|
||||
use OCA\Forms\Controller\PageController;
|
||||
use OCA\Forms\Tests\Unit\UnitTestCase;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
|
||||
class PageControllerTest extends UnitTestCase {
|
||||
|
||||
/** @var PageController */
|
||||
private $controller;
|
||||
|
||||
private $userId = 'john';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
$avatarManager = $this->getMockBuilder('OCP\IAvatarManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$config = $this->getMockBuilder('OCP\IConfig')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$groupManager = $this->getMockBuilder('OCP\IGroupManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$l10n = $this->getMockBuilder('OCP\IL10N')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$logger = $this->getMockBuilder('OCP\ILogger')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$request = $this->getMockBuilder('OCP\IRequest')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$urlGenerator = $this->getMockBuilder('OCP\IURLGenerator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$user = $this->getMockBuilder('OCP\IUser')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$userManager = $this->getMockBuilder('OCP\IUserManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$transFactory = $this->getMockBuilder('OCP\L10N\IFactory')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$mailer = $this->getMockBuilder('OCP\Mail\IMailer')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$commentMapper = $this->getMockBuilder('OCA\Forms\Db\CommentMapper')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$optionMapper = $this->getMockBuilder('OCA\Forms\Db\OptionMapper')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$eventMapper = $this->getMockBuilder('OCA\Forms\Db\EventMapper')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$notificationMapper = $this->getMockBuilder('OCA\Forms\Db\NotificationMapper')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$voteMapper = $this->getMockBuilder('OCA\Forms\Db\VoteMapper')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->controller = new PageController(
|
||||
'forms',
|
||||
$request,
|
||||
$config,
|
||||
$userManager,
|
||||
$groupManager,
|
||||
$avatarManager,
|
||||
$logger,
|
||||
$l10n,
|
||||
$transFactory,
|
||||
$urlGenerator,
|
||||
$this->userId,
|
||||
$commentMapper,
|
||||
$optionMapper,
|
||||
$eventMapper,
|
||||
$notificationMapper,
|
||||
$voteMapper,
|
||||
$mailer
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic controller index route test.
|
||||
*/
|
||||
public function testIndex() {
|
||||
$result = $this->controller->index();
|
||||
|
||||
$this->assertEquals('forms.tmpl', $result->getTemplateName());
|
||||
$this->assertInstanceOf(TemplateResponse::class, $result);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
<?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\Forms\Tests\Unit\Db;
|
||||
|
||||
use OCA\Forms\Db\Comment;
|
||||
use OCA\Forms\Db\CommentMapper;
|
||||
use OCA\Forms\Db\Event;
|
||||
use OCA\Forms\Db\EventMapper;
|
||||
use OCA\Forms\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\Forms\Db\Event');
|
||||
$this->assertInstanceOf(Event::class, $this->eventMapper->insert($event));
|
||||
|
||||
/** @var Comment $comment */
|
||||
$comment = $this->fm->instance('OCA\Forms\Db\Comment');
|
||||
$comment->setFormId($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->getFormId());
|
||||
$this->commentMapper->delete($comment);
|
||||
$this->eventMapper->delete($event);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
<?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\Forms\Tests\Unit\Db;
|
||||
|
||||
use OCA\Forms\Db\Event;
|
||||
use OCA\Forms\Db\EventMapper;
|
||||
use OCA\Forms\Db\Option;
|
||||
use OCA\Forms\Db\OptionMapper;
|
||||
use OCA\Forms\Tests\Unit\UnitTestCase;
|
||||
use OCP\IDBConnection;
|
||||
use League\FactoryMuffin\Faker\Facade as Faker;
|
||||
|
||||
class OptionMapperTest extends UnitTestCase {
|
||||
|
||||
/** @var IDBConnection */
|
||||
private $con;
|
||||
/** @var OptionMapper */
|
||||
private $optionMapper;
|
||||
/** @var EventMapper */
|
||||
private $eventMapper;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->con = \OC::$server->getDatabaseConnection();
|
||||
$this->optionMapper = new OptionMapper($this->con);
|
||||
$this->eventMapper = new EventMapper($this->con);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create some fake data and persist them to the database.
|
||||
*
|
||||
* @return Option
|
||||
*/
|
||||
public function testCreate() {
|
||||
/** @var Event $event */
|
||||
$event = $this->fm->instance('OCA\Forms\Db\Event');
|
||||
$this->assertInstanceOf(Event::class, $this->eventMapper->insert($event));
|
||||
|
||||
/** @var Option $option */
|
||||
$option = $this->fm->instance('OCA\Forms\Db\Option');
|
||||
$option->setFormId($event->getId());
|
||||
$this->assertInstanceOf(Option::class, $this->optionMapper->insert($option));
|
||||
|
||||
return $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the previously created entry and persist the changes.
|
||||
*
|
||||
* @depends testCreate
|
||||
* @param Option $option
|
||||
* @return Option
|
||||
*/
|
||||
public function testUpdate(Option $option) {
|
||||
$newFormOptionText = Faker::text(255);
|
||||
$option->setFormOptionText($newFormOptionText());
|
||||
$this->optionMapper->update($option);
|
||||
|
||||
return $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the previously created entries from the database.
|
||||
*
|
||||
* @depends testUpdate
|
||||
* @param Option $option
|
||||
*/
|
||||
public function testDelete(Option $option) {
|
||||
$event = $this->eventMapper->find($option->getFormId());
|
||||
$this->optionMapper->delete($option);
|
||||
$this->eventMapper->delete($event);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
<?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\Forms\Db\Comment')->setDefinitions([
|
||||
'userId' => Faker::firstNameMale(),
|
||||
'dt' => function() {
|
||||
$date = new DateTime('today');
|
||||
return $date->format('Y-m-d H:i:s');
|
||||
},
|
||||
'comment' => Faker::text(255)
|
||||
]);
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
<?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\Forms\Db\Option')->setDefinitions([
|
||||
'formOptionText' => Faker::text(255)
|
||||
]);
|
||||
Loading…
Add table
Add a link
Reference in a new issue