finish annotation supprt
This commit is contained in:
parent
ece82c24a9
commit
d506df75ae
@ -24,6 +24,15 @@ class Annotation
|
|||||||
*/
|
*/
|
||||||
private $entry;
|
private $entry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $description
|
||||||
|
*/
|
||||||
|
public function __construct($description = null)
|
||||||
|
{
|
||||||
|
$this->entry = new Carbon(); // todo https://bug.tasktools.org/browse/TW-1780
|
||||||
|
$this->description = $description;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -111,7 +111,7 @@ class Task
|
|||||||
*
|
*
|
||||||
* @JMS\Type("array<DavidBadura\Taskwarrior\Annotation>")
|
* @JMS\Type("array<DavidBadura\Taskwarrior\Annotation>")
|
||||||
*/
|
*/
|
||||||
private $annotations;
|
private $annotations = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Carbon
|
* @var Carbon
|
||||||
@ -364,7 +364,7 @@ class Task
|
|||||||
*/
|
*/
|
||||||
public function getAnnotations()
|
public function getAnnotations()
|
||||||
{
|
{
|
||||||
return $this->annotations;
|
return (array)$this->annotations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -394,8 +394,9 @@ class Task
|
|||||||
*/
|
*/
|
||||||
public function removeAnnotation(Annotation $annotation)
|
public function removeAnnotation(Annotation $annotation)
|
||||||
{
|
{
|
||||||
if ($key = array_search($annotation, $this->annotations)) {
|
if (false !== $key = array_search($annotation, $this->annotations)) {
|
||||||
unset($this->annotations[$key]);
|
unset($this->annotations[$key]);
|
||||||
|
$this->annotations = array_values($this->annotations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace DavidBadura\Taskwarrior\Test;
|
namespace DavidBadura\Taskwarrior\Test;
|
||||||
|
|
||||||
|
use DavidBadura\Taskwarrior\Annotation;
|
||||||
use DavidBadura\Taskwarrior\Recurring;
|
use DavidBadura\Taskwarrior\Recurring;
|
||||||
use DavidBadura\Taskwarrior\Task;
|
use DavidBadura\Taskwarrior\Task;
|
||||||
use DavidBadura\Taskwarrior\TaskManager;
|
use DavidBadura\Taskwarrior\TaskManager;
|
||||||
@ -928,6 +929,64 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(0, $this->taskManager->count('+baz'));
|
$this->assertEquals(0, $this->taskManager->count('+baz'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEmptyAnnotation()
|
||||||
|
{
|
||||||
|
$task = new Task();
|
||||||
|
$task->setDescription('foo');
|
||||||
|
|
||||||
|
$this->taskManager->save($task);
|
||||||
|
|
||||||
|
$temp1 = $this->taskManager->find($task->getUuid());
|
||||||
|
|
||||||
|
$this->assertCount(0, $temp1->getAnnotations());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAnnotation()
|
||||||
|
{
|
||||||
|
$task = new Task();
|
||||||
|
$task->setDescription('foo');
|
||||||
|
$task->addAnnotation(new Annotation('testbar'));
|
||||||
|
|
||||||
|
$this->taskManager->save($task);
|
||||||
|
$task = $this->taskManager->find($task->getUuid());
|
||||||
|
|
||||||
|
$annotations = $task->getAnnotations();
|
||||||
|
$this->assertCount(1, $annotations);
|
||||||
|
$this->assertEquals('testbar', $annotations[0]->getDescription());
|
||||||
|
|
||||||
|
$task->addAnnotation(new Annotation('blabla'));
|
||||||
|
|
||||||
|
$this->taskManager->save($task);
|
||||||
|
$task = $this->taskManager->find($task->getUuid());
|
||||||
|
|
||||||
|
$annotations = $task->getAnnotations();
|
||||||
|
$this->assertCount(2, $annotations);
|
||||||
|
$this->assertEquals('testbar', $annotations[0]->getDescription());
|
||||||
|
$this->assertEquals('blabla', $annotations[1]->getDescription());
|
||||||
|
|
||||||
|
$task->removeAnnotation($annotations[0]);
|
||||||
|
|
||||||
|
$this->taskManager->save($task);
|
||||||
|
$task = $this->taskManager->find($task->getUuid());
|
||||||
|
|
||||||
|
$annotations = $task->getAnnotations();
|
||||||
|
$this->assertCount(1, $annotations);
|
||||||
|
$this->assertEquals('blabla', $annotations[0]->getDescription());
|
||||||
|
|
||||||
|
$task->setAnnotations([
|
||||||
|
new Annotation('foo'),
|
||||||
|
new Annotation('bar')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->taskManager->save($task);
|
||||||
|
$task = $this->taskManager->find($task->getUuid());
|
||||||
|
|
||||||
|
$annotations = $task->getAnnotations();
|
||||||
|
$this->assertCount(2, $annotations);
|
||||||
|
$this->assertEquals('foo', $annotations[0]->getDescription());
|
||||||
|
$this->assertEquals('bar', $annotations[1]->getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $string
|
* @param string $string
|
||||||
* @return \DateTime
|
* @return \DateTime
|
||||||
|
Loading…
Reference in New Issue
Block a user