ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AddressBookTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\CardDAV;
4 
6 
8 
10 
14  protected $ab;
15  protected $backend;
16 
17  function setUp() {
18 
19  $this->backend = new Backend\Mock();
20  $this->ab = new AddressBook(
21  $this->backend,
22  [
23  'uri' => 'book1',
24  'id' => 'foo',
25  '{DAV:}displayname' => 'd-name',
26  'principaluri' => 'principals/user1',
27  ]
28  );
29 
30  }
31 
32  function testGetName() {
33 
34  $this->assertEquals('book1', $this->ab->getName());
35 
36  }
37 
38  function testGetChild() {
39 
40  $card = $this->ab->getChild('card1');
41  $this->assertInstanceOf('Sabre\\CardDAV\\Card', $card);
42  $this->assertEquals('card1', $card->getName());
43 
44  }
45 
49  function testGetChildNotFound() {
50 
51  $card = $this->ab->getChild('card3');
52 
53  }
54 
55  function testGetChildren() {
56 
57  $cards = $this->ab->getChildren();
58  $this->assertEquals(2, count($cards));
59 
60  $this->assertEquals('card1', $cards[0]->getName());
61  $this->assertEquals('card2', $cards[1]->getName());
62 
63  }
64 
68  function testCreateDirectory() {
69 
70  $this->ab->createDirectory('name');
71 
72  }
73 
74  function testCreateFile() {
75 
76  $file = fopen('php://memory', 'r+');
77  fwrite($file, 'foo');
78  rewind($file);
79  $this->ab->createFile('card2', $file);
80 
81  $this->assertEquals('foo', $this->backend->cards['foo']['card2']);
82 
83  }
84 
85  function testDelete() {
86 
87  $this->ab->delete();
88  $this->assertEquals(1, count($this->backend->addressBooks));
89 
90  }
91 
95  function testSetName() {
96 
97  $this->ab->setName('foo');
98 
99  }
100 
101  function testGetLastModified() {
102 
103  $this->assertNull($this->ab->getLastModified());
104 
105  }
106 
107  function testUpdateProperties() {
108 
109  $propPatch = new PropPatch([
110  '{DAV:}displayname' => 'barrr',
111  ]);
112  $this->ab->propPatch($propPatch);
113  $this->assertTrue($propPatch->commit());
114 
115  $this->assertEquals('barrr', $this->backend->addressBooks[0]['{DAV:}displayname']);
116 
117  }
118 
119  function testGetProperties() {
120 
121  $props = $this->ab->getProperties(['{DAV:}displayname']);
122  $this->assertEquals([
123  '{DAV:}displayname' => 'd-name',
124  ], $props);
125 
126  }
127 
128  function testACLMethods() {
129 
130  $this->assertEquals('principals/user1', $this->ab->getOwner());
131  $this->assertNull($this->ab->getGroup());
132  $this->assertEquals([
133  [
134  'privilege' => '{DAV:}all',
135  'principal' => '{DAV:}owner',
136  'protected' => true,
137  ],
138  ], $this->ab->getACL());
139 
140  }
141 
145  function testSetACL() {
146 
147  $this->ab->setACL([]);
148 
149  }
150 
152 
153  $this->assertNull(
154  $this->ab->getSupportedPrivilegeSet()
155  );
156 
157  }
158 
160 
161  $this->assertNull($this->ab->getSyncToken());
162 
163  }
165 
166  $this->assertNull($this->ab->getChanges(1, null));
167 
168  }
169 
170  function testGetSyncToken() {
171 
172  $this->driver = 'sqlite';
173  $this->dropTables(['addressbooks', 'cards', 'addressbookchanges']);
174  $this->createSchema('addressbooks');
175  $backend = new Backend\PDO(
176  $this->getPDO()
177  );
178  $ab = new AddressBook($backend, ['id' => 1, '{DAV:}sync-token' => 2]);
179  $this->assertEquals(2, $ab->getSyncToken());
180  }
181 
182  function testGetSyncToken2() {
183 
184  $this->driver = 'sqlite';
185  $this->dropTables(['addressbooks', 'cards', 'addressbookchanges']);
186  $this->createSchema('addressbooks');
187  $backend = new Backend\PDO(
188  $this->getPDO()
189  );
190  $ab = new AddressBook($backend, ['id' => 1, '{http://sabredav.org/ns}sync-token' => 2]);
191  $this->assertEquals(2, $ab->getSyncToken());
192  }
193 
194 }
This class represents a set of properties that are going to be updated.
Definition: PropPatch.php:20
getPDO()
Alias for getDb.
dropTables($tableNames)
Drops tables, if they exist.
PDO CardDAV backend.
Definition: PDO.php:17
The AddressBook class represents a CardDAV addressbook, owned by a specific user. ...
Definition: AddressBook.php:17
createSchema($schemaName)
Uses .sql files from the examples directory to initialize the database.
trait DbTestHelperTrait