Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-7462: Removed "Top Level Nodes" from breadcrumbs in search suggestions #42

Merged
merged 1 commit into from
Apr 25, 2024
Merged
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
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);
adamwojs marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading