Skip to content

Commit

Permalink
OXDEV-8215 Implemented default language case
Browse files Browse the repository at this point in the history
  • Loading branch information
RahatHameed committed Jul 4, 2024
1 parent 6ed519d commit 7cb9dcc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/Shared/Service/LanguageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public function filterByLanguageAbbreviation(array $data): ?string
$langId = $this->language->getBaseLanguage();
$languageAbbr = $this->language->getLanguageAbbr(langId: $langId);

return $data[$languageAbbr] ?? null;
if (isset($data[$languageAbbr])) {
return $data[$languageAbbr];
}

if (isset($data['en'])) {
return $data['en'];
}

return null;
}
}
3 changes: 0 additions & 3 deletions tests/Unit/Shared/Core/LanguageWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
use PHPUnit\Framework\TestCase;
use OxidEsales\Eshop\Core\Language;

/**
* @covers \OxidEsales\GraphQL\ConfigurationAccess\Shared\Core\LanguageWrapper;
*/
class LanguageWrapperTest extends TestCase
{
public function testGetBaseLanguage(): void
Expand Down
20 changes: 16 additions & 4 deletions tests/Unit/Shared/Service/LanguageServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
use OxidEsales\GraphQL\ConfigurationAccess\Shared\Service\LanguageService;
use PHPUnit\Framework\TestCase;

/**
* @covers \OxidEsales\GraphQL\ConfigurationAccess\Shared\Service\LanguageService;
*/
class LanguageServiceTest extends TestCase
{
public function testFilterByLanguageAbbreviationCorrectLangValue()
Expand All @@ -36,8 +33,9 @@ public function testFilterByLanguageAbbreviationCorrectLangValue()
$this->assertSame($actualResult, $expectedResult);
}

public function testFilterByLanguageAbbreviationWrongLangValue()
public function testFilterByLanguageAbbreviationDefaultedToEnglish()
{
$expectedResult = "Title in en language";
$titlesData = [
'de' => 'Title in de language',
'en' => 'Title in en language',
Expand All @@ -50,6 +48,20 @@ public function testFilterByLanguageAbbreviationWrongLangValue()
$languageService = new LanguageService($languageWrapperMock);
$actualResult = $languageService->filterByLanguageAbbreviation($titlesData);

$this->assertSame($expectedResult, $actualResult);
}

public function testFilterByLanguageAbbreviationReturnNull(): void
{
$titlesData = [];

$languageWrapperMock = $this->createMock(LanguageWrapperInterface::class);
$languageWrapperMock->method('getBaseLanguage')->willReturn(1);
$languageWrapperMock->method('getLanguageAbbr')->with(1)->willReturn('de');

$languageService = new LanguageService($languageWrapperMock);
$actualResult = $languageService->filterByLanguageAbbreviation($titlesData);

$this->assertNull($actualResult);
}
}

0 comments on commit 7cb9dcc

Please sign in to comment.