Skip to content

Commit

Permalink
Merge pull request #109 from koehnlein/feature/typo3-13
Browse files Browse the repository at this point in the history
[TASK] Add compatibility with TYPO3 13 including tests
  • Loading branch information
ulrichmathes authored Jan 21, 2025
2 parents d367d24 + 431ee27 commit f0088b8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 25 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ jobs:
typo3-versions: 11
- php-versions: 7.4
typo3-versions: 10
- php-versions: 8.2
typo3-versions: 13
- php-versions: 8.3
typo3-versions: 13
- php-versions: 8.4
typo3-versions: 13

name: Unit Testing (PHP ${{ matrix.php-versions }}, TYPO3 ${{ matrix.typo3-versions }})
steps:
Expand Down Expand Up @@ -87,6 +93,13 @@ jobs:
matrix:
php-versions: [8.2, 8.1]
typo3-versions: [12]
include:
- php-versions: 8.2
typo3-versions: 13
- php-versions: 8.3
typo3-versions: 13
- php-versions: 8.4
typo3-versions: 13

name: Functional Testing (PHP ${{ matrix.php-versions }}, TYPO3 ${{ matrix.typo3-versions }})
steps:
Expand Down
28 changes: 14 additions & 14 deletions Classes/Utility/ResponsiveImagesUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public function createImageTagWithSrcset(
FileInterface $originalImage,
FileInterface $fallbackImage,
$srcset,
Area $cropArea = null,
Area $focusArea = null,
string $sizesQuery = null,
TagBuilder $tag = null,
?Area $cropArea = null,
?Area $focusArea = null,
?string $sizesQuery = null,
?TagBuilder $tag = null,
bool $absoluteUri = false,
bool $lazyload = false,
$ignoreFileExtensions = 'svg, gif',
Expand Down Expand Up @@ -177,9 +177,9 @@ public function createPictureTag(
FileInterface $fallbackImage,
array $breakpoints,
CropVariantCollection $cropVariantCollection,
Area $focusArea = null,
TagBuilder $tag = null,
TagBuilder $fallbackTag = null,
?Area $focusArea = null,
?TagBuilder $tag = null,
?TagBuilder $fallbackTag = null,
bool $absoluteUri = false,
bool $lazyload = false,
$ignoreFileExtensions = 'svg, gif',
Expand Down Expand Up @@ -288,7 +288,7 @@ public function createPictureSourceTag(
$srcset,
string $mediaQuery = '',
string $sizesQuery = '',
Area $cropArea = null,
?Area $cropArea = null,
bool $absoluteUri = false,
bool $lazyload = false,
?string $fileExtension = null
Expand Down Expand Up @@ -338,9 +338,9 @@ public function createPictureSourceTag(
*/
public function createSimpleImageTag(
FileInterface $originalImage,
FileInterface $fallbackImage = null,
TagBuilder $tag = null,
Area $focusArea = null,
?FileInterface $fallbackImage = null,
?TagBuilder $tag = null,
?Area $focusArea = null,
bool $absoluteUri = false,
bool $lazyload = false,
int $placeholderSize = 0,
Expand Down Expand Up @@ -406,7 +406,7 @@ public function addMetadataToImageTag(
TagBuilder $tag,
FileInterface $originalImage,
FileInterface $fallbackImage,
Area $focusArea = null
?Area $focusArea = null
) {
$focusArea = $focusArea ?: Area::createEmpty();

Expand Down Expand Up @@ -451,7 +451,7 @@ public function generateSrcsetImages(
FileInterface $image,
int $defaultWidth,
$srcset,
Area $cropArea = null,
?Area $cropArea = null,
bool $absoluteUri = false,
?string $fileExtension = null
): array {
Expand Down Expand Up @@ -519,7 +519,7 @@ public function generateSrcsetImages(
public function generatePlaceholderImage(
FileInterface $image,
int $width = 20,
Area $cropArea = null,
?Area $cropArea = null,
bool $inline = false,
bool $absoluteUri = false,
?string $fileExtension = null
Expand Down
6 changes: 3 additions & 3 deletions Classes/ViewHelpers/MediaViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public function initializeArguments(): void
public function render(): string
{
$file = $this->arguments['file'];
$additionalConfig = (array)$this->arguments['additionalConfig'];
$width = $this->arguments['width'];
$height = $this->arguments['height'];
$additionalConfig = (array)($this->arguments['additionalConfig'] ?? []);
$width = $this->arguments['width'] ?? '';
$height = $this->arguments['height'] ?? '';

// get Resource Object (non ExtBase version)
if (is_callable([$file, 'getOriginalResource'])) {
Expand Down
19 changes: 13 additions & 6 deletions Tests/Functional/ImageViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ public static function basicScalingCroppingDataProvider(): \Generator
150
];
// would be 200x150, but image will be stretched (why!?) up to have a width of 250
// @todo remove multiple possible heights when dropping support for versions before TYPO3 13
yield 'min width' => [
'<sms:image src="EXT:sms_responsive_images/Tests/Functional/Fixtures/ImageViewHelperTest.png" height="150" minWidth="250" />',
'@^<img src="(typo3temp/assets/_processed_/4/5/csm_ImageViewHelperTest_.*\.png)" width="250" height="150" alt="" />$@',
'@^<img src="(typo3temp/assets/_processed_/4/5/csm_ImageViewHelperTest_.*\.png)" width="250" height="(188|150)" alt="" />$@',
250,
150
[188, 150]
];
// would be 200x150, but image will be scaled down to have a width of 100
yield 'max width' => [
Expand All @@ -92,9 +93,11 @@ public static function basicScalingCroppingDataProvider(): \Generator
75
];
// would be 200x150, but image will be stretched (why!?) up to have a height of 200
// @todo remove multiple possible widths when dropping support for versions before TYPO3 13
yield 'min height' => [
'<sms:image src="EXT:sms_responsive_images/Tests/Functional/Fixtures/ImageViewHelperTest.png" width="200" minHeight="200" />',
'@^<img src="(typo3temp/assets/_processed_/4/5/csm_ImageViewHelperTest_.*\.png)" width="200" height="200" alt="" />$@',
'@^<img src="(typo3temp/assets/_processed_/4/5/csm_ImageViewHelperTest_.*\.png)" width="(267|200)" height="200" alt="" />$@',
[267, 200],
200,
200
];
Expand All @@ -108,10 +111,14 @@ public static function basicScalingCroppingDataProvider(): \Generator
}

/**
* @TODO convert parameters to `int` only when dropping support for versions before TYPO3 13
* @param int|int[] $expectedWidth
* @param int|int[] $expectedHeight
*
* @test
* @dataProvider basicScalingCroppingDataProvider
*/
public function basicScalingCropping(string $template, string $expected, int $expectedWidth, int $expectedHeight): void
public function basicScalingCropping(string $template, string $expected, $expectedWidth, $expectedHeight): void
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplateSource('<html
Expand All @@ -133,8 +140,8 @@ public function basicScalingCropping(string $template, string $expected, int $ex
$matches = [];
preg_match($expected, $result, $matches);
list($width, $height) = getimagesize($this->instancePath . '/' . $matches[1]);
self::assertEquals($expectedWidth, $width, 'width of generated image does not match expected width');
self::assertEquals($expectedHeight, $height, 'height of generated image does not match expected height');
self::assertContains($width, is_array($expectedWidth) ? $expectedWidth : [$expectedWidth], 'width of generated image does not match expected width');
self::assertContains($height, is_array($expectedHeight) ? $expectedHeight : [$expectedHeight], 'height of generated image does not match expected height');
}

public static function cropVariantCollectionDataProvider(): \Generator
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"issues": "https://github.com/sitegeist/sms-responsive-images/issues"
},
"require": {
"typo3/cms-core": "^12.2 || ^11.5 || ^10.4"
"typo3/cms-core": "^13.1 || ^12.2 || ^11.5 || ^10.4"
},
"require-dev": {
"typo3/testing-framework": "^7.0 || ^6.0 || dev-main",
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'version' => '3.0.0',
'constraints' => [
'depends' => [
'typo3' => '10.4.0-12.9.99',
'typo3' => '10.4.0-13.9.99',
],
'conflicts' => [
],
Expand Down

0 comments on commit f0088b8

Please sign in to comment.