-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
36ee5cd
commit f4f48cf
Showing
3 changed files
with
75 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\User\UserSetting; | ||
|
||
use Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface; | ||
use Ibexa\User\Form\ChoiceList\Loader\AvailableLocaleChoiceLoader; | ||
use Ibexa\User\UserSetting\Setting\Language; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
final class LanguageTest extends TestCase | ||
{ | ||
/** @var \Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface&\PHPUnit\Framework\MockObject\MockObject */ | ||
private UserLanguagePreferenceProviderInterface $userLanguagePreferenceProvider; | ||
|
||
/** @var \Ibexa\User\Form\ChoiceList\Loader\AvailableLocaleChoiceLoader&\PHPUnit\Framework\MockObject\MockObject */ | ||
private AvailableLocaleChoiceLoader $availableLocaleChoiceLoader; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->userLanguagePreferenceProvider = $this->createMock( | ||
UserLanguagePreferenceProviderInterface::class | ||
); | ||
$this->availableLocaleChoiceLoader = $this->createMock( | ||
AvailableLocaleChoiceLoader::class | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider providerForDefaultValue | ||
* | ||
* @param string[] $availableLocales | ||
* @param string[] $preferredLocales | ||
*/ | ||
public function testGetDefaultValue( | ||
array $preferredLocales, | ||
array $availableLocales, | ||
string $expectedDefaultValue | ||
): void { | ||
$this->userLanguagePreferenceProvider->method('getPreferredLocales')->willReturn($preferredLocales); | ||
$this->availableLocaleChoiceLoader->method('getChoiceList')->willReturn($availableLocales); | ||
|
||
$language = new Language( | ||
$this->createMock(TranslatorInterface::class), | ||
$this->userLanguagePreferenceProvider, | ||
$this->availableLocaleChoiceLoader, | ||
); | ||
|
||
self::assertSame($expectedDefaultValue, $language->getDefaultValue()); | ||
} | ||
|
||
/** | ||
* @return iterable<string, array<mixed>> | ||
*/ | ||
public function providerForDefaultValue(): iterable | ||
{ | ||
yield 'intersection' => [['en_GB', 'en'], ['en', 'de', 'el', 'en_US'], 'en']; | ||
yield 'no available locale' => [['en_GB', 'en'], ['de', 'el', 'en_US'], '']; | ||
yield 'user preferred language priority' => [['en_GB', 'en', 'de'], ['de', 'en', 'el'], 'en']; | ||
} | ||
} |