diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2017-04-03 18:04:14 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2017-04-25 20:47:17 +0200 |
commit | 36cee1f3867bdaf9fd792fe9c03fe4e4ef95ffcc (patch) | |
tree | 6d466d8c99b406f6ffb2037ef5b6afc46a136691 /tests | |
parent | 5762cd94369acde40cdc40834f5df5f85150e8a3 (diff) | |
download | nextcloud-server-36cee1f3867bdaf9fd792fe9c03fe4e4ef95ffcc.tar.gz nextcloud-server-36cee1f3867bdaf9fd792fe9c03fe4e4ef95ffcc.zip |
Let apps register contact menu provider via info.xml
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Controller/ContactsMenuControllerTest.php | 16 | ||||
-rw-r--r-- | tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php | 66 | ||||
-rw-r--r-- | tests/lib/Contacts/ContactsMenu/ManagerTest.php | 4 |
3 files changed, 73 insertions, 13 deletions
diff --git a/tests/Core/Controller/ContactsMenuControllerTest.php b/tests/Core/Controller/ContactsMenuControllerTest.php index 2483d5e94c3..bf6188e9097 100644 --- a/tests/Core/Controller/ContactsMenuControllerTest.php +++ b/tests/Core/Controller/ContactsMenuControllerTest.php @@ -28,6 +28,8 @@ use OC\Contacts\ContactsMenu\Manager; use OC\Core\Controller\ContactsMenuController; use OCP\Contacts\ContactsMenu\IEntry; use OCP\IRequest; +use OCP\IUser; +use OCP\IUserSession; use PHPUnit_Framework_MockObject_MockObject; use Test\TestCase; @@ -36,8 +38,8 @@ class ContactsMenuControllerTest extends TestCase { /** @var IRequest|PHPUnit_Framework_MockObject_MockObject */ private $request; - /** @var string */ - private $userId; + /** @var IUserSession|PHPUnit_Framework_MockObject_MockObject */ + private $userSession; /** @var Manager|PHPUnit_Framework_MockObject_MockObject */ private $contactsManager; @@ -49,20 +51,24 @@ class ContactsMenuControllerTest extends TestCase { parent::setUp(); $this->request = $this->createMock(IRequest::class); - $this->userId = 'user4563'; + $this->userSession = $this->createMock(IUserSession::class); $this->contactsManager = $this->createMock(Manager::class); - $this->controller = new ContactsMenuController($this->request, $this->userId, $this->contactsManager); + $this->controller = new ContactsMenuController($this->request, $this->userSession, $this->contactsManager); } public function testIndex() { + $user = $this->createMock(IUser::class); $entries = [ $this->createMock(IEntry::class), $this->createMock(IEntry::class), ]; + $this->userSession->expects($this->once()) + ->method('getUser') + ->willReturn($user); $this->contactsManager->expects($this->once()) ->method('getEntries') - ->with($this->equalTo($this->userId), $this->equalTo(null)) + ->with($this->equalTo($user), $this->equalTo(null)) ->willReturn($entries); $response = $this->controller->index(); diff --git a/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php b/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php index 208ce94c6b0..8738e19b513 100644 --- a/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php +++ b/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php @@ -25,11 +25,15 @@ namespace Tests\Contacts\ContactsMenu; use Exception; +use OC\App\AppManager; use OC\Contacts\ContactsMenu\ActionProviderStore; use OC\Contacts\ContactsMenu\Providers\EMailProvider; +use OCP\App\IAppManager; use OCP\AppFramework\QueryException; +use OCP\Contacts\ContactsMenu\IProvider; use OCP\ILogger; use OCP\IServerContainer; +use OCP\IUser; use PHPUnit_Framework_MockObject_MockObject; use Test\TestCase; @@ -38,6 +42,9 @@ class ActionProviderStoreTest extends TestCase { /** @var IServerContainer|PHPUnit_Framework_MockObject_MockObject */ private $serverContainer; + /** @var IAppManager|PHPUnit_Framework_MockObject_MockObject */ + private $appManager; + /** @var ILogger|PHPUnit_Framework_MockObject_MockObject */ private $logger; @@ -48,19 +55,61 @@ class ActionProviderStoreTest extends TestCase { parent::setUp(); $this->serverContainer = $this->createMock(IServerContainer::class); + $this->appManager = $this->createMock(AppManager::class); $this->logger = $this->createMock(ILogger::class); - $this->actionProviderStore = new ActionProviderStore($this->serverContainer, $this->logger); + + $this->actionProviderStore = new ActionProviderStore($this->serverContainer, $this->appManager, $this->logger); } public function testGetProviders() { - $emailProvider = $this->createMock(EMailProvider::class); + $user = $this->createMock(IUser::class); + $provider1 = $this->createMock(EMailProvider::class); + $provider2 = $this->createMock(IProvider::class); + + $this->appManager->expects($this->once()) + ->method('getEnabledAppsForUser') + ->with($user) + ->willReturn(['contacts']); + $this->appManager->expects($this->once()) + ->method('getAppInfo') + ->with('contacts') + ->willReturn([ + 'contactsmenu' => [ + 'OCA\Contacts\Provider1', + ], + ]); $this->serverContainer->expects($this->exactly(2)) ->method('query') ->will($this->returnValueMap([ - [EMailProvider::class, $emailProvider], + [EMailProvider::class, $provider1], + ['OCA\Contacts\Provider1', $provider2] + ])); + + $providers = $this->actionProviderStore->getProviders($user); + + $this->assertCount(2, $providers); + $this->assertInstanceOf(EMailProvider::class, $providers[0]); + } + + public function testGetProvidersOfAppWithIncompleInfo() { + $user = $this->createMock(IUser::class); + $provider1 = $this->createMock(EMailProvider::class); + + $this->appManager->expects($this->once()) + ->method('getEnabledAppsForUser') + ->with($user) + ->willReturn(['contacts']); + $this->appManager->expects($this->once()) + ->method('getAppInfo') + ->with('contacts') + ->willReturn([/* Empty info.xml */]); + $this->serverContainer->expects($this->once()) + ->method('query') + ->will($this->returnValueMap([ + [EMailProvider::class, $provider1], ])); - $providers = $this->actionProviderStore->getProviders(); + $providers = $this->actionProviderStore->getProviders($user); $this->assertCount(1, $providers); $this->assertInstanceOf(EMailProvider::class, $providers[0]); @@ -70,13 +119,16 @@ class ActionProviderStoreTest extends TestCase { * @expectedException Exception */ public function testGetProvidersWithQueryException() { - $emailProvider = $this->createMock(EMailProvider::class); - $detailsProvider = $this->createMock(DetailsProvider::class); + $user = $this->createMock(IUser::class); + $this->appManager->expects($this->once()) + ->method('getEnabledAppsForUser') + ->with($user) + ->willReturn([]); $this->serverContainer->expects($this->once()) ->method('query') ->willThrowException(new QueryException()); - $providers = $this->actionProviderStore->getProviders(); + $this->actionProviderStore->getProviders($user); } } diff --git a/tests/lib/Contacts/ContactsMenu/ManagerTest.php b/tests/lib/Contacts/ContactsMenu/ManagerTest.php index bcbcec96817..9b84bd76648 100644 --- a/tests/lib/Contacts/ContactsMenu/ManagerTest.php +++ b/tests/lib/Contacts/ContactsMenu/ManagerTest.php @@ -30,6 +30,7 @@ use OC\Contacts\ContactsMenu\Manager; use OCP\App\IAppManager; use OCP\Contacts\ContactsMenu\IEntry; use OCP\Contacts\ContactsMenu\IProvider; +use OCP\IUser; use PHPUnit_Framework_MockObject_MockObject; use Test\TestCase; @@ -71,7 +72,7 @@ class ManagerTest extends TestCase { public function testGetFilteredEntries() { $filter = 'con'; - $user = 'user849'; + $user = $this->createMock(IUser::class); $entries = $this->generateTestEntries(); $provider = $this->createMock(IProvider::class); $this->contactsStore->expects($this->once()) @@ -80,6 +81,7 @@ class ManagerTest extends TestCase { ->willReturn($entries); $this->actionProviderStore->expects($this->once()) ->method('getProviders') + ->with($user) ->willReturn([$provider]); $provider->expects($this->exactly(25)) ->method('process'); |