6702: CalDAV: single event appears in personal and shared calendar
[tine20] / tests / tine20 / Addressbook / Frontend / CardDAVTest.php
1 <?php
2 /**
3  * Tine 2.0 - http://www.tine20.org
4  * 
5  * @package     Addressbook
6  * @license     http://www.gnu.org/licenses/agpl.html
7  * @copyright   Copyright (c) 2011-2041 Metaways Infosystems GmbH (http://www.metaways.de)
8  * @author      Lars Kneschke <l.kneschke@metaways.de>
9  */
10
11 /**
12  * Test class for Addressbook_Frontend_CardDAV
13  */
14 class Addressbook_Frontend_CardDAVTest extends TestCase
15 {
16     /**
17      * test getChildren
18      */
19     public function testGetChildren()
20     {
21         $collection = new Addressbook_Frontend_WebDAV(\Sabre\CardDAV\Plugin::ADDRESSBOOK_ROOT, true);
22         
23         $children = $collection->getChildren();
24         
25         $this->assertTrue($children[0] instanceof Addressbook_Frontend_WebDAV);
26     }
27         
28     /**
29      * test getChild
30      */
31     public function testGetChild()
32     {
33         $collection = new Addressbook_Frontend_WebDAV(\Sabre\CardDAV\Plugin::ADDRESSBOOK_ROOT . '/' . Tinebase_Core::getUser()->contact_id, true);
34         
35         $child = $collection->getChild($this->_getTestContainer()->getId());
36         
37         $this->assertTrue($child instanceof Addressbook_Frontend_WebDAV_Container);
38     }
39     
40     /**
41      * test to a create file. this should not be possible at this level
42      */
43     public function testCreateFile()
44     {
45         $collection = new Addressbook_Frontend_WebDAV(\Sabre\CardDAV\Plugin::ADDRESSBOOK_ROOT . '/' . Tinebase_Core::getUser()->contact_id, true);
46         
47         $this->setExpectedException('Sabre\DAV\Exception\Forbidden');
48         
49         $collection->createFile('foobar');
50     }
51     
52     /**
53      * test to create a new directory
54      */
55     public function testCreateDirectory()
56     {
57         $randomName = Tinebase_Record_Abstract::generateUID();
58         
59         $collection = new Addressbook_Frontend_WebDAV(\Sabre\CardDAV\Plugin::ADDRESSBOOK_ROOT . '/' . Tinebase_Core::getUser()->contact_id, true);
60         
61         $collection->createDirectory($randomName);
62         
63         $container = Tinebase_Container::getInstance()->getContainerByName('Addressbook', $randomName, Tinebase_Model_Container::TYPE_PERSONAL, Tinebase_Core::getUser());
64         
65         $this->assertTrue($container instanceof Tinebase_Model_Container);
66     }
67     
68     public function testGetAllContactsMetaContainer()
69     {
70         $_SERVER['HTTP_USER_AGENT'] = 'Mac OS X/10.9 (13A603) AddressBook/1365';
71     
72         $collection = new Addressbook_Frontend_WebDAV(\Sabre\CardDAV\Plugin::ADDRESSBOOK_ROOT . '/' . Tinebase_Core::getUser()->contact_id, true);
73     
74         $children = $collection->getChildren();
75         
76         $this->assertCount(1, $children, 'there should be just one global container');
77         $this->assertTrue($children[0] instanceof Addressbook_Frontend_CardDAV_AllContacts, 'wrong instance');
78     }
79     
80     public function testGetAllContainers()
81     {
82         $_SERVER['HTTP_USER_AGENT'] = 'FooBar User Agent';
83     
84         $collection = new Addressbook_Frontend_WebDAV(\Sabre\CardDAV\Plugin::ADDRESSBOOK_ROOT, true);
85     
86         $children = $collection->getChildren();
87     
88         $this->assertGreaterThanOrEqual(2, count($children), 'there should be more than one container');
89     }
90     
91     /**
92      * create test container
93      * 
94      * @return Tinebase_Model_Container
95      */
96     protected function _getTestContainer()
97     {
98         $container = Tinebase_Container::getInstance()->addContainer(new Tinebase_Model_Container(array(
99             'name'              => Tinebase_Record_Abstract::generateUID(),
100             'type'              => Tinebase_Model_Container::TYPE_PERSONAL,
101             'backend'           => 'Sql',
102             'application_id'    => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(),
103         )));
104         
105         return $container;
106     }
107 }