summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2014-12-19 13:28:11 +0100
committerMorris Jobke <hey@morrisjobke.de>2015-01-05 09:54:12 +0100
commit556c9b6f460d462ff22f886ff678d4d4299b871c (patch)
tree11c95ab5d0cf3fbec7c4c5194eafe67a306177aa /tests
parentf2ddd565e843e7bccd24c10a45a30f9056bf24e3 (diff)
downloadnextcloud-server-556c9b6f460d462ff22f886ff678d4d4299b871c.tar.gz
nextcloud-server-556c9b6f460d462ff22f886ff678d4d4299b871c.zip
Write unit-tests and use DI
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/connector/sabre/principal.php247
1 files changed, 247 insertions, 0 deletions
diff --git a/tests/lib/connector/sabre/principal.php b/tests/lib/connector/sabre/principal.php
new file mode 100644
index 00000000000..77edf0113ba
--- /dev/null
+++ b/tests/lib/connector/sabre/principal.php
@@ -0,0 +1,247 @@
+<?php
+/**
+ * @author Lukas Reschke
+ * @copyright 2014 Lukas Reschke lukas@owncloud.com
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+use OCP\IUserManager;
+use OCP\IConfig;
+
+class Test_OC_Connector_Sabre_Principal extends \Test\TestCase {
+ /** @var IUserManager */
+ private $userManager;
+ /** @var IConfig */
+ private $config;
+ /** @var OC_Connector_Sabre_Principal */
+ private $connector;
+
+ public function setUp() {
+ $this->userManager = $this->getMockBuilder('\OCP\IUserManager')
+ ->disableOriginalConstructor()->getMock();
+ $this->config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()->getMock();
+
+ $this->connector = new OC_Connector_Sabre_Principal($this->config, $this->userManager);
+ parent::setUp();
+ }
+
+ public function testGetPrincipalsByPrefixWithoutPrefix() {
+ $response = $this->connector->getPrincipalsByPrefix('');
+ $this->assertSame([], $response);
+ }
+
+ public function testGetPrincipalsByPrefixWithUsers() {
+ $fooUser = $this->getMockBuilder('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $fooUser
+ ->expects($this->exactly(3))
+ ->method('getUID')
+ ->will($this->returnValue('foo'));
+ $barUser = $this->getMockBuilder('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $barUser
+ ->expects($this->exactly(3))
+ ->method('getUID')
+ ->will($this->returnValue('bar'));
+ $this->userManager
+ ->expects($this->once())
+ ->method('search')
+ ->with('')
+ ->will($this->returnValue([$fooUser, $barUser]));
+ $this->config
+ ->expects($this->at(0))
+ ->method('getUserValue')
+ ->with('foo', 'settings', 'email')
+ ->will($this->returnValue(''));
+ $this->config
+ ->expects($this->at(1))
+ ->method('getUserValue')
+ ->with('bar', 'settings', 'email')
+ ->will($this->returnValue('bar@owncloud.org'));
+
+ $expectedResponse = [
+ 0 => [
+ 'uri' => 'principals/foo',
+ '{DAV:}displayname' => 'foo'
+ ],
+ 1 => [
+ 'uri' => 'principals/bar',
+ '{DAV:}displayname' => 'bar',
+ '{http://sabredav.org/ns}email-address' => 'bar@owncloud.org'
+ ]
+ ];
+ $response = $this->connector->getPrincipalsByPrefix('principals');
+ $this->assertSame($expectedResponse, $response);
+ }
+
+ public function testGetPrincipalsByPrefixEmpty() {
+ $this->userManager
+ ->expects($this->once())
+ ->method('search')
+ ->with('')
+ ->will($this->returnValue([]));
+
+ $response = $this->connector->getPrincipalsByPrefix('principals');
+ $this->assertSame([], $response);
+ }
+
+ public function testGetPrincipalsByPathWithoutMail() {
+ $fooUser = $this->getMockBuilder('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $fooUser
+ ->expects($this->exactly(3))
+ ->method('getUID')
+ ->will($this->returnValue('foo'));
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('foo')
+ ->will($this->returnValue($fooUser));
+ $this->config
+ ->expects($this->once())
+ ->method('getUserValue')
+ ->with('foo', 'settings', 'email')
+ ->will($this->returnValue(''));
+
+ $expectedResponse = [
+ 'uri' => 'principals/foo',
+ '{DAV:}displayname' => 'foo'
+ ];
+ $response = $this->connector->getPrincipalByPath('principals/foo');
+ $this->assertSame($expectedResponse, $response);
+ }
+
+ public function testGetPrincipalsByPathWithMail() {
+ $fooUser = $this->getMockBuilder('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $fooUser
+ ->expects($this->exactly(3))
+ ->method('getUID')
+ ->will($this->returnValue('foo'));
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('foo')
+ ->will($this->returnValue($fooUser));
+ $this->config
+ ->expects($this->once())
+ ->method('getUserValue')
+ ->with('foo', 'settings', 'email')
+ ->will($this->returnValue('foo@owncloud.org'));
+
+ $expectedResponse = [
+ 'uri' => 'principals/foo',
+ '{DAV:}displayname' => 'foo',
+ '{http://sabredav.org/ns}email-address' => 'foo@owncloud.org'
+ ];
+ $response = $this->connector->getPrincipalByPath('principals/foo');
+ $this->assertSame($expectedResponse, $response);
+ }
+
+ public function testGetPrincipalsByPathEmpty() {
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('foo')
+ ->will($this->returnValue(null));
+
+ $response = $this->connector->getPrincipalByPath('principals/foo');
+ $this->assertSame(null, $response);
+ }
+
+ public function testGetGroupMemberSet() {
+ $fooUser = $this->getMockBuilder('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $fooUser
+ ->expects($this->exactly(3))
+ ->method('getUID')
+ ->will($this->returnValue('foo'));
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('foo')
+ ->will($this->returnValue($fooUser));
+ $this->config
+ ->expects($this->once())
+ ->method('getUserValue')
+ ->with('foo', 'settings', 'email')
+ ->will($this->returnValue('foo@owncloud.org'));
+
+ $response = $this->connector->getGroupMemberSet('principals/foo');
+ $this->assertSame(['principals/foo'], $response);
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception
+ * @expectedExceptionMessage Principal not found
+ */
+ public function testGetGroupMemberSetEmpty() {
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('foo')
+ ->will($this->returnValue(null));
+
+ $this->connector->getGroupMemberSet('principals/foo');
+ }
+
+ public function testGetGroupMembership() {
+ $fooUser = $this->getMockBuilder('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $fooUser
+ ->expects($this->exactly(3))
+ ->method('getUID')
+ ->will($this->returnValue('foo'));
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('foo')
+ ->will($this->returnValue($fooUser));
+ $this->config
+ ->expects($this->once())
+ ->method('getUserValue')
+ ->with('foo', 'settings', 'email')
+ ->will($this->returnValue('foo@owncloud.org'));
+
+ $expectedResponse = [
+ 'principals/foo/calendar-proxy-read',
+ 'principals/foo/calendar-proxy-write'
+ ];
+ $response = $this->connector->getGroupMembership('principals/foo');
+ $this->assertSame($expectedResponse, $response);
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception
+ * @expectedExceptionMessage Principal not found
+ */
+ public function testGetGroupMembershipEmpty() {
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('foo')
+ ->will($this->returnValue(null));
+
+ $this->connector->getGroupMembership('principals/foo');
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception
+ * @expectedExceptionMessage Setting members of the group is not supported yet
+ */
+ public function testSetGroupMembership() {
+ $this->connector->setGroupMemberSet('principals/foo', ['foo']);
+ }
+
+ public function testUpdatePrincipal() {
+ $this->assertSame(0, $this->connector->updatePrincipal('foo', []));
+ }
+
+ public function testSearchPrincipals() {
+ $this->assertSame([], $this->connector->searchPrincipals('principals', []));
+ }
+}