summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Core/Controller/ClientFlowLoginControllerTest.php408
-rw-r--r--tests/Core/Controller/ContactsMenuControllerTest.php110
-rw-r--r--tests/karma.config.js3
-rw-r--r--tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php67
-rw-r--r--tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php134
-rw-r--r--tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php90
-rw-r--r--tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php255
-rw-r--r--tests/lib/Contacts/ContactsMenu/EntryTest.php114
-rw-r--r--tests/lib/Contacts/ContactsMenu/ManagerTest.php147
-rw-r--r--tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php82
-rw-r--r--tests/lib/Repair/RepairMimeTypesTest.php21
-rw-r--r--tests/lib/User/UserTest.php50
12 files changed, 1478 insertions, 3 deletions
diff --git a/tests/Core/Controller/ClientFlowLoginControllerTest.php b/tests/Core/Controller/ClientFlowLoginControllerTest.php
new file mode 100644
index 00000000000..7c525b53210
--- /dev/null
+++ b/tests/Core/Controller/ClientFlowLoginControllerTest.php
@@ -0,0 +1,408 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Tests\Core\Controller;
+
+use OC\Authentication\Exceptions\InvalidTokenException;
+use OC\Authentication\Exceptions\PasswordlessTokenException;
+use OC\Authentication\Token\IProvider;
+use OC\Authentication\Token\IToken;
+use OC\Core\Controller\ClientFlowLoginController;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\Defaults;
+use OCP\IL10N;
+use OCP\IRequest;
+use OCP\ISession;
+use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserSession;
+use OCP\Security\ISecureRandom;
+use OCP\Session\Exceptions\SessionNotAvailableException;
+use Test\TestCase;
+
+class ClientFlowLoginControllerTest extends TestCase {
+ /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
+ private $request;
+ /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
+ private $userSession;
+ /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
+ private $l10n;
+ /** @var Defaults|\PHPUnit_Framework_MockObject_MockObject */
+ private $defaults;
+ /** @var ISession|\PHPUnit_Framework_MockObject_MockObject */
+ private $session;
+ /** @var IProvider|\PHPUnit_Framework_MockObject_MockObject */
+ private $tokenProvider;
+ /** @var ISecureRandom|\PHPUnit_Framework_MockObject_MockObject */
+ private $random;
+ /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
+ private $urlGenerator;
+ /** @var ClientFlowLoginController */
+ private $clientFlowLoginController;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->request = $this->createMock(IRequest::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10n
+ ->expects($this->any())
+ ->method('t')
+ ->will($this->returnCallback(function($text, $parameters = array()) {
+ return vsprintf($text, $parameters);
+ }));
+ $this->defaults = $this->createMock(Defaults::class);
+ $this->session = $this->createMock(ISession::class);
+ $this->tokenProvider = $this->createMock(IProvider::class);
+ $this->random = $this->createMock(ISecureRandom::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+
+ $this->clientFlowLoginController = new ClientFlowLoginController(
+ 'core',
+ $this->request,
+ $this->userSession,
+ $this->l10n,
+ $this->defaults,
+ $this->session,
+ $this->tokenProvider,
+ $this->random,
+ $this->urlGenerator
+ );
+ }
+
+ public function testShowAuthPickerPageNotAuthenticated() {
+ $this->userSession
+ ->expects($this->once())
+ ->method('isLoggedIn')
+ ->willReturn(true);
+
+ $expected = new TemplateResponse(
+ 'core',
+ '403',
+ [
+ 'file' => 'Auth flow can only be started unauthenticated.',
+ ],
+ 'guest'
+ );
+ $this->assertEquals($expected, $this->clientFlowLoginController->showAuthPickerPage());
+ }
+
+ public function testShowAuthPickerPage() {
+ $this->userSession
+ ->expects($this->once())
+ ->method('isLoggedIn')
+ ->willReturn(false);
+ $this->random
+ ->expects($this->once())
+ ->method('generate')
+ ->with(
+ 64,
+ ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS
+ )
+ ->willReturn('StateToken');
+ $this->session
+ ->expects($this->once())
+ ->method('set')
+ ->with('client.flow.state.token', 'StateToken');
+ $this->request
+ ->expects($this->exactly(2))
+ ->method('getHeader')
+ ->with('USER_AGENT')
+ ->willReturn('Mac OS X Sync Client');
+ $this->defaults
+ ->expects($this->once())
+ ->method('getName')
+ ->willReturn('ExampleCloud');
+ $this->request
+ ->expects($this->once())
+ ->method('getServerHost')
+ ->willReturn('example.com');
+
+ $expected = new TemplateResponse(
+ 'core',
+ 'loginflow/authpicker',
+ [
+ 'client' => 'Mac OS X Sync Client',
+ 'instanceName' => 'ExampleCloud',
+ 'urlGenerator' => $this->urlGenerator,
+ 'stateToken' => 'StateToken',
+ 'serverHost' => 'example.com',
+ ],
+ 'guest'
+ );
+ $this->assertEquals($expected, $this->clientFlowLoginController->showAuthPickerPage());
+ }
+
+ public function testRedirectPageWithInvalidToken() {
+ $this->session
+ ->expects($this->once())
+ ->method('get')
+ ->with('client.flow.state.token')
+ ->willReturn('OtherToken');
+
+ $expected = new TemplateResponse(
+ 'core',
+ '403',
+ [
+ 'file' => 'State token does not match',
+ ],
+ 'guest'
+ );
+ $expected->setStatus(Http::STATUS_FORBIDDEN);
+ $this->assertEquals($expected, $this->clientFlowLoginController->redirectPage('MyStateToken'));
+ }
+
+ public function testRedirectPageWithoutToken() {
+ $this->session
+ ->expects($this->once())
+ ->method('get')
+ ->with('client.flow.state.token')
+ ->willReturn(null);
+
+ $expected = new TemplateResponse(
+ 'core',
+ '403',
+ [
+ 'file' => 'State token does not match',
+ ],
+ 'guest'
+ );
+ $expected->setStatus(Http::STATUS_FORBIDDEN);
+ $this->assertEquals($expected, $this->clientFlowLoginController->redirectPage('MyStateToken'));
+ }
+
+ public function testRedirectPage() {
+ $this->session
+ ->expects($this->once())
+ ->method('get')
+ ->with('client.flow.state.token')
+ ->willReturn('MyStateToken');
+
+ $expected = new TemplateResponse(
+ 'core',
+ 'loginflow/redirect',
+ [
+ 'urlGenerator' => $this->urlGenerator,
+ 'stateToken' => 'MyStateToken',
+ ],
+ 'empty'
+ );
+ $this->assertEquals($expected, $this->clientFlowLoginController->redirectPage('MyStateToken'));
+ }
+
+ public function testGenerateAppPasswordWithInvalidToken() {
+ $this->session
+ ->expects($this->once())
+ ->method('get')
+ ->with('client.flow.state.token')
+ ->willReturn('OtherToken');
+ $this->session
+ ->expects($this->once())
+ ->method('remove')
+ ->with('client.flow.state.token');
+
+ $expected = new TemplateResponse(
+ 'core',
+ '403',
+ [
+ 'file' => 'State token does not match',
+ ],
+ 'guest'
+ );
+ $expected->setStatus(Http::STATUS_FORBIDDEN);
+ $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
+ }
+
+ public function testGenerateAppPasswordWithSessionNotAvailableException() {
+ $this->session
+ ->expects($this->once())
+ ->method('get')
+ ->with('client.flow.state.token')
+ ->willReturn('MyStateToken');
+ $this->session
+ ->expects($this->once())
+ ->method('remove')
+ ->with('client.flow.state.token');
+ $this->session
+ ->expects($this->once())
+ ->method('getId')
+ ->willThrowException(new SessionNotAvailableException());
+
+ $expected = new Http\Response();
+ $expected->setStatus(Http::STATUS_FORBIDDEN);
+ $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
+ }
+
+ public function testGenerateAppPasswordWithInvalidTokenException() {
+ $this->session
+ ->expects($this->once())
+ ->method('get')
+ ->with('client.flow.state.token')
+ ->willReturn('MyStateToken');
+ $this->session
+ ->expects($this->once())
+ ->method('remove')
+ ->with('client.flow.state.token');
+ $this->session
+ ->expects($this->once())
+ ->method('getId')
+ ->willReturn('SessionId');
+ $this->tokenProvider
+ ->expects($this->once())
+ ->method('getToken')
+ ->with('SessionId')
+ ->willThrowException(new InvalidTokenException());
+
+ $expected = new Http\Response();
+ $expected->setStatus(Http::STATUS_FORBIDDEN);
+ $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
+ }
+
+ public function testGeneratePasswordWithPassword() {
+ $this->session
+ ->expects($this->once())
+ ->method('get')
+ ->with('client.flow.state.token')
+ ->willReturn('MyStateToken');
+ $this->session
+ ->expects($this->once())
+ ->method('remove')
+ ->with('client.flow.state.token');
+ $this->session
+ ->expects($this->once())
+ ->method('getId')
+ ->willReturn('SessionId');
+ $myToken = $this->createMock(IToken::class);
+ $myToken
+ ->expects($this->once())
+ ->method('getLoginName')
+ ->willReturn('MyLoginName');
+ $this->tokenProvider
+ ->expects($this->once())
+ ->method('getToken')
+ ->with('SessionId')
+ ->willReturn($myToken);
+ $this->tokenProvider
+ ->expects($this->once())
+ ->method('getPassword')
+ ->with($myToken, 'SessionId')
+ ->willReturn('MyPassword');
+ $this->random
+ ->expects($this->once())
+ ->method('generate')
+ ->with(72)
+ ->willReturn('MyGeneratedToken');
+ $user = $this->createMock(IUser::class);
+ $user
+ ->expects($this->once())
+ ->method('getUID')
+ ->willReturn('MyUid');
+ $this->userSession
+ ->expects($this->once())
+ ->method('getUser')
+ ->willReturn($user);
+ $this->tokenProvider
+ ->expects($this->once())
+ ->method('generateToken')
+ ->with(
+ 'MyGeneratedToken',
+ 'MyUid',
+ 'MyLoginName',
+ 'MyPassword',
+ 'unknown',
+ IToken::PERMANENT_TOKEN,
+ IToken::DO_NOT_REMEMBER
+ );
+ $this->request
+ ->expects($this->once())
+ ->method('getServerHost')
+ ->willReturn('example.com');
+
+ $expected = new Http\RedirectResponse('nc://MyLoginName:MyGeneratedToken@example.com');
+ $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
+ }
+
+ public function testGeneratePasswordWithoutPassword() {
+ $this->session
+ ->expects($this->once())
+ ->method('get')
+ ->with('client.flow.state.token')
+ ->willReturn('MyStateToken');
+ $this->session
+ ->expects($this->once())
+ ->method('remove')
+ ->with('client.flow.state.token');
+ $this->session
+ ->expects($this->once())
+ ->method('getId')
+ ->willReturn('SessionId');
+ $myToken = $this->createMock(IToken::class);
+ $myToken
+ ->expects($this->once())
+ ->method('getLoginName')
+ ->willReturn('MyLoginName');
+ $this->tokenProvider
+ ->expects($this->once())
+ ->method('getToken')
+ ->with('SessionId')
+ ->willReturn($myToken);
+ $this->tokenProvider
+ ->expects($this->once())
+ ->method('getPassword')
+ ->with($myToken, 'SessionId')
+ ->willThrowException(new PasswordlessTokenException());
+ $this->random
+ ->expects($this->once())
+ ->method('generate')
+ ->with(72)
+ ->willReturn('MyGeneratedToken');
+ $user = $this->createMock(IUser::class);
+ $user
+ ->expects($this->once())
+ ->method('getUID')
+ ->willReturn('MyUid');
+ $this->userSession
+ ->expects($this->once())
+ ->method('getUser')
+ ->willReturn($user);
+ $this->tokenProvider
+ ->expects($this->once())
+ ->method('generateToken')
+ ->with(
+ 'MyGeneratedToken',
+ 'MyUid',
+ 'MyLoginName',
+ null,
+ 'unknown',
+ IToken::PERMANENT_TOKEN,
+ IToken::DO_NOT_REMEMBER
+ );
+ $this->request
+ ->expects($this->once())
+ ->method('getServerHost')
+ ->willReturn('example.com');
+
+ $expected = new Http\RedirectResponse('nc://MyLoginName:MyGeneratedToken@example.com');
+ $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
+ }
+}
diff --git a/tests/Core/Controller/ContactsMenuControllerTest.php b/tests/Core/Controller/ContactsMenuControllerTest.php
new file mode 100644
index 00000000000..92a185cf2ad
--- /dev/null
+++ b/tests/Core/Controller/ContactsMenuControllerTest.php
@@ -0,0 +1,110 @@
+<?php
+
+/**
+ * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Tests\Controller;
+
+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;
+
+class ContactsMenuControllerTest extends TestCase {
+
+ /** @var IRequest|PHPUnit_Framework_MockObject_MockObject */
+ private $request;
+
+ /** @var IUserSession|PHPUnit_Framework_MockObject_MockObject */
+ private $userSession;
+
+ /** @var Manager|PHPUnit_Framework_MockObject_MockObject */
+ private $contactsManager;
+
+ /** @var ContactsMenuController */
+ private $controller;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->request = $this->createMock(IRequest::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->contactsManager = $this->createMock(Manager::class);
+
+ $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($user), $this->equalTo(null))
+ ->willReturn($entries);
+
+ $response = $this->controller->index();
+
+ $this->assertEquals($entries, $response);
+ }
+
+ public function testFindOne() {
+ $user = $this->createMock(IUser::class);
+ $entry = $this->createMock(IEntry::class);
+ $this->userSession->expects($this->once())
+ ->method('getUser')
+ ->willReturn($user);
+ $this->contactsManager->expects($this->once())
+ ->method('findOne')
+ ->with($this->equalTo($user), $this->equalTo(42), $this->equalTo('test-search-phrase'))
+ ->willReturn($entry);
+
+ $response = $this->controller->findOne(42, 'test-search-phrase');
+
+ $this->assertEquals($entry, $response);
+ }
+
+ public function testFindOne404() {
+ $user = $this->createMock(IUser::class);
+ $this->userSession->expects($this->once())
+ ->method('getUser')
+ ->willReturn($user);
+ $this->contactsManager->expects($this->once())
+ ->method('findOne')
+ ->with($this->equalTo($user), $this->equalTo(42), $this->equalTo('test-search-phrase'))
+ ->willReturn(null);
+
+ $response = $this->controller->findOne(42, 'test-search-phrase');
+
+ $this->assertEquals([], $response->getData());
+ $this->assertEquals(404, $response->getStatus());
+ }
+}
diff --git a/tests/karma.config.js b/tests/karma.config.js
index 014a8709615..62b5171dcd1 100644
--- a/tests/karma.config.js
+++ b/tests/karma.config.js
@@ -112,8 +112,7 @@ module.exports = function(config) {
srcFiles: [
'settings/js/apps.js',
'settings/js/users/deleteHandler.js',
- 'core/vendor/marked/marked.min.js',
- 'core/vendor/DOMPurify/dist/purify.min.js'
+ 'core/vendor/marked/marked.min.js'
],
testFiles: [
'settings/tests/js/appsSpec.js',
diff --git a/tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php b/tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php
new file mode 100644
index 00000000000..d1273c2b9ad
--- /dev/null
+++ b/tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php
@@ -0,0 +1,67 @@
+<?php
+
+/**
+ * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Tests\Contacts\ContactsMenu;
+
+use OC\Contacts\ContactsMenu\ActionFactory;
+use OCP\Contacts\ContactsMenu\IAction;
+use Test\TestCase;
+
+class ActionFactoryTest extends TestCase {
+
+ /** @var ActionFactory */
+ private $actionFactory;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->actionFactory = new ActionFactory();
+ }
+
+ public function testNewLinkAction() {
+ $icon = 'icon-test';
+ $name = 'Test';
+ $href = 'some/url';
+
+ $action = $this->actionFactory->newLinkAction($icon, $name, $href);
+
+ $this->assertInstanceOf(IAction::class, $action);
+ $this->assertEquals($name, $action->getName());
+ $this->assertEquals(10, $action->getPriority());
+ }
+
+ public function testNewEMailAction() {
+ $icon = 'icon-test';
+ $name = 'Test';
+ $href = 'user@example.com';
+
+ $action = $this->actionFactory->newEMailAction($icon, $name, $href);
+
+ $this->assertInstanceOf(IAction::class, $action);
+ $this->assertEquals($name, $action->getName());
+ $this->assertEquals(10, $action->getPriority());
+ $this->assertEquals('mailto:user%40example.com', $action->getHref());
+ }
+
+}
diff --git a/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php b/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php
new file mode 100644
index 00000000000..8738e19b513
--- /dev/null
+++ b/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php
@@ -0,0 +1,134 @@
+<?php
+
+/**
+ * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+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;
+
+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;
+
+ /** @var ActionProviderStore */
+ private $actionProviderStore;
+
+ protected function setUp() {
+ 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->appManager, $this->logger);
+ }
+
+ public function testGetProviders() {
+ $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, $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($user);
+
+ $this->assertCount(1, $providers);
+ $this->assertInstanceOf(EMailProvider::class, $providers[0]);
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testGetProvidersWithQueryException() {
+ $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());
+
+ $this->actionProviderStore->getProviders($user);
+ }
+
+}
diff --git a/tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php b/tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php
new file mode 100644
index 00000000000..31654b40918
--- /dev/null
+++ b/tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php
@@ -0,0 +1,90 @@
+<?php
+
+/**
+ * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Tests\Contacts\ContactsMenu\Actions;
+
+use OC\Contacts\ContactsMenu\Actions\LinkAction;
+use Test\TestCase;
+
+class LinkActionTest extends TestCase {
+
+ private $action;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->action = new LinkAction();
+ }
+
+ public function testSetIcon() {
+ $icon = 'icon-test';
+
+ $this->action->setIcon($icon);
+ $json = $this->action->jsonSerialize();
+
+ $this->assertArrayHasKey('icon', $json);
+ $this->assertEquals($json['icon'], $icon);
+ }
+
+ public function testGetSetName() {
+ $name = 'Jane Doe';
+
+ $this->assertNull($this->action->getName());
+ $this->action->setName($name);
+ $this->assertEquals($name, $this->action->getName());
+ }
+
+ public function testGetSetPriority() {
+ $prio = 50;
+
+ $this->assertEquals(10, $this->action->getPriority());
+ $this->action->setPriority($prio);
+ $this->assertEquals($prio, $this->action->getPriority());
+ }
+
+ public function testSetHref() {
+ $this->action->setHref('/some/url');
+
+ $json = $this->action->jsonSerialize();
+ $this->assertArrayHasKey('hyperlink', $json);
+ $this->assertEquals($json['hyperlink'], '/some/url');
+ }
+
+ public function testJsonSerialize() {
+ $this->action->setIcon('icon-contacts');
+ $this->action->setName('Nickie Works');
+ $this->action->setPriority(33);
+ $this->action->setHref('example.com');
+ $expected = [
+ 'title' => 'Nickie Works',
+ 'icon' => 'icon-contacts',
+ 'hyperlink' => 'example.com',
+ ];
+
+ $json = $this->action->jsonSerialize();
+
+ $this->assertEquals($expected, $json);
+ }
+
+}
diff --git a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
new file mode 100644
index 00000000000..08da360388f
--- /dev/null
+++ b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
@@ -0,0 +1,255 @@
+<?php
+
+/**
+ * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Tests\Contacts\ContactsMenu;
+
+use OC\Contacts\ContactsMenu\ContactsStore;
+use OCP\Contacts\IManager;
+use OCP\IUser;
+use PHPUnit_Framework_MockObject_MockObject;
+use Test\TestCase;
+
+class ContactsStoreTest extends TestCase {
+
+ /** @var ContactsStore */
+ private $contactsStore;
+
+ /** @var IManager|PHPUnit_Framework_MockObject_MockObject */
+ private $contactsManager;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->contactsManager = $this->createMock(IManager::class);
+
+ $this->contactsStore = new ContactsStore($this->contactsManager);
+ }
+
+ public function testGetContactsWithoutFilter() {
+ $user = $this->createMock(IUser::class);
+ $this->contactsManager->expects($this->once())
+ ->method('search')
+ ->with($this->equalTo(''), $this->equalTo(['FN']))
+ ->willReturn([
+ [
+ 'UID' => 123,
+ ],
+ [
+ 'UID' => 567,
+ 'FN' => 'Darren Roner',
+ 'EMAIL' => [
+ 'darren@roner.au'
+ ],
+ ],
+ ]);
+ $user->expects($this->once())
+ ->method('getUID')
+ ->willReturn('user123');
+
+ $entries = $this->contactsStore->getContacts($user, '');
+
+ $this->assertCount(2, $entries);
+ $this->assertEquals([
+ 'darren@roner.au'
+ ], $entries[1]->getEMailAddresses());
+ }
+
+ public function testGetContactsHidesOwnEntry() {
+ $user = $this->createMock(IUser::class);
+ $this->contactsManager->expects($this->once())
+ ->method('search')
+ ->with($this->equalTo(''), $this->equalTo(['FN']))
+ ->willReturn([
+ [
+ 'UID' => 'user123',
+ ],
+ [
+ 'UID' => 567,
+ 'FN' => 'Darren Roner',
+ 'EMAIL' => [
+ 'darren@roner.au'
+ ],
+ ],
+ ]);
+ $user->expects($this->once())
+ ->method('getUID')
+ ->willReturn('user123');
+
+ $entries = $this->contactsStore->getContacts($user, '');
+
+ $this->assertCount(1, $entries);
+ }
+
+ public function testGetContactsWithoutBinaryImage() {
+ $user = $this->createMock(IUser::class);
+ $this->contactsManager->expects($this->once())
+ ->method('search')
+ ->with($this->equalTo(''), $this->equalTo(['FN']))
+ ->willReturn([
+ [
+ 'UID' => 123,
+ ],
+ [
+ 'UID' => 567,
+ 'FN' => 'Darren Roner',
+ 'EMAIL' => [
+ 'darren@roner.au'
+ ],
+ 'PHOTO' => base64_encode('photophotophoto'),
+ ],
+ ]);
+ $user->expects($this->once())
+ ->method('getUID')
+ ->willReturn('user123');
+
+ $entries = $this->contactsStore->getContacts($user, '');
+
+ $this->assertCount(2, $entries);
+ $this->assertNull($entries[1]->getAvatar());
+ }
+
+ public function testGetContactsWithoutAvatarURI() {
+ $user = $this->createMock(IUser::class);
+ $this->contactsManager->expects($this->once())
+ ->method('search')
+ ->with($this->equalTo(''), $this->equalTo(['FN']))
+ ->willReturn([
+ [
+ 'UID' => 123,
+ ],
+ [
+ 'UID' => 567,
+ 'FN' => 'Darren Roner',
+ 'EMAIL' => [
+ 'darren@roner.au'
+ ],
+ 'PHOTO' => 'VALUE=uri:https://photo',
+ ],
+ ]);
+ $user->expects($this->once())
+ ->method('getUID')
+ ->willReturn('user123');
+
+ $entries = $this->contactsStore->getContacts($user, '');
+
+ $this->assertCount(2, $entries);
+ $this->assertEquals('https://photo', $entries[1]->getAvatar());
+ }
+
+ public function testFindOneUser() {
+ $user = $this->createMock(IUser::class);
+ $this->contactsManager->expects($this->once())
+ ->method('search')
+ ->with($this->equalTo('a567'), $this->equalTo(['UID']))
+ ->willReturn([
+ [
+ 'UID' => 123,
+ 'isLocalSystemBook' => false
+ ],
+ [
+ 'UID' => 'a567',
+ 'FN' => 'Darren Roner',
+ 'EMAIL' => [
+ 'darren@roner.au'
+ ],
+ 'isLocalSystemBook' => true
+ ],
+ ]);
+ $user->expects($this->once())
+ ->method('getUID')
+ ->willReturn('user123');
+
+ $entry = $this->contactsStore->findOne($user, 0, 'a567');
+
+ $this->assertEquals([
+ 'darren@roner.au'
+ ], $entry->getEMailAddresses());
+ }
+
+ public function testFindOneEMail() {
+ $user = $this->createMock(IUser::class);
+ $this->contactsManager->expects($this->once())
+ ->method('search')
+ ->with($this->equalTo('darren@roner.au'), $this->equalTo(['EMAIL']))
+ ->willReturn([
+ [
+ 'UID' => 123,
+ 'isLocalSystemBook' => false
+ ],
+ [
+ 'UID' => 'a567',
+ 'FN' => 'Darren Roner',
+ 'EMAIL' => [
+ 'darren@roner.au'
+ ],
+ 'isLocalSystemBook' => false
+ ],
+ ]);
+ $user->expects($this->once())
+ ->method('getUID')
+ ->willReturn('user123');
+
+ $entry = $this->contactsStore->findOne($user, 4, 'darren@roner.au');
+
+ $this->assertEquals([
+ 'darren@roner.au'
+ ], $entry->getEMailAddresses());
+ }
+
+ public function testFindOneNotSupportedType() {
+ $user = $this->createMock(IUser::class);
+
+ $entry = $this->contactsStore->findOne($user, 42, 'darren@roner.au');
+
+ $this->assertEquals(null, $entry);
+ }
+
+ public function testFindOneNoMatches() {
+ $user = $this->createMock(IUser::class);
+ $this->contactsManager->expects($this->once())
+ ->method('search')
+ ->with($this->equalTo('a567'), $this->equalTo(['UID']))
+ ->willReturn([
+ [
+ 'UID' => 123,
+ 'isLocalSystemBook' => false
+ ],
+ [
+ 'UID' => 'a567',
+ 'FN' => 'Darren Roner',
+ 'EMAIL' => [
+ 'darren@roner.au123'
+ ],
+ 'isLocalSystemBook' => false
+ ],
+ ]);
+ $user->expects($this->once())
+ ->method('getUID')
+ ->willReturn('user123');
+
+ $entry = $this->contactsStore->findOne($user, 0, 'a567');
+
+ $this->assertEquals(null, $entry);
+ }
+}
diff --git a/tests/lib/Contacts/ContactsMenu/EntryTest.php b/tests/lib/Contacts/ContactsMenu/EntryTest.php
new file mode 100644
index 00000000000..ddc6cc916d7
--- /dev/null
+++ b/tests/lib/Contacts/ContactsMenu/EntryTest.php
@@ -0,0 +1,114 @@
+<?php
+
+/**
+ * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Tests\Contacts\ContactsMenu;
+
+use OC\Contacts\ContactsMenu\Actions\LinkAction;
+use OC\Contacts\ContactsMenu\Entry;
+use OCP\Contacts\ContactsMenu\IAction;
+use Test\TestCase;
+
+class EntryTest extends \PHPUnit_Framework_TestCase {
+
+ /** @var Entry */
+ private $entry;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->entry = new Entry();
+ }
+
+ public function testSetId() {
+ $this->entry->setId(123);
+ }
+
+ public function testSetGetFullName() {
+ $fn = 'Danette Chaille';
+ $this->assertEquals('', $this->entry->getFullName());
+ $this->entry->setFullName($fn);
+ $this->assertEquals($fn, $this->entry->getFullName());
+ }
+
+ public function testAddGetEMailAddresses() {
+ $this->assertEmpty($this->entry->getEMailAddresses());
+ $this->entry->addEMailAddress('user@example.com');
+ $this->assertEquals(['user@example.com'], $this->entry->getEMailAddresses());
+ }
+
+ public function testAddAndSortAction() {
+ // Three actions, two with equal priority
+ $action1 = new LinkAction();
+ $action2 = new LinkAction();
+ $action3 = new LinkAction();
+ $action1->setPriority(10);
+ $action1->setName('Bravo');
+
+ $action2->setPriority(0);
+ $action2->setName('Batman');
+
+ $action3->setPriority(10);
+ $action3->setName('Alfa');
+
+ $this->entry->addAction($action1);
+ $this->entry->addAction($action2);
+ $this->entry->addAction($action3);
+ $sorted = $this->entry->getActions();
+
+ $this->assertSame($action3, $sorted[0]);
+ $this->assertSame($action1, $sorted[1]);
+ $this->assertSame($action2, $sorted[2]);
+ }
+
+ public function testSetGetProperties() {
+ $props = [
+ 'prop1' => 123,
+ 'prop2' => 'string',
+ ];
+
+ $this->entry->setProperties($props);
+
+ $this->assertNull($this->entry->getProperty('doesntexist'));
+ $this->assertEquals(123, $this->entry->getProperty('prop1'));
+ $this->assertEquals('string', $this->entry->getProperty('prop2'));
+ }
+
+ public function testJsonSerialize() {
+ $expectedJson = [
+ 'id' => 123,
+ 'fullName' => 'Guadalupe Frisbey',
+ 'topAction' => null,
+ 'actions' => [],
+ 'lastMessage' => '',
+ 'avatar' => null,
+ ];
+
+ $this->entry->setId(123);
+ $this->entry->setFullName('Guadalupe Frisbey');
+ $json = $this->entry->jsonSerialize();
+
+ $this->assertEquals($expectedJson, $json);
+ }
+
+}
diff --git a/tests/lib/Contacts/ContactsMenu/ManagerTest.php b/tests/lib/Contacts/ContactsMenu/ManagerTest.php
new file mode 100644
index 00000000000..783e5590a29
--- /dev/null
+++ b/tests/lib/Contacts/ContactsMenu/ManagerTest.php
@@ -0,0 +1,147 @@
+<?php
+
+/**
+ * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Tests\Contacts\ContactsMenu;
+
+use OC\Contacts\ContactsMenu\ActionProviderStore;
+use OC\Contacts\ContactsMenu\ContactsStore;
+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;
+
+class ManagerTest extends TestCase {
+
+ /** @var ContactsStore|PHPUnit_Framework_MockObject_MockObject */
+ private $contactsStore;
+
+ /** @var IAppManager|PHPUnit_Framework_MockObject_MockObject */
+ private $appManager;
+
+ /** @var ActionProviderStore|PHPUnit_Framework_MockObject_MockObject */
+ private $actionProviderStore;
+
+ /** @var Manager */
+ private $manager;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->contactsStore = $this->createMock(ContactsStore::class);
+ $this->actionProviderStore = $this->createMock(ActionProviderStore::class);
+ $this->appManager = $this->createMock(IAppManager::class);
+
+ $this->manager = new Manager($this->contactsStore, $this->actionProviderStore, $this->appManager);
+ }
+
+ private function generateTestEntries() {
+ $entries = [];
+ foreach (range('Z', 'A') as $char) {
+ $entry = $this->createMock(IEntry::class);
+ $entry->expects($this->any())
+ ->method('getFullName')
+ ->willReturn('Contact ' . $char);
+ $entries[] = $entry;
+ }
+ return $entries;
+ }
+
+ public function testGetFilteredEntries() {
+ $filter = 'con';
+ $user = $this->createMock(IUser::class);
+ $entries = $this->generateTestEntries();
+ $provider = $this->createMock(IProvider::class);
+ $this->contactsStore->expects($this->once())
+ ->method('getContacts')
+ ->with($user, $filter)
+ ->willReturn($entries);
+ $this->actionProviderStore->expects($this->once())
+ ->method('getProviders')
+ ->with($user)
+ ->willReturn([$provider]);
+ $provider->expects($this->exactly(25))
+ ->method('process');
+ $this->appManager->expects($this->once())
+ ->method('isEnabledForUser')
+ ->with($this->equalTo('contacts'), $user)
+ ->willReturn(false);
+ $expected = [
+ 'contacts' => array_slice($entries, 0, 25),
+ 'contactsAppEnabled' => false,
+ ];
+
+ $data = $this->manager->getEntries($user, $filter);
+
+ $this->assertEquals($expected, $data);
+ }
+
+ public function testFindOne() {
+ $shareTypeFilter = 42;
+ $shareWithFilter = 'foobar';
+
+ $user = $this->createMock(IUser::class);
+ $entry = current($this->generateTestEntries());
+ $provider = $this->createMock(IProvider::class);
+ $this->contactsStore->expects($this->once())
+ ->method('findOne')
+ ->with($user, $shareTypeFilter, $shareWithFilter)
+ ->willReturn($entry);
+ $this->actionProviderStore->expects($this->once())
+ ->method('getProviders')
+ ->with($user)
+ ->willReturn([$provider]);
+ $provider->expects($this->once())
+ ->method('process');
+
+ $data = $this->manager->findOne($user, $shareTypeFilter, $shareWithFilter);
+
+ $this->assertEquals($entry, $data);
+ }
+
+ public function testFindOne404() {
+ $shareTypeFilter = 42;
+ $shareWithFilter = 'foobar';
+
+ $user = $this->createMock(IUser::class);
+ $provider = $this->createMock(IProvider::class);
+ $this->contactsStore->expects($this->once())
+ ->method('findOne')
+ ->with($user, $shareTypeFilter, $shareWithFilter)
+ ->willReturn(null);
+ $this->actionProviderStore->expects($this->never())
+ ->method('getProviders')
+ ->with($user)
+ ->willReturn([$provider]);
+ $provider->expects($this->never())
+ ->method('process');
+
+ $data = $this->manager->findOne($user, $shareTypeFilter, $shareWithFilter);
+
+ $this->assertEquals(null, $data);
+ }
+
+}
diff --git a/tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php b/tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php
new file mode 100644
index 00000000000..2d82fa5d68e
--- /dev/null
+++ b/tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php
@@ -0,0 +1,82 @@
+<?php
+
+/**
+ * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Tests\Contacts\ContactsMenu\Providers;
+
+use OC\Contacts\ContactsMenu\Providers\EMailProvider;
+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 EMailproviderTest extends TestCase {
+
+ /** @var IActionFactory|PHPUnit_Framework_MockObject_MockObject */
+ private $actionFactory;
+
+ /** @var IURLGenerator|PHPUnit_Framework_MockObject_MockObject */
+ private $urlGenerator;
+
+ /** @var EMailProvider */
+ private $provider;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->actionFactory = $this->createMock(IActionFactory::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+
+ $this->provider = new EMailProvider($this->actionFactory, $this->urlGenerator);
+ }
+
+ public function testProcess() {
+ $entry = $this->createMock(IEntry::class);
+ $action = $this->createMock(ILinkAction::class);
+ $iconUrl = 'https://example.com/img/actions/icon.svg';
+ $this->urlGenerator->expects($this->once())
+ ->method('imagePath')
+ ->willReturn('img/actions/icon.svg');
+ $this->urlGenerator->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->with('img/actions/icon.svg')
+ ->willReturn($iconUrl);
+ $entry->expects($this->once())
+ ->method('getEMailAddresses')
+ ->willReturn([
+ 'user@example.com',
+ ]);
+ $this->actionFactory->expects($this->once())
+ ->method('newEMailAction')
+ ->with($this->equalTo($iconUrl), $this->equalTo('user@example.com'), $this->equalTo('user@example.com'))
+ ->willReturn($action);
+ $entry->expects($this->once())
+ ->method('addAction')
+ ->with($action);
+
+ $this->provider->process($entry);
+ }
+
+}
diff --git a/tests/lib/Repair/RepairMimeTypesTest.php b/tests/lib/Repair/RepairMimeTypesTest.php
index ef1412b2fd2..f30bbdf7d11 100644
--- a/tests/lib/Repair/RepairMimeTypesTest.php
+++ b/tests/lib/Repair/RepairMimeTypesTest.php
@@ -107,6 +107,23 @@ class RepairMimeTypesTest extends \Test\TestCase {
}
/**
+ * Test renaming the additional image mime types
+ */
+ public function testRenameImageTypes() {
+ $currentMimeTypes = [
+ ['test.jp2', 'application/octet-stream'],
+ ['test.webp', 'application/octet-stream'],
+ ];
+
+ $fixedMimeTypes = [
+ ['test.jp2', 'image/jp2'],
+ ['test.webp', 'image/webp'],
+ ];
+
+ $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
+ }
+
+ /**
* Test renaming the richdocuments additional office mime types
*/
public function testRenameWindowsProgramTypes() {
@@ -163,8 +180,10 @@ class RepairMimeTypesTest extends \Test\TestCase {
['test.sr2', 'image/x-dcraw'],
['test.xrf', 'image/x-dcraw'],
['test.DNG', 'image/x-dcraw'],
+ ['test.jp2', 'image/jp2'],
['test.jps', 'image/jpeg'],
['test.MPO', 'image/jpeg'],
+ ['test.webp', 'image/webp'],
['test.conf', 'text/plain'],
['test.cnf', 'text/plain'],
['test.yaml', 'application/yaml'],
@@ -215,8 +234,10 @@ class RepairMimeTypesTest extends \Test\TestCase {
['test.sr2', 'image/x-dcraw'],
['test.xrf', 'image/x-dcraw'],
['test.DNG', 'image/x-dcraw'],
+ ['test.jp2', 'image/jp2'],
['test.jps', 'image/jpeg'],
['test.MPO', 'image/jpeg'],
+ ['test.webp', 'image/webp'],
['test.conf', 'text/plain'],
['test.cnf', 'text/plain'],
['test.yaml', 'application/yaml'],
diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php
index 5fc07b692f7..b53d07b0d4e 100644
--- a/tests/lib/User/UserTest.php
+++ b/tests/lib/User/UserTest.php
@@ -705,7 +705,55 @@ class UserTest extends TestCase {
'false'
);
- $user = new User('foo', $backend, null, $config);
+ $user = $this->getMockBuilder(User::class)
+ ->setConstructorArgs([
+ 'foo',
+ $backend,
+ null,
+ $config,
+ ])
+ ->setMethods(['isEnabled', 'triggerChange'])
+ ->getMock();
+
+ $user->expects($this->once())
+ ->method('isEnabled')
+ ->willReturn(true);
+ $user->expects($this->once())
+ ->method('triggerChange')
+ ->with(
+ 'enabled',
+ 'false'
+ );
+
+ $user->setEnabled(false);
+ }
+
+ public function testSetDisabledAlreadyDisabled() {
+ /**
+ * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
+ */
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
+
+ $config = $this->createMock(IConfig::class);
+ $config->expects($this->never())
+ ->method('setUserValue');
+
+ $user = $this->getMockBuilder(User::class)
+ ->setConstructorArgs([
+ 'foo',
+ $backend,
+ null,
+ $config,
+ ])
+ ->setMethods(['isEnabled', 'triggerChange'])
+ ->getMock();
+
+ $user->expects($this->once())
+ ->method('isEnabled')
+ ->willReturn(false);
+ $user->expects($this->never())
+ ->method('triggerChange');
+
$user->setEnabled(false);
}