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;
|
namespace OC\Core;
|
||||||
|
|
||||||
use OC\Authentication\Token\DefaultTokenProvider;
|
|
||||||
use OC\Authentication\Token\IProvider;
|
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
use OCP\Util;
|
use OCP\Util;
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,9 @@ class SimpleContainer extends Container implements IContainer {
|
||||||
// Service not found, use the default value when available
|
// Service not found, use the default value when available
|
||||||
if ($parameter->isDefaultValueAvailable()) {
|
if ($parameter->isDefaultValueAvailable()) {
|
||||||
$parameters[] = $parameter->getDefaultValue();
|
$parameters[] = $parameter->getDefaultValue();
|
||||||
|
} else if ($parameterClass !== null) {
|
||||||
|
$resolveName = $parameter->getName();
|
||||||
|
$parameters[] = $this->query($resolveName);
|
||||||
} else {
|
} else {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,22 +30,11 @@
|
||||||
|
|
||||||
namespace OC\Settings;
|
namespace OC\Settings;
|
||||||
|
|
||||||
use OC\Files\View;
|
use OC\Authentication\Token\IProvider;
|
||||||
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\Settings\Middleware\SubadminMiddleware;
|
use OC\Settings\Middleware\SubadminMiddleware;
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
use OCP\IContainer;
|
use OCP\IContainer;
|
||||||
|
use OCP\Settings\IManager;
|
||||||
use OCP\Util;
|
use OCP\Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,171 +51,19 @@ class Application extends App {
|
||||||
|
|
||||||
$container = $this->getContainer();
|
$container = $this->getContainer();
|
||||||
|
|
||||||
/**
|
// Register Middleware
|
||||||
* Controllers
|
$container->registerAlias('SubadminMiddleware', SubadminMiddleware::class);
|
||||||
*/
|
$container->registerMiddleWare('SubadminMiddleware');
|
||||||
$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');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core class wrappers
|
* 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 */
|
/** 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());
|
return \OC_User::isAdminUser(\OC_User::getUser());
|
||||||
});
|
});
|
||||||
/** FIXME: Remove once OC_SubAdmin is non-static and mockable */
|
/** 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();
|
$userObject = \OC::$server->getUserSession()->getUser();
|
||||||
$isSubAdmin = false;
|
$isSubAdmin = false;
|
||||||
if($userObject !== null) {
|
if($userObject !== null) {
|
||||||
|
@ -234,57 +71,19 @@ class Application extends App {
|
||||||
}
|
}
|
||||||
return $isSubAdmin;
|
return $isSubAdmin;
|
||||||
});
|
});
|
||||||
$container->registerService('Mailer', function(IContainer $c) {
|
$container->registerService('fromMailAddress', function() {
|
||||||
return $c->query('ServerContainer')->getMailer();
|
|
||||||
});
|
|
||||||
$container->registerService('Defaults', function(IContainer $c) {
|
|
||||||
return $c->query('ServerContainer')->getThemingDefaults();
|
|
||||||
});
|
|
||||||
$container->registerService('DefaultMailAddress', function(IContainer $c) {
|
|
||||||
return Util::getDefaultEmailAddress('no-reply');
|
return Util::getDefaultEmailAddress('no-reply');
|
||||||
});
|
});
|
||||||
$container->registerService('Logger', function(IContainer $c) {
|
$container->registerService('userCertificateManager', 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){
|
|
||||||
return $c->query('ServerContainer')->getCertificateManager();
|
return $c->query('ServerContainer')->getCertificateManager();
|
||||||
});
|
}, false);
|
||||||
$container->registerService('SystemCertificateManager', function (IContainer $c) {
|
$container->registerService('systemCertificateManager', function (IContainer $c) {
|
||||||
return $c->query('ServerContainer')->getCertificateManager(null);
|
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) {
|
$container->registerService(IManager::class, 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) {
|
|
||||||
return $c->query('ServerContainer')->getSettingsManager();
|
return $c->query('ServerContainer')->getSettingsManager();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,14 +60,14 @@ class AuthSettingsController extends Controller {
|
||||||
* @param IUserManager $userManager
|
* @param IUserManager $userManager
|
||||||
* @param ISession $session
|
* @param ISession $session
|
||||||
* @param ISecureRandom $random
|
* @param ISecureRandom $random
|
||||||
* @param string $uid
|
* @param string $userId
|
||||||
*/
|
*/
|
||||||
public function __construct($appName, IRequest $request, IProvider $tokenProvider, IUserManager $userManager,
|
public function __construct($appName, IRequest $request, IProvider $tokenProvider, IUserManager $userManager,
|
||||||
ISession $session, ISecureRandom $random, $uid) {
|
ISession $session, ISecureRandom $random, $userId) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->tokenProvider = $tokenProvider;
|
$this->tokenProvider = $tokenProvider;
|
||||||
$this->userManager = $userManager;
|
$this->userManager = $userManager;
|
||||||
$this->uid = $uid;
|
$this->uid = $userId;
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
$this->random = $random;
|
$this->random = $random;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,14 +23,15 @@
|
||||||
|
|
||||||
|
|
||||||
namespace OC\Settings\Controller;
|
namespace OC\Settings\Controller;
|
||||||
|
|
||||||
use OC\Files\View;
|
use OC\Files\View;
|
||||||
use OCA\Encryption\Migration;
|
use OCA\Encryption\Migration;
|
||||||
|
use OCP\IDBConnection;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OC\DB\Connection;
|
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,10 +39,10 @@ use OCP\IUserManager;
|
||||||
*/
|
*/
|
||||||
class EncryptionController extends Controller {
|
class EncryptionController extends Controller {
|
||||||
|
|
||||||
/** @var \OCP\IL10N */
|
/** @var IL10N */
|
||||||
private $l10n;
|
private $l10n;
|
||||||
|
|
||||||
/** @var Connection */
|
/** @var IDBConnection */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/** @var IConfig */
|
/** @var IConfig */
|
||||||
|
@ -53,15 +54,15 @@ class EncryptionController extends Controller {
|
||||||
/** @var View */
|
/** @var View */
|
||||||
private $view;
|
private $view;
|
||||||
|
|
||||||
/** @var ILogger */
|
/** @var ILogger */
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $appName
|
* @param string $appName
|
||||||
* @param IRequest $request
|
* @param IRequest $request
|
||||||
* @param \OCP\IL10N $l10n
|
* @param IL10N $l10n
|
||||||
* @param \OCP\IConfig $config
|
* @param IConfig $config
|
||||||
* @param \OC\DB\Connection $connection
|
* @param IDBConnection $connection
|
||||||
* @param IUserManager $userManager
|
* @param IUserManager $userManager
|
||||||
* @param View $view
|
* @param View $view
|
||||||
* @param ILogger $logger
|
* @param ILogger $logger
|
||||||
|
@ -70,7 +71,7 @@ class EncryptionController extends Controller {
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
IL10N $l10n,
|
IL10N $l10n,
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
Connection $connection,
|
IDBConnection $connection,
|
||||||
IUserManager $userManager,
|
IUserManager $userManager,
|
||||||
View $view,
|
View $view,
|
||||||
ILogger $logger) {
|
ILogger $logger) {
|
||||||
|
@ -86,13 +87,13 @@ class EncryptionController extends Controller {
|
||||||
/**
|
/**
|
||||||
* @param IConfig $config
|
* @param IConfig $config
|
||||||
* @param View $view
|
* @param View $view
|
||||||
* @param Connection $connection
|
* @param IDBConnection $connection
|
||||||
* @param ILogger $logger
|
* @param ILogger $logger
|
||||||
* @return Migration
|
* @return Migration
|
||||||
*/
|
*/
|
||||||
protected function getMigration(IConfig $config,
|
protected function getMigration(IConfig $config,
|
||||||
View $view,
|
View $view,
|
||||||
Connection $connection,
|
IDBConnection $connection,
|
||||||
ILogger $logger) {
|
ILogger $logger) {
|
||||||
return new Migration($config, $view, $connection, $logger);
|
return new Migration($config, $view, $connection, $logger);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,11 @@
|
||||||
|
|
||||||
namespace OC\Settings\Controller;
|
namespace OC\Settings\Controller;
|
||||||
|
|
||||||
use OC\User\Session;
|
use OCP\AppFramework\Controller;
|
||||||
use \OCP\AppFramework\Controller;
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
use OCP\IUserSession;
|
||||||
use OCP\Mail\IMailer;
|
use OCP\Mail\IMailer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,14 +36,12 @@ use OCP\Mail\IMailer;
|
||||||
*/
|
*/
|
||||||
class MailSettingsController extends Controller {
|
class MailSettingsController extends Controller {
|
||||||
|
|
||||||
/** @var \OCP\IL10N */
|
/** @var IL10N */
|
||||||
private $l10n;
|
private $l10n;
|
||||||
/** @var \OCP\IConfig */
|
/** @var IConfig */
|
||||||
private $config;
|
private $config;
|
||||||
/** @var Session */
|
/** @var IUserSession */
|
||||||
private $userSession;
|
private $userSession;
|
||||||
/** @var \OC_Defaults */
|
|
||||||
private $defaults;
|
|
||||||
/** @var IMailer */
|
/** @var IMailer */
|
||||||
private $mailer;
|
private $mailer;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
|
@ -54,26 +52,23 @@ class MailSettingsController extends Controller {
|
||||||
* @param IRequest $request
|
* @param IRequest $request
|
||||||
* @param IL10N $l10n
|
* @param IL10N $l10n
|
||||||
* @param IConfig $config
|
* @param IConfig $config
|
||||||
* @param Session $userSession
|
* @param IUserSession $userSession
|
||||||
* @param \OC_Defaults $defaults
|
|
||||||
* @param IMailer $mailer
|
* @param IMailer $mailer
|
||||||
* @param string $defaultMailAddress
|
* @param string $fromMailAddress
|
||||||
*/
|
*/
|
||||||
public function __construct($appName,
|
public function __construct($appName,
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
IL10N $l10n,
|
IL10N $l10n,
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
Session $userSession,
|
IUserSession $userSession,
|
||||||
\OC_Defaults $defaults,
|
|
||||||
IMailer $mailer,
|
IMailer $mailer,
|
||||||
$defaultMailAddress) {
|
$fromMailAddress) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->userSession = $userSession;
|
$this->userSession = $userSession;
|
||||||
$this->defaults = $defaults;
|
|
||||||
$this->mailer = $mailer;
|
$this->mailer = $mailer;
|
||||||
$this->defaultMailAddress = $defaultMailAddress;
|
$this->defaultMailAddress = $fromMailAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -96,6 +96,7 @@ class UsersController extends Controller {
|
||||||
* @param string $fromMailAddress
|
* @param string $fromMailAddress
|
||||||
* @param IURLGenerator $urlGenerator
|
* @param IURLGenerator $urlGenerator
|
||||||
* @param IAppManager $appManager
|
* @param IAppManager $appManager
|
||||||
|
* @param IAvatarManager $avatarManager
|
||||||
*/
|
*/
|
||||||
public function __construct($appName,
|
public function __construct($appName,
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
|
|
|
@ -40,7 +40,7 @@ use PHPUnit_Framework_MockObject_MockObject;
|
||||||
*
|
*
|
||||||
* @package OC\Core\Controller
|
* @package OC\Core\Controller
|
||||||
*/
|
*/
|
||||||
class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
class LostControllerTest extends \Test\TestCase {
|
||||||
|
|
||||||
/** @var LostController */
|
/** @var LostController */
|
||||||
private $lostController;
|
private $lostController;
|
||||||
|
@ -68,6 +68,7 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
private $request;
|
private $request;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
$this->existingUser = $this->getMockBuilder('OCP\IUser')
|
$this->existingUser = $this->getMockBuilder('OCP\IUser')
|
||||||
->disableOriginalConstructor()->getMock();
|
->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;
|
private $encryptionController;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
$this->request = $this->getMockBuilder('\\OCP\\IRequest')
|
$this->request = $this->getMockBuilder('\\OCP\\IRequest')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->l10n = $this->getMockBuilder('\\OCP\\IL10N')
|
$this->l10n = $this->getMockBuilder('\\OCP\\IL10N')
|
||||||
|
|
|
@ -10,42 +10,47 @@
|
||||||
|
|
||||||
namespace Tests\Settings\Controller;
|
namespace Tests\Settings\Controller;
|
||||||
|
|
||||||
use OC\Group\Group;
|
|
||||||
use OC\Group\MetaData;
|
use OC\Group\MetaData;
|
||||||
use \OC\Settings\Application;
|
|
||||||
use OC\Settings\Controller\GroupsController;
|
use OC\Settings\Controller\GroupsController;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
use OCP\IGroupManager;
|
||||||
|
use OCP\IL10N;
|
||||||
|
use OCP\IRequest;
|
||||||
|
use OCP\IUserSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package Tests\Settings\Controller
|
* @package Tests\Settings\Controller
|
||||||
*/
|
*/
|
||||||
class GroupsControllerTest extends \Test\TestCase {
|
class GroupsControllerTest extends \Test\TestCase {
|
||||||
|
|
||||||
/** @var \OCP\AppFramework\IAppContainer */
|
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $container;
|
private $groupManager;
|
||||||
|
|
||||||
|
/** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $userSession;
|
||||||
|
|
||||||
/** @var GroupsController */
|
/** @var GroupsController */
|
||||||
private $groupsController;
|
private $groupsController;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
$app = new Application();
|
parent::setUp();
|
||||||
$this->container = $app->getContainer();
|
|
||||||
$this->container['AppName'] = 'settings';
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||||
$this->container['GroupManager'] = $this->getMockBuilder('\OCP\IGroupManager')
|
$this->userSession = $this->createMock(IUserSession::class);
|
||||||
->disableOriginalConstructor()->getMock();
|
$l = $this->createMock(IL10N::class);
|
||||||
$this->container['UserSession'] = $this->getMockBuilder('\OC\User\Session')
|
$l->method('t')
|
||||||
->disableOriginalConstructor()->getMock();
|
->will($this->returnCallback(function($text, $parameters = []) {
|
||||||
$this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N')
|
return vsprintf($text, $parameters);
|
||||||
->disableOriginalConstructor()->getMock();
|
}));
|
||||||
$this->container['IsAdmin'] = true;
|
$this->groupsController = new GroupsController(
|
||||||
$this->container['L10N']
|
'settings',
|
||||||
->expects($this->any())
|
$this->createMock(IRequest::class),
|
||||||
->method('t')
|
$this->groupManager,
|
||||||
->will($this->returnCallback(function($text, $parameters = array()) {
|
$this->userSession,
|
||||||
return vsprintf($text, $parameters);
|
true,
|
||||||
}));
|
$l
|
||||||
$this->groupsController = $this->container['GroupsController'];
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +100,7 @@ class GroupsControllerTest extends \Test\TestCase {
|
||||||
|
|
||||||
$user = $this->getMockBuilder('\OC\User\User')
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->container['UserSession']
|
$this->userSession
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getUser')
|
->method('getUser')
|
||||||
->will($this->returnValue($user));
|
->will($this->returnValue($user));
|
||||||
|
@ -103,8 +108,7 @@ class GroupsControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('MyAdminUser'));
|
->will($this->returnValue('MyAdminUser'));
|
||||||
$this->container['GroupManager']
|
$this->groupManager->method('search')
|
||||||
->method('search')
|
|
||||||
->will($this->returnValue($groups));
|
->will($this->returnValue($groups));
|
||||||
|
|
||||||
$expectedResponse = new DataResponse(
|
$expectedResponse = new DataResponse(
|
||||||
|
@ -188,7 +192,7 @@ class GroupsControllerTest extends \Test\TestCase {
|
||||||
|
|
||||||
$user = $this->getMockBuilder('\OC\User\User')
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->container['UserSession']
|
$this->userSession
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getUser')
|
->method('getUser')
|
||||||
->will($this->returnValue($user));
|
->will($this->returnValue($user));
|
||||||
|
@ -196,7 +200,7 @@ class GroupsControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('MyAdminUser'));
|
->will($this->returnValue('MyAdminUser'));
|
||||||
$this->container['GroupManager']
|
$this->groupManager
|
||||||
->method('search')
|
->method('search')
|
||||||
->will($this->returnValue($groups));
|
->will($this->returnValue($groups));
|
||||||
|
|
||||||
|
@ -236,7 +240,7 @@ class GroupsControllerTest extends \Test\TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateWithExistingGroup() {
|
public function testCreateWithExistingGroup() {
|
||||||
$this->container['GroupManager']
|
$this->groupManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('groupExists')
|
->method('groupExists')
|
||||||
->with('ExistingGroup')
|
->with('ExistingGroup')
|
||||||
|
@ -253,12 +257,12 @@ class GroupsControllerTest extends \Test\TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateSuccessful() {
|
public function testCreateSuccessful() {
|
||||||
$this->container['GroupManager']
|
$this->groupManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('groupExists')
|
->method('groupExists')
|
||||||
->with('NewGroup')
|
->with('NewGroup')
|
||||||
->will($this->returnValue(false));
|
->will($this->returnValue(false));
|
||||||
$this->container['GroupManager']
|
$this->groupManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('createGroup')
|
->method('createGroup')
|
||||||
->with('NewGroup')
|
->with('NewGroup')
|
||||||
|
@ -275,12 +279,12 @@ class GroupsControllerTest extends \Test\TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateUnsuccessful() {
|
public function testCreateUnsuccessful() {
|
||||||
$this->container['GroupManager']
|
$this->groupManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('groupExists')
|
->method('groupExists')
|
||||||
->with('NewGroup')
|
->with('NewGroup')
|
||||||
->will($this->returnValue(false));
|
->will($this->returnValue(false));
|
||||||
$this->container['GroupManager']
|
$this->groupManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('createGroup')
|
->method('createGroup')
|
||||||
->with('NewGroup')
|
->with('NewGroup')
|
||||||
|
@ -300,7 +304,7 @@ class GroupsControllerTest extends \Test\TestCase {
|
||||||
public function testDestroySuccessful() {
|
public function testDestroySuccessful() {
|
||||||
$group = $this->getMockBuilder('\OC\Group\Group')
|
$group = $this->getMockBuilder('\OC\Group\Group')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->container['GroupManager']
|
$this->groupManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with('ExistingGroup')
|
->with('ExistingGroup')
|
||||||
|
@ -322,7 +326,7 @@ class GroupsControllerTest extends \Test\TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDestroyUnsuccessful() {
|
public function testDestroyUnsuccessful() {
|
||||||
$this->container['GroupManager']
|
$this->groupManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with('ExistingGroup')
|
->with('ExistingGroup')
|
||||||
|
|
|
@ -13,25 +13,36 @@ namespace Tests\Settings\Controller;
|
||||||
use \OC\Settings\Application;
|
use \OC\Settings\Application;
|
||||||
use OC\Settings\Controller\LogSettingsController;
|
use OC\Settings\Controller\LogSettingsController;
|
||||||
use OCP\AppFramework\Http\StreamResponse;
|
use OCP\AppFramework\Http\StreamResponse;
|
||||||
|
use OCP\IConfig;
|
||||||
|
use OCP\IL10N;
|
||||||
|
use OCP\IRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package Tests\Settings\Controller
|
* @package Tests\Settings\Controller
|
||||||
*/
|
*/
|
||||||
class LogSettingsControllerTest extends \Test\TestCase {
|
class LogSettingsControllerTest extends \Test\TestCase {
|
||||||
|
|
||||||
/** @var \OCP\AppFramework\IAppContainer */
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $container;
|
private $config;
|
||||||
|
|
||||||
/** @var LogSettingsController */
|
/** @var LogSettingsController */
|
||||||
private $logSettingsController;
|
private $logSettingsController;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
$app = new Application();
|
parent::setUp();
|
||||||
$this->container = $app->getContainer();
|
|
||||||
$this->container['Config'] = $this->getMockBuilder('\OCP\IConfig')
|
$this->config = $this->createMock(IConfig::class);
|
||||||
->disableOriginalConstructor()->getMock();
|
$l = $this->createMock(IL10N::class);
|
||||||
$this->container['AppName'] = 'settings';
|
$l->method('t')
|
||||||
$this->logSettingsController = $this->container['LogSettingsController'];
|
->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) {
|
public function testSetLogLevel($level, $inRange) {
|
||||||
if ($inRange) {
|
if ($inRange) {
|
||||||
$this->container['Config']
|
$this->config->expects($this->once())
|
||||||
->expects($this->once())
|
|
||||||
->method('setSystemValue')
|
->method('setSystemValue')
|
||||||
->with('loglevel', $level);
|
->with('loglevel', $level);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,75 +10,60 @@
|
||||||
|
|
||||||
namespace Tests\Settings\Controller;
|
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
|
* @package Tests\Settings\Controller
|
||||||
*/
|
*/
|
||||||
class MailSettingsControllerTest extends \Test\TestCase {
|
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() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$app = new Application();
|
$this->l = $this->createMock(IL10N::class);
|
||||||
$this->container = $app->getContainer();
|
$this->config = $this->createMock(IConfig::class);
|
||||||
$this->container['Config'] = $this->getMockBuilder('\OCP\IConfig')
|
$this->userSession = $this->createMock(IUserSession::class);
|
||||||
->disableOriginalConstructor()->getMock();
|
$this->mailer = $this->createMock(IMailer::class);
|
||||||
$this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N')
|
// $this->mailer = $this->getMockBuilder(IMailer::class)
|
||||||
->disableOriginalConstructor()->getMock();
|
// ->setMethods(['send'])
|
||||||
$this->container['AppName'] = 'settings';
|
// ->getMock();
|
||||||
$this->container['UserSession'] = $this->getMockBuilder('\OC\User\Session')
|
$this->mailController = new MailSettingsController(
|
||||||
->disableOriginalConstructor()->getMock();
|
'settings',
|
||||||
$this->container['MailMessage'] = $this->getMockBuilder('\OCP\Mail\IMessage')
|
$this->createMock(IRequest::class),
|
||||||
->disableOriginalConstructor()->getMock();
|
$this->l,
|
||||||
$this->container['Mailer'] = $this->getMockBuilder('\OC\Mail\Mailer')
|
$this->config,
|
||||||
->setMethods(['send'])
|
$this->userSession,
|
||||||
->disableOriginalConstructor()->getMock();
|
$this->mailer,
|
||||||
$this->container['Defaults'] = $this->getMockBuilder('\OC_Defaults')
|
'no-reply@owncloud.com'
|
||||||
->disableOriginalConstructor()->getMock();
|
);
|
||||||
$this->container['DefaultMailAddress'] = 'no-reply@owncloud.com';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetMailSettings() {
|
public function testSetMailSettings() {
|
||||||
$this->container['L10N']
|
$this->l
|
||||||
->expects($this->exactly(2))
|
->expects($this->exactly(2))
|
||||||
->method('t')
|
->method('t')
|
||||||
->will($this->returnValue('Saved'));
|
->will($this->returnValue('Saved'));
|
||||||
|
|
||||||
/**
|
$this->config->expects($this->exactly(2))
|
||||||
* FIXME: Use the following block once Jenkins uses PHPUnit >= 4.1
|
->method('setSystemValues')
|
||||||
*/
|
|
||||||
/*
|
|
||||||
$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
|
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
[[
|
[[
|
||||||
'mail_domain' => 'owncloud.com',
|
'mail_domain' => 'owncloud.com',
|
||||||
|
@ -103,10 +88,9 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
||||||
'mail_smtppassword' => null,
|
'mail_smtppassword' => null,
|
||||||
]]
|
]]
|
||||||
);
|
);
|
||||||
*/
|
|
||||||
|
|
||||||
// With authentication
|
// With authentication
|
||||||
$response = $this->container['MailSettingsController']->setMailSettings(
|
$response = $this->mailController->setMailSettings(
|
||||||
'owncloud.com',
|
'owncloud.com',
|
||||||
'demo@owncloud.com',
|
'demo@owncloud.com',
|
||||||
'smtp',
|
'smtp',
|
||||||
|
@ -120,7 +104,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
||||||
$this->assertSame($expectedResponse, $response);
|
$this->assertSame($expectedResponse, $response);
|
||||||
|
|
||||||
// Without authentication (testing the deletion of the stored password)
|
// Without authentication (testing the deletion of the stored password)
|
||||||
$response = $this->container['MailSettingsController']->setMailSettings(
|
$response = $this->mailController->setMailSettings(
|
||||||
'owncloud.com',
|
'owncloud.com',
|
||||||
'demo@owncloud.com',
|
'demo@owncloud.com',
|
||||||
'smtp',
|
'smtp',
|
||||||
|
@ -136,12 +120,12 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStoreCredentials() {
|
public function testStoreCredentials() {
|
||||||
$this->container['L10N']
|
$this->l
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('t')
|
->method('t')
|
||||||
->will($this->returnValue('Saved'));
|
->will($this->returnValue('Saved'));
|
||||||
|
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('setSystemValues')
|
->method('setSystemValues')
|
||||||
->with([
|
->with([
|
||||||
|
@ -149,7 +133,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
||||||
'mail_smtppassword' => 'PasswordToStore',
|
'mail_smtppassword' => 'PasswordToStore',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = $this->container['MailSettingsController']->storeCredentials('UsernameToStore', 'PasswordToStore');
|
$response = $this->mailController->storeCredentials('UsernameToStore', 'PasswordToStore');
|
||||||
$expectedResponse = array('data' => array('message' =>'Saved'), 'status' => 'success');
|
$expectedResponse = array('data' => array('message' =>'Saved'), 'status' => 'success');
|
||||||
|
|
||||||
$this->assertSame($expectedResponse, $response);
|
$this->assertSame($expectedResponse, $response);
|
||||||
|
@ -166,7 +150,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
||||||
->method('getDisplayName')
|
->method('getDisplayName')
|
||||||
->will($this->returnValue('Werner Brösel'));
|
->will($this->returnValue('Werner Brösel'));
|
||||||
|
|
||||||
$this->container['L10N']
|
$this->l
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
->method('t')
|
->method('t')
|
||||||
->will(
|
->will(
|
||||||
|
@ -182,22 +166,25 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
||||||
'If you received this email, the settings seem to be correct.')
|
'If you received this email, the settings seem to be correct.')
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
$this->container['UserSession']
|
$this->userSession
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
->method('getUser')
|
->method('getUser')
|
||||||
->will($this->returnValue($user));
|
->will($this->returnValue($user));
|
||||||
|
|
||||||
// Ensure that it fails when no mail address has been specified
|
// 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');
|
$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);
|
$this->assertSame($expectedResponse, $response);
|
||||||
|
|
||||||
// If no exception is thrown it should work
|
// If no exception is thrown it should work
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
->method('getUserValue')
|
->method('getUserValue')
|
||||||
->will($this->returnValue('mail@example.invalid'));
|
->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');
|
$expectedResponse = array('data' => array('message' =>'Email sent'), 'status' => 'success');
|
||||||
$this->assertSame($expectedResponse, $response);
|
$this->assertSame($expectedResponse, $response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,33 +11,37 @@ namespace Tests\Settings\Controller;
|
||||||
|
|
||||||
use \OC\Settings\Application;
|
use \OC\Settings\Application;
|
||||||
use OC\Settings\Controller\SecuritySettingsController;
|
use OC\Settings\Controller\SecuritySettingsController;
|
||||||
|
use OCP\IConfig;
|
||||||
|
use OCP\IRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package Tests\Settings\Controller
|
* @package Tests\Settings\Controller
|
||||||
*/
|
*/
|
||||||
class SecuritySettingsControllerTest extends \PHPUnit_Framework_TestCase {
|
class SecuritySettingsControllerTest extends \Test\TestCase {
|
||||||
|
|
||||||
/** @var \OCP\AppFramework\IAppContainer */
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $container;
|
private $config;
|
||||||
|
|
||||||
/** @var SecuritySettingsController */
|
/** @var SecuritySettingsController */
|
||||||
private $securitySettingsController;
|
private $securitySettingsController;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
$app = new Application();
|
parent::setUp();
|
||||||
$this->container = $app->getContainer();
|
|
||||||
$this->container['Config'] = $this->getMockBuilder('\OCP\IConfig')
|
$this->config = $this->createMock(IConfig::class);
|
||||||
->disableOriginalConstructor()->getMock();
|
$this->securitySettingsController = new SecuritySettingsController(
|
||||||
$this->container['AppName'] = 'settings';
|
'settings',
|
||||||
$this->securitySettingsController = $this->container['SecuritySettingsController'];
|
$this->createMock(IRequest::class),
|
||||||
|
$this->config
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTrustedDomainsWithExistingValues() {
|
public function testTrustedDomainsWithExistingValues() {
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('setSystemValue')
|
->method('setSystemValue')
|
||||||
->with('trusted_domains', array('owncloud.org', 'owncloud.com', 'newdomain.com'));
|
->with('trusted_domains', array('owncloud.org', 'owncloud.com', 'newdomain.com'));
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getSystemValue')
|
->method('getSystemValue')
|
||||||
->with('trusted_domains')
|
->with('trusted_domains')
|
||||||
|
@ -50,11 +54,11 @@ class SecuritySettingsControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTrustedDomainsEmpty() {
|
public function testTrustedDomainsEmpty() {
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('setSystemValue')
|
->method('setSystemValue')
|
||||||
->with('trusted_domains', array('newdomain.com'));
|
->with('trusted_domains', array('newdomain.com'));
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getSystemValue')
|
->method('getSystemValue')
|
||||||
->with($this->equalTo('trusted_domains'), $this->equalTo([]))
|
->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;
|
private $controller;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
|
parent::setUp();
|
||||||
$this->reflector = $this->getMockBuilder('\OC\AppFramework\Utility\ControllerMethodReflector')
|
$this->reflector = $this->getMockBuilder('\OC\AppFramework\Utility\ControllerMethodReflector')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->controller = $this->getMockBuilder('\OCP\AppFramework\Controller')
|
$this->controller = $this->getMockBuilder('\OCP\AppFramework\Controller')
|
||||||
|
|
Loading…
Reference in New Issue