summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/LexerTest.php193
-rw-r--r--tests/units/TaskFilterTest.php170
2 files changed, 363 insertions, 0 deletions
diff --git a/tests/units/LexerTest.php b/tests/units/LexerTest.php
new file mode 100644
index 00000000..4abe451b
--- /dev/null
+++ b/tests/units/LexerTest.php
@@ -0,0 +1,193 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Core\Lexer;
+
+class LexerTest extends Base
+{
+ public function testAssigneeQuery()
+ {
+ $lexer = new Lexer;
+
+ $this->assertEquals(
+ array(array('match' => 'assignee:', 'token' => 'T_ASSIGNEE'), array('match' => 'me', 'token' => 'T_STRING')),
+ $lexer->tokenize('assignee:me')
+ );
+
+ $this->assertEquals(
+ array(array('match' => 'assignee:', 'token' => 'T_ASSIGNEE'), array('match' => 'everybody', 'token' => 'T_STRING')),
+ $lexer->tokenize('assignee:everybody')
+ );
+
+ $this->assertEquals(
+ array(array('match' => 'assignee:', 'token' => 'T_ASSIGNEE'), array('match' => 'nobody', 'token' => 'T_STRING')),
+ $lexer->tokenize('assignee:nobody')
+ );
+
+ $this->assertEquals(
+ array('T_ASSIGNEE' => array('nobody')),
+ $lexer->map($lexer->tokenize('assignee:nobody'))
+ );
+
+ $this->assertEquals(
+ array('T_ASSIGNEE' => array('John Doe', 'me')),
+ $lexer->map($lexer->tokenize('assignee:"John Doe" assignee:me'))
+ );
+ }
+
+ public function testColorQuery()
+ {
+ $lexer = new Lexer;
+
+ $this->assertEquals(
+ array(array('match' => 'color:', 'token' => 'T_COLOR'), array('match' => 'Blue', 'token' => 'T_STRING')),
+ $lexer->tokenize('color:Blue')
+ );
+
+ $this->assertEquals(
+ array(array('match' => 'color:', 'token' => 'T_COLOR'), array('match' => 'Dark Grey', 'token' => 'T_STRING')),
+ $lexer->tokenize('color:"Dark Grey"')
+ );
+
+ $this->assertEquals(
+ array('T_COLOR' => array('Blue')),
+ $lexer->map($lexer->tokenize('color:Blue'))
+ );
+
+ $this->assertEquals(
+ array('T_COLOR' => array('Dark Grey')),
+ $lexer->map($lexer->tokenize('color:"Dark Grey"'))
+ );
+
+ $this->assertEquals(
+ array(),
+ $lexer->map($lexer->tokenize('color: '))
+ );
+ }
+
+ public function testDueDateQuery()
+ {
+ $lexer = new Lexer;
+
+ $this->assertEquals(
+ array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '2015-05-01', 'token' => 'T_DATE')),
+ $lexer->tokenize('due:2015-05-01')
+ );
+
+ $this->assertEquals(
+ array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '<2015-05-01', 'token' => 'T_DATE')),
+ $lexer->tokenize('due:<2015-05-01')
+ );
+
+ $this->assertEquals(
+ array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '>2015-05-01', 'token' => 'T_DATE')),
+ $lexer->tokenize('due:>2015-05-01')
+ );
+
+ $this->assertEquals(
+ array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '<=2015-05-01', 'token' => 'T_DATE')),
+ $lexer->tokenize('due:<=2015-05-01')
+ );
+
+ $this->assertEquals(
+ array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '>=2015-05-01', 'token' => 'T_DATE')),
+ $lexer->tokenize('due:>=2015-05-01')
+ );
+
+ $this->assertEquals(
+ array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => 'yesterday', 'token' => 'T_DATE')),
+ $lexer->tokenize('due:yesterday')
+ );
+
+ $this->assertEquals(
+ array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => 'tomorrow', 'token' => 'T_DATE')),
+ $lexer->tokenize('due:tomorrow')
+ );
+
+ $this->assertEquals(
+ array(),
+ $lexer->tokenize('due:#2015-05-01')
+ );
+
+ $this->assertEquals(
+ array(),
+ $lexer->tokenize('due:01-05-1024')
+ );
+
+ $this->assertEquals(
+ array('T_DUE' => '2015-05-01'),
+ $lexer->map($lexer->tokenize('due:2015-05-01'))
+ );
+
+ $this->assertEquals(
+ array('T_DUE' => '<2015-05-01'),
+ $lexer->map($lexer->tokenize('due:<2015-05-01'))
+ );
+
+ $this->assertEquals(
+ array('T_DUE' => 'today'),
+ $lexer->map($lexer->tokenize('due:today'))
+ );
+ }
+
+ public function testMultipleCriterias()
+ {
+ $lexer = new Lexer;
+
+ $this->assertEquals(
+ array('T_COLOR' => array('Dark Grey'), 'T_ASSIGNEE' => array('Fred G'), 'T_TITLE' => 'my task title'),
+ $lexer->map($lexer->tokenize('color:"Dark Grey" assignee:"Fred G" my task title'))
+ );
+
+ $this->assertEquals(
+ array('T_TITLE' => 'my title', 'T_COLOR' => array('yellow')),
+ $lexer->map($lexer->tokenize('my title color:yellow'))
+ );
+
+ $this->assertEquals(
+ array('T_TITLE' => 'my title', 'T_DUE' => '2015-04-01'),
+ $lexer->map($lexer->tokenize('my title due:2015-04-01'))
+ );
+
+ $this->assertEquals(
+ array('T_TITLE' => 'awesome', 'T_DUE' => '<=2015-04-01'),
+ $lexer->map($lexer->tokenize('due:<=2015-04-01 awesome'))
+ );
+
+ $this->assertEquals(
+ array('T_TITLE' => 'awesome', 'T_DUE' => 'today'),
+ $lexer->map($lexer->tokenize('due:today awesome'))
+ );
+
+ $this->assertEquals(
+ array('T_TITLE' => 'my title', 'T_COLOR' => array('yellow'), 'T_DUE' => '2015-04-01'),
+ $lexer->map($lexer->tokenize('my title color:yellow due:2015-04-01'))
+ );
+
+ $this->assertEquals(
+ array('T_TITLE' => 'my title', 'T_COLOR' => array('yellow'), 'T_DUE' => '2015-04-01', 'T_ASSIGNEE' => array('John Doe')),
+ $lexer->map($lexer->tokenize('my title color:yellow due:2015-04-01 assignee:"John Doe"'))
+ );
+
+ $this->assertEquals(
+ array('T_TITLE' => 'my title'),
+ $lexer->map($lexer->tokenize('my title color:'))
+ );
+
+ $this->assertEquals(
+ array('T_TITLE' => 'my title'),
+ $lexer->map($lexer->tokenize('my title color:assignee:'))
+ );
+
+ $this->assertEquals(
+ array('T_TITLE' => 'my title'),
+ $lexer->map($lexer->tokenize('my title '))
+ );
+
+ $this->assertEquals(
+ array(),
+ $lexer->map($lexer->tokenize('color:assignee:'))
+ );
+ }
+}
diff --git a/tests/units/TaskFilterTest.php b/tests/units/TaskFilterTest.php
index 1872d429..e509371c 100644
--- a/tests/units/TaskFilterTest.php
+++ b/tests/units/TaskFilterTest.php
@@ -2,10 +2,180 @@
require_once __DIR__.'/Base.php';
+use Model\Project;
+use Model\User;
use Model\TaskFilter;
+use Model\TaskCreation;
+use Model\DateParser;
class TaskFilterTest extends Base
{
+ public function testSearchWithEmptyResult()
+ {
+ $dp = new DateParser($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFilter($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'date_due' => $dp->getTimestampFromIsoFormat('-2 days'))));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'date_due' => $dp->getTimestampFromIsoFormat('+1 day'))));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work', 'date_due' => $dp->getTimestampFromIsoFormat('-1 day'))));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'youpi', 'date_due' => $dp->getTimestampFromIsoFormat(time()))));
+
+ $this->assertEmpty($tf->search('search something')->findAll());
+ }
+
+ public function testSearchWithDueDate()
+ {
+ $dp = new DateParser($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFilter($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'date_due' => $dp->getTimestampFromIsoFormat('-2 days'))));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'date_due' => $dp->getTimestampFromIsoFormat('+1 day'))));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work', 'date_due' => $dp->getTimestampFromIsoFormat('-1 day'))));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'youpi', 'date_due' => $dp->getTimestampFromIsoFormat(time()))));
+
+ $tf->search('due:>'.date('Y-m-d'));
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('my task title is amazing', $tasks[0]['title']);
+
+ $tf->search('due:>='.date('Y-m-d'));
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('my task title is amazing', $tasks[0]['title']);
+ $this->assertEquals('youpi', $tasks[1]['title']);
+
+ $tf->search('due:<'.date('Y-m-d'));
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('my task title is awesome', $tasks[0]['title']);
+ $this->assertEquals('Bob at work', $tasks[1]['title']);
+
+ $tf->search('due:<='.date('Y-m-d'));
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(3, $tasks);
+ $this->assertEquals('my task title is awesome', $tasks[0]['title']);
+ $this->assertEquals('Bob at work', $tasks[1]['title']);
+ $this->assertEquals('youpi', $tasks[2]['title']);
+
+ $tf->search('due:tomorrow');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('my task title is amazing', $tasks[0]['title']);
+
+ $tf->search('due:yesterday');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Bob at work', $tasks[0]['title']);
+
+ $tf->search('due:today');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('youpi', $tasks[0]['title']);
+ }
+
+ public function testSearchWithColor()
+ {
+ $p = new Project($this->container);
+ $u = new User($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFilter($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Bob Ryan')));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'color_id' => 'light_green')));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'color_id' => 'blue')));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work')));
+
+ $tf->search('color:"Light Green"');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('my task title is awesome', $tasks[0]['title']);
+
+ $tf->search('color:"Light Green" amazing');
+ $tasks = $tf->findAll();
+ $this->assertEmpty($tasks);
+
+ $tf->search('color:"plop');
+ $tasks = $tf->findAll();
+ $this->assertEmpty($tasks);
+
+ $tf->search('color:unknown');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(3, $tasks);
+
+ $tf->search('color:blue amazing');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('my task title is amazing', $tasks[0]['title']);
+
+ $tf->search('color:blue color:Yellow');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('my task title is amazing', $tasks[0]['title']);
+ $this->assertEquals('Bob at work', $tasks[1]['title']);
+ }
+
+ public function testSearchWithAssignee()
+ {
+ $p = new Project($this->container);
+ $u = new User($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFilter($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Bob Ryan')));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'owner_id' => 1)));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'owner_id' => 0)));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work', 'owner_id' => 2)));
+
+ $tf->search('assignee:john');
+ $tasks = $tf->findAll();
+ $this->assertEmpty($tasks);
+
+ $tf->search('assignee:admin my task title');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('my task title is awesome', $tasks[0]['title']);
+
+ $tf->search('my task title');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('my task title is awesome', $tasks[0]['title']);
+ $this->assertEquals('my task title is amazing', $tasks[1]['title']);
+
+ $tf->search('my task title assignee:nobody');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('my task title is amazing', $tasks[0]['title']);
+
+ $tf->search('assignee:"Bob ryan" assignee:nobody');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('my task title is amazing', $tasks[0]['title']);
+ $this->assertEquals('Bob at work', $tasks[1]['title']);
+ }
+
public function testCopy()
{
$tf = new TaskFilter($this->container);