Add suggest menu for task ID
This commit is contained in:
103
tests/units/Filter/TaskStartsWithIdFilterTest.php
Normal file
103
tests/units/Filter/TaskStartsWithIdFilterTest.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
use Kanboard\Filter\TaskStartsWithIdFilter;
|
||||
use Kanboard\Model\ProjectModel;
|
||||
use Kanboard\Model\TaskCreationModel;
|
||||
use Kanboard\Model\TaskFinderModel;
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
class TaskStartsWithIdFilterTest extends Base
|
||||
{
|
||||
public function testManyResults()
|
||||
{
|
||||
$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(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']);
|
||||
}
|
||||
}
|
||||
39
tests/units/Formatter/TaskSuggestMenuFormatterTest.php
Normal file
39
tests/units/Formatter/TaskSuggestMenuFormatterTest.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
42
tests/units/Formatter/UserMentionFormatterTest.php
Normal file
42
tests/units/Formatter/UserMentionFormatterTest.php
Normal file
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ class TextHelperTest extends Base
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Task <a href="?controller=TaskViewController&action=readonly&token='.$project['token'].'&task_id=1">#1</a></p>',
|
||||
'<p>Task <a href="http://localhost/?controller=TaskViewController&action=readonly&token='.$project['token'].'&task_id=1">#1</a></p>',
|
||||
$helper->markdown('Task #1', true)
|
||||
);
|
||||
|
||||
@@ -47,12 +47,12 @@ class TextHelperTest extends Base
|
||||
public function testMarkdownUserLink()
|
||||
{
|
||||
$h = new TextHelper($this->container);
|
||||
$this->assertEquals('<p>Text <a href="http://localhost/?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a> @notfound</p>', $h->markdown('Text @admin @notfound'));
|
||||
$this->assertEquals('<p>Text <a href="http://localhost/?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>,</p>', $h->markdown('Text @admin,'));
|
||||
$this->assertEquals('<p>Text <a href="http://localhost/?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>!</p>', $h->markdown('Text @admin!'));
|
||||
$this->assertEquals('<p>Text <a href="http://localhost/?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>? </p>', $h->markdown('Text @admin? '));
|
||||
$this->assertEquals('<p>Text <a href="http://localhost/?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>.</p>', $h->markdown('Text @admin.'));
|
||||
$this->assertEquals('<p>Text <a href="http://localhost/?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>: test</p>', $h->markdown('Text @admin: test'));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a> @notfound</p>', $h->markdown('Text @admin @notfound'));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>,</p>', $h->markdown('Text @admin,'));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>!</p>', $h->markdown('Text @admin!'));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>? </p>', $h->markdown('Text @admin? '));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>.</p>', $h->markdown('Text @admin.'));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>: test</p>', $h->markdown('Text @admin: test'));
|
||||
$this->assertEquals('<p>Text @admin @notfound</p>', $h->markdown('Text @admin @notfound', true));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user