From c9cba0ccbabf968f30ad3f78b1358c2285cbd084 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Wed, 12 Jun 2024 14:01:41 +0200 Subject: [PATCH 1/6] BUGFIX: Clear calculatedFiles before processing new Images --- Classes/DataProcessing/ResponsiveImagesProcessor.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Classes/DataProcessing/ResponsiveImagesProcessor.php b/Classes/DataProcessing/ResponsiveImagesProcessor.php index bd1608c..909542f 100644 --- a/Classes/DataProcessing/ResponsiveImagesProcessor.php +++ b/Classes/DataProcessing/ResponsiveImagesProcessor.php @@ -54,6 +54,8 @@ public function process( array $processorConfiguration, array $processedData ): array { + $this->calculatedFiles = []; + if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) { return $processedData; } From 3f45d93e2ce26da7f0a0262b039fbb7e8973a68b Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Wed, 12 Jun 2024 14:12:13 +0200 Subject: [PATCH 2/6] BUGFIX: Get data for ContentBlockData from processedData --- .../ResponsiveImagesProcessor.php | 72 +++++++++++++++---- 1 file changed, 59 insertions(+), 13 deletions(-) diff --git a/Classes/DataProcessing/ResponsiveImagesProcessor.php b/Classes/DataProcessing/ResponsiveImagesProcessor.php index 909542f..bf46986 100644 --- a/Classes/DataProcessing/ResponsiveImagesProcessor.php +++ b/Classes/DataProcessing/ResponsiveImagesProcessor.php @@ -26,7 +26,9 @@ use Codappix\ResponsiveImages\Domain\Factory\BreakpointFactory; use Codappix\ResponsiveImages\Domain\Factory\RootlineFactory; use RuntimeException; +use TYPO3\CMS\ContentBlocks\DataProcessing\ContentBlockData; use TYPO3\CMS\Core\Resource\FileInterface; +use TYPO3\CMS\Core\Resource\FileRepository; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; @@ -42,11 +44,13 @@ final class ResponsiveImagesProcessor implements DataProcessorInterface private array $contentElementSizes = []; + private array $processedData = []; + public function __construct( + private readonly FileRepository $fileRepository, private readonly BreakpointFactory $breakpointFactory, private readonly RootlineFactory $rootlineFactory - ) { - } + ) {} public function process( ContentObjectRenderer $cObj, @@ -60,6 +64,8 @@ public function process( return $processedData; } + $this->processedData = $processedData; + $filesDataKey = (string) $cObj->stdWrapValue( 'filesDataKey', $processorConfiguration, @@ -70,10 +76,17 @@ public function process( $processorConfiguration, 'image' ); - if (isset($processedData[$filesDataKey]) && is_array($processedData[$filesDataKey])) { - $this->files = $processedData[$filesDataKey]; - } else { - // Files key is empty or not configured. + $targetFieldName = (string) $cObj->stdWrapValue( + 'as', + $processorConfiguration, + 'responsiveImages' + ); + + $this->files = $this->getFiles($filesDataKey, $fieldName); + + if (empty($this->files)) { + $processedData[$targetFieldName] = []; + return $processedData; } @@ -82,16 +95,10 @@ public function process( throw new RuntimeException('Could not fetch TypoScriptFrontendController from request.', 1712819889); } - $rootline = $this->rootlineFactory->create($processedData['data'], $fieldName, $tsfe); + $rootline = $this->rootlineFactory->create($this->getData(), $fieldName, $tsfe); $this->contentElementSizes = $rootline->getFinalSize(); $this->calculateFileDimensions(); - $targetFieldName = (string) $cObj->stdWrapValue( - 'as', - $processorConfiguration, - 'responsiveImages' - ); - $processedData[$targetFieldName] = $this->calculatedFiles; return $processedData; @@ -128,4 +135,43 @@ private function calculateFileDimensionForBreakpoints(): array return $fileDimensions; } + + public function getData(): array + { + if ( + $this->processedData['data'] instanceof ContentBlockData + ) { + assert(is_array($this->processedData['data']->_raw)); + $data = $this->processedData['data']->_raw; + } else { + assert(is_array($this->processedData['data'])); + $data = $this->processedData['data']; + } + + return $data; + } + + private function getFiles(string $filesDataKey, string $fieldName): array + { + if ( + isset($this->processedData[$filesDataKey]) + && is_array($this->processedData[$filesDataKey]) + ) { + return $this->processedData[$filesDataKey]; + } + + if ($fieldName === '') { + return []; + } + + if ($this->processedData['data'] instanceof ContentBlockData) { + return $this->processedData['data']->{$fieldName}; + } + + return $this->fileRepository->findByRelation( + 'tt_content', + $fieldName, + $this->processedData['data']['uid'] + ); + } } From 64ea8639e6c8cbf1f1c3bbd1348eb2a50d5af78a Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Tue, 16 Apr 2024 16:27:37 +0200 Subject: [PATCH 3/6] TASK: Add tests for content_blocks in backend layout Relates: #20 --- .../TSconfig/Page/Backend_Layouts.tsconfig | 22 ++++ .../ContentElements/codappix_image.typoscript | 26 +++++ .../codappix_imagefixedwidth.typoscript | 26 +++++ .../responsive_images/Setup.typoscript | 49 +++++++++ .../TypoScript/Rendering.typoscript | 9 ++ .../Configuration/TypoScript/Setup.typoscript | 2 + .../image-fixed-width/Assets/Icon.svg | 1 + .../image-fixed-width/EditorInterface.yaml | 12 ++ .../image-fixed-width/Source/Frontend.html | 7 ++ .../Source/Language/Labels.xlf | 17 +++ .../ContentElements/image/Assets/Icon.svg | 1 + .../image/EditorInterface.yaml | 12 ++ .../image/Source/Frontend.html | 7 ++ .../image/Source/Language/Labels.xlf | 17 +++ .../Test/Fixtures/0colDatabase.php | 32 ++++++ .../Fixtures/0colImageFixWidthDatabase.php | 32 ++++++ .../content_blocks_example/composer.json | 15 +++ Tests/Functional/ContentBlocksTest.php | 103 ++++++++++++++++++ 18 files changed, 390 insertions(+) create mode 100644 Tests/Fixtures/content_blocks_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig create mode 100644 Tests/Fixtures/content_blocks_example/Configuration/TypoScript/ContentElements/codappix_image.typoscript create mode 100644 Tests/Fixtures/content_blocks_example/Configuration/TypoScript/ContentElements/codappix_imagefixedwidth.typoscript create mode 100644 Tests/Fixtures/content_blocks_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript create mode 100644 Tests/Fixtures/content_blocks_example/Configuration/TypoScript/Rendering.typoscript create mode 100644 Tests/Fixtures/content_blocks_example/Configuration/TypoScript/Setup.typoscript create mode 100644 Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Assets/Icon.svg create mode 100644 Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/EditorInterface.yaml create mode 100644 Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Source/Frontend.html create mode 100644 Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Source/Language/Labels.xlf create mode 100644 Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Assets/Icon.svg create mode 100644 Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/EditorInterface.yaml create mode 100644 Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Source/Frontend.html create mode 100644 Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Source/Language/Labels.xlf create mode 100644 Tests/Fixtures/content_blocks_example/Test/Fixtures/0colDatabase.php create mode 100644 Tests/Fixtures/content_blocks_example/Test/Fixtures/0colImageFixWidthDatabase.php create mode 100644 Tests/Fixtures/content_blocks_example/composer.json create mode 100644 Tests/Functional/ContentBlocksTest.php diff --git a/Tests/Fixtures/content_blocks_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig b/Tests/Fixtures/content_blocks_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig new file mode 100644 index 0000000..2a2ce24 --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig @@ -0,0 +1,22 @@ +mod.web_layout.BackendLayouts { + MainTemplate { + title = MainTemplate + name = MainTemplate + config { + backend_layout { + colCount = 1 + rowCount = 1 + rows { + 1 { + columns { + 1 { + name = Main Content + colPos = 0 + } + } + } + } + } + } + } +} diff --git a/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/ContentElements/codappix_image.typoscript b/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/ContentElements/codappix_image.typoscript new file mode 100644 index 0000000..903dda2 --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/ContentElements/codappix_image.typoscript @@ -0,0 +1,26 @@ +tt_content.codappix_image { + dataProcessing { + 100 = Codappix\ResponsiveImages\DataProcessing\ResponsiveImagesProcessor + 100 { + fieldName = image + } + } +} + +plugin.tx_responsiveimages { + settings { + contentelements { + codappix_image { + image { + multiplier { + xs = 1 + sm = 1 + md = 1 + lg = 1 + xl = 0.5 + } + } + } + } + } +} diff --git a/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/ContentElements/codappix_imagefixedwidth.typoscript b/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/ContentElements/codappix_imagefixedwidth.typoscript new file mode 100644 index 0000000..6c827d8 --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/ContentElements/codappix_imagefixedwidth.typoscript @@ -0,0 +1,26 @@ +tt_content.codappix_imagefixedwidth { + dataProcessing { + 100 = Codappix\ResponsiveImages\DataProcessing\ResponsiveImagesProcessor + 100 { + fieldName = image + } + } +} + +plugin.tx_responsiveimages { + settings { + contentelements { + codappix_imagefixedwidth { + image { + sizes { + xs = 600 + sm = 900 + md = 1200 + lg = 1600 + xl = 1600 + } + } + } + } + } +} diff --git a/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript b/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript new file mode 100644 index 0000000..0db48c6 --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript @@ -0,0 +1,49 @@ +plugin.tx_responsiveimages { + settings { + breakpoints { + xs { + cropVariant = mobile + max = 480 + } + sm { + cropVariant = mobile + max = 767 + } + md { + cropVariant = tablet + max = 991 + } + lg { + cropVariant = default + max = 1479 + } + xl { + cropVariant = large + min = 1480 + } + } + + backendlayouts { + pagets__MainTemplate { + sizes { + xs = 734 + sm = 704 + md = 924 + lg = 1124 + xl = 1124 + } + columns { + 0 { + multiplier { + xs = 1 + sm = 1 + md = 1 + lg = 1 + xl = 1 + } + } + } + } + } + } +} diff --git a/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/Rendering.typoscript b/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/Rendering.typoscript new file mode 100644 index 0000000..0ac066c --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/Rendering.typoscript @@ -0,0 +1,9 @@ +page = PAGE +page { + 10 < styles.content.get + + config { + disableAllHeaderCode = 1 + admPanel = 0 + } +} diff --git a/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/Setup.typoscript b/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/Setup.typoscript new file mode 100644 index 0000000..1a2a0ce --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/Configuration/TypoScript/Setup.typoscript @@ -0,0 +1,2 @@ + + diff --git a/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Assets/Icon.svg b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Assets/Icon.svg new file mode 100644 index 0000000..54568d7 --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Assets/Icon.svg @@ -0,0 +1 @@ + diff --git a/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/EditorInterface.yaml b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/EditorInterface.yaml new file mode 100644 index 0000000..d315456 --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/EditorInterface.yaml @@ -0,0 +1,12 @@ +name: codappix/image-fixed-width +title: codappix/image-fixed-width +description: 'Description for Content Element codappix/image-fixed-width' +group: common +prefixFields: true +prefixType: full +fields: + - + identifier: image + useExistingField: true + type: File + allowed: common-image-types diff --git a/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Source/Frontend.html b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Source/Frontend.html new file mode 100644 index 0000000..e0f3a22 --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Source/Frontend.html @@ -0,0 +1,7 @@ + + + +{size.breakpoint.cropVariant} {size.size} {size.breakpoint.mediaQuery} + + + diff --git a/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Source/Language/Labels.xlf b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Source/Language/Labels.xlf new file mode 100644 index 0000000..e2ed87e --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Source/Language/Labels.xlf @@ -0,0 +1,17 @@ + + + +
+ + + codappix/image-fixed-width + + + Description for Content Element codappix/image-fixed-width + + + Custom image label + + + + diff --git a/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Assets/Icon.svg b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Assets/Icon.svg new file mode 100644 index 0000000..54568d7 --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Assets/Icon.svg @@ -0,0 +1 @@ + diff --git a/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/EditorInterface.yaml b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/EditorInterface.yaml new file mode 100644 index 0000000..14b4f30 --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/EditorInterface.yaml @@ -0,0 +1,12 @@ +name: codappix/image +title: codappix/image +description: 'Description for Content Element codappix/image' +group: common +prefixFields: true +prefixType: full +fields: + - + identifier: image + useExistingField: true + type: File + allowed: common-image-types diff --git a/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Source/Frontend.html b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Source/Frontend.html new file mode 100644 index 0000000..e0f3a22 --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Source/Frontend.html @@ -0,0 +1,7 @@ + + + +{size.breakpoint.cropVariant} {size.size} {size.breakpoint.mediaQuery} + + + diff --git a/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Source/Language/Labels.xlf b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Source/Language/Labels.xlf new file mode 100644 index 0000000..aa3e88a --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Source/Language/Labels.xlf @@ -0,0 +1,17 @@ + + + +
+ + + codappix/image + + + Description for Content Element codappix/image + + + Custom image label + + + + diff --git a/Tests/Fixtures/content_blocks_example/Test/Fixtures/0colDatabase.php b/Tests/Fixtures/content_blocks_example/Test/Fixtures/0colDatabase.php new file mode 100644 index 0000000..71d44e4 --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/Test/Fixtures/0colDatabase.php @@ -0,0 +1,32 @@ + [ + 1 => [ + 'uid' => '1', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'codappix_image', + 'header' => 'codappix_image', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '0', + 'sys_language_uid' => '0', + 'image' => '1', + ], + ], + 'sys_file_reference' => [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'uid_local' => '1', + 'uid_foreign' => '1', + 'tablenames' => 'tt_content', + 'fieldname' => 'image', + ], + ], +]; diff --git a/Tests/Fixtures/content_blocks_example/Test/Fixtures/0colImageFixWidthDatabase.php b/Tests/Fixtures/content_blocks_example/Test/Fixtures/0colImageFixWidthDatabase.php new file mode 100644 index 0000000..82bd96a --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/Test/Fixtures/0colImageFixWidthDatabase.php @@ -0,0 +1,32 @@ + [ + 1 => [ + 'uid' => '1', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'codappix_imagefixedwidth', + 'header' => 'codappix_imagefixedwidth', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '0', + 'sys_language_uid' => '0', + 'image' => '1', + ], + ], + 'sys_file_reference' => [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'uid_local' => '1', + 'uid_foreign' => '1', + 'tablenames' => 'tt_content', + 'fieldname' => 'image', + ], + ], +]; diff --git a/Tests/Fixtures/content_blocks_example/composer.json b/Tests/Fixtures/content_blocks_example/composer.json new file mode 100644 index 0000000..6221e75 --- /dev/null +++ b/Tests/Fixtures/content_blocks_example/composer.json @@ -0,0 +1,15 @@ +{ + "name": "codappix/content_blocks_example", + "description": "Add a content blocks example for frontend tests", + "type": "typo3-cms-extension", + "license": "GPL-2.0-or-later", + "require": { + "typo3/cms-core": "*", + "codappix/typo3-responsive-images": "*" + }, + "extra": { + "typo3/cms": { + "extension-key": "content_blocks_example" + } + } +} diff --git a/Tests/Functional/ContentBlocksTest.php b/Tests/Functional/ContentBlocksTest.php new file mode 100644 index 0000000..78a7456 --- /dev/null +++ b/Tests/Functional/ContentBlocksTest.php @@ -0,0 +1,103 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use Codappix\Typo3PhpDatasets\TestingFramework; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; +use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; + +class ContentBlocksTest extends FunctionalTestCase +{ + use TestingFramework; + + protected function setUp(): void + { + $this->coreExtensionsToLoad = [ + ]; + + $this->testExtensionsToLoad = [ + 'codappix/typo3-responsive-images', + 'contentblocks/content-blocks', + 'typo3conf/ext/responsive_images/Tests/Fixtures/content_blocks_example', + ]; + + $this->pathsToLinkInTestInstance = [ + 'typo3conf/ext/responsive_images/Tests/Fixtures/fileadmin/test_data' => 'fileadmin/test_data', + 'typo3conf/ext/responsive_images/Tests/Fixtures/config/sites' => 'typo3conf/sites', + ]; + + parent::setUp(); + + $this->importPHPDataSet(__DIR__ . '/../Fixtures/BaseDatabase.php'); + $this->setUpFrontendRootPage(1, [ + 'EXT:responsive_images/Configuration/TypoScript/Setup.typoscript', + 'EXT:content_blocks_example/Configuration/TypoScript/Setup.typoscript', + 'EXT:content_blocks_example/Configuration/TypoScript/Rendering.typoscript', + ]); + } + + public static function imageScalingValuesDataProvider(): iterable + { + yield '0 Column' => [ + '0colDatabase.php', + [ + '0' => 'mobile 734 (max-width: 480px)', + '1' => 'mobile 704 (max-width: 767px)', + '2' => 'tablet 924 (max-width: 991px)', + '3' => 'default 1124 (max-width: 1479px)', + '4' => 'large 562 (min-width: 1480px)', + ], + ]; + yield '0 Column with ImageFixWidth' => [ + '0colImageFixWidthDatabase.php', + [ + '0' => 'mobile 600 (max-width: 480px)', + '1' => 'mobile 900 (max-width: 767px)', + '2' => 'tablet 1200 (max-width: 991px)', + '3' => 'default 1600 (max-width: 1479px)', + '4' => 'large 1600 (min-width: 1480px)', + ], + ]; + } + + #[Test] + #[DataProvider(methodName: 'imageScalingValuesDataProvider')] + public function imageIsScaledCorrectly(string $phpDataSet, array $expectedValues): void + { + $this->importPHPDataSet(__DIR__ . '/../Fixtures/content_blocks_example/Test/Fixtures/' . $phpDataSet); + + $request = new InternalRequest(); + $request = $request->withPageId(2); + + $result = $this->executeFrontendSubRequest($request); + + self::assertSame(200, $result->getStatusCode()); + + foreach ($expectedValues as $expectedValue) { + self::assertStringContainsString($expectedValue, (string) $result->getBody()); + } + } +} From 4210bfb0c6eeb1b79b7c5a6d25995fdf84ca28fe Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Tue, 16 Apr 2024 17:11:54 +0200 Subject: [PATCH 4/6] TASK: Add tests for content block element in container Relates: #20 --- .../Fixtures/{ => Content}/0colDatabase.php | 0 .../0colImageFixWidthDatabase.php | 0 .../{ => Content}/1col2colDatabase.php | 0 .../1col2colFullWidthDatabase.php | 0 ...ol2colWidthContainerMultiplierDatabase.php | 0 .../1col2colWidthContainerSizeDatabase.php | 0 .../Fixtures/{ => Content}/1colDatabase.php | 0 .../{ => Content}/1colFullWidthDatabase.php | 0 .../{ => Content}/2col2colDatabase.php | 0 .../{ => Content}/2col_50_50_Database.php | 0 .../2col_66_33_ImageLeft_Database.php | 0 .../2col_66_33_ImageRight_Database.php | 0 .../Fixtures/{ => Content}/3colDatabase.php | 0 .../3colImageFixWidthDatabase.php | 0 .../Fixtures/ContentBlocks/0colDatabase.php | 11 +++++++++ .../0colImageFixWidthDatabase.php | 11 +++++++++ .../ContentBlocks/1col2colDatabase.php | 11 +++++++++ .../1col2colFullWidthDatabase.php | 11 +++++++++ ...ol2colWidthContainerMultiplierDatabase.php | 11 +++++++++ .../1col2colWidthContainerSizeDatabase.php | 11 +++++++++ .../Fixtures/ContentBlocks/1colDatabase.php | 11 +++++++++ .../ContentBlocks/1colFullWidthDatabase.php | 11 +++++++++ .../ContentBlocks/2col2colDatabase.php | 11 +++++++++ .../ContentBlocks/2col_50_50_Database.php | 11 +++++++++ .../2col_66_33_ImageLeft_Database.php | 11 +++++++++ .../2col_66_33_ImageRight_Database.php | 11 +++++++++ .../Fixtures/ContentBlocks/3colDatabase.php | 11 +++++++++ .../3colImageFixWidthDatabase.php | 11 +++++++++ Tests/Functional/ContainerTest.php | 24 ++++++++++++++++++- 29 files changed, 177 insertions(+), 1 deletion(-) rename Tests/Fixtures/container_example/Test/Fixtures/{ => Content}/0colDatabase.php (100%) rename Tests/Fixtures/container_example/Test/Fixtures/{ => Content}/0colImageFixWidthDatabase.php (100%) rename Tests/Fixtures/container_example/Test/Fixtures/{ => Content}/1col2colDatabase.php (100%) rename Tests/Fixtures/container_example/Test/Fixtures/{ => Content}/1col2colFullWidthDatabase.php (100%) rename Tests/Fixtures/container_example/Test/Fixtures/{ => Content}/1col2colWidthContainerMultiplierDatabase.php (100%) rename Tests/Fixtures/container_example/Test/Fixtures/{ => Content}/1col2colWidthContainerSizeDatabase.php (100%) rename Tests/Fixtures/container_example/Test/Fixtures/{ => Content}/1colDatabase.php (100%) rename Tests/Fixtures/container_example/Test/Fixtures/{ => Content}/1colFullWidthDatabase.php (100%) rename Tests/Fixtures/container_example/Test/Fixtures/{ => Content}/2col2colDatabase.php (100%) rename Tests/Fixtures/container_example/Test/Fixtures/{ => Content}/2col_50_50_Database.php (100%) rename Tests/Fixtures/container_example/Test/Fixtures/{ => Content}/2col_66_33_ImageLeft_Database.php (100%) rename Tests/Fixtures/container_example/Test/Fixtures/{ => Content}/2col_66_33_ImageRight_Database.php (100%) rename Tests/Fixtures/container_example/Test/Fixtures/{ => Content}/3colDatabase.php (100%) rename Tests/Fixtures/container_example/Test/Fixtures/{ => Content}/3colImageFixWidthDatabase.php (100%) create mode 100644 Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/0colDatabase.php create mode 100644 Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/0colImageFixWidthDatabase.php create mode 100644 Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/1col2colDatabase.php create mode 100644 Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/1col2colFullWidthDatabase.php create mode 100644 Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/1col2colWidthContainerMultiplierDatabase.php create mode 100644 Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/1col2colWidthContainerSizeDatabase.php create mode 100644 Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/1colDatabase.php create mode 100644 Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/1colFullWidthDatabase.php create mode 100644 Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/2col2colDatabase.php create mode 100644 Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/2col_50_50_Database.php create mode 100644 Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/2col_66_33_ImageLeft_Database.php create mode 100644 Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/2col_66_33_ImageRight_Database.php create mode 100644 Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/3colDatabase.php create mode 100644 Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/3colImageFixWidthDatabase.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/0colDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/Content/0colDatabase.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/0colDatabase.php rename to Tests/Fixtures/container_example/Test/Fixtures/Content/0colDatabase.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/0colImageFixWidthDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/Content/0colImageFixWidthDatabase.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/0colImageFixWidthDatabase.php rename to Tests/Fixtures/container_example/Test/Fixtures/Content/0colImageFixWidthDatabase.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/1col2colDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/Content/1col2colDatabase.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/1col2colDatabase.php rename to Tests/Fixtures/container_example/Test/Fixtures/Content/1col2colDatabase.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/1col2colFullWidthDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/Content/1col2colFullWidthDatabase.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/1col2colFullWidthDatabase.php rename to Tests/Fixtures/container_example/Test/Fixtures/Content/1col2colFullWidthDatabase.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/1col2colWidthContainerMultiplierDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/Content/1col2colWidthContainerMultiplierDatabase.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/1col2colWidthContainerMultiplierDatabase.php rename to Tests/Fixtures/container_example/Test/Fixtures/Content/1col2colWidthContainerMultiplierDatabase.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/1col2colWidthContainerSizeDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/Content/1col2colWidthContainerSizeDatabase.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/1col2colWidthContainerSizeDatabase.php rename to Tests/Fixtures/container_example/Test/Fixtures/Content/1col2colWidthContainerSizeDatabase.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/1colDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/Content/1colDatabase.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/1colDatabase.php rename to Tests/Fixtures/container_example/Test/Fixtures/Content/1colDatabase.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/1colFullWidthDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/Content/1colFullWidthDatabase.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/1colFullWidthDatabase.php rename to Tests/Fixtures/container_example/Test/Fixtures/Content/1colFullWidthDatabase.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/2col2colDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/Content/2col2colDatabase.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/2col2colDatabase.php rename to Tests/Fixtures/container_example/Test/Fixtures/Content/2col2colDatabase.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/2col_50_50_Database.php b/Tests/Fixtures/container_example/Test/Fixtures/Content/2col_50_50_Database.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/2col_50_50_Database.php rename to Tests/Fixtures/container_example/Test/Fixtures/Content/2col_50_50_Database.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/2col_66_33_ImageLeft_Database.php b/Tests/Fixtures/container_example/Test/Fixtures/Content/2col_66_33_ImageLeft_Database.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/2col_66_33_ImageLeft_Database.php rename to Tests/Fixtures/container_example/Test/Fixtures/Content/2col_66_33_ImageLeft_Database.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/2col_66_33_ImageRight_Database.php b/Tests/Fixtures/container_example/Test/Fixtures/Content/2col_66_33_ImageRight_Database.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/2col_66_33_ImageRight_Database.php rename to Tests/Fixtures/container_example/Test/Fixtures/Content/2col_66_33_ImageRight_Database.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/3colDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/Content/3colDatabase.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/3colDatabase.php rename to Tests/Fixtures/container_example/Test/Fixtures/Content/3colDatabase.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/3colImageFixWidthDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/Content/3colImageFixWidthDatabase.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/3colImageFixWidthDatabase.php rename to Tests/Fixtures/container_example/Test/Fixtures/Content/3colImageFixWidthDatabase.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/0colDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/0colDatabase.php new file mode 100644 index 0000000..8430b7f --- /dev/null +++ b/Tests/Fixtures/container_example/Test/Fixtures/ContentBlocks/0colDatabase.php @@ -0,0 +1,11 @@ +testExtensionsToLoad = [ 'b13/container', 'codappix/typo3-responsive-images', + 'contentblocks/content-blocks', 'typo3conf/ext/responsive_images/Tests/Fixtures/base_example', 'typo3conf/ext/responsive_images/Tests/Fixtures/container_example', + 'typo3conf/ext/responsive_images/Tests/Fixtures/content_blocks_example', ]; $this->pathsToLinkInTestInstance = [ @@ -60,6 +62,8 @@ protected function setUp(): void 'EXT:base_example/Configuration/TypoScript/Setup.typoscript', 'EXT:base_example/Configuration/TypoScript/Rendering.typoscript', 'EXT:container_example/Configuration/TypoScript/Setup.typoscript', + 'EXT:content_blocks_example/Configuration/TypoScript/ContentElements/codappix_image.typoscript', + 'EXT:content_blocks_example/Configuration/TypoScript/ContentElements/codappix_imagefixedwidth.typoscript', ]); } @@ -211,7 +215,25 @@ public static function imageScalingValuesDataProvider(): iterable #[DataProvider(methodName: 'imageScalingValuesDataProvider')] public function imageIsScaledCorrectly(string $phpDataSet, array $expectedValues): void { - $this->importPHPDataSet(__DIR__ . '/../Fixtures/container_example/Test/Fixtures/' . $phpDataSet); + $this->importPHPDataSet(__DIR__ . '/../Fixtures/container_example/Test/Fixtures/Content/' . $phpDataSet); + + $request = new InternalRequest(); + $request = $request->withPageId(2); + + $result = $this->executeFrontendSubRequest($request); + + self::assertSame(200, $result->getStatusCode()); + + foreach ($expectedValues as $expectedValue) { + self::assertStringContainsString($expectedValue, (string) $result->getBody()); + } + } + + #[Test] + #[DataProvider(methodName: 'imageScalingValuesDataProvider')] + public function contentBlocksImageIsScaledCorrectly(string $phpDataSet, array $expectedValues): void + { + $this->importPHPDataSet(__DIR__ . '/../Fixtures/container_example/Test/Fixtures/ContentBlocks/' . $phpDataSet); $request = new InternalRequest(); $request = $request->withPageId(2); From 22cc3c5c9db9af802e4a69d4359465c0968f631f Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Wed, 12 Jun 2024 15:08:54 +0200 Subject: [PATCH 5/6] TASK: Add content-blocks to dev dependencies Relates: #20 --- Classes/DataProcessing/ResponsiveImagesProcessor.php | 5 +++-- composer.json | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Classes/DataProcessing/ResponsiveImagesProcessor.php b/Classes/DataProcessing/ResponsiveImagesProcessor.php index bf46986..5f80fb3 100644 --- a/Classes/DataProcessing/ResponsiveImagesProcessor.php +++ b/Classes/DataProcessing/ResponsiveImagesProcessor.php @@ -50,7 +50,8 @@ public function __construct( private readonly FileRepository $fileRepository, private readonly BreakpointFactory $breakpointFactory, private readonly RootlineFactory $rootlineFactory - ) {} + ) { + } public function process( ContentObjectRenderer $cObj, @@ -136,7 +137,7 @@ private function calculateFileDimensionForBreakpoints(): array return $fileDimensions; } - public function getData(): array + private function getData(): array { if ( $this->processedData['data'] instanceof ContentBlockData diff --git a/composer.json b/composer.json index b61cf62..f869944 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,7 @@ "require-dev": { "b13/container": "^2.3", "codappix/typo3-php-datasets": "^1.5", + "contentblocks/content-blocks": "^0.7", "erickskrauch/php-cs-fixer-custom-fixers": "^1.2", "friendsofphp/php-cs-fixer": "^3.50", "kubawerlos/php-cs-fixer-custom-fixers": "^3.21", From 20617b84d6dc7ba0a1ec701b082620aa231cff33 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Fri, 30 Aug 2024 11:06:19 +0200 Subject: [PATCH 6/6] BUGFIX: Replace tabs with spaces in generated translation files Relates: #20 --- .../Source/Language/Labels.xlf | 28 +++++++++---------- .../image/Source/Language/Labels.xlf | 28 +++++++++---------- Tests/Functional/ContentBlocksTest.php | 3 -- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Source/Language/Labels.xlf b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Source/Language/Labels.xlf index e2ed87e..43009e5 100644 --- a/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Source/Language/Labels.xlf +++ b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image-fixed-width/Source/Language/Labels.xlf @@ -1,17 +1,17 @@ - -
- - - codappix/image-fixed-width - - - Description for Content Element codappix/image-fixed-width - - - Custom image label - - - + +
+ + + codappix/image-fixed-width + + + Description for Content Element codappix/image-fixed-width + + + Custom image label + + + diff --git a/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Source/Language/Labels.xlf b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Source/Language/Labels.xlf index aa3e88a..209f583 100644 --- a/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Source/Language/Labels.xlf +++ b/Tests/Fixtures/content_blocks_example/ContentBlocks/ContentElements/image/Source/Language/Labels.xlf @@ -1,17 +1,17 @@ - -
- - - codappix/image - - - Description for Content Element codappix/image - - - Custom image label - - - + +
+ + + codappix/image + + + Description for Content Element codappix/image + + + Custom image label + + + diff --git a/Tests/Functional/ContentBlocksTest.php b/Tests/Functional/ContentBlocksTest.php index 78a7456..7e245e3 100644 --- a/Tests/Functional/ContentBlocksTest.php +++ b/Tests/Functional/ContentBlocksTest.php @@ -35,9 +35,6 @@ class ContentBlocksTest extends FunctionalTestCase protected function setUp(): void { - $this->coreExtensionsToLoad = [ - ]; - $this->testExtensionsToLoad = [ 'codappix/typo3-responsive-images', 'contentblocks/content-blocks',