From bf463ca63a3c15f53c0e3793976eb5e074b97aea Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Tue, 16 Apr 2024 16:27:37 +0200 Subject: [PATCH] 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()); + } + } +}