diff options
Diffstat (limited to 'tests/units/Formatter')
4 files changed, 122 insertions, 0 deletions
diff --git a/tests/units/Formatter/BoardFormatterTest.php b/tests/units/Formatter/BoardFormatterTest.php index c107eaf5..4d469eac 100644 --- a/tests/units/Formatter/BoardFormatterTest.php +++ b/tests/units/Formatter/BoardFormatterTest.php @@ -46,12 +46,17 @@ class BoardFormatterTest extends Base $this->assertCount(3, $board); + $this->assertSame(0, $board[0]['id']); $this->assertEquals('Default swimlane', $board[0]['name']); $this->assertCount(4, $board[0]['columns']); $this->assertEquals(3, $board[0]['nb_swimlanes']); $this->assertEquals(4, $board[0]['nb_columns']); $this->assertEquals(6, $board[0]['nb_tasks']); $this->assertEquals(10, $board[0]['score']); + $this->assertSame(1, $board[0]['columns'][0]['id']); + $this->assertSame(2, $board[0]['columns'][1]['id']); + $this->assertSame(3, $board[0]['columns'][2]['id']); + $this->assertSame(4, $board[0]['columns'][3]['id']); $this->assertEquals(4, $board[0]['columns'][0]['column_nb_tasks']); $this->assertEquals(1, $board[0]['columns'][1]['column_nb_tasks']); @@ -80,6 +85,7 @@ class BoardFormatterTest extends Base $this->assertEquals('Task 5', $board[0]['columns'][1]['tasks'][0]['title']); $this->assertEquals('Task 6', $board[0]['columns'][2]['tasks'][0]['title']); + $this->assertSame(1, $board[1]['id']); $this->assertEquals('Swimlane 1', $board[1]['name']); $this->assertCount(4, $board[1]['columns']); $this->assertEquals(3, $board[1]['nb_swimlanes']); @@ -117,6 +123,7 @@ class BoardFormatterTest extends Base $this->assertSame(0, $board[2]['columns'][3]['nb_tasks']); $this->assertEquals('Task 8', $board[2]['columns'][2]['tasks'][0]['title']); + $this->assertArrayHasKey('is_draggable', $board[2]['columns'][2]['tasks'][0]); } public function testFormatWithoutDefaultSwimlane() diff --git a/tests/units/Formatter/TaskAutoCompleteFormatterTest.php b/tests/units/Formatter/TaskAutoCompleteFormatterTest.php new file mode 100644 index 00000000..20baf549 --- /dev/null +++ b/tests/units/Formatter/TaskAutoCompleteFormatterTest.php @@ -0,0 +1,34 @@ +<?php + +use Kanboard\Formatter\TaskAutoCompleteFormatter; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; + +require_once __DIR__.'/../Base.php'; + +class TaskAutoCompleteFormatterTest extends Base +{ + public function testFormat() + { + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'My Project'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task 1', 'project_id' => 1))); + $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task 2', 'project_id' => 1))); + + $tasks = TaskAutoCompleteFormatter::getInstance($this->container) + ->withQuery($taskFinderModel->getExtendedQuery()) + ->format(); + + $this->assertCount(2, $tasks); + $this->assertEquals('My Project > #1 Task 1', $tasks[0]['label']); + $this->assertEquals('Task 1', $tasks[0]['value']); + $this->assertEquals(1, $tasks[0]['id']); + $this->assertEquals('My Project > #2 Task 2', $tasks[1]['label']); + $this->assertEquals('Task 2', $tasks[1]['value']); + $this->assertEquals(2, $tasks[1]['id']); + } +} diff --git a/tests/units/Formatter/TaskSuggestMenuFormatterTest.php b/tests/units/Formatter/TaskSuggestMenuFormatterTest.php new file mode 100644 index 00000000..d247d670 --- /dev/null +++ b/tests/units/Formatter/TaskSuggestMenuFormatterTest.php @@ -0,0 +1,39 @@ +<?php + +use Kanboard\Formatter\TaskSuggestMenuFormatter; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; + +require_once __DIR__.'/../Base.php'; + +class TaskSuggestMenuFormatterTest extends Base +{ + public function testFormat() + { + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskSuggestMenuFormatter = new TaskSuggestMenuFormatter($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'My Project'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task 1', 'project_id' => 1))); + $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task 2', 'project_id' => 1))); + + $result = $taskSuggestMenuFormatter + ->withQuery($this->container['taskFinderModel']->getExtendedQuery()) + ->format() + ; + + $expected = array( + array( + 'value' => '1', + 'html' => '#1 Task 1 <small>My Project</small>', + ), + array( + 'value' => '2', + 'html' => '#2 Task 2 <small>My Project</small>', + ), + ); + + $this->assertSame($expected, $result); + } +} diff --git a/tests/units/Formatter/UserMentionFormatterTest.php b/tests/units/Formatter/UserMentionFormatterTest.php new file mode 100644 index 00000000..6338e80f --- /dev/null +++ b/tests/units/Formatter/UserMentionFormatterTest.php @@ -0,0 +1,42 @@ +<?php + +use Kanboard\Formatter\UserMentionFormatter; + +require_once __DIR__.'/../Base.php'; + +class UserMentionFormatterTest extends Base +{ + public function testFormat() + { + $userMentionFormatter = new UserMentionFormatter($this->container); + $users = array( + array( + 'id' => 1, + 'username' => 'someone', + 'name' => 'Someone', + 'email' => 'test@localhost', + 'avatar_path' => 'avatar_image', + ), + array( + 'id' => 2, + 'username' => 'somebody', + 'name' => '', + 'email' => '', + 'avatar_path' => '', + ) + ); + + $expected = array( + array( + 'value' => 'someone', + 'html' => '<div class="avatar avatar-20 avatar-inline"><img src="?controller=AvatarFileController&action=image&user_id=1&size=20" alt="Someone" title="Someone"></div> someone <small>Someone</small>', + ), + array( + 'value' => 'somebody', + 'html' => '<div class="avatar avatar-20 avatar-inline"><div class="avatar-letter" style="background-color: rgb(191, 210, 121)" title="somebody">S</div></div> somebody', + ), + ); + + $this->assertSame($expected, $userMentionFormatter->withUsers($users)->format()); + } +} |