Skip to content

Commit

Permalink
IBX-7462: Removed "Top Level Nodes" from breadcrumbs in search sugges…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
adamwojs committed Dec 25, 2023
1 parent f252988 commit d0e9279
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
7 changes: 7 additions & 0 deletions src/lib/Mapper/SearchHitToContentSuggestionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

final class SearchHitToContentSuggestionMapper implements SearchHitToContentSuggestionMapperInterface
{
private const ROOT_LOCATION_ID = 1;

private ConfigResolverInterface $configResolver;

private ParentLocationProviderInterface $parentLocationProvider;
Expand Down Expand Up @@ -51,6 +53,11 @@ public function map(SearchHit $searchHit): ?ContentSuggestion
$parentsLocation = array_slice($parentsLocation, (int)$position);
}

if (reset($parentsLocation) === self::ROOT_LOCATION_ID) {
// Remove "Top Level Nodes" from suggestion path
array_shift($parentsLocation);
}

$parentLocations = $this->parentLocationProvider->provide($parentsLocation);

return new ContentSuggestion(
Expand Down
61 changes: 46 additions & 15 deletions tests/lib/Mapper/SearchHitToContentSuggestionMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,51 @@ public function testMap(): void
$this->getConfigResolverMock()
);

$content = new Content([
$content = $this->createContentWithLocationPath(['1', '2', '3', '4', '5', '6', '7']);

$result = $mapper->map(
new SearchHit([
'valueObject' => $content,
])
);

self::assertInstanceOf(ContentSuggestion::class, $result);
self::assertSame($content, $result->getContent());
self::assertSame('5/6/7', $result->getPathString());
self::assertCount(3, $result->getParentsLocation());
self::assertSame('name_eng', $result->getName());
self::assertSame(50.0, $result->getScore());
}

public function testMapContentOutsideRootLocation(): void
{
$mapper = new SearchHitToContentSuggestionMapper(
$this->getParentLocationProviderMock(),
$this->getConfigResolverMock()
);

$content = $this->createContentWithLocationPath(['1', '2', '3', '4', '6', '7']);

$result = $mapper->map(
new SearchHit([
'valueObject' => $content,
])
);

self::assertInstanceOf(ContentSuggestion::class, $result);
self::assertSame($content, $result->getContent());
self::assertSame('2/3/4/6/7', $result->getPathString());
self::assertCount(5, $result->getParentsLocation());
self::assertSame('name_eng', $result->getName());
self::assertSame(50.0, $result->getScore());
}

/**
* @param string[] $path
*/
private function createContentWithLocationPath(array $path): Content
{
return new Content([
'id' => 1,
'contentInfo' => new ContentInfo([
'name' => 'name',
Expand All @@ -46,27 +90,14 @@ public function testMap(): void
'contentTypeId' => 1,
'mainLocation' => new Location([
'id' => 8,
'path' => ['1', '2', '3', '4', '5', '6', '7'],
'path' => $path,
]),
]),
]),
'contentType' => new ContentType([
'identifier' => 'content_type_identifier',
]),
]);

$result = $mapper->map(
new SearchHit([
'valueObject' => $content,
])
);

self::assertInstanceOf(ContentSuggestion::class, $result);
self::assertSame($content, $result->getContent());
self::assertSame('5/6/7', $result->getPathString());
self::assertCount(3, $result->getParentsLocation());
self::assertSame('name_eng', $result->getName());
self::assertSame(50.0, $result->getScore());
}

/**
Expand Down

0 comments on commit d0e9279

Please sign in to comment.