Merge pull request #15668 from nextcloud/fix/10832/l10n-on-settings-page

Fix l10n for SettingsManager by injecting the l10n factory
This commit is contained in:
blizzz 2019-05-22 00:50:44 +02:00 committed by GitHub
commit f739783780
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 4 deletions

View File

@ -1093,7 +1093,7 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerService('SettingsManager', function (Server $c) { $this->registerService('SettingsManager', function (Server $c) {
$manager = new \OC\Settings\Manager( $manager = new \OC\Settings\Manager(
$c->getLogger(), $c->getLogger(),
$c->getL10N('lib'), $c->getL10NFactory(),
$c->getURLGenerator(), $c->getURLGenerator(),
$c $c
); );

View File

@ -34,6 +34,7 @@ use OCP\IL10N;
use OCP\ILogger; use OCP\ILogger;
use OCP\IServerContainer; use OCP\IServerContainer;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use OCP\Settings\ISettings; use OCP\Settings\ISettings;
use OCP\Settings\IManager; use OCP\Settings\IManager;
use OCP\Settings\ISection; use OCP\Settings\ISection;
@ -46,6 +47,9 @@ class Manager implements IManager {
/** @var IL10N */ /** @var IL10N */
private $l; private $l;
/** @var IFactory */
private $l10nFactory;
/** @var IURLGenerator */ /** @var IURLGenerator */
private $url; private $url;
@ -54,12 +58,12 @@ class Manager implements IManager {
public function __construct( public function __construct(
ILogger $log, ILogger $log,
IL10N $l10n, IFactory $l10nFactory,
IURLGenerator $url, IURLGenerator $url,
IServerContainer $container IServerContainer $container
) { ) {
$this->log = $log; $this->log = $log;
$this->l = $l10n; $this->l10nFactory = $l10nFactory;
$this->url = $url; $this->url = $url;
$this->container = $container; $this->container = $container;
} }
@ -190,6 +194,10 @@ class Manager implements IManager {
* @inheritdoc * @inheritdoc
*/ */
public function getAdminSections(): array { public function getAdminSections(): array {
if ($this->l === null) {
$this->l = $this->l10nFactory->get('lib');
}
// built-in sections // built-in sections
$sections = [ $sections = [
0 => [new Section('overview', $this->l->t('Overview'), 0, $this->url->imagePath('settings', 'admin.svg'))], 0 => [new Section('overview', $this->l->t('Overview'), 0, $this->url->imagePath('settings', 'admin.svg'))],
@ -301,6 +309,10 @@ class Manager implements IManager {
* @inheritdoc * @inheritdoc
*/ */
public function getPersonalSections(): array { public function getPersonalSections(): array {
if ($this->l === null) {
$this->l = $this->l10nFactory->get('lib');
}
$sections = [ $sections = [
0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))],
5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))], 5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))],

View File

@ -33,6 +33,7 @@ use OCP\IL10N;
use OCP\ILogger; use OCP\ILogger;
use OCP\IServerContainer; use OCP\IServerContainer;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use Test\TestCase; use Test\TestCase;
class ManagerTest extends TestCase { class ManagerTest extends TestCase {
@ -43,6 +44,8 @@ class ManagerTest extends TestCase {
private $logger; private $logger;
/** @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */ /** @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */
private $l10n; private $l10n;
/** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
private $l10nFactory;
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
private $url; private $url;
/** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject */ /** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject */
@ -53,18 +56,24 @@ class ManagerTest extends TestCase {
$this->logger = $this->createMock(ILogger::class); $this->logger = $this->createMock(ILogger::class);
$this->l10n = $this->createMock(IL10N::class); $this->l10n = $this->createMock(IL10N::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->url = $this->createMock(IURLGenerator::class); $this->url = $this->createMock(IURLGenerator::class);
$this->container = $this->createMock(IServerContainer::class); $this->container = $this->createMock(IServerContainer::class);
$this->manager = new Manager( $this->manager = new Manager(
$this->logger, $this->logger,
$this->l10n, $this->l10nFactory,
$this->url, $this->url,
$this->container $this->container
); );
} }
public function testGetAdminSections() { public function testGetAdminSections() {
$this->l10nFactory
->expects($this->once())
->method('get')
->with('lib')
->willReturn($this->l10n);
$this->l10n $this->l10n
->expects($this->any()) ->expects($this->any())
->method('t') ->method('t')
@ -95,6 +104,11 @@ class ManagerTest extends TestCase {
} }
public function testGetPersonalSections() { public function testGetPersonalSections() {
$this->l10nFactory
->expects($this->once())
->method('get')
->with('lib')
->willReturn($this->l10n);
$this->l10n $this->l10n
->expects($this->any()) ->expects($this->any())
->method('t') ->method('t')
@ -119,6 +133,11 @@ class ManagerTest extends TestCase {
} }
public function testGetAdminSectionsEmptySection() { public function testGetAdminSectionsEmptySection() {
$this->l10nFactory
->expects($this->once())
->method('get')
->with('lib')
->willReturn($this->l10n);
$this->l10n $this->l10n
->expects($this->any()) ->expects($this->any())
->method('t') ->method('t')
@ -146,6 +165,11 @@ class ManagerTest extends TestCase {
} }
public function testGetPersonalSectionsEmptySection() { public function testGetPersonalSectionsEmptySection() {
$this->l10nFactory
->expects($this->once())
->method('get')
->with('lib')
->willReturn($this->l10n);
$this->l10n $this->l10n
->expects($this->any()) ->expects($this->any())
->method('t') ->method('t')
@ -201,6 +225,11 @@ class ManagerTest extends TestCase {
} }
public function testSameSectionAsPersonalAndAdmin() { public function testSameSectionAsPersonalAndAdmin() {
$this->l10nFactory
->expects($this->once())
->method('get')
->with('lib')
->willReturn($this->l10n);
$this->l10n $this->l10n
->expects($this->any()) ->expects($this->any())
->method('t') ->method('t')