summaryrefslogtreecommitdiff
path: root/tests/units/ProjectDuplicationTest.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-01-25 18:08:28 -0500
committerFrederic Guillot <fred@kanboard.net>2015-01-25 18:08:28 -0500
commit1fc6d69e2e25d6e4feaa38fe03dab98c75cfb36c (patch)
tree984e346cefa4b34b6bb5cfa4454f2156e64fe1da /tests/units/ProjectDuplicationTest.php
parente6cf1bf23648f02615eeeddd34b0f4f2578f1f0a (diff)
Fix bug duplicate project with a too long name
Diffstat (limited to 'tests/units/ProjectDuplicationTest.php')
-rw-r--r--tests/units/ProjectDuplicationTest.php206
1 files changed, 206 insertions, 0 deletions
diff --git a/tests/units/ProjectDuplicationTest.php b/tests/units/ProjectDuplicationTest.php
new file mode 100644
index 00000000..ab50b9f1
--- /dev/null
+++ b/tests/units/ProjectDuplicationTest.php
@@ -0,0 +1,206 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Action;
+use Model\Project;
+use Model\Category;
+use Model\ProjectPermission;
+use Model\ProjectDuplication;
+use Model\User;
+use Model\Task;
+use Model\TaskCreation;
+use Model\Acl;
+use Model\Board;
+
+class ProjectDuplicationTest extends Base
+{
+ public function testProjectName()
+ {
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals('test (Clone)', $pd->getClonedProjectName('test'));
+
+ $this->assertEquals(50, strlen($pd->getClonedProjectName(str_repeat('a', 50))));
+ $this->assertEquals(str_repeat('a', 42).' (Clone)', $pd->getClonedProjectName(str_repeat('a', 50)));
+
+ $this->assertEquals(50, strlen($pd->getClonedProjectName(str_repeat('a', 60))));
+ $this->assertEquals(str_repeat('a', 42).' (Clone)', $pd->getClonedProjectName(str_repeat('a', 60)));
+ }
+
+ public function testCopyProjectWithLongName()
+ {
+ $p = new Project($this->container);
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => str_repeat('a', 50))));
+ $this->assertEquals(2, $pd->duplicate(1));
+
+ $project = $p->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals(str_repeat('a', 42).' (Clone)', $project['name']);
+ }
+
+ public function testClonePublicProject()
+ {
+ $p = new Project($this->container);
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'Public')));
+ $this->assertEquals(2, $pd->duplicate(1));
+
+ $project = $p->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Public (Clone)', $project['name']);
+ $this->assertEquals(0, $project['is_private']);
+ $this->assertEquals(0, $project['is_public']);
+ $this->assertEmpty($project['token']);
+ }
+
+ public function testClonePrivateProject()
+ {
+ $p = new Project($this->container);
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'Private', 'is_private' => 1), 1, true));
+ $this->assertEquals(2, $pd->duplicate(1));
+
+ $project = $p->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Private (Clone)', $project['name']);
+ $this->assertEquals(1, $project['is_private']);
+ $this->assertEquals(0, $project['is_public']);
+ $this->assertEmpty($project['token']);
+
+ $pp = new ProjectPermission($this->container);
+
+ $this->assertEquals(array(1 => 'admin'), $pp->getMembers(1));
+ $this->assertEquals(array(1 => 'admin'), $pp->getMembers(2));
+ }
+
+ public function testCloneProjectWithCategories()
+ {
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1)));
+ $this->assertEquals(3, $c->create(array('name' => 'C3', 'project_id' => 1)));
+
+ $this->assertEquals(2, $pd->duplicate(1));
+
+ $project = $p->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('P1 (Clone)', $project['name']);
+
+ $categories = $c->getAll(2);
+ $this->assertNotempty($categories);
+ $this->assertEquals(3, count($categories));
+
+ $this->assertEquals(4, $categories[0]['id']);
+ $this->assertEquals('C1', $categories[0]['name']);
+
+ $this->assertEquals(5, $categories[1]['id']);
+ $this->assertEquals('C2', $categories[1]['name']);
+
+ $this->assertEquals(6, $categories[2]['id']);
+ $this->assertEquals('C3', $categories[2]['name']);
+ }
+
+ public function testCloneProjectWithUsers()
+ {
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+ $pp = new ProjectPermission($this->container);
+ $u = new User($this->container);
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals(2, $u->create(array('username' => 'unittest1', 'password' => 'unittest')));
+ $this->assertEquals(3, $u->create(array('username' => 'unittest2', 'password' => 'unittest')));
+ $this->assertEquals(4, $u->create(array('username' => 'unittest3', 'password' => 'unittest')));
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+ $this->assertTrue($pp->addMember(1, 2));
+ $this->assertTrue($pp->addMember(1, 4));
+ $this->assertTrue($pp->addManager(1, 3));
+ $this->assertTrue($pp->isMember(1, 2));
+ $this->assertTrue($pp->isMember(1, 3));
+ $this->assertTrue($pp->isMember(1, 4));
+ $this->assertFalse($pp->isManager(1, 2));
+ $this->assertTrue($pp->isManager(1, 3));
+ $this->assertFalse($pp->isManager(1, 4));
+
+ $this->assertEquals(2, $pd->duplicate(1));
+
+ $project = $p->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('P1 (Clone)', $project['name']);
+
+ $this->assertEquals(3, count($pp->getMembers(2)));
+ $this->assertTrue($pp->isMember(2, 2));
+ $this->assertTrue($pp->isMember(2, 3));
+ $this->assertTrue($pp->isMember(2, 4));
+ $this->assertFalse($pp->isManager(2, 2));
+ $this->assertTrue($pp->isManager(2, 3));
+ $this->assertFalse($pp->isManager(2, 4));
+ }
+
+ public function testCloneProjectWithActionTaskAssignCurrentUser()
+ {
+ $p = new Project($this->container);
+ $a = new Action($this->container);
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+
+ $this->assertTrue($a->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => 'TaskAssignCurrentUser',
+ 'params' => array('column_id' => 2),
+ )));
+
+ $this->assertEquals(2, $pd->duplicate(1));
+
+ $actions = $a->getAllByProject(2);
+
+ $this->assertNotEmpty($actions);
+ $this->assertEquals('TaskAssignCurrentUser', $actions[0]['action_name']);
+ $this->assertNotEmpty($actions[0]['params']);
+ $this->assertEquals(6, $actions[0]['params'][0]['value']);
+ }
+
+ public function testCloneProjectWithActionTaskAssignColorCategory()
+ {
+ $p = new Project($this->container);
+ $a = new Action($this->container);
+ $c = new Category($this->container);
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1)));
+ $this->assertEquals(3, $c->create(array('name' => 'C3', 'project_id' => 1)));
+
+ $this->assertTrue($a->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE_UPDATE,
+ 'action_name' => 'TaskAssignColorCategory',
+ 'params' => array('color_id' => 'blue', 'category_id' => 2),
+ )));
+
+ $this->assertEquals(2, $pd->duplicate(1));
+
+ $actions = $a->getAllByProject(2);
+
+ $this->assertNotEmpty($actions);
+ $this->assertEquals('TaskAssignColorCategory', $actions[0]['action_name']);
+ $this->assertNotEmpty($actions[0]['params']);
+ $this->assertEquals('blue', $actions[0]['params'][0]['value']);
+ $this->assertEquals(5, $actions[0]['params'][1]['value']);
+ }
+}