diff --git a/composer.json b/composer.json index 234bd30..57541cd 100644 --- a/composer.json +++ b/composer.json @@ -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/" + } + } } diff --git a/composer.lock b/composer.lock index c0813a3..58a93eb 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/config/debug.yml b/config/debug.yml new file mode 100644 index 0000000..cf23158 --- /dev/null +++ b/config/debug.yml @@ -0,0 +1,10 @@ + monolog: + handlers: + buffered: + type: buffer + handler: easylog + channels: ["!event"] + level: debug + easylog: + type: service + id: easycorp.easylog.handler diff --git a/config/main.yml b/config/main.yml new file mode 100644 index 0000000..1151a41 --- /dev/null +++ b/config/main.yml @@ -0,0 +1,6 @@ +services: + easycorp.easylog.handler: + class: EasyCorp\EasyLog\EasyLogHandler + public: false + arguments: + - '%kernel.logs_dir%/%kernel.environment%.log' diff --git a/libs/TaskwarriorCalendarEvent.php b/libs/TaskwarriorCalendarEvent.php deleted file mode 100644 index e3ca0cc..0000000 --- a/libs/TaskwarriorCalendarEvent.php +++ /dev/null @@ -1,86 +0,0 @@ -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; - } - - - - - - - - - -} - - - -?> diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..752a146 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,19 @@ + + + + + + ./tests + + + + + + diff --git a/src/Config.php b/src/Config.php new file mode 100644 index 0000000..f882735 --- /dev/null +++ b/src/Config.php @@ -0,0 +1,62 @@ +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(){ + + } + +} +?> diff --git a/libs/Plugin.php b/src/Plugin.php similarity index 95% rename from libs/Plugin.php rename to src/Plugin.php index 8738553..f1fffbe 100644 --- a/libs/Plugin.php +++ b/src/Plugin.php @@ -1,23 +1,22 @@ 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(''); diff --git a/src/Properties/TaskwarriorProps.php b/src/Properties/TaskwarriorProps.php new file mode 100644 index 0000000..d9daa14 --- /dev/null +++ b/src/Properties/TaskwarriorProps.php @@ -0,0 +1,9 @@ + diff --git a/src/Taskwarrior.php b/src/Taskwarrior.php new file mode 100644 index 0000000..0764bb5 --- /dev/null +++ b/src/Taskwarrior.php @@ -0,0 +1,70 @@ +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){} +} + +?> diff --git a/src/iCalEventProcessor.php b/src/iCalEventProcessor.php new file mode 100644 index 0000000..fc6a290 --- /dev/null +++ b/src/iCalEventProcessor.php @@ -0,0 +1,114 @@ +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; + + } + + } + + + + + + + + + + + + +} + + + +?> diff --git a/test/PluginTest.php b/test/PluginTest.php deleted file mode 100644 index 4a98b61..0000000 --- a/test/PluginTest.php +++ /dev/null @@ -1,40 +0,0 @@ -$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); - - } - - -} - -?> diff --git a/tests/PluginTest.php b/tests/PluginTest.php new file mode 100644 index 0000000..f3e0f82 --- /dev/null +++ b/tests/PluginTest.php @@ -0,0 +1,96 @@ +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); + + } + + } + + */ +} + +?> diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..7ed6784 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,13 @@ +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); + + } +} + + +?>