aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateVCardTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/CardDAV/ValidateVCardTest.php')
-rw-r--r--vendor/sabre/dav/tests/Sabre/CardDAV/ValidateVCardTest.php253
1 files changed, 193 insertions, 60 deletions
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'));
}
}
-
-?>