3 abstract class Sabre_CardDAV_Backend_AbstractPDOTest extends PHPUnit_Framework_TestCase {
6 * @var Sabre_CardDAV_Backend_PDO
14 abstract function getPDO();
16 public function setUp() {
18 $this->backend = new Sabre_CardDAV_Backend_PDO($this->getPDO());
22 public function testGetAddressBooksForUser() {
24 $result = $this->backend->getAddressBooksForUser('principals/user1');
30 'principaluri' => 'principals/user1',
31 '{DAV:}displayname' => 'book1',
32 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
33 '{http://calendarserver.org/ns/}getctag' => 1,
34 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
38 $this->assertEquals($expected, $result);
42 public function testUpdateAddressBookInvalidProp() {
44 $result = $this->backend->updateAddressBook(1, array(
45 '{DAV:}displayname' => 'updated',
46 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
50 $this->assertFalse($result);
52 $result = $this->backend->getAddressBooksForUser('principals/user1');
58 'principaluri' => 'principals/user1',
59 '{DAV:}displayname' => 'book1',
60 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
61 '{http://calendarserver.org/ns/}getctag' => 1,
62 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
66 $this->assertEquals($expected, $result);
70 public function testUpdateAddressBookNoProps() {
72 $result = $this->backend->updateAddressBook(1, array());
74 $this->assertFalse($result);
76 $result = $this->backend->getAddressBooksForUser('principals/user1');
82 'principaluri' => 'principals/user1',
83 '{DAV:}displayname' => 'book1',
84 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
85 '{http://calendarserver.org/ns/}getctag' => 1,
86 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
90 $this->assertEquals($expected, $result);
95 public function testUpdateAddressBookSuccess() {
97 $result = $this->backend->updateAddressBook(1, array(
98 '{DAV:}displayname' => 'updated',
99 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
102 $this->assertTrue($result);
104 $result = $this->backend->getAddressBooksForUser('principals/user1');
110 'principaluri' => 'principals/user1',
111 '{DAV:}displayname' => 'updated',
112 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
113 '{http://calendarserver.org/ns/}getctag' => 2,
114 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
118 $this->assertEquals($expected, $result);
123 public function testDeleteAddressBook() {
125 $this->backend->deleteAddressBook(1);
127 $this->assertEquals(array(), $this->backend->getAddressBooksForUser('principals/user1'));
132 * @expectedException Sabre_DAV_Exception_BadRequest
134 public function testCreateAddressBookUnsupportedProp() {
136 $this->backend->createAddressBook('principals/user1','book2', array(
137 '{DAV:}foo' => 'bar',
142 public function testCreateAddressBookSuccess() {
144 $this->backend->createAddressBook('principals/user1','book2', array(
145 '{DAV:}displayname' => 'book2',
146 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 2',
153 'principaluri' => 'principals/user1',
154 '{DAV:}displayname' => 'book1',
155 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
156 '{http://calendarserver.org/ns/}getctag' => 1,
157 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
162 'principaluri' => 'principals/user1',
163 '{DAV:}displayname' => 'book2',
164 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 2',
165 '{http://calendarserver.org/ns/}getctag' => 1,
166 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
169 $result = $this->backend->getAddressBooksForUser('principals/user1');
170 $this->assertEquals($expected, $result);
174 public function testGetCards() {
176 $result = $this->backend->getCards(1);
182 'carddata' => 'card1',
187 $this->assertEquals($expected, $result);
191 public function testGetCard() {
193 $result = $this->backend->getCard(1,'card1');
198 'carddata' => 'card1',
202 $this->assertEquals($expected, $result);
207 * @depends testGetCard
209 public function testCreateCard() {
211 $result = $this->backend->createCard(1, 'card2', 'data2');
212 $this->assertEquals('"' . md5('data2') . '"', $result);
213 $result = $this->backend->getCard(1,'card2');
214 $this->assertEquals(2, $result['id']);
215 $this->assertEquals('card2', $result['uri']);
216 $this->assertEquals('data2', $result['carddata']);
221 * @depends testGetCard
223 public function testUpdateCard() {
225 $result = $this->backend->updateCard(1, 'card1', 'newdata');
226 $this->assertEquals('"' . md5('newdata') . '"', $result);
228 $result = $this->backend->getCard(1,'card1');
229 $this->assertEquals(1, $result['id']);
230 $this->assertEquals('newdata', $result['carddata']);
235 * @depends testGetCard
237 public function testDeleteCard() {
239 $this->backend->deleteCard(1, 'card1');
240 $result = $this->backend->getCard(1,'card1');
241 $this->assertFalse($result);