diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index ceb9522..0000000 --- a/.gitattributes +++ /dev/null @@ -1,3 +0,0 @@ -bin/ export-ignore -phpstan.neon.dist export-ignore -psalm.xml export-ignore diff --git a/.github/workflows/pack-plugin.yml b/.github/workflows/pack-plugin.yml deleted file mode 100644 index ea0c36e..0000000 --- a/.github/workflows/pack-plugin.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: PackPlugin -on: - push: - branches: - - main - -jobs: - build: - uses: FriendsOfShopware/actions/.github/workflows/store-shopware-cli.yml@main - with: - extensionName: FroshPlatformThumbnailProcessor - secrets: - accountUser: ${{ secrets.ACCOUNT_USER }} - accountPassword: ${{ secrets.ACCOUNT_PASSWORD }} - ghToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test-branches.yml b/.github/workflows/test-branches.yml deleted file mode 100644 index 72ca917..0000000 --- a/.github/workflows/test-branches.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: Test branches -on: - workflow_dispatch: - schedule: - - cron: "5 15 * * *" - -jobs: - main: - uses: FriendsOfShopware/FroshPlatformThumbnailProcessor/.github/workflows/test.yml@main - v4: - uses: FriendsOfShopware/FroshPlatformThumbnailProcessor/.github/workflows/test.yml@v4 \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 957d9a2..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,103 +0,0 @@ -name: Test -on: - push: - branches: - - 'main' - tags-ignore: - - '*' - pull_request: - workflow_call: - -jobs: - Test: - env: - PLUGIN_NAME: FroshPlatformThumbnailProcessor - strategy: - fail-fast: false - matrix: - # don't forget to update the matrix for integration tests - version: [ "v6.6.4.0", "v6.6.3.1", "v6.6.2.0", "v6.6.1.1", "v6.6.0.3", "trunk" ] - php-version: [ "8.2", "8.3" ] - runs-on: ubuntu-latest - steps: - - name: Setup Shopware - uses: shopware/setup-shopware@main - with: - shopware-version: ${{ matrix.version }} - php-version: ${{ matrix.php-version }} - php-extensions: pcov - - - name: Info - run: | - php bin/console -V - mysql -V - php -v - composer -V - - - name: Checkout - uses: actions/checkout@v3 - with: - path: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }} - - - name: Run UnitTests - working-directory: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }} - run: | - composer create-placeholders - php -d pcov.enabled=1 ${{ github.workspace }}/vendor/bin/phpunit --coverage-clover clover.xml --testsuite Unit - - - uses: codecov/codecov-action@v3 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - with: - files: ./clover.xml - root_dir: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }} - working-directory: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }} - - # we call this after PHPUnit to make sure that the generated files are available - - name: PHPStan - run: | - ${{ github.workspace }}/vendor/bin/phpstan analyse -c ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }}/phpstan.neon - - IntegrationTest: - env: - PLUGIN_NAME: FroshPlatformThumbnailProcessor - strategy: - fail-fast: false - matrix: - version: [ "v6.6.4.0", "v6.6.3.1", "v6.6.2.0", "v6.6.1.1", "v6.6.0.3", "trunk" ] - php-version: [ "8.2", "8.3" ] - runs-on: ubuntu-latest - steps: - - name: Setup Shopware - uses: shopware/setup-shopware@main - with: - shopware-version: ${{ matrix.version }} - php-version: ${{ matrix.php-version }} - php-extensions: pcov - - - name: Info - run: | - php bin/console -V - mysql -V - php -v - composer -V - - - name: Checkout - uses: actions/checkout@v3 - with: - path: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }} - - - name: PHPUnit Integration - working-directory: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }} - run: | - composer create-placeholders - php -d pcov.enabled=1 ${{ github.workspace }}/vendor/bin/phpunit --testsuite Integration - - - uses: codecov/codecov-action@v3 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - with: - files: ./clover.xml - root_dir: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }} - working-directory: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }} - diff --git a/.gitignore b/.gitignore deleted file mode 100755 index 751b333..0000000 --- a/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -vendor -frosh-platform-thumbnail-processor.css -frosh-platform-thumbnail-processor.js -node_modules -src/DependencyInjection/ThumbnailService.php -src/DependencyInjection/FileSaver.php diff --git a/.shopware-extension.yml b/.shopware-extension.yml deleted file mode 100644 index 549ba20..0000000 --- a/.shopware-extension.yml +++ /dev/null @@ -1,59 +0,0 @@ -store: - availabilities: - - German - - International - default_locale: en_GB - localizations: - - de_DE - - en_GB - categories: - - ConversionOptimierung - type: extension - icon: src/Resources/store/icon.png - automatic_bugfix_version_compatibility: false - description: - de: file:src/Resources/store/de.md - en: file:src/Resources/store/en.md - tags: - de: - - thumbnail - - performance - - storage - - webp - en: - - thumbnail - - performance - - storage - - webp - features: - de: - - Keine Thumbnail-Dateien mehr - - URL pro SalesChannel möglich - en: - - No more thumbnail files - - URL per SalesChannel possible - images: - - file: src/Resources/store/images/0.jpg - activate: - de: true - en: true - preview: - de: true - en: true - priority: 0 - - file: src/Resources/store/images/1.jpg - activate: - de: true - en: true - preview: - de: false - en: false - priority: 1 -build: - zip: - assets: - enable_es_build_for_admin: true - enable_es_build_for_storefront: true - pack: - before_hooks: - - composer create-placeholders diff --git a/src/DependencyInjection/FileSaver.php b/src/DependencyInjection/FileSaver.php new file mode 100644 index 0000000..78f4ace --- /dev/null +++ b/src/DependencyInjection/FileSaver.php @@ -0,0 +1,10 @@ +{var a=`{% block frosh_thumbnail_processor_info_texts %} +
+

+ Hint: You can set the configuration per SalesChannel and you don't need to use all variables. +

+ +

+ Available variables for the ThumbnailPattern:
+ {mediaUrl}: e.g. https://cdn.test.de/
+ {mediaPath}: e.g. media/image/5b/6d/16/tea.png
+ {width}: e.g. 800 + {mediaUpdatedAt}: 1716882050 (unix timestamp) or 0 +

+ +

+ Find patterns in the discussion category 'Patterns' of the GitHub repository:
+ + GitHub Category 'Patterns' + +

+
+{% endblock %} +`;var{Component:p}=Shopware;p.register("frosh-thumbnail-processor-info-texts",{template:a});var c=` + + {{ btnLabel }} + + +
+

