From 465fd1939913e8c99a9545d5c8e244f81bedd2c2 Mon Sep 17 00:00:00 2001 From: Tomasz Kryszan Date: Tue, 24 Oct 2023 08:11:11 +0200 Subject: [PATCH] [Tests] Added integration test coverage for image criterions --- phpunit-integration-legacy-solr.xml | 1 + phpunit-integration-legacy.xml | 1 + .../Repository/SearchServiceImageTest.php | 320 ++++++++++++++++++ .../Repository/_fixtures/image/landscape.jpg | Bin 0 -> 3461 bytes .../Repository/_fixtures/image/portrait.jpg | Bin 0 -> 2836 bytes .../Repository/_fixtures/image/square.png | Bin 0 -> 177 bytes 6 files changed, 322 insertions(+) create mode 100644 tests/integration/Core/Repository/SearchServiceImageTest.php create mode 100644 tests/integration/Core/Repository/_fixtures/image/landscape.jpg create mode 100644 tests/integration/Core/Repository/_fixtures/image/portrait.jpg create mode 100644 tests/integration/Core/Repository/_fixtures/image/square.png 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..ca796a3615 --- /dev/null +++ b/tests/integration/Core/Repository/SearchServiceImageTest.php @@ -0,0 +1,320 @@ +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' => 100, + ], + 'height' => [ + 'min' => 0, + 'max' => 100, + ], + ] + ), + ]; + + 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, + 100 + ), + ]; + + yield 'Height' => [ + 3, + new Query\Criterion\Image\Height( + self::IMAGE_FIELD_DEF_IDENTIFIER, + 0, + 100 + ), + ]; + + yield 'MimeType - single' => [ + 2, + new Query\Criterion\Image\MimeType( + self::IMAGE_FIELD_DEF_IDENTIFIER, + 'image/jpeg', + ), + ]; + + yield 'MimeType - multiple' => [ + 3, + 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' => 100, + ], + 'height' => [ + 'min' => 0, + 'max' => 100, + ], + 'orientation' => [ + Orientation::LANDSCAPE, + Orientation::PORTRAIT, + ], + ] + ), + ]; + } + + /** + * @return iterable + */ + public function provideInvalidDataForTestCriterion(): iterable + { + yield 'Dimensions - width and height values too large' => [ + 0, + new Query\Criterion\Image\Dimensions( + self::IMAGE_FIELD_DEF_IDENTIFIER, + [ + 'width' => [ + 'min' => 101, + 'max' => 200, + ], + 'height' => [ + 'min' => 101, + 'max' => 300, + ], + ] + ), + ]; + + yield 'FileSize - size value too large' => [ + 0, + new Query\Criterion\Image\FileSize( + self::IMAGE_FIELD_DEF_IDENTIFIER, + 1, + 2 + ), + ]; + + yield 'Width - width value to large' => [ + 0, + new Query\Criterion\Image\Width( + self::IMAGE_FIELD_DEF_IDENTIFIER, + 101, + 200 + ), + ]; + + yield 'Height - height value to large' => [ + 0, + new Query\Criterion\Image\Height( + self::IMAGE_FIELD_DEF_IDENTIFIER, + 101, + 300 + ), + ]; + + yield 'MimeType - invalid single mime type' => [ + 0, + new Query\Criterion\Image\MimeType( + self::IMAGE_FIELD_DEF_IDENTIFIER, + 'image/invalid', + ), + ]; + + yield 'MimeType - invalid multiple mime types' => [ + 0, + new Query\Criterion\Image\MimeType( + self::IMAGE_FIELD_DEF_IDENTIFIER, + [ + 'image/invalid', + 'image/gif', + ], + ), + ]; + } + + 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 0000000000000000000000000000000000000000..1be0750b3b4f52f3718b62bfc12d268d304a2df6 GIT binary patch literal 3461 zcmbW2cT`i$_Qy|1LI(*Dnn36Xh)R``Q1ntQ2r6g*5kfUm0s#RjqL&EL1Vrgd7rcZ^ z6Htms6|VFmozOxrK?nkp7kqc!x7P2k-+Oyz&3w-~d+#})J+scxzR{)uE>lAjLjVK< z0AqRsXe1!oz~9Xo0IpmCLA6HK=F_kmt0F4VK zS0KmP>Gn%Y|B_q-BGDspKpAA|5liyw-h~j_CjiC_Tm&4!AQ->^1A$>6S~Gy4e+3lu z%YKE?2M_}o0%c@kW?^NcJ5+K33?ML=0Ro0XkCy=j)87LS7?fLFNuQC&+@47S$EzF` zpT#VBp|lZh(Yq<7;^6(5g_VzAKu}0pM)s7PysDb|c@0gii@zBd8X23IUcYhE((2Z2 zG{(`%*~QiEo)6yF?}2|n;FI6O2~Q&;pCu%|NP77yIVCkaCpRy@;B8@1S$Rd}`>N`i z51*TwTUy)NzjXBV4-5_se;XMk&CJftFOV0PmbWO|-*_a$|t2t zlHNK-`$hKu1AF{Gk^KYqAFeU_{(%`7jyv5T^bTb{-WDh;6B8pdJ1aXo8!Hhr`)V@C)$q3UKqnd1>?{ATT`!0%d_hS$H|vIC%eSqfO9{B?oO3 zURL@yvG1qp1Z9ue6#r6kyaR~UN-KvOQ z>#}5Q&yUVl;|Hu+H+DKPnoD6ei47G!t9hG}okv0=UvaZ$C#+l1y2?iqf+wS&eAMWE zL%jF()W`Doacw6Nm-aea0^cVF78cl=h$Oxd_5JYMXXSD3xy(lglW`g z>~?4XC-zy1xh1YZ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af5k>|dV*vvm3c6KEm&=f$*VpB=_?O*?H~>{laJ+mxpsGC3?ES&7aa#Rf zILS}drgr#WYHj39qIYpYZKS{a7~Ny%mP z|60~FgJ-}Ed;F7X1~nfF%c*8oZdZWQM#bJ;*W#A_q+l-S05L6L#GZwHKw44TaPphg w;+CP+7BS&c%Y_pu2s5FRcTB+HZ{;Hw?X+H+d`szGwm{N%nueX-iuXVK3%T3)=>Px# literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..159ab778de1f86e74ab1a229980f29604d36625e GIT binary patch literal 177 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1SFYWcSQjy#^NA%Cx&(BWL^R}oCO|{#S9GG z!XV7ZFl&wkP>{XE)7O>#4hNf{gmU9*r&gelWQl7;iF1B#Zfaf$gL6@8Vo7R>LV0FM zhJw4NZ$Nk>pEyvFoTrOph{fsTlo