summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-07-04 08:56:13 +0200
committerGitHub <noreply@github.com>2020-07-04 08:56:13 +0200
commit4d8b4ef3cca51012e0e0989b6cbdbc2bea8aba21 (patch)
tree8e976e52e2687ec289ce8e9f87da65dd080d01d5 /apps/dav
parent6d2c79598ad8d322a3a439f4790979672232200a (diff)
parentdb8267db26e2e81ef4a39b424c5a8ea7bc124bfd (diff)
downloadnextcloud-server-4d8b4ef3cca51012e0e0989b6cbdbc2bea8aba21.tar.gz
nextcloud-server-4d8b4ef3cca51012e0e0989b6cbdbc2bea8aba21.zip
Merge pull request #21533 from nextcloud/techdebt/noid/dedicated-method-to-get-a-users-language
Techdebt/noid/dedicated method to get a users language
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php2
-rw-r--r--apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php11
-rw-r--r--apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php113
3 files changed, 47 insertions, 79 deletions
diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php
index 5a6591fb749..d694b249e96 100644
--- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php
+++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php
@@ -54,7 +54,7 @@ abstract class AbstractProvider implements INotificationProvider {
protected $logger;
/** @var L10NFactory */
- private $l10nFactory;
+ protected $l10nFactory;
/** @var IL10N[] */
private $l10ns;
diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php
index 4152e02dc8d..90a86230ec3 100644
--- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php
+++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php
@@ -35,7 +35,6 @@ use OCP\IConfig;
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;
@@ -349,7 +348,7 @@ class EmailProvider extends AbstractProvider {
foreach ($users as $user) {
$emailAddress = $user->getEMailAddress();
if ($emailAddress) {
- $lang = $this->getLangForUser($user);
+ $lang = $this->l10nFactory->getUserLanguage($user);
if ($lang) {
$emailAddresses[$emailAddress] = [
'LANG' => $lang,
@@ -364,14 +363,6 @@ class EmailProvider extends AbstractProvider {
}
/**
- * @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
* @return string
diff --git a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php
index 9a22f63c1be..d8df7613729 100644
--- a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php
+++ b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php
@@ -40,27 +40,28 @@ use OCP\L10N\IFactory as L10NFactory;
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 {
@@ -101,19 +102,6 @@ class EmailProviderTest extends AbstractNotificationProviderTest {
$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);
@@ -126,30 +114,31 @@ class EmailProviderTest extends AbstractNotificationProviderTest {
$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);
@@ -223,19 +212,6 @@ class EmailProviderTest extends AbstractNotificationProviderTest {
$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);
@@ -248,30 +224,31 @@ class EmailProviderTest extends AbstractNotificationProviderTest {
$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);