summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/Formatter/BoardFormatterTest.php81
-rw-r--r--tests/units/FunctionTest.php102
-rw-r--r--tests/units/Model/TaskTagModelTest.php50
3 files changed, 231 insertions, 2 deletions
diff --git a/tests/units/Formatter/BoardFormatterTest.php b/tests/units/Formatter/BoardFormatterTest.php
index 02b0b518..c107eaf5 100644
--- a/tests/units/Formatter/BoardFormatterTest.php
+++ b/tests/units/Formatter/BoardFormatterTest.php
@@ -6,6 +6,7 @@ use Kanboard\Model\ProjectModel;
use Kanboard\Model\SwimlaneModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskTagModel;
require_once __DIR__.'/../Base.php';
@@ -308,4 +309,84 @@ class BoardFormatterTest extends Base
$this->assertSame(0, $board[2]['columns'][2]['nb_tasks']);
$this->assertSame(0, $board[2]['columns'][3]['nb_tasks']);
}
+
+ public function testFormatWithTags()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2', 'column_id' => 3)));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2')));
+ $this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
+
+ $board = BoardFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->withProjectId(1)
+ ->format();
+
+ $this->assertCount(1, $board);
+
+ $this->assertEquals('Default swimlane', $board[0]['name']);
+ $this->assertCount(4, $board[0]['columns']);
+ $this->assertEquals(1, $board[0]['nb_swimlanes']);
+ $this->assertEquals(4, $board[0]['nb_columns']);
+ $this->assertEquals(3, $board[0]['nb_tasks']);
+ $this->assertEquals(0, $board[0]['score']);
+
+ $this->assertEquals(2, $board[0]['columns'][0]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][1]['column_nb_tasks']);
+ $this->assertEquals(1, $board[0]['columns'][2]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_nb_tasks']);
+
+ $this->assertEquals(0, $board[0]['columns'][0]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][1]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][2]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_score']);
+
+ $this->assertSame(0, $board[0]['columns'][0]['score']);
+ $this->assertSame(0, $board[0]['columns'][1]['score']);
+ $this->assertSame(0, $board[0]['columns'][2]['score']);
+ $this->assertSame(0, $board[0]['columns'][3]['score']);
+
+ $this->assertSame(2, $board[0]['columns'][0]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][1]['nb_tasks']);
+ $this->assertSame(1, $board[0]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('test1', $board[0]['columns'][0]['tasks'][0]['title']);
+ $this->assertEquals('test3', $board[0]['columns'][0]['tasks'][1]['title']);
+ $this->assertEquals('test2', $board[0]['columns'][2]['tasks'][0]['title']);
+
+ $expected = array(
+ array(
+ 'id' => 1,
+ 'name' => 'My tag 1',
+ 'task_id' => 1,
+ ),
+ array(
+ 'id' => 2,
+ 'name' => 'My tag 2',
+ 'task_id' => 1,
+ ),
+ );
+
+ $this->assertEquals($expected, $board[0]['columns'][0]['tasks'][0]['tags']);
+ $this->assertEquals(array(), $board[0]['columns'][0]['tasks'][1]['tags']);
+
+ $expected = array(
+ array(
+ 'id' => 3,
+ 'name' => 'My tag 3',
+ 'task_id' => 2,
+ ),
+ );
+
+ $this->assertEquals($expected, $board[0]['columns'][2]['tasks'][0]['tags']);
+ }
}
diff --git a/tests/units/FunctionTest.php b/tests/units/FunctionTest.php
index 72895845..1c5f971d 100644
--- a/tests/units/FunctionTest.php
+++ b/tests/units/FunctionTest.php
@@ -18,4 +18,106 @@ class FunctionTest extends Base
$this->assertSame(579.7, array_column_sum($input, 'my_column'));
}
+
+ public function testArrayColumnIndex()
+ {
+ $input = array(
+ array(
+ 'k1' => 11,
+ 'k2' => 22,
+ ),
+ array(
+ 'k1' => 11,
+ 'k2' => 55,
+ ),
+ array(
+ 'k1' => 33,
+ 'k2' => 44,
+ ),
+ array()
+ );
+
+ $expected = array(
+ 11 => array(
+ array(
+ 'k1' => 11,
+ 'k2' => 22,
+ ),
+ array(
+ 'k1' => 11,
+ 'k2' => 55,
+ )
+ ),
+ 33 => array(
+ array(
+ 'k1' => 33,
+ 'k2' => 44,
+ )
+ )
+ );
+
+ $this->assertSame($expected, array_column_index($input, 'k1'));
+ }
+
+ public function testArrayMergeRelation()
+ {
+ $relations = array(
+ 88 => array(
+ 'id' => 123,
+ 'value' => 'test1',
+ ),
+ 99 => array(
+ 'id' => 456,
+ 'value' => 'test2',
+ ),
+ 55 => array()
+ );
+
+ $input = array(
+ array(),
+ array(
+ 'task_id' => 88,
+ 'title' => 'task1'
+ ),
+ array(
+ 'task_id' => 99,
+ 'title' => 'task2'
+ ),
+ array(
+ 'task_id' => 11,
+ 'title' => 'task3'
+ )
+ );
+
+ $expected = array(
+ array(
+ 'my_relation' => array(),
+ ),
+ array(
+ 'task_id' => 88,
+ 'title' => 'task1',
+ 'my_relation' => array(
+ 'id' => 123,
+ 'value' => 'test1',
+ ),
+ ),
+ array(
+ 'task_id' => 99,
+ 'title' => 'task2',
+ 'my_relation' => array(
+ 'id' => 456,
+ 'value' => 'test2',
+ ),
+ ),
+ array(
+ 'task_id' => 11,
+ 'title' => 'task3',
+ 'my_relation' => array(),
+ )
+ );
+
+ array_merge_relation($input, $relations, 'my_relation', 'task_id');
+
+ $this->assertSame($expected, $input);
+ }
}
diff --git a/tests/units/Model/TaskTagModelTest.php b/tests/units/Model/TaskTagModelTest.php
index c08b571f..819f55b8 100644
--- a/tests/units/Model/TaskTagModelTest.php
+++ b/tests/units/Model/TaskTagModelTest.php
@@ -24,7 +24,7 @@ class TaskTagModelTest extends Base
$this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
- $tags = $taskTagModel->getAll(1);
+ $tags = $taskTagModel->getTagsByTask(1);
$this->assertCount(3, $tags);
$this->assertEquals(1, $tags[0]['id']);
@@ -38,7 +38,7 @@ class TaskTagModelTest extends Base
$this->assertTrue($taskTagModel->save(1, 1, array('My tag 3', 'My tag 1', 'My tag 4')));
- $tags = $taskTagModel->getAll(1);
+ $tags = $taskTagModel->getTagsByTask(1);
$this->assertCount(3, $tags);
$this->assertEquals(1, $tags[0]['id']);
@@ -64,4 +64,50 @@ class TaskTagModelTest extends Base
$this->assertEquals('My tag 4', $tags[3]['name']);
$this->assertEquals(1, $tags[3]['project_id']);
}
+
+ public function testGetTagsForTasks()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
+ $this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
+
+ $tags = $taskTagModel->getTagsByTasks(array(1, 2, 3));
+
+ $expected = array(
+ 1 => array(
+ array(
+ 'id' => 1,
+ 'name' => 'My tag 1',
+ 'task_id' => 1
+ ),
+ array(
+ 'id' => 2,
+ 'name' => 'My tag 2',
+ 'task_id' => 1
+ ),
+ array(
+ 'id' => 3,
+ 'name' => 'My tag 3',
+ 'task_id' => 1
+ ),
+ ),
+ 2 => array(
+ array(
+ 'id' => 3,
+ 'name' => 'My tag 3',
+ 'task_id' => 2,
+ )
+ )
+ );
+
+ $this->assertEquals($expected, $tags);
+ }
}