- feat: Updated nestbot/carbon to 2.0.0 - fix: Replaced zendframework/zend-validator with laminas/laminas-validator - fix: Replaced zendframework/zend-stdlib with laminas/laminas-stdlib
		
			
				
	
	
		
			171 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			171 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php 
 | |
| 
 | |
| use Sabre\VObject\Component\VCalendar;
 | |
| use Aerex\TaskwarriorPlugin\Taskwarrior\Task;
 | |
| use Aerex\TaskwarriorPlugin\Plugin;
 | |
| use Carbon\Carbon;
 | |
| use Sabre\DAV\Server;
 | |
| use DateTime;
 | |
| 
 | |
| 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);
 | |
| 
 | |
|   }
 | |
| }
 | |
| 
 |