From f7a2c176e40e72fe0129dd2086c48cee4d6880c0 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Tue, 19 Mar 2024 11:32:52 +0100 Subject: [PATCH 1/2] TASK: Check if container extension is installed Related: #7 --- Classes/Sizes/Rootline.php | 15 +-- .../TSconfig/Page/Backend_Layouts.tsconfig | 22 +++++ .../ContentElements/image.typoscript | 35 +++++++ .../responsive_images/Setup.typoscript | 49 ++++++++++ .../TypoScript/Rendering.typoscript | 2 + .../Configuration/TypoScript/Setup.typoscript | 2 + .../FluidStyledContent/Media/Image.html | 9 ++ .../Templates/FluidStyledContent/Image.html | 7 ++ .../Test/Fixtures/0colDatabase.php | 32 +++++++ Tests/Fixtures/base_example/composer.json | 15 +++ Tests/Functional/BaseTest.php | 94 +++++++++++++++++++ 11 files changed, 276 insertions(+), 6 deletions(-) create mode 100644 Tests/Fixtures/base_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig create mode 100644 Tests/Fixtures/base_example/Configuration/TypoScript/ContentElements/image.typoscript create mode 100644 Tests/Fixtures/base_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript create mode 100644 Tests/Fixtures/base_example/Configuration/TypoScript/Rendering.typoscript create mode 100644 Tests/Fixtures/base_example/Configuration/TypoScript/Setup.typoscript create mode 100644 Tests/Fixtures/base_example/Resources/Private/Partials/FluidStyledContent/Media/Image.html create mode 100644 Tests/Fixtures/base_example/Resources/Private/Templates/FluidStyledContent/Image.html create mode 100644 Tests/Fixtures/base_example/Test/Fixtures/0colDatabase.php create mode 100644 Tests/Fixtures/base_example/composer.json create mode 100644 Tests/Functional/BaseTest.php diff --git a/Classes/Sizes/Rootline.php b/Classes/Sizes/Rootline.php index 6b3a24e..5fe8967 100644 --- a/Classes/Sizes/Rootline.php +++ b/Classes/Sizes/Rootline.php @@ -27,6 +27,7 @@ use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Error\Exception; +use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Page\PageLayoutResolver; @@ -106,14 +107,16 @@ private function parseRootline(ContentElementInterface $contentElement): void return; } - $parentContainer = $contentElement->getData('tx_container_parent'); - assert(is_int($parentContainer)); - $parent = $this->fetchContentElementFromDatabase($parentContainer); + if (ExtensionManagementUtility::isLoaded('b13/container')) { + $parentContainer = $contentElement->getData('tx_container_parent'); + assert(is_int($parentContainer)); + $parent = $this->fetchContentElementFromDatabase($parentContainer); - $this->rootline[] = $parent; - $this->parseRootline($parent); + $this->rootline[] = $parent; + $this->parseRootline($parent); - $contentElement->setParent($parent); + $contentElement->setParent($parent); + } } /** diff --git a/Tests/Fixtures/base_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig b/Tests/Fixtures/base_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig new file mode 100644 index 0000000..2a2ce24 --- /dev/null +++ b/Tests/Fixtures/base_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/base_example/Configuration/TypoScript/ContentElements/image.typoscript b/Tests/Fixtures/base_example/Configuration/TypoScript/ContentElements/image.typoscript new file mode 100644 index 0000000..3c2b33a --- /dev/null +++ b/Tests/Fixtures/base_example/Configuration/TypoScript/ContentElements/image.typoscript @@ -0,0 +1,35 @@ +tt_content.image { + templateRootPaths { + 110 = EXT:base_example/Resources/Private/Templates/FluidStyledContent + } + partialRootPaths { + 110 = EXT:base_example/Resources/Private/Partials/FluidStyledContent + } + + dataProcessing { + 20 > + 20 = Codappix\ResponsiveImages\DataProcessing\ResponsiveImagesProcessor + 20 { + fieldName = image + filesDataKey = files + } + } +} + +plugin.tx_responsiveimages { + settings { + contentelements { + image { + image { + multiplier { + xs = 1 + sm = 1 + md = 1 + lg = 1 + xl = 1 + } + } + } + } + } +} diff --git a/Tests/Fixtures/base_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript b/Tests/Fixtures/base_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript new file mode 100644 index 0000000..0db48c6 --- /dev/null +++ b/Tests/Fixtures/base_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/base_example/Configuration/TypoScript/Rendering.typoscript b/Tests/Fixtures/base_example/Configuration/TypoScript/Rendering.typoscript new file mode 100644 index 0000000..57404ed --- /dev/null +++ b/Tests/Fixtures/base_example/Configuration/TypoScript/Rendering.typoscript @@ -0,0 +1,2 @@ +page = PAGE +page.10 < styles.content.get \ No newline at end of file diff --git a/Tests/Fixtures/base_example/Configuration/TypoScript/Setup.typoscript b/Tests/Fixtures/base_example/Configuration/TypoScript/Setup.typoscript new file mode 100644 index 0000000..66bace5 --- /dev/null +++ b/Tests/Fixtures/base_example/Configuration/TypoScript/Setup.typoscript @@ -0,0 +1,2 @@ + + diff --git a/Tests/Fixtures/base_example/Resources/Private/Partials/FluidStyledContent/Media/Image.html b/Tests/Fixtures/base_example/Resources/Private/Partials/FluidStyledContent/Media/Image.html new file mode 100644 index 0000000..5958224 --- /dev/null +++ b/Tests/Fixtures/base_example/Resources/Private/Partials/FluidStyledContent/Media/Image.html @@ -0,0 +1,9 @@ + + + + + {size.breakpoint.cropVariant} {size.size} {size.breakpoint.mediaQuery} + + + + diff --git a/Tests/Fixtures/base_example/Resources/Private/Templates/FluidStyledContent/Image.html b/Tests/Fixtures/base_example/Resources/Private/Templates/FluidStyledContent/Image.html new file mode 100644 index 0000000..23439a4 --- /dev/null +++ b/Tests/Fixtures/base_example/Resources/Private/Templates/FluidStyledContent/Image.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Tests/Fixtures/base_example/Test/Fixtures/0colDatabase.php b/Tests/Fixtures/base_example/Test/Fixtures/0colDatabase.php new file mode 100644 index 0000000..71b14c8 --- /dev/null +++ b/Tests/Fixtures/base_example/Test/Fixtures/0colDatabase.php @@ -0,0 +1,32 @@ + [ + 1 => [ + 'uid' => '1', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'image', + 'header' => '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/base_example/composer.json b/Tests/Fixtures/base_example/composer.json new file mode 100644 index 0000000..d0d9c89 --- /dev/null +++ b/Tests/Fixtures/base_example/composer.json @@ -0,0 +1,15 @@ +{ + "name": "codappix/base_example", + "description": "Add a base example for frontend tests", + "type": "typo3-cms-extension", + "license": "GPL-2.0-or-later", + "require": { + "typo3/cms-core": "*", + "codappix/responsive-images": "*" + }, + "extra": { + "typo3/cms": { + "extension-key": "base_example" + } + } +} diff --git a/Tests/Functional/BaseTest.php b/Tests/Functional/BaseTest.php new file mode 100644 index 0000000..d2e9cc9 --- /dev/null +++ b/Tests/Functional/BaseTest.php @@ -0,0 +1,94 @@ + + * + * 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 BaseTest extends FunctionalTestCase +{ + use TestingFramework; + + protected function setUp(): void + { + $this->coreExtensionsToLoad = [ + 'fluid_styled_content', + ]; + + $this->testExtensionsToLoad = [ + 'codappix/responsive-images', + 'typo3conf/ext/responsive_images/Tests/Fixtures/base_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:fluid_styled_content/Configuration/TypoScript/setup.typoscript', + 'EXT:responsive_images/Configuration/TypoScript/Setup.typoscript', + 'EXT:base_example/Configuration/TypoScript/Setup.typoscript', + 'EXT:base_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 1124 (min-width: 1480px)', + ], + ]; + } + + #[Test] + #[DataProvider(methodName: 'imageScalingValuesDataProvider')] + public function imageIsScaledCorrectly(string $phpDataSet, array $expectedValues): void + { + $this->importPHPDataSet(__DIR__ . '/../Fixtures/base_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 07a53328412335eb44499a6ce5482d3b0b37101a Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Tue, 19 Mar 2024 12:07:48 +0100 Subject: [PATCH 2/2] CLEANUP: Remove duplication in base_example and container_example --- .../TSconfig/Page/Backend_Layouts.tsconfig | 22 --------- .../TypoScript/Container/1col.typoscript | 5 ++ .../Container/2col-33-66.typoscript | 5 ++ .../Container/2col-50-50.typoscript | 5 ++ .../Container/2col-66-33.typoscript | 5 ++ .../TypoScript/Container/3col.typoscript | 5 ++ .../ContentElements/image.typoscript | 35 ------------- .../responsive_images/Setup.typoscript | 49 ------------------- .../TypoScript/Rendering.typoscript | 2 - .../Configuration/TypoScript/Setup.typoscript | 29 +---------- .../FluidStyledContent/Media/Image.html | 9 ---- .../Templates/FluidStyledContent/Image.html | 7 --- Tests/Functional/ContainerTest.php | 4 +- 13 files changed, 29 insertions(+), 153 deletions(-) delete mode 100644 Tests/Fixtures/container_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig delete mode 100644 Tests/Fixtures/container_example/Configuration/TypoScript/ContentElements/image.typoscript delete mode 100644 Tests/Fixtures/container_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript delete mode 100644 Tests/Fixtures/container_example/Configuration/TypoScript/Rendering.typoscript delete mode 100644 Tests/Fixtures/container_example/Resources/Private/Partials/FluidStyledContent/Media/Image.html delete mode 100644 Tests/Fixtures/container_example/Resources/Private/Templates/FluidStyledContent/Image.html diff --git a/Tests/Fixtures/container_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig b/Tests/Fixtures/container_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig deleted file mode 100644 index 2a2ce24..0000000 --- a/Tests/Fixtures/container_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig +++ /dev/null @@ -1,22 +0,0 @@ -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/container_example/Configuration/TypoScript/Container/1col.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/1col.typoscript index 14af340..e77c473 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/1col.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/1col.typoscript @@ -15,3 +15,8 @@ plugin.tx_responsiveimages { } } } + +tt_content.example_container-1col < lib.containerElement +tt_content.example_container-1col { + templateName = 1col +} diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-33-66.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-33-66.typoscript index c85850e..233ecad 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-33-66.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-33-66.typoscript @@ -25,3 +25,8 @@ plugin.tx_responsiveimages { } } } + +tt_content.example_container-2col-33-66 < lib.containerElement +tt_content.example_container-2col-33-66 { + templateName = 2col-33-66 +} diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50.typoscript index 94fe8a6..451eb67 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50.typoscript @@ -25,3 +25,8 @@ plugin.tx_responsiveimages { } } } + +tt_content.example_container-2col-50-50 < lib.containerElement +tt_content.example_container-2col-50-50 { + templateName = 2col-50-50 +} diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-66-33.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-66-33.typoscript index be60576..68375a5 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-66-33.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-66-33.typoscript @@ -25,3 +25,8 @@ plugin.tx_responsiveimages { } } } + +tt_content.example_container-2col-66-33 < lib.containerElement +tt_content.example_container-2col-66-33 { + templateName = 2col-66-33 +} diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript index d2a0956..9cf6190 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript @@ -35,3 +35,8 @@ plugin.tx_responsiveimages { } } } + +tt_content.example_container-3col < lib.containerElement +tt_content.example_container-3col { + templateName = 3col +} diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/ContentElements/image.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/ContentElements/image.typoscript deleted file mode 100644 index a2bdf61..0000000 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/ContentElements/image.typoscript +++ /dev/null @@ -1,35 +0,0 @@ -tt_content.image { - templateRootPaths { - 110 = EXT:container_example/Resources/Private/Templates/FluidStyledContent - } - partialRootPaths { - 110 = EXT:container_example/Resources/Private/Partials/FluidStyledContent - } - - dataProcessing { - 20 > - 20 = Codappix\ResponsiveImages\DataProcessing\ResponsiveImagesProcessor - 20 { - fieldName = image - filesDataKey = files - } - } -} - -plugin.tx_responsiveimages { - settings { - contentelements { - image { - image { - multiplier { - xs = 1 - sm = 1 - md = 1 - lg = 1 - xl = 1 - } - } - } - } - } -} diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript deleted file mode 100644 index 0db48c6..0000000 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript +++ /dev/null @@ -1,49 +0,0 @@ -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/container_example/Configuration/TypoScript/Rendering.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Rendering.typoscript deleted file mode 100644 index 57404ed..0000000 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Rendering.typoscript +++ /dev/null @@ -1,2 +0,0 @@ -page = PAGE -page.10 < styles.content.get \ No newline at end of file diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Setup.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Setup.typoscript index b6a3f3c..b5e0a79 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Setup.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Setup.typoscript @@ -1,7 +1,3 @@ - - - - lib.containerElement =< lib.contentElement lib.containerElement { layoutRootPaths { @@ -22,27 +18,4 @@ lib.containerElement { } } -tt_content.example_container-1col < lib.containerElement -tt_content.example_container-1col { - templateName = 1col -} - -tt_content.example_container-2col-33-66 < lib.containerElement -tt_content.example_container-2col-33-66 { - templateName = 2col-33-66 -} - -tt_content.example_container-2col-50-50 < lib.containerElement -tt_content.example_container-2col-50-50 { - templateName = 2col-50-50 -} - -tt_content.example_container-2col-66-33 < lib.containerElement -tt_content.example_container-2col-66-33 { - templateName = 2col-66-33 -} - -tt_content.example_container-3col < lib.containerElement -tt_content.example_container-3col { - templateName = 3col -} + diff --git a/Tests/Fixtures/container_example/Resources/Private/Partials/FluidStyledContent/Media/Image.html b/Tests/Fixtures/container_example/Resources/Private/Partials/FluidStyledContent/Media/Image.html deleted file mode 100644 index 5958224..0000000 --- a/Tests/Fixtures/container_example/Resources/Private/Partials/FluidStyledContent/Media/Image.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - - {size.breakpoint.cropVariant} {size.size} {size.breakpoint.mediaQuery} - - - - diff --git a/Tests/Fixtures/container_example/Resources/Private/Templates/FluidStyledContent/Image.html b/Tests/Fixtures/container_example/Resources/Private/Templates/FluidStyledContent/Image.html deleted file mode 100644 index 23439a4..0000000 --- a/Tests/Fixtures/container_example/Resources/Private/Templates/FluidStyledContent/Image.html +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/Tests/Functional/ContainerTest.php b/Tests/Functional/ContainerTest.php index 4fe918a..741371a 100644 --- a/Tests/Functional/ContainerTest.php +++ b/Tests/Functional/ContainerTest.php @@ -42,6 +42,7 @@ protected function setUp(): void $this->testExtensionsToLoad = [ 'b13/container', 'codappix/responsive-images', + 'typo3conf/ext/responsive_images/Tests/Fixtures/base_example', 'typo3conf/ext/responsive_images/Tests/Fixtures/container_example', ]; @@ -56,8 +57,9 @@ protected function setUp(): void $this->setUpFrontendRootPage(1, [ 'EXT:fluid_styled_content/Configuration/TypoScript/setup.typoscript', 'EXT:responsive_images/Configuration/TypoScript/Setup.typoscript', + 'EXT:base_example/Configuration/TypoScript/Setup.typoscript', + 'EXT:base_example/Configuration/TypoScript/Rendering.typoscript', 'EXT:container_example/Configuration/TypoScript/Setup.typoscript', - 'EXT:container_example/Configuration/TypoScript/Rendering.typoscript', ]); }