2018-10-27 01:19:34 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Sabre\DAV\Exception\BadRequest;
|
|
|
|
use Monolog\Logger;
|
|
|
|
use Sabre\VObject\Component\VCalendar;
|
2018-10-28 00:11:01 -05:00
|
|
|
use Aerex\TaskwarriorPlugin\TaskwarriorManager;
|
2018-10-27 01:19:34 -05:00
|
|
|
use Aerex\TaskwarriorPlugin\iCalEventProcessor;
|
|
|
|
use Aerex\TaskwarriorPlugin\Config;
|
2018-10-28 00:11:01 -05:00
|
|
|
use DavidBadura\Taskwarrior\Task;
|
2018-10-27 01:19:34 -05:00
|
|
|
use DateTime;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class iCalEventProcessorTest extends \PHPUnit\Framework\TestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
* */
|
|
|
|
private $mockTaskwarrior;
|
|
|
|
|
|
|
|
/***
|
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
private $mockTaskwarriorConfig;
|
|
|
|
|
|
|
|
/***
|
2018-10-28 00:11:01 -05:00
|
|
|
* @var \PHPUnit_Framework__MockObject
|
2018-10-27 01:19:34 -05:00
|
|
|
*/
|
|
|
|
private $mockLogger;
|
|
|
|
|
|
|
|
function setup(){
|
|
|
|
|
2018-10-28 00:11:01 -05:00
|
|
|
$this->mockTaskwarrior = $this->createMock(TaskwarriorManager::class);
|
|
|
|
$this->mockTask = $this->createMock(Task::class);
|
2018-10-27 01:19:34 -05:00
|
|
|
$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);
|
|
|
|
|
2018-10-28 00:11:01 -05:00
|
|
|
$this->mockTaskwarrior->expects($this->exactly(4))
|
|
|
|
->method('parseiCalDateTime')
|
|
|
|
->will($this->onConsecutiveCalls($startTime, $startTime, $modifiedTime, $endTime));
|
2018-10-27 01:19:34 -05:00
|
|
|
|
2018-10-28 00:11:01 -05:00
|
|
|
$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);
|
2018-10-27 01:19:34 -05:00
|
|
|
|
2018-10-28 00:11:01 -05:00
|
|
|
$this->mockTask->expects($this->once())->method('setTags')
|
|
|
|
->with($this->equalTo($categories));
|
2018-10-27 01:19:34 -05:00
|
|
|
|
2018-10-28 00:11:01 -05:00
|
|
|
$this->mockTaskwarrior->expects($this->exactly(4))
|
|
|
|
->method('setValue');
|
2018-10-27 01:19:34 -05:00
|
|
|
|
2018-10-28 00:11:01 -05:00
|
|
|
$this->mockLogger->expects($this->never())->method('error');
|
2018-10-27 01:19:34 -05:00
|
|
|
|
2018-10-28 00:11:01 -05:00
|
|
|
$this->mockTaskwarriorConfig
|
2018-10-27 01:19:34 -05:00
|
|
|
->expects($this->once())
|
2018-10-28 00:11:01 -05:00
|
|
|
->method('getTaskwarriorInstance')
|
|
|
|
->will($this->returnValue($this->mockTaskwarrior));
|
2018-10-27 01:19:34 -05:00
|
|
|
|
|
|
|
$this
|
|
|
|
->mockTaskwarrior
|
|
|
|
->expects($this->once())
|
|
|
|
->method('save');
|
|
|
|
|
|
|
|
$twCalEvent = new iCalEventProcessor($this->mockTaskwarriorConfig);
|
|
|
|
$twCalEvent->importTask($mockVTodo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function testFailTaskNoComponentDefine(){
|
|
|
|
|
2018-10-28 00:11:01 -05:00
|
|
|
$this->mockTaskwarrior->expects($this->never())->method('createTask');
|
2018-10-27 01:19:34 -05:00
|
|
|
$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();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-28 00:11:01 -05:00
|
|
|
|
2018-10-27 01:19:34 -05:00
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception\BadRequest
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2018-10-28 00:11:01 -05:00
|
|
|
|
|
|
|
/*
|
2018-10-27 01:19:34 -05:00
|
|
|
function testFailTaskExists(){
|
|
|
|
$uuid = '9f353281-1051-4c45-92db-462f5d353c76';
|
|
|
|
|
|
|
|
$mockVCalendar = new VCalendar();
|
|
|
|
$mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]);
|
|
|
|
$expectedErrorMessage = "already exists";
|
|
|
|
|
2018-10-28 00:11:01 -05:00
|
|
|
$this->mockTaskwarrior->expects($this->never())->method('createTask');
|
2018-10-27 01:19:34 -05:00
|
|
|
$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);
|
|
|
|
|
|
|
|
}
|
2018-10-28 00:11:01 -05:00
|
|
|
*/
|
|
|
|
|
2018-10-27 01:19:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|