summaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api
diff options
context:
space:
mode:
authorzulan <git@zulan.net>2018-09-24 22:54:57 +0200
committerzulan <git@zulan.net>2018-10-15 19:01:46 +0200
commitcf266ee00491bc0e70fbbb7dc9720a9e2f8c3708 (patch)
tree54778b79b3db543bd6d2fad3af02fe51afdb1ce9 /apps/provisioning_api
parent50a280338e22f34e66f03c1c069fffbf32c912b2 (diff)
downloadnextcloud-server-cf266ee00491bc0e70fbbb7dc9720a9e2f8c3708.tar.gz
nextcloud-server-cf266ee00491bc0e70fbbb7dc9720a9e2f8c3708.zip
Get l10n within NewUserMailHelper to ensure it always uses the new user's language.
Some related tests had to be changed because they relied on internals, see also from the PHPUnit documentation: "Exercise caution when using [the at] matcher as it can lead to brittle tests which are too closely tied to specific implementation details." Signed-off-by: Zulan <git@zulan.net>
Diffstat (limited to 'apps/provisioning_api')
-rw-r--r--apps/provisioning_api/lib/AppInfo/Application.php2
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php8
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php69
3 files changed, 4 insertions, 75 deletions
diff --git a/apps/provisioning_api/lib/AppInfo/Application.php b/apps/provisioning_api/lib/AppInfo/Application.php
index b7a93d6fb13..7e9e04978fe 100644
--- a/apps/provisioning_api/lib/AppInfo/Application.php
+++ b/apps/provisioning_api/lib/AppInfo/Application.php
@@ -43,7 +43,7 @@ class Application extends App {
return new NewUserMailHelper(
$server->query(Defaults::class),
$server->getURLGenerator(),
- $server->getL10N('settings'),
+ $server->getL10NFactory(),
$server->getMailer(),
$server->getSecureRandom(),
new TimeFactory(),
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php
index 9aa32e1186a..27d66a83c81 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -894,16 +894,8 @@ class UsersController extends AUserData {
if ($email === '' || $email === null) {
throw new OCSException('Email address not available', 101);
}
- $username = $targetUser->getUID();
- $lang = $this->config->getUserValue($username, 'core', 'lang', 'en');
- if (!$this->l10nFactory->languageExists('settings', $lang)) {
- $lang = 'en';
- }
-
- $l10n = $this->l10nFactory->get('settings', $lang);
try {
- $this->newUserMailHelper->setL10N($l10n);
$emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false);
$this->newUserMailHelper->sendMail($targetUser, $emailTemplate);
} catch(\Exception $e) {
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
index adbdb9d8685..57283e11912 100644
--- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
@@ -3257,35 +3257,13 @@ class UsersControllerTest extends TestCase {
->expects($this->once())
->method('getEmailAddress')
->will($this->returnValue('abc@example.org'));
- $this->config
- ->expects($this->at(0))
- ->method('getUserValue')
- ->with('user-id', 'core', 'lang')
- ->willReturn('es');
- $l10n = $this->getMockBuilder(IL10N::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->l10nFactory
- ->expects($this->at(0))
- ->method('languageExists')
- ->with('settings', 'es')
- ->willReturn(true);
- $this->l10nFactory
- ->expects($this->at(1))
- ->method('get')
- ->with('settings', 'es')
- ->willReturn($l10n);
$emailTemplate = $this->createMock(IEMailTemplate::class);
$this->newUserMailHelper
->expects($this->at(0))
- ->method('setL10N')
- ->willReturn($l10n);
- $this->newUserMailHelper
- ->expects($this->at(1))
->method('generateTemplate')
->willReturn($emailTemplate);
$this->newUserMailHelper
- ->expects($this->at(2))
+ ->expects($this->at(1))
->method('sendMail')
->with($targetUser, $emailTemplate);
@@ -3327,35 +3305,16 @@ class UsersControllerTest extends TestCase {
->expects($this->once())
->method('getEmailAddress')
->will($this->returnValue('abc@example.org'));
- $this->config
- ->expects($this->at(0))
- ->method('getUserValue')
- ->with('user-id', 'core', 'lang')
- ->willReturn('es');
$l10n = $this->getMockBuilder(IL10N::class)
->disableOriginalConstructor()
->getMock();
- $this->l10nFactory
- ->expects($this->at(0))
- ->method('languageExists')
- ->with('settings', 'es')
- ->willReturn(false);
- $this->l10nFactory
- ->expects($this->at(1))
- ->method('get')
- ->with('settings', 'en')
- ->willReturn($l10n);
$emailTemplate = $this->createMock(IEMailTemplate::class);
$this->newUserMailHelper
->expects($this->at(0))
- ->method('setL10N')
- ->willReturn($l10n);
- $this->newUserMailHelper
- ->expects($this->at(1))
->method('generateTemplate')
->willReturn($emailTemplate);
$this->newUserMailHelper
- ->expects($this->at(2))
+ ->expects($this->at(1))
->method('sendMail')
->with($targetUser, $emailTemplate);
@@ -3402,35 +3361,13 @@ class UsersControllerTest extends TestCase {
->expects($this->once())
->method('getEmailAddress')
->will($this->returnValue('abc@example.org'));
- $this->config
- ->expects($this->at(0))
- ->method('getUserValue')
- ->with('user-id', 'core', 'lang')
- ->willReturn('es');
- $l10n = $this->getMockBuilder(IL10N::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->l10nFactory
- ->expects($this->at(0))
- ->method('languageExists')
- ->with('settings', 'es')
- ->willReturn(true);
- $this->l10nFactory
- ->expects($this->at(1))
- ->method('get')
- ->with('settings', 'es')
- ->willReturn($l10n);
$emailTemplate = $this->createMock(IEMailTemplate::class);
$this->newUserMailHelper
->expects($this->at(0))
- ->method('setL10N')
- ->willReturn($l10n);
- $this->newUserMailHelper
- ->expects($this->at(1))
->method('generateTemplate')
->willReturn($emailTemplate);
$this->newUserMailHelper
- ->expects($this->at(2))
+ ->expects($this->at(1))
->method('sendMail')
->with($targetUser, $emailTemplate)
->willThrowException(new \Exception());