From 41e796c52aa693d13636b54efe15705eaec27f3f Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 20 Sep 2014 14:49:31 +0200 Subject: Models refactoring/improvements --- tests/units/SubtaskTest.php | 4 +- tests/units/TaskTest.php | 97 +++++++++++++++++++++++++++++++++++++++++++++ tests/units/UserTest.php | 51 ++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 2 deletions(-) (limited to 'tests/units') diff --git a/tests/units/SubtaskTest.php b/tests/units/SubtaskTest.php index a74ee60a..f272db1f 100644 --- a/tests/units/SubtaskTest.php +++ b/tests/units/SubtaskTest.php @@ -24,8 +24,8 @@ class SubTaskTest extends Base $this->assertEquals(2, $t->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0))); // We create many subtasks for the first task - $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 3, 'status' => 1))); - $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 0, 'time_spent' => 0, 'status' => 2, 'user_id' => 1))); + $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 3, 'status' => 1, 'another_subtask' => 'on'))); + $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => '', 'status' => 2, 'user_id' => 1))); // We duplicate our subtasks $this->assertTrue($s->duplicate(1, 2)); diff --git a/tests/units/TaskTest.php b/tests/units/TaskTest.php index dee3accd..e01ed8be 100644 --- a/tests/units/TaskTest.php +++ b/tests/units/TaskTest.php @@ -10,6 +10,103 @@ use Model\User; class TaskTest extends Base { + public function testPrepareCreation() + { + $t = new Task($this->registry); + $p = new Project($this->registry); + + $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); + + $input = array( + 'title' => 'youpi', + 'description' => '', + 'project_id' => '1', + 'owner_id' => '0', + 'category_id' => '0', + 'column_id' => '2', + 'color_id' => 'yellow', + 'score' => '', + 'date_due' => '', + 'creator_id' => '1', + 'another_task' => '1', + ); + + $t->prepareCreation($input); + + $this->assertInternalType('integer', $input['date_due']); + $this->assertEquals(0, $input['date_due']); + + $this->assertInternalType('integer', $input['score']); + $this->assertEquals(0, $input['score']); + + $this->assertArrayNotHasKey('another_task', $input); + + $this->assertArrayHasKey('date_creation', $input); + $this->assertEquals(time(), $input['date_creation']); + + $this->assertArrayHasKey('date_modification', $input); + $this->assertEquals(time(), $input['date_modification']); + + $this->assertArrayHasKey('position', $input); + $this->assertGreaterThan(0, $input['position']); + + $input = array( + 'title' => 'youpi', + 'project_id' => '1', + ); + + $t->prepareCreation($input); + + $this->assertArrayNotHasKey('date_due', $input); + $this->assertArrayNotHasKey('score', $input); + + $this->assertArrayHasKey('date_creation', $input); + $this->assertEquals(time(), $input['date_creation']); + + $this->assertArrayHasKey('date_modification', $input); + $this->assertEquals(time(), $input['date_modification']); + + $this->assertArrayHasKey('position', $input); + $this->assertGreaterThan(0, $input['position']); + + $this->assertArrayHasKey('color_id', $input); + $this->assertEquals('yellow', $input['color_id']); + + $this->assertArrayHasKey('column_id', $input); + $this->assertEquals(1, $input['column_id']); + + $input = array( + 'title' => 'youpi', + 'project_id' => '1', + 'date_due' => '2014-09-15', + ); + + $t->prepareCreation($input); + + $this->assertArrayHasKey('date_due', $input); + $this->assertInternalType('integer', $input['date_due']); + $this->assertEquals('2014-09-15', date('Y-m-d', $input['date_due'])); + } + + public function testPrepareModification() + { + $t = new Task($this->registry); + $p = new Project($this->registry); + + $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); + + $input = array( + 'id' => '1', + 'description' => 'Boo', + ); + + $t->prepareModification($input); + + $this->assertArrayNotHasKey('id', $input); + $this->assertArrayHasKey('date_modification', $input); + $this->assertEquals(time(), $input['date_modification']); + } + public function testCreation() { $t = new Task($this->registry); diff --git a/tests/units/UserTest.php b/tests/units/UserTest.php index cc0b7c44..9a304e85 100644 --- a/tests/units/UserTest.php +++ b/tests/units/UserTest.php @@ -8,6 +8,57 @@ use Model\Project; class UserTest extends Base { + public function testPrepare() + { + $u = new User($this->registry); + + $input = array( + 'username' => 'user1', + 'password' => '1234', + 'confirmation' => '1234', + 'name' => 'me', + 'is_admin' => '', + ); + + $u->prepare($input); + $this->assertArrayNotHasKey('confirmation', $input); + + $this->assertArrayHasKey('password', $input); + $this->assertNotEquals('1234', $input['password']); + $this->assertNotEmpty($input['password']); + + $this->assertArrayHasKey('is_admin', $input); + $this->assertInternalType('integer', $input['is_admin']); + + $input = array( + 'username' => 'user1', + 'password' => '1234', + 'current_password' => 'bla', + 'confirmation' => '1234', + 'name' => 'me', + 'is_ldap_user' => '1', + ); + + $u->prepare($input); + $this->assertArrayNotHasKey('confirmation', $input); + $this->assertArrayNotHasKey('current_password', $input); + + $this->assertArrayHasKey('password', $input); + $this->assertNotEquals('1234', $input['password']); + $this->assertNotEmpty($input['password']); + + $this->assertArrayHasKey('is_ldap_user', $input); + $this->assertEquals(1, $input['is_ldap_user']); + + $input = array( + 'id' => 2, + 'name' => 'me', + ); + + $u->prepare($input); + $this->assertEquals(array('id' => 2, 'name' => 'me'), $input); + } + public function testCreate() { $u = new User($this->registry); -- cgit v1.2.3