-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tests] Added integration test coverage for image criterions
- Loading branch information
Showing
5 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
247 changes: 247 additions & 0 deletions
247
tests/integration/Core/Repository/SearchServiceImageTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.