diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4c1acf0..47b5615 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -100,3 +100,54 @@ jobs: - name: Code Quality (by PHPStan) run: ./vendor/bin/phpstan analyse + + tests-mysql: + runs-on: ubuntu-latest + needs: + - php-linting + - xml-linting + strategy: + matrix: + include: + - php-version: '8.1' + typo3-version: '^12.4' + db-version: '8' + - php-version: '8.2' + typo3-version: '^12.4' + db-version: '8' + - php-version: '8.3' + typo3-version: '^12.4' + db-version: '8' + steps: + - uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php-version }}" + tools: composer:v2 + + - name: Setup MySQL + uses: mirromutth/mysql-action@v1.1 + with: + mysql version: "${{ matrix.db-version }}" + mysql database: 'typo3' + mysql root password: 'root' + + - name: Wait for MySQL + run: | + while ! mysqladmin ping --host=127.0.0.1 --password=root --silent; do + sleep 1 + done + + - name: Install dependencies + run: composer require --no-interaction --prefer-dist --no-progress "typo3/cms-backend:${{ matrix.typo3-version }}" "typo3/cms-core:${{ matrix.typo3-version }}" "typo3/cms-extbase:${{ matrix.typo3-version }}" "typo3/cms-frontend:${{ matrix.typo3-version }}" "typo3/cms-fluid-styled-content:${{ matrix.typo3-version }}" + + - name: PHPUnit Tests + run: |- + export typo3DatabaseDriver="pdo_mysql" + export typo3DatabaseName="typo3" + export typo3DatabaseHost="127.0.0.1" + export typo3DatabaseUsername="root" + export typo3DatabasePassword="root" + ./vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index 760ad8f..15f338a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /composer.lock /.php-cs-fixer.cache +/.phpunit.cache /.Build/ -/public/ -/vendor/ \ No newline at end of file +/vendor/ diff --git a/Classes/Sizes/Rootline.php b/Classes/Sizes/Rootline.php index 3d05ff1..0c3fbd8 100644 --- a/Classes/Sizes/Rootline.php +++ b/Classes/Sizes/Rootline.php @@ -23,6 +23,10 @@ * 02110-1301, USA. */ +use TYPO3\CMS\Core\Database\Connection; +use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Database\Query\QueryBuilder; +use TYPO3\CMS\Core\Error\Exception; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Page\PageLayoutResolver; @@ -106,6 +110,38 @@ private function parseRootline(ContentElementInterface $contentElement): void return; } + + $parentContainer = $contentElement->getData('tx_container_parent'); + assert(is_int($parentContainer)); + $parent = $this->fetchContentElementFromDatabase($parentContainer); + + $this->rootline[] = $parent; + $this->parseRootline($parent); + + $contentElement->setParent($parent); + } + + /** + * @throws \Doctrine\DBAL\Exception + * @throws Exception + */ + private function fetchContentElementFromDatabase(int $identifier): ContentElementInterface + { + /** @var QueryBuilder $queryBuilder */ + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content'); + $rawData = $queryBuilder + ->select('*') + ->from('tt_content') + ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($identifier, Connection::PARAM_INT))) + ->executeQuery() + ->fetchAssociative() + ; + + if ($rawData === false) { + throw new Exception("Content element '" . $identifier . "' not found."); + } + + return $this->determineContentElement($rawData); } private function calculateSizes(): void diff --git a/Tests/Fixtures/BaseDatabase.php b/Tests/Fixtures/BaseDatabase.php new file mode 100644 index 0000000..e915ad1 --- /dev/null +++ b/Tests/Fixtures/BaseDatabase.php @@ -0,0 +1,74 @@ + [ + 0 => [ + 'uid' => '1', + 'pid' => '0', + 'title' => 'Root', + 'doktype' => PageRepository::DOKTYPE_DEFAULT, + 'slug' => '/', + 'sorting' => '128', + 'deleted' => '0', + 'backend_layout' => 'pagets__MainTemplate', + 'backend_layout_next_level' => 'pagets__MainTemplate', + ], + 1 => [ + 'uid' => '2', + 'pid' => '1', + 'title' => 'Root', + 'doktype' => PageRepository::DOKTYPE_DEFAULT, + 'slug' => '/test', + 'sorting' => '128', + 'deleted' => '0', + ], + ], + 'sys_file_storage' => [ + 0 => [ + 'uid' => '1', + 'name' => 'test', + 'driver' => 'Local', + 'is_default' => '1', + 'is_public' => '1', + 'is_browsable' => '1', + 'is_writable' => '1', + 'configuration' => ' + + + + + + fileadmin/ + + + relative + + + + + + 1 + + + + +', + ], + ], + 'sys_file' => [ + 0 => [ + 'uid' => '1', + 'pid' => '0', + 'storage' => '1', + 'type' => '2', + 'identifier' => 'test_data/Example.png', + 'name' => 'Example.png', + 'extension' => 'png', + 'mime_type' => 'image/png', + ], + ], +]; diff --git a/Tests/Fixtures/config/sites/default/config.yaml b/Tests/Fixtures/config/sites/default/config.yaml new file mode 100644 index 0000000..bf04c79 --- /dev/null +++ b/Tests/Fixtures/config/sites/default/config.yaml @@ -0,0 +1,19 @@ +base: / +languages: + - + title: English + enabled: true + base: / + typo3Language: default + locale: en_GB.UTF-8 + iso-639-1: en + websiteTitle: '' + navigationTitle: English + hreflang: en-GB + direction: '' + flag: gb + languageId: 0 + fallbackType: strict + fallbacks: '0' +rootPageId: 1 +websiteTitle: 'Container Example' diff --git a/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_1col.php b/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_1col.php new file mode 100644 index 0000000..3e3f60e --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_1col.php @@ -0,0 +1,23 @@ +configureContainer(new ContainerConfiguration( + $cType, + '1 Column: 100', + '(100%)', + [ + [ + [ + 'name' => 'Column 101', + 'colPos' => 101, + ], + ], + ] + )); +})(); diff --git a/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_33_66.php b/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_33_66.php new file mode 100644 index 0000000..2dd65d2 --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_33_66.php @@ -0,0 +1,27 @@ +configureContainer(new ContainerConfiguration( + $cType, + '2 Column: 33-66', + '(33% / 66%)', + [ + [ + [ + 'name' => 'Column 101', + 'colPos' => 101, + ], + [ + 'name' => 'Column 102', + 'colPos' => 102, + ], + ], + ] + )); +})(); diff --git a/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_50_50.php b/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_50_50.php new file mode 100644 index 0000000..7eb502d --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_50_50.php @@ -0,0 +1,27 @@ +configureContainer(new ContainerConfiguration( + $cType, + '2 Column: 50-50', + '(50% / 50%)', + [ + [ + [ + 'name' => 'Column 101', + 'colPos' => 101, + ], + [ + 'name' => 'Column 102', + 'colPos' => 102, + ], + ], + ] + )); +})(); diff --git a/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_66_33.php b/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_66_33.php new file mode 100644 index 0000000..4353dad --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_66_33.php @@ -0,0 +1,27 @@ +configureContainer(new ContainerConfiguration( + $cType, + '2 Column: 66-33', + '(66% / 33%)', + [ + [ + [ + 'name' => 'Column 101', + 'colPos' => 101, + ], + [ + 'name' => 'Column 102', + 'colPos' => 102, + ], + ], + ] + )); +})(); diff --git a/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_3col.php b/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_3col.php new file mode 100644 index 0000000..f965fab --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_3col.php @@ -0,0 +1,31 @@ +configureContainer(new ContainerConfiguration( + $cType, + '3 Column: 33-33-33', + '(33% / 33% / 33%)', + [ + [ + [ + 'name' => 'Column 101', + 'colPos' => 101, + ], + [ + 'name' => 'Column 102', + 'colPos' => 102, + ], + [ + 'name' => 'Column 103', + 'colPos' => 103, + ], + ], + ] + )); +})(); diff --git a/Tests/Fixtures/container_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig b/Tests/Fixtures/container_example/Configuration/TSconfig/Page/Backend_Layouts.tsconfig new file mode 100644 index 0000000..2a2ce24 --- /dev/null +++ b/Tests/Fixtures/container_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/container_example/Configuration/TypoScript/Container/1col.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/1col.typoscript new file mode 100644 index 0000000..14af340 --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/1col.typoscript @@ -0,0 +1,17 @@ +plugin.tx_responsiveimages { + settings { + example_container-1col { + columns { + 101 { + multiplier { + xs = 1 + sm = 1 + md = 1 + lg = 1 + xl = 1 + } + } + } + } + } +} 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 new file mode 100644 index 0000000..c85850e --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-33-66.typoscript @@ -0,0 +1,27 @@ +plugin.tx_responsiveimages { + settings { + example_container-2col-33-66 { + columns { + 101 { + multiplier { + xs = 1 + sm = 1 + md = 0,333 + lg = 0,333 + xl = 0,333 + } + } + + 102 { + multiplier { + xs = 1 + sm = 1 + md = 0,666 + lg = 0,666 + xl = 0,666 + } + } + } + } + } +} 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 new file mode 100644 index 0000000..94fe8a6 --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50.typoscript @@ -0,0 +1,27 @@ +plugin.tx_responsiveimages { + settings { + example_container-2col-50-50 { + columns { + 101 { + multiplier { + xs = 1 + sm = 1 + md = 0,5 + lg = 0,5 + xl = 0,5 + } + } + + 102 { + multiplier { + xs = 1 + sm = 1 + md = 0,5 + lg = 0,5 + xl = 0,5 + } + } + } + } + } +} 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 new file mode 100644 index 0000000..be60576 --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-66-33.typoscript @@ -0,0 +1,27 @@ +plugin.tx_responsiveimages { + settings { + example_container-2col-66-33 { + columns { + 101 { + multiplier { + xs = 1 + sm = 1 + md = 0,666 + lg = 0,666 + xl = 0,666 + } + } + + 102 { + multiplier { + xs = 1 + sm = 1 + md = 0,333 + lg = 0,333 + xl = 0,333 + } + } + } + } + } +} diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript new file mode 100644 index 0000000..d2a0956 --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript @@ -0,0 +1,37 @@ +plugin.tx_responsiveimages { + settings { + example_container-3col { + columns { + 101 { + multiplier { + xs = 1 + sm = 1 + md = 0,333 + lg = 0,333 + xl = 0,333 + } + } + + 102 { + multiplier { + xs = 1 + sm = 1 + md = 0,333 + lg = 0,333 + xl = 0,333 + } + } + + 103 { + multiplier { + xs = 1 + sm = 1 + md = 0,333 + lg = 0,333 + xl = 0,333 + } + } + } + } + } +} diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/ContentElements/image.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/ContentElements/image.typoscript new file mode 100644 index 0000000..a2bdf61 --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/ContentElements/image.typoscript @@ -0,0 +1,35 @@ +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 new file mode 100644 index 0000000..0db48c6 --- /dev/null +++ b/Tests/Fixtures/container_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/container_example/Configuration/TypoScript/Rendering.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Rendering.typoscript new file mode 100644 index 0000000..57404ed --- /dev/null +++ b/Tests/Fixtures/container_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/container_example/Configuration/TypoScript/Setup.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Setup.typoscript new file mode 100644 index 0000000..b6a3f3c --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Setup.typoscript @@ -0,0 +1,48 @@ + + + + +lib.containerElement =< lib.contentElement +lib.containerElement { + layoutRootPaths { + 100 = EXT:fluid_styled_content/Resources/Private/Layouts + } + + templateRootPaths { + 100 = EXT:fluid_styled_content/Resources/Private/Templates + 110 = EXT:container_example/Resources/Private/Templates/Container + } + + partialRootPaths { + 100 = EXT:fluid_styled_content/Resources/Private/Partials + } + + dataProcessing { + 10 = B13\Container\DataProcessing\ContainerProcessor + } +} + +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 new file mode 100644 index 0000000..5958224 --- /dev/null +++ b/Tests/Fixtures/container_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/container_example/Resources/Private/Templates/Container/1col.html b/Tests/Fixtures/container_example/Resources/Private/Templates/Container/1col.html new file mode 100644 index 0000000..4054a32 --- /dev/null +++ b/Tests/Fixtures/container_example/Resources/Private/Templates/Container/1col.html @@ -0,0 +1,9 @@ + + + + + {child.renderedContent -> f:format.raw()} + + + + \ No newline at end of file diff --git a/Tests/Fixtures/container_example/Resources/Private/Templates/Container/2col-33-66.html b/Tests/Fixtures/container_example/Resources/Private/Templates/Container/2col-33-66.html new file mode 100644 index 0000000..fb2572d --- /dev/null +++ b/Tests/Fixtures/container_example/Resources/Private/Templates/Container/2col-33-66.html @@ -0,0 +1,18 @@ + + +
+
+
+ + {child.renderedContent -> f:format.raw()} + +
+
+ + {child.renderedContent -> f:format.raw()} + +
+
+
+ + \ No newline at end of file diff --git a/Tests/Fixtures/container_example/Resources/Private/Templates/Container/2col-50-50.html b/Tests/Fixtures/container_example/Resources/Private/Templates/Container/2col-50-50.html new file mode 100644 index 0000000..8c6e81a --- /dev/null +++ b/Tests/Fixtures/container_example/Resources/Private/Templates/Container/2col-50-50.html @@ -0,0 +1,18 @@ + + +
+
+
+ + {child.renderedContent -> f:format.raw()} + +
+
+ + {child.renderedContent -> f:format.raw()} + +
+
+
+ + \ No newline at end of file diff --git a/Tests/Fixtures/container_example/Resources/Private/Templates/Container/2col-66-33.html b/Tests/Fixtures/container_example/Resources/Private/Templates/Container/2col-66-33.html new file mode 100644 index 0000000..df30102 --- /dev/null +++ b/Tests/Fixtures/container_example/Resources/Private/Templates/Container/2col-66-33.html @@ -0,0 +1,18 @@ + + +
+
+
+ + {child.renderedContent -> f:format.raw()} + +
+
+ + {child.renderedContent -> f:format.raw()} + +
+
+
+ + \ No newline at end of file diff --git a/Tests/Fixtures/container_example/Resources/Private/Templates/Container/3col.html b/Tests/Fixtures/container_example/Resources/Private/Templates/Container/3col.html new file mode 100644 index 0000000..2e18c5a --- /dev/null +++ b/Tests/Fixtures/container_example/Resources/Private/Templates/Container/3col.html @@ -0,0 +1,29 @@ + + +
+
+
+ + + {child.renderedContent -> f:format.raw()} + + +
+
+ + + {child.renderedContent -> f:format.raw()} + + +
+
+ + + {child.renderedContent -> f:format.raw()} + + +
+
+
+ + \ No newline at end of file diff --git a/Tests/Fixtures/container_example/Resources/Private/Templates/FluidStyledContent/Image.html b/Tests/Fixtures/container_example/Resources/Private/Templates/FluidStyledContent/Image.html new file mode 100644 index 0000000..23439a4 --- /dev/null +++ b/Tests/Fixtures/container_example/Resources/Private/Templates/FluidStyledContent/Image.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Tests/Fixtures/container_example/Test/Fixtures/1colDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/1colDatabase.php new file mode 100644 index 0000000..8c27a32 --- /dev/null +++ b/Tests/Fixtures/container_example/Test/Fixtures/1colDatabase.php @@ -0,0 +1,47 @@ + [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'example_container-1col', + 'header' => '1col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '0', + 'sys_language_uid' => '0', + 'tx_container_parent' => '0', + ], + 1 => [ + 'uid' => '2', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'image', + 'header' => 'image in 1col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '101', + 'sys_language_uid' => '0', + 'image' => '1', + 'tx_container_parent' => '1', + ], + ], + 'sys_file_reference' => [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'uid_local' => '1', + 'uid_foreign' => '2', + 'tablenames' => 'tt_content', + 'fieldname' => 'image', + ], + ], +]; diff --git a/Tests/Fixtures/container_example/Test/Fixtures/2col2colDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/2col2colDatabase.php new file mode 100644 index 0000000..8bc53b9 --- /dev/null +++ b/Tests/Fixtures/container_example/Test/Fixtures/2col2colDatabase.php @@ -0,0 +1,61 @@ + [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'example_container-2col-50-50', + 'header' => '2col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '0', + 'sys_language_uid' => '0', + 'tx_container_parent' => '0', + ], + 1 => [ + 'uid' => '2', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'example_container-2col-50-50', + 'header' => '2col in 2col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '101', + 'sys_language_uid' => '0', + 'tx_container_parent' => '1', + ], + 2 => [ + 'uid' => '3', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'image', + 'header' => 'image in 2col in 2col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '101', + 'sys_language_uid' => '0', + 'image' => '1', + 'tx_container_parent' => '2', + ], + ], + 'sys_file_reference' => [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'uid_local' => '1', + 'uid_foreign' => '3', + 'tablenames' => 'tt_content', + 'fieldname' => 'image', + ], + ], +]; diff --git a/Tests/Fixtures/container_example/Test/Fixtures/2col_50_50_Database.php b/Tests/Fixtures/container_example/Test/Fixtures/2col_50_50_Database.php new file mode 100644 index 0000000..f5f78bc --- /dev/null +++ b/Tests/Fixtures/container_example/Test/Fixtures/2col_50_50_Database.php @@ -0,0 +1,47 @@ + [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'example_container-2col-50-50', + 'header' => '1col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '0', + 'sys_language_uid' => '0', + 'tx_container_parent' => '0', + ], + 1 => [ + 'uid' => '2', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'image', + 'header' => 'image in 2col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '101', + 'sys_language_uid' => '0', + 'image' => '1', + 'tx_container_parent' => '1', + ], + ], + 'sys_file_reference' => [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'uid_local' => '1', + 'uid_foreign' => '2', + 'tablenames' => 'tt_content', + 'fieldname' => 'image', + ], + ], +]; diff --git a/Tests/Fixtures/container_example/Test/Fixtures/2col_66_33_Database.php b/Tests/Fixtures/container_example/Test/Fixtures/2col_66_33_Database.php new file mode 100644 index 0000000..6d2527b --- /dev/null +++ b/Tests/Fixtures/container_example/Test/Fixtures/2col_66_33_Database.php @@ -0,0 +1,47 @@ + [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'example_container-2col-66-33', + 'header' => '1col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '0', + 'sys_language_uid' => '0', + 'tx_container_parent' => '0', + ], + 1 => [ + 'uid' => '2', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'image', + 'header' => 'image in 2col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '101', + 'sys_language_uid' => '0', + 'image' => '1', + 'tx_container_parent' => '1', + ], + ], + 'sys_file_reference' => [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'uid_local' => '1', + 'uid_foreign' => '2', + 'tablenames' => 'tt_content', + 'fieldname' => 'image', + ], + ], +]; diff --git a/Tests/Fixtures/container_example/Test/Fixtures/3colDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/3colDatabase.php new file mode 100644 index 0000000..606188f --- /dev/null +++ b/Tests/Fixtures/container_example/Test/Fixtures/3colDatabase.php @@ -0,0 +1,47 @@ + [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'example_container-3col', + 'header' => '3col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '0', + 'sys_language_uid' => '0', + 'tx_container_parent' => '0', + ], + 1 => [ + 'uid' => '2', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'image', + 'header' => 'image in 3col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '101', + 'sys_language_uid' => '0', + 'image' => '1', + 'tx_container_parent' => '1', + ], + ], + 'sys_file_reference' => [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'uid_local' => '1', + 'uid_foreign' => '2', + 'tablenames' => 'tt_content', + 'fieldname' => 'image', + ], + ], +]; diff --git a/Tests/Fixtures/container_example/composer.json b/Tests/Fixtures/container_example/composer.json new file mode 100644 index 0000000..d8a2d6a --- /dev/null +++ b/Tests/Fixtures/container_example/composer.json @@ -0,0 +1,16 @@ +{ + "name": "codappix/container_example", + "description": "Add a container example for frontend tests", + "type": "typo3-cms-extension", + "license": "GPL-2.0-or-later", + "require": { + "typo3/cms-core": "*", + "b13/container": "*", + "codappix/typo3-responsive-images": "*" + }, + "extra": { + "typo3/cms": { + "extension-key": "container_example" + } + } +} diff --git a/Tests/Fixtures/fileadmin/test_data/Example.png b/Tests/Fixtures/fileadmin/test_data/Example.png new file mode 100644 index 0000000..bb01213 Binary files /dev/null and b/Tests/Fixtures/fileadmin/test_data/Example.png differ diff --git a/Tests/Functional/ContainerTest.php b/Tests/Functional/ContainerTest.php new file mode 100644 index 0000000..9cbfd17 --- /dev/null +++ b/Tests/Functional/ContainerTest.php @@ -0,0 +1,138 @@ + + * + * 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 TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; + +class ContainerTest extends FunctionalTestCase +{ + use TestingFramework; + + protected function setUp(): void + { + $this->coreExtensionsToLoad = [ + 'fluid_styled_content', + ]; + + $this->testExtensionsToLoad = [ + 'b13/container', + 'codappix/typo3-responsive-images', + 'typo3conf/ext/responsive_images/Tests/Fixtures/container_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:container_example/Configuration/TypoScript/Setup.typoscript', + 'EXT:container_example/Configuration/TypoScript/Rendering.typoscript', + ]); + } + + public static function imageScalingValuesDataProvider(): iterable + { + + yield '1 Column' => [ + '1colDatabase.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)', + ], + ]; + yield '2 Column 50-50' => [ + '2col_50_50_Database.php', + [ + '0' => 'mobile 734 (max-width: 480px)', + '1' => 'mobile 704 (max-width: 767px)', + '2' => 'tablet 462 (max-width: 991px)', + '3' => 'default 562 (max-width: 1479px)', + '4' => 'large 562 (min-width: 1480px)', + ], + ]; + yield '2 Column 66-33' => [ + '2col_66_33_Database.php', + [ + '0' => 'mobile 734 (max-width: 480px)', + '1' => 'mobile 704 (max-width: 767px)', + '2' => 'tablet 615.384 (max-width: 991px)', + '3' => 'default 748.584 (max-width: 1479px)', + '4' => 'large 748.584 (min-width: 1480px)', + ], + ]; + yield '2 Column in 2 Column' => [ + '2col2colDatabase.php', + [ + '0' => 'mobile 734 (max-width: 480px)', + '1' => 'mobile 704 (max-width: 767px)', + '2' => 'tablet 231 (max-width: 991px)', + '3' => 'default 281 (max-width: 1479px)', + '4' => 'large 281 (min-width: 1480px)', + ], + ]; + yield '3 Column' => [ + '3colDatabase.php', + [ + '0' => 'mobile 734 (max-width: 480px)', + '1' => 'mobile 704 (max-width: 767px)', + '2' => 'tablet 307.692 (max-width: 991px)', + '3' => 'default 374.292 (max-width: 1479px)', + '4' => 'large 374.292 (min-width: 1480px)', + ], + ]; + + } + + /** + * @test + * + * @dataProvider imageScalingValuesDataProvider + */ + public function imageIsScaledCorrectly(string $phpDataSet, array $expectedValues): void + { + $this->importPHPDataSet(__DIR__ . '/../Fixtures/container_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/composer.json b/composer.json index 9425243..7c382ad 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,6 @@ "description": "TYPO3 Extension to generate perfectly sized responsive images", "type": "typo3-cms-extension", "license": "GPL-2.0-or-later", - "version": "1.0.0", "authors": [ { "name": "Justus Moroni", @@ -16,20 +15,25 @@ "Codappix\\ResponsiveImages\\": "Classes/" } }, + "autoload-dev": { + "psr-4": { + "Codappix\\ResponsiveImages\\Tests\\": "Tests/" + } + }, "extra": { "typo3/cms": { - "extension-key": "responsive_images" + "extension-key": "responsive_images", + "web-dir": ".Build/public" } }, "require": { "php": "~8.1.0 || ~8.2.0 || ~8.3.0", "typo3/cms-core": "^12.4", - "typo3/cms-extbase": "^12.4", - "typo3/cms-frontend": "^12.4", - "ext-pdo": "*" + "typo3/cms-frontend": "^12.4" }, "require-dev": { "b13/container": "^2.3", + "codappix/typo3-php-datasets": "^1.5", "erickskrauch/php-cs-fixer-custom-fixers": "^1.2", "friendsofphp/php-cs-fixer": "^3.50", "kubawerlos/php-cs-fixer-custom-fixers": "^3.21", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f6dded2..bafba5e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -24,9 +24,6 @@ - - Tests/Unit/ - Tests/Functional/