fix tags
modified: README.md modified: src/Task.php modified: tests/TaskManagerTest.php
This commit is contained in:
		@@ -15,7 +15,6 @@ $task->setDescription('program this lib');
 | 
			
		||||
$task->setProject('hobby');
 | 
			
		||||
$task->setDue(new \DateTime('tomorrow'));
 | 
			
		||||
$task->setPriority(Task::PRIORITY_HIGH);
 | 
			
		||||
 | 
			
		||||
$task->addTag('next');
 | 
			
		||||
 | 
			
		||||
$tm->save($task);
 | 
			
		||||
 
 | 
			
		||||
@@ -184,6 +184,10 @@ class Task
 | 
			
		||||
     */
 | 
			
		||||
    public function addTag($tag)
 | 
			
		||||
    {
 | 
			
		||||
        if (!$this->tags) {
 | 
			
		||||
            $this->tags = [$tag];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!in_array($tag, $this->tags)) {
 | 
			
		||||
            $this->tags[] = $tag;
 | 
			
		||||
        }
 | 
			
		||||
@@ -194,6 +198,10 @@ class Task
 | 
			
		||||
     */
 | 
			
		||||
    public function removeTag($tag)
 | 
			
		||||
    {
 | 
			
		||||
        if (!$this->tags) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (false !== $key = array_search($tag, $this->tags)) {
 | 
			
		||||
            unset($this->tags[$key]);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -140,11 +140,14 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
 | 
			
		||||
 | 
			
		||||
        $task2 = new Task();
 | 
			
		||||
        $task2->setDescription('foo2');
 | 
			
		||||
        $task2->setPriority(Task::PRIORITY_HIGH);
 | 
			
		||||
        $task2->setProject('home');
 | 
			
		||||
        $task2->addTag('now');
 | 
			
		||||
 | 
			
		||||
        $this->taskManager->save($task1);
 | 
			
		||||
        $this->taskManager->save($task2);
 | 
			
		||||
 | 
			
		||||
        $this->assertCount(2, $this->taskManager->filter('status:pending')); // todo better test
 | 
			
		||||
        $this->assertCount(1, $this->taskManager->filter('project:home prio:H +now'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testPending()
 | 
			
		||||
@@ -384,6 +387,8 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
 | 
			
		||||
        $task1 = $this->taskManager->find($task1->getUuid());
 | 
			
		||||
        $this->assertEmpty($task1->getTags());
 | 
			
		||||
 | 
			
		||||
        $task1->removeTag('a');
 | 
			
		||||
        $task1->addTag('a');
 | 
			
		||||
        $task1->setTags(array('a', 'b', 'c'));
 | 
			
		||||
        $this->taskManager->save($task1);
 | 
			
		||||
        $this->taskManager->clear();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user