diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-09-09 20:39:45 +0200 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-09-09 20:39:45 +0200 |
commit | 9bde377bbe85617dde280af985e033cf7de61803 (patch) | |
tree | 2d2c080a86542206f862bd6d1c14ce622aa225a8 /tests | |
parent | ef95c7c28479a22e41fff35a893f05eb084e1f2c (diff) |
Start to implement task history and project activity
Diffstat (limited to 'tests')
-rw-r--r-- | tests/units/Base.php | 5 | ||||
-rw-r--r-- | tests/units/TaskHistoryTest.php | 98 |
2 files changed, 103 insertions, 0 deletions
diff --git a/tests/units/Base.php b/tests/units/Base.php index 0d721e3d..c1702c61 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -28,7 +28,9 @@ 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/Task.php'; @@ -41,6 +43,7 @@ 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/TaskHistory.php'; require_once __DIR__.'/../../app/Action/Base.php'; require_once __DIR__.'/../../app/Action/TaskClose.php'; @@ -55,6 +58,8 @@ abstract class Base extends PHPUnit_Framework_TestCase { public function setUp() { + date_default_timezone_set('UTC'); + $this->registry = new \Core\Registry; $this->registry->db = $this->getDbConnection(); $this->registry->event = new \Core\Event; diff --git a/tests/units/TaskHistoryTest.php b/tests/units/TaskHistoryTest.php new file mode 100644 index 00000000..0d24be58 --- /dev/null +++ b/tests/units/TaskHistoryTest.php @@ -0,0 +1,98 @@ +<?php + +require_once __DIR__.'/Base.php'; + +use Model\Task; +use Model\TaskHistory; +use Model\Project; + +class TaskHistoryTest extends Base +{ + public function testCreation() + { + $e = new TaskHistory($this->registry); + $t = new Task($this->registry); + $p = new Project($this->registry); + + $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1))); + $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1))); + + $this->assertTrue($e->create(1, 1, 1, Task::EVENT_CLOSE)); + $this->assertTrue($e->create(1, 2, 1, Task::EVENT_UPDATE)); + $this->assertFalse($e->create(1, 1, 0, Task::EVENT_OPEN)); + + $events = $e->getAllByProjectId(1); + + $this->assertNotEmpty($events); + $this->assertTrue(is_array($events)); + $this->assertEquals(2, count($events)); + $this->assertEquals(time(), $events[0]['date_creation']); + $this->assertEquals(Task::EVENT_UPDATE, $events[0]['event_name']); + $this->assertEquals(Task::EVENT_CLOSE, $events[1]['event_name']); + } + + public function testFetchAllContent() + { + $e = new TaskHistory($this->registry); + $t = new Task($this->registry); + $p = new Project($this->registry); + + $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1))); + + $nb_events = 80; + + for ($i = 0; $i < $nb_events; $i++) { + $this->assertTrue($e->create(1, 1, 1, Task::EVENT_UPDATE)); + } + + $events = $e->getAllContentByProjectId(1); + + $this->assertNotEmpty($events); + $this->assertTrue(is_array($events)); + $this->assertEquals(50, count($events)); + $this->assertEquals('admin', $events[0]['author']); + $this->assertNotEmpty($events[0]['event_title']); + $this->assertNotEmpty($events[0]['event_content']); + } + + public function testCleanup() + { + $e = new TaskHistory($this->registry); + $t = new Task($this->registry); + $p = new Project($this->registry); + + $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1))); + + $max = 15; + $nb_events = 100; + + for ($i = 0; $i < $nb_events; $i++) { + $this->assertTrue($e->create(1, 1, 1, Task::EVENT_CLOSE)); + } + + $this->assertEquals($nb_events, $this->registry->db->table('task_has_events')->count()); + $e->cleanup($max); + + $events = $e->getAllByProjectId(1); + + $this->assertNotEmpty($events); + $this->assertTrue(is_array($events)); + $this->assertEquals($max, count($events)); + $this->assertEquals(100, $events[0]['id']); + $this->assertEquals(99, $events[1]['id']); + $this->assertEquals(86, $events[14]['id']); + + // Cleanup during task creation + + $nb_events = TaskHistory::MAX_EVENTS + 10; + + for ($i = 0; $i < $nb_events; $i++) { + $this->assertTrue($e->create(1, 1, 1, Task::EVENT_CLOSE)); + } + + $this->assertEquals(TaskHistory::MAX_EVENTS, $this->registry->db->table('task_has_events')->count()); + } +} |