aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/CardDAV/Backend
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/CardDAV/Backend')
-rw-r--r--vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php351
-rw-r--r--vendor/sabre/dav/tests/Sabre/CardDAV/Backend/Mock.php257
-rw-r--r--vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOMySQLTest.php10
-rw-r--r--vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOSqliteTest.php10
4 files changed, 0 insertions, 628 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php
deleted file mode 100644
index bac3b2b22..000000000
--- a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php
+++ /dev/null
@@ -1,351 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Sabre\CardDAV\Backend;
-
-use Sabre\CardDAV;
-use Sabre\DAV\PropPatch;
-
-abstract class AbstractPDOTest extends \PHPUnit\Framework\TestCase
-{
- use \Sabre\DAV\DbTestHelperTrait;
-
- /**
- * @var CardDAV\Backend\PDO
- */
- protected $backend;
-
- public function setup(): void
- {
- $this->dropTables([
- 'addressbooks',
- 'cards',
- 'addressbookchanges',
- ]);
- $this->createSchema('addressbooks');
- $pdo = $this->getPDO();
-
- $this->backend = new PDO($pdo);
- $pdo->exec("INSERT INTO addressbooks (principaluri, displayname, uri, description, synctoken) VALUES ('principals/user1', 'book1', 'book1', 'addressbook 1', 1)");
- $pdo->exec("INSERT INTO cards (addressbookid, carddata, uri, lastmodified, etag, size) VALUES (1, 'card1', 'card1', 0, '".md5('card1')."', 5)");
- }
-
- public function testGetAddressBooksForUser()
- {
- $result = $this->backend->getAddressBooksForUser('principals/user1');
-
- $expected = [
- [
- 'id' => 1,
- 'uri' => 'book1',
- 'principaluri' => 'principals/user1',
- '{DAV:}displayname' => 'book1',
- '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => 'addressbook 1',
- '{http://calendarserver.org/ns/}getctag' => 1,
- '{http://sabredav.org/ns}sync-token' => 1,
- ],
- ];
-
- $this->assertEquals($expected, $result);
- }
-
- public function testUpdateAddressBookInvalidProp()
- {
- $propPatch = new PropPatch([
- '{DAV:}displayname' => 'updated',
- '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => 'updated',
- '{DAV:}foo' => 'bar',
- ]);
-
- $this->backend->updateAddressBook(1, $propPatch);
- $result = $propPatch->commit();
-
- $this->assertFalse($result);
-
- $result = $this->backend->getAddressBooksForUser('principals/user1');
-
- $expected = [
- [
- 'id' => 1,
- 'uri' => 'book1',
- 'principaluri' => 'principals/user1',
- '{DAV:}displayname' => 'book1',
- '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => 'addressbook 1',
- '{http://calendarserver.org/ns/}getctag' => 1,
- '{http://sabredav.org/ns}sync-token' => 1,
- ],
- ];
-
- $this->assertEquals($expected, $result);
- }
-
- public function testUpdateAddressBookNoProps()
- {
- $propPatch = new PropPatch([
- ]);
-
- $this->backend->updateAddressBook(1, $propPatch);
- $result = $propPatch->commit();
- $this->assertTrue($result);
-
- $result = $this->backend->getAddressBooksForUser('principals/user1');
-
- $expected = [
- [
- 'id' => 1,
- 'uri' => 'book1',
- 'principaluri' => 'principals/user1',
- '{DAV:}displayname' => 'book1',
- '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => 'addressbook 1',
- '{http://calendarserver.org/ns/}getctag' => 1,
- '{http://sabredav.org/ns}sync-token' => 1,
- ],
- ];
-
- $this->assertEquals($expected, $result);
- }
-
- public function testUpdateAddressBookSuccess()
- {
- $propPatch = new PropPatch([
- '{DAV:}displayname' => 'updated',
- '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => 'updated',
- ]);
-
- $this->backend->updateAddressBook(1, $propPatch);
- $result = $propPatch->commit();
-
- $this->assertTrue($result);
-
- $result = $this->backend->getAddressBooksForUser('principals/user1');
-
- $expected = [
- [
- 'id' => 1,
- 'uri' => 'book1',
- 'principaluri' => 'principals/user1',
- '{DAV:}displayname' => 'updated',
- '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => 'updated',
- '{http://calendarserver.org/ns/}getctag' => 2,
- '{http://sabredav.org/ns}sync-token' => 2,
- ],
- ];
-
- $this->assertEquals($expected, $result);
- }
-
- public function testDeleteAddressBook()
- {
- $this->backend->deleteAddressBook(1);
-
- $this->assertEquals([], $this->backend->getAddressBooksForUser('principals/user1'));
- }
-
- public function testCreateAddressBookUnsupportedProp()
- {
- $this->expectException('Sabre\DAV\Exception\BadRequest');
- $this->backend->createAddressBook('principals/user1', 'book2', [
- '{DAV:}foo' => 'bar',
- ]);
- }
-
- public function testCreateAddressBookSuccess()
- {
- $this->backend->createAddressBook('principals/user1', 'book2', [
- '{DAV:}displayname' => 'book2',
- '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => 'addressbook 2',
- ]);
-
- $expected = [
- [
- 'id' => 1,
- 'uri' => 'book1',
- 'principaluri' => 'principals/user1',
- '{DAV:}displayname' => 'book1',
- '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => 'addressbook 1',
- '{http://calendarserver.org/ns/}getctag' => 1,
- '{http://sabredav.org/ns}sync-token' => 1,
- ],
- [
- 'id' => 2,
- 'uri' => 'book2',
- 'principaluri' => 'principals/user1',
- '{DAV:}displayname' => 'book2',
- '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => 'addressbook 2',
- '{http://calendarserver.org/ns/}getctag' => 1,
- '{http://sabredav.org/ns}sync-token' => 1,
- ],
- ];
- $result = $this->backend->getAddressBooksForUser('principals/user1');
- $this->assertEquals($expected, $result);
- }
-
- public function testGetCards()
- {
- $result = $this->backend->getCards(1);
-
- $expected = [
- [
- 'id' => 1,
- 'uri' => 'card1',
- 'lastmodified' => 0,
- 'etag' => '"'.md5('card1').'"',
- 'size' => 5,
- ],
- ];
-
- $this->assertEquals($expected, $result);
- }
-
- public function testGetCard()
- {
- $result = $this->backend->getCard(1, 'card1');
-
- $expected = [
- 'id' => 1,
- 'uri' => 'card1',
- 'carddata' => 'card1',
- 'lastmodified' => 0,
- 'etag' => '"'.md5('card1').'"',
- 'size' => 5,
- ];
-
- if (is_resource($result['carddata'])) {
- $result['carddata'] = stream_get_contents($result['carddata']);
- }
-
- $this->assertEquals($expected, $result);
- }
-
- /**
- * @depends testGetCard
- */
- public function testCreateCard()
- {
- $result = $this->backend->createCard(1, 'card2', 'data2');
- $this->assertEquals('"'.md5('data2').'"', $result);
- $result = $this->backend->getCard(1, 'card2');
- $this->assertEquals(2, $result['id']);
- $this->assertEquals('card2', $result['uri']);
- if (is_resource($result['carddata'])) {
- $result['carddata'] = stream_get_contents($result['carddata']);
- }
- $this->assertEquals('data2', $result['carddata']);
- }
-
- /**
- * @depends testCreateCard
- */
- public function testGetMultiple()
- {
- $result = $this->backend->createCard(1, 'card2', 'data2');
- $result = $this->backend->createCard(1, 'card3', 'data3');
- $check = [
- [
- 'id' => 1,
- 'uri' => 'card1',
- 'carddata' => 'card1',
- 'lastmodified' => 0,
- ],
- [
- 'id' => 2,
- 'uri' => 'card2',
- 'carddata' => 'data2',
- 'lastmodified' => time(),
- ],
- [
- 'id' => 3,
- 'uri' => 'card3',
- 'carddata' => 'data3',
- 'lastmodified' => time(),
- ],
- ];
-
- $result = $this->backend->getMultipleCards(1, ['card1', 'card2', 'card3']);
-
- foreach ($check as $index => $node) {
- foreach ($node as $k => $v) {
- $expected = $v;
- $actual = $result[$index][$k];
-
- switch ($k) {
- case 'lastmodified':
- $this->assertIsInt($actual);
- break;
- case 'carddata':
- if (is_resource($actual)) {
- $actual = stream_get_contents($actual);
- }
- // no break intended.
- default:
- $this->assertEquals($expected, $actual);
- break;
- }
- }
- }
- }
-
- /**
- * @depends testGetCard
- */
- public function testUpdateCard()
- {
- $result = $this->backend->updateCard(1, 'card1', 'newdata');
- $this->assertEquals('"'.md5('newdata').'"', $result);
-
- $result = $this->backend->getCard(1, 'card1');
- $this->assertEquals(1, $result['id']);
- if (is_resource($result['carddata'])) {
- $result['carddata'] = stream_get_contents($result['carddata']);
- }
- $this->assertEquals('newdata', $result['carddata']);
- }
-
- /**
- * @depends testGetCard
- */
- public function testDeleteCard()
- {
- $this->backend->deleteCard(1, 'card1');
- $result = $this->backend->getCard(1, 'card1');
- $this->assertFalse($result);
- }
-
- public function testGetChanges()
- {
- $backend = $this->backend;
- $id = $backend->createAddressBook(
- 'principals/user1',
- 'bla',
- []
- );
- $result = $backend->getChangesForAddressBook($id, null, 1);
-
- $this->assertEquals([
- 'syncToken' => 1,
- 'added' => [],
- 'modified' => [],
- 'deleted' => [],
- ], $result);
-
- $currentToken = $result['syncToken'];
-
- $dummyCard = "BEGIN:VCARD\r\nEND:VCARD\r\n";
-
- $backend->createCard($id, 'card1.ics', $dummyCard);
- $backend->createCard($id, 'card2.ics', $dummyCard);
- $backend->createCard($id, 'card3.ics', $dummyCard);
- $backend->updateCard($id, 'card1.ics', $dummyCard);
- $backend->deleteCard($id, 'card2.ics');
-
- $result = $backend->getChangesForAddressBook($id, $currentToken, 1);
-
- $this->assertEquals([
- 'syncToken' => 6,
- 'modified' => ['card1.ics'],
- 'deleted' => ['card2.ics'],
- 'added' => ['card3.ics'],
- ], $result);
- }
-}
diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/Mock.php b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/Mock.php
deleted file mode 100644
index 630465cc8..000000000
--- a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/Mock.php
+++ /dev/null
@@ -1,257 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Sabre\CardDAV\Backend;
-
-class Mock extends AbstractBackend
-{
- public $addressBooks;
- public $cards;
-
- public function __construct($addressBooks = null, $cards = null)
- {
- $this->addressBooks = $addressBooks;
- $this->cards = $cards;
-
- if (is_null($this->addressBooks)) {
- $this->addressBooks = [
- [
- 'id' => 'foo',
- 'uri' => 'book1',
- 'principaluri' => 'principals/user1',
- '{DAV:}displayname' => 'd-name',
- ],
- [
- 'id' => 'bar',
- 'uri' => 'book3',
- 'principaluri' => 'principals/user1',
- '{DAV:}displayname' => 'd-name',
- ],
- ];
-
- $card2 = fopen('php://memory', 'r+');
- fwrite($card2, "BEGIN:VCARD\nVERSION:3.0\nUID:45678\nEND:VCARD");
- rewind($card2);
- $this->cards = [
- 'foo' => [
- 'card1' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD",
- 'card2' => $card2,
- ],
- 'bar' => [
- 'card3' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nFN:Test-Card\nEMAIL;TYPE=home:bar@example.org\nEND:VCARD",
- ],
- ];
- }
- }
-
- public function getAddressBooksForUser($principalUri)
- {
- $books = [];
- foreach ($this->addressBooks as $book) {
- if ($book['principaluri'] === $principalUri) {
- $books[] = $book;
- }
- }
-
- return $books;
- }
-
- /**
- * Updates properties for an address book.
- *
- * The list of mutations is stored in a Sabre\DAV\PropPatch object.
- * To do the actual updates, you must tell this object which properties
- * you're going to process with the handle() method.
- *
- * Calling the handle method is like telling the PropPatch object "I
- * promise I can handle updating this property".
- *
- * Read the PropPatch documentation for more info and examples.
- *
- * @param string $addressBookId
- */
- public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch)
- {
- foreach ($this->addressBooks as &$book) {
- if ($book['id'] !== $addressBookId) {
- continue;
- }
-
- $propPatch->handleRemaining(function ($mutations) use (&$book) {
- foreach ($mutations as $key => $value) {
- $book[$key] = $value;
- }
-
- return true;
- });
- }
- }
-
- public function createAddressBook($principalUri, $url, array $properties)
- {
- $this->addressBooks[] = array_merge($properties, [
- 'id' => $url,
- 'uri' => $url,
- 'principaluri' => $principalUri,
- ]);
- }
-
- public function deleteAddressBook($addressBookId)
- {
- foreach ($this->addressBooks as $key => $value) {
- if ($value['id'] === $addressBookId) {
- unset($this->addressBooks[$key]);
- }
- }
- unset($this->cards[$addressBookId]);
- }
-
- /**
- * Returns all cards for a specific addressbook id.
- *
- * This method should return the following properties for each card:
- * * carddata - raw vcard data
- * * uri - Some unique url
- * * lastmodified - A unix timestamp
- *
- * It's recommended to also return the following properties:
- * * etag - A unique etag. This must change every time the card changes.
- * * size - The size of the card in bytes.
- *
- * If these last two properties are provided, less time will be spent
- * calculating them. If they are specified, you can also ommit carddata.
- * This may speed up certain requests, especially with large cards.
- *
- * @param mixed $addressBookId
- *
- * @return array
- */
- public function getCards($addressBookId)
- {
- $cards = [];
- foreach ($this->cards[$addressBookId] as $uri => $data) {
- if (is_resource($data)) {
- $cards[] = [
- 'uri' => $uri,
- 'carddata' => $data,
- ];
- } else {
- $cards[] = [
- 'uri' => $uri,
- 'carddata' => $data,
- 'etag' => '"'.md5($data).'"',
- 'size' => strlen($data),
- ];
- }
- }
-
- return $cards;
- }
-
- /**
- * Returns a specfic card.
- *
- * The same set of properties must be returned as with getCards. The only
- * exception is that 'carddata' is absolutely required.
- *
- * If the card does not exist, you must return false.
- *
- * @param mixed $addressBookId
- * @param string $cardUri
- *
- * @return array
- */
- public function getCard($addressBookId, $cardUri)
- {
- if (!isset($this->cards[$addressBookId][$cardUri])) {
- return false;
- }
-
- $data = $this->cards[$addressBookId][$cardUri];
-
- return [
- 'uri' => $cardUri,
- 'carddata' => $data,
- 'etag' => '"'.md5($data).'"',
- 'size' => strlen($data),
- ];
- }
-
- /**
- * Creates a new card.
- *
- * The addressbook id will be passed as the first argument. This is the
- * same id as it is returned from the getAddressBooksForUser method.
- *
- * The cardUri is a base uri, and doesn't include the full path. The
- * cardData argument is the vcard body, and is passed as a string.
- *
- * It is possible to return an ETag from this method. This ETag is for the
- * newly created resource, and must be enclosed with double quotes (that
- * is, the string itself must contain the double quotes).
- *
- * You should only return the ETag if you store the carddata as-is. If a
- * subsequent GET request on the same card does not have the same body,
- * byte-by-byte and you did return an ETag here, clients tend to get
- * confused.
- *
- * If you don't return an ETag, you can just return null.
- *
- * @param mixed $addressBookId
- * @param string $cardUri
- * @param string $cardData
- *
- * @return string|null
- */
- public function createCard($addressBookId, $cardUri, $cardData)
- {
- if (is_resource($cardData)) {
- $cardData = stream_get_contents($cardData);
- }
- $this->cards[$addressBookId][$cardUri] = $cardData;
-
- return '"'.md5($cardData).'"';
- }
-
- /**
- * Updates a card.
- *
- * The addressbook id will be passed as the first argument. This is the
- * same id as it is returned from the getAddressBooksForUser method.
- *
- * The cardUri is a base uri, and doesn't include the full path. The
- * cardData argument is the vcard body, and is passed as a string.
- *
- * It is possible to return an ETag from this method. This ETag should
- * match that of the updated resource, and must be enclosed with double
- * quotes (that is: the string itself must contain the actual quotes).
- *
- * You should only return the ETag if you store the carddata as-is. If a
- * subsequent GET request on the same card does not have the same body,
- * byte-by-byte and you did return an ETag here, clients tend to get
- * confused.
- *
- * If you don't return an ETag, you can just return null.
- *
- * @param mixed $addressBookId
- * @param string $cardUri
- * @param string $cardData
- *
- * @return string|null
- */
- public function updateCard($addressBookId, $cardUri, $cardData)
- {
- if (is_resource($cardData)) {
- $cardData = stream_get_contents($cardData);
- }
- $this->cards[$addressBookId][$cardUri] = $cardData;
-
- return '"'.md5($cardData).'"';
- }
-
- public function deleteCard($addressBookId, $cardUri)
- {
- unset($this->cards[$addressBookId][$cardUri]);
- }
-}
diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOMySQLTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOMySQLTest.php
deleted file mode 100644
index 718eec6be..000000000
--- a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOMySQLTest.php
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Sabre\CardDAV\Backend;
-
-class PDOMySQLTest extends AbstractPDOTest
-{
- public $driver = 'mysql';
-}
diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOSqliteTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOSqliteTest.php
deleted file mode 100644
index b16a00ce2..000000000
--- a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOSqliteTest.php
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Sabre\CardDAV\Backend;
-
-class PDOSqliteTest extends AbstractPDOTest
-{
- public $driver = 'sqlite';
-}