From 198f3eda90807c0295a013cd4ebdc3806545d608 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 4 Jul 2015 17:35:52 -0400 Subject: Add search attribute to search by reference --- tests/units/LexerTest.php | 30 ++++++++++++++++++++++++++++++ tests/units/TaskFilterTest.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) (limited to 'tests/units') diff --git a/tests/units/LexerTest.php b/tests/units/LexerTest.php index 38974357..0e3a61ae 100644 --- a/tests/units/LexerTest.php +++ b/tests/units/LexerTest.php @@ -171,6 +171,36 @@ class LexerTest extends Base ); } + public function testReferenceQuery() + { + $lexer = new Lexer; + + $this->assertEquals( + array(array('match' => 'ref:', 'token' => 'T_REFERENCE'), array('match' => '123', 'token' => 'T_STRING')), + $lexer->tokenize('ref:123') + ); + + $this->assertEquals( + array(array('match' => 'reference:', 'token' => 'T_REFERENCE'), array('match' => '456', 'token' => 'T_STRING')), + $lexer->tokenize('reference:456') + ); + + $this->assertEquals( + array('T_REFERENCE' => '123'), + $lexer->map($lexer->tokenize('reference:123')) + ); + + $this->assertEquals( + array('T_REFERENCE' => '456'), + $lexer->map($lexer->tokenize('ref:456')) + ); + + $this->assertEquals( + array(), + $lexer->map($lexer->tokenize('ref: ')) + ); + } + public function testDescriptionQuery() { $lexer = new Lexer; diff --git a/tests/units/TaskFilterTest.php b/tests/units/TaskFilterTest.php index c68e8880..6a48f194 100644 --- a/tests/units/TaskFilterTest.php +++ b/tests/units/TaskFilterTest.php @@ -27,6 +27,37 @@ class TaskFilterTest extends Base $this->assertEmpty($tf->search('search something')->findAll()); } + public function testSearchWithReference() + { + $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' => 'task1'))); + $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2', 'reference' => 123))); + + $tf->search('ref:123'); + $tasks = $tf->findAll(); + $this->assertNotEmpty($tasks); + $this->assertCount(1, $tasks); + $this->assertEquals('task2', $tasks[0]['title']); + + $tf->search('reference:123'); + $tasks = $tf->findAll(); + $this->assertNotEmpty($tasks); + $this->assertCount(1, $tasks); + $this->assertEquals('task2', $tasks[0]['title']); + + $tf->search('ref:plop'); + $tasks = $tf->findAll(); + $this->assertEmpty($tasks); + + $tf->search('ref:'); + $tasks = $tf->findAll(); + $this->assertEmpty($tasks); + } + public function testSearchWithStatus() { $p = new Project($this->container); -- cgit v1.2.3