protected $logger;
/** @var L10NFactory */
- private $l10nFactory;
+ protected $l10nFactory;
/** @var IL10N[] */
private $l10ns;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\L10N\IFactory as L10NFactory;
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
foreach ($users as $user) {
$emailAddress = $user->getEMailAddress();
if ($emailAddress) {
- $lang = $this->getLangForUser($user);
+ $lang = $this->l10nFactory->getUserLanguage($user);
if ($lang) {
$emailAddresses[$emailAddress] = [
'LANG' => $lang,
return $emailAddresses;
}
- /**
- * @param IUser $user
- * @return string
- */
- private function getLangForUser(IUser $user): ?string {
- return $this->config->getUserValue($user->getUID(), 'core', 'lang', null);
- }
-
/**
* @param IL10N $l10n
* @param VEvent $vevent
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
use OCP\Mail\IMessage;
+use PHPUnit\Framework\MockObject\MockObject;
use Sabre\VObject\Component\VCalendar;
class EmailProviderTest extends AbstractNotificationProviderTest {
public const USER_EMAIL = 'frodo@hobb.it';
- /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ILogger|MockObject */
protected $logger;
- /** @var L10NFactory|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var L10NFactory|MockObject */
protected $l10nFactory;
- /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IL10N|MockObject */
protected $l10n;
- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IURLGenerator|MockObject */
protected $urlGenerator;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IConfig|MockObject */
protected $config;
- /** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IMailer|MockObject */
private $mailer;
protected function setUp(): void {
$users = [$user1, $user2, $user3, $user4];
- $this->config->expects($this->at(0))
- ->method('getUserValue')
- ->with('uid1', 'core', 'lang', null)
- ->willReturn(null);
- $this->config->expects($this->at(1))
- ->method('getUserValue')
- ->with('uid2', 'core', 'lang', null)
- ->willReturn('de');
- $this->config->expects($this->at(2))
- ->method('getUserValue')
- ->with('uid3', 'core', 'lang', null)
- ->willReturn('de');
-
$enL10N = $this->createMock(IL10N::class);
$enL10N->method('t')
->willReturnArgument(0);
$deL10N->method('l')
->willReturnArgument(0);
- $this->l10nFactory->expects($this->at(0))
+ $this->l10nFactory
+ ->method('getUserLanguage')
+ ->willReturnMap([
+ [$user1, 'en'],
+ [$user2, 'de'],
+ [$user3, 'de'],
+ ]);
+
+ $this->l10nFactory
->method('findLanguage')
- ->with()
->willReturn('en');
- $this->l10nFactory->expects($this->at(1))
- ->method('languageExists')
- ->with('dav', 'en')
- ->willReturn(true);
-
- $this->l10nFactory->expects($this->at(2))
- ->method('get')
- ->with('dav', 'en')
- ->willReturn($enL10N);
-
- $this->l10nFactory->expects($this->at(3))
+ $this->l10nFactory
->method('languageExists')
- ->with('dav', 'de')
- ->willReturn(true);
+ ->willReturnMap([
+ ['dav', 'en', true],
+ ['dav', 'de', true],
+ ]);
- $this->l10nFactory->expects($this->at(4))
+ $this->l10nFactory
->method('get')
- ->with('dav', 'de')
- ->willReturn($deL10N);
+ ->willReturnMap([
+ ['dav', 'en', null, $enL10N],
+ ['dav', 'de', null, $deL10N],
+ ]);
$template1 = $this->getTemplateMock();
$message11 = $this->getMessageMock('uid1@example.com', $template1);
$users = [$user1, $user2, $user3, $user4];
- $this->config->expects($this->at(0))
- ->method('getUserValue')
- ->with('uid1', 'core', 'lang', null)
- ->willReturn(null);
- $this->config->expects($this->at(1))
- ->method('getUserValue')
- ->with('uid2', 'core', 'lang', null)
- ->willReturn('de');
- $this->config->expects($this->at(2))
- ->method('getUserValue')
- ->with('uid3', 'core', 'lang', null)
- ->willReturn('de');
-
$enL10N = $this->createMock(IL10N::class);
$enL10N->method('t')
->willReturnArgument(0);
$deL10N->method('l')
->willReturnArgument(0);
- $this->l10nFactory->expects($this->at(0))
+ $this->l10nFactory
+ ->method('getUserLanguage')
+ ->willReturnMap([
+ [$user1, 'en'],
+ [$user2, 'de'],
+ [$user3, 'de'],
+ ]);
+
+ $this->l10nFactory
->method('findLanguage')
- ->with()
->willReturn('en');
- $this->l10nFactory->expects($this->at(1))
- ->method('languageExists')
- ->with('dav', 'de')
- ->willReturn(true);
-
- $this->l10nFactory->expects($this->at(2))
- ->method('get')
- ->with('dav', 'de')
- ->willReturn($enL10N);
-
- $this->l10nFactory->expects($this->at(3))
+ $this->l10nFactory
->method('languageExists')
- ->with('dav', 'en')
- ->willReturn(true);
+ ->willReturnMap([
+ ['dav', 'en', true],
+ ['dav', 'de', true],
+ ]);
- $this->l10nFactory->expects($this->at(4))
+ $this->l10nFactory
->method('get')
- ->with('dav', 'en')
- ->willReturn($deL10N);
+ ->willReturnMap([
+ ['dav', 'en', null, $enL10N],
+ ['dav', 'de', null, $deL10N],
+ ]);
$template1 = $this->getTemplateMock();
$message11 = $this->getMessageMock('foo1@example.org', $template1);
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
+use OCP\L10N\IFactory;
use OCP\User\Backend\ISetDisplayNameBackend;
use OCP\User\Backend\ISetPasswordBackend;
protected $userSession;
/** @var AccountManager */
protected $accountManager;
+ /** @var IFactory */
+ protected $l10nFactory;
- /**
- * @param string $appName
- * @param IRequest $request
- * @param IUserManager $userManager
- * @param IConfig $config
- * @param IGroupManager $groupManager
- * @param IUserSession $userSession
- * @param AccountManager $accountManager
- */
public function __construct(string $appName,
IRequest $request,
IUserManager $userManager,
IConfig $config,
IGroupManager $groupManager,
IUserSession $userSession,
- AccountManager $accountManager) {
+ AccountManager $accountManager,
+ IFactory $l10nFactory) {
parent::__construct($appName, $request);
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->userSession = $userSession;
$this->accountManager = $accountManager;
+ $this->l10nFactory = $l10nFactory;
}
/**
$data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value'];
$data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value'];
$data['groups'] = $gids;
- $data['language'] = $this->config->getSystemValue('force_language', $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'));
+ $data['language'] = $this->l10nFactory->getUserLanguage($targetUserObject);
$data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale');
$backend = $targetUserObject->getBackend();
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
+use OCP\L10N\IFactory;
class GroupsController extends AUserData {
/** @var ILogger */
private $logger;
- /**
- * @param string $appName
- * @param IRequest $request
- * @param IUserManager $userManager
- * @param IConfig $config
- * @param IGroupManager $groupManager
- * @param IUserSession $userSession
- * @param AccountManager $accountManager
- * @param ILogger $logger
- * @param UsersController $userController
- */
public function __construct(string $appName,
IRequest $request,
IUserManager $userManager,
IGroupManager $groupManager,
IUserSession $userSession,
AccountManager $accountManager,
+ IFactory $l10nFactory,
ILogger $logger) {
parent::__construct($appName,
$request,
$config,
$groupManager,
$userSession,
- $accountManager);
+ $accountManager,
+ $l10nFactory
+ );
$this->logger = $logger;
}
/** @var ILogger */
private $logger;
/** @var IFactory */
- private $l10nFactory;
+ protected $l10nFactory;
/** @var NewUserMailHelper */
private $newUserMailHelper;
/** @var FederatedFileSharingFactory */
/** @var RemoteWipe */
private $remoteWipe;
- /**
- * @param string $appName
- * @param IRequest $request
- * @param IUserManager $userManager
- * @param IConfig $config
- * @param IAppManager $appManager
- * @param IGroupManager $groupManager
- * @param IUserSession $userSession
- * @param AccountManager $accountManager
- * @param ILogger $logger
- * @param IFactory $l10nFactory
- * @param NewUserMailHelper $newUserMailHelper
- * @param FederatedFileSharingFactory $federatedFileSharingFactory
- * @param ISecureRandom $secureRandom
- */
public function __construct(string $appName,
IRequest $request,
IUserManager $userManager,
$config,
$groupManager,
$userSession,
- $accountManager);
+ $accountManager,
+ $l10nFactory);
$this->appManager = $appManager;
$this->logger = $logger;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
+use OCP\L10N\IFactory;
use OCP\UserInterface;
class GroupsControllerTest extends \Test\TestCase {
$this->groupManager = $this->createMock(Manager::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->accountManager = $this->createMock(AccountManager::class);
+ $this->l10nFactory = $this->createMock(IFactory::class);
$this->logger = $this->createMock(ILogger::class);
$this->subAdminManager = $this->createMock(SubAdmin::class);
$this->groupManager,
$this->userSession,
$this->accountManager,
+ $this->l10nFactory,
$this->logger
])
->setMethods(['fillStorageInfo'])
->method('getUserValue')
->with('UID', 'core', 'enabled', 'true')
->willReturn('true');
- $this->config
- ->expects($this->at(1))
- ->method('getUserValue')
- ->with('UID', 'core', 'lang')
- ->willReturn('de');
- $this->config
- ->expects($this->once())
- ->method('getSystemValue')
- ->with('force_language', 'de')
- ->willReturn('de');
$this->api
->expects($this->once())
->method('fillStorageInfo')
->method('getBackend')
->willReturn($backend);
$targetUser
- ->expects($this->exactly(6))
->method('getUID')
->willReturn('UID');
+ $this->l10nFactory
+ ->expects($this->once())
+ ->method('getUserLanguage')
+ ->with($targetUser)
+ ->willReturn('de');
+
$expected = [
'id' => 'UID',
'enabled' => true,
->method('getUserValue')
->with('UID', 'core', 'enabled', 'true')
->willReturn('true');
- $this->config
- ->expects($this->once())
- ->method('getSystemValue')
- ->with('force_language', 'da')
- ->willReturn('da');
- $this->config
- ->expects($this->at(1))
- ->method('getUserValue')
- ->with('UID', 'core', 'lang')
- ->willReturn('da');
$this->api
->expects($this->once())
->method('fillStorageInfo')
->method('getBackend')
->willReturn($backend);
$targetUser
- ->expects($this->exactly(6))
->method('getUID')
->willReturn('UID');
$this->accountManager->expects($this->any())->method('getUser')
]
);
+ $this->l10nFactory
+ ->expects($this->once())
+ ->method('getUserLanguage')
+ ->with($targetUser)
+ ->willReturn('da');
+
$expected = [
'id' => 'UID',
'enabled' => true,
->method('fillStorageInfo')
->with('UID')
->willReturn(['DummyValue']);
- $this->config
- ->expects($this->once())
- ->method('getSystemValue')
- ->with('force_language', 'ru')
- ->willReturn('ru');
$backend = $this->createMock(UserInterface::class);
$backend->expects($this->atLeastOnce())
->method('getEMailAddress')
->willReturn('subadmin@nextcloud.com');
$targetUser
- ->expects($this->exactly(6))
->method('getUID')
->willReturn('UID');
$targetUser
->expects($this->once())
->method('getBackend')
->willReturn($backend);
- $this->config
- ->expects($this->at(0))
- ->method('getUserValue')
- ->with('UID', 'core', 'lang')
- ->willReturn('ru');
$this->accountManager->expects($this->any())->method('getUser')
->with($targetUser)
->willReturn(
]
);
+ $this->l10nFactory
+ ->expects($this->once())
+ ->method('getUserLanguage')
+ ->with($targetUser)
+ ->willReturn('ru');
+
$expected = [
'id' => 'UID',
'storageLocation' => '/var/www/newtcloud/data/UID',
$subAdminManager
->expects($this->once())
->method('createSubAdmin')
- ->with($targetUser, $targetGroup)
- ->willReturn(true);
+ ->with($targetUser, $targetGroup);
$this->groupManager
->expects($this->once())
->method('getSubAdmin')
$subAdminManager
->expects($this->once())
->method('deleteSubAdmin')
- ->with($targetUser, $targetGroup)
- ->willReturn(true);
+ ->with($targetUser, $targetGroup);
$this->groupManager
->expects($this->once())
->method('getSubAdmin')
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
-use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
protected $config;
/** @var IFactory */
protected $languageFactory;
- /** @var IL10N */
- protected $l;
public function __construct(IActivityManager $activityManager,
IGroupManager $groupManager,
IURLGenerator $urlGenerator,
IMailer $mailer,
IConfig $config,
- IFactory $languageFactory,
- IL10N $l) {
+ IFactory $languageFactory) {
$this->activityManager = $activityManager;
$this->groupManager = $groupManager;
$this->userManager = $userManager;
$this->mailer = $mailer;
$this->config = $config;
$this->languageFactory = $languageFactory;
- $this->l = $l;
}
/**
->setAffectedUser($user->getUID());
$instanceUrl = $this->urlGenerator->getAbsoluteURL('/');
+ $language = $this->languageFactory->getUserLanguage($user);
+ $l = $this->languageFactory->get('settings', $language);
$actor = $this->userSession->getUser();
if ($actor instanceof IUser) {
if ($actor->getUID() !== $user->getUID()) {
// Admin changed the password through the user panel
- $this->l = $this->languageFactory->get(
- 'settings',
- $this->config->getUserValue(
- $user->getUID(), 'core', 'lang',
- $this->config->getSystemValue('default_language', 'en')
- )
- );
-
- $text = $this->l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]);
+ $text = $l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]);
$event->setAuthor($actor->getUID())
->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]);
} else {
// User changed their password themselves through settings
- $text = $this->l->t('Your password on %s was changed.', [$instanceUrl]);
+ $text = $l->t('Your password on %s was changed.', [$instanceUrl]);
$event->setAuthor($actor->getUID())
->setSubject(Provider::PASSWORD_CHANGED_SELF);
}
} else {
if (\OC::$CLI) {
// Admin used occ to reset the password
- $text = $this->l->t('Your password on %s was reset by an administrator.', [$instanceUrl]);
+ $text = $l->t('Your password on %s was reset by an administrator.', [$instanceUrl]);
$event->setSubject(Provider::PASSWORD_RESET);
} else {
// User reset their password from Lost page
- $text = $this->l->t('Your password on %s was reset.', [$instanceUrl]);
+ $text = $l->t('Your password on %s was reset.', [$instanceUrl]);
$event->setSubject(Provider::PASSWORD_RESET_SELF);
}
}
'instanceUrl' => $instanceUrl,
]);
- $template->setSubject($this->l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl]));
+ $template->setSubject($l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl]));
$template->addHeader();
- $template->addHeading($this->l->t('Password changed for %s', [$user->getDisplayName()]), false);
- $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.'));
+ $template->addHeading($l->t('Password changed for %s', [$user->getDisplayName()]), false);
+ $template->addBodyText($text . ' ' . $l->t('If you did not request this, please contact an administrator.'));
$template->addFooter();
->setAffectedUser($user->getUID());
$instanceUrl = $this->urlGenerator->getAbsoluteURL('/');
+ $language = $this->languageFactory->getUserLanguage($user);
+ $l = $this->languageFactory->get('settings', $language);
$actor = $this->userSession->getUser();
if ($actor instanceof IUser) {
$subject = Provider::EMAIL_CHANGED_SELF;
if ($actor->getUID() !== $user->getUID()) {
- $this->l = $this->languageFactory->get(
- 'settings',
- $this->config->getUserValue(
- $user->getUID(), 'core', 'lang',
- $this->config->getSystemValue('default_language', 'en')
- )
- );
$subject = Provider::EMAIL_CHANGED;
}
- $text = $this->l->t('Your email address on %s was changed.', [$instanceUrl]);
+ $text = $l->t('Your email address on %s was changed.', [$instanceUrl]);
$event->setAuthor($actor->getUID())
->setSubject($subject);
} else {
- $text = $this->l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]);
+ $text = $l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]);
$event->setSubject(Provider::EMAIL_CHANGED);
}
$this->activityManager->publish($event);
'instanceUrl' => $instanceUrl,
]);
- $template->setSubject($this->l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl]));
+ $template->setSubject($l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl]));
$template->addHeader();
- $template->addHeading($this->l->t('Email address changed for %s', [$user->getDisplayName()]), false);
- $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.'));
+ $template->addHeading($l->t('Email address changed for %s', [$user->getDisplayName()]), false);
+ $template->addBodyText($text . ' ' . $l->t('If you did not request this, please contact an administrator.'));
if ($user->getEMailAddress()) {
- $template->addBodyText($this->l->t('The new email address is %s', [$user->getEMailAddress()]));
+ $template->addBodyText($l->t('The new email address is %s', [$user->getEMailAddress()]));
}
$template->addFooter();
*/
public function generateTemplate(IUser $user, $generatePasswordResetToken = false) {
$userId = $user->getUID();
- $lang = $this->config->getUserValue($userId, 'core', 'lang', 'en');
- if (!$this->l10nFactory->languageExists('settings', $lang)) {
- $lang = 'en';
- }
-
+ $lang = $this->l10nFactory->getUserLanguage($user);
$l10n = $this->l10nFactory->get('settings', $lang);
if ($generatePasswordResetToken) {
/** @var IUser $recipient */
$email = $recipient->getEMailAddress();
if ($email) {
- $language = $this->config->getSystemValue('force_language', false);
- $language = \is_string($language) ? $language : $this->config->getUserValue($recipient->getUID(), 'core', 'lang', null);
- $language = $language ?? $this->config->getSystemValue('default_language', 'en');
-
+ $language = $this->l10nFactory->getUserLanguage($recipient);
if (!isset($toListByLanguage[$language])) {
$toListByLanguage[$language] = [];
}
if ($user !== null) {
$emailAddress = $user->getEMailAddress();
if ($emailAddress !== null && $emailAddress !== '') {
- $userLang = $this->config->getUserValue($share->getSharedWith(), 'core', 'lang', null);
+ $userLang = $this->l10nFactory->getUserLanguage($user);
$l = $this->l10nFactory->get('lib', $userLang);
$this->sendMailNotification(
$l,