public function testSameAs() { $todo1 = TodoParser::parse('This is a test todo +projects @contexts Due:2015-04-26'); $todo2 = TodoParser::parse('This is a test todo +projects @contexts Due:2015-04-26'); $todo3 = TodoParser::parse('This is a different test todo +projects @contexts Due:2015-04-26'); $this->assertTrue($todo1->sameAs($todo2), 'Failed to compare similar Todos'); $this->assertFalse($todo2->sameAs($todo3), 'Failed to detect different Todos'); }
public function testCanParseDateShortCuts() { //Test day names $dayNames = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; foreach ($dayNames as $day) { $testTodoText = "(A) This is a test todo due:{$day} +project @context"; $testTodo = TodoParser::parse($testTodoText); $this->assertNotNull($testTodo->getDue(), 'Could not parse due date with day name: ' . $day); if ($testTodo->getDue()) { $this->assertEquals((new \DateTime($day))->format(Todo::TODO_DATE_FORMAT), $testTodo->getDue()->format(Todo::TODO_DATE_FORMAT), 'Could not parse due date with full day name'); } $testTodoText = "(A) This is a test todo due:{$day}"; $testTodo = TodoParser::parse($testTodoText); $this->assertNotNull($testTodo->getDue(), 'Could not parse due date with day name: ' . $day . ' at end of line'); if ($testTodo->getDue()) { $this->assertEquals((new \DateTime($day))->format(Todo::TODO_DATE_FORMAT), $testTodo->getDue()->format(Todo::TODO_DATE_FORMAT), 'Could not parse due date with full day name'); } } //Test relative date strings $dayStrings = ['today', 'tomorrow', 'yesterday', 'next monday', 'next week']; foreach ($dayStrings as $day) { $testTodoText = "(A) This is a test todo due:{$day} +project @context"; $testTodo = TodoParser::parse($testTodoText); $this->assertNotNull($testTodo->getDue(), 'Could not parse due date with day string: ' . $day); if ($testTodo->getDue()) { $this->assertEquals((new \DateTime($day))->format(Todo::TODO_DATE_FORMAT), $testTodo->getDue()->format(Todo::TODO_DATE_FORMAT), 'Could not parse due date with full day name'); } $testTodoText = "(A) This is a test todo due:{$day} +project @context"; $testTodo = TodoParser::parse($testTodoText); $this->assertNotNull($testTodo->getDue(), 'Could not parse due date with day string: ' . $day . ' at end of line'); if ($testTodo->getDue()) { $this->assertEquals((new \DateTime($day))->format(Todo::TODO_DATE_FORMAT), $testTodo->getDue()->format(Todo::TODO_DATE_FORMAT), 'Could not parse due date with full day name'); } } }