task and event containers need different uuids
[tine20] / tests / tine20 / Calendar / Import / CalDAVTest.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) 2014 Metaways Infosystems GmbH (http://www.metaways.de)
8  * @author      Philipp Schüle <p.schuele@metaways.de>
9  * 
10  */
11
12 /**
13  * Test class for Calendar_Import_CalDAV
14  */
15 class Calendar_Import_CalDAVTest extends Calendar_TestCase
16 {
17     /**
18      * unit in test
19      *
20      * @var Calendar_Import_CalDav_Client
21      */
22     protected $_uit = null;
23     
24     /**
25      * lazy init of uit
26      *
27      * @return Calendar_Import_CalDav_Client
28      */
29     protected function _getUit()
30     {
31         if ($this->_uit === null) {
32             $caldavClientOptions = array(
33                 'baseUri' => 'localhost',
34                 'userName' => Tinebase_Core::getUser()->accountLoginName,
35                 'password' => Zend_Registry::get('testConfig')->password, // TODO use credential cache?
36             );
37             $this->_uit = new Calendar_Import_CalDAV_ClientMock($caldavClientOptions, 'MacOSX');
38             $this->_uit->setVerifyPeer(false);
39         }
40         
41         return $this->_uit;
42     }
43     
44     /**
45      * test import of a single container/calendar of current user
46      */
47     public function testImportCalendars()
48     {
49         $this->_getUit()->importAllCalendars();
50         
51         $importedCalendar = $this->_getImportCalendar();
52         
53         $this->assertEquals('calendar', $importedCalendar->name);
54         $this->assertEquals('Calendar_Model_Event', $importedCalendar->model, print_r($importedCalendar->toArray(), true));
55         $this->assertEquals( Tinebase_Core::getUser()->getId(), $importedCalendar->owner_id, print_r($importedCalendar->toArray(), true));
56     }
57     
58     /**
59      * fetch import calendar
60      * 
61      * @return Tinebase_Model_Container
62      */
63     protected function _getImportCalendar()
64     {
65         $calendarUuid = sha1('/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0/calendar/');
66         return Tinebase_Container::getInstance()->getByProperty($calendarUuid, 'uuid');
67     }
68     
69     /**
70      * test import of events
71      */
72     public function testImportEvents()
73     {
74         $this->testImportCalendars();
75         $this->_getUit()->importAllCalendarData();
76         
77         $importedCalendar = $this->_getImportCalendar();
78         
79         $events = Calendar_Controller_Event::getInstance()->search(new Calendar_Model_EventFilter(array(
80             array('field' => 'container_id', 'operator' => 'in', 'value' => array($importedCalendar->getId()))
81         )));
82         $this->assertEquals(3, count($events));
83         $this->assertTrue(array(
84             '"bcc36c611f0b60bfee64b4d42e44aa1d"',
85             '"8b89914690ad7290fa9a2dc1da490489"',
86             '"0b3621a20e9045d8679075db57e881dd"'
87         ) == $events->etag);
88     }
89     
90     /**
91      * @todo implement
92      */
93     public function testUpdateEvents()
94     {
95         $this->markTestIncomplete('TODO: finish test');
96         $this->testImportEvents();
97         // @todo change some events
98         $this->_getUit()->updateAllCalendarData();
99         // @todo add assertions
100     }
101 }