diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/units/DateParserTest.php | 18 | ||||
-rw-r--r-- | tests/units/HelperTest.php | 10 | ||||
-rw-r--r-- | tests/units/ProjectDuplicationTest.php (renamed from tests/units/ProjectDuplicateTest.php) | 96 |
3 files changed, 119 insertions, 5 deletions
diff --git a/tests/units/DateParserTest.php b/tests/units/DateParserTest.php index e98fa6a5..5828fc48 100644 --- a/tests/units/DateParserTest.php +++ b/tests/units/DateParserTest.php @@ -29,4 +29,22 @@ class DateParserTest extends Base $this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('2014_03_05'))); $this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('03/05/2014'))); } + + public function testConvert() + { + $d = new DateParser($this->container); + + $values = array( + 'date_due' => '2015-01-25', + 'date_started' => '2015_01_25', + ); + + $d->convert($values, array('date_due', 'date_started')); + + $this->assertEquals(mktime(0, 0, 0, 1, 25, 2015), $values['date_due']); + $this->assertEquals('2015-01-25', date('Y-m-d', $values['date_due'])); + + $this->assertEquals(mktime(0, 0, 0, 1, 25, 2015), $values['date_started']); + $this->assertEquals('2015-01-25', date('Y-m-d', $values['date_started'])); + } } diff --git a/tests/units/HelperTest.php b/tests/units/HelperTest.php index 2ae75684..8694e8a2 100644 --- a/tests/units/HelperTest.php +++ b/tests/units/HelperTest.php @@ -18,8 +18,16 @@ class HelperTest extends Base ); $this->assertEquals( - '<p>Task <a href="?controller=a&action=b&c=d&task_id=123" class="" title="" >#123</a></p>', + '<p>Task <a href="?controller=a&action=b&c=d&task_id=123">#123</a></p>', $h->markdown('Task #123', array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd'))) ); + + $this->assertEquals( + '<p>Check that: <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454">http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454</a></p>', + $h->markdown( + 'Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454', + array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd')) + ) + ); } } diff --git a/tests/units/ProjectDuplicateTest.php b/tests/units/ProjectDuplicationTest.php index 161bbe20..ab50b9f1 100644 --- a/tests/units/ProjectDuplicateTest.php +++ b/tests/units/ProjectDuplicationTest.php @@ -2,9 +2,11 @@ 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; @@ -13,12 +15,39 @@ 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, $p->duplicate(1)); + $this->assertEquals(2, $pd->duplicate(1)); $project = $p->getById(2); $this->assertNotEmpty($project); @@ -31,9 +60,10 @@ class ProjectDuplicationTest extends Base 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, $p->duplicate(1)); + $this->assertEquals(2, $pd->duplicate(1)); $project = $p->getById(2); $this->assertNotEmpty($project); @@ -52,6 +82,7 @@ class ProjectDuplicationTest extends Base { $p = new Project($this->container); $c = new Category($this->container); + $pd = new ProjectDuplication($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1'))); @@ -59,7 +90,7 @@ class ProjectDuplicationTest extends Base $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, $p->duplicate(1)); + $this->assertEquals(2, $pd->duplicate(1)); $project = $p->getById(2); $this->assertNotEmpty($project); @@ -85,6 +116,7 @@ class ProjectDuplicationTest extends Base $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'))); @@ -101,7 +133,7 @@ class ProjectDuplicationTest extends Base $this->assertTrue($pp->isManager(1, 3)); $this->assertFalse($pp->isManager(1, 4)); - $this->assertEquals(2, $p->duplicate(1)); + $this->assertEquals(2, $pd->duplicate(1)); $project = $p->getById(2); $this->assertNotEmpty($project); @@ -115,4 +147,60 @@ class ProjectDuplicationTest extends Base $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']); + } } |