From 3fd93f23f5f51eb381b257cfe1578da4c04850d1 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Mon, 20 Mar 2017 13:42:32 +0100 Subject: Add contacts menu integration Signed-off-by: Christoph Wurst --- .../ContactsMenu/Provider/DetailsProviderTest.php | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/unit/ContactsMenu/Provider/DetailsProviderTest.php (limited to 'tests') diff --git a/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php b/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php new file mode 100644 index 00000000..6e9871eb --- /dev/null +++ b/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php @@ -0,0 +1,91 @@ + + * + * @author 2017 Christoph Wurst + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see . + * + */ + +namespace Tests\Contacts\ContactsMenu\Providers; + +use OC\Contacts\ContactsMenu\Providers\DetailsProvider; +use OCP\Contacts\ContactsMenu\IActionFactory; +use OCP\Contacts\ContactsMenu\IEntry; +use OCP\Contacts\ContactsMenu\ILinkAction; +use OCP\IURLGenerator; +use PHPUnit_Framework_MockObject_MockObject; +use Test\TestCase; + +class DetailsProviderTest extends TestCase { + + /** @var IURLGenerator|PHPUnit_Framework_MockObject_MockObject */ + private $urlGenerator; + + /** @var IActionFactory|PHPUnit_Framework_MockObject_MockObject */ + private $actionFactory; + + /** @var DetailsProvider */ + private $provider; + + protected function setUp() { + parent::setUp(); + + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->actionFactory = $this->createMock(IActionFactory::class); + $this->provider = new DetailsProvider($this->urlGenerator, $this->actionFactory); + } + + public function testProcess() { + $entry = $this->createMock(IEntry::class); + $action = $this->createMock(ILinkAction::class); + + $entry->expects($this->once()) + ->method('getProperty') + ->with($this->equalTo('UID')) + ->willReturn('e3a71614-c602-4eb5-9994-47eec551542b'); + $this->urlGenerator->expects($this->once()) + ->method('getAbsoluteURL') + ->with('/index.php/apps/contacts') + ->willReturn('cloud.example.com/index.php/apps/contacts'); + $this->actionFactory->expects($this->once()) + ->method('newLinkAction') + ->with($this->equalTo('icon-info'), $this->equalTo('Details'), $this->equalTo('cloud.example.com/index.php/apps/contacts')) + ->willReturn($action); + $action->expects($this->once()) + ->method('setPriority') + ->with($this->equalTo(0)); + $entry->expects($this->once()) + ->method('addAction') + ->with($action); + + $this->provider->process($entry); + } + + public function testProcessNoUID() { + $entry = $this->createMock(IEntry::class); + + $entry->expects($this->once()) + ->method('getProperty') + ->with($this->equalTo('UID')) + ->willReturn(null); + + $this->provider->process($entry); + } + +} -- cgit v1.2.3 From 07f1bb1013f1427d14d4b4c3b93a7e4fce4a261f Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Tue, 11 Apr 2017 08:40:52 +0200 Subject: Ignore system contacts Signed-off-by: Christoph Wurst --- .../ContactsMenu/Provider/DetailsProviderTest.php | 31 +++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php b/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php index 6e9871eb..85f34cb4 100644 --- a/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php +++ b/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php @@ -24,15 +24,15 @@ namespace Tests\Contacts\ContactsMenu\Providers; -use OC\Contacts\ContactsMenu\Providers\DetailsProvider; +use OCA\Contacts\ContactsMenu\Providers\DetailsProvider; use OCP\Contacts\ContactsMenu\IActionFactory; use OCP\Contacts\ContactsMenu\IEntry; use OCP\Contacts\ContactsMenu\ILinkAction; use OCP\IURLGenerator; use PHPUnit_Framework_MockObject_MockObject; -use Test\TestCase; +use PHPUnit_Framework_TestCase; -class DetailsProviderTest extends TestCase { +class DetailsProviderTest extends PHPUnit_Framework_TestCase { /** @var IURLGenerator|PHPUnit_Framework_MockObject_MockObject */ private $urlGenerator; @@ -55,10 +55,12 @@ class DetailsProviderTest extends TestCase { $entry = $this->createMock(IEntry::class); $action = $this->createMock(ILinkAction::class); - $entry->expects($this->once()) + $entry->expects($this->exactly(2)) ->method('getProperty') - ->with($this->equalTo('UID')) - ->willReturn('e3a71614-c602-4eb5-9994-47eec551542b'); + ->will($this->returnValueMap([ + ['UID', 'e3a71614-c602-4eb5-9994-47eec551542b'], + ['isLocalSystemBook', null] + ])); $this->urlGenerator->expects($this->once()) ->method('getAbsoluteURL') ->with('/index.php/apps/contacts') @@ -79,11 +81,26 @@ class DetailsProviderTest extends TestCase { public function testProcessNoUID() { $entry = $this->createMock(IEntry::class); - $entry->expects($this->once()) ->method('getProperty') ->with($this->equalTo('UID')) ->willReturn(null); + $entry->expects($this->never()) + ->method('addAction'); + + $this->provider->process($entry); + } + + public function testProcessSystemContact() { + $entry = $this->createMock(IEntry::class); + $entry->expects($this->exactly(2)) + ->method('getProperty') + ->will($this->returnValueMap([ + ['UID', 1234], + ['isLocalSystemBook', true] + ])); + $entry->expects($this->never()) + ->method('addAction'); $this->provider->process($entry); } -- cgit v1.2.3 From a309d7c2802f654c5c13b76672620f438cffb9be Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Tue, 11 Apr 2017 09:22:46 +0200 Subject: Use absolute path for icon url Signed-off-by: Christoph Wurst --- .../ContactsMenu/Provider/DetailsProviderTest.php | 25 ++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php b/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php index 85f34cb4..26f00575 100644 --- a/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php +++ b/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php @@ -58,16 +58,23 @@ class DetailsProviderTest extends PHPUnit_Framework_TestCase { $entry->expects($this->exactly(2)) ->method('getProperty') ->will($this->returnValueMap([ - ['UID', 'e3a71614-c602-4eb5-9994-47eec551542b'], - ['isLocalSystemBook', null] - ])); + ['UID', 'e3a71614-c602-4eb5-9994-47eec551542b'], + ['isLocalSystemBook', null] + ])); $this->urlGenerator->expects($this->once()) + ->method('imagePath') + ->with('core', 'actions/info.svg') + ->willReturn('core/img/actions/info.svg'); + $iconUrl = 'https://example.com/core/img/actions/info.svg'; + $this->urlGenerator->expects($this->exactly(2)) ->method('getAbsoluteURL') - ->with('/index.php/apps/contacts') - ->willReturn('cloud.example.com/index.php/apps/contacts'); + ->will($this->returnValueMap([ + ['/index.php/apps/contacts', 'cloud.example.com/index.php/apps/contacts'], + ['core/img/actions/info.svg', $iconUrl], + ])); $this->actionFactory->expects($this->once()) ->method('newLinkAction') - ->with($this->equalTo('icon-info'), $this->equalTo('Details'), $this->equalTo('cloud.example.com/index.php/apps/contacts')) + ->with($this->equalTo($iconUrl), $this->equalTo('Details'), $this->equalTo('cloud.example.com/index.php/apps/contacts')) ->willReturn($action); $action->expects($this->once()) ->method('setPriority') @@ -96,9 +103,9 @@ class DetailsProviderTest extends PHPUnit_Framework_TestCase { $entry->expects($this->exactly(2)) ->method('getProperty') ->will($this->returnValueMap([ - ['UID', 1234], - ['isLocalSystemBook', true] - ])); + ['UID', 1234], + ['isLocalSystemBook', true] + ])); $entry->expects($this->never()) ->method('addAction'); -- cgit v1.2.3 From 026d509336775b9d6bf4c1d10849f03a2e9e5692 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Mon, 24 Apr 2017 11:31:49 +0200 Subject: Redirect from UID to GID+UID Signed-off-by: Christoph Wurst --- tests/unit/ContactsMenu/Provider/DetailsProviderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php b/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php index 26f00575..8ee73d87 100644 --- a/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php +++ b/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php @@ -69,12 +69,12 @@ class DetailsProviderTest extends PHPUnit_Framework_TestCase { $this->urlGenerator->expects($this->exactly(2)) ->method('getAbsoluteURL') ->will($this->returnValueMap([ - ['/index.php/apps/contacts', 'cloud.example.com/index.php/apps/contacts'], + ['/index.php/apps/contacts#/contact/e3a71614-c602-4eb5-9994-47eec551542b', 'cloud.example.com/index.php/apps/contacts#/contact/e3a71614-c602-4eb5-9994-47eec551542b'], ['core/img/actions/info.svg', $iconUrl], ])); $this->actionFactory->expects($this->once()) ->method('newLinkAction') - ->with($this->equalTo($iconUrl), $this->equalTo('Details'), $this->equalTo('cloud.example.com/index.php/apps/contacts')) + ->with($this->equalTo($iconUrl), $this->equalTo('Details'), $this->equalTo('cloud.example.com/index.php/apps/contacts#/contact/e3a71614-c602-4eb5-9994-47eec551542b')) ->willReturn($action); $action->expects($this->once()) ->method('setPriority') -- cgit v1.2.3 From 04f992654203050d28bf6f41ab8ac2ea1019d6b0 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Mon, 24 Apr 2017 11:35:18 +0200 Subject: Translate details action Signed-off-by: Christoph Wurst --- tests/unit/ContactsMenu/Provider/DetailsProviderTest.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php b/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php index 8ee73d87..d1945c3a 100644 --- a/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php +++ b/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php @@ -28,6 +28,7 @@ use OCA\Contacts\ContactsMenu\Providers\DetailsProvider; use OCP\Contacts\ContactsMenu\IActionFactory; use OCP\Contacts\ContactsMenu\IEntry; use OCP\Contacts\ContactsMenu\ILinkAction; +use OCP\IL10N; use OCP\IURLGenerator; use PHPUnit_Framework_MockObject_MockObject; use PHPUnit_Framework_TestCase; @@ -40,6 +41,9 @@ class DetailsProviderTest extends PHPUnit_Framework_TestCase { /** @var IActionFactory|PHPUnit_Framework_MockObject_MockObject */ private $actionFactory; + /** @var IL10n|PHPUnit_Framework_MockObject_MockObject */ + private $l10n; + /** @var DetailsProvider */ private $provider; @@ -48,7 +52,8 @@ class DetailsProviderTest extends PHPUnit_Framework_TestCase { $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->actionFactory = $this->createMock(IActionFactory::class); - $this->provider = new DetailsProvider($this->urlGenerator, $this->actionFactory); + $this->l10n = $this->createMock(IL10N::class); + $this->provider = new DetailsProvider($this->urlGenerator, $this->actionFactory, $this->l10n); } public function testProcess() { @@ -72,6 +77,10 @@ class DetailsProviderTest extends PHPUnit_Framework_TestCase { ['/index.php/apps/contacts#/contact/e3a71614-c602-4eb5-9994-47eec551542b', 'cloud.example.com/index.php/apps/contacts#/contact/e3a71614-c602-4eb5-9994-47eec551542b'], ['core/img/actions/info.svg', $iconUrl], ])); + $this->l10n->expects($this->once()) + ->method('t') + ->with('Details') + ->willReturnArgument(0); $this->actionFactory->expects($this->once()) ->method('newLinkAction') ->with($this->equalTo($iconUrl), $this->equalTo('Details'), $this->equalTo('cloud.example.com/index.php/apps/contacts#/contact/e3a71614-c602-4eb5-9994-47eec551542b')) -- cgit v1.2.3