diff --git a/phpunit-integration-legacy-solr.xml b/phpunit-integration-legacy-solr.xml index 3dce726268..70513747fe 100644 --- a/phpunit-integration-legacy-solr.xml +++ b/phpunit-integration-legacy-solr.xml @@ -19,6 +19,7 @@ + diff --git a/phpunit-integration-legacy.xml b/phpunit-integration-legacy.xml index 6b1da1c84c..cb4a636435 100644 --- a/phpunit-integration-legacy.xml +++ b/phpunit-integration-legacy.xml @@ -18,6 +18,7 @@ + diff --git a/tests/integration/Core/Repository/SearchServiceImageTest.php b/tests/integration/Core/Repository/SearchServiceImageTest.php new file mode 100644 index 0000000000..fac72dc3db --- /dev/null +++ b/tests/integration/Core/Repository/SearchServiceImageTest.php @@ -0,0 +1,247 @@ +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 + */ + 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); + } +} diff --git a/tests/integration/Core/Repository/_fixtures/image/landscape.jpg b/tests/integration/Core/Repository/_fixtures/image/landscape.jpg new file mode 100644 index 0000000000..1be0750b3b Binary files /dev/null and b/tests/integration/Core/Repository/_fixtures/image/landscape.jpg differ diff --git a/tests/integration/Core/Repository/_fixtures/image/portrait.jpg b/tests/integration/Core/Repository/_fixtures/image/portrait.jpg new file mode 100644 index 0000000000..0ddd840923 Binary files /dev/null and b/tests/integration/Core/Repository/_fixtures/image/portrait.jpg differ diff --git a/tests/integration/Core/Repository/_fixtures/image/square.png b/tests/integration/Core/Repository/_fixtures/image/square.png new file mode 100644 index 0000000000..159ab778de Binary files /dev/null and b/tests/integration/Core/Repository/_fixtures/image/square.png differ