diff options
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/CardDAV')
16 files changed, 822 insertions, 620 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/AbstractPluginTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/AbstractPluginTest.php index a123099a0..552e2ba77 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/AbstractPluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/AbstractPluginTest.php @@ -26,13 +26,13 @@ abstract class AbstractPluginTest extends \PHPUnit_Framework_TestCase { $this->backend = new Backend\Mock(); $principalBackend = new DAVACL\PrincipalBackend\Mock(); - $tree = array( + $tree = [ new AddressBookRoot($principalBackend, $this->backend), new DAVACL\PrincipalCollection($principalBackend) - ); + ]; $this->plugin = new Plugin(); - $this->plugin->directories = array('directory'); + $this->plugin->directories = ['directory']; $this->server = new DAV\Server($tree); $this->server->sapi = new HTTP\SapiMock(); $this->server->addPlugin($this->plugin); diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookQueryTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookQueryTest.php index 478f6beb5..2c3171bf3 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookQueryTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookQueryTest.php @@ -12,11 +12,11 @@ class AddressBookQueryTest extends AbstractPluginTest { function testQuery() { - $request = HTTP\Sapi::createFromServerArray(array( - 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/addressbooks/user1/book1', - 'HTTP_DEPTH' => '1', - )); + $request = new HTTP\Request( + 'REPORT', + '/addressbooks/user1/book1', + ['Depth' => '1'] + ); $request->setBody( '<?xml version="1.0"?> @@ -40,33 +40,33 @@ class AddressBookQueryTest extends AbstractPluginTest { $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); // using the client for parsing - $client = new DAV\Client(array('baseUri'=>'/')); + $client = new DAV\Client(['baseUri' => '/']); $result = $client->parseMultiStatus($response->body); - $this->assertEquals(array( - '/addressbooks/user1/book1/card1' => array( - 200 => array( + $this->assertEquals([ + '/addressbooks/user1/book1/card1' => [ + 200 => [ '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', - ), - ), - '/addressbooks/user1/book1/card2' => array( - 404 => array( + ], + ], + '/addressbooks/user1/book1/card2' => [ + 404 => [ '{DAV:}getetag' => null, - ), - ) - ), $result); + ], + ] + ], $result); } function testQueryDepth0() { - $request = HTTP\Sapi::createFromServerArray(array( - 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/addressbooks/user1/book1/card1', - 'HTTP_DEPTH' => '0', - )); + $request = new HTTP\Request( + 'REPORT', + '/addressbooks/user1/book1/card1', + ['Depth' => '0'] + ); $request->setBody( '<?xml version="1.0"?> @@ -90,28 +90,28 @@ class AddressBookQueryTest extends AbstractPluginTest { $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); // using the client for parsing - $client = new DAV\Client(array('baseUri'=>'/')); + $client = new DAV\Client(['baseUri' => '/']); $result = $client->parseMultiStatus($response->body); - $this->assertEquals(array( - '/addressbooks/user1/book1/card1' => array( - 200 => array( + $this->assertEquals([ + '/addressbooks/user1/book1/card1' => [ + 200 => [ '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', - ), - ), - ), $result); + ], + ], + ], $result); } function testQueryNoMatch() { - $request = HTTP\Sapi::createFromServerArray(array( - 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/addressbooks/user1/book1', - 'HTTP_DEPTH' => '1', - )); + $request = new HTTP\Request( + 'REPORT', + '/addressbooks/user1/book1', + ['Depth' => '1'] + ); $request->setBody( '<?xml version="1.0"?> @@ -135,21 +135,21 @@ class AddressBookQueryTest extends AbstractPluginTest { $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); // using the client for parsing - $client = new DAV\Client(array('baseUri'=>'/')); + $client = new DAV\Client(['baseUri' => '/']); $result = $client->parseMultiStatus($response->body); - $this->assertEquals(array(), $result); + $this->assertEquals([], $result); } function testQueryLimit() { - $request = HTTP\Sapi::createFromServerArray(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/addressbooks/user1/book1', - 'HTTP_DEPTH' => '1', - )); + 'REQUEST_URI' => '/addressbooks/user1/book1', + 'HTTP_DEPTH' => '1', + ]); $request->setBody( '<?xml version="1.0"?> @@ -174,17 +174,17 @@ class AddressBookQueryTest extends AbstractPluginTest { $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); // using the client for parsing - $client = new DAV\Client(array('baseUri'=>'/')); + $client = new DAV\Client(['baseUri' => '/']); $result = $client->parseMultiStatus($response->body); - $this->assertEquals(array( - '/addressbooks/user1/book1/card1' => array( - 200 => array( - '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"). '"', - ), - ), - ), $result); + $this->assertEquals([ + '/addressbooks/user1/book1/card1' => [ + 200 => [ + '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', + ], + ], + ], $result); } @@ -217,20 +217,20 @@ class AddressBookQueryTest extends AbstractPluginTest { $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); // using the client for parsing - $client = new DAV\Client(array('baseUri'=>'/')); + $client = new DAV\Client(['baseUri' => '/']); $result = $client->parseMultiStatus($response->body); $vobjVersion = \Sabre\VObject\Version::VERSION; - $this->assertEquals(array( - '/addressbooks/user1/book1/card1' => array( - 200 => array( - '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"). '"', + $this->assertEquals([ + '/addressbooks/user1/book1/card1' => [ + 200 => [ + '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', '{urn:ietf:params:xml:ns:carddav}address-data' => '["vcard",[["version",{},"text","4.0"],["prodid",{},"text","-\/\/Sabre\/\/Sabre VObject ' . $vobjVersion . '\/\/EN"],["uid",{},"text","12345"]]]', - ), - ), - ), $result); + ], + ], + ], $result); } @@ -262,20 +262,20 @@ class AddressBookQueryTest extends AbstractPluginTest { $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); // using the client for parsing - $client = new DAV\Client(array('baseUri'=>'/')); + $client = new DAV\Client(['baseUri' => '/']); $result = $client->parseMultiStatus($response->body); $vobjVersion = \Sabre\VObject\Version::VERSION; - $this->assertEquals(array( - '/addressbooks/user1/book1/card1' => array( - 200 => array( - '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"). '"', + $this->assertEquals([ + '/addressbooks/user1/book1/card1' => [ + 200 => [ + '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:4.0\r\nPRODID:-//Sabre//Sabre VObject $vobjVersion//EN\r\nUID:12345\r\nEND:VCARD\r\n", - ), - ), - ), $result); + ], + ], + ], $result); } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookTest.php index fe8ba9025..1a36fd10c 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookTest.php @@ -4,10 +4,10 @@ namespace Sabre\CardDAV; use Sabre\DAV\PropPatch; -require_once 'Sabre/CardDAV/Backend/Mock.php'; - class AddressBookTest extends \PHPUnit_Framework_TestCase { + use \Sabre\DAV\DbTestHelperTrait; + /** * @var Sabre\CardDAV\AddressBook */ @@ -19,12 +19,12 @@ class AddressBookTest extends \PHPUnit_Framework_TestCase { $this->backend = new Backend\Mock(); $this->ab = new AddressBook( $this->backend, - array( - 'uri' => 'book1', - 'id' => 'foo', + [ + 'uri' => 'book1', + 'id' => 'foo', '{DAV:}displayname' => 'd-name', - 'principaluri' => 'principals/user1', - ) + 'principaluri' => 'principals/user1', + ] ); } @@ -73,10 +73,10 @@ class AddressBookTest extends \PHPUnit_Framework_TestCase { function testCreateFile() { - $file = fopen('php://memory','r+'); - fwrite($file,'foo'); + $file = fopen('php://memory', 'r+'); + fwrite($file, 'foo'); rewind($file); - $this->ab->createFile('card2',$file); + $this->ab->createFile('card2', $file); $this->assertEquals('foo', $this->backend->cards['foo']['card2']); @@ -85,7 +85,7 @@ class AddressBookTest extends \PHPUnit_Framework_TestCase { function testDelete() { $this->ab->delete(); - $this->assertEquals(array(), $this->backend->addressBooks); + $this->assertEquals([], $this->backend->addressBooks); } @@ -118,10 +118,10 @@ class AddressBookTest extends \PHPUnit_Framework_TestCase { function testGetProperties() { - $props = $this->ab->getProperties(array('{DAV:}displayname')); - $this->assertEquals(array( + $props = $this->ab->getProperties(['{DAV:}displayname']); + $this->assertEquals([ '{DAV:}displayname' => 'd-name', - ), $props); + ], $props); } @@ -129,27 +129,22 @@ class AddressBookTest extends \PHPUnit_Framework_TestCase { $this->assertEquals('principals/user1', $this->ab->getOwner()); $this->assertNull($this->ab->getGroup()); - $this->assertEquals(array( - array( - 'privilege' => '{DAV:}read', - 'principal' => 'principals/user1', - 'protected' => true, - ), - array( - 'privilege' => '{DAV:}write', - 'principal' => 'principals/user1', + $this->assertEquals([ + [ + 'privilege' => '{DAV:}all', + 'principal' => '{DAV:}owner', 'protected' => true, - ), - ), $this->ab->getACL()); + ], + ], $this->ab->getACL()); } /** - * @expectedException Sabre\DAV\Exception\MethodNotAllowed + * @expectedException Sabre\DAV\Exception\Forbidden */ function testSetACL() { - $this->ab->setACL(array()); + $this->ab->setACL([]); } @@ -168,45 +163,32 @@ class AddressBookTest extends \PHPUnit_Framework_TestCase { } function testGetChangesNoSyncSupport() { - $this->assertNull($this->ab->getChanges(1,null)); + $this->assertNull($this->ab->getChanges(1, null)); } function testGetSyncToken() { - if (!SABRE_HASSQLITE) { - $this->markTestSkipped('Sqlite is required for this test to run'); - } - $ab = new AddressBook(TestUtil::getBackend(), [ 'id' => 1, '{DAV:}sync-token' => 2]); + $this->driver = 'sqlite'; + $this->dropTables(['addressbooks', 'cards', 'addressbookchanges']); + $this->createSchema('addressbooks'); + $backend = new Backend\PDO( + $this->getPDO() + ); + $ab = new AddressBook($backend, [ 'id' => 1, '{DAV:}sync-token' => 2]); $this->assertEquals(2, $ab->getSyncToken()); - TestUtil::deleteSQLiteDB(); } function testGetSyncToken2() { - if (!SABRE_HASSQLITE) { - $this->markTestSkipped('Sqlite is required for this test to run'); - } - $ab = new AddressBook(TestUtil::getBackend(), [ 'id' => 1, '{http://sabredav.org/ns}sync-token' => 2]); + $this->driver = 'sqlite'; + $this->dropTables(['addressbooks', 'cards', 'addressbookchanges']); + $this->createSchema('addressbooks'); + $backend = new Backend\PDO( + $this->getPDO() + ); + $ab = new AddressBook($backend, [ 'id' => 1, '{http://sabredav.org/ns}sync-token' => 2]); $this->assertEquals(2, $ab->getSyncToken()); - TestUtil::deleteSQLiteDB(); } - function testGetChanges() { - - if (!SABRE_HASSQLITE) { - $this->markTestSkipped('Sqlite is required for this test to run'); - } - $ab = new AddressBook(TestUtil::getBackend(), [ 'id' => 1, '{DAV:}sync-token' => 2]); - $this->assertEquals([ - 'syncToken' => 2, - 'modified' => [], - 'deleted' => [], - 'added' => ['UUID-2345'], - ], $ab->getChanges(1, 1)); - TestUtil::deleteSQLiteDB(); - - } - - } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php index d2ec278be..f62bfb1ae 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php @@ -7,52 +7,55 @@ use Sabre\DAV\PropPatch; abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { + use \Sabre\DAV\DbTestHelperTrait; + /** * @var CardDAV\Backend\PDO */ protected $backend; - /** - * @abstract - * @return PDO - */ - abstract function getPDO(); - - public function setUp() { + function setUp() { + $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)'); + $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() { + function testGetAddressBooksForUser() { $result = $this->backend->getAddressBooksForUser('principals/user1'); - $expected = array( - array( - 'id' => 1, - 'uri' => 'book1', - 'principaluri' => 'principals/user1', - '{DAV:}displayname' => 'book1', + $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 - ) - ); + '{http://calendarserver.org/ns/}getctag' => 1, + '{http://sabredav.org/ns}sync-token' => 1 + ] + ]; $this->assertEquals($expected, $result); } - public function testUpdateAddressBookInvalidProp() { + function testUpdateAddressBookInvalidProp() { $propPatch = new PropPatch([ - '{DAV:}displayname' => 'updated', + '{DAV:}displayname' => 'updated', '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated', - '{DAV:}foo' => 'bar', + '{DAV:}foo' => 'bar', ]); $this->backend->updateAddressBook(1, $propPatch); @@ -62,23 +65,23 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $result = $this->backend->getAddressBooksForUser('principals/user1'); - $expected = array( - array( - 'id' => 1, - 'uri' => 'book1', - 'principaluri' => 'principals/user1', - '{DAV:}displayname' => 'book1', + $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 - ) - ); + '{http://calendarserver.org/ns/}getctag' => 1, + '{http://sabredav.org/ns}sync-token' => 1 + ] + ]; $this->assertEquals($expected, $result); } - public function testUpdateAddressBookNoProps() { + function testUpdateAddressBookNoProps() { $propPatch = new PropPatch([ ]); @@ -89,27 +92,27 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $result = $this->backend->getAddressBooksForUser('principals/user1'); - $expected = array( - array( - 'id' => 1, - 'uri' => 'book1', - 'principaluri' => 'principals/user1', - '{DAV:}displayname' => 'book1', + $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 - ) - ); + '{http://calendarserver.org/ns/}getctag' => 1, + '{http://sabredav.org/ns}sync-token' => 1 + ] + ]; $this->assertEquals($expected, $result); } - public function testUpdateAddressBookSuccess() { + function testUpdateAddressBookSuccess() { $propPatch = new PropPatch([ - '{DAV:}displayname' => 'updated', + '{DAV:}displayname' => 'updated', '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated', ]); @@ -120,104 +123,108 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $result = $this->backend->getAddressBooksForUser('principals/user1'); - $expected = array( - array( - 'id' => 1, - 'uri' => 'book1', - 'principaluri' => 'principals/user1', - '{DAV:}displayname' => 'updated', + $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 - ) - ); + '{http://calendarserver.org/ns/}getctag' => 2, + '{http://sabredav.org/ns}sync-token' => 2 + ] + ]; $this->assertEquals($expected, $result); } - public function testDeleteAddressBook() { + function testDeleteAddressBook() { $this->backend->deleteAddressBook(1); - $this->assertEquals(array(), $this->backend->getAddressBooksForUser('principals/user1')); + $this->assertEquals([], $this->backend->getAddressBooksForUser('principals/user1')); } /** * @expectedException Sabre\DAV\Exception\BadRequest */ - public function testCreateAddressBookUnsupportedProp() { + function testCreateAddressBookUnsupportedProp() { - $this->backend->createAddressBook('principals/user1','book2', array( + $this->backend->createAddressBook('principals/user1', 'book2', [ '{DAV:}foo' => 'bar', - )); + ]); } - public function testCreateAddressBookSuccess() { + function testCreateAddressBookSuccess() { - $this->backend->createAddressBook('principals/user1','book2', array( - '{DAV:}displayname' => 'book2', + $this->backend->createAddressBook('principals/user1', 'book2', [ + '{DAV:}displayname' => 'book2', '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 2', - )); - - $expected = array( - array( - 'id' => 1, - 'uri' => 'book1', - 'principaluri' => 'principals/user1', - '{DAV:}displayname' => 'book1', + ]); + + $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, - ), - array( - 'id' => 2, - 'uri' => 'book2', - 'principaluri' => 'principals/user1', - '{DAV:}displayname' => 'book2', + '{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, - ) - ); + '{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() { + function testGetCards() { $result = $this->backend->getCards(1); - $expected = array( - array( - 'id' => 1, - 'uri' => 'card1', + $expected = [ + [ + 'id' => 1, + 'uri' => 'card1', 'lastmodified' => 0, - 'etag' => '"' . md5('card1') . '"', - 'size' => 5 - ) - ); + 'etag' => '"' . md5('card1') . '"', + 'size' => 5 + ] + ]; $this->assertEquals($expected, $result); } - public function testGetCard() { + function testGetCard() { - $result = $this->backend->getCard(1,'card1'); + $result = $this->backend->getCard(1, 'card1'); - $expected = array( - 'id' => 1, - 'uri' => 'card1', - 'carddata' => 'card1', + $expected = [ + 'id' => 1, + 'uri' => 'card1', + 'carddata' => 'card1', 'lastmodified' => 0, - 'etag' => '"' . md5('card1') . '"', - 'size' => 5 - ); + 'etag' => '"' . md5('card1') . '"', + 'size' => 5 + ]; + + if (is_resource($result['carddata'])) { + $result['carddata'] = stream_get_contents($result['carddata']); + } $this->assertEquals($expected, $result); @@ -226,13 +233,16 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { /** * @depends testGetCard */ - public function testCreateCard() { + function testCreateCard() { $result = $this->backend->createCard(1, 'card2', 'data2'); $this->assertEquals('"' . md5('data2') . '"', $result); - $result = $this->backend->getCard(1,'card2'); + $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']); } @@ -240,41 +250,52 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { /** * @depends testCreateCard */ - public function testGetMultiple() { + function testGetMultiple() { $result = $this->backend->createCard(1, 'card2', 'data2'); $result = $this->backend->createCard(1, 'card3', 'data3'); $check = [ [ - 'id' => 1, - 'uri' => 'card1', - 'carddata' => 'card1', + 'id' => 1, + 'uri' => 'card1', + 'carddata' => 'card1', 'lastmodified' => 0, ], [ - 'id' => 2, - 'uri' => 'card2', - 'carddata' => 'data2', + 'id' => 2, + 'uri' => 'card2', + 'carddata' => 'data2', 'lastmodified' => time(), ], [ - 'id' => 3, - 'uri' => 'card3', - 'carddata' => 'data3', + 'id' => 3, + 'uri' => 'card3', + 'carddata' => 'data3', 'lastmodified' => time(), ], ]; - $result = $this->backend->getMultipleCards(1, ['card1','card2','card3']); + $result = $this->backend->getMultipleCards(1, ['card1', 'card2', 'card3']); + + foreach ($check as $index => $node) { - foreach($check as $index=>$node) { + foreach ($node as $k => $v) { - foreach($node as $k=>$v) { + $expected = $v; + $actual = $result[$index][$k]; - if ($k!=='lastmodified') { - $this->assertEquals($v, $result[$index][$k]); - } else { - $this->assertTrue(isset($result[$index][$k])); + switch ($k) { + case 'lastmodified' : + $this->assertInternalType('int', $actual); + break; + case 'carddata' : + if (is_resource($actual)) { + $actual = stream_get_contents($actual); + } + // No break intended. + default : + $this->assertEquals($expected, $actual); + break; } } @@ -287,13 +308,16 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { /** * @depends testGetCard */ - public function testUpdateCard() { + function testUpdateCard() { $result = $this->backend->updateCard(1, 'card1', 'newdata'); $this->assertEquals('"' . md5('newdata') . '"', $result); - $result = $this->backend->getCard(1,'card1'); + $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']); } @@ -301,10 +325,10 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { /** * @depends testGetCard */ - public function testDeleteCard() { + function testDeleteCard() { $this->backend->deleteCard(1, 'card1'); - $result = $this->backend->getCard(1,'card1'); + $result = $this->backend->getCard(1, 'card1'); $this->assertFalse($result); } @@ -347,4 +371,3 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { } } - diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/Mock.php b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/Mock.php index 3f96d3c5d..840b898e8 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/Mock.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/Mock.php @@ -13,24 +13,24 @@ class Mock extends AbstractBackend { $this->cards = $cards; if (is_null($this->addressBooks)) { - $this->addressBooks = array( - array( - 'id' => 'foo', - 'uri' => 'book1', - 'principaluri' => 'principals/user1', + $this->addressBooks = [ + [ + 'id' => 'foo', + 'uri' => 'book1', + 'principaluri' => 'principals/user1', '{DAV:}displayname' => 'd-name', - ), - ); + ], + ]; - $card2 = fopen('php://memory','r+'); - fwrite($card2,"BEGIN:VCARD\nVERSION:3.0\nUID:45678\nEND:VCARD"); + $card2 = fopen('php://memory', 'r+'); + fwrite($card2, "BEGIN:VCARD\nVERSION:3.0\nUID:45678\nEND:VCARD"); rewind($card2); - $this->cards = array( - 'foo' => array( + $this->cards = [ + 'foo' => [ 'card1' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD", 'card2' => $card2, - ), - ); + ], + ]; } } @@ -38,8 +38,8 @@ class Mock extends AbstractBackend { function getAddressBooksForUser($principalUri) { - $books = array(); - foreach($this->addressBooks as $book) { + $books = []; + foreach ($this->addressBooks as $book) { if ($book['principaluri'] === $principalUri) { $books[] = $book; } @@ -64,14 +64,14 @@ class Mock extends AbstractBackend { * @param \Sabre\DAV\PropPatch $propPatch * @return void */ - public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) { + function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) { - foreach($this->addressBooks as &$book) { + foreach ($this->addressBooks as &$book) { if ($book['id'] !== $addressBookId) continue; $propPatch->handleRemaining(function($mutations) use (&$book) { - foreach($mutations as $key=>$value) { + foreach ($mutations as $key => $value) { $book[$key] = $value; } return true; @@ -83,17 +83,17 @@ class Mock extends AbstractBackend { function createAddressBook($principalUri, $url, array $properties) { - $this->addressBooks[] = array_merge($properties, array( - 'id' => $url, - 'uri' => $url, + $this->addressBooks[] = array_merge($properties, [ + 'id' => $url, + 'uri' => $url, 'principaluri' => $principalUri, - )); + ]); } function deleteAddressBook($addressBookId) { - foreach($this->addressBooks as $key=>$value) { + foreach ($this->addressBooks as $key => $value) { if ($value['id'] === $addressBookId) unset($this->addressBooks[$key]); } @@ -101,41 +101,142 @@ class Mock extends AbstractBackend { } + /** + * 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 + */ function getCards($addressBookId) { - $cards = array(); - foreach($this->cards[$addressBookId] as $uri=>$data) { - $cards[] = array( - 'uri' => $uri, - 'carddata' => $data, - ); + $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 + */ function getCard($addressBookId, $cardUri) { if (!isset($this->cards[$addressBookId][$cardUri])) { return false; } - return array( - 'uri' => $cardUri, - 'carddata' => $this->cards[$addressBookId][$cardUri], - ); + $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 + */ 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 + */ function updateCard($addressBookId, $cardUri, $cardData) { + if (is_resource($cardData)) { + $cardData = stream_get_contents($cardData); + } $this->cards[$addressBookId][$cardUri] = $cardData; + return '"' . md5($cardData) . '"'; } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOMySQLTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOMySQLTest.php index 38cb655d0..c1b0e274e 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOMySQLTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOMySQLTest.php @@ -2,35 +2,8 @@ namespace Sabre\CardDAV\Backend; -require_once 'Sabre/TestUtil.php'; - class PDOMySQLTest extends AbstractPDOTest { - /** - * @return PDO - */ - public function getPDO() { - - if (!SABRE_HASMYSQL) $this->markTestSkipped('MySQL driver is not available, or not properly configured'); - - $pdo = \Sabre\TestUtil::getMySQLDB(); - if (!$pdo) $this->markTestSkipped('Could not connect to MySQL database'); - - $pdo->query("DROP TABLE IF EXISTS addressbooks, cards, addressbookchanges"); - - $queries = explode( - ';', - file_get_contents(__DIR__ . '/../../../../examples/sql/mysql.addressbook.sql') - ); - - foreach($queries as $query) { - $query = trim($query," \r\n\t"); - if ($query) - $pdo->exec($query); - } - return $pdo; - - } + 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 index 5a4a7a327..b187c4d78 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOSqliteTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOSqliteTest.php @@ -2,53 +2,8 @@ namespace Sabre\CardDAV\Backend; -require_once 'Sabre/TestUtil.php'; - class PDOSqliteTest extends AbstractPDOTest { - function tearDown() { - - if (file_exists(SABRE_TEMPDIR . '/pdobackend')) unlink(SABRE_TEMPDIR . '/pdobackend'); - if (file_exists(SABRE_TEMPDIR . '/pdobackend2')) unlink(SABRE_TEMPDIR . '/pdobackend2'); - - } - - /** - * @return PDO - */ - function getPDO() { - - return self::getSQLite(); - - } - - /** - * @return PDO - */ - static function getSQLite() { - - if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available'); - $pdo = new \PDO('sqlite:'.SABRE_TEMPDIR.'/pdobackend'); - $pdo->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION); - - $pdo->query("DROP TABLE IF EXISTS addressbooks"); - $pdo->query("DROP TABLE IF EXISTS addressbookchanges"); - $pdo->query("DROP TABLE IF EXISTS cards"); - - $queries = explode( - ';', - file_get_contents(__DIR__ . '/../../../../examples/sql/sqlite.addressbooks.sql') - ); - - foreach($queries as $query) { - $query = trim($query," \r\n\t"); - if ($query) - $pdo->exec($query); - } - - return $pdo; - - } + public $driver = 'sqlite'; } - diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/CardTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/CardTest.php index cf8dbab0c..cb7d152c3 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/CardTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/CardTest.php @@ -18,16 +18,16 @@ class CardTest extends \PHPUnit_Framework_TestCase { $this->backend = new Backend\Mock(); $this->card = new Card( $this->backend, - array( - 'uri' => 'book1', - 'id' => 'foo', + [ + 'uri' => 'book1', + 'id' => 'foo', 'principaluri' => 'principals/user1', - ), - array( - 'uri' => 'card1', + ], + [ + 'uri' => 'card1', 'addressbookid' => 'foo', - 'carddata' => 'card', - ) + 'carddata' => 'card', + ] ); } @@ -42,15 +42,15 @@ class CardTest extends \PHPUnit_Framework_TestCase { $this->card = new Card( $this->backend, - array( - 'uri' => 'book1', - 'id' => 'foo', + [ + 'uri' => 'book1', + 'id' => 'foo', 'principaluri' => 'principals/user1', - ), - array( - 'uri' => 'card1', + ], + [ + 'uri' => 'card1', 'addressbookid' => 'foo', - ) + ] ); $result = $this->card->get(); $this->assertEquals("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD", $result); @@ -63,7 +63,7 @@ class CardTest extends \PHPUnit_Framework_TestCase { */ function testPut() { - $file = fopen('php://memory','r+'); + $file = fopen('php://memory', 'r+'); fwrite($file, 'newdata'); rewind($file); $this->card->put($file); @@ -88,7 +88,7 @@ class CardTest extends \PHPUnit_Framework_TestCase { function testGetETag() { - $this->assertEquals('"' . md5('card') . '"' , $this->card->getETag()); + $this->assertEquals('"' . md5('card') . '"', $this->card->getETag()); } @@ -96,19 +96,19 @@ class CardTest extends \PHPUnit_Framework_TestCase { $card = new Card( $this->backend, - array( - 'uri' => 'book1', - 'id' => 'foo', + [ + 'uri' => 'book1', + 'id' => 'foo', 'principaluri' => 'principals/user1', - ), - array( - 'uri' => 'card1', + ], + [ + 'uri' => 'card1', 'addressbookid' => 'foo', - 'carddata' => 'card', - 'etag' => '"blabla"', - ) + 'carddata' => 'card', + 'etag' => '"blabla"', + ] ); - $this->assertEquals('"blabla"' , $card->getETag()); + $this->assertEquals('"blabla"', $card->getETag()); } @@ -129,17 +129,17 @@ class CardTest extends \PHPUnit_Framework_TestCase { $card = new Card( $this->backend, - array( - 'uri' => 'book1', - 'id' => 'foo', + [ + 'uri' => 'book1', + 'id' => 'foo', 'principaluri' => 'principals/user1', - ), - array( - 'uri' => 'card1', + ], + [ + 'uri' => 'card1', 'addressbookid' => 'foo', - 'etag' => '"blabla"', - 'size' => 4, - ) + 'etag' => '"blabla"', + 'size' => 4, + ] ); $this->assertEquals(4, $card->getSize()); @@ -149,58 +149,53 @@ class CardTest extends \PHPUnit_Framework_TestCase { $this->assertEquals('principals/user1', $this->card->getOwner()); $this->assertNull($this->card->getGroup()); - $this->assertEquals(array( - array( - 'privilege' => '{DAV:}read', - 'principal' => 'principals/user1', - 'protected' => true, - ), - array( - 'privilege' => '{DAV:}write', + $this->assertEquals([ + [ + 'privilege' => '{DAV:}all', 'principal' => 'principals/user1', 'protected' => true, - ), - ), $this->card->getACL()); + ], + ], $this->card->getACL()); } function testOverrideACL() { $card = new Card( $this->backend, - array( - 'uri' => 'book1', - 'id' => 'foo', + [ + 'uri' => 'book1', + 'id' => 'foo', 'principaluri' => 'principals/user1', - ), - array( - 'uri' => 'card1', + ], + [ + 'uri' => 'card1', 'addressbookid' => 'foo', - 'carddata' => 'card', - 'acl' => array( - array( + 'carddata' => 'card', + 'acl' => [ + [ 'privilege' => '{DAV:}read', 'principal' => 'principals/user1', 'protected' => true, - ), - ), - ) + ], + ], + ] ); - $this->assertEquals(array( - array( + $this->assertEquals([ + [ 'privilege' => '{DAV:}read', 'principal' => 'principals/user1', 'protected' => true, - ), - ), $card->getACL()); + ], + ], $card->getACL()); } /** - * @expectedException Sabre\DAV\Exception\MethodNotAllowed + * @expectedException Sabre\DAV\Exception\Forbidden */ function testSetACL() { - $this->card->setACL(array()); + $this->card->setACL([]); } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/IDirectoryTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/IDirectoryTest.php index 431cd2524..4796a131f 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/IDirectoryTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/IDirectoryTest.php @@ -8,15 +8,15 @@ class IDirectoryTest extends \PHPUnit_Framework_TestCase { function testResourceType() { - $tree = array( + $tree = [ new DirectoryMock('directory') - ); + ]; $server = new DAV\Server($tree); $plugin = new Plugin(); $server->addPlugin($plugin); - $props = $server->getProperties('directory', array('{DAV:}resourcetype')); + $props = $server->getProperties('directory', ['{DAV:}resourcetype']); $this->assertTrue($props['{DAV:}resourcetype']->is('{' . Plugin::NS_CARDDAV . '}directory')); } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/MultiGetTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/MultiGetTest.php index b0ee45880..d79239d0f 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/MultiGetTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/MultiGetTest.php @@ -11,10 +11,10 @@ class MultiGetTest extends AbstractPluginTest { function testMultiGet() { - $request = HTTP\Sapi::createFromServerArray(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/addressbooks/user1/book1', - )); + 'REQUEST_URI' => '/addressbooks/user1/book1', + ]); $request->setBody( '<?xml version="1.0"?> @@ -37,27 +37,27 @@ class MultiGetTest extends AbstractPluginTest { $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); // using the client for parsing - $client = new DAV\Client(array('baseUri'=>'/')); + $client = new DAV\Client(['baseUri' => '/']); $result = $client->parseMultiStatus($response->body); - $this->assertEquals(array( - '/addressbooks/user1/book1/card1' => array( - 200 => array( - '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', - '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:3.0\r\nUID:12345\r\nEND:VCARD\r\n", - ) - ) - ), $result); + $this->assertEquals([ + '/addressbooks/user1/book1/card1' => [ + 200 => [ + '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', + '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD", + ] + ] + ], $result); } function testMultiGetVCard4() { - $request = HTTP\Sapi::createFromServerArray(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/addressbooks/user1/book1', - )); + 'REQUEST_URI' => '/addressbooks/user1/book1', + ]); $request->setBody( '<?xml version="1.0"?> @@ -80,20 +80,20 @@ class MultiGetTest extends AbstractPluginTest { $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); // using the client for parsing - $client = new DAV\Client(array('baseUri'=>'/')); + $client = new DAV\Client(['baseUri' => '/']); $result = $client->parseMultiStatus($response->body); $prodId = "PRODID:-//Sabre//Sabre VObject " . \Sabre\VObject\Version::VERSION . "//EN"; - $this->assertEquals(array( - '/addressbooks/user1/book1/card1' => array( - 200 => array( - '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', + $this->assertEquals([ + '/addressbooks/user1/book1/card1' => [ + 200 => [ + '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:4.0\r\n$prodId\r\nUID:12345\r\nEND:VCARD\r\n", - ) - ) - ), $result); + ] + ] + ], $result); } } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/PluginTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/PluginTest.php index 9c916350e..6962e7830 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/PluginTest.php @@ -3,7 +3,6 @@ namespace Sabre\CardDAV; use Sabre\DAV; -use Sabre\DAV\Xml\Property\Href; class PluginTest extends AbstractPluginTest { @@ -18,23 +17,23 @@ class PluginTest extends AbstractPluginTest { function testSupportedReportSet() { - $this->assertEquals(array( + $this->assertEquals([ '{' . Plugin::NS_CARDDAV . '}addressbook-multiget', '{' . Plugin::NS_CARDDAV . '}addressbook-query', - ), $this->plugin->getSupportedReportSet('addressbooks/user1/book1')); + ], $this->plugin->getSupportedReportSet('addressbooks/user1/book1')); } function testSupportedReportSetEmpty() { - $this->assertEquals(array( - ), $this->plugin->getSupportedReportSet('')); + $this->assertEquals([ + ], $this->plugin->getSupportedReportSet('')); } function testAddressBookHomeSet() { - $result = $this->server->getProperties('principals/user1', array('{' . Plugin::NS_CARDDAV . '}addressbook-home-set')); + $result = $this->server->getProperties('principals/user1', ['{' . Plugin::NS_CARDDAV . '}addressbook-home-set']); $this->assertEquals(1, count($result)); $this->assertTrue(isset($result['{' . Plugin::NS_CARDDAV . '}addressbook-home-set'])); @@ -44,11 +43,11 @@ class PluginTest extends AbstractPluginTest { function testDirectoryGateway() { - $result = $this->server->getProperties('principals/user1', array('{' . Plugin::NS_CARDDAV . '}directory-gateway')); + $result = $this->server->getProperties('principals/user1', ['{' . Plugin::NS_CARDDAV . '}directory-gateway']); $this->assertEquals(1, count($result)); $this->assertTrue(isset($result['{' . Plugin::NS_CARDDAV . '}directory-gateway'])); - $this->assertEquals(array('directory'), $result['{' . Plugin::NS_CARDDAV . '}directory-gateway']->getHrefs()); + $this->assertEquals(['directory'], $result['{' . Plugin::NS_CARDDAV . '}directory-gateway']->getHrefs()); } @@ -64,7 +63,7 @@ class PluginTest extends AbstractPluginTest { $r = $this->server->emit('onHTMLActionsPanel', [$this->server->tree->getNodeForPath('addressbooks/user1'), &$output]); $this->assertFalse($r); - $this->assertTrue(!!strpos($output,'Display name')); + $this->assertTrue(!!strpos($output, 'Display name')); } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/SogoStripContentTypeTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/SogoStripContentTypeTest.php index f828cc25b..0ba4fd669 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/SogoStripContentTypeTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/SogoStripContentTypeTest.php @@ -5,44 +5,44 @@ namespace Sabre\CardDAV; use Sabre\HTTP; use Sabre\DAV\PropFind; -class SogoStripContentType extends \Sabre\DAVServerTest { +class SogoStripContentTypeTest extends \Sabre\DAVServerTest { protected $setupCardDAV = true; - protected $carddavAddressBooks = array( - array( - 'id' => 1, - 'uri' => 'book1', + protected $carddavAddressBooks = [ + [ + 'id' => 1, + 'uri' => 'book1', 'principaluri' => 'principals/user1', - ), - ); - protected $carddavCards = array( - 1 => array( + ], + ]; + protected $carddavCards = [ + 1 => [ 'card1.vcf' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD", - ), - ); + ], + ]; function testDontStrip() { - $result = $this->server->getProperties('addressbooks/user1/book1/card1.vcf',array('{DAV:}getcontenttype')); - $this->assertEquals(array( + $result = $this->server->getProperties('addressbooks/user1/book1/card1.vcf', ['{DAV:}getcontenttype']); + $this->assertEquals([ '{DAV:}getcontenttype' => 'text/vcard; charset=utf-8' - ), $result); + ], $result); } function testStrip() { - $this->server->httpRequest = HTTP\Sapi::createFromServerArray(array( + $this->server->httpRequest = HTTP\Sapi::createFromServerArray([ 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 Lightning/1.2.1', - )); - $result = $this->server->getProperties('addressbooks/user1/book1/card1.vcf',array('{DAV:}getcontenttype')); - $this->assertEquals(array( + ]); + $result = $this->server->getProperties('addressbooks/user1/book1/card1.vcf', ['{DAV:}getcontenttype']); + $this->assertEquals([ '{DAV:}getcontenttype' => 'text/x-vcard' - ), $result); + ], $result); } function testDontTouchOtherMimeTypes() { - $this->server->httpRequest = new HTTP\Request('GET','/addressbooks/user1/book1/card1.vcf', [ + $this->server->httpRequest = new HTTP\Request('GET', '/addressbooks/user1/book1/card1.vcf', [ 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 Lightning/1.2.1', ]); diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/TestUtil.php b/vendor/sabre/dav/tests/Sabre/CardDAV/TestUtil.php index c9cc10d35..ec8a3501e 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/TestUtil.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/TestUtil.php @@ -2,8 +2,6 @@ namespace Sabre\CardDAV; -use PDO; - class TestUtil { static function getBackend() { @@ -22,18 +20,18 @@ class TestUtil { $addressbookId = $backend->createAddressBook( 'principals/user1', 'UUID-123467', - array( - '{DAV:}displayname' => 'user1 addressbook', + [ + '{DAV:}displayname' => 'user1 addressbook', '{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'AddressBook description', - ) + ] ); $backend->createAddressBook( 'principals/user1', 'UUID-123468', - array( - '{DAV:}displayname' => 'user1 addressbook2', + [ + '{DAV:}displayname' => 'user1 addressbook2', '{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'AddressBook description', - ) + ] ); $backend->createCard($addressbookId, 'UUID-2345', self::getTestCardData()); return $pdo; diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/VCFExportTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/VCFExportTest.php index 71fde719d..82d82fadd 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/VCFExportTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/VCFExportTest.php @@ -10,21 +10,21 @@ class VCFExportTest extends \Sabre\DAVServerTest { protected $autoLogin = 'user1'; protected $setupACL = true; - protected $carddavAddressBooks = array( - array( - 'id' => 'book1', - 'uri' => 'book1', + protected $carddavAddressBooks = [ + [ + 'id' => 'book1', + 'uri' => 'book1', 'principaluri' => 'principals/user1', - ) - ); - protected $carddavCards = array( - 'book1' => array( + ] + ]; + protected $carddavCards = [ + 'book1' => [ "card1" => "BEGIN:VCARD\r\nFN:Person1\r\nEND:VCARD\r\n", "card2" => "BEGIN:VCARD\r\nFN:Person2\r\nEND:VCARD", "card3" => "BEGIN:VCARD\r\nFN:Person3\r\nEND:VCARD\r\n", "card4" => "BEGIN:VCARD\nFN:Person4\nEND:VCARD\n", - ) - ); + ] + ]; function setUp() { @@ -50,11 +50,11 @@ class VCFExportTest extends \Sabre\DAVServerTest { function testExport() { - $request = HTTP\Sapi::createFromServerArray(array( - 'REQUEST_URI' => '/addressbooks/user1/book1?export', - 'QUERY_STRING' => 'export', + $request = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/addressbooks/user1/book1?export', + 'QUERY_STRING' => 'export', 'REQUEST_METHOD' => 'GET', - )); + ]); $response = $this->request($request); $this->assertEquals(200, $response->status, $response->body); @@ -73,7 +73,7 @@ FN:Person4 END:VCARD "; // We actually expected windows line endings - $expected = str_replace("\n","\r\n", $expected); + $expected = str_replace("\n", "\r\n", $expected); $this->assertEquals($expected, $response->body); @@ -89,4 +89,47 @@ END:VCARD } + function testContentDisposition() { + + $request = new HTTP\Request( + 'GET', + '/addressbooks/user1/book1?export' + ); + + $response = $this->request($request, 200); + $this->assertEquals('text/directory', $response->getHeader('Content-Type')); + $this->assertEquals( + 'attachment; filename="book1-' . date('Y-m-d') . '.vcf"', + $response->getHeader('Content-Disposition') + ); + + } + + function testContentDispositionBadChars() { + + $this->carddavBackend->createAddressBook( + 'principals/user1', + 'book-b_ad"(ch)ars', + [] + ); + $this->carddavBackend->createCard( + 'book-b_ad"(ch)ars', + 'card1', + "BEGIN:VCARD\r\nFN:Person1\r\nEND:VCARD\r\n" + ); + + $request = new HTTP\Request( + 'GET', + '/addressbooks/user1/book-b_ad"(ch)ars?export' + ); + + $response = $this->request($request, 200); + $this->assertEquals('text/directory', $response->getHeader('Content-Type')); + $this->assertEquals( + 'attachment; filename="book-b_adchars-' . date('Y-m-d') . '.vcf"', + $response->getHeader('Content-Disposition') + ); + + } + } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateFilterTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateFilterTest.php index c87716c10..57ac21b4a 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateFilterTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateFilterTest.php @@ -48,35 +48,35 @@ HELLO; // Check if TITLE is defined $filter1 = - array('name' => 'title', 'is-not-defined' => false, 'param-filters' => array(), 'text-matches' => array()); + ['name' => 'title', 'is-not-defined' => false, 'param-filters' => [], 'text-matches' => []]; // Check if FOO is defined $filter2 = - array('name' => 'foo', 'is-not-defined' => false, 'param-filters' => array(), 'text-matches' => array()); + ['name' => 'foo', 'is-not-defined' => false, 'param-filters' => [], 'text-matches' => []]; // Check if TITLE is not defined $filter3 = - array('name' => 'title', 'is-not-defined' => true, 'param-filters' => array(), 'text-matches' => array()); + ['name' => 'title', 'is-not-defined' => true, 'param-filters' => [], 'text-matches' => []]; // Check if FOO is not defined $filter4 = - array('name' => 'foo', 'is-not-defined' => true, 'param-filters' => array(), 'text-matches' => array()); + ['name' => 'foo', 'is-not-defined' => true, 'param-filters' => [], 'text-matches' => []]; // Check if TEL[TYPE] is defined $filter5 = - array( - 'name' => 'tel', + [ + 'name' => 'tel', 'is-not-defined' => false, - 'test' => 'anyof', - 'param-filters' => array( - array( - 'name' => 'type', + 'test' => 'anyof', + 'param-filters' => [ + [ + 'name' => 'type', 'is-not-defined' => false, - 'text-match' => null - ), - ), - 'text-matches' => array(), - ); + 'text-match' => null + ], + ], + 'text-matches' => [], + ]; // Check if TEL[FOO] is defined $filter6 = $filter5; @@ -101,20 +101,20 @@ HELLO; // Check if URL contains 'google' $filter11 = - array( - 'name' => 'url', + [ + 'name' => 'url', 'is-not-defined' => false, - 'test' => 'anyof', - 'param-filters' => array(), - 'text-matches' => array( - array( - 'match-type' => 'contains', - 'value' => 'google', + 'test' => 'anyof', + 'param-filters' => [], + 'text-matches' => [ + [ + 'match-type' => 'contains', + 'value' => 'google', 'negate-condition' => false, - 'collation' => 'i;octet', - ), - ), - ); + 'collation' => 'i;octet', + ], + ], + ]; // Check if URL contains 'bing' $filter12 = $filter11; @@ -131,12 +131,12 @@ HELLO; // Param filter with text $filter15 = $filter5; - $filter15['param-filters'][0]['text-match'] = array( - 'match-type' => 'contains', - 'value' => 'WORK', - 'collation' => 'i;octet', + $filter15['param-filters'][0]['text-match'] = [ + 'match-type' => 'contains', + 'value' => 'WORK', + 'collation' => 'i;octet', 'negate-condition' => false, - ); + ]; $filter16 = $filter15; $filter16['param-filters'][0]['text-match']['negate-condition'] = true; @@ -144,60 +144,60 @@ HELLO; // Param filter + text filter $filter17 = $filter5; $filter17['test'] = 'anyof'; - $filter17['text-matches'][] = array( - 'match-type' => 'contains', - 'value' => '444', - 'collation' => 'i;octet', + $filter17['text-matches'][] = [ + 'match-type' => 'contains', + 'value' => '444', + 'collation' => 'i;octet', 'negate-condition' => false, - ); + ]; $filter18 = $filter17; $filter18['text-matches'][0]['negate-condition'] = true; $filter18['test'] = 'allof'; - return array( + return [ // Basic filters - array($body1, array($filter1), 'anyof',true), - array($body1, array($filter2), 'anyof',false), - array($body1, array($filter3), 'anyof',false), - array($body1, array($filter4), 'anyof',true), + [$body1, [$filter1], 'anyof',true], + [$body1, [$filter2], 'anyof',false], + [$body1, [$filter3], 'anyof',false], + [$body1, [$filter4], 'anyof',true], // Combinations - array($body1, array($filter1, $filter2), 'anyof',true), - array($body1, array($filter1, $filter2), 'allof',false), - array($body1, array($filter1, $filter4), 'anyof',true), - array($body1, array($filter1, $filter4), 'allof',true), - array($body1, array($filter2, $filter3), 'anyof',false), - array($body1, array($filter2, $filter3), 'allof',false), + [$body1, [$filter1, $filter2], 'anyof',true], + [$body1, [$filter1, $filter2], 'allof',false], + [$body1, [$filter1, $filter4], 'anyof',true], + [$body1, [$filter1, $filter4], 'allof',true], + [$body1, [$filter2, $filter3], 'anyof',false], + [$body1, [$filter2, $filter3], 'allof',false], // Basic parameters - array($body1, array($filter5), 'anyof', true, 'TEL;TYPE is defined, so this should return true'), - array($body1, array($filter6), 'anyof', false, 'TEL;FOO is not defined, so this should return false'), + [$body1, [$filter5], 'anyof', true, 'TEL;TYPE is defined, so this should return true'], + [$body1, [$filter6], 'anyof', false, 'TEL;FOO is not defined, so this should return false'], - array($body1, array($filter7), 'anyof', false, 'TEL;TYPE is defined, so this should return false'), - array($body1, array($filter8), 'anyof', true, 'TEL;TYPE is not defined, so this should return true'), + [$body1, [$filter7], 'anyof', false, 'TEL;TYPE is defined, so this should return false'], + [$body1, [$filter8], 'anyof', true, 'TEL;TYPE is not defined, so this should return true'], // Combined parameters - array($body1, array($filter9), 'anyof', true), - array($body1, array($filter10), 'anyof', false), + [$body1, [$filter9], 'anyof', true], + [$body1, [$filter10], 'anyof', false], // Text-filters - array($body1, array($filter11), 'anyof', true), - array($body1, array($filter12), 'anyof', false), - array($body1, array($filter13), 'anyof', false), - array($body1, array($filter14), 'anyof', true), + [$body1, [$filter11], 'anyof', true], + [$body1, [$filter12], 'anyof', false], + [$body1, [$filter13], 'anyof', false], + [$body1, [$filter14], 'anyof', true], // Param filter with text-match - array($body1, array($filter15), 'anyof', true), - array($body1, array($filter16), 'anyof', false), + [$body1, [$filter15], 'anyof', true], + [$body1, [$filter16], 'anyof', false], // Param filter + text filter - array($body1, array($filter17), 'anyof', true), - array($body1, array($filter18), 'anyof', false), - array($body1, array($filter18), 'anyof', false), - ); + [$body1, [$filter17], 'anyof', true], + [$body1, [$filter18], 'anyof', false], + [$body1, [$filter18], 'anyof', false], + ]; } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateVCardTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateVCardTest.php index ad8495c13..dda8a0c37 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateVCardTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateVCardTest.php @@ -15,20 +15,20 @@ class ValidateVCardTest extends \PHPUnit_Framework_TestCase { function setUp() { - $addressbooks = array( - array( - 'id' => 'addressbook1', + $addressbooks = [ + [ + 'id' => 'addressbook1', 'principaluri' => 'principals/admin', - 'uri' => 'addressbook1', - ) - ); + 'uri' => 'addressbook1', + ] + ]; - $this->cardBackend = new Backend\Mock($addressbooks,array()); + $this->cardBackend = new Backend\Mock($addressbooks, []); $principalBackend = new DAVACL\PrincipalBackend\Mock(); - $tree = array( + $tree = [ new AddressBookRoot($principalBackend, $this->cardBackend), - ); + ]; $this->server = new DAV\Server($tree); $this->server->sapi = new HTTP\SapiMock(); @@ -42,21 +42,36 @@ class ValidateVCardTest extends \PHPUnit_Framework_TestCase { } - function request(HTTP\Request $request) { + function request(HTTP\Request $request, $expectedStatus = null) { $this->server->httpRequest = $request; $this->server->exec(); + if ($expectedStatus) { + + $realStatus = $this->server->httpResponse->getStatus(); + + $msg = ''; + if ($realStatus !== $expectedStatus) { + $msg = 'Response body: ' . $this->server->httpResponse->getBodyAsString(); + } + $this->assertEquals( + $expectedStatus, + $realStatus, + $msg + ); + } + return $this->server->httpResponse; } function testCreateFile() { - $request = HTTP\Sapi::createFromServerArray(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'PUT', - 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf', - )); + 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf', + ]); $response = $this->request($request); @@ -66,38 +81,159 @@ class ValidateVCardTest extends \PHPUnit_Framework_TestCase { function testCreateFileValid() { - $request = HTTP\Sapi::createFromServerArray(array( - 'REQUEST_METHOD' => 'PUT', - 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf', - )); - $request->setBody("BEGIN:VCARD\r\nUID:foo\r\nEND:VCARD\r\n"); - - $response = $this->request($request); + $request = new HTTP\Request( + 'PUT', + '/addressbooks/admin/addressbook1/blabla.vcf' + ); - $this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); - $expected = array( - 'uri' => 'blabla.vcf', - 'carddata' => "BEGIN:VCARD\r\nUID:foo\r\nEND:VCARD\r\n", + $vcard = <<<VCF +BEGIN:VCARD +VERSION:4.0 +UID:foo +FN:Firstname LastName +N:LastName;FirstName;;; +END:VCARD +VCF; + $request->setBody($vcard); + + $response = $this->request($request, 201); + + // The custom Ew header should not be set + $this->assertNull( + $response->getHeader('X-Sabre-Ew-Gross') + ); + // Valid, non-auto-fixed responses should contain an ETag. + $this->assertTrue( + $response->getHeader('ETag') !== null, + 'We did not receive an etag' ); - $this->assertEquals($expected, $this->cardBackend->getCard('addressbook1','blabla.vcf')); + + $expected = [ + 'uri' => 'blabla.vcf', + 'carddata' => $vcard, + 'size' => strlen($vcard), + 'etag' => '"' . md5($vcard) . '"', + ]; + + $this->assertEquals($expected, $this->cardBackend->getCard('addressbook1', 'blabla.vcf')); } - function testCreateFileNoUID() { + /** + * This test creates an intentionally broken vCard that vobject is able + * to automatically repair. + * + * @depends testCreateFileValid + */ + function testCreateVCardAutoFix() { $request = new HTTP\Request( 'PUT', '/addressbooks/admin/addressbook1/blabla.vcf' ); - $request->setBody("BEGIN:VCARD\r\nEND:VCARD\r\n"); - $response = $this->request($request); + // The error in this vcard is that there's not enough semi-colons in N + $vcard = <<<VCF +BEGIN:VCARD +VERSION:4.0 +UID:foo +FN:Firstname LastName +N:LastName;FirstName;; +END:VCARD +VCF; - $this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $request->setBody($vcard); + + $response = $this->request($request, 201); + + // Auto-fixed vcards should NOT return an etag + $this->assertNull( + $response->getHeader('ETag') + ); + + // We should have gotten an Ew header + $this->assertNotNull( + $response->getHeader('X-Sabre-Ew-Gross') + ); + + $expectedVCard = <<<VCF +BEGIN:VCARD\r +VERSION:4.0\r +UID:foo\r +FN:Firstname LastName\r +N:LastName;FirstName;;;\r +END:VCARD\r + +VCF; + + $expected = [ + 'uri' => 'blabla.vcf', + 'carddata' => $expectedVCard, + 'size' => strlen($expectedVCard), + 'etag' => '"' . md5($expectedVCard) . '"', + ]; + + $this->assertEquals($expected, $this->cardBackend->getCard('addressbook1', 'blabla.vcf')); - $foo = $this->cardBackend->getCard('addressbook1','blabla.vcf'); - $this->assertTrue(strpos($foo['carddata'],'UID')!==false); + } + + /** + * This test creates an intentionally broken vCard that vobject is able + * to automatically repair. + * + * However, we're supplying a heading asking the server to treat the + * request as strict, so the server should still let the request fail. + * + * @depends testCreateFileValid + */ + function testCreateVCardStrictFail() { + + $request = new HTTP\Request( + 'PUT', + '/addressbooks/admin/addressbook1/blabla.vcf', + [ + 'Prefer' => 'handling=strict', + ] + ); + + // The error in this vcard is that there's not enough semi-colons in N + $vcard = <<<VCF +BEGIN:VCARD +VERSION:4.0 +UID:foo +FN:Firstname LastName +N:LastName;FirstName;; +END:VCARD +VCF; + + $request->setBody($vcard); + $this->request($request, 415); + + } + + function testCreateFileNoUID() { + + $request = new HTTP\Request( + 'PUT', + '/addressbooks/admin/addressbook1/blabla.vcf' + ); + $vcard = <<<VCF +BEGIN:VCARD +VERSION:4.0 +FN:Firstname LastName +N:LastName;FirstName;;; +END:VCARD +VCF; + $request->setBody($vcard); + + $response = $this->request($request, 201); + + $foo = $this->cardBackend->getCard('addressbook1', 'blabla.vcf'); + $this->assertTrue( + strpos($foo['carddata'], 'UID') !== false, + print_r($foo, true) + ); } function testCreateFileJson() { @@ -106,23 +242,23 @@ class ValidateVCardTest extends \PHPUnit_Framework_TestCase { 'PUT', '/addressbooks/admin/addressbook1/blabla.vcf' ); - $request->setBody('[ "vcard" , [ [ "UID" , {}, "text", "foo" ] ] ]'); + $request->setBody('[ "vcard" , [ [ "VERSION", {}, "text", "4.0"], [ "UID" , {}, "text", "foo" ], [ "FN", {}, "text", "FirstName LastName"] ] ]'); $response = $this->request($request); $this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); - $foo = $this->cardBackend->getCard('addressbook1','blabla.vcf'); - $this->assertEquals("BEGIN:VCARD\r\nUID:foo\r\nEND:VCARD\r\n", $foo['carddata']); + $foo = $this->cardBackend->getCard('addressbook1', 'blabla.vcf'); + $this->assertEquals("BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nFN:FirstName LastName\r\nEND:VCARD\r\n", $foo['carddata']); } function testCreateFileVCalendar() { - $request = HTTP\Sapi::createFromServerArray(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'PUT', - 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf', - )); + 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf', + ]); $request->setBody("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n"); $response = $this->request($request); @@ -133,40 +269,37 @@ class ValidateVCardTest extends \PHPUnit_Framework_TestCase { function testUpdateFile() { - $this->cardBackend->createCard('addressbook1','blabla.vcf','foo'); - $request = HTTP\Sapi::createFromServerArray(array( - 'REQUEST_METHOD' => 'PUT', - 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf', - )); - - $response = $this->request($request); + $this->cardBackend->createCard('addressbook1', 'blabla.vcf', 'foo'); + $request = new HTTP\Request( + 'PUT', + '/addressbooks/admin/addressbook1/blabla.vcf' + ); - $this->assertEquals(415, $response->status); + $response = $this->request($request, 415); } function testUpdateFileParsableBody() { - $this->cardBackend->createCard('addressbook1','blabla.vcf','foo'); - $request = HTTP\Sapi::createFromServerArray(array( - 'REQUEST_METHOD' => 'PUT', - 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf', - )); - $body = "BEGIN:VCARD\r\nUID:foo\r\nEND:VCARD\r\n"; - $request->setBody($body); + $this->cardBackend->createCard('addressbook1', 'blabla.vcf', 'foo'); + $request = new HTTP\Request( + 'PUT', + '/addressbooks/admin/addressbook1/blabla.vcf' + ); - $response = $this->request($request); + $body = "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nFN:FirstName LastName\r\nEND:VCARD\r\n"; + $request->setBody($body); - $this->assertEquals(204, $response->status); + $response = $this->request($request, 204); - $expected = array( + $expected = [ 'uri' => 'blabla.vcf', - 'carddata' => $body, - ); + 'carddata' => $body, + 'size' => strlen($body), + 'etag' => '"' . md5($body) . '"', + ]; - $this->assertEquals($expected, $this->cardBackend->getCard('addressbook1','blabla.vcf')); + $this->assertEquals($expected, $this->cardBackend->getCard('addressbook1', 'blabla.vcf')); } } - -?> |