summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/Core/Filter/LexerTest.php89
-rw-r--r--tests/units/Filter/ProjectActivityCreationDateFilterTest.php20
2 files changed, 105 insertions, 4 deletions
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);