diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-10-30 16:05:25 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-06 15:26:51 +0100 |
commit | d8e965e59ad139c3f07f300344c7ab415cfbc901 (patch) | |
tree | 4f6021f5086a50a72a4df45091cae0f7811554e1 /apps/dav/tests | |
parent | 82f8374f63967d3f3d0000b9819a794f0183f889 (diff) | |
download | nextcloud-server-d8e965e59ad139c3f07f300344c7ab415cfbc901.tar.gz nextcloud-server-d8e965e59ad139c3f07f300344c7ab415cfbc901.zip |
Introducing CardDAV into core
Diffstat (limited to 'apps/dav/tests')
17 files changed, 206 insertions, 22 deletions
diff --git a/apps/dav/tests/unit/carddav/carddavbackendtest.php b/apps/dav/tests/unit/carddav/carddavbackendtest.php new file mode 100644 index 00000000000..f7456e9634c --- /dev/null +++ b/apps/dav/tests/unit/carddav/carddavbackendtest.php @@ -0,0 +1,180 @@ +<?php +/** + * @author Lukas Reschke <lukas@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\DAV\Tests\Unit\CardDAV; + +use OCA\DAV\CardDAV\CardDavBackend; +use Sabre\DAV\PropPatch; +use Test\TestCase; + +class CardDavBackendTest extends TestCase { + + /** @var CardDavBackend */ + private $backend; + + const UNIT_TEST_USER = 'carddav-unit-test'; + + + public function setUp() { + parent::setUp(); + + $db = \OC::$server->getDatabaseConnection(); + $this->backend = new CardDavBackend($db); + + $this->tearDown(); + } + + public function tearDown() { + parent::tearDown(); + + if (is_null($this->backend)) { + return; + } + $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER); + foreach ($books as $book) { + $this->backend->deleteAddressBook($book['id']); + } + } + + public function testAddressBookOperations() { + + // create a new address book + $this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []); + + $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER); + $this->assertEquals(1, count($books)); + + // update it's display name + $patch = new PropPatch([ + '{DAV:}displayname' => 'Unit test', + '{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'Addressbook used for unit testing' + ]); + $this->backend->updateAddressBook($books[0]['id'], $patch); + $patch->commit(); + $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER); + $this->assertEquals(1, count($books)); + $this->assertEquals('Unit test', $books[0]['{DAV:}displayname']); + $this->assertEquals('Addressbook used for unit testing', $books[0]['{urn:ietf:params:xml:ns:carddav}addressbook-description']); + + // delete the address book + $this->backend->deleteAddressBook($books[0]['id']); + $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER); + $this->assertEquals(0, count($books)); + } + + public function testCardOperations() { + // create a new address book + $this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []); + $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER); + $this->assertEquals(1, count($books)); + $bookId = $books[0]['id']; + + // create a card + $uri = $this->getUniqueID('card'); + $this->backend->createCard($bookId, $uri, ''); + + // get all the cards + $cards = $this->backend->getCards($bookId); + $this->assertEquals(1, count($cards)); + $this->assertEquals('', $cards[0]['carddata']); + + // get the cards + $card = $this->backend->getCard($bookId, $uri); + $this->assertNotNull($card); + $this->assertArrayHasKey('id', $card); + $this->assertArrayHasKey('uri', $card); + $this->assertArrayHasKey('lastmodified', $card); + $this->assertArrayHasKey('etag', $card); + $this->assertArrayHasKey('size', $card); + $this->assertEquals('', $card['carddata']); + + // update the card + $this->backend->updateCard($bookId, $uri, '***'); + $card = $this->backend->getCard($bookId, $uri); + $this->assertEquals('***', $card['carddata']); + + // delete the card + $this->backend->deleteCard($bookId, $uri); + $cards = $this->backend->getCards($bookId); + $this->assertEquals(0, count($cards)); + } + + public function testMultiCard() { + // create a new address book + $this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []); + $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER); + $this->assertEquals(1, count($books)); + $bookId = $books[0]['id']; + + // create a card + $uri0 = $this->getUniqueID('card'); + $this->backend->createCard($bookId, $uri0, ''); + $uri1 = $this->getUniqueID('card'); + $this->backend->createCard($bookId, $uri1, ''); + $uri2 = $this->getUniqueID('card'); + $this->backend->createCard($bookId, $uri2, ''); + + // get all the cards + $cards = $this->backend->getCards($bookId); + $this->assertEquals(3, count($cards)); + $this->assertEquals('', $cards[0]['carddata']); + $this->assertEquals('', $cards[1]['carddata']); + $this->assertEquals('', $cards[2]['carddata']); + + // get the cards + $cards = $this->backend->getMultipleCards($bookId, [$uri1, $uri2]); + $this->assertEquals(2, count($cards)); + foreach($cards as $card) { + $this->assertArrayHasKey('id', $card); + $this->assertArrayHasKey('uri', $card); + $this->assertArrayHasKey('lastmodified', $card); + $this->assertArrayHasKey('etag', $card); + $this->assertArrayHasKey('size', $card); + $this->assertEquals('', $card['carddata']); + } + + // delete the card + $this->backend->deleteCard($bookId, $uri0); + $this->backend->deleteCard($bookId, $uri1); + $this->backend->deleteCard($bookId, $uri2); + $cards = $this->backend->getCards($bookId); + $this->assertEquals(0, count($cards)); + } + + public function testSyncSupport() { + // create a new address book + $this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []); + $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER); + $this->assertEquals(1, count($books)); + $bookId = $books[0]['id']; + + // fist call without synctoken + $changes = $this->backend->getChangesForAddressBook($bookId, '', 1); + $syncToken = $changes['syncToken']; + + // add a change + $uri0 = $this->getUniqueID('card'); + $this->backend->createCard($bookId, $uri0, ''); + + // look for changes + $changes = $this->backend->getChangesForAddressBook($bookId, $syncToken, 1); + $this->assertEquals($uri0, $changes['added'][0]); + } +} diff --git a/apps/dav/tests/unit/connector/sabre/BlockLegacyClientPluginTest.php b/apps/dav/tests/unit/connector/sabre/BlockLegacyClientPluginTest.php index 1e390cf15f7..3004c03b266 100644 --- a/apps/dav/tests/unit/connector/sabre/BlockLegacyClientPluginTest.php +++ b/apps/dav/tests/unit/connector/sabre/BlockLegacyClientPluginTest.php @@ -19,7 +19,7 @@ * */ -namespace Test\Connector\Sabre; +namespace OCA\DAV\Tests\Unit\Connector\Sabre; use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin; use Test\TestCase; diff --git a/apps/dav/tests/unit/connector/sabre/DummyGetResponsePluginTest.php b/apps/dav/tests/unit/connector/sabre/DummyGetResponsePluginTest.php index 1fd89c84ff6..d2d4a849a51 100644 --- a/apps/dav/tests/unit/connector/sabre/DummyGetResponsePluginTest.php +++ b/apps/dav/tests/unit/connector/sabre/DummyGetResponsePluginTest.php @@ -19,7 +19,7 @@ * */ -namespace Test\Connector\Sabre; +namespace OCA\DAV\Tests\Unit\Connector\Sabre; use OCA\DAV\Connector\Sabre\DummyGetResponsePlugin; use Test\TestCase; diff --git a/apps/dav/tests/unit/connector/sabre/MaintenancePluginTest.php b/apps/dav/tests/unit/connector/sabre/MaintenancePluginTest.php index c0acd4fc3de..34fa7f7eef9 100644 --- a/apps/dav/tests/unit/connector/sabre/MaintenancePluginTest.php +++ b/apps/dav/tests/unit/connector/sabre/MaintenancePluginTest.php @@ -19,7 +19,7 @@ * */ -namespace Test\Connector\Sabre; +namespace OCA\DAV\Tests\Unit\Connector\Sabre; use OCA\DAV\Connector\Sabre\MaintenancePlugin; use Test\TestCase; diff --git a/apps/dav/tests/unit/connector/sabre/auth.php b/apps/dav/tests/unit/connector/sabre/auth.php index 0466f3aab77..d18747d732a 100644 --- a/apps/dav/tests/unit/connector/sabre/auth.php +++ b/apps/dav/tests/unit/connector/sabre/auth.php @@ -18,7 +18,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ -namespace Tests\Connector\Sabre; + +namespace OCA\DAV\Tests\Unit\Connector\Sabre; use Test\TestCase; use OCP\ISession; diff --git a/apps/dav/tests/unit/connector/sabre/copyetagheaderplugintest.php b/apps/dav/tests/unit/connector/sabre/copyetagheaderplugintest.php index 2080755cd51..74dd4edd8cf 100644 --- a/apps/dav/tests/unit/connector/sabre/copyetagheaderplugintest.php +++ b/apps/dav/tests/unit/connector/sabre/copyetagheaderplugintest.php @@ -1,6 +1,6 @@ <?php -namespace Tests\Connector\Sabre; +namespace OCA\DAV\Tests\Unit\Connector\Sabre; /** * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com> diff --git a/apps/dav/tests/unit/connector/sabre/custompropertiesbackend.php b/apps/dav/tests/unit/connector/sabre/custompropertiesbackend.php index 973a5d4c27b..e1bcc996908 100644 --- a/apps/dav/tests/unit/connector/sabre/custompropertiesbackend.php +++ b/apps/dav/tests/unit/connector/sabre/custompropertiesbackend.php @@ -1,6 +1,6 @@ <?php -namespace Tests\Connector\Sabre; +namespace OCA\DAV\Tests\Unit\Connector\Sabre; /** * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com> @@ -16,7 +16,7 @@ class CustomPropertiesBackend extends \Test\TestCase { private $server; /** - * @var \Sabre\DAV\ObjectTree + * @var \Sabre\DAV\Tree */ private $tree; diff --git a/apps/dav/tests/unit/connector/sabre/directory.php b/apps/dav/tests/unit/connector/sabre/directory.php index d85290df80a..148a91d26db 100644 --- a/apps/dav/tests/unit/connector/sabre/directory.php +++ b/apps/dav/tests/unit/connector/sabre/directory.php @@ -6,11 +6,14 @@ * later. * See the COPYING-README file. */ -class Test_OC_Connector_Sabre_Directory extends \Test\TestCase { - /** @var OC\Files\View | PHPUnit_Framework_MockObject_MockObject */ +namespace OCA\DAV\Tests\Unit\Connector\Sabre; + +class Directory extends \Test\TestCase { + + /** @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject */ private $view; - /** @var OC\Files\FileInfo | PHPUnit_Framework_MockObject_MockObject */ + /** @var \OC\Files\FileInfo | \PHPUnit_Framework_MockObject_MockObject */ private $info; protected function setUp() { diff --git a/apps/dav/tests/unit/connector/sabre/exception/invalidpathtest.php b/apps/dav/tests/unit/connector/sabre/exception/invalidpathtest.php index 4c0af58ffea..19e82320d55 100644 --- a/apps/dav/tests/unit/connector/sabre/exception/invalidpathtest.php +++ b/apps/dav/tests/unit/connector/sabre/exception/invalidpathtest.php @@ -1,6 +1,6 @@ <?php -namespace Test\Connector\Sabre\Exception; +namespace OCA\DAV\Tests\Unit\Connector\Sabre\Exception; use OCA\DAV\Connector\Sabre\Exception\InvalidPath; diff --git a/apps/dav/tests/unit/connector/sabre/exceptionloggerplugin.php b/apps/dav/tests/unit/connector/sabre/exceptionloggerplugin.php index d85aa5a9cc3..0c364df012b 100644 --- a/apps/dav/tests/unit/connector/sabre/exceptionloggerplugin.php +++ b/apps/dav/tests/unit/connector/sabre/exceptionloggerplugin.php @@ -7,7 +7,7 @@ * See the COPYING-README file. */ -namespace Test\Connector\Sabre; +namespace OCA\DAV\Tests\Unit\Connector\Sabre; use OCA\DAV\Connector\Sabre\Exception\InvalidPath; use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin as PluginToTest; diff --git a/apps/dav/tests/unit/connector/sabre/file.php b/apps/dav/tests/unit/connector/sabre/file.php index d874b7f33c2..94dadf88fe4 100644 --- a/apps/dav/tests/unit/connector/sabre/file.php +++ b/apps/dav/tests/unit/connector/sabre/file.php @@ -6,7 +6,7 @@ * See the COPYING-README file. */ -namespace Test\Connector\Sabre; +namespace OCA\DAV\Tests\Unit\Connector\Sabre; use OC\Files\Storage\Local; use Test\HookHelper; diff --git a/apps/dav/tests/unit/connector/sabre/filesplugin.php b/apps/dav/tests/unit/connector/sabre/filesplugin.php index db3bbabefd0..f3c862941c0 100644 --- a/apps/dav/tests/unit/connector/sabre/filesplugin.php +++ b/apps/dav/tests/unit/connector/sabre/filesplugin.php @@ -1,6 +1,6 @@ <?php -namespace Tests\Connector\Sabre; +namespace OCA\DAV\Tests\Unit\Connector\Sabre; /** * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com> diff --git a/apps/dav/tests/unit/connector/sabre/node.php b/apps/dav/tests/unit/connector/sabre/node.php index a9610fd84b3..cee64fb7dff 100644 --- a/apps/dav/tests/unit/connector/sabre/node.php +++ b/apps/dav/tests/unit/connector/sabre/node.php @@ -7,7 +7,7 @@ * See the COPYING-README file. */ -namespace Test\Connector\Sabre; +namespace OCA\DAV\Tests\Unit\Connector\Sabre; class Node extends \Test\TestCase { public function davPermissionsProvider() { diff --git a/apps/dav/tests/unit/connector/sabre/objecttree.php b/apps/dav/tests/unit/connector/sabre/objecttree.php index 2691385c1c1..3a56404e552 100644 --- a/apps/dav/tests/unit/connector/sabre/objecttree.php +++ b/apps/dav/tests/unit/connector/sabre/objecttree.php @@ -6,11 +6,10 @@ * See the COPYING-README file. */ -namespace Test\OCA\DAV\Connector\Sabre; +namespace OCA\DAV\Tests\Unit\Connector\Sabre; use OC\Files\FileInfo; -use OCA\DAV\Connector\Sabre\Directory; use OC\Files\Storage\Temporary; class TestDoubleFileView extends \OC\Files\View { @@ -103,7 +102,7 @@ class ObjectTree extends \Test\TestCase { $info = new FileInfo('', null, null, array(), null); - $rootDir = new Directory($view, $info); + $rootDir = new \OCA\DAV\Connector\Sabre\Directory($view, $info); $objectTree = $this->getMock('\OCA\DAV\Connector\Sabre\ObjectTree', array('nodeExists', 'getNodeForPath'), array($rootDir, $view)); diff --git a/apps/dav/tests/unit/connector/sabre/principal.php b/apps/dav/tests/unit/connector/sabre/principal.php index 3c0abeac3f1..2fbab124fb7 100644 --- a/apps/dav/tests/unit/connector/sabre/principal.php +++ b/apps/dav/tests/unit/connector/sabre/principal.php @@ -8,7 +8,7 @@ * See the COPYING-README file. */ -namespace Test\Connector\Sabre; +namespace OCA\DAV\Tests\Unit\Connector\Sabre; use \Sabre\DAV\PropPatch; use OCP\IUserManager; diff --git a/apps/dav/tests/unit/connector/sabre/quotaplugin.php b/apps/dav/tests/unit/connector/sabre/quotaplugin.php index 5d3364e1f8c..470fd9cbf85 100644 --- a/apps/dav/tests/unit/connector/sabre/quotaplugin.php +++ b/apps/dav/tests/unit/connector/sabre/quotaplugin.php @@ -1,12 +1,13 @@ <?php +namespace OCA\DAV\Tests\Unit\Connector\Sabre; /** * Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ -class Test_OC_Connector_Sabre_QuotaPlugin extends \Test\TestCase { +class QuotaPlugin extends \Test\TestCase { /** * @var \Sabre\DAV\Server diff --git a/apps/dav/tests/unit/connector/sabre/tagsplugin.php b/apps/dav/tests/unit/connector/sabre/tagsplugin.php index 4731e770cfa..f1f6cc40dab 100644 --- a/apps/dav/tests/unit/connector/sabre/tagsplugin.php +++ b/apps/dav/tests/unit/connector/sabre/tagsplugin.php @@ -1,6 +1,6 @@ <?php -namespace Tests\Connector\Sabre; +namespace OCA\DAV\Tests\Unit\Connector\Sabre; /** * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com> @@ -20,7 +20,7 @@ class TagsPlugin extends \Test\TestCase { private $server; /** - * @var \Sabre\DAV\ObjectTree + * @var \Sabre\DAV\Tree */ private $tree; |