Skip to content

Commit

Permalink
fix: Default locale of the ResourceChannel must be taken into account…
Browse files Browse the repository at this point in the history
… when determining the index name.wrong suggests
  • Loading branch information
sitepark-veltrup committed Jun 27, 2024
1 parent 2c7fe56 commit 6e236b4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/Service/ResourceChannelBasedIndexName.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ private function langToAvailableLocale(
return '';
}

$defaultChannelLang = $resourceChannel->locale;
$sepPos = strpos($defaultChannelLang, '_');
if ($sepPos !== false) {
$defaultChannelLang = substr($defaultChannelLang, 0, $sepPos);
}
if ($lang->code === $defaultChannelLang) {
return '';
}

foreach (
$resourceChannel->translationLocales as $availableLocale
) {
Expand Down
7 changes: 7 additions & 0 deletions test/Service/Indexer/InternalResourceIndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ public function testGetIndex(): void
);
}

public function testGetStatus(): void
{
$this->indexerProgressHandler->expects($this->once())
->method('getStatus');
$this->indexer->getStatus();
}

public function testAbort(): void
{
$this->aborter->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@
use Atoolo\Search\Service\Indexer\IndexSchema2xDocument;
use Atoolo\Search\Service\Indexer\SiteKit\DefaultSchema2xDocumentEnricher;
use DateTime;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class DefaultSchema2xDocumentEnricherTest extends TestCase
{
private DefaultSchema2xDocumentEnricher $enricher;

private SiteKitNavigationHierarchyLoader&MockObject $navigationLoader;

public function setUp(): void
{
$navigationLoader = $this->createStub(
$this->navigationLoader = $this->createMock(
SiteKitNavigationHierarchyLoader::class
);
$navigationLoader
$this->navigationLoader
->method('loadRoot')
->willReturnCallback(function ($location) {
if ($location->location === 'throwException') {
Expand All @@ -41,11 +44,18 @@ public function setUp(): void
->willReturn('collected content');

$this->enricher = new DefaultSchema2xDocumentEnricher(
$navigationLoader,
$this->navigationLoader,
$contentCollector
);
}

public function testCleanup(): void
{
$this->navigationLoader->expects($this->once())
->method('cleanup');
$this->enricher->cleanup();
}

public function testEnrichSpId(): void
{
$resource = new Resource(
Expand Down
12 changes: 11 additions & 1 deletion test/Service/ResourceChannelBasedIndexNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function setUp(): void
'',
false,
'',
'',
'de_DE',
'',
'',
'',
Expand Down Expand Up @@ -68,6 +68,16 @@ public function testNameWithEmptyLang(): void
);
}

public function testNameWithResourceChannelDefaultLang(): void
{
$this->assertEquals(
'test',
$this->indexName->name(ResourceLanguage::of('de')),
'The default index name should be returned ' .
'if the default language is given'
);
}

public function testNameWithUnsupportedLang(): void
{
$this->expectException(UnsupportedIndexLanguageException::class);
Expand Down

0 comments on commit 6e236b4

Please sign in to comment.