diff options
Diffstat (limited to 'tests/units/Model')
-rw-r--r-- | tests/units/Model/ProjectDuplicationModelTest.php | 22 | ||||
-rw-r--r-- | tests/units/Model/ProjectModelTest.php (renamed from tests/units/Model/ProjectTest.php) | 196 | ||||
-rw-r--r-- | tests/units/Model/ProjectTaskPriorityModelTest.php | 84 |
3 files changed, 189 insertions, 113 deletions
diff --git a/tests/units/Model/ProjectDuplicationModelTest.php b/tests/units/Model/ProjectDuplicationModelTest.php index 41e59c9c..54261728 100644 --- a/tests/units/Model/ProjectDuplicationModelTest.php +++ b/tests/units/Model/ProjectDuplicationModelTest.php @@ -141,6 +141,28 @@ class ProjectDuplicationModelTest extends Base $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1)); } + public function testCloneProjectWithDifferentPriorities() + { + $projectModel = new ProjectModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array( + 'name' => 'My project', + 'priority_default' => 2, + 'priority_start' => -2, + 'priority_end' => 8, + ))); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1)); + + $project = $projectModel->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('My project (Clone)', $project['name']); + $this->assertEquals(2, $project['priority_default']); + $this->assertEquals(-2, $project['priority_start']); + $this->assertEquals(8, $project['priority_end']); + } + public function testCloneProjectWithDifferentName() { $projectModel = new ProjectModel($this->container); diff --git a/tests/units/Model/ProjectTest.php b/tests/units/Model/ProjectModelTest.php index 472d7351..81e0dd57 100644 --- a/tests/units/Model/ProjectTest.php +++ b/tests/units/Model/ProjectModelTest.php @@ -11,16 +11,16 @@ use Kanboard\Model\TaskCreationModel; use Kanboard\Model\ConfigModel; use Kanboard\Model\CategoryModel; -class ProjectTest extends Base +class ProjectModelTest extends Base { public function testCreationForAllLanguages() { - $p = new ProjectModel($this->container); + $projectModel = new ProjectModel($this->container); foreach ($this->container['languageModel']->getLanguages() as $locale => $language) { Translator::unload(); Translator::load($locale); - $this->assertNotFalse($p->create(array('name' => 'UnitTest '.$locale)), 'Unable to create project with '.$locale.':'.$language); + $this->assertNotFalse($projectModel->create(array('name' => 'UnitTest '.$locale)), 'Unable to create project with '.$locale.':'.$language); } Translator::unload(); @@ -28,11 +28,11 @@ class ProjectTest extends Base public function testCreation() { - $p = new ProjectModel($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); - $project = $p->getById(1); + $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals(1, $project['is_active']); $this->assertEquals(0, $project['is_public']); @@ -43,19 +43,19 @@ class ProjectTest extends Base public function testCreationWithDuplicateName() { - $p = new ProjectModel($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertEquals(2, $p->create(array('name' => 'UnitTest'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest'))); } public function testCreationWithStartAndDate() { - $p = new ProjectModel($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest', 'start_date' => '2015-01-01', 'end_date' => '2015-12-31'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest', 'start_date' => '2015-01-01', 'end_date' => '2015-12-31'))); - $project = $p->getById(1); + $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals('2015-01-01', $project['start_date']); $this->assertEquals('2015-12-31', $project['end_date']); @@ -63,19 +63,19 @@ class ProjectTest extends Base public function testCreationWithDefaultCategories() { - $p = new ProjectModel($this->container); - $c = new ConfigModel($this->container); - $cat = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $configModel = new ConfigModel($this->container); + $categoryModel = new CategoryModel($this->container); // Multiple categories correctly formatted - $this->assertTrue($c->save(array('project_categories' => 'Test1, Test2'))); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); + $this->assertTrue($configModel->save(array('project_categories' => 'Test1, Test2'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1'))); - $project = $p->getById(1); + $project = $projectModel->getById(1); $this->assertNotEmpty($project); - $categories = $cat->getAll(1); + $categories = $categoryModel->getAll(1); $this->assertNotEmpty($categories); $this->assertEquals(2, count($categories)); $this->assertEquals('Test1', $categories[0]['name']); @@ -83,85 +83,85 @@ class ProjectTest extends Base // Single category - $this->assertTrue($c->save(array('project_categories' => 'Test1'))); + $this->assertTrue($configModel->save(array('project_categories' => 'Test1'))); $this->container['memoryCache']->flush(); - $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2'))); - $project = $p->getById(2); + $project = $projectModel->getById(2); $this->assertNotEmpty($project); - $categories = $cat->getAll(2); + $categories = $categoryModel->getAll(2); $this->assertNotEmpty($categories); $this->assertEquals(1, count($categories)); $this->assertEquals('Test1', $categories[0]['name']); // Multiple categories badly formatted - $this->assertTrue($c->save(array('project_categories' => 'ABC, , DEF 3, '))); + $this->assertTrue($configModel->save(array('project_categories' => 'ABC, , DEF 3, '))); $this->container['memoryCache']->flush(); - $this->assertEquals(3, $p->create(array('name' => 'UnitTest3'))); + $this->assertEquals(3, $projectModel->create(array('name' => 'UnitTest3'))); - $project = $p->getById(3); + $project = $projectModel->getById(3); $this->assertNotEmpty($project); - $categories = $cat->getAll(3); + $categories = $categoryModel->getAll(3); $this->assertNotEmpty($categories); $this->assertEquals(2, count($categories)); $this->assertEquals('ABC', $categories[0]['name']); $this->assertEquals('DEF 3', $categories[1]['name']); // No default categories - $this->assertTrue($c->save(array('project_categories' => ' '))); + $this->assertTrue($configModel->save(array('project_categories' => ' '))); $this->container['memoryCache']->flush(); - $this->assertEquals(4, $p->create(array('name' => 'UnitTest4'))); + $this->assertEquals(4, $projectModel->create(array('name' => 'UnitTest4'))); - $project = $p->getById(4); + $project = $projectModel->getById(4); $this->assertNotEmpty($project); - $categories = $cat->getAll(4); + $categories = $categoryModel->getAll(4); $this->assertEmpty($categories); } public function testUpdateLastModifiedDate() { - $p = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + $projectModel = new ProjectModel($this->container); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $now = time(); - $project = $p->getById(1); + $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals($now, $project['last_modified'], 'Wrong Timestamp', 1); sleep(1); - $this->assertTrue($p->updateModificationDate(1)); + $this->assertTrue($projectModel->updateModificationDate(1)); - $project = $p->getById(1); + $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertGreaterThan($now, $project['last_modified']); } public function testGetAllIds() { - $p = new ProjectModel($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); - $this->assertEmpty($p->getAllByIds(array())); - $this->assertNotEmpty($p->getAllByIds(array(1, 2))); - $this->assertCount(1, $p->getAllByIds(array(1))); + $this->assertEmpty($projectModel->getAllByIds(array())); + $this->assertNotEmpty($projectModel->getAllByIds(array(1, 2))); + $this->assertCount(1, $projectModel->getAllByIds(array(1))); } public function testIsLastModified() { - $p = new ProjectModel($this->container); - $tc = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $now = time(); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); - $project = $p->getById(1); + $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals($now, $project['last_modified']); @@ -170,113 +170,113 @@ class ProjectTest extends Base $listener = new ProjectModificationDateSubscriber($this->container); $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($listener, 'execute')); - $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1))); $called = $this->container['dispatcher']->getCalledListeners(); $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.Kanboard\Subscriber\ProjectModificationDateSubscriber::execute', $called); - $project = $p->getById(1); + $project = $projectModel->getById(1); $this->assertNotEmpty($project); - $this->assertTrue($p->isModifiedSince(1, $now)); + $this->assertTrue($projectModel->isModifiedSince(1, $now)); } public function testRemove() { - $p = new ProjectModel($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($p->remove(1)); - $this->assertFalse($p->remove(1234)); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertTrue($projectModel->remove(1)); + $this->assertFalse($projectModel->remove(1234)); } public function testEnable() { - $p = new ProjectModel($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($p->disable(1)); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertTrue($projectModel->disable(1)); - $project = $p->getById(1); + $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals(0, $project['is_active']); - $this->assertFalse($p->disable(1111)); + $this->assertFalse($projectModel->disable(1111)); } public function testDisable() { - $p = new ProjectModel($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($p->disable(1)); - $this->assertTrue($p->enable(1)); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertTrue($projectModel->disable(1)); + $this->assertTrue($projectModel->enable(1)); - $project = $p->getById(1); + $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals(1, $project['is_active']); - $this->assertFalse($p->enable(1234567)); + $this->assertFalse($projectModel->enable(1234567)); } public function testEnablePublicAccess() { - $p = new ProjectModel($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($p->enablePublicAccess(1)); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertTrue($projectModel->enablePublicAccess(1)); - $project = $p->getById(1); + $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals(1, $project['is_public']); $this->assertNotEmpty($project['token']); - $this->assertFalse($p->enablePublicAccess(123)); + $this->assertFalse($projectModel->enablePublicAccess(123)); } public function testDisablePublicAccess() { - $p = new ProjectModel($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($p->enablePublicAccess(1)); - $this->assertTrue($p->disablePublicAccess(1)); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertTrue($projectModel->enablePublicAccess(1)); + $this->assertTrue($projectModel->disablePublicAccess(1)); - $project = $p->getById(1); + $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals(0, $project['is_public']); $this->assertEmpty($project['token']); - $this->assertFalse($p->disablePublicAccess(123)); + $this->assertFalse($projectModel->disablePublicAccess(123)); } public function testIdentifier() { - $p = new ProjectModel($this->container); + $projectModel = new ProjectModel($this->container); // Creation - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2'))); - $project = $p->getById(1); + $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals('TEST1', $project['identifier']); - $project = $p->getById(2); + $project = $projectModel->getById(2); $this->assertNotEmpty($project); $this->assertEquals('', $project['identifier']); // Update - $this->assertTrue($p->update(array('id' => '2', 'identifier' => 'test2'))); + $this->assertTrue($projectModel->update(array('id' => '2', 'identifier' => 'test2'))); - $project = $p->getById(2); + $project = $projectModel->getById(2); $this->assertNotEmpty($project); $this->assertEquals('TEST2', $project['identifier']); - $project = $p->getByIdentifier('test1'); + $project = $projectModel->getByIdentifier('test1'); $this->assertNotEmpty($project); $this->assertEquals('TEST1', $project['identifier']); - $project = $p->getByIdentifier(''); + $project = $projectModel->getByIdentifier(''); $this->assertFalse($project); } @@ -303,34 +303,4 @@ class ProjectTest extends Base $this->assertEquals('', $project['owner_username']); $this->assertEquals(0, $project['owner_id']); } - - public function testPriority() - { - $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $projectModel->create(array('name' => 'My project 2'))); - - $project = $projectModel->getById(1); - $this->assertNotEmpty($project); - $this->assertEquals(0, $project['priority_default']); - $this->assertEquals(0, $project['priority_start']); - $this->assertEquals(3, $project['priority_end']); - - $this->assertEquals( - array(0 => 0, 1 => 1, 2 => 2, 3 => 3), - $projectModel->getPriorities($project) - ); - - $this->assertTrue($projectModel->update(array('id' => 1, 'priority_start' => 2, 'priority_end' => 5, 'priority_default' => 4))); - - $project = $projectModel->getById(1); - $this->assertNotEmpty($project); - $this->assertEquals(4, $project['priority_default']); - $this->assertEquals(2, $project['priority_start']); - $this->assertEquals(5, $project['priority_end']); - - $this->assertEquals( - array(2 => 2, 3 => 3, 4 => 4, 5 => 5), - $projectModel->getPriorities($project) - ); - } } diff --git a/tests/units/Model/ProjectTaskPriorityModelTest.php b/tests/units/Model/ProjectTaskPriorityModelTest.php new file mode 100644 index 00000000..61661e5e --- /dev/null +++ b/tests/units/Model/ProjectTaskPriorityModelTest.php @@ -0,0 +1,84 @@ +<?php + +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectTaskPriorityModel; + +require_once __DIR__.'/../Base.php'; + +class ProjectTaskPriorityModelTest extends Base +{ + public function testPriority() + { + $projectModel = new ProjectModel($this->container); + $projectTaskPriorityModel = new ProjectTaskPriorityModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'My project 2'))); + $this->assertEquals(0, $projectTaskPriorityModel->getDefaultPriority(1)); + + $project = $projectModel->getById(1); + $this->assertNotEmpty($project); + $this->assertEquals(0, $project['priority_default']); + $this->assertEquals(0, $project['priority_start']); + $this->assertEquals(3, $project['priority_end']); + + $this->assertEquals( + array(0 => 0, 1 => 1, 2 => 2, 3 => 3), + $projectTaskPriorityModel->getPriorities($project) + ); + + $this->assertTrue($projectModel->update(array('id' => 1, 'priority_start' => 2, 'priority_end' => 5, 'priority_default' => 4))); + + $project = $projectModel->getById(1); + $this->assertNotEmpty($project); + $this->assertEquals(4, $project['priority_default']); + $this->assertEquals(2, $project['priority_start']); + $this->assertEquals(5, $project['priority_end']); + + $this->assertEquals( + array(2 => 2, 3 => 3, 4 => 4, 5 => 5), + $projectTaskPriorityModel->getPriorities($project) + ); + + $this->assertEquals(4, $projectTaskPriorityModel->getDefaultPriority(1)); + } + + public function testGetPrioritySettings() + { + $projectModel = new ProjectModel($this->container); + $projectTaskPriorityModel = new ProjectTaskPriorityModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'My project 2'))); + + $expected = array( + 'priority_default' => 0, + 'priority_start' => 0, + 'priority_end' => 3, + ); + + $this->assertEquals($expected, $projectTaskPriorityModel->getPrioritySettings(1)); + $this->assertNull($projectTaskPriorityModel->getPrioritySettings(2)); + } + + public function testGetPriorityForProject() + { + $projectModel = new ProjectModel($this->container); + $projectTaskPriorityModel = new ProjectTaskPriorityModel($this->container); + + $this->assertEquals(1, $projectModel->create(array( + 'name' => 'My project 1', + 'priority_default' => 2, + 'priority_start' => -2, + 'priority_end' => 8, + ))); + + $this->assertEquals(2, $projectTaskPriorityModel->getPriorityForProject(1, 42)); + $this->assertEquals(0, $projectTaskPriorityModel->getPriorityForProject(1, 0)); + $this->assertEquals(1, $projectTaskPriorityModel->getPriorityForProject(1, 1)); + $this->assertEquals(-2, $projectTaskPriorityModel->getPriorityForProject(1, -2)); + $this->assertEquals(-1, $projectTaskPriorityModel->getPriorityForProject(1, -1)); + $this->assertEquals(8, $projectTaskPriorityModel->getPriorityForProject(1, 8)); + $this->assertEquals(5, $projectTaskPriorityModel->getPriorityForProject(1, 5)); + $this->assertEquals(2, $projectTaskPriorityModel->getPriorityForProject(1, 9)); + $this->assertEquals(2, $projectTaskPriorityModel->getPriorityForProject(1, -3)); + } +} |