+
+
+
+`;var{Component:d,Mixin:f}=Shopware;d.register("thumbnailprocessor-test",{template:c,props:["btnLabel"],inject:["thumbnailProcessorTest"],mixins:[f.getByName("notification")],data(){return{isLoading:!1,isSuccessful:!1}},computed:{pluginSalesChannelId(){let t=this.getParentComponent();if(!t)throw"Can not get pluginConfigData";return t.currentSalesChannelId}},methods:{finish(){this.isSuccessful=!1},showError(t,s,e){this.isSuccessful=!1,s&&(t+=" sample url: "+s),e.innerText=t,e.scrollIntoView(),this.createNotificationError({title:this.$tc("thumbnail-processor.test.title"),message:t})},check(){this.isLoading=!0,this.thumbnailProcessorTest.getUrl(this.pluginSalesChannelId).then(t=>{if(t.url){this.isSuccessful=!0;let s=this,e=document.createElement("img"),i=document.querySelector("#testimage-container"),r=i.querySelector("img"),n=document.querySelector("#test-result");if(e.src=t.url,e.width=200,e.height=200,e.onload=function(){e.naturalWidth!==200&&s.showError(s.$tc("thumbnail-processor.test.error.noResize"),t.url,n)},e.onerror=function(){r.height=0,r.width=0,s.showError(s.$tc("thumbnail-processor.test.error.general"),t.url,n)},r){r.replaceWith(e);return}i.appendChild(e)}else this.showError(this.$tc("thumbnail-processor.test.error.general"));setTimeout(()=>{this.isLoading=!1},2500)})},systemConfigSaveAll(){this.isLoading=!0;let t=this.getParentComponent();if(!t)throw this.isLoading=!1,"Can not get systemConfig";t.saveAll().then(()=>{this.check(),this.isLoading=!1})},getParentComponent(t=this){return typeof t.actualConfigData<"u"?t:t.$parent?this.getParentComponent(t.$parent):null}}});var l=Shopware.Classes.ApiService,{Application:h}=Shopware,o=class extends l{constructor(s,e,i="thumbnail-processor-test"){super(s,e,i)}getUrl(s){let e=this.getBasicHeaders({});return this.httpClient.post(`_action/${this.getApiBasePath()}/get-sample-image`,{salesChannelId:s},{headers:e}).then(i=>l.handleResponse(i))}};h.addServiceProvider("thumbnailProcessorTest",t=>{let s=h.getContainer("init");return new o(s.httpClient,t.loginService)});})(); diff --git a/src/Resources/store/de.md b/src/Resources/store/de.md deleted file mode 100644 index c9291fd..0000000 --- a/src/Resources/store/de.md +++ /dev/null @@ -1,38 +0,0 @@ -Verschwende keine Rechenleistung und keinen Speicherplatz mit Thumbnails! -Mit diesem Plugin können Sie auf dynamische Thumbnails zurückgreifen. -Jedes Produkt, jedes Bild in der Einkaufswelten hat berechtigterweise Thumbnails. Diese werden standardmäßig -automatisch beim Upload erzeugt und auf der Festplatte gespeichert. -An diesem Punkt greift dieses Plugin ein und stellt die Funktion zur Verfügung, dass keine Thumbnaildateien mehr erstellt -werden müssen. Es bleibt lediglich, dass die Thumbnail-Größen in der Datenbank gespeichert werden. -Die Thumbnails werden dann in Echtzeit beim Besuch durch einen externen Dienst erzeugt und ausgeliefert. - -## Vorteile vom Sparen der Thumbnailerzeugung: -- Nutze einen externen Dienst, um deine Bilder optimiert auszuliefern -- Sparen von Speicherplatz -- Schnellerer Upload von Bildern -- Entlastung des Servers -- Schnellere Backups durch weniger Dateien - -## Hinzufügen weiterer Thumbnail-Größen: -- im Order der Medienverwaltung neue Größe hinterlegen -- dann den Befehl `bin/console media:generate-thumbnails` auf der Konsole ausführen, damit die Thumbnails für alle Bilder in der Datenbank aktualisiert werden (ab v3.0.2 nicht mehr notwendig) -- Shop-Cache leeren - -## Welchen Dienst verwende ich nun für die Thumbnails: -Beachten Sie, dass dieses Plugin nur die Funktion zum Ausliefern der Thumbnail-Urls bereitstellt. -Dieses Plugin erstellt keine Thumbnails! Dazu werden die entsprechenden Dienste verwendet. - -Es gibt drei Parameter, die Ihnen optional zur Erstellung des Links zur Verfügung stehen: -{mediaUrl}: Primär die Config shopware.cdn.url, alternativ Shop-Url -{mediaPath}: relativer Pfad zu dem Originalbild -{width}: Breite des Thumbnails - -Finde fertige Template auf GitHub: -[GitHub Category Patterns](https://github.com/FriendsOfShopware/FroshPlatformThumbnailProcessor/discussions/categories/patterns). - -Nach der Einrichtung und Prüfung im DeveloperTools Ihres Browsers, können Sie auch den vorhandenen thumbnail-Ordner sichern und löschen. - -Dieses Plugin wird von [@FriendsOfShopware](https://store.shopware.com/friends-of-shopware.html) entwickelt. -Maintainer dieses Plugins ist: [Sebastian König (tinect)](https://github.com/tinect) - -Bei Fragen / Fehlern bitte ein [GitHub Issue](https://github.com/FriendsOfShopware/FroshPlatformThumbnailProcessor/issues/new) erstellen diff --git a/src/Resources/store/en.md b/src/Resources/store/en.md deleted file mode 100644 index f10b158..0000000 --- a/src/Resources/store/en.md +++ /dev/null @@ -1,36 +0,0 @@ -Don't waste the computing power and space with thumbnails! With this plugin you can access dynamic thumbnails. -Every product, every picture in the shopping worlds legitimately has thumbnails. These become standard -generated and saved automatically during upload. -At this point this plugin intervenes and provides the function that no more thumbnail files are created. The only thing that remains is that the thumbnail sizes are stored in the database. -The thumbnails are then generated and delivered by an external service in real time when visiting. - -## Advantages of saving thumbnail generation: -- Use external service to deliver images optimized -- Save space on disk -- Faster upload of images -- Relief of the server -- Faster backups with fewer files - -## Adding more thumbnail sizes: -- Save new size in the folder of the media management -- then run the command `bin/console media:generate-thumbnails` on the console to update the thumbnails for all images in the database (no more needed from version 3.0.2) -- Clear shop cache - -## Which service do I now use for the thumbnails: -Please note that this plugin only provides the function for delivering the thumbnail urls. -This plugin does not create thumbnails! The corresponding services are used for this. - -There are three parameters that are optionally available for creating the link: -{mediaUrl}: Primarily your config shopware.cdn.url, alternatively shop url -{mediaPath}: The relative path to the original image -{width}: The width of the thumbnail - -Find pattern at GitHub: -[GitHub Category Patterns](https://github.com/FriendsOfShopware/FroshPlatformThumbnailProcessor/discussions/categories/patterns). - -After setting up and checking in the developer tools of your browser, you can also backup and delete the existing thumbnail folder. - -This plugin is part of [@FriendsOfShopware](https://store.shopware.com/en/friends-of-shopware.html). -Maintainer from the plugin is: [Sebastian König (tinect)](https://github.com/tinect) - -For questions or bugs please create a [GitHub Issue](https://github.com/FriendsOfShopware/FroshPlatformThumbnailProcessor/issues/new) diff --git a/src/Resources/store/icon.png b/src/Resources/store/icon.png deleted file mode 100644 index 885856b..0000000 Binary files a/src/Resources/store/icon.png and /dev/null differ diff --git a/src/Resources/store/images/0.jpg b/src/Resources/store/images/0.jpg deleted file mode 100644 index f2fb563..0000000 Binary files a/src/Resources/store/images/0.jpg and /dev/null differ diff --git a/src/Resources/store/images/1.jpg b/src/Resources/store/images/1.jpg deleted file mode 100644 index 23ce474..0000000 Binary files a/src/Resources/store/images/1.jpg and /dev/null differ diff --git a/tests/TestBootstraper.php b/tests/TestBootstraper.php deleted file mode 100644 index bcef83d..0000000 --- a/tests/TestBootstraper.php +++ /dev/null @@ -1,47 +0,0 @@ -setLoadEnvFile(true) - ->setForceInstallPlugins(true) - ->addActivePlugins($pluginName) - ->bootstrap() - ->getClassLoader(); -} - -$paths = [ - '../../../../src/Core/TestBootstrapper.php', - '../vendor/shopware/core/TestBootstrapper.php', - '../../../../vendor/shopware/core/TestBootstrapper.php', -]; - -foreach ($paths as $path) { - $path = realpath(__DIR__ . '/' . $path); - - if (!\is_string($path)) { - continue; - } - - if (!\is_file($path)) { - continue; - } - - require $path; - - return (new TestBootstrapper()) - ->setPlatformEmbedded(false) - ->setLoadEnvFile(true) - ->setForceInstallPlugins(true) - ->addActivePlugins($pluginName) - ->bootstrap() - ->getClassLoader(); -} diff --git a/tests/integration/MediaUrlTest.php b/tests/integration/MediaUrlTest.php deleted file mode 100644 index 7f4fabb..0000000 --- a/tests/integration/MediaUrlTest.php +++ /dev/null @@ -1,169 +0,0 @@ -getContainer(); - - $urlGenerator = $container->get(AbstractMediaUrlGenerator::class); - \assert($urlGenerator instanceof AbstractMediaUrlGenerator); - - $this->mediaRepository = $container->get('media.repository'); - \assert($this->mediaRepository instanceof EntityRepository); - - $this->generateThumbnailsCommand = $container->get(GenerateThumbnailsCommand::class); - \assert($this->generateThumbnailsCommand instanceof GenerateThumbnailsCommand); - - $this->systemConfigService = $container->get(SystemConfigService::class); - \assert($this->systemConfigService instanceof SystemConfigService); - - $this->context = Context::createDefaultContext(); - } - - public function testMediaUrlWithInactiveConfigResultsInOriginalMedia(): void - { - $fixture = $this->mediaFixtures['NamedMimePngEtxPngWithFolder']; - $media = $this->getPngWithFolder(); - - static::assertMatchesRegularExpression('/http:\/\/localhost:8000\/media\/_test\/pngFileWithExtensionAndFolder\.png\?(\d+|ts=\d+)/', $media->getUrl()); - - $folderName = null; - if (\is_array($fixture['mediaFolder']) && !empty($fixture['mediaFolder']['name'])) { - $folderName = $fixture['mediaFolder']['name']; - } - - static::assertNotEmpty($folderName); - - $resource = fopen(TestController::TEST_FILE_PATH, 'rb'); - \assert($resource !== false); - - $filePath = $media->getPath(); - $fileSystem = $this->getPublicFilesystem(); - $fileSystem->writeStream($filePath, $resource); - - static::assertTrue($fileSystem->has($filePath)); - - $parameters = []; - $parameters['--folder-name'] = $folderName; - - $this->generateThumbnailsCommand->run(new ArrayInput($parameters, $this->generateThumbnailsCommand->getDefinition()), new NullOutput()); - - $this->runWorker(); - - $searchCriteria = new Criteria(); - $searchCriteria->setLimit(1); - $searchCriteria->addFilter(new EqualsFilter('media.id', $media->getId())); - $searchCriteria->addAssociation('mediaFolder.configuration.mediaThumbnailSizes'); - - $mediaResult = $this->mediaRepository->search($searchCriteria, $this->context); - - /** @var MediaEntity $updatedMedia */ - $updatedMedia = $mediaResult->getEntities()->first(); - - $thumbnails = $updatedMedia->getThumbnails(); - static::assertInstanceOf(MediaThumbnailCollection::class, $thumbnails); - static::assertEquals(2, $thumbnails->count()); - - foreach ($thumbnails as $thumbnail) { - $thumbnailUrl = $thumbnail->getUrl(); - - static::assertStringStartsWith('http://localhost:8000', $thumbnailUrl); - static::assertStringNotContainsString('thumbnail/', $thumbnailUrl); - static::assertSame($media->getUrl(), $thumbnailUrl); - static::assertFalse($fileSystem->has(\str_replace('media/', 'thumbnail/', $filePath))); - static::assertFalse($fileSystem->has($thumbnailUrl)); - } - } - - public function testMediaUrlWithActiveConfig(): void - { - $this->systemConfigService->set('FroshPlatformThumbnailProcessor.config.Active', true); - - $fixture = $this->mediaFixtures['NamedMimePngEtxPngWithFolder']; - $media = $this->getPngWithFolder(); - - static::assertStringEndsWith('pngFileWithExtensionAndFolder.png?width=3000', $media->getUrl()); - - $folderName = null; - if (\is_array($fixture['mediaFolder']) && !empty($fixture['mediaFolder']['name'])) { - $folderName = $fixture['mediaFolder']['name']; - } - - static::assertNotEmpty($folderName); - - $resource = fopen(TestController::TEST_FILE_PATH, 'rb'); - \assert($resource !== false); - - $filePath = $media->getPath(); - $fileSystem = $this->getPublicFilesystem(); - $fileSystem->writeStream($filePath, $resource); - - static::assertTrue($fileSystem->has($filePath)); - - $parameters = []; - $parameters['--folder-name'] = $folderName; - - $this->generateThumbnailsCommand->run(new ArrayInput($parameters, $this->generateThumbnailsCommand->getDefinition()), new NullOutput()); - - $this->runWorker(); - - $searchCriteria = new Criteria(); - $searchCriteria->setLimit(1); - $searchCriteria->addFilter(new EqualsFilter('media.id', $media->getId())); - $searchCriteria->addAssociation('mediaFolder.configuration.mediaThumbnailSizes'); - - $mediaResult = $this->mediaRepository->search($searchCriteria, $this->context); - - /** @var MediaEntity $updatedMedia */ - $updatedMedia = $mediaResult->getEntities()->first(); - - $thumbnails = $updatedMedia->getThumbnails(); - static::assertInstanceOf(MediaThumbnailCollection::class, $thumbnails); - static::assertEquals(2, $thumbnails->count()); - - foreach ($thumbnails as $thumbnail) { - $thumbnailUrl = $thumbnail->getUrl(); - - static::assertStringStartsWith('http://localhost:8000', $thumbnailUrl); - static::assertStringEndsWith('pngFileWithExtensionAndFolder.png?width=' . $thumbnail->getWidth(), $thumbnailUrl); - static::assertStringNotContainsString('thumbnail/', $thumbnailUrl); - - static::assertFalse($fileSystem->has(\str_replace('media/', 'thumbnail/', $filePath))); - static::assertFalse($fileSystem->has($thumbnailUrl)); - } - } -} diff --git a/tests/unit/Controller/Api/TestControllerTest.php b/tests/unit/Controller/Api/TestControllerTest.php deleted file mode 100644 index 4be2a02..0000000 --- a/tests/unit/Controller/Api/TestControllerTest.php +++ /dev/null @@ -1,403 +0,0 @@ -createMock(AbstractMediaUrlGenerator::class); - $mediaRepository = $this->createMock(EntityRepository::class); - $mediaFolderRepository = $this->createMock(EntityRepository::class); - $fileSaver = $this->createMock(FileSaver::class); - $fileFetcher = $this->createMock(FileFetcher::class); - - $controller = new TestController( - $urlGenerator, - $mediaRepository, - $mediaFolderRepository, - $fileSaver, - $fileFetcher, - ); - - $request = new Request(); - $dataBag = new RequestDataBag(); - - $result = $controller->check($request, $dataBag); - static::assertSame('{"success":false}', $result->getContent()); - } - - public function testCheckFailsWithoutFile(): void - { - $urlGenerator = $this->createMock(AbstractMediaUrlGenerator::class); - $mediaRepository = $this->createMock(EntityRepository::class); - $mediaFolderRepository = $this->createMock(EntityRepository::class); - $fileSaver = $this->createMock(FileSaver::class); - $fileFetcher = $this->createMock(FileFetcher::class); - - $controller = new TestController( - $urlGenerator, - $mediaRepository, - $mediaFolderRepository, - $fileSaver, - $fileFetcher, - ); - - $request = new Request(); - $dataBag = new RequestDataBag(); - $dataBag->add(['salesChannelId' => null]); - - static::assertFileExists(TestController::TEST_FILE_PATH); - \rename(TestController::TEST_FILE_PATH, TestController::TEST_FILE_PATH . '.bak'); - static::assertFileDoesNotExist(TestController::TEST_FILE_PATH); - - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage(\sprintf('Test file at "%s" is missing or not readable', \realpath(TestController::TEST_FILE_PATH))); - $controller->check($request, $dataBag); - } - - public function testCheckFailsMediaSaving(): void - { - $urlGenerator = $this->createMock(AbstractMediaUrlGenerator::class); - $urlGenerator->expects(static::never()) - ->method('generate'); - - $mediaRepository = $this->createMock(EntityRepository::class); - - $mediaFolderRepository = $this->createMock(EntityRepository::class); - $mediaFolderRepository->expects(static::once()) - ->method('searchIds') - ->willReturn( - new IdSearchResult( - 1, - [['primaryKey' => 'folder-id', 'data' => []]], - new Criteria(), - Context::createDefaultContext(), - ), - ); - - $fileSaver = $this->createMock(FileSaver::class); - $fileFetcher = $this->createMock(FileFetcher::class); - - $controller = new TestController( - $urlGenerator, - $mediaRepository, - $mediaFolderRepository, - $fileSaver, - $fileFetcher, - ); - - $request = new Request(); - $dataBag = new RequestDataBag(); - $dataBag->add(['salesChannelId' => null]); - - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('Media has not been saved!'); - $controller->check($request, $dataBag); - } - - public function testCheckFailsProductMediaId(): void - { - $urlGenerator = $this->createMock(AbstractMediaUrlGenerator::class); - $urlGenerator->expects(static::never()) - ->method('generate'); - - $mediaRepository = $this->createMock(EntityRepository::class); - - $mediaFolderRepository = $this->createMock(EntityRepository::class); - $mediaFolderRepository->expects(static::once()) - ->method('searchIds') - ->willReturn( - new IdSearchResult( - 0, - [], - new Criteria(), - Context::createDefaultContext(), - ), - ); - - $fileSaver = $this->createMock(FileSaver::class); - $fileFetcher = $this->createMock(FileFetcher::class); - - $controller = new TestController( - $urlGenerator, - $mediaRepository, - $mediaFolderRepository, - $fileSaver, - $fileFetcher, - ); - - $request = new Request(); - $dataBag = new RequestDataBag(); - $dataBag->add(['salesChannelId' => null]); - - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('Media folder for product could not have been found!'); - $controller->check($request, $dataBag); - } - - public function testCheckWithExistingMedia(): void - { - $urlGenerator = $this->createMock(AbstractMediaUrlGenerator::class); - $urlGenerator->expects(static::once()) - ->method('generate') - ->willReturn(['test' => 'http://localhost/thumbnail.jpg?width=200']); - - $mediaRepository = $this->createMock(EntityRepository::class); - $mediaRepository->expects(static::once()) - ->method('search') - ->willReturnCallback(function (Criteria $criteria, Context $context): EntitySearchResult { - $collection = new EntityCollection(); - $media = new MediaEntity(); - $media->setId('test'); - $media->setFileExtension('jpg'); - $media->setFileName('test.jpg'); - $media->setMimeType('image/jpg'); - $media->setPath('thumbnail.jpg'); - $media->setFileSize(100); - $media->setCreatedAt(new \DateTime()); - $media->setUpdatedAt(new \DateTime()); - $media->setMediaFolderId('test'); - $media->setMediaType(new ImageType()); - $collection->add($media); - - return new EntitySearchResult( - 'media_entity', - 1, - $collection, - null, - new Criteria(), - Context::createDefaultContext() - ); - }); - - $mediaFolderRepository = $this->createMock(EntityRepository::class); - $mediaFolderRepository->expects(static::never()) - ->method('searchIds') - ->willReturn( - new IdSearchResult( - 1, - [['primaryKey' => 'folder-id', 'data' => []]], - new Criteria(), - Context::createDefaultContext(), - ), - ); - - $fileSaver = $this->createMock(FileSaver::class); - $fileFetcher = $this->createMock(FileFetcher::class); - - $controller = new TestController( - $urlGenerator, - $mediaRepository, - $mediaFolderRepository, - $fileSaver, - $fileFetcher, - ); - - $request = new Request(); - $dataBag = new RequestDataBag(); - $dataBag->add(['salesChannelId' => null]); - - $result = $controller->check($request, $dataBag); - assertSame('{"url":"http:\/\/localhost\/thumbnail.jpg?width=200"}', $result->getContent()); - } - - public function testCheck(): void - { - $urlGenerator = $this->createMock(AbstractMediaUrlGenerator::class); - $urlGenerator->expects(static::once()) - ->method('generate') - ->willReturn(['test' => 'http://localhost/thumbnail.jpg?width=200']); - - $mediaRepositoryResults = []; - $mediaRepositoryResults[] = new EntitySearchResult( - 'media_entity', - 0, - new EntityCollection(), - null, - new Criteria(), - Context::createDefaultContext() - ); - - $collection = new EntityCollection(); - $media = new MediaEntity(); - $media->setId('test'); - $media->setPath('thumbnail.jpg'); - $media->setFileExtension('jpg'); - $media->setFileName('test.jpg'); - $media->setMimeType('image/jpg'); - $media->setFileSize(100); - $media->setCreatedAt(new \DateTime()); - $media->setUpdatedAt(new \DateTime()); - $media->setMediaFolderId('test'); - $media->setMediaType(new ImageType()); - $collection->add($media); - - $mediaRepositoryResults[] = new EntitySearchResult( - 'media_entity', - 1, - $collection, - null, - new Criteria(), - Context::createDefaultContext() - ); - - $matcher = static::exactly(2); - - $mediaRepository = $this->createMock(EntityRepository::class); - $mediaRepository->expects($matcher) - ->method('search') - ->willReturnCallback(function () use ($mediaRepositoryResults, $matcher): EntitySearchResult { - return match ($matcher->numberOfInvocations()) { - 1 => $mediaRepositoryResults[0], - 2 => $mediaRepositoryResults[1], - default => throw new \RuntimeException('Unexpected invocation count'), - }; - }); - - $mediaFolderRepository = $this->createMock(EntityRepository::class); - $mediaFolderRepository->expects(static::once()) - ->method('searchIds') - ->willReturn( - new IdSearchResult( - 1, - [['primaryKey' => 'folder-id', 'data' => []]], - new Criteria(), - Context::createDefaultContext(), - ), - ); - - $fileSaver = $this->createMock(FileSaver::class); - $fileFetcher = $this->createMock(FileFetcher::class); - - $controller = new TestController( - $urlGenerator, - $mediaRepository, - $mediaFolderRepository, - $fileSaver, - $fileFetcher, - ); - - $request = new Request(); - $dataBag = new RequestDataBag(); - $dataBag->add(['salesChannelId' => null]); - - $result = $controller->check($request, $dataBag); - assertSame('{"url":"http:\/\/localhost\/thumbnail.jpg?width=200"}', $result->getContent()); - } - - public function testCheckWithSalesChannel(): void - { - $urlGenerator = $this->createMock(AbstractMediaUrlGenerator::class); - $urlGenerator->expects(static::once()) - ->method('generate') - ->willReturn(['test' => 'http://localhost/thumbnail.jpg?width=200']); - - $mediaRepositoryResults = []; - $mediaRepositoryResults[] = new EntitySearchResult( - 'media_entity', - 0, - new EntityCollection(), - null, - new Criteria(), - Context::createDefaultContext() - ); - - $collection = new EntityCollection(); - $media = new MediaEntity(); - $media->setId('test'); - $media->setFileExtension('jpg'); - $media->setPath('thumbnail.jpg'); - $media->setFileName('test.jpg'); - $media->setMimeType('image/jpg'); - $media->setFileSize(100); - $media->setCreatedAt(new \DateTime()); - $media->setUpdatedAt(new \DateTime()); - $media->setMediaFolderId('test'); - $media->setMediaType(new ImageType()); - $collection->add($media); - - $mediaRepositoryResults[] = new EntitySearchResult( - 'media_entity', - 1, - $collection, - null, - new Criteria(), - Context::createDefaultContext() - ); - - $matcher = static::exactly(2); - - $mediaRepository = $this->createMock(EntityRepository::class); - $mediaRepository->expects($matcher) - ->method('search') - ->willReturnCallback(function () use ($mediaRepositoryResults, $matcher): EntitySearchResult { - return match ($matcher->numberOfInvocations()) { - 1 => $mediaRepositoryResults[0], - 2 => $mediaRepositoryResults[1], - default => throw new \RuntimeException('Unexpected invocation count'), - }; - }); - - $mediaFolderRepository = $this->createMock(EntityRepository::class); - $mediaFolderRepository->expects(static::once()) - ->method('searchIds') - ->willReturn( - new IdSearchResult( - 1, - [['primaryKey' => 'folder-id', 'data' => []]], - new Criteria(), - Context::createDefaultContext(), - ), - ); - - $fileSaver = $this->createMock(FileSaver::class); - $fileFetcher = $this->createMock(FileFetcher::class); - - $controller = new TestController( - $urlGenerator, - $mediaRepository, - $mediaFolderRepository, - $fileSaver, - $fileFetcher, - ); - - $request = new Request(); - $dataBag = new RequestDataBag(); - $dataBag->add(['salesChannelId' => '1111']); - - $result = $controller->check($request, $dataBag); - static::assertSame('{"url":"http:\/\/localhost\/thumbnail.jpg?width=200"}', $result->getContent()); - - static::assertTrue($request->attributes->has(TestController::REQUEST_ATTRIBUTE_TEST_ACTIVE)); - static::assertSame('1111', $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID)); - } -} diff --git a/tests/unit/Core/Media/ExtendedUrlParamsTest.php b/tests/unit/Core/Media/ExtendedUrlParamsTest.php deleted file mode 100644 index 7ee6f76..0000000 --- a/tests/unit/Core/Media/ExtendedUrlParamsTest.php +++ /dev/null @@ -1,156 +0,0 @@ -assign(['path' => null]); - - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('"path" must be a string'); - ExtendedUrlParams::fromMedia($entity); - } - - public function testFromMediaWithNotSetUpdatedAtAndCreatedAt(): void - { - $entity = new Entity(); - $entity->assign([ - '_uniqueIdentifier' => Uuid::randomHex(), - 'path' => 'test.txt', - ]); - - $result = ExtendedUrlParams::fromMedia($entity); - static::assertNull($result->updatedAt); - } - - public function testFromMediaWithUpdatedAtWithString(): void - { - $entity = new Entity(); - $entity->assign([ - '_uniqueIdentifier' => Uuid::randomHex(), - 'path' => 'test.txt', - 'updatedAt' => '2021-09-01 12:00:00', - ]); - - $result = ExtendedUrlParams::fromMedia($entity); - static::assertNull($result->updatedAt); - } - - public function testFromMediaWithUpdatedAtWithDateTimeInterface(): void - { - $entity = new Entity(); - $entity->assign([ - '_uniqueIdentifier' => Uuid::randomHex(), - 'path' => 'test.txt', - 'updatedAt' => new \DateTime(), - ]); - - $result = ExtendedUrlParams::fromMedia($entity); - static::assertInstanceOf(\DateTimeInterface::class, $result->updatedAt); - } - - public function testFromThumbnailThrowsExceptionOnInvalidPath(): void - { - $entity = new Entity(); - $entity->assign(['path' => null]); - - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('"path" must be a string'); - ExtendedUrlParams::fromThumbnail($entity); - } - - public function testFromThumbnailWithNotSetUpdatedAtAndCreatedAt(): void - { - $entity = new Entity(); - $entity->assign([ - '_uniqueIdentifier' => Uuid::randomHex(), - 'path' => 'test.txt', - 'width' => 100, - ]); - - $urlParam = ExtendedUrlParams::fromMedia($entity); - - $entity->setTranslated(['mediaUrlParam' => ExtendedUrlParam::fromUrlParams($urlParam)]); - - $result = ExtendedUrlParams::fromThumbnail($entity); - static::assertNull($result->updatedAt); - } - - public function testFromThumbnailWithUpdatedAtWithString(): void - { - $entity = new Entity(); - $entity->assign([ - '_uniqueIdentifier' => Uuid::randomHex(), - 'path' => 'test.txt', - 'width' => 100, - 'updatedAt' => '2021-09-01 12:00:00', - ]); - - $urlParam = ExtendedUrlParams::fromMedia($entity); - - $entity->setTranslated(['mediaUrlParam' => ExtendedUrlParam::fromUrlParams($urlParam)]); - - $result = ExtendedUrlParams::fromThumbnail($entity); - static::assertNull($result->updatedAt); - } - - public function testFromThumbnailWithoutMediaUrlParamThrowsException(): void - { - $entity = new Entity(); - $entity->assign([ - '_uniqueIdentifier' => Uuid::randomHex(), - 'path' => 'test.txt', - 'width' => 100, - 'updatedAt' => '2021-09-01 12:00:00', - ]); - - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage(\sprintf('"mediaUrlParam" within translations must be type of "%s"', ExtendedUrlParams::class)); - ExtendedUrlParams::fromThumbnail($entity); - } - - public function testFromThumbnailWithInvalidWidthResultsInNullWidth(): void - { - $entity = new Entity(); - $entity->assign([ - '_uniqueIdentifier' => Uuid::randomHex(), - 'path' => 'test.txt', - 'width' => 'invalid', - 'updatedAt' => '2021-09-01 12:00:00', - ]); - - $urlParam = ExtendedUrlParams::fromMedia($entity); - - $entity->setTranslated(['mediaUrlParam' => ExtendedUrlParam::fromUrlParams($urlParam)]); - - $result = ExtendedUrlParams::fromThumbnail($entity); - static::assertNull($result->width); - } - - public function testFromThumbnailWithUpdatedAtWithDateTimeInterface(): void - { - $entity = new Entity(); - $entity->assign([ - '_uniqueIdentifier' => Uuid::randomHex(), - 'path' => 'test.txt', - 'width' => 100, - 'updatedAt' => new \DateTime(), - ]); - - $urlParam = ExtendedUrlParams::fromMedia($entity); - - $entity->setTranslated(['mediaUrlParam' => ExtendedUrlParam::fromUrlParams($urlParam)]); - - $result = ExtendedUrlParams::fromThumbnail($entity); - static::assertInstanceOf(\DateTimeInterface::class, $result->updatedAt); - } -} diff --git a/tests/unit/Core/Media/MediaUrlGeneratorTest.php b/tests/unit/Core/Media/MediaUrlGeneratorTest.php deleted file mode 100644 index e78c946..0000000 --- a/tests/unit/Core/Media/MediaUrlGeneratorTest.php +++ /dev/null @@ -1,297 +0,0 @@ -createMock(AbstractMediaUrlGenerator::class); - $thumbnailUrlTemplate = $this->createMock(ThumbnailUrlTemplateInterface::class); - $thumbnailUrlTemplate->expects(static::once()) - ->method('getUrl') - ->willReturn('https://localhost/media/123.jpg?width=3000'); - $filesystem = $this->createMock(PrefixFilesystem::class); - $filesystem->expects(static::once()) - ->method('publicUrl') - ->willReturn('https://localhost'); - - $configReader = $this->createMock(ConfigReader::class); - - $defaultPluginConfig = [ - 'Active' => true, - 'ProcessOriginalImageMaxWidth' => '3000', - 'ExtensionsAllowList' => 'jpg', - 'ThumbnailPattern' => '{mediaUrl}/{mediaPath}?width={width}', - ]; - $configReader->expects(static::any()) - ->method('getConfig') - ->willReturnCallback(function ($key) use ($defaultPluginConfig) { - return $defaultPluginConfig[$key] ?? null; - }); - - $mediaUrlGenerator = new MediaUrlGenerator( - $decoratedMediaUrlGenerator, - $thumbnailUrlTemplate, - $filesystem, - $configReader - ); - - $urlParam = new UrlParams( - '123', - UrlParamsSource::MEDIA, - 'media/123.jpg', - null - ); - - $generatedPaths = $mediaUrlGenerator->generate([$urlParam]); - - static::assertIsIterable($generatedPaths); - static::assertCount(1, $generatedPaths); - static::assertEquals('https://localhost/media/123.jpg?width=3000', current($generatedPaths)); - } - - public function testGenerateWithExtendedUrlParam(): void - { - $decoratedMediaUrlGenerator = $this->createMock(AbstractMediaUrlGenerator::class); - $thumbnailUrlTemplate = $this->createMock(ThumbnailUrlTemplateInterface::class); - $thumbnailUrlTemplate->expects(static::once()) - ->method('getUrl') - ->willReturn('https://localhost/media/123.jpg?width=100'); - $filesystem = $this->createMock(PrefixFilesystem::class); - $filesystem->expects(static::once()) - ->method('publicUrl') - ->willReturn('https://localhost'); - - $configReader = $this->createMock(ConfigReader::class); - - $defaultPluginConfig = [ - 'Active' => true, - 'ProcessOriginalImageMaxWidth' => '3000', - 'ExtensionsAllowList' => 'jpg', - 'ThumbnailPattern' => '{mediaUrl}/{mediaPath}?width={width}', - ]; - $configReader->expects(static::any()) - ->method('getConfig') - ->willReturnCallback(function ($key) use ($defaultPluginConfig) { - return $defaultPluginConfig[$key] ?? null; - }); - - $mediaUrlGenerator = new MediaUrlGenerator( - $decoratedMediaUrlGenerator, - $thumbnailUrlTemplate, - $filesystem, - $configReader - ); - - $entity = new Entity(); - $entity->assign([ - '_uniqueIdentifier' => Uuid::randomHex(), - 'path' => 'media/123.jpg', - 'width' => 100, - ]); - - $urlParam = ExtendedUrlParams::fromMedia($entity); - - $entity->setTranslated(['mediaUrlParam' => ExtendedUrlParam::fromUrlParams($urlParam)]); - - $urlParam = ExtendedUrlParams::fromThumbnail($entity); - - $generatedPaths = $mediaUrlGenerator->generate([$urlParam]); - - static::assertIsIterable($generatedPaths); - static::assertCount(1, $generatedPaths); - static::assertEquals('https://localhost/media/123.jpg?width=100', current($generatedPaths)); - } - - public function testGenerateWithInactiveConfig(): void - { - $decoratedMediaUrlGenerator = $this->createMock(AbstractMediaUrlGenerator::class); - $decoratedMediaUrlGenerator->expects(static::once()) - ->method('generate') - ->willReturn(['https://localhost/media/123.jpg']); - - $thumbnailUrlTemplate = $this->createMock(ThumbnailUrlTemplateInterface::class); - $thumbnailUrlTemplate->expects(static::never()) - ->method('getUrl') - ->willReturn('https://localhost/media/123.jpg?width=3000'); - $filesystem = $this->createMock(PrefixFilesystem::class); - $filesystem->expects(static::never()) - ->method('publicUrl') - ->willReturn('https://localhost'); - - $configReader = $this->createMock(ConfigReader::class); - - $defaultPluginConfig = [ - 'Active' => false, - 'ProcessOriginalImageMaxWidth' => '3000', - 'ExtensionsAllowList' => 'jpg', - 'ThumbnailPattern' => '{mediaUrl}/{mediaPath}?width={width}', - ]; - $configReader->expects(static::any()) - ->method('getConfig') - ->willReturnCallback(function ($key) use ($defaultPluginConfig) { - return $defaultPluginConfig[$key] ?? null; - }); - - $urlParam = new UrlParams( - '123', - UrlParamsSource::MEDIA, - 'media/123.jpg', - null - ); - - $mediaUrlGenerator = new MediaUrlGenerator( - $decoratedMediaUrlGenerator, - $thumbnailUrlTemplate, - $filesystem, - $configReader - ); - - $generatedPaths = $mediaUrlGenerator->generate([$urlParam]); - - static::assertIsIterable($generatedPaths); - static::assertCount(1, $generatedPaths); - static::assertEquals('https://localhost/media/123.jpg', current($generatedPaths)); - } - - /** - * @dataProvider provideAllowedExtensions - */ - public function testGenerateWithNotAllowedExtensionResultsInOriginal(string $allowList): void - { - $decoratedMediaUrlGenerator = $this->createMock(AbstractMediaUrlGenerator::class); - $decoratedMediaUrlGenerator->expects(static::once()) - ->method('generate') - ->willReturn(['https://localhost/media/123.jpg']); - - $thumbnailUrlTemplate = $this->createMock(ThumbnailUrlTemplateInterface::class); - $thumbnailUrlTemplate->expects(static::never()) - ->method('getUrl') - ->willReturn('https://localhost/media/123.jpg?width=3000'); - $filesystem = $this->createMock(PrefixFilesystem::class); - $filesystem->expects(static::once()) - ->method('publicUrl') - ->willReturn('https://localhost'); - - $configReader = $this->createMock(ConfigReader::class); - - $defaultPluginConfig = [ - 'Active' => true, - 'ProcessOriginalImageMaxWidth' => '3000', - 'ExtensionsAllowList' => $allowList, - 'ThumbnailPattern' => '{mediaUrl}/{mediaPath}?width={width}', - ]; - $configReader->expects(static::any()) - ->method('getConfig') - ->willReturnCallback(function ($key) use ($defaultPluginConfig) { - return $defaultPluginConfig[$key] ?? null; - }); - - $urlParam = new UrlParams( - '123', - UrlParamsSource::MEDIA, - 'media/123.jpg', - null - ); - - $mediaUrlGenerator = new MediaUrlGenerator( - $decoratedMediaUrlGenerator, - $thumbnailUrlTemplate, - $filesystem, - $configReader - ); - - $generatedPaths = $mediaUrlGenerator->generate([$urlParam]); - - static::assertIsIterable($generatedPaths); - static::assertCount(1, $generatedPaths); - static::assertEquals('https://localhost/media/123.jpg', current($generatedPaths)); - } - - public function testMultipleGenerationsUseCachedExtensionAllowList(): void - { - $decoratedMediaUrlGenerator = $this->createMock(AbstractMediaUrlGenerator::class); - $thumbnailUrlTemplate = $this->createMock(ThumbnailUrlTemplateInterface::class); - $thumbnailUrlTemplate->expects(static::exactly(2)) - ->method('getUrl') - ->willReturn('https://localhost/media/123.jpg?width=100'); - $filesystem = $this->createMock(PrefixFilesystem::class); - $filesystem->expects(static::once()) - ->method('publicUrl') - ->willReturn('https://localhost'); - - $configReader = $this->createMock(ConfigReader::class); - - $defaultPluginConfig = [ - 'Active' => true, - 'ProcessOriginalImageMaxWidth' => '3000', - 'ExtensionsAllowList' => 'jpg', - 'ThumbnailPattern' => '{mediaUrl}/{mediaPath}?width={width}', - ]; - $configReader->expects(static::exactly(3)) - ->method('getConfig') - ->willReturnCallback(function ($key) use ($defaultPluginConfig) { - return $defaultPluginConfig[$key] ?? null; - }); - - $mediaUrlGenerator = new MediaUrlGenerator( - $decoratedMediaUrlGenerator, - $thumbnailUrlTemplate, - $filesystem, - $configReader - ); - - $entity = new Entity(); - $entity->assign([ - '_uniqueIdentifier' => Uuid::randomHex(), - 'path' => 'media/123.jpg', - 'width' => 100, - ]); - - $urlParam = ExtendedUrlParams::fromMedia($entity); - - $entity->setTranslated(['mediaUrlParam' => ExtendedUrlParam::fromUrlParams($urlParam)]); - - $urlParam = ExtendedUrlParams::fromThumbnail($entity); - - $entity2 = new Entity(); - $entity2->assign([ - '_uniqueIdentifier' => Uuid::randomHex(), - 'path' => 'media/1232.jpg', - 'width' => 100, - ]); - - $entity2->setTranslated(['mediaUrlParam' => ExtendedUrlParam::fromUrlParams($urlParam)]); - - $urlParam2 = ExtendedUrlParams::fromThumbnail($entity); - - $generatedPaths = $mediaUrlGenerator->generate([$urlParam, $urlParam2]); - - static::assertIsIterable($generatedPaths); - static::assertCount(2, $generatedPaths); - static::assertEquals('https://localhost/media/123.jpg?width=100', current($generatedPaths)); - } - - /** - * @return iterable - */ - public static function provideAllowedExtensions(): iterable - { - yield ['gif,png']; - yield ['']; - } -} diff --git a/tests/unit/Core/Media/MediaUrlLoaderTest.php b/tests/unit/Core/Media/MediaUrlLoaderTest.php deleted file mode 100644 index eb3c508..0000000 --- a/tests/unit/Core/Media/MediaUrlLoaderTest.php +++ /dev/null @@ -1,267 +0,0 @@ -createMock(MediaUrlGenerator::class); - $mediaUrlGenerator->expects(static::once()) - ->method('generate') - ->willReturn([$id => 'https://example.com/a0/image.jpg']); - - $mediaUrlLoader = new MediaUrlLoader($mediaUrlGenerator); - $entity = new PartialEntity(); - $entity->assign([ - 'id' => $id, - 'path' => 'a0/image.txt', - 'private' => false, - ]); - - static::assertFalse($entity->has('url')); - - $mediaUrlLoader->loaded([$entity]); - - static::assertTrue($entity->has('url')); - static::assertSame('https://example.com/a0/image.jpg', $entity->get('url')); - } - - public function testLoadedWithMissingPrivate(): void - { - $id = Uuid::randomHex(); - - $mediaUrlGenerator = $this->createMock(MediaUrlGenerator::class); - $mediaUrlGenerator->expects(static::never()) - ->method('generate') - ->willReturn([$id => 'https://example.com/a0/image.jpg']); - - $mediaUrlLoader = new MediaUrlLoader($mediaUrlGenerator); - $entity = new PartialEntity(); - $entity->assign([ - 'id' => $id, - 'path' => 'a0/image.txt', - ]); - - static::assertFalse($entity->has('url')); - - $mediaUrlLoader->loaded([$entity]); - - static::assertFalse($entity->has('url')); - } - - public function testLoadedWithMissingUrlResult(): void - { - $id = Uuid::randomHex(); - - $mediaUrlGenerator = $this->createMock(MediaUrlGenerator::class); - $mediaUrlGenerator->expects(static::once()) - ->method('generate') - ->willReturn([]); - - $mediaUrlLoader = new MediaUrlLoader($mediaUrlGenerator); - $entity = new PartialEntity(); - $entity->assign([ - 'id' => $id, - 'path' => 'a0/image.txt', - 'private' => false, - ]); - - static::assertFalse($entity->has('url')); - - $mediaUrlLoader->loaded([$entity]); - - static::assertFalse($entity->has('url')); - } - - public function testLoadedWithMissingPathResult(): void - { - $id = Uuid::randomHex(); - - $mediaUrlGenerator = $this->createMock(MediaUrlGenerator::class); - $mediaUrlGenerator->expects(static::never()) - ->method('generate'); - - $mediaUrlLoader = new MediaUrlLoader($mediaUrlGenerator); - $entity = new PartialEntity(); - $entity->assign([ - 'id' => $id, - 'private' => false, - ]); - - static::assertFalse($entity->has('url')); - - $mediaUrlLoader->loaded([$entity]); - - static::assertFalse($entity->has('url')); - } - - public function testLoadedWithThumbnailHavingUrls(): void - { - $mediaUrlGenerator = $this->createMock(MediaUrlGenerator::class); - $mediaUrlGenerator->expects(static::once()) - ->method('generate') - ->willReturn([ - '1' => 'https://example.com/a0/image.jpg?width=100', - '2' => 'https://example.com/a0/thumbnailimage.jpg?width=100', - ]); - - $mediaUrlLoader = new MediaUrlLoader($mediaUrlGenerator); - $entity = new PartialEntity(); - $entity->assign([ - 'id' => '1', - 'path' => 'a0/image.txt', - 'private' => false, - 'width' => 100, - 'thumbnails' => [ - (new PartialEntity())->assign([ - 'id' => '2', - 'path' => 'a0/thumbnailimage.jpg', - 'width' => 100, - ]), - ], - ]); - - static::assertFalse($entity->has('url')); - - $thumbnails = $entity->get('thumbnails'); - static::assertIsArray($thumbnails); - static::assertFalse($thumbnails[0]->has('url')); - - $mediaUrlLoader->loaded([$entity]); - - static::assertTrue($entity->has('url')); - - $thumbnails = $entity->get('thumbnails'); - static::assertIsArray($thumbnails); - static::assertTrue($thumbnails[0]->has('url')); - static::assertSame('https://example.com/a0/thumbnailimage.jpg?width=100', $thumbnails[0]->get('url')); - } - - public function testLoadedWithThumbnailHavingMaxWidthWithMissingWidth(): void - { - $mediaUrlGenerator = $this->createMock(MediaUrlGenerator::class); - $mediaUrlGenerator->expects(static::once()) - ->method('generate') - ->willReturn([ - '1' => 'https://example.com/a0/image.jpg?width=100', - '2' => 'https://example.com/a0/thumbnailimage.jpg?width=100', - ]); - - $mediaUrlLoader = new MediaUrlLoader($mediaUrlGenerator); - $entity = new PartialEntity(); - $entity->assign([ - 'id' => '1', - 'path' => 'a0/image.txt', - 'private' => false, - 'thumbnails' => [ - (new PartialEntity())->assign([ - 'id' => '2', - 'path' => 'a0/thumbnailimage.jpg', - ]), - ], - ]); - - static::assertFalse($entity->has('url')); - - $thumbnails = $entity->get('thumbnails'); - static::assertIsArray($thumbnails); - static::assertFalse($thumbnails[0]->has('url')); - - $mediaUrlLoader->loaded([$entity]); - - static::assertTrue($entity->has('url')); - - $thumbnails = $entity->get('thumbnails'); - static::assertIsArray($thumbnails); - static::assertTrue($thumbnails[0]->has('url')); - static::assertSame('https://example.com/a0/thumbnailimage.jpg?width=100', $thumbnails[0]->get('url')); - } - - public function testLoadedWithThumbnailHavingNoUrl(): void - { - $mediaUrlGenerator = $this->createMock(MediaUrlGenerator::class); - $mediaUrlGenerator->expects(static::once()) - ->method('generate') - ->willReturn([ - '1' => 'https://example.com/a0/image.jpg', - ]); - - $mediaUrlLoader = new MediaUrlLoader($mediaUrlGenerator); - $entity = new PartialEntity(); - $entity->assign([ - 'id' => '1', - 'path' => 'a0/image.txt', - 'private' => false, - 'width' => 100, - 'thumbnails' => [ - (new PartialEntity())->assign([ - 'id' => '2', - ]), - ], - ]); - - static::assertFalse($entity->has('url')); - - $thumbnails = $entity->get('thumbnails'); - static::assertIsArray($thumbnails); - static::assertFalse($thumbnails[0]->has('url')); - - $mediaUrlLoader->loaded([$entity]); - - static::assertTrue($entity->has('url')); - - $thumbnails = $entity->get('thumbnails'); - static::assertIsArray($thumbnails); - static::assertFalse($thumbnails[0]->has('url')); - } - - /** - * @dataProvider provideInvalidThumbnailData - */ - public function testLoadedWithNotIterableThumbnail(mixed $thumbnail): void - { - $mediaUrlGenerator = $this->createMock(MediaUrlGenerator::class); - $mediaUrlGenerator->expects(static::once()) - ->method('generate') - ->willReturn([ - '1' => 'https://example.com/a0/image.jpg', - ]); - - $mediaUrlLoader = new MediaUrlLoader($mediaUrlGenerator); - $entity = new PartialEntity(); - $entity->assign([ - 'id' => '1', - 'path' => 'a0/image.txt', - 'private' => false, - 'width' => 100, - 'thumbnails' => $thumbnail, - ]); - - static::assertFalse($entity->has('url')); - - $mediaUrlLoader->loaded([$entity]); - - static::assertTrue($entity->has('url')); - } - - /** - * @return iterable - */ - public static function provideInvalidThumbnailData(): iterable - { - yield [[]]; - yield [[null]]; - yield ['']; - yield [['']]; - yield [new PartialEntity()]; - } -} diff --git a/tests/unit/EventListener/ThumbnailSizesChangedListenerTest.php b/tests/unit/EventListener/ThumbnailSizesChangedListenerTest.php deleted file mode 100644 index 98029b4..0000000 --- a/tests/unit/EventListener/ThumbnailSizesChangedListenerTest.php +++ /dev/null @@ -1,88 +0,0 @@ - 'onThumbnailSizeChanged', - MediaFolderConfigurationMediaThumbnailSizeDefinition::ENTITY_NAME . '.deleted' => 'onThumbnailSizeChanged', - ], ThumbnailSizesChangedListener::getSubscribedEvents()); - } - - public function testOnThumbnailSizeChanged(): void - { - $generateThumbnailsCommand = $this->createMock(GenerateThumbnailsCommand::class); - $generateThumbnailsCommand->expects(static::once()) - ->method('run'); - - $generateThumbnailsCommand->expects(static::once()) - ->method('getDefinition') - ->willReturn((new GenerateThumbnailsCommand( - $this->createMock(ThumbnailService::class), - $this->createMock(EntityRepository::class), - $this->createMock(EntityRepository::class), - $this->createMock(MessageBus::class), - ))->getDefinition()); - - $mediaFolderEntity = new MediaFolderEntity(); - $mediaFolderEntity->setId('1111'); - $mediaFolderEntity->setName('Product Media'); - - $mediaFolderCollection = new MediaFolderCollection(); - $mediaFolderCollection->add($mediaFolderEntity); - - $mediaFolderRepository = new StaticEntityRepository([$mediaFolderCollection]); - - $thumbnailSizesChangedListener = new ThumbnailSizesChangedListener( - $generateThumbnailsCommand, - $mediaFolderRepository - ); - - $entityName = MediaFolderConfigurationMediaThumbnailSizeDefinition::ENTITY_NAME; - - $writtenResult = new EntityWriteResult('1111', ['mediaFolderConfigurationId' => '1111'], $entityName, EntityWriteResult::OPERATION_INSERT); - $writtenEvent = new EntityWrittenEvent($entityName, [$writtenResult], Context::createDefaultContext()); - - $thumbnailSizesChangedListener->onThumbnailSizeChanged($writtenEvent); - } - - public function testOnThumbnailSizeChangedWithEmptyPayload(): void - { - $generateThumbnailsCommand = $this->createMock(GenerateThumbnailsCommand::class); - $generateThumbnailsCommand->expects(static::never()) - ->method('run'); - - $mediaFolderRepository = $this->createMock(EntityRepository::class); - $mediaFolderRepository->expects(static::never()) - ->method('search'); - - $thumbnailSizesChangedListener = new ThumbnailSizesChangedListener( - $generateThumbnailsCommand, - $mediaFolderRepository - ); - - $entityName = MediaFolderConfigurationMediaThumbnailSizeDefinition::ENTITY_NAME; - - $writtenResult = new EntityWriteResult('1111', [], $entityName, EntityWriteResult::OPERATION_INSERT); - $writtenEvent = new EntityWrittenEvent($entityName, [$writtenResult], Context::createDefaultContext()); - - $thumbnailSizesChangedListener->onThumbnailSizeChanged($writtenEvent); - } -} diff --git a/tests/unit/FroshPlatformThumbnailProcessorTest.php b/tests/unit/FroshPlatformThumbnailProcessorTest.php deleted file mode 100644 index 4485930..0000000 --- a/tests/unit/FroshPlatformThumbnailProcessorTest.php +++ /dev/null @@ -1,27 +0,0 @@ -createMock(ContainerBuilder::class); - $container->expects(static::exactly(3)) - ->method('addCompilerPass'); - - $pluginBootstrap->build($container); - } - - public function testExecuteComposerCommands(): void - { - $pluginBootstrap = new FroshPlatformThumbnailProcessor(true, __DIR__ . '/../../'); - static::assertTrue($pluginBootstrap->executeComposerCommands()); - } -} diff --git a/tests/unit/Migration/Migration1686772873AddActiveConfigTest.php b/tests/unit/Migration/Migration1686772873AddActiveConfigTest.php deleted file mode 100644 index a018539..0000000 --- a/tests/unit/Migration/Migration1686772873AddActiveConfigTest.php +++ /dev/null @@ -1,110 +0,0 @@ -getCreationTimestamp()); - } - - public function testUpdate(): void - { - $migration = new Migration1686772873AddActiveConfig(); - $connection = $this->createMock(Connection::class); - - $queryBuilder = $this->createMock(QueryBuilder::class); - $queryBuilder->expects(static::once())->method('select')->willReturn($queryBuilder); - $queryBuilder->expects(static::once())->method('from')->willReturn($queryBuilder); - $queryBuilder->expects(static::once())->method('where')->willReturn($queryBuilder); - $queryBuilder->expects(static::once())->method('andWhere')->willReturn($queryBuilder); - $queryBuilder->expects(static::once())->method('setParameter')->willReturn($queryBuilder); - - $statement = $this->createMock(Result::class); - $statement->expects(static::once())->method('fetchOne')->willReturn('3.0.2'); - - $queryBuilder->expects(static::once())->method('executeQuery')->willReturn($statement); - - $connection->expects(static::once()) - ->method('createQueryBuilder') - ->willReturn($queryBuilder); - - $connection->expects(static::once()) - ->method('update'); - - $migration->update($connection); - } - - /** - * @dataProvider provideVersions - */ - public function testUpdateWithVersions(bool $runUpdate, ?string $version): void - { - $migration = new Migration1686772873AddActiveConfig(); - $connection = $this->createMock(Connection::class); - - $queryBuilder = $this->createMock(QueryBuilder::class); - $queryBuilder->expects(static::once())->method('select')->willReturn($queryBuilder); - $queryBuilder->expects(static::once())->method('from')->willReturn($queryBuilder); - $queryBuilder->expects(static::once())->method('where')->willReturn($queryBuilder); - $queryBuilder->expects(static::once())->method('andWhere')->willReturn($queryBuilder); - $queryBuilder->expects(static::once())->method('setParameter')->willReturn($queryBuilder); - - $statement = $this->createMock(Result::class); - $statement->expects(static::once())->method('fetchOne')->willReturn($version); - - $queryBuilder->expects(static::once())->method('executeQuery')->willReturn($statement); - - $connection->expects(static::once()) - ->method('createQueryBuilder') - ->willReturn($queryBuilder); - - $expects = $runUpdate ? static::once() : static::never(); - $connection->expects($expects) - ->method('update'); - - $migration->update($connection); - } - - public function testUpdateDestructive(): void - { - $migration = new Migration1686772873AddActiveConfig(); - $connection = $this->createMock(Connection::class); - $connection->expects(static::never()) - ->method('createQueryBuilder'); - $migration->updateDestructive($connection); - } - - /** - * @return iterable - */ - public static function provideVersions(): iterable - { - yield [false, null]; - yield [true, '2.0.0']; - yield [true, '2.0.1']; - yield [false, '2.1.0']; - yield [false, '2.1.1']; - yield [true, '3.0.0']; - yield [true, '3.0.1']; - yield [true, '3.0.2']; - yield [true, '3.0.3']; - yield [false, '3.0.4']; - yield [false, '3.1.0']; - yield [false, '3.1.1']; - yield [false, '3.1.2']; - yield [false, '3.1.3']; - yield [false, '3.1.4']; - yield [false, '3.1.5']; - yield [false, '3.1.6']; - yield [false, '3.1.7']; - } -} diff --git a/tests/unit/Service/ConfigReaderTest.php b/tests/unit/Service/ConfigReaderTest.php deleted file mode 100644 index bc53bf1..0000000 --- a/tests/unit/Service/ConfigReaderTest.php +++ /dev/null @@ -1,139 +0,0 @@ -set('FroshPlatformThumbnailProcessor.config.AnyString', 'test', $salesChannelId); - $systemConfigService->set('FroshPlatformThumbnailProcessor.config.AnyNumber', 5, $salesChannelId); - - $salesChannelIdDetector = $this->createMock(SalesChannelIdDetector::class); - $salesChannelIdDetector->expects(static::once()) - ->method('getSalesChannelId')->willReturn($salesChannelId); - - $class = new ConfigReader($systemConfigService, $salesChannelIdDetector, new RequestStack()); - - $anyStringConfig = $class->getConfig('AnyString'); - static::assertIsString($anyStringConfig); - static::assertSame('test', $anyStringConfig); - - $anyNumberConfig = $class->getConfig('AnyNumber'); - static::assertIsNumeric($anyNumberConfig); - static::assertSame(5, $anyNumberConfig); - } - - /** - * @dataProvider getWidths - */ - public function testGetConfigProcessOriginalImageMaxWidthAlwaysString(int|string|float $width): void - { - $systemConfigService = new StaticSystemConfigService(); - $systemConfigService->set('FroshPlatformThumbnailProcessor.config.ProcessOriginalImageMaxWidth', $width); - - $salesChannelIdDetector = $this->createMock(SalesChannelIdDetector::class); - $salesChannelIdDetector->expects(static::once()) - ->method('getSalesChannelId')->willReturn(null); - - $class = new ConfigReader($systemConfigService, $salesChannelIdDetector, new RequestStack()); - - $anyStringConfig = $class->getConfig('ProcessOriginalImageMaxWidth'); - static::assertIsString($anyStringConfig); - static::assertSame('300', $anyStringConfig); - } - - public function testGetConfigProcessOriginalImageMaxWidthFallbacksTo3000(): void - { - $systemConfigService = new StaticSystemConfigService(); - $systemConfigService->set('FroshPlatformThumbnailProcessor.config.ProcessOriginalImageMaxWidth', null); - - $salesChannelIdDetector = $this->createMock(SalesChannelIdDetector::class); - $salesChannelIdDetector->expects(static::once()) - ->method('getSalesChannelId')->willReturn(null); - - $class = new ConfigReader($systemConfigService, $salesChannelIdDetector, new RequestStack()); - - $anyStringConfig = $class->getConfig('ProcessOriginalImageMaxWidth'); - static::assertIsString($anyStringConfig); - static::assertSame('3000', $anyStringConfig); - } - - /** - * @dataProvider getActiveValues - */ - public function testGetConfigActive(null|bool $value): void - { - $systemConfigService = new StaticSystemConfigService(); - $systemConfigService->set('FroshPlatformThumbnailProcessor.config.Active', $value); - - $salesChannelIdDetector = $this->createMock(SalesChannelIdDetector::class); - $salesChannelIdDetector->expects(static::once()) - ->method('getSalesChannelId')->willReturn(null); - - $class = new ConfigReader($systemConfigService, $salesChannelIdDetector, new RequestStack()); - - static::assertTrue($class->getConfig('Active')); - } - - public function testGetConfigActiveWithActiveTest(): void - { - $systemConfigService = new StaticSystemConfigService(); - $systemConfigService->set('FroshPlatformThumbnailProcessor.config.Active', false); - - $salesChannelIdDetector = $this->createMock(SalesChannelIdDetector::class); - $salesChannelIdDetector->expects(static::once()) - ->method('getSalesChannelId')->willReturn(null); - - $requestStack = new RequestStack(); - $requestStack->push(new Request(attributes: [TestController::REQUEST_ATTRIBUTE_TEST_ACTIVE => true])); - - $class = new ConfigReader($systemConfigService, $salesChannelIdDetector, $requestStack); - - static::assertTrue($class->getConfig('Active')); - } - - /** - * @return iterable - */ - public static function getSalesChannelIds(): iterable - { - yield [null]; - yield [Uuid::randomHex()]; - yield [Uuid::randomHex()]; - yield [Uuid::randomHex()]; - yield [Uuid::randomHex()]; - } - - /** - * @return iterable - */ - public static function getWidths(): iterable - { - yield [300]; - yield ['300']; - yield [300.00]; - } - - /** - * @return iterable - */ - public static function getActiveValues(): iterable - { - yield [null]; - yield [true]; - } -} diff --git a/tests/unit/Service/SalesChannelIdDetectorTest.php b/tests/unit/Service/SalesChannelIdDetectorTest.php deleted file mode 100644 index 84d4fb3..0000000 --- a/tests/unit/Service/SalesChannelIdDetectorTest.php +++ /dev/null @@ -1,116 +0,0 @@ - 'mySalesChannelId', - ], - ); - - $requestStack->push($mainRequest); - $requestStack->push(new Request(['foo' => 'bar'])); - - $productExportRepository = $this->createMock(EntityRepository::class); - $class = new SalesChannelIdDetector($requestStack, $productExportRepository); - - static::assertSame('mySalesChannelId', $class->getSalesChannelId()); - } - - public function testGetSalesChannelIdWithoutMainRequest(): void - { - $requestStack = new RequestStack(); - - $productExportRepository = $this->createMock(EntityRepository::class); - $class = new SalesChannelIdDetector($requestStack, $productExportRepository); - - static::assertNull($class->getSalesChannelId()); - } - - public function testGetSalesChannelIdNull(): void - { - $requestStack = new RequestStack(); - $requestStack->push(new Request()); - - $productExportRepository = $this->createMock(EntityRepository::class); - $class = new SalesChannelIdDetector($requestStack, $productExportRepository); - - static::assertNull($class->getSalesChannelId()); - } - - public function testGetSalesChannelId(): void - { - $requestStack = new RequestStack(); - $requestStack->push(new Request( - attributes: [ - PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID => 'mySalesChannelId', - ], - )); - - $productExportRepository = $this->createMock(EntityRepository::class); - $class = new SalesChannelIdDetector($requestStack, $productExportRepository); - - static::assertSame('mySalesChannelId', $class->getSalesChannelId()); - } - - public function testGetSalesChannelIdProductExport(): void - { - $requestStack = new RequestStack(); - $requestStack->push(new Request( - attributes: [ - '_route' => 'store-api.product.export', - 'fileName' => 'anyFilename', - 'accessKey' => 'anyAccessKey', - ], - )); - - $productExportEntity = new ProductExportEntity(); - $productExportEntity->setId(Uuid::randomHex()); - $productExportEntity->setFileName('anyFilename'); - $productExportEntity->setAccessKey('anyAccessKey'); - $productExportEntity->setSalesChannelId('myCoolSalesChannelId'); - - $productExportCollection = new ProductExportCollection(); - $productExportCollection->add($productExportEntity); - - $productExportRepository = new StaticEntityRepository([$productExportCollection]); - - $class = new SalesChannelIdDetector($requestStack, $productExportRepository); - - static::assertSame('myCoolSalesChannelId', $class->getSalesChannelId()); - } - - public function testGetSalesChannelIdProductExportWithoutFileNameAndAccessKey(): void - { - $requestStack = new RequestStack(); - $requestStack->push(new Request( - attributes: [ - '_route' => 'store-api.product.export', - ], - )); - - $productExportRepository = $this->createMock(StaticEntityRepository::class); - $productExportRepository->expects(static::never())->method('search'); - - $class = new SalesChannelIdDetector($requestStack, $productExportRepository); - - static::assertNull($class->getSalesChannelId()); - } -} diff --git a/tests/unit/Service/ThumbnailUrlTemplateTest.php b/tests/unit/Service/ThumbnailUrlTemplateTest.php deleted file mode 100644 index 80e7ba9..0000000 --- a/tests/unit/Service/ThumbnailUrlTemplateTest.php +++ /dev/null @@ -1,74 +0,0 @@ -createMock(ConfigReader::class); - $configReader->expects(static::once()) - ->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}&updatedAt={mediaUpdatedAt}&uff'); - - $class = new ThumbnailUrlTemplate($configReader); - - $url = $class->getUrl($mediaUrl, $mediaPath, $width, $date); - - static::assertSame(\sprintf('%s/%s?width=%s&updatedAt=%s&uff', $mediaUrl, $mediaPath, $width, $date?->getTimestamp() ?: '0'), $url); - } - - /** - * @dataProvider getSalesChannelIds - */ - public function testGetUrlWithoutSetConfig(?string $salesChannelId, string $mediaUrl, string $mediaPath, string $width, ?\DateTimeInterface $date): void - { - $configReader = $this->createMock(ConfigReader::class); - $configReader->expects(static::once()) - ->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}&updatedAt={mediaUpdatedAt}'); - - $class = new ThumbnailUrlTemplate($configReader); - - $url = $class->getUrl($mediaUrl, $mediaPath, $width, $date); - - static::assertSame(\sprintf('%s/%s?width=%s&updatedAt=%s', $mediaUrl, $mediaPath, $width, $date?->getTimestamp() ?: '0'), $url); - } - - /** - * @dataProvider getSalesChannelIds - */ - public function testGetUrlGetPatternOnce(?string $salesChannelId, string $mediaUrl, string $mediaPath, string $width, ?\DateTimeInterface $date): void - { - $configReader = $this->createMock(ConfigReader::class); - $configReader->expects(static::once()) - ->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}&updatedAt={mediaUpdatedAt}'); - - $class = new ThumbnailUrlTemplate($configReader); - - $class->getUrl($mediaUrl, $mediaPath, $width, $date); - - $url = $class->getUrl($mediaUrl, $mediaPath, $width, $date); - - static::assertSame(\sprintf('%s/%s?width=%s&updatedAt=%s', $mediaUrl, $mediaPath, $width, $date?->getTimestamp() ?: '0'), $url); - } - - /** - * @return iterable - */ - public static function getSalesChannelIds(): iterable - { - yield [null, 'https://www.anywebpage.test', 'media/78/a1/myimage.jpg', '200', null]; - yield [null, 'https://www.anyotherwebpage.test', 'media/78/a1/myimage.jpg', '200', new \DateTimeImmutable()]; - yield [Uuid::randomHex(), 'https://www.anyother2webpage.test', 'media/aa/a1/myimage.jpg', '300', new \DateTimeImmutable()]; - yield [Uuid::randomHex(), 'https://www.anyother3webpage.test', 'media/aa/bb/myimage.jpg', '700', null]; - yield [Uuid::randomHex(), 'https://www.anyother4webpage.test', 'media/aa/cc/myimage.jpg', '900', new \DateTimeImmutable()]; - yield [Uuid::randomHex(), 'https://www.anyother5webpage.test', 'media/aa/dd/myimage.jpg', '1000', null]; - } -} diff --git a/tests/unit/Storefront/Framework/Twig/Extension/UrlEncodingTwigFilterTest.php b/tests/unit/Storefront/Framework/Twig/Extension/UrlEncodingTwigFilterTest.php deleted file mode 100644 index adb9d74..0000000 --- a/tests/unit/Storefront/Framework/Twig/Extension/UrlEncodingTwigFilterTest.php +++ /dev/null @@ -1,23 +0,0 @@ -encodeUrl('https://example.com/w:1/image.jpg'); - static::assertSame('https://example.com/w:1/image.jpg', $result); - } - - public function testEncodeUrlNull(): void - { - $urlEncodingTwigFilter = new UrlEncodingTwigFilter(); - $result = $urlEncodingTwigFilter->encodeUrl(null); - static::assertNull($result); - } -} \ No newline at end of file