aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/ContactsManagerTest.php
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2016-05-19 09:27:21 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2016-05-19 09:27:21 +0200
commit55fc6536d33bd044a72437ac61d3c5ade09111cb (patch)
treeee2f5dd35734d7f8fdba75b77d5cfb98444abeb7 /tests/lib/ContactsManagerTest.php
parent7f3f16d1554bd2adbe3287fbf09a1124664f54af (diff)
downloadnextcloud-server-55fc6536d33bd044a72437ac61d3c5ade09111cb.tar.gz
nextcloud-server-55fc6536d33bd044a72437ac61d3c5ade09111cb.zip
FIx lib/ a-d
Diffstat (limited to 'tests/lib/ContactsManagerTest.php')
-rw-r--r--tests/lib/ContactsManagerTest.php210
1 files changed, 210 insertions, 0 deletions
diff --git a/tests/lib/ContactsManagerTest.php b/tests/lib/ContactsManagerTest.php
new file mode 100644
index 00000000000..89a9cb95b97
--- /dev/null
+++ b/tests/lib/ContactsManagerTest.php
@@ -0,0 +1,210 @@
+<?php
+
+namespace Test;
+
+class ContactsManagerTest extends \Test\TestCase {
+
+ /** @var \OC\ContactsManager */
+ private $cm;
+
+ protected function setUp() {
+ parent::setUp();
+ $this->cm = new \OC\ContactsManager();
+ }
+
+ public function searchProvider(){
+ $search1 = array(
+ 0 => array(
+ 'N' => array(0 => '', 1 => 'Jan', 2 => 'Jansen', 3 => '', 4 => '',),
+ 'UID' => '04ada7f5-01f9-4309-9c82-6b555b2170ed',
+ 'FN' => 'Jan Jansen',
+ 'id' => '1',
+ 'addressbook-key' => 'simple:1',
+ ),
+ 0 => array(
+ 'N' => array(0 => '', 1 => 'Tom', 2 => 'Peeters', 3 => '', 4 => '',),
+ 'UID' => '04ada7f5-01f9-4309-9c82-2345-2345--6b555b2170ed',
+ 'FN' => 'Tom Peeters',
+ 'id' => '2',
+ 'addressbook-key' => 'simple:1',
+ ),
+ );
+
+ $search2 = array(
+ 0 => array(
+ 'N' => array(0 => '', 1 => 'fg', 2 => '', 3 => '', 4 => '',),
+ 'UID' => '04ada234h5jh357f5-01f9-4309-9c82-6b555b2170ed',
+ 'FN' => 'Jan Rompuy',
+ 'id' => '1',
+ 'addressbook-key' => 'simple:2',
+ ),
+ 0 => array(
+ 'N' => array(0 => '', 1 => 'fg', 2 => '', 3 => '', 4 => '',),
+ 'UID' => '04ada7f5-01f9-4309-345kj345j9c82-2345-2345--6b555b2170ed',
+ 'FN' => 'Tim Peeters',
+ 'id' => '2',
+ 'addressbook-key' => 'simple:2',
+ ),
+ );
+
+ $expectedResult = array_merge($search1, $search2);
+ return array(
+ array(
+ $search1,
+ $search2,
+ $expectedResult
+ )
+ );
+ }
+
+ /**
+ * @dataProvider searchProvider
+ */
+ public function testSearch($search1, $search2, $expectedResult ){
+ $addressbook1 = $this->getMockBuilder('\OCP\IAddressBook')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $addressbook1->expects($this->once())
+ ->method('search')
+ ->willReturn($search1);
+
+ $addressbook1->expects($this->any())
+ ->method('getKey')
+ ->willReturn('simple:1');
+
+ $addressbook2 = $this->getMockBuilder('\OCP\IAddressBook')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $addressbook2->expects($this->once())
+ ->method('search')
+ ->willReturn($search2);
+
+ $addressbook2->expects($this->any())
+ ->method('getKey')
+ ->willReturn('simple:2');
+
+
+ $this->cm->registerAddressBook($addressbook1);
+ $this->cm->registerAddressBook($addressbook2);
+ $result = $this->cm->search('');
+ $this->assertEquals($expectedResult, $result);
+ }
+
+
+ public function testDeleteHavePermission(){
+ $addressbook = $this->getMockBuilder('\OCP\IAddressBook')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $addressbook->expects($this->any())
+ ->method('getPermissions')
+ ->willReturn(\OCP\Constants::PERMISSION_ALL);
+
+ $addressbook->expects($this->once())
+ ->method('delete')
+ ->willReturn('returnMe');
+
+
+ $this->cm->registerAddressBook($addressbook);
+ $result = $this->cm->delete(1, $addressbook->getKey());
+ $this->assertEquals($result, 'returnMe');
+ }
+
+ public function testDeleteNoPermission(){
+ $addressbook = $this->getMockBuilder('\OCP\IAddressBook')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $addressbook->expects($this->any())
+ ->method('getPermissions')
+ ->willReturn(\OCP\Constants::PERMISSION_READ);
+
+ $addressbook->expects($this->never())
+ ->method('delete');
+
+ $this->cm->registerAddressBook($addressbook);
+ $result = $this->cm->delete(1, $addressbook->getKey());
+ $this->assertEquals($result, null);
+ }
+
+ public function testDeleteNoAddressbook(){
+ $addressbook = $this->getMockBuilder('\OCP\IAddressBook')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $addressbook->expects($this->never())
+ ->method('delete');
+
+ $this->cm->registerAddressBook($addressbook);
+ $result = $this->cm->delete(1, 'noaddressbook');
+ $this->assertEquals($result, null);
+
+ }
+
+ public function testCreateOrUpdateHavePermission(){
+ $addressbook = $this->getMockBuilder('\OCP\IAddressBook')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $addressbook->expects($this->any())
+ ->method('getPermissions')
+ ->willReturn(\OCP\Constants::PERMISSION_ALL);
+
+ $addressbook->expects($this->once())
+ ->method('createOrUpdate')
+ ->willReturn('returnMe');
+
+ $this->cm->registerAddressBook($addressbook);
+ $result = $this->cm->createOrUpdate(array(), $addressbook->getKey());
+ $this->assertEquals($result, 'returnMe');
+ }
+
+ public function testCreateOrUpdateNoPermission(){
+ $addressbook = $this->getMockBuilder('\OCP\IAddressBook')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $addressbook->expects($this->any())
+ ->method('getPermissions')
+ ->willReturn(\OCP\Constants::PERMISSION_READ);
+
+ $addressbook->expects($this->never())
+ ->method('createOrUpdate');
+
+ $this->cm->registerAddressBook($addressbook);
+ $result = $this->cm->createOrUpdate(array(), $addressbook->getKey());
+ $this->assertEquals($result, null);
+
+ }
+
+ public function testCreateOrUpdateNOAdressbook(){
+ $addressbook = $this->getMockBuilder('\OCP\IAddressBook')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $addressbook->expects($this->never())
+ ->method('createOrUpdate');
+
+ $this->cm->registerAddressBook($addressbook);
+ $result = $this->cm->createOrUpdate(array(), 'noaddressbook');
+ $this->assertEquals($result, null);
+ }
+
+ public function testIsEnabledIfNot(){
+ $result = $this->cm->isEnabled();
+ $this->assertFalse($result);
+ }
+
+ public function testIsEnabledIfSo(){
+ $addressbook = $this->getMockBuilder('\OCP\IAddressBook')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->cm->registerAddressBook($addressbook);
+ $result = $this->cm->isEnabled();
+ $this->assertTrue($result);
+ }
+
+}