Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Migration/Mapping/Lookup/LanguageLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public function get(string $localeCode, Context $context): ?string

$language = $this->getLanguage($localeUuid, $context);
if (!$language instanceof LanguageEntity) {
$this->cache[$localeCode] = null;

return null;
}

Expand Down
49 changes: 49 additions & 0 deletions tests/Migration/Mapping/Lookup/LanguageLookupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,55 @@ public function testGetShouldGetDataFromCache(string $localeCode, ?string $expec
static::assertSame($expectedResult, $documentTypeLookup->get($localeCode, Context::createDefaultContext()));
}

public function testGetDoesNotCacheMissingLanguage(): void
{
$context = Context::createDefaultContext();

$languageRepository = static::getContainer()->get('language.repository');
$localeRepository = static::getContainer()->get('locale.repository');

$localeId = Uuid::randomHex();
$localeCode = 'zz-ZZ';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix the failing test:

Suggested change
$localeCode = 'zz-ZZ';
$localeCode = 'en-US-' . Uuid::randomHex();

(zz-ZZ is rejected by the stricter locale validation introduced in shopware/shopware#16285)

$languageId = Uuid::randomHex();

try {
$localeRepository->create([
[
'id' => $localeId,
'code' => $localeCode,
'name' => 'Test Locale',
'territory' => 'Test Territory',
],
], $context);

$languageLookup = new LanguageLookup(
$languageRepository,
new LocaleLookup($localeRepository)
);

static::assertNull($languageLookup->get($localeCode, $context));

$languageRepository->create([
[
'id' => $languageId,
'name' => 'Test language',
'localeId' => $localeId,
'translationCodeId' => $localeId,
],
], $context);

static::assertSame($languageId, $languageLookup->get($localeCode, $context));
} finally {
$languageRepository->delete([
['id' => $languageId],
], $context);

$localeRepository->delete([
['id' => $localeId],
], $context);
}
}

#[DataProvider('getLanguageIdData')]
public function testGetDefaultLanguageEntity(string $languageId, ?string $expectedResult): void
{
Expand Down
Loading