summaryrefslogtreecommitdiffstats
path: root/tests/lib/l10n
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2016-01-27 15:54:57 +0100
committerLukas Reschke <lukas@owncloud.com>2016-01-27 18:30:18 +0100
commitcb1a64b94935b76f877696cbb028271862228464 (patch)
treed4152cb688105fe8d5a62facf5105db5b64eb4ca /tests/lib/l10n
parent816c23c17a71443d8774107d54ada8bda7486f32 (diff)
downloadnextcloud-server-cb1a64b94935b76f877696cbb028271862228464.tar.gz
nextcloud-server-cb1a64b94935b76f877696cbb028271862228464.zip
Check whether ownCloud is installed
ownCloud might not yet be setup. This causes an issue as the user config requires a setup ownCloud. Thus this needs a block whether ownCloud is installed or not. Fixes https://github.com/owncloud/core/issues/21955
Diffstat (limited to 'tests/lib/l10n')
-rw-r--r--tests/lib/l10n/factorytest.php265
-rw-r--r--tests/lib/l10n/l10nlegacytest.php2
-rw-r--r--tests/lib/l10n/l10ntest.php5
3 files changed, 195 insertions, 77 deletions
diff --git a/tests/lib/l10n/factorytest.php b/tests/lib/l10n/factorytest.php
index f632e48e2de..9f5954d0ee1 100644
--- a/tests/lib/l10n/factorytest.php
+++ b/tests/lib/l10n/factorytest.php
@@ -8,7 +8,6 @@
namespace Test\L10N;
-
use OC\L10N\Factory;
use Test\TestCase;
@@ -26,6 +25,9 @@ class FactoryTest extends TestCase {
/** @var \OCP\IRequest|\PHPUnit_Framework_MockObject_MockObject */
protected $request;
+ /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */
+ protected $userSession;
+
public function setUp() {
parent::setUp();
@@ -38,6 +40,8 @@ class FactoryTest extends TestCase {
$this->request = $this->getMockBuilder('OCP\IRequest')
->disableOriginalConstructor()
->getMock();
+
+ $this->userSession = $this->getMock('\OCP\IUserSession');
}
/**
@@ -50,98 +54,209 @@ class FactoryTest extends TestCase {
->setConstructorArgs([
$this->config,
$this->request,
+ $this->userSession
])
->setMethods($methods)
->getMock();
} else {
- return new Factory($this->config, $this->request);
+ return new Factory($this->config, $this->request, $this->userSession);
}
}
- public function dataFindLanguage() {
+ public function dataFindAvailableLanguages() {
return [
- [null, false, 1, 'de', true, null, null, null, null, null, 'de'],
- [null, 'test', 2, 'de', false, 'ru', true, null, null, null, 'ru'],
- [null, 'test', 1, '', null, 'ru', true, null, null, null, 'ru'],
- [null, 'test', 3, 'de', false, 'ru', false, 'cz', true, null, 'cz'],
- [null, 'test', 2, '', null, 'ru', false, 'cz', true, null, 'cz'],
- [null, 'test', 1, '', null, '', null, 'cz', true, null, 'cz'],
- [null, 'test', 3, 'de', false, 'ru', false, 'cz', false, 'ar', 'ar'],
- [null, 'test', 2, '', null, 'ru', false, 'cz', false, 'ar', 'ar'],
- [null, 'test', 1, '', null, '', null, 'cz', false, 'ar', 'ar'],
- [null, 'test', 0, '', null, '', null, false, null, 'ar', 'ar'],
+ [null],
+ ['files'],
];
}
- /**
- * @dataProvider dataFindLanguage
- *
- * @param string|null $app
- * @param string|null $user
- * @param int $existsCalls
- * @param string $storedRequestLang
- * @param bool $srlExists
- * @param string|null $userLang
- * @param bool $ulExists
- * @param string|false $defaultLang
- * @param bool $dlExists
- * @param string|null $requestLang
- * @param string $expected
- */
- public function testFindLanguage($app, $user, $existsCalls, $storedRequestLang, $srlExists, $userLang, $ulExists, $defaultLang, $dlExists, $requestLang, $expected) {
- $factory = $this->getFactory([
- 'languageExists',
- 'setLanguageFromRequest',
- ]);
+ public function testFindLanguageWithExistingRequestLanguageAndNoApp() {
+ $factory = $this->getFactory(['languageExists']);
+ $this->invokePrivate($factory, 'requestLanguage', ['de']);
+ $factory->expects($this->once())
+ ->method('languageExists')
+ ->with(null, 'de')
+ ->willReturn(true);
- $session = $this->getMockBuilder('OCP\ISession')
- ->disableOriginalConstructor()
- ->getMock();
- $session->expects($this->any())
- ->method('get')
- ->with('user_id')
- ->willReturn($user);
- $userSession = $this->getMockBuilder('OC\User\Session')
- ->disableOriginalConstructor()
- ->getMock();
- $userSession->expects($this->any())
- ->method('getSession')
- ->willReturn($session);
+ $this->assertSame('de', $factory->findLanguage());
+ }
+
+ public function testFindLanguageWithExistingRequestLanguageAndApp() {
+ $factory = $this->getFactory(['languageExists']);
+ $this->invokePrivate($factory, 'requestLanguage', ['de']);
+ $factory->expects($this->once())
+ ->method('languageExists')
+ ->with('MyApp', 'de')
+ ->willReturn(true);
- $this->invokePrivate($factory, 'requestLanguage', [$storedRequestLang]);
+ $this->assertSame('de', $factory->findLanguage('MyApp'));
+ }
- $factory->expects($this->exactly($existsCalls))
- ->method('languageExists')
- ->willReturnMap([
- [$app, $storedRequestLang, $srlExists],
- [$app, $userLang, $ulExists],
- [$app, $defaultLang, $dlExists],
- ]);
-
- $factory->expects($requestLang !== null ? $this->once() : $this->never())
- ->method('setLanguageFromRequest')
- ->willReturn($requestLang);
-
- $this->config->expects($userLang !== null ? $this->any() : $this->never())
- ->method('getUserValue')
- ->with($this->anything(), 'core', 'lang')
- ->willReturn($userLang);
-
- $this->config->expects($defaultLang !== null ? $this->once() : $this->never())
+ public function testFindLanguageWithNotExistingRequestLanguageAndExistingStoredUserLanguage() {
+ $factory = $this->getFactory(['languageExists']);
+ $this->invokePrivate($factory, 'requestLanguage', ['de']);
+ $factory->expects($this->at(0))
+ ->method('languageExists')
+ ->with('MyApp', 'de')
+ ->willReturn(false);
+ $this->config
+ ->expects($this->once())
->method('getSystemValue')
- ->with('default_language', false)
- ->willReturn($defaultLang);
+ ->with('installed', false)
+ ->willReturn(true);
+ $user = $this->getMock('\OCP\IUser');
+ $user->expects($this->once())
+ ->method('getUID')
+ ->willReturn('MyUserUid');
+ $this->userSession
+ ->expects($this->exactly(2))
+ ->method('getUser')
+ ->willReturn($user);
+ $this->config
+ ->expects($this->once())
+ ->method('getUserValue')
+ ->with('MyUserUid', 'core', 'lang', null)
+ ->willReturn('jp');
+ $factory->expects($this->at(1))
+ ->method('languageExists')
+ ->with('MyApp', 'jp')
+ ->willReturn(true);
+
+ $this->assertSame('jp', $factory->findLanguage('MyApp'));
+ }
- $this->overwriteService('UserSession', $userSession);
- $this->assertSame($expected, $factory->findLanguage($app));
- $this->restoreService('UserSession');
+ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStoredUserLanguage() {
+ $factory = $this->getFactory(['languageExists']);
+ $this->invokePrivate($factory, 'requestLanguage', ['de']);
+ $factory->expects($this->at(0))
+ ->method('languageExists')
+ ->with('MyApp', 'de')
+ ->willReturn(false);
+ $this->config
+ ->expects($this->at(0))
+ ->method('getSystemValue')
+ ->with('installed', false)
+ ->willReturn(true);
+ $user = $this->getMock('\OCP\IUser');
+ $user->expects($this->once())
+ ->method('getUID')
+ ->willReturn('MyUserUid');
+ $this->userSession
+ ->expects($this->exactly(2))
+ ->method('getUser')
+ ->willReturn($user);
+ $this->config
+ ->expects($this->once())
+ ->method('getUserValue')
+ ->with('MyUserUid', 'core', 'lang', null)
+ ->willReturn('jp');
+ $factory->expects($this->at(1))
+ ->method('languageExists')
+ ->with('MyApp', 'jp')
+ ->willReturn(false);
+ $this->config
+ ->expects($this->at(2))
+ ->method('getSystemValue')
+ ->with('default_language', false)
+ ->willReturn('es');
+ $factory->expects($this->at(2))
+ ->method('languageExists')
+ ->with('MyApp', 'es')
+ ->willReturn(true);
+
+ $this->assertSame('es', $factory->findLanguage('MyApp'));
}
- public function dataFindAvailableLanguages() {
- return [
- [null],
- ['files'],
- ];
+ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStoredUserLanguageAndNotExistingDefault() {
+ $factory = $this->getFactory(['languageExists']);
+ $this->invokePrivate($factory, 'requestLanguage', ['de']);
+ $factory->expects($this->at(0))
+ ->method('languageExists')
+ ->with('MyApp', 'de')
+ ->willReturn(false);
+ $this->config
+ ->expects($this->at(0))
+ ->method('getSystemValue')
+ ->with('installed', false)
+ ->willReturn(true);
+ $user = $this->getMock('\OCP\IUser');
+ $user->expects($this->once())
+ ->method('getUID')
+ ->willReturn('MyUserUid');
+ $this->userSession
+ ->expects($this->exactly(2))
+ ->method('getUser')
+ ->willReturn($user);
+ $this->config
+ ->expects($this->once())
+ ->method('getUserValue')
+ ->with('MyUserUid', 'core', 'lang', null)
+ ->willReturn('jp');
+ $factory->expects($this->at(1))
+ ->method('languageExists')
+ ->with('MyApp', 'jp')
+ ->willReturn(false);
+ $this->config
+ ->expects($this->at(2))
+ ->method('getSystemValue')
+ ->with('default_language', false)
+ ->willReturn('es');
+ $factory->expects($this->at(2))
+ ->method('languageExists')
+ ->with('MyApp', 'es')
+ ->willReturn(false);
+ $this->config
+ ->expects($this->never())
+ ->method('setUserValue');
+
+ $this->assertSame('en', $factory->findLanguage('MyApp'));
+ }
+
+ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStoredUserLanguageAndNotExistingDefaultAndNoAppInScope() {
+ $factory = $this->getFactory(['languageExists']);
+ $this->invokePrivate($factory, 'requestLanguage', ['de']);
+ $factory->expects($this->at(0))
+ ->method('languageExists')
+ ->with('MyApp', 'de')
+ ->willReturn(false);
+ $this->config
+ ->expects($this->at(0))
+ ->method('getSystemValue')
+ ->with('installed', false)
+ ->willReturn(true);
+ $user = $this->getMock('\OCP\IUser');
+ $user->expects($this->once())
+ ->method('getUID')
+ ->willReturn('MyUserUid');
+ $this->userSession
+ ->expects($this->exactly(2))
+ ->method('getUser')
+ ->willReturn($user);
+ $this->config
+ ->expects($this->once())
+ ->method('getUserValue')
+ ->with('MyUserUid', 'core', 'lang', null)
+ ->willReturn('jp');
+ $factory->expects($this->at(1))
+ ->method('languageExists')
+ ->with('MyApp', 'jp')
+ ->willReturn(false);
+ $this->config
+ ->expects($this->at(2))
+ ->method('getSystemValue')
+ ->with('default_language', false)
+ ->willReturn('es');
+ $factory->expects($this->at(2))
+ ->method('languageExists')
+ ->with('MyApp', 'es')
+ ->willReturn(false);
+ $this->config
+ ->expects($this->never())
+ ->method('setUserValue')
+ ->with('MyUserUid', 'core', 'lang', 'en');
+
+
+ $this->assertSame('en', $factory->findLanguage('MyApp'));
}
/**
diff --git a/tests/lib/l10n/l10nlegacytest.php b/tests/lib/l10n/l10nlegacytest.php
index ae84968e65d..025f761fe5c 100644
--- a/tests/lib/l10n/l10nlegacytest.php
+++ b/tests/lib/l10n/l10nlegacytest.php
@@ -124,7 +124,7 @@ class L10nLegacyTest extends \Test\TestCase {
}
public function testFactoryGetLanguageCode() {
- $factory = new \OC\L10N\Factory($this->getMock('OCP\IConfig'), $this->getMock('OCP\IRequest'));
+ $factory = new \OC\L10N\Factory($this->getMock('OCP\IConfig'), $this->getMock('OCP\IRequest'), $this->getMock('OCP\IUserSession'));
$l = $factory->get('lib', 'de');
$this->assertEquals('de', $l->getLanguageCode());
}
diff --git a/tests/lib/l10n/l10ntest.php b/tests/lib/l10n/l10ntest.php
index 95546b4f788..0d175954bc1 100644
--- a/tests/lib/l10n/l10ntest.php
+++ b/tests/lib/l10n/l10ntest.php
@@ -12,6 +12,7 @@ namespace Test\L10N;
use DateTime;
use OC\L10N\Factory;
use OC\L10N\L10N;
+use OCP\IUserSession;
use Test\TestCase;
/**
@@ -28,7 +29,9 @@ class L10nTest extends TestCase {
$config = $this->getMock('OCP\IConfig');
/** @var \OCP\IRequest $request */
$request = $this->getMock('OCP\IRequest');
- return new Factory($config, $request);
+ /** @var IUserSession $userSession */
+ $userSession = $this->getMock('OCP\IUserSession');
+ return new Factory($config, $request, $userSession);
}
public function testGermanPluralTranslations() {