Skip to content

Commit

Permalink
Merged branch '4.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
konradoboza committed Jul 17, 2023
2 parents be03c8e + 7b3f233 commit 2fb3b30
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 19 deletions.
11 changes: 11 additions & 0 deletions src/lib/MVC/Symfony/Locale/LocaleConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ public function convertToEz($posixLocale)

return $this->reverseConversionMap[$posixLocale];
}

public function convertToRepository(string $posixLocale): ?string
{
if (!isset($this->reverseConversionMap[$posixLocale])) {
$this->logger->warning("Could not convert locale '$posixLocale' to Repository format. Please check your locale configuration in ibexa.yaml");

return null;
}

return $this->reverseConversionMap[$posixLocale];
}
}

class_alias(LocaleConverter::class, 'eZ\Publish\Core\MVC\Symfony\Locale\LocaleConverter');
9 changes: 9 additions & 0 deletions src/lib/MVC/Symfony/Locale/LocaleConverterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ interface LocaleConverterInterface
* Converts a locale in Ibexa internal format to POSIX format.
* Returns null if conversion cannot be made.
*
* @deprecated use convertToRepository instead
* @see convertToRepository
*
* @param string $ezpLocale
*
* @return string|null
Expand All @@ -34,6 +37,12 @@ public function convertToPOSIX($ezpLocale);
* @return string|null
*/
public function convertToEz($posixLocale);

/**
* Converts a locale in POSIX format to Repository internal format.
* Returns null if conversion cannot be made.
*/
public function convertToRepository(string $posixLocale): ?string;
}

class_alias(LocaleConverterInterface::class, 'eZ\Publish\Core\MVC\Symfony\Locale\LocaleConverterInterface');
62 changes: 43 additions & 19 deletions tests/lib/MVC/Symfony/Locale/LocaleConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,27 @@
/**
* @covers \Ibexa\Core\MVC\Symfony\Locale\LocaleConverter
*/
class LocaleConverterTest extends TestCase
final class LocaleConverterTest extends TestCase
{
/** @var \Ibexa\Core\MVC\Symfony\Locale\LocaleConverter */
private $localeConverter;
private LocaleConverter $localeConverter;

/** @var \PHPUnit\Framework\MockObject\MockObject */
private $logger;
/** @var \Psr\Log\LoggerInterface&\PHPUnit\Framework\MockObject\MockObject */
private LoggerInterface $logger;

private $conversionMap;
/**
* @var array{
* array{
* string,
* string|null,
* }
* }
*/
private array $conversionMap;

protected function setUp(): void
{
parent::setUp();

$this->conversionMap = [
'eng-GB' => 'en_GB',
'eng-US' => 'en_US',
Expand All @@ -41,22 +49,19 @@ protected function setUp(): void

/**
* @dataProvider convertToPOSIXProvider
*
* @param $ezpLocale
* @param $expected
*/
public function testConvertToPOSIX($ezpLocale, $expected)
public function testConvertToPOSIX(string $repositoryLocale, ?string $expected): void
{
if ($expected === null) {
$this->logger
->expects($this->once())
->method('warning');
}

$this->assertSame($expected, $this->localeConverter->convertToPOSIX($ezpLocale));
self::assertSame($expected, $this->localeConverter->convertToPOSIX($repositoryLocale));
}

public function convertToPOSIXProvider()
public function convertToPOSIXProvider(): array
{
return [
['eng-GB', 'en_GB'],
Expand All @@ -69,23 +74,42 @@ public function convertToPOSIXProvider()
}

/**
* @dataProvider convertToEzProvider
*
* @param $posixLocale
* @param $expected
* @dataProvider convertToRepositoryProvider
*/
public function testConvertToEz(string $posixLocale, ?string $expected): void
{
if ($expected === null) {
$this->logger
->expects($this->once())
->method('warning');
}

self::assertSame($expected, $this->localeConverter->convertToEz($posixLocale));
}

/**
* @dataProvider convertToRepositoryProvider
*/
public function testConvertToEz($posixLocale, $expected)
public function testConvertToRepository(string $posixLocale, ?string $expected): void
{
if ($expected === null) {
$this->logger
->expects($this->once())
->method('warning');
}

$this->assertSame($expected, $this->localeConverter->convertToEz($posixLocale));
self::assertSame($expected, $this->localeConverter->convertToRepository($posixLocale));
}

public function convertToEzProvider()
/**
* @return array{
* array{
* string,
* string|null,
* }
* }
*/
public function convertToRepositoryProvider(): array
{
return [
['en_GB', 'eng-GB'],
Expand Down

0 comments on commit 2fb3b30

Please sign in to comment.