From 74a84a28e34f3c1c38631fb80cc74ab589a44298 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Wed, 25 May 2016 21:00:01 -0400 Subject: Support strtotime strings for date search --- tests/units/Core/Filter/LexerTest.php | 89 +++++++++++++++++++++- .../ProjectActivityCreationDateFilterTest.php | 20 +++++ 2 files changed, 105 insertions(+), 4 deletions(-) (limited to 'tests/units') 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); -- cgit v1.2.3