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.php155
1 files changed, 155 insertions, 0 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateVCardTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateVCardTest.php
new file mode 100644
index 000000000..1f52f30a7
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateVCardTest.php
@@ -0,0 +1,155 @@
+<?php
+
+namespace Sabre\CardDAV;
+
+use Sabre\DAV;
+use Sabre\HTTP;
+use Sabre\DAVACL;
+
+require_once 'Sabre/HTTP/ResponseMock.php';
+
+class ValidateVCardTest extends \PHPUnit_Framework_TestCase {
+
+ protected $server;
+ protected $cardBackend;
+
+ function setUp() {
+
+ $addressbooks = array(
+ array(
+ 'id' => 'addressbook1',
+ 'principaluri' => 'principals/admin',
+ 'uri' => 'addressbook1',
+ )
+ );
+
+ $this->cardBackend = new Backend\Mock($addressbooks,array());
+ $principalBackend = new DAVACL\PrincipalBackend\Mock();
+
+ $tree = array(
+ new AddressBookRoot($principalBackend, $this->cardBackend),
+ );
+
+ $this->server = new DAV\Server($tree);
+ $this->server->debugExceptions = true;
+
+ $plugin = new Plugin();
+ $this->server->addPlugin($plugin);
+
+ $response = new HTTP\ResponseMock();
+ $this->server->httpResponse = $response;
+
+ }
+
+ function request(HTTP\Request $request) {
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ return $this->server->httpResponse;
+
+ }
+
+ function testCreateFile() {
+
+ $request = new HTTP\Request(array(
+ 'REQUEST_METHOD' => 'PUT',
+ 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf',
+ ));
+
+ $response = $this->request($request);
+
+ $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status);
+
+ }
+
+ function testCreateFileValid() {
+
+ $request = new HTTP\Request(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);
+
+ $this->assertEquals('HTTP/1.1 201 Created', $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",
+ );
+
+ $this->assertEquals($expected, $this->cardBackend->getCard('addressbook1','blabla.vcf'));
+
+ }
+
+ function testCreateFileNoUID() {
+
+ $request = new HTTP\Request(array(
+ 'REQUEST_METHOD' => 'PUT',
+ 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf',
+ ));
+ $request->setBody("BEGIN:VCARD\r\nEND:VCARD\r\n");
+
+ $response = $this->request($request);
+
+ $this->assertEquals('HTTP/1.1 201 Created', $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
+
+ $foo = $this->cardBackend->getCard('addressbook1','blabla.vcf');
+ $this->assertTrue(strpos($foo['carddata'],'UID')!==false);
+ }
+
+
+ function testCreateFileVCalendar() {
+
+ $request = new HTTP\Request(array(
+ 'REQUEST_METHOD' => 'PUT',
+ 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf',
+ ));
+ $request->setBody("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n");
+
+ $response = $this->request($request);
+
+ $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
+
+ }
+
+ function testUpdateFile() {
+
+ $this->cardBackend->createCard('addressbook1','blabla.vcf','foo');
+ $request = new HTTP\Request(array(
+ 'REQUEST_METHOD' => 'PUT',
+ 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf',
+ ));
+
+ $response = $this->request($request);
+
+ $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status);
+
+ }
+
+ function testUpdateFileParsableBody() {
+
+ $this->cardBackend->createCard('addressbook1','blabla.vcf','foo');
+ $request = new HTTP\Request(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);
+
+ $response = $this->request($request);
+
+ $this->assertEquals('HTTP/1.1 204 No Content', $response->status);
+
+ $expected = array(
+ 'uri' => 'blabla.vcf',
+ 'carddata' => $body,
+ );
+
+ $this->assertEquals($expected, $this->cardBackend->getCard('addressbook1','blabla.vcf'));
+
+ }
+}
+
+?>