diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | app/Model/ProjectModel.php | 8 | ||||
-rw-r--r-- | tests/units/Model/ProjectModelTest.php | 68 |
3 files changed, 79 insertions, 1 deletions
@@ -6,6 +6,10 @@ Improvements: * Add wildcard search for task reference field * Improve automated action TaskAssignColorOnDueDate to update task only when necessary +Bug fixes: + +* Ensure project tags are removed when the project is removed + Version 1.0.43 (April 30, 2017) ------------------------------- diff --git a/app/Model/ProjectModel.php b/app/Model/ProjectModel.php index 7f489c75..7f55a9fb 100644 --- a/app/Model/ProjectModel.php +++ b/app/Model/ProjectModel.php @@ -462,7 +462,13 @@ class ProjectModel extends Base */ public function remove($project_id) { - return $this->db->table(self::TABLE)->eq('id', $project_id)->remove(); + $this->db->startTransaction(); + + $this->db->table(TagModel::TABLE)->eq('project_id', $project_id)->remove(); + $result = $this->db->table(self::TABLE)->eq('id', $project_id)->remove(); + + $this->db->closeTransaction(); + return $result; } /** diff --git a/tests/units/Model/ProjectModelTest.php b/tests/units/Model/ProjectModelTest.php index 03ba708e..fd247ffe 100644 --- a/tests/units/Model/ProjectModelTest.php +++ b/tests/units/Model/ProjectModelTest.php @@ -2,7 +2,13 @@ require_once __DIR__.'/../Base.php'; +use Kanboard\Api\Procedure\ProjectPermissionProcedure; +use Kanboard\Core\Security\Role; use Kanboard\Core\Translator; +use Kanboard\Model\ColumnModel; +use Kanboard\Model\ProjectPermissionModel; +use Kanboard\Model\SwimlaneModel; +use Kanboard\Model\TagModel; use Kanboard\Subscriber\ProjectModificationDateSubscriber; use Kanboard\Model\ProjectModel; use Kanboard\Model\UserModel; @@ -207,6 +213,68 @@ class ProjectModelTest extends Base $this->assertFalse($projectModel->remove(1234)); } + public function testRemoveTagsOnProjectRemove() + { + $projectModel = new ProjectModel($this->container); + $tagModel = new TagModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertNotFalse($tagModel->create(1, 'TestTag')); + + $this->assertCount(1, $tagModel->getAllByProject(1)); + + $this->assertTrue($projectModel->remove(1)); + + $this->assertCount(0, $tagModel->getAllByProject(1)); + } + + public function testRemoveSwimlaneOnProjectRemove() + { + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + + $swimlaneId = $swimlaneModel->create(1, 'TestSwimlane'); + $this->assertNotFalse($swimlaneId); + + $this->assertTrue($projectModel->remove(1)); + $this->assertNull($swimlaneModel->getById($swimlaneId)); + } + + public function testRemoveColumnOnProjectRemove() + { + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + + $columnId = $columnModel->create(1, 'TestColumn'); + $this->assertNotFalse($columnId); + + $this->assertTrue($projectModel->remove(1)); + $this->assertNull($columnModel->getById($columnId)); + } + + public function testRemovePermissionOnProjectRemove() + { + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + + $permissionModel = new ProjectPermissionModel($this->container); + $permissionProcedure = new ProjectPermissionProcedure($this->container); + + $userId = $userModel->create(array('username' => 'user1')); + $this->assertNotFalse($userId); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $permissionProcedure->addProjectUser(1, $userId, Role::PROJECT_MEMBER); + + $this->assertTrue($permissionModel->isUserAllowed(1, $userId)); + $this->assertTrue($projectModel->remove(1)); + $this->assertFalse($permissionModel->isUserAllowed(1, $userId)); + } + public function testEnable() { $projectModel = new ProjectModel($this->container); |