Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
98b67855ca | |||
2d2122e05d | |||
84e96940ed | |||
d465f4481e |
@@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "aerex/taskwarrior",
|
"name": "aerex/taskwarrior-baikal-plugin",
|
||||||
"description": "A Baikal plugin for taskwarrior",
|
"description": "A Baikal plugin for taskwarrior",
|
||||||
"version": "1.0.0",
|
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"task",
|
"task",
|
||||||
@@ -10,11 +9,12 @@
|
|||||||
"Baikal",
|
"Baikal",
|
||||||
"sabre"
|
"sabre"
|
||||||
],
|
],
|
||||||
|
|
||||||
|
"repositories": [{"type": "vcs", "url": "https://aerex.me/git/Aerex/Taskwarrior"}],
|
||||||
"require": {
|
"require": {
|
||||||
|
"php": ">=5.5",
|
||||||
"sabre/dav": "~3.1.2",
|
"sabre/dav": "~3.1.2",
|
||||||
"davidbadura/taskwarrior": "^3.0",
|
|
||||||
"sabre/vobject": "^4.0",
|
"sabre/vobject": "^4.0",
|
||||||
"jms/serializer": "^1.13",
|
|
||||||
"easycorp/easy-log-handler": "^1.0"
|
"easycorp/easy-log-handler": "^1.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
1259
composer.lock
generated
1259
composer.lock
generated
File diff suppressed because it is too large
Load Diff
43
src/CalendarProcessor.php
Normal file
43
src/CalendarProcessor.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Aerex\TaskwarriorPlugin\Processors;
|
||||||
|
use Aerex\TaskwarriorPlugin\TaskwarriorManager;
|
||||||
|
use Sabre\VObject\Component\VTodo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ToDo
|
||||||
|
*
|
||||||
|
* @author Aerex
|
||||||
|
*/
|
||||||
|
class CalendarProcessor
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct(TaskwarriorManager $taskwarriorManager){
|
||||||
|
$this->taskwarriorManager = $taskwarriorManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function importTask(VTodo $Todo){
|
||||||
|
|
||||||
|
if($this->taskwarriorManager->exists($Todo->UID)){
|
||||||
|
$this->taskwarriorManager->updateTask($Todo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->taskwarriorManager->addTask($Todo);
|
||||||
|
|
||||||
|
} catch(Exception $e){
|
||||||
|
echo $e->getMessage();
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function export(){
|
||||||
|
echo "Not yet implemented";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aerex\TaskwarriorPlugin;
|
namespace Aerex\TaskwarriorPlugin\Configuration;
|
||||||
|
|
||||||
use DavidBadura\Taskwarrior\Taskwarrior;
|
use DavidBadura\Taskwarrior\Taskwarrior;
|
||||||
use Aerex\Taskwarrior\TaskwarriorManager;
|
use Aerex\TaskwarriorPlugin\TaskwarriorManager;
|
||||||
|
|
||||||
class Config {
|
class Config {
|
||||||
|
|
||||||
|
@@ -3,13 +3,13 @@
|
|||||||
namespace Aerex\TaskwarriorPlugin;
|
namespace Aerex\TaskwarriorPlugin;
|
||||||
|
|
||||||
use Sabre\DAV\Exception\BadRequest;
|
use Sabre\DAV\Exception\BadRequest;
|
||||||
use Sabre\VObject\Document;
|
use Sabre\VObject\Component\VCalendar;
|
||||||
use Sabre\HTTP\RequestInterface;
|
use Sabre\HTTP\RequestInterface;
|
||||||
use Sabre\HTTP\ResponseInterface;
|
use Sabre\HTTP\ResponseInterface;
|
||||||
use Sabre\Xml\ParseException;
|
use Sabre\Xml\ParseException;
|
||||||
use Sabre\DAV\ServerPlugin;
|
use Sabre\DAV\ServerPlugin;
|
||||||
use Sabre\DAV\Server;
|
use Sabre\DAV\Server;
|
||||||
use Aerex\TaskwarriorPlugin\iCalEventProcessor;
|
use Aerex\TaskwarriorPlugin\CalendarProcessor;
|
||||||
use Aerex\TaskwarriorPlugin\Config;
|
use Aerex\TaskwarriorPlugin\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +49,7 @@ class Plugin extends ServerPlugin {
|
|||||||
if(!is_null($TWCalManager)){
|
if(!is_null($TWCalManager)){
|
||||||
$this->twCalManager = $TWCalManager;
|
$this->twCalManager = $TWCalManager;
|
||||||
} else {
|
} else {
|
||||||
$this->twCalManager = new iCalEventProcessor();
|
$this->twCalManager = new CalendarProcessor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ class Plugin extends ServerPlugin {
|
|||||||
*
|
*
|
||||||
* @param VCalendar $vCal parsed calendar object
|
* @param VCalendar $vCal parsed calendar object
|
||||||
*/
|
*/
|
||||||
function processCalendarEventForTaskwarrior(Document $vCal){
|
function processCalendarEventForTaskwarrior(VCalendar $vCal){
|
||||||
try {
|
try {
|
||||||
$this->twCalManager->importTask($vCal->VTODO);
|
$this->twCalManager->importTask($vCal->VTODO);
|
||||||
} catch(BadRequest $e){
|
} catch(BadRequest $e){
|
||||||
|
@@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class TaskwarriorProps {
|
|
||||||
static $DESCRIPTION = 'description';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
10
src/Taskwarrior/Commands/IStrategy.php
Normal file
10
src/Taskwarrior/Commands/IStrategy.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
namespace Aerex\TaskwarriorPlugin\Taskwarrior\Commands;
|
||||||
|
|
||||||
|
use Aerex\TaskwarriorPlugin\Taskwarrior\Task;
|
||||||
|
|
||||||
|
interface Strategy {
|
||||||
|
public function add(Task $task);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
62
src/Taskwarrior/Commands/TodoStrategy.php
Normal file
62
src/Taskwarrior/Commands/TodoStrategy.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
class TodoStrategy implements IStrategy {
|
||||||
|
|
||||||
|
public function __construct(TaskwarriorConfig $config){
|
||||||
|
$this->config = $config;
|
||||||
|
$this->cmd[] = $this->config->taskBin();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add(Task $task){
|
||||||
|
$this->cmd[] = 'add';
|
||||||
|
|
||||||
|
if($task->getDescription() != null){
|
||||||
|
$this->cmd[] = sprintf('"%s"', $task->getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
if($task->getCategories() != null){
|
||||||
|
$categories = implode(' +', $task->getCategories());
|
||||||
|
$this->cmd[] = $categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($task->getDue() != null){
|
||||||
|
$this->cmd[] = $task->getDue('Y-m-dTH:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($task->getRecurrence() != null){
|
||||||
|
$rrule = $task->getRecurrence()->getParts();
|
||||||
|
$this->cmd[] = sprintf('recur:%s', $rrule['FREQ']);
|
||||||
|
if(isset($rrule['UNTIL'])){
|
||||||
|
$this->cmd[] = sprintf('until:%s', $rrule['UNTIL']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($task->getStatus() != null){
|
||||||
|
$this->cmd[] = sprintf('status:%s', $task->getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->executeCommand($cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private function executeCommand($command){
|
||||||
|
|
||||||
|
|
||||||
|
$cmdString = implode(' ', $command);
|
||||||
|
$process = new Process($cmdString);
|
||||||
|
|
||||||
|
$process->run();
|
||||||
|
|
||||||
|
if(!$process->isSuccessful()){
|
||||||
|
throw new TaskwarriorCommandLineException($process);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $process->getOutput();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
264
src/Taskwarrior/Task.php
Normal file
264
src/Taskwarrior/Task.php
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Aerex\TaskwarriorPlugin\Taskwarrior;
|
||||||
|
use Zend\Validator\Uuid;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Sabre\VObject\Component\VTodo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task
|
||||||
|
* @author Aerex
|
||||||
|
*/
|
||||||
|
class Task {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @JMS\Type("string")
|
||||||
|
*/
|
||||||
|
private $uuid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @JMS\Type("string")
|
||||||
|
*/
|
||||||
|
private $description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @JMS\Type("string")
|
||||||
|
*/
|
||||||
|
private $priority;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @JMS\Type("string")
|
||||||
|
*/
|
||||||
|
private $project;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Carbon
|
||||||
|
*
|
||||||
|
* @JMS\Type("Carbon")
|
||||||
|
*/
|
||||||
|
private $due;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Carbon
|
||||||
|
*
|
||||||
|
* @JMS\Type("Carbon")
|
||||||
|
*/
|
||||||
|
private $wait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*
|
||||||
|
* @JMS\Type("array<string>")
|
||||||
|
*/
|
||||||
|
private $tags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var float
|
||||||
|
*
|
||||||
|
* @JMS\Type("float")
|
||||||
|
*/
|
||||||
|
private $urgency;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Carbon
|
||||||
|
*
|
||||||
|
* @JMS\Type("Carbon")
|
||||||
|
*/
|
||||||
|
private $entry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Carbon
|
||||||
|
*
|
||||||
|
* @JMS\Type("Carbon")
|
||||||
|
*/
|
||||||
|
private $start;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @JMS\Type("Recurring")
|
||||||
|
*/
|
||||||
|
private $recur;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Carbon
|
||||||
|
*
|
||||||
|
* @JMS\Type("Carbon")
|
||||||
|
*/
|
||||||
|
private $until;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Annotation[]
|
||||||
|
*
|
||||||
|
* @JMS\Type("array<Aerex\Taskwarrior\Annotation>")
|
||||||
|
*/
|
||||||
|
private $annotations = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Carbon
|
||||||
|
*
|
||||||
|
* @JMS\Type("Carbon")
|
||||||
|
*/
|
||||||
|
private $modified;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Carbon
|
||||||
|
*
|
||||||
|
* @JMS\Type("Carbon")
|
||||||
|
*/
|
||||||
|
private $end;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @JMS\Type("string")
|
||||||
|
*/
|
||||||
|
private $status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Task[]|ArrayCollection
|
||||||
|
*
|
||||||
|
* @JMS\Type("Depends")
|
||||||
|
*/
|
||||||
|
private $depends;
|
||||||
|
|
||||||
|
public function __construct($UUID=null){
|
||||||
|
$validator = new Uuid();
|
||||||
|
|
||||||
|
if(!isset($UUID)){
|
||||||
|
$this->uuid = uniqid();
|
||||||
|
} else if(isset($UUID) && !$validator->isValid($UUID)){
|
||||||
|
throw new Exception(sprintf('%s is not a valid uuid', $UUID));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->uuid = $UUID;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* If description is not available attempt to summary, otherwise throw Exception
|
||||||
|
*/
|
||||||
|
public function setDescription(VTodo $component){
|
||||||
|
if(!isset($component->DESCRIPTION) && isset($component->SUMMARY)){
|
||||||
|
$this->description = $component->SUMMARY;
|
||||||
|
} else if(!isset($component->DESCRIPTION) && !isset($component->SUMMARY)){
|
||||||
|
throw new Exception("Task must have a description or summary");
|
||||||
|
} else {
|
||||||
|
$this->description = $component->DESCRIPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(){
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEntryTime(VTodo $document){
|
||||||
|
|
||||||
|
if(isset($document->DTSTAMP)){
|
||||||
|
$this->entry = new Carbon($document->DTSTAMP->getDateTime()->format(\DateTime::W3C));
|
||||||
|
} else {
|
||||||
|
throw new Exception('Task must have a entry time');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEntryTime(){
|
||||||
|
return $this->entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStartTime(VTodo $document){
|
||||||
|
if(isset($document->DTSTART)){
|
||||||
|
$this->start = new Carbon($document->DTSTART->getDateTime()->format(\DateTime::W3C));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStartTime(){
|
||||||
|
return $this->start;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setModifiedTime(VTodo $document){
|
||||||
|
if(isset($document->{'LAST-MODIFIED'})){
|
||||||
|
$this->modified = new Carbon($document->{'LAST-MODIFIED'}->getDateTime()->format(\DateTime::W3C));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getModifiedTime(){
|
||||||
|
return $this->modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDue(VTodo $document){
|
||||||
|
|
||||||
|
if(isset($document->DUE)){
|
||||||
|
$this->due = new Carbon($document->DUE->getDateTime()->format(\DateTime::W3C));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function getDue(){
|
||||||
|
return $this->due;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStopTime(VTodo $document){
|
||||||
|
if(isset($document->DTEND)){
|
||||||
|
$this->end = new Carbon($document->DTEND->getDateTime()->format(\DateTime::W3C));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStopTime(){
|
||||||
|
return $this->end;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCategories(VTodo $document){
|
||||||
|
if(isset($document->CATEGORIES)){
|
||||||
|
$this->tags = explode(',', (string)$document->CATEGORIES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCategories(){
|
||||||
|
return $this->tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStatus(VTodo $document){
|
||||||
|
if(isset($document->STATUS)){
|
||||||
|
switch((string)$document->STATUS){
|
||||||
|
case 'NEEDS-ACTION':
|
||||||
|
$this->status = 'pending';
|
||||||
|
break;
|
||||||
|
case 'COMPLETED':
|
||||||
|
$this->status = 'completed';
|
||||||
|
break;
|
||||||
|
case 'CANCELED':
|
||||||
|
$this->status = 'deleted';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRecurrence(VTodo $document){
|
||||||
|
if(isset($document->RRULE)){
|
||||||
|
$this->recur = $document->RRULE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatus(){
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
66
src/Taskwarrior/Taskwarrior.php
Normal file
66
src/Taskwarrior/Taskwarrior.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Aerex\TaskwarriorPlugin\Taskwarrior;
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
use Aerex\TaskwarriorPlugin\Commands\IStrategy;
|
||||||
|
|
||||||
|
class Taskwarrior {
|
||||||
|
|
||||||
|
const EXPORT = 'export';
|
||||||
|
const IMPORT = 'import';
|
||||||
|
const ADD = 'add';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var TaskwarriorConfig
|
||||||
|
*/
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $bin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $taskrc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $taskData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $rcOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function __construct(TaskwarriorConfig $config){
|
||||||
|
if(!isset($config)){
|
||||||
|
$this->config = new TaskwarriorConfig();
|
||||||
|
}
|
||||||
|
$this->config = $config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStrategy(IStrategy $strategy){
|
||||||
|
$this->strategy = $strategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createTask($uuid){
|
||||||
|
$task = new Task($uuid);
|
||||||
|
return $task;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function add($task){
|
||||||
|
$this->strategy($task);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
158
src/Taskwarrior/TaskwarriorManager.php
Normal file
158
src/Taskwarrior/TaskwarriorManager.php
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Aerex\TaskwarriorPlugin;
|
||||||
|
|
||||||
|
use Aerex\TaskwarriorPlugin\Taskwarrior;
|
||||||
|
use Sabre\VObject\Component\VTodo;
|
||||||
|
use DavidBadura\Taskwarrior\TaskManager;
|
||||||
|
use DavidBadura\Taskwarrior\Task;
|
||||||
|
|
||||||
|
class TaskwarriorManager {
|
||||||
|
|
||||||
|
const DESCRIPTION = 'description';
|
||||||
|
const CATEGORIES = 'categories';
|
||||||
|
const TASK_UUID = 'uuid';
|
||||||
|
const ICAL_UID = 'uid';
|
||||||
|
|
||||||
|
private $tasks;
|
||||||
|
|
||||||
|
const ENTRY = 'entry';
|
||||||
|
const START = 'start';
|
||||||
|
const MODIFIED = 'modified';
|
||||||
|
const END = 'end';
|
||||||
|
|
||||||
|
public function __construct($taskwarrior){
|
||||||
|
parent::__construct($taskwarrior);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createTask($UUID){
|
||||||
|
$task = new Task();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function export(VTodo $document){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addTask(VTodo $document){
|
||||||
|
|
||||||
|
$task = $this->taskwarrior->createTask($document->UID);
|
||||||
|
|
||||||
|
$task->setDescription($document);
|
||||||
|
|
||||||
|
$task->setEntry($document);
|
||||||
|
|
||||||
|
$task->setStartTime($document);
|
||||||
|
|
||||||
|
$task->setModifiedTime($document);
|
||||||
|
|
||||||
|
$task->setStopTime($document);
|
||||||
|
|
||||||
|
$task->setDue($document);
|
||||||
|
|
||||||
|
$task->setCategories($document);
|
||||||
|
|
||||||
|
$task->setStatus($document);
|
||||||
|
|
||||||
|
$task->setRecurrence($document);
|
||||||
|
|
||||||
|
return $this->taskwarrior->add($task);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateTask(VTodo $document){
|
||||||
|
|
||||||
|
$task = $this->taskwarrior->get($document->UID);
|
||||||
|
|
||||||
|
$task->setDescription($document);
|
||||||
|
|
||||||
|
$task->setEntry($document);
|
||||||
|
|
||||||
|
$task->setStartTime($document);
|
||||||
|
|
||||||
|
$task->setModifiedTime($document);
|
||||||
|
|
||||||
|
$task->setStopTime($document);
|
||||||
|
|
||||||
|
$task->setDue($document);
|
||||||
|
|
||||||
|
$task->setCategories($document);
|
||||||
|
|
||||||
|
$task->setStatus($document);
|
||||||
|
|
||||||
|
$task->setRecurrence($document);
|
||||||
|
|
||||||
|
$updatedTask = $this->taskwarrior->modify($task);
|
||||||
|
|
||||||
|
return $upatedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function setEntryTime($entry){
|
||||||
|
}
|
||||||
|
|
||||||
|
function exists($UUID){}
|
||||||
|
|
||||||
|
function setEndTime($end){}
|
||||||
|
function setModifiedTime($modifiedTime){}
|
||||||
|
function setSummary($description){
|
||||||
|
if(!isset($description)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->taskWarriorJSON[self::DESCRIPTION] = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setStartTime($startTime){}
|
||||||
|
function setCategories($categories){
|
||||||
|
if(!isset($categories)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!is_array($catergories)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->taskWarriorJSON[self::CATEGORIES] = $categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function taskExists($taskUuid){
|
||||||
|
$taskIsInCache = isset($this->cachedTasks[$taskUuid]);
|
||||||
|
|
||||||
|
if($taskIsInCache){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$jsonArray = $this->taskwarrior->export($taskUuid);
|
||||||
|
$taskWithUuidExists = count($jsonArray) > 0;
|
||||||
|
|
||||||
|
return $taskWithUuidExists;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(){
|
||||||
|
|
||||||
|
}
|
||||||
|
public function build(){
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param Task $task
|
||||||
|
* @param string $attr
|
||||||
|
* @param mixed $value
|
||||||
|
*/
|
||||||
|
public function setValue(Task $task, $attr, $value)
|
||||||
|
{
|
||||||
|
$refClass = new \ReflectionClass(Task::class);
|
||||||
|
$refProp = $refClass->getProperty($attr);
|
||||||
|
$refProp->setAccessible(true);
|
||||||
|
$refProp->setValue($task, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function setDescription($description){}
|
||||||
|
function parseiCalDateTime($iCalDateTime){}
|
||||||
|
function convertToStringArray($categories){}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@@ -1,112 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Aerex\TaskwarriorPlugin;
|
|
||||||
|
|
||||||
use Aerex\TaskwarriorPlugin\Taskwarrior;
|
|
||||||
use DavidBadura\Taskwarrior\TaskManager;
|
|
||||||
use DavidBadura\Taskwarrior\Task;
|
|
||||||
|
|
||||||
class TaskwarriorManager extends TaskManager {
|
|
||||||
|
|
||||||
const DESCRIPTION = 'description';
|
|
||||||
const CATEGORIES = 'categories';
|
|
||||||
const TASK_UUID = 'uuid';
|
|
||||||
const ICAL_UID = 'uid';
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @var \DavidBadura\Taskwarrior\Task
|
|
||||||
*/
|
|
||||||
private $tasks;
|
|
||||||
|
|
||||||
const ENTRY = 'entry';
|
|
||||||
const START = 'start';
|
|
||||||
const MODIFIED = 'modified';
|
|
||||||
const END = 'end';
|
|
||||||
|
|
||||||
public function __construct($taskwarrior){
|
|
||||||
parent::__construct($taskwarrior);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createTask($UUID){
|
|
||||||
$task = new Task();
|
|
||||||
$this->setValue($task, $ICAL_UID, $UUID);
|
|
||||||
return $task;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function export(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function setEntryTime($entry){
|
|
||||||
}
|
|
||||||
|
|
||||||
function exists($UUID){}
|
|
||||||
|
|
||||||
function setEndTime($end){}
|
|
||||||
function setModifiedTime($modifiedTime){}
|
|
||||||
function setSummary($description){
|
|
||||||
if(!isset($description)){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->taskWarriorJSON[self::DESCRIPTION] = $description;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setStartTime($startTime){}
|
|
||||||
function setCategories($categories){
|
|
||||||
if(!isset($categories)){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!is_array($catergories)){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->taskWarriorJSON[self::CATEGORIES] = $categories;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function taskExists($taskUuid){
|
|
||||||
$taskIsInCache = isset($this->cachedTasks[$taskUuid]);
|
|
||||||
|
|
||||||
if($taskIsInCache){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$jsonArray = $this->taskwarrior->export($taskUuid);
|
|
||||||
$taskWithUuidExists = count($jsonArray) > 0;
|
|
||||||
|
|
||||||
return $taskWithUuidExists;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function save(){
|
|
||||||
|
|
||||||
}
|
|
||||||
public function build(){
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param Task $task
|
|
||||||
* @param string $attr
|
|
||||||
* @param mixed $value
|
|
||||||
*/
|
|
||||||
public function setValue(Task $task, $attr, $value)
|
|
||||||
{
|
|
||||||
$refClass = new \ReflectionClass(Task::class);
|
|
||||||
$refProp = $refClass->getProperty($attr);
|
|
||||||
$refProp->setAccessible(true);
|
|
||||||
$refProp->setValue($task, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function setDescription($description){}
|
|
||||||
function parseiCalDateTime($iCalDateTime){}
|
|
||||||
function convertToStringArray($categories){}
|
|
||||||
function setDueDate($dueDate){}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
@@ -1,125 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Aerex\TaskwarriorPlugin;
|
|
||||||
|
|
||||||
use Aerex\TaskwarriorPlugin\Config;
|
|
||||||
use Sabre\DAV\Exception;
|
|
||||||
use Sabre\VObject\Component\VEvent;
|
|
||||||
use Sabre\VObject\Component\VTodo;
|
|
||||||
|
|
||||||
|
|
||||||
class iCalEventProcessor {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Config
|
|
||||||
*/
|
|
||||||
private $config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private $taskrc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
|
|
||||||
private $taskDataDir;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $cachedTasks = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
|
|
||||||
private $taskBinFile;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Taskwarrior
|
|
||||||
*/
|
|
||||||
|
|
||||||
private $taskwarrior;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Config $taskConfig = null){
|
|
||||||
if(!is_null($taskConfig)){
|
|
||||||
$this->taskConfig = $taskConfig;
|
|
||||||
} else {
|
|
||||||
$this->taskConfig = new Config();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->taskwarrior = $this->taskConfig->getTaskwarriorInstance();
|
|
||||||
$this->logger = $this->taskConfig->getLogger();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function importTask(VTodo $ToDoComponent = null){
|
|
||||||
|
|
||||||
if(!isset($ToDoComponent)){
|
|
||||||
$this->logger->error("vCal ToDo component is not defined");
|
|
||||||
throw new Exception("vCal Todo component is not defined");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if($this->taskwarrior->exists($ToDoComponent->UID)){
|
|
||||||
$this->logger->error("Event already exists " . (string)$ToDoComponent->UID);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
|
|
||||||
// parse iCalendar event times to DateTime objects
|
|
||||||
$entry = $this->taskwarrior->parseiCalDateTime($ToDoComponent->DSTAMP);
|
|
||||||
$start = $this->taskwarrior->parseiCalDateTime($ToDoComponent->DSTART);
|
|
||||||
$modified = $this->taskwarrior->parseiCalDateTime($ToDoComponent->{'LAST-MODIFIED'});
|
|
||||||
$end = $this->taskwarrior->parseiCalDateTime($ToDoComponent->DTEND);
|
|
||||||
|
|
||||||
$task = $this->taskwarrior->createTask($ToDoComponent->UID);
|
|
||||||
|
|
||||||
$tags = $this->taskwarrior->convertToStringArray($ToDoComponent->CATEGORIES);
|
|
||||||
$task->setTags($tags);
|
|
||||||
|
|
||||||
$task->setDue($ToDoComponent->DUE->getDateTime());
|
|
||||||
$task->setDescription($ToDoComponent->DESCRIPTION);
|
|
||||||
|
|
||||||
|
|
||||||
// override protected taskwarrior properties using iCal event
|
|
||||||
|
|
||||||
$this->taskwarrior->setValue($task, $this->taskwarrior::ENTRY, $entry);
|
|
||||||
$this->taskwarrior->setValue($task, $this->taskwarrior::START, $start);
|
|
||||||
$this->taskwarrior->setValue($task, $this->taskwarrior::MODIFIED, $modified);
|
|
||||||
$this->taskwarrior->setValue($task, $this->taskwarrior::END, $end);
|
|
||||||
|
|
||||||
$this->taskwarrior->save($task);
|
|
||||||
|
|
||||||
} catch(Exception $e){
|
|
||||||
$this->logger->error($e->message);
|
|
||||||
throw $e;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
59
tests/Processors/TodoTest.php
Normal file
59
tests/Processors/TodoTest.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Sabre\DAV\Exception\BadRequest;
|
||||||
|
use Monolog\Logger;
|
||||||
|
use Aerex\TaskwarriorPlugin\TaskwarriorManager;
|
||||||
|
use Aerex\TaskwarriorPlugin\Processors\ToDo;
|
||||||
|
use Sabre\VObject\Component\VCalendar;
|
||||||
|
use DavidBadura\Taskwarrior\Task;
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TodoTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||||
|
* */
|
||||||
|
private $mockTaskwarriorManager;
|
||||||
|
|
||||||
|
|
||||||
|
function setup(){
|
||||||
|
|
||||||
|
$this->mockTaskwarriorManager = $this->createMock(TaskwarriorManager::class);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function testImportAndAddTask(){
|
||||||
|
$uuid = '9f353281-1051-4c45-92db-462f5d353c76';
|
||||||
|
$mockVCalendar = new VCalendar();
|
||||||
|
$mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]);
|
||||||
|
|
||||||
|
$this->mockTaskwarriorManager->expects($this->once())->method('exists')->with($this->equalTo($uuid))
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
$this->mockTaskwarriorManager->expects($this->once())->method('addTask')->with($this->equalTo($mockVTodo));
|
||||||
|
$todo = new ToDo($this->mockTaskwarriorManager);
|
||||||
|
$todo->import($mockVTodo);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function testImportAndUpdateTask(){
|
||||||
|
$uuid = '9f353281-1051-4c45-92db-462f5d353c76';
|
||||||
|
|
||||||
|
$mockVCalendar = new VCalendar();
|
||||||
|
$mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]);
|
||||||
|
|
||||||
|
$this->mockTaskwarriorManager->expects($this->once())->method('exists')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
|
||||||
|
$this->mockTaskwarriorManager->expects($this->once())->method('updateTask');
|
||||||
|
|
||||||
|
$todo = new ToDo($this->mockTaskwarriorManager);
|
||||||
|
$todo->import($mockVTodo);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
173
tests/TaskTest.php
Normal file
173
tests/TaskTest.php
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Sabre\VObject\Component\VCalendar;
|
||||||
|
use Sabre\DAV\Exception\BadRequest;
|
||||||
|
use Aerex\TaskwarriorPlugin\Taskwarrior\Task;
|
||||||
|
use Aerex\TaskwarriorPlugin\Plugin;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Aerex\TaskwarriorPlugin\Config;
|
||||||
|
use Sabre\DAV\Server;
|
||||||
|
use DateTime;
|
||||||
|
use DateTimeZone;
|
||||||
|
|
||||||
|
class TaskTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Plugin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private $plugin;
|
||||||
|
/**
|
||||||
|
* @var VCalendar
|
||||||
|
*/
|
||||||
|
private $cal;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Server
|
||||||
|
*/
|
||||||
|
private $server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var TaskwarriorCalendarEvent
|
||||||
|
*/
|
||||||
|
private $mockTaskCalEvent;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function testSetDescriptionUsingDescription(){
|
||||||
|
$uuid = 'f987aa59-9031-4a7b-9cf3-6bfa4dc44a85';
|
||||||
|
$expectedDescription = 'This is a description';
|
||||||
|
|
||||||
|
$mockVCalendar = new VCalendar();
|
||||||
|
$mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]);
|
||||||
|
|
||||||
|
$mockVTodo->DESCRIPTION = $expectedDescription;
|
||||||
|
|
||||||
|
|
||||||
|
$todo = new Task();
|
||||||
|
|
||||||
|
$todo->setDescription($mockVTodo);
|
||||||
|
$actualDescription = $todo->getDescription();
|
||||||
|
|
||||||
|
$this->assertEquals($expectedDescription, $actualDescription);
|
||||||
|
}
|
||||||
|
public function testSetDescriptionUsingSummary(){
|
||||||
|
$uuid = 'f987aa59-9031-4a7b-9cf3-6bfa4dc44a85';
|
||||||
|
$expectedDescription = 'This is a description';
|
||||||
|
|
||||||
|
$mockVCalendar = new VCalendar();
|
||||||
|
$mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]);
|
||||||
|
|
||||||
|
$mockVTodo->SUMMARY = $expectedDescription;
|
||||||
|
|
||||||
|
|
||||||
|
$todo = new Task();
|
||||||
|
|
||||||
|
$todo->setDescription($mockVTodo);
|
||||||
|
$actualDescription = $todo->getDescription();
|
||||||
|
|
||||||
|
$this->assertEquals($expectedDescription, $actualDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Error
|
||||||
|
*/
|
||||||
|
public function testFailureSetDescription(){
|
||||||
|
$uuid = 'f987aa59-9031-4a7b-9cf3-6bfa4dc44a85';
|
||||||
|
$expectedDescription = 'This is a description';
|
||||||
|
|
||||||
|
$mockVCalendar = new VCalendar();
|
||||||
|
$mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]);
|
||||||
|
|
||||||
|
$todo = new Task();
|
||||||
|
|
||||||
|
$todo->setDescription($mockVTodo);
|
||||||
|
$actualDescription = $todo->getDescription();
|
||||||
|
|
||||||
|
}
|
||||||
|
public function testSetEntryTime(){
|
||||||
|
$uuid = 'f987aa59-9031-4a7b-9cf3-6bfa4dc44a85';
|
||||||
|
$expectedEntryTime = new DateTime('2018-11-11');
|
||||||
|
|
||||||
|
$mockVCalendar = new VCalendar();
|
||||||
|
$mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]);
|
||||||
|
$expectedCarbonDate = new Carbon($expectedEntryTime->format('Y-m-d'));
|
||||||
|
$mockVTodo->DTSTAMP = $expectedEntryTime;
|
||||||
|
|
||||||
|
$todo = new Task();
|
||||||
|
|
||||||
|
$todo->setEntryTime($mockVTodo);
|
||||||
|
$actualEntryTime = $todo->getEntryTime();
|
||||||
|
|
||||||
|
$this->assertEquals($expectedCarbonDate, $actualEntryTime);
|
||||||
|
}
|
||||||
|
public function testSetStartTime(){
|
||||||
|
$uuid = 'f987aa59-9031-4a7b-9cf3-6bfa4dc44a85';
|
||||||
|
$expectedStartTime = new DateTime('2018-11-11');
|
||||||
|
|
||||||
|
$mockVCalendar = new VCalendar();
|
||||||
|
$mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]);
|
||||||
|
$expectedCarbonDate = new Carbon($expectedStartTime->format('Y-m-d'));
|
||||||
|
$mockVTodo->DTSTART = $expectedStartTime;
|
||||||
|
|
||||||
|
$todo = new Task();
|
||||||
|
|
||||||
|
$todo->setStartTime($mockVTodo);
|
||||||
|
$actualStartTime = $todo->getStartTime();
|
||||||
|
|
||||||
|
$this->assertEquals($expectedCarbonDate, $actualStartTime);
|
||||||
|
}
|
||||||
|
public function testSetModifiedTime(){
|
||||||
|
$uuid = '182a6301-98e6-44df-97eb-8c7620f25b43';
|
||||||
|
$expectedModifiedTime = new DateTime('2018-11-11');
|
||||||
|
|
||||||
|
$mockVCalendar = new VCalendar();
|
||||||
|
$mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]);
|
||||||
|
$expectedCarbonDate = new Carbon($expectedModifiedTime->format('Y-m-d'));
|
||||||
|
$mockVTodo->{'LAST-MODIFIED'} = $expectedModifiedTime;
|
||||||
|
|
||||||
|
$todo = new Task();
|
||||||
|
|
||||||
|
$todo->setModifiedTime($mockVTodo);
|
||||||
|
$actualModifiedTime = $todo->getModifiedTime();
|
||||||
|
|
||||||
|
$this->assertEquals($expectedCarbonDate, $actualModifiedTime);
|
||||||
|
}
|
||||||
|
public function testSetDue(){
|
||||||
|
$uuid = 'dde78b02-97d9-4e11-8603-e0fc14474c7c';
|
||||||
|
$expectedDueTime = new DateTime('2018-11-11');
|
||||||
|
|
||||||
|
$mockVCalendar = new VCalendar();
|
||||||
|
$mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]);
|
||||||
|
$expectedCarbonDate = new Carbon($expectedDueTime->format('Y-m-d'));
|
||||||
|
$mockVTodo->DUE = $expectedDueTime;
|
||||||
|
|
||||||
|
$todo = new Task();
|
||||||
|
|
||||||
|
$todo->setDue($mockVTodo);
|
||||||
|
$actualDue = $todo->getDue();
|
||||||
|
|
||||||
|
$this->assertEquals($expectedCarbonDate, $actualDue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetCategories(){
|
||||||
|
|
||||||
|
$uuid = '182a6301-98e6-44df-97eb-8c7620f25b43';
|
||||||
|
$expectedCategories = array("home", "work");
|
||||||
|
|
||||||
|
$mockVCalendar = new VCalendar();
|
||||||
|
$mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]);
|
||||||
|
$mockVTodo->CATEGORIES = $expectedCategories;
|
||||||
|
|
||||||
|
$todo = new Task();
|
||||||
|
|
||||||
|
$todo->setCategories($mockVTodo);
|
||||||
|
$actualCategories = $todo->getCategories();
|
||||||
|
|
||||||
|
$this->assertEquals($expectedCategories, $actualCategories);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -1,174 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Sabre\DAV\Exception\BadRequest;
|
|
||||||
use Monolog\Logger;
|
|
||||||
use Sabre\VObject\Component\VCalendar;
|
|
||||||
use Aerex\TaskwarriorPlugin\TaskwarriorManager;
|
|
||||||
use Aerex\TaskwarriorPlugin\iCalEventProcessor;
|
|
||||||
use Aerex\TaskwarriorPlugin\Config;
|
|
||||||
use DavidBadura\Taskwarrior\Task;
|
|
||||||
use DateTime;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class iCalEventProcessorTest extends \PHPUnit\Framework\TestCase {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
|
||||||
* */
|
|
||||||
private $mockTaskwarrior;
|
|
||||||
|
|
||||||
/***
|
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
|
||||||
*/
|
|
||||||
private $mockTaskwarriorConfig;
|
|
||||||
|
|
||||||
/***
|
|
||||||
* @var \PHPUnit_Framework__MockObject
|
|
||||||
*/
|
|
||||||
private $mockLogger;
|
|
||||||
|
|
||||||
function setup(){
|
|
||||||
|
|
||||||
$this->mockTaskwarrior = $this->createMock(TaskwarriorManager::class);
|
|
||||||
$this->mockTask = $this->createMock(Task::class);
|
|
||||||
$this->mockTaskwarriorConfig = $this->createMock(Config::class);
|
|
||||||
$this->mockLogger = $this->createMock(Logger::class);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function testConstructorWithConfig() {
|
|
||||||
$this->mockTaskwarriorConfig->expects($this->once())
|
|
||||||
->method('getTaskwarriorInstance')
|
|
||||||
->will($this->returnValue($this->mockTaskwarrior));
|
|
||||||
|
|
||||||
$this->taskCalEvent = new iCalEventProcessor($this->mockTaskwarriorConfig);
|
|
||||||
|
|
||||||
}
|
|
||||||
function testBuildToDoComponent(){
|
|
||||||
$uuid = '9f353281-1051-4c45-92db-462f5d353c76';
|
|
||||||
$startTime = new DateTime('2018-07-04');
|
|
||||||
$endTime = new DateTime('2018-07-06');
|
|
||||||
$modifiedTime = new DateTime('2018-08-05');
|
|
||||||
$categories = array('home', 'test');
|
|
||||||
$dueDate = new DateTime('2018-08-20');
|
|
||||||
$description = 'This is a simple todo';
|
|
||||||
|
|
||||||
$mockVCalendar = new VCalendar();
|
|
||||||
$mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]);
|
|
||||||
$mockVTodo->add('DSTAMP', $startTime);
|
|
||||||
$mockVTodo->add('DUE', $dueDate);
|
|
||||||
$mockVTodo->add('LAST-MODIFIED',$modifiedTime);
|
|
||||||
$mockVTodo->add('DSTART', $startTime);
|
|
||||||
$mockVTodo->add('DTEND', $endTime);
|
|
||||||
$mockVTodo->add('DESCRIPTION', $description);
|
|
||||||
$mockVTodo->add('CATEGORIES', $categories);
|
|
||||||
|
|
||||||
$this->mockTaskwarrior->expects($this->exactly(4))
|
|
||||||
->method('parseiCalDateTime')
|
|
||||||
->will($this->onConsecutiveCalls($startTime, $startTime, $modifiedTime, $endTime));
|
|
||||||
|
|
||||||
$this->mockTaskwarrior->expects($this->once())->method('createTask')->with($this->equalTo($uuid))
|
|
||||||
->willReturn($this->mockTask);
|
|
||||||
$this->mockTask->expects($this->once())->method('setDue')->with($this->equalTo($dueDate));
|
|
||||||
$this->mockTask->expects($this->once())->method('setDescription')->with($this->equalTo($description));
|
|
||||||
$this->mockTaskwarrior->expects($this->once())->method('convertToStringArray')->with($this->equalTo($mockVTodo->CATEGORIES))
|
|
||||||
->willReturn($categories);
|
|
||||||
|
|
||||||
$this->mockTask->expects($this->once())->method('setTags')
|
|
||||||
->with($this->equalTo($categories));
|
|
||||||
|
|
||||||
$this->mockTaskwarrior->expects($this->exactly(4))
|
|
||||||
->method('setValue');
|
|
||||||
|
|
||||||
$this->mockLogger->expects($this->never())->method('error');
|
|
||||||
|
|
||||||
$this->mockTaskwarriorConfig
|
|
||||||
->expects($this->once())
|
|
||||||
->method('getTaskwarriorInstance')
|
|
||||||
->will($this->returnValue($this->mockTaskwarrior));
|
|
||||||
|
|
||||||
$this
|
|
||||||
->mockTaskwarrior
|
|
||||||
->expects($this->once())
|
|
||||||
->method('save');
|
|
||||||
|
|
||||||
$twCalEvent = new iCalEventProcessor($this->mockTaskwarriorConfig);
|
|
||||||
$twCalEvent->importTask($mockVTodo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException Sabre\DAV\Exception
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function testFailTaskNoComponentDefine(){
|
|
||||||
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('createTask');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('setEntryTime');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('setEndTime');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('setDueDate');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('setSummary');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('setCategories');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('build');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('save');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('exists');
|
|
||||||
|
|
||||||
$this->mockTaskwarriorConfig->expects($this->once())->method('getTaskwarriorInstance')
|
|
||||||
->willReturn($this->mockTaskwarrior);
|
|
||||||
|
|
||||||
$this->mockLogger->expects($this->once())->method('error');
|
|
||||||
|
|
||||||
$this->mockTaskwarriorConfig->expects($this->once())->method('getLogger')
|
|
||||||
->willReturn($this->mockLogger);
|
|
||||||
|
|
||||||
$twCalEvent = new iCalEventProcessor($this->mockTaskwarriorConfig);
|
|
||||||
$twCalEvent->importTask();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException Sabre\DAV\Exception\BadRequest
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
function testFailTaskExists(){
|
|
||||||
$uuid = '9f353281-1051-4c45-92db-462f5d353c76';
|
|
||||||
|
|
||||||
$mockVCalendar = new VCalendar();
|
|
||||||
$mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]);
|
|
||||||
$expectedErrorMessage = "already exists";
|
|
||||||
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('createTask');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('setEntryTime');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('setEndTime');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('setDueDate');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('setSummary');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('setCategories');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('build');
|
|
||||||
$this->mockTaskwarrior->expects($this->never())->method('save');
|
|
||||||
|
|
||||||
$this->mockTaskwarrior->expects($this->once())->method('exists')
|
|
||||||
->willReturn(true);
|
|
||||||
|
|
||||||
$this->mockTaskwarriorConfig->expects($this->once())->method('getTaskwarriorInstance')
|
|
||||||
->willReturn($this->mockTaskwarrior);
|
|
||||||
|
|
||||||
$this->mockLogger->expects($this->once())->method('error');
|
|
||||||
|
|
||||||
$this->mockTaskwarriorConfig->expects($this->once())->method('getLogger')
|
|
||||||
->willReturn($this->mockLogger);
|
|
||||||
|
|
||||||
$twCalEvent = new iCalEventProcessor($this->mockTaskwarriorConfig);
|
|
||||||
$twCalEvent->importTask($mockVTodo);
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
Reference in New Issue
Block a user