From 3cf9484644dc5002b396eb31a2065456ce0de5b7 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Fri, 12 May 2017 16:26:11 -0400 Subject: Ensure project tags are removed when the project is removed (PR #3250) --- tests/units/Model/ProjectModelTest.php | 68 ++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'tests') 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); -- cgit v1.2.3