diff options
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | app/Core/Filter/Lexer.php | 11 | ||||
-rw-r--r-- | tests/units/Core/Filter/LexerTest.php | 89 | ||||
-rw-r--r-- | tests/units/Filter/ProjectActivityCreationDateFilterTest.php | 20 |
4 files changed, 112 insertions, 9 deletions
@@ -11,6 +11,7 @@ New features: Improvements: +* Support strtotime strings for date search * Reset failed login counter and unlock user when changing password * Task do not open anymore in a new window on the Gantt chart * Do not display task progress for tasks with no start/end date diff --git a/app/Core/Filter/Lexer.php b/app/Core/Filter/Lexer.php index 041b58d3..8a7a68b1 100644 --- a/app/Core/Filter/Lexer.php +++ b/app/Core/Filter/Lexer.php @@ -26,9 +26,10 @@ class Lexer */ private $tokenMap = array( "/^(\s+)/" => 'T_WHITESPACE', - '/^([<=>]{0,2}[0-9]{4}-[0-9]{2}-[0-9]{2})/' => 'T_DATE', - '/^(yesterday|tomorrow|today)/' => 'T_DATE', - '/^("(.*?)")/' => 'T_STRING', + '/^([<=>]{0,2}[0-9]{4}-[0-9]{2}-[0-9]{2})/' => 'T_STRING', + '/^([<=>]{1,2}\w+)/' => 'T_STRING', + '/^([<=>]{1,2}".+")/' => 'T_STRING', + '/^("(.+)")/' => 'T_STRING', "/^(\w+)/" => 'T_STRING', "/^(#\d+)/" => 'T_STRING', ); @@ -107,7 +108,7 @@ class Lexer $this->offset += strlen($matches[1]); return array( - 'match' => trim($matches[1], '"'), + 'match' => str_replace('"', '', $matches[1]), 'token' => $name, ); } @@ -134,7 +135,7 @@ class Lexer } else { $next = next($tokens); - if ($next !== false && in_array($next['token'], array('T_STRING', 'T_DATE'))) { + if ($next !== false && $next['token'] === 'T_STRING') { $map[$token['token']][] = $next['match']; } } diff --git a/tests/units/Core/Filter/LexerTest.php b/tests/units/Core/Filter/LexerTest.php index 3f3e368e..d405e9df 100644 --- a/tests/units/Core/Filter/LexerTest.php +++ b/tests/units/Core/Filter/LexerTest.php @@ -77,22 +77,103 @@ class LexerTest extends Base public function testTokenizeWithStringDate() { $lexer = new Lexer(); - $lexer->addToken("/^(date:)/", 'T_DATE'); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); $expected = array( - 'T_DATE' => array('today'), + 'T_MY_DATE' => array('today'), ); $this->assertSame($expected, $lexer->tokenize('date:today something else')); } + public function testTokenizeWithStringDateWithSpaces() + { + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('last month'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:"last month" something else')); + } + + public function testTokenizeWithStringDateWithSpacesAndOperator() + { + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('<=last month'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:<="last month" something else')); + + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('>=next month'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:>="next month" something else')); + + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('<+2 days'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:<"+2 days" something else')); + + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('<-1 hour'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:<"-1 hour" something else')); + } + + public function testTokenizeWithStringDateAndOperator() + { + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('<=today'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:<=today something else')); + + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('>now'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:>now something else')); + + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('>=now'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:>=now something else')); + } + public function testTokenizeWithIsoDate() { $lexer = new Lexer(); - $lexer->addToken("/^(date:)/", 'T_DATE'); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); $expected = array( - 'T_DATE' => array('<=2016-01-01'), + 'T_MY_DATE' => array('<=2016-01-01'), ); $this->assertSame($expected, $lexer->tokenize('date:<=2016-01-01 something else')); diff --git a/tests/units/Filter/ProjectActivityCreationDateFilterTest.php b/tests/units/Filter/ProjectActivityCreationDateFilterTest.php index d679f285..1dce4451 100644 --- a/tests/units/Filter/ProjectActivityCreationDateFilterTest.php +++ b/tests/units/Filter/ProjectActivityCreationDateFilterTest.php @@ -51,6 +51,26 @@ class ProjectActivityCreationDateFilterTest extends Base $this->assertCount(0, $events); } + public function testWithStrtotimeString() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityCreationDateFilter('<=last week'); + $filter->setDateParser($this->container['dateParser']); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(0, $events); + } + public function testWithIsoDate() { $taskFinder = new TaskFinder($this->container); |