diff --git a/src/Service/ResourceChannelBasedIndexName.php b/src/Service/ResourceChannelBasedIndexName.php index f9f2541..bdd998c 100644 --- a/src/Service/ResourceChannelBasedIndexName.php +++ b/src/Service/ResourceChannelBasedIndexName.php @@ -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 ) { diff --git a/test/Service/Indexer/InternalResourceIndexerTest.php b/test/Service/Indexer/InternalResourceIndexerTest.php index d4ed0ff..26cdec0 100644 --- a/test/Service/Indexer/InternalResourceIndexerTest.php +++ b/test/Service/Indexer/InternalResourceIndexerTest.php @@ -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()) diff --git a/test/Service/Indexer/SiteKit/DefaultSchema2xDocumentEnricherTest.php b/test/Service/Indexer/SiteKit/DefaultSchema2xDocumentEnricherTest.php index 5ecd1c5..b8f11ab 100644 --- a/test/Service/Indexer/SiteKit/DefaultSchema2xDocumentEnricherTest.php +++ b/test/Service/Indexer/SiteKit/DefaultSchema2xDocumentEnricherTest.php @@ -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') { @@ -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( diff --git a/test/Service/ResourceChannelBasedIndexNameTest.php b/test/Service/ResourceChannelBasedIndexNameTest.php index e80fbdd..39f341d 100644 --- a/test/Service/ResourceChannelBasedIndexNameTest.php +++ b/test/Service/ResourceChannelBasedIndexNameTest.php @@ -25,7 +25,7 @@ public function setUp(): void '', false, '', - '', + 'de_DE', '', '', '', @@ -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);