Skip to content

Commit

Permalink
[Tests] Added integration tests coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Oct 24, 2023
1 parent b88532d commit 8268d0f
Show file tree
Hide file tree
Showing 3 changed files with 249 additions and 0 deletions.
1 change: 1 addition & 0 deletions phpunit-integration-legacy-solr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
<ini name="error_reporting" value="-1" />
<env name="KERNEL_CLASS" value="Ibexa\Contracts\Core\Test\IbexaTestKernel"/>
<env name="SEARCH_ENGINE" value="solr"/>
</php>
<testsuites>
<!-- Search service is used all over the place, so we must run entire integration test suite -->
Expand Down
1 change: 1 addition & 0 deletions phpunit-integration-legacy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ini name="error_reporting" value="-1" />
<env name="DATABASE_URL" value="sqlite://:memory:" />
<env name="KERNEL_CLASS" value="Ibexa\Contracts\Core\Test\IbexaTestKernel"/>
<env name="SEARCH_ENGINE" value="legacy"/>
</php>
<testsuites>
<testsuite name="integration_core">
Expand Down
247 changes: 247 additions & 0 deletions tests/integration/Core/Repository/SearchServiceImageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Integration\Core\Repository;

use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
use Ibexa\Contracts\Core\Test\IbexaKernelTestCase;
use Ibexa\Core\FieldType\Image\Orientation;
use Ibexa\Core\FieldType\Image\Value as ImageValue;
use Ibexa\Core\FieldType\TextLine\Value as TextValue;

final class SearchServiceImageTest extends IbexaKernelTestCase
{
private const IMAGE_CONTENT_TYPE = 'image';
private const IMAGE_FIELD_DEF_IDENTIFIER = 'image';
private const IMAGE_FILES = [
'landscape.jpg',
'portrait.jpg',
'square.png',
];

private const IMAGE_FIXTURES_DIR_PATH = __DIR__ . '/_fixtures/image/';

protected function setUp(): void
{
parent::setUp();

self::loadSchema();
self::loadFixtures();

self::setAdministratorUser();
}

/**
* @dataProvider provideDataForTestCriterion
*/
public function testCriterion(
int $expectedCount,
Query\Criterion $imageCriterion
): void {
if (getenv('SEARCH_ENGINE') === 'legacy') {
self::markTestSkipped('Image criteria are not supported in Legacy Search Engine');
}

$this->createImages();

$query = new Query();
$query->filter = new Query\Criterion\LogicalAnd(
[
new Query\Criterion\ContentTypeIdentifier(self::IMAGE_CONTENT_TYPE),
$imageCriterion,
]
);

$searchHits = self::getSearchService()->findContent($query);

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

/**
* @return iterable<array{
* int,
* \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion
* }>
*/
public function provideDataForTestCriterion(): iterable
{
yield 'Dimensions' => [
3,
new Query\Criterion\Image\Dimensions(
self::IMAGE_FIELD_DEF_IDENTIFIER,
[
'width' => [
'min' => 0,
'max' => 1,
],
'height' => [
'min' => 0,
'max' => 1,
],
]
),
];

yield 'FileSize' => [
3,
new Query\Criterion\Image\FileSize(
self::IMAGE_FIELD_DEF_IDENTIFIER,
0,
1
),
];

yield 'Width' => [
3,
new Query\Criterion\Image\Width(
self::IMAGE_FIELD_DEF_IDENTIFIER,
0,
1
),
];

yield 'Height' => [
3,
new Query\Criterion\Image\Height(
self::IMAGE_FIELD_DEF_IDENTIFIER,
0,
1
),
];

yield 'MimeType - single' => [
1,
new Query\Criterion\Image\MimeType(
self::IMAGE_FIELD_DEF_IDENTIFIER,
'image/jpeg',
),
];

yield 'MimeType - multiple' => [
2,
new Query\Criterion\Image\MimeType(
self::IMAGE_FIELD_DEF_IDENTIFIER,
[
'image/jpeg',
'image/png',
],
),
];

yield 'Orientation - landscape' => [
1,
new Query\Criterion\Image\Orientation(
self::IMAGE_FIELD_DEF_IDENTIFIER,
Orientation::LANDSCAPE
),
];

yield 'Orientation - portrait' => [
1,
new Query\Criterion\Image\Orientation(
self::IMAGE_FIELD_DEF_IDENTIFIER,
Orientation::PORTRAIT
),
];

yield 'Orientation - square' => [
1,
new Query\Criterion\Image\Orientation(
self::IMAGE_FIELD_DEF_IDENTIFIER,
Orientation::SQUARE
),
];

yield 'Orientation - multiple' => [
3,
new Query\Criterion\Image\Orientation(
self::IMAGE_FIELD_DEF_IDENTIFIER,
[
Orientation::LANDSCAPE,
Orientation::PORTRAIT,
Orientation::SQUARE,
]
),
];

yield 'Image' => [
2,
new Query\Criterion\Image(
self::IMAGE_FIELD_DEF_IDENTIFIER,
[
'mimeTypes' => [
'image/jpeg',
'image/png',
],
'size' => [
'min' => 0,
'max' => 1,
],
'width' => [
'min' => 0,
'max' => 1,
],
'height' => [
'min' => 0,
'max' => 1,
],
'orientation' => [
Orientation::LANDSCAPE,
Orientation::PORTRAIT,
],
]
),
];
}

private function createImages(): void
{
$contentType = $this->loadContentTypeImage();
foreach (self::IMAGE_FILES as $image) {
$this->createContentImage(
$contentType,
self::IMAGE_FIXTURES_DIR_PATH . $image,
$image
);
}
}

private function createContentImage(
ContentType $contentType,
string $path,
string $fileName
): void {
$contentCreateStruct = self::getContentService()->newContentCreateStruct(
$contentType,
'eng-GB'
);

$imageValue = new ImageValue();
$imageValue->fileName = $fileName;
$imageValue->path = $path;

$contentCreateStruct->setField('name', new TextValue('Image'), 'eng-GB');
$contentCreateStruct->setField('image', $imageValue, 'eng-GB');

$contentService = self::getContentService();
$contentService->publishVersion(
$contentService
->createContent($contentCreateStruct)
->getVersionInfo()
);
}

private function loadContentTypeImage(): ContentType
{
return self::getContentTypeService()->loadContentTypeByIdentifier(self::IMAGE_CONTENT_TYPE);
}
}

0 comments on commit 8268d0f

Please sign in to comment.