Taskwarrior/tests/TaskManagerTest.php

940 lines
26 KiB
PHP
Raw Normal View History

2015-02-05 13:41:03 -06:00
<?php
namespace DavidBadura\Taskwarrior\Test;
2015-02-08 12:32:51 -06:00
use DavidBadura\Taskwarrior\Recurring;
2015-02-05 13:41:03 -06:00
use DavidBadura\Taskwarrior\Task;
2015-02-06 05:38:54 -06:00
use DavidBadura\Taskwarrior\TaskManager;
2015-02-05 13:41:03 -06:00
use DavidBadura\Taskwarrior\Taskwarrior;
use Symfony\Component\Filesystem\Filesystem;
/**
2015-07-25 04:02:18 -05:00
* @author David Badura <d.a.badura@gmail.com>
* @author Tobias Olry <tobias.olry@gmail.com>
2015-02-05 13:41:03 -06:00
*/
2015-02-06 05:38:54 -06:00
class TaskManagerTest extends \PHPUnit_Framework_TestCase
2015-02-05 13:41:03 -06:00
{
/**
* @var Taskwarrior
*/
protected $taskwarrior;
2015-02-06 05:38:54 -06:00
/**
* @var TaskManager
*/
protected $taskManager;
2015-04-22 07:31:30 -05:00
/**
* @var string
*/
protected $taskDir;
2015-02-05 13:41:03 -06:00
public function setUp()
{
2015-04-22 07:31:30 -05:00
$this->taskDir = __DIR__;
$fs = new Filesystem();
$fs->remove($this->taskDir . '/.taskrc');
$fs->remove($this->taskDir . '/.task');
2015-08-01 16:50:00 -05:00
$bin = 'task';
if (file_exists(__DIR__ . '/../task')) {
$bin = realpath(__DIR__ . '/../task');
}
$this->taskwarrior = new Taskwarrior($this->taskDir . '/.taskrc', $this->taskDir . '/.task', [], $bin);
2015-02-06 05:38:54 -06:00
$this->taskManager = new TaskManager($this->taskwarrior);
2015-02-06 06:08:13 -06:00
$this->taskwarrior->version(); // to initialise
2015-02-05 13:41:03 -06:00
}
public function tearDown()
{
$fs = new Filesystem();
2015-04-22 07:31:30 -05:00
$fs->remove($this->taskDir . '/.taskrc');
$fs->remove($this->taskDir . '/.task');
2015-02-05 13:41:03 -06:00
}
public function testEmpty()
{
2015-12-26 06:27:32 -06:00
$tasks = $this->taskManager->findPending();
2015-02-05 13:41:03 -06:00
$this->assertEmpty($tasks);
}
public function testSaveTask()
{
$task = new Task();
$task->setDescription('foo');
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task);
$this->taskManager->clear();
2015-02-05 13:41:03 -06:00
$this->assertNotEmpty($task->getUuid());
2015-02-06 05:38:54 -06:00
$result = $this->taskManager->find($task->getUuid());
2015-02-05 13:41:03 -06:00
$this->assertEquals($task, $result);
}
2015-06-28 08:11:00 -05:00
public function provideDescriptions()
{
return array(
array('hier http://google.de'),
array("test ' foo"),
array("test (foo) bar"),
array("foo-bar"),
array("test +bar")
);
}
/**
* @dataProvider provideDescriptions
*/
public function testDescription($description)
2015-04-23 11:49:41 -05:00
{
$task = new Task();
2015-06-28 08:11:00 -05:00
$task->setDescription($description);
2015-04-23 11:49:41 -05:00
$this->taskManager->save($task);
$this->taskManager->clear();
2015-06-28 08:11:00 -05:00
$task = $this->taskManager->find($task->getUuid());
2015-04-23 11:49:41 -05:00
2015-06-28 08:11:00 -05:00
$this->assertEquals($description, $task->getDescription());
2015-04-23 11:49:41 -05:00
$this->taskManager->save($task);
$this->taskManager->clear();
2015-06-28 08:11:00 -05:00
$task = $this->taskManager->find($task->getUuid());
2015-04-23 11:49:41 -05:00
2015-06-28 08:11:00 -05:00
$this->assertEquals($description, $task->getDescription());
2015-04-23 11:49:41 -05:00
}
2015-02-06 06:08:13 -06:00
public function testSaveTaskWithoutDescription()
{
2015-04-06 16:13:02 -05:00
$this->setExpectedException('DavidBadura\Taskwarrior\Exception\TaskwarriorException');
2015-02-06 06:08:13 -06:00
$task = new Task();
$this->taskManager->save($task);
}
2015-02-05 13:41:03 -06:00
public function testFindFromCache()
{
$task = new Task();
$task->setDescription('foo');
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task);
2015-02-05 13:41:03 -06:00
2015-02-06 05:38:54 -06:00
$result = $this->taskManager->find($task->getUuid());
2015-02-05 13:41:03 -06:00
$this->assertSame($task, $result);
}
public function testFilterFromCache()
{
$task = new Task();
$task->setDescription('foo');
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task);
2015-02-05 13:41:03 -06:00
2015-04-23 16:28:57 -05:00
$result = $this->taskManager->filter($task->getUuid());
2015-02-05 13:41:03 -06:00
$this->assertSame($task, $result[0]);
}
public function testDontFind()
{
2015-07-08 18:29:50 -05:00
$this->setExpectedException('DavidBadura\Taskwarrior\Exception\TaskwarriorException',
"task not found");
2015-02-06 05:38:54 -06:00
$task = $this->taskManager->find('56464asd46s4adas54da6');
2015-02-05 13:41:03 -06:00
}
public function testDoubleSave()
{
$task = new Task();
$task->setDescription('foo');
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task);
2015-02-05 13:41:03 -06:00
$this->assertNotEmpty($task->getUuid());
$uuid = $task->getUuid();
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task);
2015-02-05 13:41:03 -06:00
$this->assertEquals($uuid, $task->getUuid());
2015-12-26 06:27:32 -06:00
$this->assertCount(1, $this->taskManager->findPending());
2015-02-05 13:41:03 -06:00
2015-02-06 05:38:54 -06:00
$this->taskManager->clear();
2015-02-05 13:41:03 -06:00
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task);
2015-02-05 13:41:03 -06:00
$this->assertEquals($uuid, $task->getUuid());
2015-12-26 06:27:32 -06:00
$this->assertCount(1, $this->taskManager->findPending());
2015-02-05 13:41:03 -06:00
}
2015-02-06 12:01:04 -06:00
public function testClone()
{
$task = new Task();
$task->setDescription('foo');
$this->taskManager->save($task);
2015-12-26 06:27:32 -06:00
$this->assertCount(1, $this->taskManager->findPending());
2015-02-06 12:01:04 -06:00
$task2 = clone $task;
$this->taskManager->save($task2);
2015-12-26 06:27:32 -06:00
$this->assertCount(2, $this->taskManager->findPending());
2015-02-06 12:01:04 -06:00
$this->taskManager->done($task);
2015-08-02 10:46:03 -05:00
$this->assertTrue($task->isCompleted());
2015-02-06 12:01:04 -06:00
$task3 = clone $task;
2015-08-02 10:46:03 -05:00
$this->assertTrue($task3->isPending());
2015-02-06 12:01:04 -06:00
$this->taskManager->save($task3);
2015-08-02 10:46:03 -05:00
$this->assertTrue($task->isCompleted());
$this->assertTrue($task3->isPending());
2015-02-06 12:01:04 -06:00
}
2015-02-05 13:41:03 -06:00
public function testFilterAll()
{
$task1 = new Task();
$task1->setDescription('foo1');
$task2 = new Task();
$task2->setDescription('foo2');
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task1);
$this->taskManager->save($task2);
2015-02-05 13:41:03 -06:00
2015-12-26 06:27:32 -06:00
$result = $this->taskManager->findPending();
2015-04-22 05:44:11 -05:00
$this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $result);
$this->assertCount(2, $result);
2015-02-05 13:41:03 -06:00
}
2015-02-06 03:05:01 -06:00
public function testMultiFilter()
{
$task1 = new Task();
$task1->setDescription('foo1');
$task2 = new Task();
$task2->setDescription('foo2');
$task2->setPriority(Task::PRIORITY_HIGH);
$task2->setProject('home');
$task2->addTag('now');
2015-02-06 03:05:01 -06:00
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task1);
$this->taskManager->save($task2);
2015-02-06 03:05:01 -06:00
2015-12-26 06:27:32 -06:00
$this->assertCount(1, $this->taskManager->findPending('project:home prio:H +now'));
2015-02-06 03:05:01 -06:00
}
2015-02-08 05:23:14 -06:00
public function testModified()
2015-02-06 17:22:17 -06:00
{
2015-02-08 07:13:03 -06:00
if (version_compare($this->taskwarrior->version(), '2.2.0') < 0) {
2015-02-08 05:23:14 -06:00
$this->markTestSkipped(sprintf(
'taskwarrior version %s dont support modified attr',
$this->taskwarrior->version()
));
}
2015-02-06 17:22:17 -06:00
$task1 = new Task();
$task1->setDescription('foo1');
$this->taskManager->save($task1);
$this->assertInstanceOf('DateTime', $task1->getEntry());
2015-04-22 06:32:43 -05:00
$this->assertInstanceOf('DateTime', $task1->getModified());
$mod = $task1->getModified();
2015-04-22 06:39:33 -05:00
sleep(2);
2015-02-06 17:22:17 -06:00
$task1->setDescription('bar2');
$this->taskManager->save($task1);
$this->assertInstanceOf('DateTime', $task1->getEntry());
$this->assertInstanceOf('DateTime', $task1->getModified());
2015-04-22 06:32:43 -05:00
$this->assertNotEquals($mod, $task1->getModified());
2015-02-08 05:23:14 -06:00
}
public function testEnd()
{
$task1 = new Task();
$task1->setDescription('foo1');
$this->taskManager->save($task1);
$this->assertInstanceOf('DateTime', $task1->getEntry());
$this->assertNull($task1->getEnd());
$task1->setDescription('bar2');
$this->taskManager->save($task1);
$this->assertInstanceOf('DateTime', $task1->getEntry());
2015-02-06 17:22:17 -06:00
$this->assertNull($task1->getEnd());
$this->taskManager->done($task1);
$this->assertInstanceOf('DateTime', $task1->getEntry());
$this->assertInstanceOf('DateTime', $task1->getEnd());
}
2015-04-23 14:33:10 -05:00
public function testStart()
{
$task1 = new Task();
$task1->setDescription('foo1');
$this->taskManager->save($task1);
$this->assertNull($task1->getStart());
$this->taskManager->start($task1);
$this->taskManager->save($task1);
$this->assertInstanceOf('DateTime', $task1->getStart());
$this->taskManager->stop($task1);
$this->taskManager->save($task1);
$this->assertNull($task1->getStart());
}
2015-02-05 16:00:30 -06:00
public function testPending()
{
$task1 = new Task();
$task1->setDescription('foo1');
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task1);
2015-02-05 16:00:30 -06:00
$this->assertEquals(Task::STATUS_PENDING, $task1->getStatus());
$this->assertTrue($task1->isPending());
2015-02-06 05:38:54 -06:00
$this->taskManager->clear();
$result = $this->taskManager->find($task1->getUuid());
2015-02-05 16:00:30 -06:00
$this->assertEquals(Task::STATUS_PENDING, $result->getStatus());
$this->assertTrue($result->isPending());
2015-12-26 06:27:32 -06:00
$this->assertCount(1, $this->taskManager->findPending());
2015-02-05 16:00:30 -06:00
}
public function testDelete()
{
$task1 = new Task();
$task1->setDescription('foo1');
2015-12-26 06:27:32 -06:00
$this->assertCount(0, $this->taskManager->findPending());
2015-02-05 16:00:30 -06:00
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task1);
$this->assertCount(1, $this->taskManager->filter());
2015-12-26 06:27:32 -06:00
$this->assertCount(1, $this->taskManager->findPending());
2015-02-05 16:00:30 -06:00
$this->assertFalse($task1->isDeleted());
$this->assertEquals(Task::STATUS_PENDING, $task1->getStatus());
2015-02-06 05:38:54 -06:00
$this->taskManager->delete($task1);
2015-04-23 16:28:57 -05:00
$this->assertCount(1, $this->taskManager->filter());
2015-12-26 06:27:32 -06:00
$this->assertCount(0, $this->taskManager->findPending());
2015-02-05 16:00:30 -06:00
$this->assertTrue($task1->isDeleted());
$this->assertEquals(Task::STATUS_DELETED, $task1->getStatus());
}
public function testCompleted()
{
$task1 = new Task();
$task1->setDescription('foo1');
2015-12-26 06:27:32 -06:00
$this->assertCount(0, $this->taskManager->findPending());
2015-02-05 16:00:30 -06:00
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task1);
$this->assertCount(1, $this->taskManager->filter());
2015-12-26 06:27:32 -06:00
$this->assertCount(1, $this->taskManager->findPending());
2015-02-05 16:00:30 -06:00
$this->assertFalse($task1->isCompleted());
$this->assertEquals(Task::STATUS_PENDING, $task1->getStatus());
2015-02-06 05:38:54 -06:00
$this->taskManager->done($task1);
2015-04-23 16:28:57 -05:00
$this->assertCount(1, $this->taskManager->filter());
2015-12-26 06:27:32 -06:00
$this->assertCount(0, $this->taskManager->findPending());
2015-02-05 16:00:30 -06:00
$this->assertTrue($task1->isCompleted());
$this->assertEquals(Task::STATUS_COMPLETED, $task1->getStatus());
}
2015-02-05 13:41:03 -06:00
public function testModifyDescription()
{
$task1 = new Task();
$task1->setDescription('foo1');
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task1);
2015-02-05 13:41:03 -06:00
$this->assertEquals('foo1', $task1->getDescription());
$task1->setDescription('bar1');
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task1);
2015-02-05 13:41:03 -06:00
2015-02-06 05:38:54 -06:00
$this->taskManager->clear();
2015-02-05 13:41:03 -06:00
2015-02-06 05:38:54 -06:00
$result = $this->taskManager->find($task1->getUuid());
2015-02-05 13:41:03 -06:00
$this->assertEquals('bar1', $result->getDescription());
}
2015-02-05 17:09:29 -06:00
public function testDue()
{
$date = $this->createDateTime('1989-01-08 11:12:13');
$task1 = new Task();
$task1->setDescription('foo1');
$task1->setDue($date);
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task1);
$this->taskManager->clear();
2015-02-05 17:09:29 -06:00
2015-02-06 05:38:54 -06:00
$task2 = $this->taskManager->find($task1->getUuid());
2015-02-05 17:09:29 -06:00
$this->assertEquals($date, $task2->getDue());
$newDate = $this->createDateTime('2002-02-20 11:12:13');
$task2->setDue($newDate);
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task2);
$this->taskManager->clear();
2015-02-05 17:09:29 -06:00
2015-02-06 05:38:54 -06:00
$task3 = $this->taskManager->find($task1->getUuid());
2015-02-05 17:09:29 -06:00
$this->assertEquals($newDate, $task3->getDue());
2015-02-05 17:34:57 -06:00
$task2->setDue(null);
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task2);
$this->taskManager->clear();
2015-02-05 17:34:57 -06:00
2015-02-06 05:38:54 -06:00
$task3 = $this->taskManager->find($task1->getUuid());
2015-02-05 17:34:57 -06:00
$this->assertNull($task3->getDue());
2015-02-05 17:09:29 -06:00
}
public function testUrgency()
{
$task1 = new Task();
$task1->setDescription('foo1');
2015-09-19 05:45:05 -05:00
$this->taskManager->save($task1);
$this->assertEquals(0, $task1->getUrgency());
2015-02-05 17:34:57 -06:00
$task1->setDue($this->createDateTime('1989-01-08 11:12:13'));
2015-02-05 17:09:29 -06:00
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task1);
2015-02-05 17:09:29 -06:00
$this->assertEquals(12, $task1->getUrgency());
2015-02-05 17:34:57 -06:00
$task1->setDue(null);
2015-02-06 05:38:54 -06:00
$this->taskManager->save($task1);
2015-02-05 17:34:57 -06:00
$this->assertEquals(0, $task1->getUrgency());
}
2015-08-02 09:39:17 -05:00
public function provideProjectNames()
2015-02-06 06:08:13 -06:00
{
2015-08-02 09:39:17 -05:00
return [
['foo'],
['später'],
['grandparent.parent.child'],
['parent.child'],
];
}
2015-02-06 06:08:13 -06:00
2015-08-02 09:39:17 -05:00
/**
* @dataProvider provideProjectNames
*/
public function testProject($project)
{
$task = new Task();
$task->setDescription('foo1');
$task->setProject($project);
2015-02-06 06:08:13 -06:00
2015-08-02 09:39:17 -05:00
// no exception thrown
$this->taskManager->save($task);
2015-02-06 06:08:13 -06:00
2015-08-02 09:39:17 -05:00
// refetch the task
2015-02-06 06:08:13 -06:00
$this->taskManager->clear();
2015-08-02 09:39:17 -05:00
$task = $this->taskManager->find($task->getUuid());
2015-02-06 06:08:13 -06:00
2015-08-02 09:39:17 -05:00
$this->assertEquals($project, $task->getProject());
2015-02-06 06:08:13 -06:00
2015-12-26 06:27:32 -06:00
$this->assertCount(1, $this->taskManager->findPending());
$this->assertCount(1, $this->taskManager->findPending('project:' . $project));
$this->assertCount(0, $this->taskManager->findPending('project:emtpy_project'));
2015-02-06 06:08:13 -06:00
}
public function testProjects()
{
$task1 = new Task();
$task1->setDescription('foo1');
$task1->setProject('home');
$task2 = new Task();
$task2->setDescription('foo2');
$task2->setProject('office');
$this->taskManager->save($task1);
$this->taskManager->save($task2);
2015-02-06 17:22:17 -06:00
$this->assertEquals(array('home', 'office'), $this->taskwarrior->projects());
2015-02-06 06:08:13 -06:00
}
2015-02-06 11:05:29 -06:00
public function testPriority()
{
$task1 = new Task();
$task1->setDescription('foo1');
$task1->setPriority(Task::PRIORITY_MEDIUM);
$this->taskManager->save($task1);
$this->taskManager->clear();
$task1 = $this->taskManager->find($task1->getUuid());
$this->assertEquals(Task::PRIORITY_MEDIUM, $task1->getPriority());
$task1->setPriority(Task::PRIORITY_HIGH);
$this->taskManager->save($task1);
$this->taskManager->clear();
$task1 = $this->taskManager->find($task1->getUuid());
$this->assertEquals(Task::PRIORITY_HIGH, $task1->getPriority());
}
2015-02-06 11:31:13 -06:00
public function testTag()
{
$task1 = new Task();
$task1->setDescription('foo1');
$this->taskManager->save($task1);
$this->taskManager->clear();
$task1 = $this->taskManager->find($task1->getUuid());
2015-04-03 09:11:02 -05:00
$this->assertTrue(is_array($task1->getTags()));
2015-02-06 11:31:13 -06:00
$this->assertEmpty($task1->getTags());
$task1->removeTag('a');
$task1->addTag('a');
2015-02-06 11:31:13 -06:00
$task1->setTags(array('a', 'b', 'c'));
$this->taskManager->save($task1);
$this->taskManager->clear();
$task1 = $this->taskManager->find($task1->getUuid());
$this->assertEquals(array('a', 'b', 'c'), $task1->getTags());
$task1->addTag('d');
$task1->removeTag('a');
$this->taskManager->save($task1);
$this->taskManager->clear();
$task1 = $this->taskManager->find($task1->getUuid());
$this->assertEquals(array('b', 'c', 'd'), $task1->getTags());
2015-12-26 06:27:32 -06:00
$this->assertCount(0, $this->taskManager->findPending('+a'));
$this->assertCount(1, $this->taskManager->findPending('+b'));
2015-02-06 11:31:13 -06:00
}
2015-04-03 15:27:45 -05:00
public function testTagUnicode()
{
$task1 = new Task();
$task1->setDescription('foo1');
$task1->addTag('später');
$this->taskManager->save($task1);
$this->taskManager->clear();
$task1 = $this->taskManager->find($task1->getUuid());
$this->assertEquals(array('später'), $task1->getTags());
2015-04-03 17:23:26 -05:00
$this->assertEquals(array('später'), $this->taskwarrior->tags());
2015-04-03 15:27:45 -05:00
2015-12-26 06:27:32 -06:00
$this->assertCount(1, $this->taskManager->findPending('+später'));
2015-04-03 15:27:45 -05:00
}
2015-06-28 08:34:51 -05:00
public function testTagNameNotAllowed()
{
$this->setExpectedException('DavidBadura\Taskwarrior\Exception\TaskwarriorException',
"Tag with the name 'foo-bar' is not allowed");
$task1 = new Task();
$task1->setDescription('foo1');
$task1->addTag('foo-bar');
$this->taskManager->save($task1);
}
2015-02-06 17:22:17 -06:00
public function testWait()
{
$task1 = new Task();
$task1->setDescription('foo1');
$this->taskManager->save($task1);
$this->taskManager->clear();
$task1 = $this->taskManager->find($task1->getUuid());
$this->assertNull($task1->getWait());
$task1->setWait($this->createDateTime('+2 sec'));
$this->taskManager->save($task1);
$this->assertTrue($task1->isWaiting());
2015-12-26 06:27:32 -06:00
$this->assertCount(0, $this->taskManager->findPending());
2015-04-23 16:28:57 -05:00
$this->assertCount(1, $this->taskManager->filter('status:waiting'));
2015-02-06 17:22:17 -06:00
sleep(3);
2015-12-26 06:27:32 -06:00
$this->assertCount(1, $this->taskManager->findPending());
2015-02-06 17:22:17 -06:00
$this->assertFalse($task1->isWaiting());
}
2015-02-08 06:13:53 -06:00
public function testRecurring()
2015-02-06 17:22:17 -06:00
{
2015-02-08 06:13:53 -06:00
$task1 = new Task();
$task1->setDescription('foo1');
$task1->setDue('tomorrow');
2015-02-08 07:29:44 -06:00
$task1->setRecurring('daily');
2015-02-08 06:13:53 -06:00
$this->taskManager->save($task1);
2015-04-23 16:28:57 -05:00
$this->assertCount(2, $this->taskManager->filter());
2015-02-06 17:22:17 -06:00
2015-04-03 15:27:45 -05:00
$this->assertTrue($task1->isRecurring());
2015-02-08 06:13:53 -06:00
2015-12-26 06:27:32 -06:00
$result = $this->taskManager->findPending();
2015-02-08 06:13:53 -06:00
$this->assertCount(1, $result);
$this->assertTrue($result[0]->isPending());
}
2015-04-03 15:27:45 -05:00
public function testRecurringRemoveRecurringException()
2015-04-03 09:11:02 -05:00
{
2015-04-06 16:13:02 -05:00
$this->setExpectedException('DavidBadura\Taskwarrior\Exception\TaskwarriorException',
2015-04-03 15:27:45 -05:00
'You cannot remove the recurrence from a recurring task.');
2015-04-03 09:11:02 -05:00
$task1 = new Task();
$task1->setDescription('foo1');
$task1->setDue('tomorrow');
$task1->setRecurring('daily');
$this->taskManager->save($task1);
$task1->setRecurring(null);
2015-04-03 09:36:58 -05:00
$this->taskManager->save($task1);
2015-04-03 09:11:02 -05:00
}
2015-04-03 15:27:45 -05:00
public function testRecurringRemoveDueException()
{
2015-04-06 16:13:02 -05:00
$this->setExpectedException('DavidBadura\Taskwarrior\Exception\TaskwarriorException',
2015-04-03 15:27:45 -05:00
'You cannot remove the due date from a recurring task.');
$task1 = new Task();
$task1->setDescription('foo1');
$task1->setDue('tomorrow');
$task1->setRecurring('daily');
$this->taskManager->save($task1);
$task1->setDue(null);
$this->taskManager->save($task1);
}
public function testRecurringWithoutDue()
{
2015-04-06 16:13:02 -05:00
$this->setExpectedException('DavidBadura\Taskwarrior\Exception\TaskwarriorException',
2015-04-03 15:27:45 -05:00
"A recurring task must also have a 'due' date.");
$task1 = new Task();
$task1->setDescription('foo1');
$task1->setRecurring('daily');
$this->taskManager->save($task1);
}
2015-04-03 09:11:02 -05:00
public function testRecurringNull()
{
$task1 = new Task();
$task1->setDescription('foo1');
$task1->setDue('tomorrow');
$task1->setRecurring(null);
$this->taskManager->save($task1);
2015-04-23 16:28:57 -05:00
$this->assertCount(1, $this->taskManager->filter());
2015-04-03 09:11:02 -05:00
}
2015-02-08 12:32:51 -06:00
public function testRecurringModify()
{
$recur1 = new Recurring(Recurring::DAILY);
$recur2 = new Recurring(Recurring::WEEKLY);
$task1 = new Task();
$task1->setDescription('foo1');
$task1->setDue('tomorrow');
$task1->setRecurring($recur1);
$this->taskManager->save($task1);
$this->taskManager->clear();
$task1 = $this->taskManager->find($task1->getUuid());
$this->assertEquals($recur1, $task1->getRecurring());
$task1->setRecurring($recur2);
$this->taskManager->save($task1);
$this->taskManager->clear();
$task1 = $this->taskManager->find($task1->getUuid());
$this->assertEquals($recur2, $task1->getRecurring());
}
2015-04-06 16:13:02 -05:00
public function testRecurringDelete()
{
$recur1 = new Recurring(Recurring::DAILY);
$task1 = new Task();
$task1->setDescription('foo1');
$task1->setDue('tomorrow');
$task1->setRecurring($recur1);
$this->taskManager->save($task1);
$this->taskManager->clear();
2015-04-23 16:28:57 -05:00
$this->assertCount(1, $this->taskManager->filter('status:recurring'));
$this->assertCount(2, $this->taskManager->filter());
2015-04-06 16:13:02 -05:00
$this->taskManager->delete($task1);
$this->taskManager->clear();
2015-04-23 16:28:57 -05:00
$this->assertCount(0, $this->taskManager->filter('status:recurring'));
$this->assertCount(2, $this->taskManager->filter());
2015-04-06 16:13:02 -05:00
}
2015-02-08 06:13:53 -06:00
public function testUntil()
{
2015-02-06 17:22:17 -06:00
$task1 = new Task();
$task1->setDescription('foo1');
$task1->setUntil('+2 sec');
$this->taskManager->save($task1);
2015-12-26 06:27:32 -06:00
$this->assertCount(1, $this->taskManager->findPending());
2015-02-06 17:22:17 -06:00
sleep(3);
2015-12-26 06:27:32 -06:00
$this->assertCount(0, $this->taskManager->findPending());
2015-02-06 17:22:17 -06:00
}
2015-02-06 11:31:13 -06:00
2015-02-08 12:32:51 -06:00
public function testUntilModify()
{
$date1 = $this->createDateTime('tomorrow');
$date2 = $this->createDateTime('+2 day');
$task1 = new Task();
$task1->setDescription('foo1');
$task1->setUntil($date1);
$this->taskManager->save($task1);
$this->taskManager->clear();
$task1 = $this->taskManager->find($task1->getUuid());
$this->assertEquals($date1, $task1->getUntil());
$task1->setUntil($date2);
$this->taskManager->save($task1);
$this->taskManager->clear();
$task1 = $this->taskManager->find($task1->getUuid());
$this->assertEquals($date2, $task1->getUntil());
}
2015-02-10 14:49:30 -06:00
public function testReopen()
{
$task = new Task();
$task->setDescription('foo');
$this->taskManager->save($task);
$this->assertTrue($task->isPending());
$this->assertNull($task->getEnd());
$this->taskManager->done($task);
$this->assertTrue($task->isCompleted());
$this->assertInstanceOf('Carbon\Carbon', $task->getEnd());
$this->taskManager->reopen($task);
$this->assertTrue($task->isPending());
$this->assertNull($task->getEnd());
$this->taskManager->delete($task);
$this->assertTrue($task->isDeleted());
$this->assertInstanceOf('Carbon\Carbon', $task->getEnd());
$this->taskManager->reopen($task);
$this->assertTrue($task->isPending());
$this->assertNull($task->getEnd());
}
2015-04-22 09:33:35 -05:00
public function testComplexFilter()
{
$task1 = new Task();
$task1->setDescription('foo1');
$this->taskManager->save($task1);
2015-04-23 16:28:57 -05:00
$this->assertCount(1, $this->taskManager->filter('(status:pending or status:waiting)'));
2015-12-26 06:27:32 -06:00
$this->assertCount(1, $this->taskManager->findPending('(status:pending or status:waiting)'));
2015-04-22 09:33:35 -05:00
}
2015-07-07 18:17:00 -05:00
public function testDependenciesException()
{
$this->setExpectedException('DavidBadura\Taskwarrior\Exception\ReferenceException');
$task1 = new Task();
$task1->setDescription("a");
$task2 = new Task();
$task2->setDescription("b");
$task3 = new Task();
$task3->setDescription("c");
$task1->addDependency($task2);
$task1->addDependency($task3);
$this->taskManager->save($task1);
}
public function testDependencies()
{
$task1 = new Task();
$task1->setDescription("a");
$task2 = new Task();
$task2->setDescription("b");
$task1->addDependency($task2);
$this->taskManager->save($task2);
$this->taskManager->save($task1);
$this->taskManager->clear();
$temp1 = $this->taskManager->find($task1->getUuid());
$this->assertCount(1, $temp1->getDependencies());
$temp2 = $temp1->getDependencies()[0];
$this->assertInstanceOf('DavidBadura\Taskwarrior\Task', $temp2);
2015-07-08 18:29:50 -05:00
$this->assertEquals($task2->getUuid(), $temp2->getUuid());
2015-07-07 18:17:00 -05:00
$this->assertEquals('b', $temp2->getDescription());
$temp1->removeDependency($temp2);
$this->taskManager->save($temp1);
$this->taskManager->clear();
$temp1 = $this->taskManager->find($task1->getUuid());
$this->assertCount(0, $temp1->getDependencies());
}
2015-07-08 18:29:50 -05:00
public function testLazyReferencesUuid()
{
$task = $this->taskManager->getReference('foo');
$this->assertEquals('foo', $task->getUuid());
}
public function testLazyReferencesNotFound()
{
$this->setExpectedException('DavidBadura\Taskwarrior\Exception\TaskwarriorException');
$task = $this->taskManager->getReference('foo');
$task->getDescription();
}
public function testLazyReferencesLoad()
{
$task = new Task();
$task->setDescription('foo');
$this->taskManager->save($task);
$this->taskManager->clear();
$task2 = $this->taskManager->getReference($task->getUuid());
$this->assertNotSame($task, $task2);
$this->assertEquals('foo', $task2->getDescription());
}
public function testSameReferences()
{
$task = new Task();
$task->setDescription('foo');
$this->taskManager->save($task);
$task2 = $this->taskManager->getReference($task->getUuid());
$this->assertSame($task, $task2);
$this->assertEquals('foo', $task2->getDescription());
}
public function testFilterReferences()
{
$task = new Task();
$task->setDescription('foo');
$this->taskManager->save($task);
$this->taskManager->clear();
$task = $this->taskManager->getReference($task->getUuid());
$this->taskManager->filter();
$this->assertEquals('foo', $task->getDescription());
}
2015-12-26 06:27:32 -06:00
public function testCount()
{
$this->assertEquals(0, $this->taskManager->count());
$task = new Task();
$task->setDescription('foo');
$task->addTag('bar');
$this->taskManager->save($task);
$this->assertEquals(1, $this->taskManager->count());
$this->assertEquals(1, $this->taskManager->count('+bar'));
$this->assertEquals(0, $this->taskManager->count('+baz'));
}
2015-02-05 17:09:29 -06:00
/**
* @param string $string
* @return \DateTime
*/
private function createDateTime($string = 'now')
{
2015-04-22 07:31:30 -05:00
return new \Carbon\Carbon($string);
2015-02-05 17:09:29 -06:00
}
2015-07-08 04:55:42 -05:00
}