cleanup remove tabs
[tine20] / tests / tine20 / Tasks / Convert / Task / VCalendar / EMClientTest.php
1 <?php
2 /**
3  * Tine 2.0 - http://www.tine20.org
4  * 
5  * @package     Calendar
6  * @license     http://www.gnu.org/licenses/agpl.html
7  * @copyright   Copyright (c) 2011-2011 Metaways Infosystems GmbH (http://www.metaways.de)
8  * @author      Thomas Pawassarat <tomp@topanet.de>
9  */
10
11 /**
12  * Test helper
13  */
14 require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
15
16 /**
17  * Test class for Tasks_Convert_Task_VCalendar_EMClient
18  */
19 class Tasks_Convert_Task_VCalendar_EMClientTest extends PHPUnit_Framework_TestCase
20 {
21     /**
22      * @var array test objects
23      */
24     protected $objects = array();
25     
26     /**
27      * Runs the test methods of this class.
28      *
29      * @access public
30      * @static
31      */
32     public static function main()
33     {
34         $suite  = new PHPUnit_Framework_TestSuite('Tine 2.0 Tasks WebDAV EM Client Task Tests');
35         PHPUnit_TextUI_TestRunner::run($suite);
36     }
37
38     /**
39      * Sets up the fixture.
40      * This method is called before a test is executed.
41      *
42      * @access protected
43      */
44     protected function setUp()
45     {
46         Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
47     }
48
49     /**
50      * Tears down the fixture
51      * This method is called after a test is executed.
52      *
53      * @access protected
54      */
55     protected function tearDown()
56     {
57         Tinebase_TransactionManager::getInstance()->rollBack();
58     }
59     
60     /**
61      * test converting vcard from lighting to Tasks_Model_Task
62      * 
63      * @return Tasks_Model_Task
64      */
65     public function testConvertToTine20Model()
66     {
67         $task = $this->_convertHelper(dirname(__FILE__) . '/../../../Import/files/emtask.ics');
68         #var_dump($task->toArray());
69         
70         $this->assertEquals(Tasks_Model_Task::CLASS_PUBLIC,      $task->class);
71         $this->assertEquals('IN-PROCESS',                        $task->status);
72         $this->assertEquals('Betreff',                          $task->summary);
73         $this->assertEquals("2013-10-15 11:00:00",               (string)$task->due);
74         $this->assertEquals("2013-10-15 10:00:00",               (string)$task->dtstart);
75         $this->assertEquals("Beschreibung\nmit\nUmbruch", $task->description);
76
77         return $task;
78     }
79     
80     /**
81      * convert helper
82      * 
83      * @param string $filename
84      * @return Tasks_Model_Task
85      */
86     protected function _convertHelper($filename)
87     {
88         $vcalendar = Tasks_Frontend_WebDAV_TaskTest::getVCalendar($filename);
89         $converter = Tasks_Convert_Task_VCalendar_Factory::factory(Tasks_Convert_Task_VCalendar_Factory::CLIENT_EMCLIENT);
90         $task = $converter->toTine20Model($vcalendar);
91         
92         return $task;
93     }
94     
95     /**
96      * test converting VTODO with status
97      */
98     public function testConvertToTine20ModelWithStatus()
99     {
100         #$this->markTestSkipped();
101         $vcalendar = Tasks_Frontend_WebDAV_TaskTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/emtask.ics', 'r');
102         $converter = Tasks_Convert_Task_VCalendar_Factory::factory(Tasks_Convert_Task_VCalendar_Factory::CLIENT_EMCLIENT);
103         
104         $vcalendar = str_replace('STATUS:IN-PROCESS', 'STATUS:NEEDS-ACTION', $vcalendar);
105         $task = $converter->toTine20Model($vcalendar);
106         $this->assertEquals('NEEDS-ACTION', $task->status);
107         return;
108         $vcalendar = str_replace('STATUS:CONFIRMED', 'STATUS:TENTATIVE', $vcalendar);
109         $task = $converter->toTine20Model($vcalendar);
110         $this->assertEquals(Tasks_Model_Task::STATUS_TENTATIVE, $task->status);
111         
112         $vcalendar = str_replace('STATUS:TENTATIVE', 'STATUS:CANCELED', $vcalendar);
113         $task = $converter->toTine20Model($vcalendar);
114         $this->assertEquals(Tasks_Model_Task::STATUS_CANCELED, $task->status);
115     }
116     
117     /**
118      * test converting vcard from sogo connector to Tasks_Model_Task
119      * @return Tasks_Model_Task
120      */
121     public function _testConvertFromIcalToTine20Model()
122     {
123         $vcalendarStream = Tasks_Frontend_WebDAV_TaskTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/emtask.ics', 'r');
124     
125         $converter = Tasks_Convert_Task_VCalendar_Factory::factory(Tasks_Convert_Task_VCalendar_Factory::CLIENT_EMCLIENT);
126     
127         $task = $converter->toTine20Model($vcalendarStream);
128     
129         #var_dump($task->toArray());
130     
131         $this->assertEquals(Tasks_Model_Task::CLASS_PRIVATE, $task->class);
132         $this->assertEquals('Ort',                               $task->location);
133         $this->assertEquals('Europe/Berlin',                     $task->originator_tz);
134         $this->assertEquals("2011-10-04 10:00:00",               (string)$task->dtend);
135         $this->assertEquals("2011-10-04 08:00:00",               (string)$task->dtstart);
136
137         return $task;
138     }
139     
140
141     /**
142      * @depends testConvertToTine20Model
143      */
144     public function testConvertFromTine20Model()
145     {
146         $task = $this->testConvertToTine20Model();
147         $task->creation_time      = new Tinebase_DateTime('2011-11-11 11:11', 'UTC');
148         $task->last_modified_time = new Tinebase_DateTime('2011-11-11 12:12', 'UTC');
149         $task->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender');
150         
151         $converter = Tasks_Convert_Task_VCalendar_Factory::factory(Tasks_Convert_Task_VCalendar_Factory::CLIENT_EMCLIENT);
152         
153         $vcalendar = $converter->fromTine20Model($task)->serialize();
154         // var_dump($vcalendar);
155         // required fields
156         $this->assertContains('VERSION:2.0',                                    $vcalendar, $vcalendar);
157         $this->assertContains('PRODID:-//tine20.com//Tine 2.0 Tasks V',         $vcalendar, $vcalendar);
158         $this->assertContains('CREATED:20111111T111100Z',       $vcalendar, $vcalendar);
159         $this->assertContains('LAST-MODIFIED:20111111T121200Z', $vcalendar, $vcalendar);
160         $this->assertContains('DTSTAMP:',                       $vcalendar, $vcalendar);
161         $this->assertContains('TZID:Europe/Berlin',               $vcalendar, $vcalendar);
162         $this->assertContains('UID:' . $task->uid,                $vcalendar, $vcalendar);
163         $this->assertContains('LOCATION:' . $task->location,      $vcalendar, $vcalendar);
164         $this->assertContains('CLASS:PUBLIC',                    $vcalendar, $vcalendar);
165         $this->assertContains('TZOFFSETFROM:+0100',  $vcalendar, $vcalendar);
166         $this->assertContains('TZOFFSETTO:+0200',    $vcalendar, $vcalendar);
167         $this->assertContains('TZNAME:CEST',         $vcalendar, $vcalendar);
168         $this->assertContains('TZOFFSETFROM:+0200',  $vcalendar, $vcalendar);
169         $this->assertContains('TZOFFSETTO:+0100',    $vcalendar, $vcalendar);
170         $this->assertContains('TZNAME:CET',          $vcalendar, $vcalendar);
171     }
172 }