Skip to content

Commit

Permalink
Dropped testCriterionExtendedSyntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Jan 17, 2024
1 parent e34db18 commit 71153dc
Showing 1 changed file with 21 additions and 126 deletions.
147 changes: 21 additions & 126 deletions tests/integration/Core/Repository/SearchServiceContentNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,50 +80,42 @@ public function testCriterionFindAllContentItems(): void
}

/**
* @dataProvider provideDataForTestCriterionExtendedSyntax
* @dataProvider provideDataForTestCriterion
*
* @param array<string> $expectedContentItemTitles
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidCriterionArgumentException
*/
public function testCriterionExtendedSyntax(
public function testCriterion(
Criterion $criterion,
?string $languageCode,
array $expectedContentItemTitles,
int $expectedCount
): void {
if (getenv('SEARCH_ENGINE') === 'legacy') {
self::markTestSkipped('Extended syntax is not supported in Legacy Search Engine');
}
$result = self::getSearchService()->findContent(
$this->createQuery($criterion),
$this->getLanguageFilter($languageCode)
);

$this->assertResult(
$criterion,
$languageCode,
self::assertEquals(
$expectedContentItemTitles,
$expectedCount
array_map(
static function (SearchHit $searchHit) use ($languageCode): ?string {
$content = $searchHit->valueObject;
if ($content instanceof Content) {
return $content->getName($languageCode);
}

return null;
},
$result->searchHits
)
);
}

/**
* @dataProvider provideDataForTestCriterion
*
* @param array<string> $expectedContentItemTitles
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidCriterionArgumentException
*/
public function testCriterion(
Criterion $criterion,
?string $languageCode,
array $expectedContentItemTitles,
int $expectedCount
): void {
$this->assertResult(
$criterion,
$languageCode,
$expectedContentItemTitles,
$expectedCount
self::assertSame(
$expectedCount,
$result->totalCount
);
}

Expand Down Expand Up @@ -219,64 +211,6 @@ public function provideDataForTestCriterion(): iterable
];
}

/**
* @return iterable<array{
* \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion,
* ?string,
* array<string>,
* int,
* }>
*/
public function provideDataForTestCriterionExtendedSyntax(): iterable
{
yield 'No content items found with "car" and "truck" in name' => [
$this->createContentNameCriterion('car AND truck'),
self::LANGUAGE_CODE_ENG,
[],
0,
];

yield 'Return content items in default language (English) that contain "car" or start with "sports" in name' => [
$this->createContentNameCriterion('*car* OR SPORTS*'),
null,
[
self::CAR_ENG,
self::SPORTS_CAR_ENG,
],
2,
];

yield 'Return content items in German that contain "sport and wagen" in name' => [
$this->createContentNameCriterion('*SPORT* AND *wagen*'),
self::LANGUAGE_CODE_GER,
[
self::SPORTS_CAR_GER,
],
1,
];

yield 'Return content items in German that contain "sport or last" in name' => [
$this->createContentNameCriterion('*sport* OR *last*'),
self::LANGUAGE_CODE_GER,
[
self::SPORTS_CAR_GER,
self::TRUCK_GER,
],
2,
];

yield 'Return content items in German that contain "auto" or ends with "wagen" in name' => [
$this->createContentNameCriterion('auto OR *wagen'),
self::LANGUAGE_CODE_GER,
[
self::CAR_GER,
self::SPORTS_CAR_GER,
self::TRUCK_GER,
],
3,
];
}

private function createTestContentItems(): void
{
foreach (self::CONTENT_ITEMS_MAP as $contentItem) {
Expand Down Expand Up @@ -340,45 +274,6 @@ private function createContentNameCriterion(string $value): Criterion
return new Criterion\ContentName($value);
}

/**
* @param array<string> $expectedContentItemTitles
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidCriterionArgumentException
*/
private function assertResult(
Criterion $criterion,
?string $languageCode,
array $expectedContentItemTitles,
int $expectedCount
): void {
$result = self::getSearchService()->findContent(
$this->createQuery($criterion),
$this->getLanguageFilter($languageCode)
);

self::assertEquals(
$expectedContentItemTitles,
array_map(
static function (SearchHit $searchHit) use ($languageCode): ?string {
$content = $searchHit->valueObject;
if ($content instanceof Content) {
return $content->getName($languageCode);
}

return null;
},
$result->searchHits
)
);

self::assertSame(
$expectedCount,
$result->totalCount
);
}

/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidCriterionArgumentException
*/
Expand Down

0 comments on commit 71153dc

Please sign in to comment.