refactor: remove builder class and use concrete class
tests: added more unit tests for event processor
This commit is contained in:
parent
f239099d55
commit
5201db7d22
@ -5,13 +5,16 @@
|
||||
"keywords": [
|
||||
"task",
|
||||
"taskwarrior",
|
||||
"GTD",
|
||||
"Baikal",
|
||||
"sabre"
|
||||
],
|
||||
"require": {
|
||||
"sabre/dav": "^3.2",
|
||||
"davidbadura/taskwarrior": "^3.0",
|
||||
"sabre/vobject": "^4.0"
|
||||
"sabre/vobject": "^4.0",
|
||||
"jms/serializer": "^1.13",
|
||||
"easycorp/easy-log-handler": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit" : "> 4.8, <=6.0.0"
|
||||
@ -21,5 +24,10 @@
|
||||
"name": "Aerex",
|
||||
"email": "aerex@aerex.me"
|
||||
}
|
||||
]
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Aerex\\TaskwarriorPlugin\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
229
composer.lock
generated
229
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "e58bd977d01c724349ead3fca7c7c0c5",
|
||||
"content-hash": "f1e3c1c3defb5c3015813049f3f3294a",
|
||||
"packages": [
|
||||
{
|
||||
"name": "davidbadura/taskwarrior",
|
||||
@ -304,17 +304,67 @@
|
||||
"time": "2014-09-09T13:34:57+00:00"
|
||||
},
|
||||
{
|
||||
"name": "jms/metadata",
|
||||
"version": "1.6.0",
|
||||
"name": "easycorp/easy-log-handler",
|
||||
"version": "v1.0.7",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/schmittjoh/metadata.git",
|
||||
"reference": "6a06970a10e0a532fb52d3959547123b84a3b3ab"
|
||||
"url": "https://github.com/EasyCorp/easy-log-handler.git",
|
||||
"reference": "5f95717248d20684f88cfb878d8bf3d78aadcbba"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/schmittjoh/metadata/zipball/6a06970a10e0a532fb52d3959547123b84a3b3ab",
|
||||
"reference": "6a06970a10e0a532fb52d3959547123b84a3b3ab",
|
||||
"url": "https://api.github.com/repos/EasyCorp/easy-log-handler/zipball/5f95717248d20684f88cfb878d8bf3d78aadcbba",
|
||||
"reference": "5f95717248d20684f88cfb878d8bf3d78aadcbba",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"monolog/monolog": "~1.6",
|
||||
"php": ">=5.3.0",
|
||||
"symfony/yaml": "~2.3|~3.0|~4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"EasyCorp\\EasyLog\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Javier Eguiluz",
|
||||
"email": "javiereguiluz@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Project Contributors",
|
||||
"homepage": "https://github.com/EasyCorp/easy-log-handler"
|
||||
}
|
||||
],
|
||||
"description": "A handler for Monolog that optimizes log messages to be processed by humans instead of software. Improve your productivity with logs that are easy to understand.",
|
||||
"homepage": "https://github.com/EasyCorp/easy-log-handler",
|
||||
"keywords": [
|
||||
"easy",
|
||||
"log",
|
||||
"logging",
|
||||
"monolog",
|
||||
"productivity"
|
||||
],
|
||||
"time": "2018-07-27T15:41:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "jms/metadata",
|
||||
"version": "1.7.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/schmittjoh/metadata.git",
|
||||
"reference": "e5854ab1aa643623dc64adde718a8eec32b957a8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/schmittjoh/metadata/zipball/e5854ab1aa643623dc64adde718a8eec32b957a8",
|
||||
"reference": "e5854ab1aa643623dc64adde718a8eec32b957a8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -337,9 +387,13 @@
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Asmir Mustafic",
|
||||
"email": "goetas@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Johannes M. Schmitt",
|
||||
"email": "schmittjoh@gmail.com"
|
||||
@ -352,7 +406,7 @@
|
||||
"xml",
|
||||
"yaml"
|
||||
],
|
||||
"time": "2016-12-05T10:18:33+00:00"
|
||||
"time": "2018-10-26T12:40:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "jms/parser-lib",
|
||||
@ -473,6 +527,84 @@
|
||||
],
|
||||
"time": "2018-07-25T13:58:54+00:00"
|
||||
},
|
||||
{
|
||||
"name": "monolog/monolog",
|
||||
"version": "1.23.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Seldaek/monolog.git",
|
||||
"reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/fd8c787753b3a2ad11bc60c063cff1358a32a3b4",
|
||||
"reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"psr/log": "~1.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/log-implementation": "1.0.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
|
||||
"doctrine/couchdb": "~1.0@dev",
|
||||
"graylog2/gelf-php": "~1.0",
|
||||
"jakub-onderka/php-parallel-lint": "0.9",
|
||||
"php-amqplib/php-amqplib": "~2.4",
|
||||
"php-console/php-console": "^3.1.3",
|
||||
"phpunit/phpunit": "~4.5",
|
||||
"phpunit/phpunit-mock-objects": "2.3.0",
|
||||
"ruflin/elastica": ">=0.90 <3.0",
|
||||
"sentry/sentry": "^0.13",
|
||||
"swiftmailer/swiftmailer": "^5.3|^6.0"
|
||||
},
|
||||
"suggest": {
|
||||
"aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB",
|
||||
"doctrine/couchdb": "Allow sending log messages to a CouchDB server",
|
||||
"ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
|
||||
"ext-mongo": "Allow sending log messages to a MongoDB server",
|
||||
"graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
|
||||
"mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver",
|
||||
"php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib",
|
||||
"php-console/php-console": "Allow sending log messages to Google Chrome",
|
||||
"rollbar/rollbar": "Allow sending log messages to Rollbar",
|
||||
"ruflin/elastica": "Allow sending log messages to an Elastic Search server",
|
||||
"sentry/sentry": "Allow sending log messages to a Sentry server"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Monolog\\": "src/Monolog"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jordi Boggiano",
|
||||
"email": "j.boggiano@seld.be",
|
||||
"homepage": "http://seld.be"
|
||||
}
|
||||
],
|
||||
"description": "Sends your logs to files, sockets, inboxes, databases and various web services",
|
||||
"homepage": "http://github.com/Seldaek/monolog",
|
||||
"keywords": [
|
||||
"log",
|
||||
"logging",
|
||||
"psr-3"
|
||||
],
|
||||
"time": "2017-06-19T01:22:40+00:00"
|
||||
},
|
||||
{
|
||||
"name": "nesbot/carbon",
|
||||
"version": "1.34.0",
|
||||
@ -738,16 +870,16 @@
|
||||
},
|
||||
{
|
||||
"name": "sabre/dav",
|
||||
"version": "3.2.2",
|
||||
"version": "3.2.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sabre-io/dav.git",
|
||||
"reference": "e987775e619728f12205606c9cc3ee565ffb1516"
|
||||
"reference": "a9780ce4f35560ecbd0af524ad32d9d2c8954b80"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sabre-io/dav/zipball/e987775e619728f12205606c9cc3ee565ffb1516",
|
||||
"reference": "e987775e619728f12205606c9cc3ee565ffb1516",
|
||||
"url": "https://api.github.com/repos/sabre-io/dav/zipball/a9780ce4f35560ecbd0af524ad32d9d2c8954b80",
|
||||
"reference": "a9780ce4f35560ecbd0af524ad32d9d2c8954b80",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -817,7 +949,7 @@
|
||||
"framework",
|
||||
"iCalendar"
|
||||
],
|
||||
"time": "2017-02-15T03:06:08+00:00"
|
||||
"time": "2018-10-19T09:58:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sabre/event",
|
||||
@ -1361,16 +1493,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/translation",
|
||||
"version": "v4.1.5",
|
||||
"version": "v4.1.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/translation.git",
|
||||
"reference": "6e49130ddf150b7bfe9e34edb2f3f698aa1aa43b"
|
||||
"reference": "9f0b61e339160a466ebcde167a6c5521c810e304"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/translation/zipball/6e49130ddf150b7bfe9e34edb2f3f698aa1aa43b",
|
||||
"reference": "6e49130ddf150b7bfe9e34edb2f3f698aa1aa43b",
|
||||
"url": "https://api.github.com/repos/symfony/translation/zipball/9f0b61e339160a466ebcde167a6c5521c810e304",
|
||||
"reference": "9f0b61e339160a466ebcde167a6c5521c810e304",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1426,7 +1558,66 @@
|
||||
],
|
||||
"description": "Symfony Translation Component",
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2018-09-21T12:49:42+00:00"
|
||||
"time": "2018-10-02T16:36:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/yaml",
|
||||
"version": "v4.1.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/yaml.git",
|
||||
"reference": "367e689b2fdc19965be435337b50bc8adf2746c9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/yaml/zipball/367e689b2fdc19965be435337b50bc8adf2746c9",
|
||||
"reference": "367e689b2fdc19965be435337b50bc8adf2746c9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1.3",
|
||||
"symfony/polyfill-ctype": "~1.8"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/console": "<3.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/console": "~3.4|~4.0"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/console": "For validating YAML files using the lint command"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.1-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\Yaml\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony Yaml Component",
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2018-10-02T16:36:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "webmozart/assert",
|
||||
|
10
config/debug.yml
Normal file
10
config/debug.yml
Normal file
@ -0,0 +1,10 @@
|
||||
monolog:
|
||||
handlers:
|
||||
buffered:
|
||||
type: buffer
|
||||
handler: easylog
|
||||
channels: ["!event"]
|
||||
level: debug
|
||||
easylog:
|
||||
type: service
|
||||
id: easycorp.easylog.handler
|
6
config/main.yml
Normal file
6
config/main.yml
Normal file
@ -0,0 +1,6 @@
|
||||
services:
|
||||
easycorp.easylog.handler:
|
||||
class: EasyCorp\EasyLog\EasyLogHandler
|
||||
public: false
|
||||
arguments:
|
||||
- '%kernel.logs_dir%/%kernel.environment%.log'
|
@ -1,86 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Aerex\Taskwarrior;
|
||||
|
||||
use Aerex\Taskwarrior\Config;
|
||||
use DavidBadura\Taskwarrior\Taskwarrior;
|
||||
use Sabre\VObject\Component\VCalendar;
|
||||
|
||||
class TaskwarriorCalendarEvent {
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
private $taskrc;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
private $taskDataDir;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
private $taskBinFile;
|
||||
|
||||
|
||||
/**
|
||||
* @var Taskwarrior
|
||||
*/
|
||||
|
||||
private $taskwarrior;
|
||||
|
||||
|
||||
public function __construct(){
|
||||
$this->config = new Config();
|
||||
|
||||
if($this->config.isNotValidConfiguration()){
|
||||
$invalidConfigurationString = $this->config.invalidConfigurations();
|
||||
|
||||
$invalidConfigurationMessage = sprintf('The following configurations are invalid %s and' .
|
||||
' the default configurations will be used', $invalidConfigurationString);
|
||||
echo($invalidConfigurationMessage);
|
||||
|
||||
$this->config.setDefaults();
|
||||
}
|
||||
|
||||
$this->taskrc = $this->config->getTaskRC();
|
||||
$this->taskDataDir = $this->config->getTaskDataDir();
|
||||
$this->taskBinFile = $this->config->getTaskBinFile();
|
||||
|
||||
$this->taskwarrior = $taskwarrior($this->taskrc,$this->taskDataDir, [], $this->taskBinFile);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function buildCalendarEvent(VCalendar $vEvent){
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public function buildToDoEvent(VCalendar $vToDo){
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
19
phpunit.xml.dist
Normal file
19
phpunit.xml.dist
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0"?>
|
||||
<phpunit
|
||||
colors="true"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
beStrictAboutTestsThatDoNotTestAnything="true">
|
||||
|
||||
|
||||
<testsuite name="TaskwarriorPlugin">
|
||||
<directory>./tests</directory>
|
||||
</testsuite>
|
||||
|
||||
<logging>
|
||||
<log type="coverage-html" target="/tmp/report" lowUpperBound="35"
|
||||
highLowerBound="70"/>
|
||||
</logging>
|
||||
</phpunit>
|
62
src/Config.php
Normal file
62
src/Config.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Aerex\TaskwarriorPlugin;
|
||||
|
||||
|
||||
|
||||
class Config {
|
||||
|
||||
public function __construct(){
|
||||
|
||||
}
|
||||
|
||||
public function getTaskwarriorInstance(){
|
||||
|
||||
if(!$this->isValidConfiguration()){
|
||||
$invalidConfigurationString = $this->invalidConfigurations();
|
||||
|
||||
$invalidConfigurationMessage = sprintf('The following configurations are invalid %s and' .
|
||||
' the default configurations will be used', $invalidConfigurationString);
|
||||
echo($invalidConfigurationMessage);
|
||||
|
||||
$this->setDefaults();
|
||||
}
|
||||
|
||||
$this->taskrc = $this->getTaskRC();
|
||||
$this->taskDataDir = $this->getTaskDataDir();
|
||||
$this->taskBinFile = $this->getTaskBinFile();
|
||||
|
||||
$this->taskwarrior = new $Taskwarrior($this->taskrc,$this->taskdatadir, [], $this->taskbinfile);
|
||||
}
|
||||
|
||||
|
||||
public function getLogger(){
|
||||
return $this->logger;
|
||||
}
|
||||
public function setLogger($logger){
|
||||
$this->logger = $logger;
|
||||
|
||||
}
|
||||
public function isValidConfigurations(){
|
||||
|
||||
}
|
||||
|
||||
public function setDefaults(){
|
||||
|
||||
}
|
||||
|
||||
public function getTaskRC() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getTaskDataDir(){
|
||||
|
||||
}
|
||||
|
||||
public function getTaskBinFile(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
@ -1,23 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Aerex\Taskwarrior;
|
||||
namespace Aerex\TaskwarriorPlugin;
|
||||
|
||||
use Sabre\DAV\Exception\BadRequest;
|
||||
use Sabre\VObject;
|
||||
use Sabre\VObject\Document;
|
||||
use Sabre\HTTP\RequestInterface;
|
||||
use Sabre\HTTP\ResponseInterface;
|
||||
use Sabre\Xml\ParseException;
|
||||
use Aerex\Taskwarrior\TaskwarriorVCalendarManger;
|
||||
use DavidBadura\Taskwarrior\TaskManager;
|
||||
use DavidBadura\Taskwarrior\Task;
|
||||
use DavidBadura\Taskwarrior\Recurring;
|
||||
use DavidBadura\Taskwarrior\Annotation;
|
||||
use Sabre\DAV\ServerPlugin;
|
||||
use Sabre\DAV\Server;
|
||||
use Aerex\TaskwarriorPlugin\iCalEventProcessor;
|
||||
use Aerex\TaskwarriorPlugin\Config;
|
||||
|
||||
/**
|
||||
* The plugin to interact with Baikal and Taskwarrior
|
||||
*
|
||||
*/
|
||||
class Taskwarrior extends ServerPlugin {
|
||||
class Plugin extends ServerPlugin {
|
||||
|
||||
/**
|
||||
* Reference to server object.
|
||||
@ -25,18 +24,43 @@ class Taskwarrior extends ServerPlugin {
|
||||
* @var Server
|
||||
*/
|
||||
protected $server;
|
||||
private $TWCalManager;
|
||||
|
||||
|
||||
/**
|
||||
* Reference to TaskwarriorConfig object
|
||||
* @var TaskwarriorConfig
|
||||
*
|
||||
*/
|
||||
protected $twConfig;
|
||||
|
||||
/**
|
||||
* Reference to TaskwarriorCalenderEvent object
|
||||
* @var TaskwarriorCalendarEvent
|
||||
*/
|
||||
protected $TWCalManager;
|
||||
|
||||
/**
|
||||
* Creates the Taskwarrior plugin
|
||||
*
|
||||
* @param TaskwarriorConfig $TWCalManager
|
||||
*
|
||||
*/
|
||||
function __construct(iCalEventProcessor $TWCalManager = null){
|
||||
if(!is_null($TWCalManager)){
|
||||
$this->twCalManager = $TWCalManager;
|
||||
} else {
|
||||
$this->twCalManager = new iCalEventProcessor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the plugin
|
||||
*
|
||||
* @param Server $server
|
||||
* @return void
|
||||
*/
|
||||
* @return void */
|
||||
function initialize(Server $server) {
|
||||
|
||||
|
||||
$this->server = $server;
|
||||
$this->$TWCalManager = new TaskwarriorCalendarEvent();
|
||||
$server->on('method:GET', [$this, 'httpGet']);
|
||||
$server->on('method:OPTIONS', [$this, 'httpOptions']);
|
||||
$server->on('method:HEAD', [$this, 'httpHead']);
|
||||
@ -76,12 +100,13 @@ class Taskwarrior extends ServerPlugin {
|
||||
*
|
||||
* @param VCalendar $vCal parsed calendar object
|
||||
*/
|
||||
function processCalendarEventForTaskwarrior(VCalendar $vCal){
|
||||
function processCalendarEventForTaskwarrior(Document $vCal){
|
||||
try {
|
||||
$TWCalManager->buildCalendarEvent($VCal->VEVENT);
|
||||
$TWCalManager->buildToDoEvent($VCal->VTODO);
|
||||
} catch(Exception $e){
|
||||
$this->twCalManager->importTask($vCal->VTODO);
|
||||
} catch(BadRequest $e){
|
||||
throw new BadRequest($e->getMessage(), null, $e);
|
||||
} catch(Exception $e){
|
||||
throw new Exception($e->getMessage(), null, $e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -96,14 +121,14 @@ class Taskwarrior extends ServerPlugin {
|
||||
* * @param mixed $isNew Whether this was a new item or we're updating one
|
||||
* * @return void
|
||||
* */
|
||||
function calendarObjectChange(RequestInterface $request, ResponseInterface $response, VCalendar $vCal, $calendarPath, &$modified, $isNew) {
|
||||
function calendarObjectChange(RequestInterface $request, ResponseInterface $response, Document $vCal, $calendarPath, &$modified, $isNew) {
|
||||
$calendarNode = $this->server->tree->getNodeForPath($calendarPath);
|
||||
$addresses = $this->getAddressesForPrincipal(
|
||||
$calendarNode->getOwner()
|
||||
);
|
||||
if ($isNew) {
|
||||
try {
|
||||
processCalendarEventForTaskwarrior($vCal);
|
||||
$this->processCalendarEventForTaskwarrior($vCal);
|
||||
} catch(Exception\BadRequest $e){
|
||||
$response->setStatus(200);
|
||||
$response->setBody('');
|
9
src/Properties/TaskwarriorProps.php
Normal file
9
src/Properties/TaskwarriorProps.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class TaskwarriorProps {
|
||||
static $DESCRIPTION = 'description';
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
70
src/Taskwarrior.php
Normal file
70
src/Taskwarrior.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Aerex\TaskwarriorPlugin;
|
||||
|
||||
use Aerex\TaskwarriorPlugin\Taskwarrior;
|
||||
|
||||
class Taskwarrior {
|
||||
|
||||
const DESCRIPTION = 'description';
|
||||
const CATEGORIES = 'categories';
|
||||
|
||||
|
||||
function __constructor(TaskwarriorConfig $taskConfig){
|
||||
$this->taskConfig = $taskConfig;
|
||||
$this->taskWarriorJSON = array();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
private 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 setUUID(){
|
||||
}
|
||||
public function build(){
|
||||
|
||||
}
|
||||
function setDescription($description){}
|
||||
function setDueDate($dueDate){}
|
||||
}
|
||||
|
||||
?>
|
114
src/iCalEventProcessor.php
Normal file
114
src/iCalEventProcessor.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?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);
|
||||
throw new Exception\BadRequest("Event already exists " . $ToDoComponent->UID);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$this->taskwarrior->setUUID($ToDoComponent->UID);
|
||||
$this->taskwarrior->setEntryTime($ToDoComponent->DSTAMP);
|
||||
$this->taskwarrior->setDueDate($ToDoComponent->DUE);
|
||||
$this->taskwarrior->setModifiedTime($ToDoComponent->{'LAST-MODIFIED'});
|
||||
$this->taskwarrior->setStartTime($ToDoComponent->DSTART);
|
||||
$this->taskwarrior->setEndTime($ToDoComponent->DTEND);
|
||||
$this->taskwarrior->setSummary($ToDoComponent->DESCRIPTION);
|
||||
$this->taskwarrior->setCategories($ToDoComponent->CATEGORIES);
|
||||
$this->taskwarrior->setDescription($ToDoComponent->DESCRIPTION);
|
||||
|
||||
$this->taskwarrior->build();
|
||||
|
||||
$this->taskwarrior->save();
|
||||
|
||||
} catch(Exception $e){
|
||||
$this->logger->error($e->message);
|
||||
throw $e;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
use Aerex\Taskwarrior;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
|
||||
|
||||
class PluginTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
protected $cal;
|
||||
protected $pluginInstance;
|
||||
|
||||
function setup(){
|
||||
$this->$cal = new Componet\VCalendar();
|
||||
$pluginInstance = new Plugin();
|
||||
|
||||
}
|
||||
|
||||
function testCreateSimpleTask() {
|
||||
$expectedTaskDescription = "Going to the Movies";
|
||||
$expectedStartTime = new \DateTime("2018-03-13 09:33:00Z");
|
||||
$expectedEndTime = new \DateTime("2018-03-13 10:45:00Z");
|
||||
|
||||
$vCalendarObjectEvent = $this->$cal->add('VEVENT', [
|
||||
"UID" => "1ff0313e-1ffa-4a18-b8c1-449bddc9109c",
|
||||
"SUMMARY" => $expectedTaskDescription,
|
||||
"DTSTART" => $expectedStartTime,
|
||||
"DTEND" => $expectedEndTime
|
||||
], false);
|
||||
|
||||
|
||||
$this->$pluginInstance->processCalendarEventForTaskwarrior($vCalendarObjectEvent);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
96
tests/PluginTest.php
Normal file
96
tests/PluginTest.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
use Sabre\VObject\Component\VCalendar;
|
||||
use Sabre\DAV\Exception\BadRequest;
|
||||
use Aerex\TaskwarriorPlugin\Plugin;
|
||||
use Aerex\TaskwarriorPlugin\Config;
|
||||
use Aerex\TaskwarriorPlugin\iCalEventProcessor;
|
||||
use Sabre\DAV\Server;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
|
||||
class PluginTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
/**
|
||||
* @var Plugin
|
||||
*
|
||||
*/
|
||||
private $plugin;
|
||||
/**
|
||||
* @var VCalendar
|
||||
*/
|
||||
private $cal;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @var Server
|
||||
*/
|
||||
private $server;
|
||||
|
||||
/**
|
||||
* @var TaskwarriorCalendarEvent
|
||||
*/
|
||||
private $mockTaskCalEvent;
|
||||
|
||||
|
||||
/**
|
||||
* @var TaskwarriorConfig
|
||||
*/
|
||||
private $mockTaskwarriorConfig;
|
||||
|
||||
function setup(){
|
||||
|
||||
$this->cal = new VCalendar();
|
||||
$this->mockTaskCalEvent = $this->createMock(iCalEventProcessor::class);
|
||||
$this->cal->add('VTODO', [
|
||||
"UID" => "1ff0313e-1ffa-4a18-b8c1-449bddc9109c",
|
||||
], false);
|
||||
|
||||
}
|
||||
|
||||
function testCreateSimpleTask() {
|
||||
|
||||
$this->server = new Server();
|
||||
|
||||
$this->mockTaskCalEvent->expects($this->once())
|
||||
->method('importTask')
|
||||
->with($this->cal->VTODO);
|
||||
|
||||
$this->plugin = new Plugin($this->mockTaskCalEvent);
|
||||
$this->plugin->initialize($this->server);
|
||||
$this->plugin->processCalendarEventForTaskwarrior($this->cal);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO Need to figure out why it is not throwing the correct Exception
|
||||
function testBadRequest(){
|
||||
$expectedBadRequestMessage = 'This was a bad request';
|
||||
|
||||
$this->server = new Server();
|
||||
$this->cal = new VCalendar();
|
||||
|
||||
$this->mockTaskCalEvent->expects($this->once())
|
||||
->method('buildVEVENTForTW')
|
||||
->with($this->cal->VEVENT);
|
||||
$this->mockTaskCalEvent
|
||||
->method('buildVTODOForTW')
|
||||
->with($this->throwException(new BadRequest));
|
||||
|
||||
|
||||
$this->plugin = new Plugin($this->mockTaskCalEvent);
|
||||
$this->plugin->initialize($this->server);
|
||||
try {
|
||||
$this->plugin->processCalendarEventForTaskwarrior($this->cal);
|
||||
} catch(BadRequest $e){
|
||||
$this->assertInstanceOf(BadRequest::class, $e);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
?>
|
13
tests/bootstrap.php
Normal file
13
tests/bootstrap.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
$loader = require __DIR__ . '/../vendor/autoload.php';
|
||||
if (!$loader) {
|
||||
die(<<<'EOT'
|
||||
You must set up the project dependencies, run the following command:
|
||||
composer install
|
||||
EOT
|
||||
);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
171
tests/iCalEventProcessorTest.php
Normal file
171
tests/iCalEventProcessorTest.php
Normal file
@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
use Sabre\DAV\Exception\BadRequest;
|
||||
use Monolog\Logger;
|
||||
use Sabre\VObject\Component\VCalendar;
|
||||
use Aerex\TaskwarriorPlugin\Taskwarrior;
|
||||
use Aerex\TaskwarriorPlugin\iCalEventProcessor;
|
||||
use Aerex\TaskwarriorPlugin\Config;
|
||||
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_MockObject
|
||||
*/
|
||||
private $mockLogger;
|
||||
|
||||
function setup(){
|
||||
|
||||
$this->mockTaskwarrior = $this->createMock(Taskwarrior::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->once())->method('setUUID')
|
||||
->with($this->equalTo($mockVTodo->UID));
|
||||
$this->mockTaskwarrior->expects($this->once())->method('setEntryTime')
|
||||
->with($this->equalTo($mockVTodo->DSTAMP));
|
||||
$this->mockTaskwarrior->expects($this->once())->method('setEndTime')
|
||||
->with($this->equalTo($mockVTodo->DTEND));
|
||||
$this->mockTaskwarrior->expects($this->once())->method('setDueDate')
|
||||
->with($this->equalTo($mockVTodo->DUE));
|
||||
$this->mockTaskwarrior->expects($this->once())->method('setSummary')
|
||||
->with($this->equalTo($mockVTodo->DESCRIPTION));
|
||||
$this->mockTaskwarrior->expects($this->once())->method('setCategories')
|
||||
->with($this->equalTo($mockVTodo->CATEGORIES));
|
||||
|
||||
$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('build');
|
||||
|
||||
$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('setUUID');
|
||||
$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('setUUID');
|
||||
$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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user