diff options
Diffstat (limited to 'tests/units/Model')
-rw-r--r-- | tests/units/Model/AclTest.php | 12 | ||||
-rw-r--r-- | tests/units/Model/FileTest.php | 77 | ||||
-rw-r--r-- | tests/units/Model/HourlyRateTest.php | 43 | ||||
-rw-r--r-- | tests/units/Model/ProjectTest.php | 2 | ||||
-rw-r--r-- | tests/units/Model/SubtaskTest.php | 130 | ||||
-rw-r--r-- | tests/units/Model/SubtaskTimeTrackingTest.php | 26 |
6 files changed, 232 insertions, 58 deletions
diff --git a/tests/units/Model/AclTest.php b/tests/units/Model/AclTest.php index fef03990..3cb28a77 100644 --- a/tests/units/Model/AclTest.php +++ b/tests/units/Model/AclTest.php @@ -290,4 +290,16 @@ class AclTest extends Base $this->assertFalse($acl->isAllowed('task', 'remove', 1)); $this->assertTrue($acl->isAllowed('app', 'index', 1)); } + + public function testExtend() + { + $acl = new Acl($this->container); + + $this->assertFalse($acl->isProjectManagerAction('plop', 'show')); + + $acl->extend('project_manager_acl', array('plop' => '*')); + + $this->assertTrue($acl->isProjectManagerAction('plop', 'show')); + $this->assertTrue($acl->isProjectManagerAction('swimlane', 'index')); + } } diff --git a/tests/units/Model/FileTest.php b/tests/units/Model/FileTest.php index da00917d..e7520c89 100644 --- a/tests/units/Model/FileTest.php +++ b/tests/units/Model/FileTest.php @@ -9,6 +9,17 @@ use Model\Project; class FileTest extends Base { + public function setUp() + { + parent::setUp(); + + $this->container['objectStorage'] = $this + ->getMockBuilder('\Core\ObjectStorage\FileStorage') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('put', 'moveFile', 'remove')) + ->getMock(); + } + public function testCreation() { $p = new Project($this->container); @@ -85,13 +96,32 @@ class FileTest extends Base public function testUploadScreenshot() { $p = new Project($this->container); - $f = new File($this->container); $tc = new TaskCreation($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(1, $f->uploadScreenshot(1, 1, base64_encode('image data'))); + $data = base64_encode('image data'); + + $f = $this + ->getMockBuilder('\Model\File') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromData')) + ->getMock(); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with( + $this->stringContains('1/1/'), + $this->equalTo(base64_decode($data)) + ) + ->will($this->returnValue(true)); + + $f->expects($this->once()) + ->method('generateThumbnailFromData'); + + $this->assertEquals(1, $f->uploadScreenshot(1, 1, $data)); $file = $f->getById(1); $this->assertNotEmpty($file); @@ -113,7 +143,18 @@ class FileTest extends Base $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(1, $f->uploadContent(1, 1, 'my file.pdf', base64_encode('file data'))); + $data = base64_encode('file data'); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with( + $this->stringContains('1/1/'), + $this->equalTo(base64_decode($data)) + ) + ->will($this->returnValue(true)); + + $this->assertEquals(1, $f->uploadContent(1, 1, 'my file.pdf', $data)); $file = $f->getById(1); $this->assertNotEmpty($file); @@ -170,9 +211,33 @@ class FileTest extends Base $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(1, $f->create(1, 'B.pdf', '/tmp/foo', 10)); - $this->assertEquals(2, $f->create(1, 'A.png', '/tmp/foo', 10)); - $this->assertEquals(3, $f->create(1, 'D.doc', '/tmp/foo', 10)); + $this->assertEquals(1, $f->create(1, 'B.pdf', '/tmp/foo1', 10)); + $this->assertEquals(2, $f->create(1, 'A.png', '/tmp/foo2', 10)); + $this->assertEquals(3, $f->create(1, 'D.doc', '/tmp/foo3', 10)); + + $this->container['objectStorage'] + ->expects($this->at(0)) + ->method('remove') + ->with( + $this->equalTo('/tmp/foo2') + ) + ->will($this->returnValue(true)); + + $this->container['objectStorage'] + ->expects($this->at(1)) + ->method('remove') + ->with( + $this->equalTo('/tmp/foo1') + ) + ->will($this->returnValue(true)); + + $this->container['objectStorage'] + ->expects($this->at(2)) + ->method('remove') + ->with( + $this->equalTo('/tmp/foo3') + ) + ->will($this->returnValue(true)); $this->assertTrue($f->remove(2)); diff --git a/tests/units/Model/HourlyRateTest.php b/tests/units/Model/HourlyRateTest.php deleted file mode 100644 index ffc0d87e..00000000 --- a/tests/units/Model/HourlyRateTest.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Model\User; -use Model\HourlyRate; - -class HourlyRateTest extends Base -{ - public function testCreation() - { - $hr = new HourlyRate($this->container); - $this->assertEquals(1, $hr->create(1, 32.4, 'EUR', '2015-01-01')); - $this->assertEquals(2, $hr->create(1, 42, 'CAD', '2015-02-01')); - - $rates = $hr->getAllByUser(0); - $this->assertEmpty($rates); - - $rates = $hr->getAllByUser(1); - $this->assertNotEmpty($rates); - $this->assertCount(2, $rates); - - $this->assertEquals(42, $rates[0]['rate']); - $this->assertEquals('CAD', $rates[0]['currency']); - $this->assertEquals('2015-02-01', date('Y-m-d', $rates[0]['date_effective'])); - - $this->assertEquals(32.4, $rates[1]['rate']); - $this->assertEquals('EUR', $rates[1]['currency']); - $this->assertEquals('2015-01-01', date('Y-m-d', $rates[1]['date_effective'])); - - $this->assertEquals(0, $hr->getCurrentRate(0)); - $this->assertEquals(42, $hr->getCurrentRate(1)); - - $this->assertTrue($hr->remove(2)); - $this->assertEquals(32.4, $hr->getCurrentRate(1)); - - $this->assertTrue($hr->remove(1)); - $this->assertEquals(0, $hr->getCurrentRate(1)); - - $rates = $hr->getAllByUser(1); - $this->assertEmpty($rates); - } -} diff --git a/tests/units/Model/ProjectTest.php b/tests/units/Model/ProjectTest.php index 97357796..9d7b6c0d 100644 --- a/tests/units/Model/ProjectTest.php +++ b/tests/units/Model/ProjectTest.php @@ -26,7 +26,7 @@ class ProjectTest extends Base $this->assertNotFalse($p->create(array('name' => 'UnitTest '.$locale)), 'Unable to create project with '.$locale.':'.$language); } - Translator::load('en_US'); + Translator::unload(); } public function testCreation() diff --git a/tests/units/Model/SubtaskTest.php b/tests/units/Model/SubtaskTest.php index 1ef04c32..5773893c 100644 --- a/tests/units/Model/SubtaskTest.php +++ b/tests/units/Model/SubtaskTest.php @@ -13,6 +13,136 @@ use Model\UserSession; class SubTaskTest extends Base { + public function onSubtaskCreated($event) + { + $this->assertInstanceOf('Event\SubtaskEvent', $event); + $data = $event->getAll(); + + $this->assertArrayHasKey('id', $data); + $this->assertArrayHasKey('title', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('time_estimated', $data); + $this->assertArrayHasKey('time_spent', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('task_id', $data); + $this->assertArrayHasKey('user_id', $data); + $this->assertArrayHasKey('position', $data); + $this->assertNotEmpty($data['task_id']); + $this->assertNotEmpty($data['id']); + } + + public function onSubtaskUpdated($event) + { + $this->assertInstanceOf('Event\SubtaskEvent', $event); + $data = $event->getAll(); + + $this->assertArrayHasKey('id', $data); + $this->assertArrayHasKey('title', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('time_estimated', $data); + $this->assertArrayHasKey('time_spent', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('task_id', $data); + $this->assertArrayHasKey('user_id', $data); + $this->assertArrayHasKey('position', $data); + $this->assertArrayHasKey('changes', $data); + $this->assertArrayHasKey('user_id', $data['changes']); + $this->assertArrayHasKey('status', $data['changes']); + + $this->assertEquals(Subtask::STATUS_INPROGRESS, $data['changes']['status']); + $this->assertEquals(1, $data['changes']['user_id']); + } + + public function onSubtaskDeleted($event) + { + $this->assertInstanceOf('Event\SubtaskEvent', $event); + $data = $event->getAll(); + + $this->assertArrayHasKey('id', $data); + $this->assertArrayHasKey('title', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('time_estimated', $data); + $this->assertArrayHasKey('time_spent', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('task_id', $data); + $this->assertArrayHasKey('user_id', $data); + $this->assertArrayHasKey('position', $data); + $this->assertNotEmpty($data['task_id']); + $this->assertNotEmpty($data['id']); + } + + public function testCreation() + { + $tc = new TaskCreation($this->container); + $s = new Subtask($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); + + $this->container['dispatcher']->addListener(Subtask::EVENT_CREATE, array($this, 'onSubtaskCreated')); + + $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); + + $subtask = $s->getById(1); + $this->assertNotEmpty($subtask); + $this->assertEquals(1, $subtask['id']); + $this->assertEquals(1, $subtask['task_id']); + $this->assertEquals('subtask #1', $subtask['title']); + $this->assertEquals(Subtask::STATUS_TODO, $subtask['status']); + $this->assertEquals(0, $subtask['time_estimated']); + $this->assertEquals(0, $subtask['time_spent']); + $this->assertEquals(0, $subtask['user_id']); + $this->assertEquals(1, $subtask['position']); + } + + public function testModification() + { + $tc = new TaskCreation($this->container); + $s = new Subtask($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); + + $this->container['dispatcher']->addListener(Subtask::EVENT_UPDATE, array($this, 'onSubtaskUpdated')); + + $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); + $this->assertTrue($s->update(array('id' => 1, 'user_id' => 1, 'status' => Subtask::STATUS_INPROGRESS))); + + $subtask = $s->getById(1); + $this->assertNotEmpty($subtask); + $this->assertEquals(1, $subtask['id']); + $this->assertEquals(1, $subtask['task_id']); + $this->assertEquals('subtask #1', $subtask['title']); + $this->assertEquals(Subtask::STATUS_INPROGRESS, $subtask['status']); + $this->assertEquals(0, $subtask['time_estimated']); + $this->assertEquals(0, $subtask['time_spent']); + $this->assertEquals(1, $subtask['user_id']); + $this->assertEquals(1, $subtask['position']); + } + + public function testRemove() + { + $tc = new TaskCreation($this->container); + $s = new Subtask($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); + $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); + + $this->container['dispatcher']->addListener(Subtask::EVENT_DELETE, array($this, 'onSubtaskDeleted')); + + $subtask = $s->getById(1); + $this->assertNotEmpty($subtask); + + $this->assertTrue($s->remove(1)); + + $subtask = $s->getById(1); + $this->assertEmpty($subtask); + } + public function testToggleStatusWithoutSession() { $tc = new TaskCreation($this->container); diff --git a/tests/units/Model/SubtaskTimeTrackingTest.php b/tests/units/Model/SubtaskTimeTrackingTest.php index ed286287..f68f283d 100644 --- a/tests/units/Model/SubtaskTimeTrackingTest.php +++ b/tests/units/Model/SubtaskTimeTrackingTest.php @@ -151,8 +151,8 @@ class SubtaskTimeTrackingTest extends Base $time = $st->calculateSubtaskTime(1); $this->assertNotempty($time); $this->assertCount(2, $time); - $this->assertEquals(3.3, $time['total_spent'], 'Total spent', 0.01); - $this->assertEquals(7.7, $time['total_estimated'], 'Total estimated', 0.01); + $this->assertEquals(3.3, $time['time_spent'], 'Total spent', 0.01); + $this->assertEquals(7.7, $time['time_estimated'], 'Total estimated', 0.01); } public function testUpdateSubtaskTimeSpent() @@ -184,13 +184,13 @@ class SubtaskTimeTrackingTest extends Base $time = $st->calculateSubtaskTime(1); $this->assertNotempty($time); - $this->assertEquals(4.2, $time['total_spent'], 'Total spent', 0.01); - $this->assertEquals(0, $time['total_estimated'], 'Total estimated', 0.01); + $this->assertEquals(4.2, $time['time_spent'], 'Total spent', 0.01); + $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01); $time = $st->calculateSubtaskTime(2); $this->assertNotempty($time); - $this->assertEquals(0, $time['total_spent'], 'Total spent', 0.01); - $this->assertEquals(0, $time['total_estimated'], 'Total estimated', 0.01); + $this->assertEquals(0, $time['time_spent'], 'Total spent', 0.01); + $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01); } public function testUpdateTaskTimeTracking() @@ -205,7 +205,7 @@ class SubtaskTimeTrackingTest extends Base $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); $this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 1.5, 'time_spent' => 0.5))); - $this->assertEquals(3, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2))); + $this->assertEquals(3, $tc->create(array('title' => 'test 3', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2))); $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_spent' => 2.2))); $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 1))); @@ -231,8 +231,18 @@ class SubtaskTimeTrackingTest extends Base $task = $tf->getById(3); $this->assertNotEmpty($task); - $this->assertEquals(4, $task['time_estimated']); + $this->assertEquals(0, $task['time_estimated']); $this->assertEquals(8, $task['time_spent']); + + $this->assertTrue($s->remove(3)); + $this->assertTrue($s->remove(4)); + + $st->updateTaskTimeTracking(2); + + $task = $tf->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['time_estimated']); + $this->assertEquals(0, $task['time_spent']); } public function testGetCalendarEvents() |