Merge pull request #1629 from nextcloud/cleanup-settings-application
Cleanup settings Application class
This commit is contained in:
commit
a0b34dfd2f
|
@ -30,8 +30,6 @@
|
|||
|
||||
namespace OC\Core;
|
||||
|
||||
use OC\Authentication\Token\DefaultTokenProvider;
|
||||
use OC\Authentication\Token\IProvider;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\Util;
|
||||
|
||||
|
|
|
@ -68,6 +68,9 @@ class SimpleContainer extends Container implements IContainer {
|
|||
// Service not found, use the default value when available
|
||||
if ($parameter->isDefaultValueAvailable()) {
|
||||
$parameters[] = $parameter->getDefaultValue();
|
||||
} else if ($parameterClass !== null) {
|
||||
$resolveName = $parameter->getName();
|
||||
$parameters[] = $this->query($resolveName);
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
|
|
|
@ -30,22 +30,11 @@
|
|||
|
||||
namespace OC\Settings;
|
||||
|
||||
use OC\Files\View;
|
||||
use OC\Server;
|
||||
use OC\Settings\Controller\AdminSettingsController;
|
||||
use OC\Settings\Controller\AppSettingsController;
|
||||
use OC\Settings\Controller\AuthSettingsController;
|
||||
use OC\Settings\Controller\CertificateController;
|
||||
use OC\Settings\Controller\CheckSetupController;
|
||||
use OC\Settings\Controller\EncryptionController;
|
||||
use OC\Settings\Controller\GroupsController;
|
||||
use OC\Settings\Controller\LogSettingsController;
|
||||
use OC\Settings\Controller\MailSettingsController;
|
||||
use OC\Settings\Controller\SecuritySettingsController;
|
||||
use OC\Settings\Controller\UsersController;
|
||||
use OC\Authentication\Token\IProvider;
|
||||
use OC\Settings\Middleware\SubadminMiddleware;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\IContainer;
|
||||
use OCP\Settings\IManager;
|
||||
use OCP\Util;
|
||||
|
||||
/**
|
||||
|
@ -62,171 +51,19 @@ class Application extends App {
|
|||
|
||||
$container = $this->getContainer();
|
||||
|
||||
/**
|
||||
* Controllers
|
||||
*/
|
||||
$container->registerService('MailSettingsController', function(IContainer $c) {
|
||||
return new MailSettingsController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('L10N'),
|
||||
$c->query('Config'),
|
||||
$c->query('UserSession'),
|
||||
$c->query('Defaults'),
|
||||
$c->query('Mailer'),
|
||||
$c->query('DefaultMailAddress')
|
||||
);
|
||||
});
|
||||
$container->registerService('EncryptionController', function(IContainer $c) {
|
||||
return new EncryptionController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('L10N'),
|
||||
$c->query('Config'),
|
||||
$c->query('DatabaseConnection'),
|
||||
$c->query('UserManager'),
|
||||
new View(),
|
||||
$c->query('Logger')
|
||||
);
|
||||
});
|
||||
$container->registerService('AppSettingsController', function(IContainer $c) {
|
||||
return new AppSettingsController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('L10N'),
|
||||
$c->query('Config'),
|
||||
$c->query('ICacheFactory'),
|
||||
$c->query('INavigationManager'),
|
||||
$c->query('IAppManager'),
|
||||
$c->query('OcsClient')
|
||||
);
|
||||
});
|
||||
$container->registerService('AuthSettingsController', function(IContainer $c) {
|
||||
return new AuthSettingsController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('ServerContainer')->query('OC\Authentication\Token\IProvider'),
|
||||
$c->query('UserManager'),
|
||||
$c->query('ServerContainer')->getSession(),
|
||||
$c->query('ServerContainer')->getSecureRandom(),
|
||||
$c->query('UserId')
|
||||
);
|
||||
});
|
||||
$container->registerService('SecuritySettingsController', function(IContainer $c) {
|
||||
return new SecuritySettingsController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('Config')
|
||||
);
|
||||
});
|
||||
$container->registerService('CertificateController', function(IContainer $c) {
|
||||
return new CertificateController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('CertificateManager'),
|
||||
$c->query('SystemCertificateManager'),
|
||||
$c->query('L10N'),
|
||||
$c->query('IAppManager')
|
||||
);
|
||||
});
|
||||
$container->registerService('GroupsController', function(IContainer $c) {
|
||||
return new GroupsController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('GroupManager'),
|
||||
$c->query('UserSession'),
|
||||
$c->query('IsAdmin'),
|
||||
$c->query('L10N')
|
||||
);
|
||||
});
|
||||
$container->registerService('UsersController', function(IContainer $c) {
|
||||
return new UsersController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('UserManager'),
|
||||
$c->query('GroupManager'),
|
||||
$c->query('UserSession'),
|
||||
$c->query('Config'),
|
||||
$c->query('IsAdmin'),
|
||||
$c->query('L10N'),
|
||||
$c->query('Logger'),
|
||||
$c->query('Defaults'),
|
||||
$c->query('Mailer'),
|
||||
$c->query('DefaultMailAddress'),
|
||||
$c->query('URLGenerator'),
|
||||
$c->query('OCP\\App\\IAppManager'),
|
||||
$c->query('OCP\\IAvatarManager')
|
||||
);
|
||||
});
|
||||
$container->registerService('LogSettingsController', function(IContainer $c) {
|
||||
return new LogSettingsController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('Config'),
|
||||
$c->query('L10N')
|
||||
);
|
||||
});
|
||||
$container->registerService('CheckSetupController', function(IContainer $c) {
|
||||
return new CheckSetupController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('Config'),
|
||||
$c->query('ClientService'),
|
||||
$c->query('URLGenerator'),
|
||||
$c->query('Util'),
|
||||
$c->query('L10N'),
|
||||
$c->query('Checker'),
|
||||
$c->query('Logger')
|
||||
);
|
||||
});
|
||||
$container->registerService('AdminSettingsController', function(IContainer $c) {
|
||||
return new AdminSettingsController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('INavigationManager'),
|
||||
$c->query('SettingsManager')
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Middleware
|
||||
*/
|
||||
$container->registerService('SubadminMiddleware', function(IContainer $c){
|
||||
return new SubadminMiddleware(
|
||||
$c->query('ControllerMethodReflector'),
|
||||
$c->query('IsSubAdmin')
|
||||
);
|
||||
});
|
||||
// Execute middlewares
|
||||
$container->registerMiddleware('SubadminMiddleware');
|
||||
// Register Middleware
|
||||
$container->registerAlias('SubadminMiddleware', SubadminMiddleware::class);
|
||||
$container->registerMiddleWare('SubadminMiddleware');
|
||||
|
||||
/**
|
||||
* Core class wrappers
|
||||
*/
|
||||
$container->registerService('Config', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getConfig();
|
||||
});
|
||||
$container->registerService('ICacheFactory', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getMemCacheFactory();
|
||||
});
|
||||
$container->registerService('L10N', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getL10N('settings');
|
||||
});
|
||||
$container->registerService('GroupManager', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getGroupManager();
|
||||
});
|
||||
$container->registerService('UserManager', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getUserManager();
|
||||
});
|
||||
$container->registerService('UserSession', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getUserSession();
|
||||
});
|
||||
/** FIXME: Remove once OC_User is non-static and mockable */
|
||||
$container->registerService('IsAdmin', function(IContainer $c) {
|
||||
$container->registerService('isAdmin', function() {
|
||||
return \OC_User::isAdminUser(\OC_User::getUser());
|
||||
});
|
||||
/** FIXME: Remove once OC_SubAdmin is non-static and mockable */
|
||||
$container->registerService('IsSubAdmin', function(IContainer $c) {
|
||||
$container->registerService('isSubAdmin', function(IContainer $c) {
|
||||
$userObject = \OC::$server->getUserSession()->getUser();
|
||||
$isSubAdmin = false;
|
||||
if($userObject !== null) {
|
||||
|
@ -234,57 +71,19 @@ class Application extends App {
|
|||
}
|
||||
return $isSubAdmin;
|
||||
});
|
||||
$container->registerService('Mailer', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getMailer();
|
||||
});
|
||||
$container->registerService('Defaults', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getThemingDefaults();
|
||||
});
|
||||
$container->registerService('DefaultMailAddress', function(IContainer $c) {
|
||||
$container->registerService('fromMailAddress', function() {
|
||||
return Util::getDefaultEmailAddress('no-reply');
|
||||
});
|
||||
$container->registerService('Logger', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getLogger();
|
||||
});
|
||||
$container->registerService('URLGenerator', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getURLGenerator();
|
||||
});
|
||||
$container->registerService('ClientService', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getHTTPClientService();
|
||||
});
|
||||
$container->registerService('INavigationManager', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getNavigationManager();
|
||||
});
|
||||
$container->registerService('IAppManager', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getAppManager();
|
||||
});
|
||||
$container->registerService('OcsClient', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getOcsClient();
|
||||
});
|
||||
$container->registerService('Util', function(IContainer $c) {
|
||||
return new \OC_Util();
|
||||
});
|
||||
$container->registerService('DatabaseConnection', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getDatabaseConnection();
|
||||
});
|
||||
$container->registerService('CertificateManager', function(IContainer $c){
|
||||
$container->registerService('userCertificateManager', function(IContainer $c) {
|
||||
return $c->query('ServerContainer')->getCertificateManager();
|
||||
});
|
||||
$container->registerService('SystemCertificateManager', function (IContainer $c) {
|
||||
}, false);
|
||||
$container->registerService('systemCertificateManager', function (IContainer $c) {
|
||||
return $c->query('ServerContainer')->getCertificateManager(null);
|
||||
}, false);
|
||||
$container->registerService(IProvider::class, function (IContainer $c) {
|
||||
return $c->query('ServerContainer')->query(IProvider::class);
|
||||
});
|
||||
$container->registerService('Checker', function(IContainer $c) {
|
||||
/** @var Server $server */
|
||||
$server = $c->query('ServerContainer');
|
||||
return $server->getIntegrityCodeChecker();
|
||||
});
|
||||
$container->registerService('EventDispatcher', function (IContainer $c) {
|
||||
return $c->query('ServerContainer')->getEventDispatcher();
|
||||
});
|
||||
$container->registerService('EncryptionManager', function (IContainer $c) {
|
||||
return $c->query('ServerContainer')->getEncryptionManager();
|
||||
});
|
||||
$container->registerService('SettingsManager', function (IContainer $c) {
|
||||
$container->registerService(IManager::class, function (IContainer $c) {
|
||||
return $c->query('ServerContainer')->getSettingsManager();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -60,14 +60,14 @@ class AuthSettingsController extends Controller {
|
|||
* @param IUserManager $userManager
|
||||
* @param ISession $session
|
||||
* @param ISecureRandom $random
|
||||
* @param string $uid
|
||||
* @param string $userId
|
||||
*/
|
||||
public function __construct($appName, IRequest $request, IProvider $tokenProvider, IUserManager $userManager,
|
||||
ISession $session, ISecureRandom $random, $uid) {
|
||||
ISession $session, ISecureRandom $random, $userId) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->tokenProvider = $tokenProvider;
|
||||
$this->userManager = $userManager;
|
||||
$this->uid = $uid;
|
||||
$this->uid = $userId;
|
||||
$this->session = $session;
|
||||
$this->random = $random;
|
||||
}
|
||||
|
|
|
@ -23,14 +23,15 @@
|
|||
|
||||
|
||||
namespace OC\Settings\Controller;
|
||||
|
||||
use OC\Files\View;
|
||||
use OCA\Encryption\Migration;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\ILogger;
|
||||
use OCP\IRequest;
|
||||
use OCP\IConfig;
|
||||
use OC\DB\Connection;
|
||||
use OCP\IUserManager;
|
||||
|
||||
/**
|
||||
|
@ -38,10 +39,10 @@ use OCP\IUserManager;
|
|||
*/
|
||||
class EncryptionController extends Controller {
|
||||
|
||||
/** @var \OCP\IL10N */
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
|
||||
/** @var Connection */
|
||||
/** @var IDBConnection */
|
||||
private $connection;
|
||||
|
||||
/** @var IConfig */
|
||||
|
@ -53,15 +54,15 @@ class EncryptionController extends Controller {
|
|||
/** @var View */
|
||||
private $view;
|
||||
|
||||
/** @var ILogger */
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* @param string $appName
|
||||
* @param IRequest $request
|
||||
* @param \OCP\IL10N $l10n
|
||||
* @param \OCP\IConfig $config
|
||||
* @param \OC\DB\Connection $connection
|
||||
* @param IL10N $l10n
|
||||
* @param IConfig $config
|
||||
* @param IDBConnection $connection
|
||||
* @param IUserManager $userManager
|
||||
* @param View $view
|
||||
* @param ILogger $logger
|
||||
|
@ -70,7 +71,7 @@ class EncryptionController extends Controller {
|
|||
IRequest $request,
|
||||
IL10N $l10n,
|
||||
IConfig $config,
|
||||
Connection $connection,
|
||||
IDBConnection $connection,
|
||||
IUserManager $userManager,
|
||||
View $view,
|
||||
ILogger $logger) {
|
||||
|
@ -86,13 +87,13 @@ class EncryptionController extends Controller {
|
|||
/**
|
||||
* @param IConfig $config
|
||||
* @param View $view
|
||||
* @param Connection $connection
|
||||
* @param IDBConnection $connection
|
||||
* @param ILogger $logger
|
||||
* @return Migration
|
||||
*/
|
||||
protected function getMigration(IConfig $config,
|
||||
View $view,
|
||||
Connection $connection,
|
||||
IDBConnection $connection,
|
||||
ILogger $logger) {
|
||||
return new Migration($config, $view, $connection, $logger);
|
||||
}
|
||||
|
|
|
@ -24,11 +24,11 @@
|
|||
|
||||
namespace OC\Settings\Controller;
|
||||
|
||||
use OC\User\Session;
|
||||
use \OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\IRequest;
|
||||
use OCP\IL10N;
|
||||
use OCP\IConfig;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Mail\IMailer;
|
||||
|
||||
/**
|
||||
|
@ -36,14 +36,12 @@ use OCP\Mail\IMailer;
|
|||
*/
|
||||
class MailSettingsController extends Controller {
|
||||
|
||||
/** @var \OCP\IL10N */
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
/** @var \OCP\IConfig */
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
/** @var Session */
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
/** @var \OC_Defaults */
|
||||
private $defaults;
|
||||
/** @var IMailer */
|
||||
private $mailer;
|
||||
/** @var string */
|
||||
|
@ -54,26 +52,23 @@ class MailSettingsController extends Controller {
|
|||
* @param IRequest $request
|
||||
* @param IL10N $l10n
|
||||
* @param IConfig $config
|
||||
* @param Session $userSession
|
||||
* @param \OC_Defaults $defaults
|
||||
* @param IUserSession $userSession
|
||||
* @param IMailer $mailer
|
||||
* @param string $defaultMailAddress
|
||||
* @param string $fromMailAddress
|
||||
*/
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
IL10N $l10n,
|
||||
IConfig $config,
|
||||
Session $userSession,
|
||||
\OC_Defaults $defaults,
|
||||
IUserSession $userSession,
|
||||
IMailer $mailer,
|
||||
$defaultMailAddress) {
|
||||
$fromMailAddress) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->l10n = $l10n;
|
||||
$this->config = $config;
|
||||
$this->userSession = $userSession;
|
||||
$this->defaults = $defaults;
|
||||
$this->mailer = $mailer;
|
||||
$this->defaultMailAddress = $defaultMailAddress;
|
||||
$this->defaultMailAddress = $fromMailAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -96,6 +96,7 @@ class UsersController extends Controller {
|
|||
* @param string $fromMailAddress
|
||||
* @param IURLGenerator $urlGenerator
|
||||
* @param IAppManager $appManager
|
||||
* @param IAvatarManager $avatarManager
|
||||
*/
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
|
|
|
@ -40,7 +40,7 @@ use PHPUnit_Framework_MockObject_MockObject;
|
|||
*
|
||||
* @package OC\Core\Controller
|
||||
*/
|
||||
class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||
class LostControllerTest extends \Test\TestCase {
|
||||
|
||||
/** @var LostController */
|
||||
private $lostController;
|
||||
|
@ -68,6 +68,7 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
|||
private $request;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->existingUser = $this->getMockBuilder('OCP\IUser')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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\Settings;
|
||||
|
||||
|
||||
use OC\Settings\Application;
|
||||
use OC\Settings\Controller\AdminSettingsController;
|
||||
use OC\Settings\Controller\AppSettingsController;
|
||||
use OC\Settings\Controller\AuthSettingsController;
|
||||
use OC\Settings\Controller\CertificateController;
|
||||
use OC\Settings\Controller\CheckSetupController;
|
||||
use OC\Settings\Controller\EncryptionController;
|
||||
use OC\Settings\Controller\GroupsController;
|
||||
use OC\Settings\Controller\LogSettingsController;
|
||||
use OC\Settings\Controller\MailSettingsController;
|
||||
use OC\Settings\Controller\SecuritySettingsController;
|
||||
use OC\Settings\Controller\UsersController;
|
||||
use OC\Settings\Middleware\SubadminMiddleware;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Middleware;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserSession;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
* Class ApplicationTest
|
||||
*
|
||||
* @package Tests\Settings
|
||||
* @group DB
|
||||
*/
|
||||
class ApplicationTest extends TestCase {
|
||||
/** @var \OC\Settings\Application */
|
||||
protected $app;
|
||||
|
||||
/** @var \OCP\AppFramework\IAppContainer */
|
||||
protected $container;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->app = new Application();
|
||||
$this->container = $this->app->getContainer();
|
||||
}
|
||||
|
||||
public function testContainerAppName() {
|
||||
$this->app = new Application();
|
||||
$this->assertEquals('settings', $this->container->getAppName());
|
||||
}
|
||||
|
||||
public function dataContainerQuery() {
|
||||
return [
|
||||
[AdminSettingsController::class, Controller::class],
|
||||
[AppSettingsController::class, Controller::class],
|
||||
[AuthSettingsController::class, Controller::class],
|
||||
// Needs session: [CertificateController::class, Controller::class],
|
||||
[CheckSetupController::class, Controller::class],
|
||||
[EncryptionController::class, Controller::class],
|
||||
[GroupsController::class, Controller::class],
|
||||
[LogSettingsController::class, Controller::class],
|
||||
[MailSettingsController::class, Controller::class],
|
||||
[SecuritySettingsController::class, Controller::class],
|
||||
[UsersController::class, Controller::class],
|
||||
|
||||
[SubadminMiddleware::class, Middleware::class],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataContainerQuery
|
||||
* @param string $service
|
||||
* @param string $expected
|
||||
*/
|
||||
public function testContainerQuery($service, $expected) {
|
||||
$this->assertTrue($this->container->query($service) instanceof $expected);
|
||||
}
|
||||
|
||||
public function dataContainerQueryRequiresSession() {
|
||||
return [
|
||||
[CertificateController::class, Controller::class],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataContainerQueryRequiresSession
|
||||
* @param string $service
|
||||
* @param string $expected
|
||||
*/
|
||||
public function testContainerQueryRequiresSession($service, $expected) {
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->expects($this->once())
|
||||
->method('getUID')
|
||||
->willReturn('test');
|
||||
|
||||
$session = $this->createMock(IUserSession::class);
|
||||
$session->expects($this->once())
|
||||
->method('getUser')
|
||||
->willReturn($user);
|
||||
|
||||
$this->overwriteService('UserSession', $session);
|
||||
$this->assertTrue($this->container->query($service) instanceof $expected);
|
||||
$this->restoreService('UserSession');
|
||||
}
|
||||
}
|
|
@ -55,6 +55,7 @@ class EncryptionControllerTest extends TestCase {
|
|||
private $encryptionController;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->request = $this->getMockBuilder('\\OCP\\IRequest')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->l10n = $this->getMockBuilder('\\OCP\\IL10N')
|
||||
|
|
|
@ -10,42 +10,47 @@
|
|||
|
||||
namespace Tests\Settings\Controller;
|
||||
|
||||
use OC\Group\Group;
|
||||
use OC\Group\MetaData;
|
||||
use \OC\Settings\Application;
|
||||
use OC\Settings\Controller\GroupsController;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserSession;
|
||||
|
||||
/**
|
||||
* @package Tests\Settings\Controller
|
||||
*/
|
||||
class GroupsControllerTest extends \Test\TestCase {
|
||||
|
||||
/** @var \OCP\AppFramework\IAppContainer */
|
||||
private $container;
|
||||
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $groupManager;
|
||||
|
||||
/** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $userSession;
|
||||
|
||||
/** @var GroupsController */
|
||||
private $groupsController;
|
||||
|
||||
protected function setUp() {
|
||||
$app = new Application();
|
||||
$this->container = $app->getContainer();
|
||||
$this->container['AppName'] = 'settings';
|
||||
$this->container['GroupManager'] = $this->getMockBuilder('\OCP\IGroupManager')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->container['UserSession'] = $this->getMockBuilder('\OC\User\Session')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->container['IsAdmin'] = true;
|
||||
$this->container['L10N']
|
||||
->expects($this->any())
|
||||
->method('t')
|
||||
->will($this->returnCallback(function($text, $parameters = array()) {
|
||||
return vsprintf($text, $parameters);
|
||||
}));
|
||||
$this->groupsController = $this->container['GroupsController'];
|
||||
parent::setUp();
|
||||
|
||||
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||
$this->userSession = $this->createMock(IUserSession::class);
|
||||
$l = $this->createMock(IL10N::class);
|
||||
$l->method('t')
|
||||
->will($this->returnCallback(function($text, $parameters = []) {
|
||||
return vsprintf($text, $parameters);
|
||||
}));
|
||||
$this->groupsController = new GroupsController(
|
||||
'settings',
|
||||
$this->createMock(IRequest::class),
|
||||
$this->groupManager,
|
||||
$this->userSession,
|
||||
true,
|
||||
$l
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
@ -95,7 +100,7 @@ class GroupsControllerTest extends \Test\TestCase {
|
|||
|
||||
$user = $this->getMockBuilder('\OC\User\User')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->container['UserSession']
|
||||
$this->userSession
|
||||
->expects($this->once())
|
||||
->method('getUser')
|
||||
->will($this->returnValue($user));
|
||||
|
@ -103,8 +108,7 @@ class GroupsControllerTest extends \Test\TestCase {
|
|||
->expects($this->once())
|
||||
->method('getUID')
|
||||
->will($this->returnValue('MyAdminUser'));
|
||||
$this->container['GroupManager']
|
||||
->method('search')
|
||||
$this->groupManager->method('search')
|
||||
->will($this->returnValue($groups));
|
||||
|
||||
$expectedResponse = new DataResponse(
|
||||
|
@ -188,7 +192,7 @@ class GroupsControllerTest extends \Test\TestCase {
|
|||
|
||||
$user = $this->getMockBuilder('\OC\User\User')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->container['UserSession']
|
||||
$this->userSession
|
||||
->expects($this->once())
|
||||
->method('getUser')
|
||||
->will($this->returnValue($user));
|
||||
|
@ -196,7 +200,7 @@ class GroupsControllerTest extends \Test\TestCase {
|
|||
->expects($this->once())
|
||||
->method('getUID')
|
||||
->will($this->returnValue('MyAdminUser'));
|
||||
$this->container['GroupManager']
|
||||
$this->groupManager
|
||||
->method('search')
|
||||
->will($this->returnValue($groups));
|
||||
|
||||
|
@ -236,7 +240,7 @@ class GroupsControllerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testCreateWithExistingGroup() {
|
||||
$this->container['GroupManager']
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('groupExists')
|
||||
->with('ExistingGroup')
|
||||
|
@ -253,12 +257,12 @@ class GroupsControllerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testCreateSuccessful() {
|
||||
$this->container['GroupManager']
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('groupExists')
|
||||
->with('NewGroup')
|
||||
->will($this->returnValue(false));
|
||||
$this->container['GroupManager']
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('createGroup')
|
||||
->with('NewGroup')
|
||||
|
@ -275,12 +279,12 @@ class GroupsControllerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testCreateUnsuccessful() {
|
||||
$this->container['GroupManager']
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('groupExists')
|
||||
->with('NewGroup')
|
||||
->will($this->returnValue(false));
|
||||
$this->container['GroupManager']
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('createGroup')
|
||||
->with('NewGroup')
|
||||
|
@ -300,7 +304,7 @@ class GroupsControllerTest extends \Test\TestCase {
|
|||
public function testDestroySuccessful() {
|
||||
$group = $this->getMockBuilder('\OC\Group\Group')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->container['GroupManager']
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('ExistingGroup')
|
||||
|
@ -322,7 +326,7 @@ class GroupsControllerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testDestroyUnsuccessful() {
|
||||
$this->container['GroupManager']
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('ExistingGroup')
|
||||
|
|
|
@ -13,25 +13,36 @@ namespace Tests\Settings\Controller;
|
|||
use \OC\Settings\Application;
|
||||
use OC\Settings\Controller\LogSettingsController;
|
||||
use OCP\AppFramework\Http\StreamResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
|
||||
/**
|
||||
* @package Tests\Settings\Controller
|
||||
*/
|
||||
class LogSettingsControllerTest extends \Test\TestCase {
|
||||
|
||||
/** @var \OCP\AppFramework\IAppContainer */
|
||||
private $container;
|
||||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $config;
|
||||
|
||||
/** @var LogSettingsController */
|
||||
private $logSettingsController;
|
||||
|
||||
protected function setUp() {
|
||||
$app = new Application();
|
||||
$this->container = $app->getContainer();
|
||||
$this->container['Config'] = $this->getMockBuilder('\OCP\IConfig')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->container['AppName'] = 'settings';
|
||||
$this->logSettingsController = $this->container['LogSettingsController'];
|
||||
parent::setUp();
|
||||
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$l = $this->createMock(IL10N::class);
|
||||
$l->method('t')
|
||||
->will($this->returnCallback(function($text, $parameters = []) {
|
||||
return vsprintf($text, $parameters);
|
||||
}));
|
||||
$this->logSettingsController = new LogSettingsController(
|
||||
'settings',
|
||||
$this->createMock(IRequest::class),
|
||||
$this->config,
|
||||
$l
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,8 +50,7 @@ class LogSettingsControllerTest extends \Test\TestCase {
|
|||
*/
|
||||
public function testSetLogLevel($level, $inRange) {
|
||||
if ($inRange) {
|
||||
$this->container['Config']
|
||||
->expects($this->once())
|
||||
$this->config->expects($this->once())
|
||||
->method('setSystemValue')
|
||||
->with('loglevel', $level);
|
||||
}
|
||||
|
|
|
@ -10,75 +10,60 @@
|
|||
|
||||
namespace Tests\Settings\Controller;
|
||||
|
||||
use OC\Settings\Application;
|
||||
use OC\Mail\Message;
|
||||
use OC\Settings\Controller\MailSettingsController;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Mail\IMailer;
|
||||
|
||||
/**
|
||||
* @package Tests\Settings\Controller
|
||||
*/
|
||||
class MailSettingsControllerTest extends \Test\TestCase {
|
||||
|
||||
private $container;
|
||||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $config;
|
||||
/** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $userSession;
|
||||
/** @var IMailer|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $mailer;
|
||||
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $l;
|
||||
|
||||
/** @var MailSettingsController */
|
||||
private $mailController;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$app = new Application();
|
||||
$this->container = $app->getContainer();
|
||||
$this->container['Config'] = $this->getMockBuilder('\OCP\IConfig')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->container['AppName'] = 'settings';
|
||||
$this->container['UserSession'] = $this->getMockBuilder('\OC\User\Session')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->container['MailMessage'] = $this->getMockBuilder('\OCP\Mail\IMessage')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->container['Mailer'] = $this->getMockBuilder('\OC\Mail\Mailer')
|
||||
->setMethods(['send'])
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->container['Defaults'] = $this->getMockBuilder('\OC_Defaults')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->container['DefaultMailAddress'] = 'no-reply@owncloud.com';
|
||||
$this->l = $this->createMock(IL10N::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->userSession = $this->createMock(IUserSession::class);
|
||||
$this->mailer = $this->createMock(IMailer::class);
|
||||
// $this->mailer = $this->getMockBuilder(IMailer::class)
|
||||
// ->setMethods(['send'])
|
||||
// ->getMock();
|
||||
$this->mailController = new MailSettingsController(
|
||||
'settings',
|
||||
$this->createMock(IRequest::class),
|
||||
$this->l,
|
||||
$this->config,
|
||||
$this->userSession,
|
||||
$this->mailer,
|
||||
'no-reply@owncloud.com'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetMailSettings() {
|
||||
$this->container['L10N']
|
||||
$this->l
|
||||
->expects($this->exactly(2))
|
||||
->method('t')
|
||||
->will($this->returnValue('Saved'));
|
||||
|
||||
/**
|
||||
* FIXME: Use the following block once Jenkins uses PHPUnit >= 4.1
|
||||
*/
|
||||
/*
|
||||
$this->container['Config']
|
||||
->expects($this->exactly(15))
|
||||
->method('setSystemValue')
|
||||
->withConsecutive(
|
||||
array($this->equalTo('mail_domain'), $this->equalTo('owncloud.com')),
|
||||
array($this->equalTo('mail_from_address'), $this->equalTo('demo@owncloud.com')),
|
||||
array($this->equalTo('mail_smtpmode'), $this->equalTo('smtp')),
|
||||
array($this->equalTo('mail_smtpsecure'), $this->equalTo('ssl')),
|
||||
array($this->equalTo('mail_smtphost'), $this->equalTo('mx.owncloud.org')),
|
||||
array($this->equalTo('mail_smtpauthtype'), $this->equalTo('NTLM')),
|
||||
array($this->equalTo('mail_smtpauth'), $this->equalTo(1)),
|
||||
array($this->equalTo('mail_smtpport'), $this->equalTo('25')),
|
||||
array($this->equalTo('mail_domain'), $this->equalTo('owncloud.com')),
|
||||
array($this->equalTo('mail_from_address'), $this->equalTo('demo@owncloud.com')),
|
||||
array($this->equalTo('mail_smtpmode'), $this->equalTo('smtp')),
|
||||
array($this->equalTo('mail_smtpsecure'), $this->equalTo('ssl')),
|
||||
array($this->equalTo('mail_smtphost'), $this->equalTo('mx.owncloud.org')),
|
||||
array($this->equalTo('mail_smtpauthtype'), $this->equalTo('NTLM')),
|
||||
array($this->equalTo('mail_smtpport'), $this->equalTo('25'))
|
||||
);
|
||||
*/
|
||||
|
||||
/** @var \PHPUnit_Framework_MockObject_MockObject $config */
|
||||
$config = $this->container['Config'];
|
||||
$config->expects($this->exactly(2))
|
||||
->method('setSystemValues');
|
||||
/**
|
||||
* FIXME: Use the following block once Jenkins uses PHPUnit >= 4.1
|
||||
$this->config->expects($this->exactly(2))
|
||||
->method('setSystemValues')
|
||||
->withConsecutive(
|
||||
[[
|
||||
'mail_domain' => 'owncloud.com',
|
||||
|
@ -103,10 +88,9 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
|||
'mail_smtppassword' => null,
|
||||
]]
|
||||
);
|
||||
*/
|
||||
|
||||
// With authentication
|
||||
$response = $this->container['MailSettingsController']->setMailSettings(
|
||||
$response = $this->mailController->setMailSettings(
|
||||
'owncloud.com',
|
||||
'demo@owncloud.com',
|
||||
'smtp',
|
||||
|
@ -120,7 +104,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
|||
$this->assertSame($expectedResponse, $response);
|
||||
|
||||
// Without authentication (testing the deletion of the stored password)
|
||||
$response = $this->container['MailSettingsController']->setMailSettings(
|
||||
$response = $this->mailController->setMailSettings(
|
||||
'owncloud.com',
|
||||
'demo@owncloud.com',
|
||||
'smtp',
|
||||
|
@ -136,12 +120,12 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testStoreCredentials() {
|
||||
$this->container['L10N']
|
||||
$this->l
|
||||
->expects($this->once())
|
||||
->method('t')
|
||||
->will($this->returnValue('Saved'));
|
||||
|
||||
$this->container['Config']
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('setSystemValues')
|
||||
->with([
|
||||
|
@ -149,7 +133,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
|||
'mail_smtppassword' => 'PasswordToStore',
|
||||
]);
|
||||
|
||||
$response = $this->container['MailSettingsController']->storeCredentials('UsernameToStore', 'PasswordToStore');
|
||||
$response = $this->mailController->storeCredentials('UsernameToStore', 'PasswordToStore');
|
||||
$expectedResponse = array('data' => array('message' =>'Saved'), 'status' => 'success');
|
||||
|
||||
$this->assertSame($expectedResponse, $response);
|
||||
|
@ -166,7 +150,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
|||
->method('getDisplayName')
|
||||
->will($this->returnValue('Werner Brösel'));
|
||||
|
||||
$this->container['L10N']
|
||||
$this->l
|
||||
->expects($this->any())
|
||||
->method('t')
|
||||
->will(
|
||||
|
@ -182,22 +166,25 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
|||
'If you received this email, the settings seem to be correct.')
|
||||
)
|
||||
));
|
||||
$this->container['UserSession']
|
||||
$this->userSession
|
||||
->expects($this->any())
|
||||
->method('getUser')
|
||||
->will($this->returnValue($user));
|
||||
|
||||
// Ensure that it fails when no mail address has been specified
|
||||
$response = $this->container['MailSettingsController']->sendTestMail();
|
||||
$response = $this->mailController->sendTestMail();
|
||||
$expectedResponse = array('data' => array('message' =>'You need to set your user email before being able to send test emails.'), 'status' => 'error');
|
||||
$this->assertSame($expectedResponse, $response);
|
||||
|
||||
// If no exception is thrown it should work
|
||||
$this->container['Config']
|
||||
$this->config
|
||||
->expects($this->any())
|
||||
->method('getUserValue')
|
||||
->will($this->returnValue('mail@example.invalid'));
|
||||
$response = $this->container['MailSettingsController']->sendTestMail();
|
||||
$this->mailer->expects($this->once())
|
||||
->method('createMessage')
|
||||
->willReturn($this->createMock(Message::class));
|
||||
$response = $this->mailController->sendTestMail();
|
||||
$expectedResponse = array('data' => array('message' =>'Email sent'), 'status' => 'success');
|
||||
$this->assertSame($expectedResponse, $response);
|
||||
}
|
||||
|
|
|
@ -11,33 +11,37 @@ namespace Tests\Settings\Controller;
|
|||
|
||||
use \OC\Settings\Application;
|
||||
use OC\Settings\Controller\SecuritySettingsController;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
|
||||
/**
|
||||
* @package Tests\Settings\Controller
|
||||
*/
|
||||
class SecuritySettingsControllerTest extends \PHPUnit_Framework_TestCase {
|
||||
class SecuritySettingsControllerTest extends \Test\TestCase {
|
||||
|
||||
/** @var \OCP\AppFramework\IAppContainer */
|
||||
private $container;
|
||||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $config;
|
||||
|
||||
/** @var SecuritySettingsController */
|
||||
private $securitySettingsController;
|
||||
|
||||
protected function setUp() {
|
||||
$app = new Application();
|
||||
$this->container = $app->getContainer();
|
||||
$this->container['Config'] = $this->getMockBuilder('\OCP\IConfig')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->container['AppName'] = 'settings';
|
||||
$this->securitySettingsController = $this->container['SecuritySettingsController'];
|
||||
parent::setUp();
|
||||
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->securitySettingsController = new SecuritySettingsController(
|
||||
'settings',
|
||||
$this->createMock(IRequest::class),
|
||||
$this->config
|
||||
);
|
||||
}
|
||||
|
||||
public function testTrustedDomainsWithExistingValues() {
|
||||
$this->container['Config']
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('setSystemValue')
|
||||
->with('trusted_domains', array('owncloud.org', 'owncloud.com', 'newdomain.com'));
|
||||
$this->container['Config']
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('getSystemValue')
|
||||
->with('trusted_domains')
|
||||
|
@ -50,11 +54,11 @@ class SecuritySettingsControllerTest extends \PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
public function testTrustedDomainsEmpty() {
|
||||
$this->container['Config']
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('setSystemValue')
|
||||
->with('trusted_domains', array('newdomain.com'));
|
||||
$this->container['Config']
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('getSystemValue')
|
||||
->with($this->equalTo('trusted_domains'), $this->equalTo([]))
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -33,6 +33,7 @@ class SubadminMiddlewareTest extends \Test\TestCase {
|
|||
private $controller;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->reflector = $this->getMockBuilder('\OC\AppFramework\Utility\ControllerMethodReflector')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->controller = $this->getMockBuilder('\OCP\AppFramework\Controller')
|
||||
|
|
Loading…
Reference in New Issue