From 23d862aef8891130bc7eaeaa25513a9895b44c95 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 3 Dec 2016 12:56:12 -0500 Subject: Add suggest menu for task ID --- tests/units/Filter/TaskStartsWithIdFilterTest.php | 103 +++++++++++++++++++++ .../Formatter/TaskSuggestMenuFormatterTest.php | 39 ++++++++ tests/units/Formatter/UserMentionFormatterTest.php | 42 +++++++++ tests/units/Helper/TextHelperTest.php | 14 +-- 4 files changed, 191 insertions(+), 7 deletions(-) create mode 100644 tests/units/Filter/TaskStartsWithIdFilterTest.php create mode 100644 tests/units/Formatter/TaskSuggestMenuFormatterTest.php create mode 100644 tests/units/Formatter/UserMentionFormatterTest.php (limited to 'tests/units') diff --git a/tests/units/Filter/TaskStartsWithIdFilterTest.php b/tests/units/Filter/TaskStartsWithIdFilterTest.php new file mode 100644 index 00000000..e911a6a1 --- /dev/null +++ b/tests/units/Filter/TaskStartsWithIdFilterTest.php @@ -0,0 +1,103 @@ +container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $query = $taskFinderModel->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + + for ($i = 1; $i <= 20; $i++) { + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i))); + } + + $filter = new TaskStartsWithIdFilter(); + $filter->withQuery($query); + $filter->withValue(1); + $filter->apply(); + + $tasks = $query->findAll(); + $this->assertCount(11, $tasks); + $this->assertEquals('Task #1', $tasks[0]['title']); + $this->assertEquals('Task #19', $tasks[10]['title']); + } + + public function testOneResult() + { + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $query = $taskFinderModel->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + + for ($i = 1; $i <= 20; $i++) { + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i))); + } + + $filter = new TaskStartsWithIdFilter(); + $filter->withQuery($query); + $filter->withValue(3); + $filter->apply(); + + $tasks = $query->findAll(); + $this->assertCount(1, $tasks); + $this->assertEquals('Task #3', $tasks[0]['title']); + } + + public function testEmptyResult() + { + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $query = $taskFinderModel->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + + for ($i = 1; $i <= 20; $i++) { + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i))); + } + + $filter = new TaskStartsWithIdFilter(); + $filter->withQuery($query); + $filter->withValue(30); + $filter->apply(); + + $tasks = $query->findAll(); + $this->assertCount(0, $tasks); + } + + public function testWithTwoDigits() + { + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $query = $taskFinderModel->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + + for ($i = 1; $i <= 20; $i++) { + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i))); + } + + $filter = new TaskStartsWithIdFilter(); + $filter->withQuery($query); + $filter->withValue(11); + $filter->apply(); + + $tasks = $query->findAll(); + $this->assertCount(1, $tasks); + $this->assertEquals('Task #11', $tasks[0]['title']); + } +} 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 @@ +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 My Project', + ), + array( + 'value' => '2', + 'html' => '#2 Task 2 My Project', + ), + ); + + $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 @@ +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' => '
Someone
someone Someone', + ), + array( + 'value' => 'somebody', + 'html' => '
S
somebody', + ), + ); + + $this->assertSame($expected, $userMentionFormatter->withUsers($users)->format()); + } +} diff --git a/tests/units/Helper/TextHelperTest.php b/tests/units/Helper/TextHelperTest.php index 8237c9e4..a54c5780 100644 --- a/tests/units/Helper/TextHelperTest.php +++ b/tests/units/Helper/TextHelperTest.php @@ -32,7 +32,7 @@ class TextHelperTest extends Base ); $this->assertEquals( - '

Task #1

', + '

Task #1

', $helper->markdown('Task #1', true) ); @@ -47,12 +47,12 @@ class TextHelperTest extends Base public function testMarkdownUserLink() { $h = new TextHelper($this->container); - $this->assertEquals('

Text @admin @notfound

', $h->markdown('Text @admin @notfound')); - $this->assertEquals('

Text @admin,

', $h->markdown('Text @admin,')); - $this->assertEquals('

Text @admin!

', $h->markdown('Text @admin!')); - $this->assertEquals('

Text @admin?

', $h->markdown('Text @admin? ')); - $this->assertEquals('

Text @admin.

', $h->markdown('Text @admin.')); - $this->assertEquals('

Text @admin: test

', $h->markdown('Text @admin: test')); + $this->assertEquals('

Text @admin @notfound

', $h->markdown('Text @admin @notfound')); + $this->assertEquals('

Text @admin,

', $h->markdown('Text @admin,')); + $this->assertEquals('

Text @admin!

', $h->markdown('Text @admin!')); + $this->assertEquals('

Text @admin?

', $h->markdown('Text @admin? ')); + $this->assertEquals('

Text @admin.

', $h->markdown('Text @admin.')); + $this->assertEquals('

Text @admin: test

', $h->markdown('Text @admin: test')); $this->assertEquals('

Text @admin @notfound

', $h->markdown('Text @admin @notfound', true)); } -- cgit v1.2.3