-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
211 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ public function testGetPanel() { | |
$this->assertContains('[email protected]', $templateHtml); | ||
$this->assertContains('<div id="groups" class="section">', $templateHtml); | ||
$this->assertContains('group2', $templateHtml); | ||
$this->assertContains('<form id="language" class="section">', $templateHtml); | ||
$this->assertContains('<select id="languageinput" name="lang"', $templateHtml); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
/** | ||
* @author Viktar Dubiniuk <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2018, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace Test\Helper; | ||
|
||
use OC\Helper\LocaleHelper; | ||
use OCP\IL10N; | ||
use OCP\L10N\IFactory; | ||
use Test\TestCase; | ||
|
||
/** | ||
* Class LocaleHelperTest | ||
* | ||
* @package Test\Helper | ||
*/ | ||
class LocaleHelperTest extends TestCase { | ||
/** | ||
* @var LocaleHelper | ||
*/ | ||
protected $localeHelper; | ||
|
||
protected function setUp() { | ||
parent::setUp(); | ||
$this->localeHelper = new LocaleHelper(); | ||
} | ||
|
||
public function langDataProvider() { | ||
return [ | ||
[ | ||
[ 'hi', 'ro', 'php', 'de', 'java' ], | ||
'en', | ||
// en was omited in the available lang list above. it will have | ||
// no translation and will not be available for selection | ||
[ | ||
'code' => 'en', | ||
'name' => 'en', | ||
], | ||
// Only de is common. en was omitted in the available lang list above | ||
[ | ||
3 => [ | ||
'code' => 'de', | ||
'name' => 'de', | ||
] | ||
], | ||
// sorted by name alphabetically but if code was not resolved | ||
// to name the item should has less priority | ||
[ | ||
[ | ||
'code' => 'ro', | ||
'name' => 'română', | ||
], | ||
[ | ||
'code' => 'hi', | ||
'name' => 'हिन्दी', | ||
], | ||
[ | ||
'code' => 'java', | ||
'name' => 'java', | ||
], | ||
[ | ||
'code' => 'php', | ||
'name' => 'php', | ||
], | ||
] | ||
], | ||
[ | ||
[ 'hi', 'ro', 'php', 'de', 'java', 'en'], | ||
'ro', | ||
// Now we have ro in a list. It will be translated | ||
[ | ||
'code' => 'ro', | ||
'name' => 'română', | ||
], | ||
// de and en are common. en should go first | ||
[ | ||
0 => [ | ||
'code' => 'en', | ||
'name' => 'English', | ||
], | ||
3 => [ | ||
'code' => 'de', | ||
'name' => 'de', | ||
] | ||
], | ||
// sorted by name alphabetically but if code was not resolved | ||
// to name the item should has less priority | ||
[ | ||
[ | ||
'code' => 'hi', | ||
'name' => 'हिन्दी', | ||
], | ||
[ | ||
'code' => 'java', | ||
'name' => 'java', | ||
], | ||
[ | ||
'code' => 'php', | ||
'name' => 'php', | ||
], | ||
] | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider langDataProvider | ||
*/ | ||
public function testNormalization($availableCodes, | ||
$currentCode, | ||
$expectedUserLang, | ||
$expectedCommonLanguages, | ||
$expectedLanguages | ||
) { | ||
$l10n = $this->createMock(IL10N::class); | ||
|
||
$langFactory = $this->createMock(IFactory::class); | ||
$langFactory->expects($this->any()) | ||
->method('findAvailableLanguages') | ||
->willReturn($availableCodes); | ||
$langFactory->expects($this->any()) | ||
->method('get') | ||
->willReturn($l10n); | ||
|
||
list( | ||
$userLang, | ||
$commonLanguages, | ||
$languages | ||
) = $this->localeHelper->getNormalizedLanguages($langFactory, $currentCode); | ||
$this->assertEquals($expectedUserLang, $userLang); | ||
$this->assertEquals($expectedCommonLanguages, $commonLanguages); | ||
$this->assertEquals($expectedLanguages, $languages); | ||
} | ||
} |