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/container_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig b/Tests/Fixtures/base_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig similarity index 100% rename from Tests/Fixtures/container_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig rename to Tests/Fixtures/base_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/ContentElements/image.typoscript b/Tests/Fixtures/base_example/Configuration/TypoScript/ContentElements/image.typoscript similarity index 80% rename from Tests/Fixtures/container_example/Configuration/TypoScript/ContentElements/image.typoscript rename to Tests/Fixtures/base_example/Configuration/TypoScript/ContentElements/image.typoscript index a2bdf61..3c2b33a 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/ContentElements/image.typoscript +++ b/Tests/Fixtures/base_example/Configuration/TypoScript/ContentElements/image.typoscript @@ -1,9 +1,9 @@ tt_content.image { templateRootPaths { - 110 = EXT:container_example/Resources/Private/Templates/FluidStyledContent + 110 = EXT:base_example/Resources/Private/Templates/FluidStyledContent } partialRootPaths { - 110 = EXT:container_example/Resources/Private/Partials/FluidStyledContent + 110 = EXT:base_example/Resources/Private/Partials/FluidStyledContent } dataProcessing { diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript b/Tests/Fixtures/base_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript similarity index 100% rename from Tests/Fixtures/container_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript rename to Tests/Fixtures/base_example/Configuration/TypoScript/Extensions/responsive_images/Setup.typoscript diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Rendering.typoscript b/Tests/Fixtures/base_example/Configuration/TypoScript/Rendering.typoscript similarity index 100% rename from Tests/Fixtures/container_example/Configuration/TypoScript/Rendering.typoscript rename to Tests/Fixtures/base_example/Configuration/TypoScript/Rendering.typoscript 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/container_example/Resources/Private/Partials/FluidStyledContent/Media/Image.html b/Tests/Fixtures/base_example/Resources/Private/Partials/FluidStyledContent/Media/Image.html similarity index 100% rename from Tests/Fixtures/container_example/Resources/Private/Partials/FluidStyledContent/Media/Image.html rename to Tests/Fixtures/base_example/Resources/Private/Partials/FluidStyledContent/Media/Image.html diff --git a/Tests/Fixtures/container_example/Resources/Private/Templates/FluidStyledContent/Image.html b/Tests/Fixtures/base_example/Resources/Private/Templates/FluidStyledContent/Image.html similarity index 100% rename from Tests/Fixtures/container_example/Resources/Private/Templates/FluidStyledContent/Image.html rename to Tests/Fixtures/base_example/Resources/Private/Templates/FluidStyledContent/Image.html 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..87d07ce --- /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/typo3-responsive-images": "*" + }, + "extra": { + "typo3/cms": { + "extension-key": "base_example" + } + } +} 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/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/Functional/BaseTest.php b/Tests/Functional/BaseTest.php new file mode 100644 index 0000000..6177aae --- /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/typo3-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()); + } + } +} diff --git a/Tests/Functional/ContainerTest.php b/Tests/Functional/ContainerTest.php index cb92063..abc56ef 100644 --- a/Tests/Functional/ContainerTest.php +++ b/Tests/Functional/ContainerTest.php @@ -42,6 +42,7 @@ protected function setUp(): void $this->testExtensionsToLoad = [ 'b13/container', 'codappix/typo3-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', ]); }