Run unit tests across different database backends + fix bugs
This commit is contained in:
@@ -9,7 +9,7 @@ use Model\Task;
|
||||
use Model\Category;
|
||||
|
||||
class ActionTest extends Base
|
||||
{/*
|
||||
{
|
||||
public function testFetchActions()
|
||||
{
|
||||
$action = new Action($this->registry);
|
||||
@@ -86,15 +86,15 @@ class ActionTest extends Base
|
||||
// We move our task
|
||||
$task->movePosition(1, 1, 4, 1);
|
||||
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_UPDATE));
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||
$this->assertFalse($this->registry->shared('event')->isEventTriggered(Task::EVENT_UPDATE));
|
||||
|
||||
// Our task should be closed
|
||||
$t1 = $task->getById(1);
|
||||
$this->assertEquals(4, $t1['column_id']);
|
||||
$this->assertEquals(0, $t1['is_active']);
|
||||
}
|
||||
*/
|
||||
|
||||
public function testEventMovePosition()
|
||||
{
|
||||
$task = new Task($this->registry);
|
||||
@@ -138,7 +138,7 @@ class ActionTest extends Base
|
||||
// We bind events
|
||||
$action->attachEvents();
|
||||
|
||||
$this->assertTrue($this->registry->event->hasListener(Task::EVENT_MOVE_POSITION, 'Action\TaskAssignColorCategory'));
|
||||
$this->assertTrue($this->registry->shared('event')->hasListener(Task::EVENT_MOVE_POSITION, 'Action\TaskAssignColorCategory'));
|
||||
|
||||
// Our task should have the color red and position=1
|
||||
$t1 = $task->getById(1);
|
||||
@@ -153,7 +153,7 @@ class ActionTest extends Base
|
||||
|
||||
// We move our tasks
|
||||
$this->assertTrue($task->movePosition(1, 1, 1, 10)); // task #1 to the end of the column
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_MOVE_POSITION));
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_POSITION));
|
||||
|
||||
$t1 = $task->getById(1);
|
||||
$this->assertEquals(2, $t1['position']);
|
||||
@@ -165,10 +165,10 @@ class ActionTest extends Base
|
||||
$this->assertEquals(1, $t1['is_active']);
|
||||
$this->assertEquals('yellow', $t1['color_id']);
|
||||
|
||||
$this->registry->event->clearTriggeredEvents();
|
||||
$this->registry->shared('event')->clearTriggeredEvents();
|
||||
$this->assertTrue($task->movePosition(1, 2, 1, 44)); // task #2 to position 1
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_MOVE_POSITION));
|
||||
$this->assertEquals('Action\TaskAssignColorCategory', $this->registry->event->getLastListenerExecuted());
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_POSITION));
|
||||
$this->assertEquals('Action\TaskAssignColorCategory', $this->registry->shared('event')->getLastListenerExecuted());
|
||||
|
||||
$t1 = $task->getById(1);
|
||||
$this->assertEquals(1, $t1['position']);
|
||||
@@ -180,7 +180,7 @@ class ActionTest extends Base
|
||||
$this->assertEquals(1, $t1['is_active']);
|
||||
$this->assertEquals('green', $t1['color_id']);
|
||||
}
|
||||
/*
|
||||
|
||||
public function testExecuteMultipleActions()
|
||||
{
|
||||
$task = new Task($this->registry);
|
||||
@@ -225,8 +225,8 @@ class ActionTest extends Base
|
||||
$action->attachEvents();
|
||||
|
||||
// Events should be attached
|
||||
$this->assertTrue($this->registry->event->hasListener(Task::EVENT_CLOSE, 'Action\TaskDuplicateAnotherProject'));
|
||||
$this->assertTrue($this->registry->event->hasListener(Task::EVENT_MOVE_COLUMN, 'Action\TaskClose'));
|
||||
$this->assertTrue($this->registry->shared('event')->hasListener(Task::EVENT_CLOSE, 'Action\TaskDuplicateAnotherProject'));
|
||||
$this->assertTrue($this->registry->shared('event')->hasListener(Task::EVENT_MOVE_COLUMN, 'Action\TaskClose'));
|
||||
|
||||
// Our task should be open, linked to the first project and in the first column
|
||||
$t1 = $task->getById(1);
|
||||
@@ -237,8 +237,8 @@ class ActionTest extends Base
|
||||
// We move our task
|
||||
$task->movePosition(1, 1, 4, 1);
|
||||
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CLOSE));
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CLOSE));
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||
|
||||
// Our task should be closed
|
||||
$t1 = $task->getById(1);
|
||||
@@ -252,5 +252,5 @@ class ActionTest extends Base
|
||||
$this->assertEquals(1, $t2['is_active']);
|
||||
$this->assertEquals(2, $t2['project_id']);
|
||||
$this->assertEquals('unit_test', $t2['title']);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +1,48 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/../../app/Core/Loader.php';
|
||||
require __DIR__.'/../../app/helpers.php';
|
||||
require __DIR__.'/../../app/functions.php';
|
||||
require __DIR__.'/../../app/constants.php';
|
||||
|
||||
use Core\Loader;
|
||||
use Core\Registry;
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
|
||||
require __DIR__.'/../../vendor/password.php';
|
||||
}
|
||||
|
||||
require __DIR__.'/../../vendor/SimpleValidator/Validator.php';
|
||||
require __DIR__.'/../../vendor/SimpleValidator/Base.php';
|
||||
require __DIR__.'/../../vendor/SimpleValidator/Validators/Required.php';
|
||||
require __DIR__.'/../../vendor/SimpleValidator/Validators/Unique.php';
|
||||
require __DIR__.'/../../vendor/SimpleValidator/Validators/MaxLength.php';
|
||||
require __DIR__.'/../../vendor/SimpleValidator/Validators/MinLength.php';
|
||||
require __DIR__.'/../../vendor/SimpleValidator/Validators/Integer.php';
|
||||
require __DIR__.'/../../vendor/SimpleValidator/Validators/Equals.php';
|
||||
require __DIR__.'/../../vendor/SimpleValidator/Validators/AlphaNumeric.php';
|
||||
require __DIR__.'/../../vendor/SimpleValidator/Validators/GreaterThan.php';
|
||||
require __DIR__.'/../../vendor/SimpleValidator/Validators/Date.php';
|
||||
require __DIR__.'/../../vendor/SimpleValidator/Validators/Email.php';
|
||||
require __DIR__.'/../../vendor/SimpleValidator/Validators/Numeric.php';
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
require_once __DIR__.'/../../app/Core/Security.php';
|
||||
|
||||
require_once __DIR__.'/../../vendor/PicoDb/Database.php';
|
||||
require_once __DIR__.'/../../app/Schema/Sqlite.php';
|
||||
|
||||
require_once __DIR__.'/../../app/Core/Registry.php';
|
||||
require_once __DIR__.'/../../app/Core/Tool.php';
|
||||
require_once __DIR__.'/../../app/Core/Listener.php';
|
||||
require_once __DIR__.'/../../app/Core/Event.php';
|
||||
require_once __DIR__.'/../../app/Core/Translator.php';
|
||||
require_once __DIR__.'/../../app/Core/Template.php';
|
||||
require_once __DIR__.'/../../app/translator.php';
|
||||
require_once __DIR__.'/../../app/helpers.php';
|
||||
|
||||
require_once __DIR__.'/../../app/Model/Base.php';
|
||||
require_once __DIR__.'/../../app/Model/Config.php';
|
||||
require_once __DIR__.'/../../app/Model/Task.php';
|
||||
require_once __DIR__.'/../../app/Model/Acl.php';
|
||||
require_once __DIR__.'/../../app/Model/Comment.php';
|
||||
require_once __DIR__.'/../../app/Model/Project.php';
|
||||
require_once __DIR__.'/../../app/Model/User.php';
|
||||
require_once __DIR__.'/../../app/Model/Board.php';
|
||||
require_once __DIR__.'/../../app/Model/Action.php';
|
||||
require_once __DIR__.'/../../app/Model/Category.php';
|
||||
require_once __DIR__.'/../../app/Model/SubTask.php';
|
||||
require_once __DIR__.'/../../app/Model/File.php';
|
||||
require_once __DIR__.'/../../app/Model/BaseHistory.php';
|
||||
require_once __DIR__.'/../../app/Model/TaskHistory.php';
|
||||
require_once __DIR__.'/../../app/Model/SubtaskHistory.php';
|
||||
require_once __DIR__.'/../../app/Model/CommentHistory.php';
|
||||
|
||||
require_once __DIR__.'/../../app/Action/Base.php';
|
||||
require_once __DIR__.'/../../app/Action/TaskClose.php';
|
||||
require_once __DIR__.'/../../app/Action/TaskAssignSpecificUser.php';
|
||||
require_once __DIR__.'/../../app/Action/TaskAssignColorUser.php';
|
||||
require_once __DIR__.'/../../app/Action/TaskAssignColorCategory.php';
|
||||
require_once __DIR__.'/../../app/Action/TaskAssignCurrentUser.php';
|
||||
require_once __DIR__.'/../../app/Action/TaskDuplicateAnotherProject.php';
|
||||
require_once __DIR__.'/../../app/Action/TaskMoveAnotherProject.php';
|
||||
$loader = new Loader;
|
||||
$loader->setPath('app');
|
||||
$loader->setPath('vendor');
|
||||
$loader->execute();
|
||||
|
||||
abstract class Base extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
$this->registry = new Registry;
|
||||
$this->registry->db = function() { return setup_db(); };
|
||||
$this->registry->event = function() { return setup_events(); };
|
||||
|
||||
$this->registry = new \Core\Registry;
|
||||
$this->registry->db = $this->getDbConnection();
|
||||
$this->registry->event = new \Core\Event;
|
||||
if (DB_DRIVER === 'mysql') {
|
||||
$pdo = new PDO('mysql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
|
||||
$pdo->exec('DROP DATABASE '.DB_NAME);
|
||||
$pdo->exec('CREATE DATABASE '.DB_NAME);
|
||||
$pdo = null;
|
||||
}
|
||||
else if (DB_DRIVER === 'postgres') {
|
||||
$pdo = new PDO('pgsql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
|
||||
$pdo->exec('DROP DATABASE '.DB_NAME);
|
||||
$pdo->exec('CREATE DATABASE '.DB_NAME.' WITH OWNER '.DB_USERNAME);
|
||||
$pdo = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function getDbConnection()
|
||||
public function tearDown()
|
||||
{
|
||||
$db = new \PicoDb\Database(array(
|
||||
'driver' => 'sqlite',
|
||||
'filename' => ':memory:'
|
||||
));
|
||||
|
||||
if ($db->schema()->check(\Schema\VERSION)) {
|
||||
return $db;
|
||||
}
|
||||
else {
|
||||
die('Unable to migrate database schema!');
|
||||
}
|
||||
$this->registry->shared('db')->closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ class TaskHistoryTest extends Base
|
||||
$this->assertTrue($e->create(1, 1, 1, Task::EVENT_CLOSE));
|
||||
}
|
||||
|
||||
$this->assertEquals($nb_events, $this->registry->db->table('task_has_events')->count());
|
||||
$this->assertEquals($nb_events, $this->registry->shared('db')->table('task_has_events')->count());
|
||||
$e->cleanup($max);
|
||||
|
||||
$events = $e->getAllByProjectId(1);
|
||||
@@ -93,6 +93,6 @@ class TaskHistoryTest extends Base
|
||||
$this->assertTrue($e->create(1, 1, 1, Task::EVENT_CLOSE));
|
||||
}
|
||||
|
||||
$this->assertEquals(TaskHistory::MAX_EVENTS, $this->registry->db->table('task_has_events')->count());
|
||||
$this->assertEquals(TaskHistory::MAX_EVENTS, $this->registry->shared('db')->table('task_has_events')->count());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,15 @@ class TaskTest extends Base
|
||||
$this->assertEquals(2, $task['position']);
|
||||
$this->assertEquals(time(), $task['date_creation']);
|
||||
$this->assertEquals(time(), $task['date_modification']);
|
||||
|
||||
$tasks = $t->getAll(1, 1);
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertTrue(is_array($tasks));
|
||||
$this->assertEquals(1, $tasks[0]['id']);
|
||||
$this->assertEquals(2, $tasks[1]['id']);
|
||||
|
||||
$tasks = $t->getAll(1, 0);
|
||||
$this->assertEmpty($tasks);
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
@@ -53,11 +62,11 @@ class TaskTest extends Base
|
||||
$p = new Project($this->registry);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $this->registry->db->table('tasks')->insert(array('title' => 'A', 'column_id' => 1, 'project_id' => 1, 'position' => 1)));
|
||||
$this->assertEquals(1, $this->registry->shared('db')->table('tasks')->insert(array('title' => 'A', 'column_id' => 1, 'project_id' => 1, 'position' => 1)));
|
||||
|
||||
// Both tasks have the same position
|
||||
$this->assertEquals(2, $this->registry->db->table('tasks')->insert(array('title' => 'B', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
|
||||
$this->assertEquals(3, $this->registry->db->table('tasks')->insert(array('title' => 'C', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
|
||||
$this->assertEquals(2, $this->registry->shared('db')->table('tasks')->insert(array('title' => 'B', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
|
||||
$this->assertEquals(3, $this->registry->shared('db')->table('tasks')->insert(array('title' => 'C', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
|
||||
|
||||
// Move the first column to the last position of the 2nd column
|
||||
$this->assertTrue($t->movePosition(1, 1, 2, 3));
|
||||
@@ -451,7 +460,7 @@ class TaskTest extends Base
|
||||
|
||||
// We duplicate our task
|
||||
$this->assertEquals(2, $t->duplicateSameProject($task));
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CREATE));
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $t->getById(2);
|
||||
@@ -483,7 +492,7 @@ class TaskTest extends Base
|
||||
|
||||
// We duplicate our task to the 2nd project
|
||||
$this->assertEquals(2, $t->duplicateToAnotherProject(2, $task));
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CREATE));
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $t->getById(2);
|
||||
@@ -517,7 +526,7 @@ class TaskTest extends Base
|
||||
// We duplicate our task to the 2nd project
|
||||
$task = $t->getById(1);
|
||||
$this->assertEquals(1, $t->moveToAnotherProject(2, $task));
|
||||
//$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CREATE));
|
||||
//$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $t->getById(1);
|
||||
@@ -551,32 +560,32 @@ class TaskTest extends Base
|
||||
|
||||
// We create task
|
||||
$this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CREATE));
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
|
||||
|
||||
// We update a task
|
||||
$this->assertTrue($t->update(array('title' => 'test2', 'id' => 1)));
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_UPDATE));
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CREATE_UPDATE));
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_UPDATE));
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE_UPDATE));
|
||||
|
||||
// We close our task
|
||||
$this->assertTrue($t->close(1));
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CLOSE));
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CLOSE));
|
||||
|
||||
// We open our task
|
||||
$this->assertTrue($t->open(1));
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_OPEN));
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_OPEN));
|
||||
|
||||
// We change the column of our task
|
||||
$this->assertTrue($t->movePosition(1, 1, 2, 1));
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||
|
||||
// We change the position of our task
|
||||
$this->assertEquals(2, $t->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 2)));
|
||||
$this->assertTrue($t->movePosition(1, 1, 2, 2));
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_MOVE_POSITION));
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_POSITION));
|
||||
|
||||
// We change the column and the position of our task
|
||||
$this->assertTrue($t->movePosition(1, 1, 1, 1));
|
||||
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user