From 074056352de98fc567b4d13184c72887c75625d0 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 12 Oct 2014 21:38:56 -0400 Subject: Project activity refactoring and listeners improvements --- tests/units/ProjectActivityTest.php | 102 ++++++++++++++++++++++++++++++++++++ tests/units/ProjectTest.php | 2 +- tests/units/TaskHistoryTest.php | 98 ---------------------------------- 3 files changed, 103 insertions(+), 99 deletions(-) create mode 100644 tests/units/ProjectActivityTest.php delete mode 100644 tests/units/TaskHistoryTest.php (limited to 'tests') diff --git a/tests/units/ProjectActivityTest.php b/tests/units/ProjectActivityTest.php new file mode 100644 index 00000000..2565b6e7 --- /dev/null +++ b/tests/units/ProjectActivityTest.php @@ -0,0 +1,102 @@ +registry); + $t = new Task($this->registry); + $tf = new TaskFinder($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->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1)))); + $this->assertTrue($e->createEvent(1, 2, 1, Task::EVENT_UPDATE, array('task' => $tf->getById(2)))); + $this->assertFalse($e->createEvent(1, 1, 0, Task::EVENT_OPEN, array('task' => $tf->getbyId(1)))); + + $events = $e->getAll(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 ProjectActivity($this->registry); + $t = new Task($this->registry); + $tf = new TaskFinder($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->createEvent(1, 1, 1, Task::EVENT_UPDATE, array('task' => $tf->getbyId(1)))); + } + + $events = $e->getAll(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 ProjectActivity($this->registry); + $t = new Task($this->registry); + $tf = new TaskFinder($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->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1)))); + } + + $this->assertEquals($nb_events, $this->registry->shared('db')->table('project_activities')->count()); + $e->cleanup($max); + + $events = $e->getAll(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 = ProjectActivity::MAX_EVENTS + 10; + + for ($i = 0; $i < $nb_events; $i++) { + $this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1)))); + } + + $this->assertEquals(ProjectActivity::MAX_EVENTS, $this->registry->shared('db')->table('project_activities')->count()); + } +} diff --git a/tests/units/ProjectTest.php b/tests/units/ProjectTest.php index 0085711a..cec8d93d 100644 --- a/tests/units/ProjectTest.php +++ b/tests/units/ProjectTest.php @@ -63,7 +63,7 @@ class ProjectTest extends Base $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1))); $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE)); - $this->assertEquals('Event\ProjectModificationDate', $this->registry->shared('event')->getLastListenerExecuted()); + $this->assertEquals('Event\ProjectModificationDateListener', $this->registry->shared('event')->getLastListenerExecuted()); $project = $p->getById(1); $this->assertNotEmpty($project); diff --git a/tests/units/TaskHistoryTest.php b/tests/units/TaskHistoryTest.php deleted file mode 100644 index 085162ea..00000000 --- a/tests/units/TaskHistoryTest.php +++ /dev/null @@ -1,98 +0,0 @@ -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->shared('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->shared('db')->table('task_has_events')->count()); - } -} -- cgit v1.2.3