From d804b0e533b067ddaa85802d5dbd32ef4448fede Mon Sep 17 00:00:00 2001 From: Justus Moroni Date: Thu, 4 Apr 2024 11:59:32 +0200 Subject: [PATCH 1/6] wip:feat: Content block support --- .../ResponsiveImagesProcessor.php | 100 +++++++++--------- Classes/Service/ResponsiveImageService.php | 70 ++++++++++++ Configuration/Services.yaml | 4 + composer.json | 3 +- 4 files changed, 128 insertions(+), 49 deletions(-) create mode 100644 Classes/Service/ResponsiveImageService.php diff --git a/Classes/DataProcessing/ResponsiveImagesProcessor.php b/Classes/DataProcessing/ResponsiveImagesProcessor.php index bd1608c..fd5dbcf 100644 --- a/Classes/DataProcessing/ResponsiveImagesProcessor.php +++ b/Classes/DataProcessing/ResponsiveImagesProcessor.php @@ -23,28 +23,23 @@ * 02110-1301, USA. */ -use Codappix\ResponsiveImages\Domain\Factory\BreakpointFactory; -use Codappix\ResponsiveImages\Domain\Factory\RootlineFactory; +use Codappix\ResponsiveImages\Service\ResponsiveImageService; use RuntimeException; -use TYPO3\CMS\Core\Resource\FileInterface; +use TYPO3\CMS\ContentBlocks\DataProcessing\ContentBlockData; +use TYPO3\CMS\Core\Resource\FileRepository; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; final class ResponsiveImagesProcessor implements DataProcessorInterface { - /** - * @var FileInterface[] - */ - private array $files = []; + private array $processedData; - private array $calculatedFiles = []; - - private array $contentElementSizes = []; + private ContentBlockData|array $data; public function __construct( - private readonly BreakpointFactory $breakpointFactory, - private readonly RootlineFactory $rootlineFactory + private readonly ResponsiveImageService $responsiveImageService, + private readonly FileRepository $fileRepository ) { } @@ -58,6 +53,9 @@ public function process( return $processedData; } + $this->processedData = $processedData; + $this->data = $processedData['data']; + $filesDataKey = (string) $cObj->stdWrapValue( 'filesDataKey', $processorConfiguration, @@ -68,10 +66,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' + ); + + $files = $this->getFiles($filesDataKey, $fieldName); + + if (empty($files)) { + $processedData[$targetFieldName] = []; + return $processedData; } @@ -80,50 +85,49 @@ public function process( throw new RuntimeException('Could not fetch TypoScriptFrontendController from request.', 1712819889); } - $rootline = $this->rootlineFactory->create($processedData['data'], $fieldName, $tsfe); - $this->contentElementSizes = $rootline->getFinalSize(); - $this->calculateFileDimensions(); - - $targetFieldName = (string) $cObj->stdWrapValue( - 'as', - $processorConfiguration, - 'responsiveImages' - ); + if ( + $this->data instanceof ContentBlockData + ) { + assert(is_array($this->data->_raw)); + $data = $this->data->_raw; + } else { + $data = $this->data; + } - $processedData[$targetFieldName] = $this->calculatedFiles; + $processedData[$targetFieldName] = $this->responsiveImageService->getCalculatedFiles($files, $data, $fieldName, $tsfe); return $processedData; } - private function calculateFileDimensions(): void + private function getFiles(string $filesDataKey, string $fieldName): array { - foreach ($this->files as $file) { - $calculatedFile = [ - 'media' => $file, - 'sizes' => $this->calculateFileDimensionForBreakpoints(), - ]; - - $this->calculatedFiles[] = $calculatedFile; + if ( + isset($this->processedData[$filesDataKey]) + && is_array($this->processedData[$filesDataKey]) + ) { + return $this->processedData[$filesDataKey]; } - } - private function calculateFileDimensionForBreakpoints(): array - { - $fileDimensions = []; + if ($fieldName === '') { + return []; + } - $breakpoints = $this->breakpointFactory->getByConfigurationPath(['breakpoints']); + $uid = $this->getFromData('uid'); + assert(is_int($uid)); - foreach ($breakpoints as $breakpoint) { - if (isset($this->contentElementSizes[$breakpoint->getIdentifier()]) === false) { - continue; - } + return $this->fileRepository->findByRelation( + 'tt_content', + $fieldName, + $uid + ); + } - $fileDimensions[$breakpoint->getIdentifier()] = [ - 'breakpoint' => $breakpoint, - 'size' => $this->contentElementSizes[$breakpoint->getIdentifier()], - ]; + private function getFromData(string $key): mixed + { + if ($this->data instanceof ContentBlockData) { + return $this->data->{$key}; } - return $fileDimensions; + return $this->data[$key]; } } diff --git a/Classes/Service/ResponsiveImageService.php b/Classes/Service/ResponsiveImageService.php new file mode 100644 index 0000000..50782fd --- /dev/null +++ b/Classes/Service/ResponsiveImageService.php @@ -0,0 +1,70 @@ +files = $files; + + $rootline = $this->rootlineFactory->create($data, $fieldName, $tsfe); + $this->contentElementSizes = $rootline->getFinalSize(); + + return $this->calculateFileDimensions(); + } + + private function calculateFileDimensions(): array + { + $calculatedFiles = []; + + foreach ($this->files as $file) { + $calculatedFiles[] = [ + 'media' => $file, + 'sizes' => $this->calculateFileDimensionForBreakpoints(), + ]; + } + + return $calculatedFiles; + } + + private function calculateFileDimensionForBreakpoints(): array + { + $fileDimensions = []; + + $breakpoints = $this->breakpointFactory->getByConfigurationPath(['breakpoints']); + + foreach ($breakpoints as $breakpoint) { + if (isset($this->contentElementSizes[$breakpoint->getIdentifier()]) === false) { + continue; + } + + $fileDimensions[$breakpoint->getIdentifier()] = [ + 'breakpoint' => $breakpoint, + 'size' => $this->contentElementSizes[$breakpoint->getIdentifier()], + ]; + } + + return $fileDimensions; + } +} diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 67ea82d..3afcd6c 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -28,6 +28,10 @@ services: Codappix\ResponsiveImages\DataProcessing\ResponsiveImagesProcessor: public: true + tags: + - + name: 'data.processor' + identifier: 'responsive-images' Codappix\ResponsiveImages\Configuration\ConfigurationManager: arguments: diff --git a/composer.json b/composer.json index 7c382ad..38692f2 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,8 @@ "staabm/phpstan-todo-by": "^0.1.20", "typo3/cms-fluid-styled-content": "^12.4", "typo3/testing-framework": "^8.0", - "tomasvotruba/cognitive-complexity": "^0.2.2" + "tomasvotruba/cognitive-complexity": "^0.2.2", + "contentblocks/content-blocks": "^0.7" }, "config": { "allow-plugins": { From 92b8079f117bebd0a262fbf3b713a26d3c694a79 Mon Sep 17 00:00:00 2001 From: Justus Moroni Date: Fri, 5 Apr 2024 10:23:09 +0200 Subject: [PATCH 2/6] wip: Fix recursive image stuff. --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 38692f2..241a867 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", @@ -46,8 +47,7 @@ "staabm/phpstan-todo-by": "^0.1.20", "typo3/cms-fluid-styled-content": "^12.4", "typo3/testing-framework": "^8.0", - "tomasvotruba/cognitive-complexity": "^0.2.2", - "contentblocks/content-blocks": "^0.7" + "tomasvotruba/cognitive-complexity": "^0.2.2" }, "config": { "allow-plugins": { From 6d5c5ae30418c1288ffe21153d13e004b5cb278b Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Tue, 16 Apr 2024 16:26:39 +0200 Subject: [PATCH 3/6] CLEANUP: Remove class variable data --- .../ResponsiveImagesProcessor.php | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/Classes/DataProcessing/ResponsiveImagesProcessor.php b/Classes/DataProcessing/ResponsiveImagesProcessor.php index fd5dbcf..fb66e76 100644 --- a/Classes/DataProcessing/ResponsiveImagesProcessor.php +++ b/Classes/DataProcessing/ResponsiveImagesProcessor.php @@ -35,8 +35,6 @@ final class ResponsiveImagesProcessor implements DataProcessorInterface { private array $processedData; - private ContentBlockData|array $data; - public function __construct( private readonly ResponsiveImageService $responsiveImageService, private readonly FileRepository $fileRepository @@ -54,7 +52,6 @@ public function process( } $this->processedData = $processedData; - $this->data = $processedData['data']; $filesDataKey = (string) $cObj->stdWrapValue( 'filesDataKey', @@ -86,12 +83,12 @@ public function process( } if ( - $this->data instanceof ContentBlockData + $this->processedData['data'] instanceof ContentBlockData ) { - assert(is_array($this->data->_raw)); - $data = $this->data->_raw; + assert(is_array($this->processedData['data']->_raw)); + $data = $this->processedData['data']->_raw; } else { - $data = $this->data; + $data = $this->processedData['data']; } $processedData[$targetFieldName] = $this->responsiveImageService->getCalculatedFiles($files, $data, $fieldName, $tsfe); @@ -112,22 +109,14 @@ private function getFiles(string $filesDataKey, string $fieldName): array return []; } - $uid = $this->getFromData('uid'); - assert(is_int($uid)); + if ($this->processedData['data'] instanceof ContentBlockData) { + return $this->processedData['data']->{$fieldName}; + } return $this->fileRepository->findByRelation( 'tt_content', $fieldName, - $uid + $this->processedData['data']['uid'] ); } - - private function getFromData(string $key): mixed - { - if ($this->data instanceof ContentBlockData) { - return $this->data->{$key}; - } - - return $this->data[$key]; - } } From 7ee05132e46e05c7bbf0eb54f173fa188f26df8d Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Tue, 16 Apr 2024 16:27:37 +0200 Subject: [PATCH 4/6] TASK: Add tests for content_blocks in backend layout --- .../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 3a67ff184ad1912b1686314d9564326d71c30612 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Tue, 16 Apr 2024 17:11:54 +0200 Subject: [PATCH 5/6] TASK: Add tests for content block element in container --- .../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 79270f478e4864784da76c601bd229ed7ee1f2ad Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Wed, 12 Jun 2024 14:31:07 +0200 Subject: [PATCH 6/6] BUGFIX: replace deprecated config option in phpstan.neon --- phpstan.neon | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 66088b7..d56432a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -11,8 +11,6 @@ parameters: - Classes - Configuration - checkMissingIterableValueType: false - checkGenericClassInNonGenericObjectType: false treatPhpDocTypesAsCertain: false cognitive_complexity: @@ -40,3 +38,6 @@ parameters: - '$_FILES' - '$_SERVER' message: 'Use API instead' + + ignoreErrors: + - identifier: 'missingType.iterableValue'