Skip to content

Commit

Permalink
Merge pull request #100 from sitegeist/typo3v12
Browse files Browse the repository at this point in the history
Typo3v12
  • Loading branch information
s2b committed Mar 20, 2023
2 parents c5358ef + 9025b7e commit 04cc0f9
Show file tree
Hide file tree
Showing 29 changed files with 1,386 additions and 313 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- uses: tomasnorre/typo3-upload-ter@v2
with:
api-token: ${{ secrets.TYPO3_API_TOKEN }}
69 changes: 56 additions & 13 deletions .github/workflows/tests.yml
Expand Up @@ -8,15 +8,15 @@ jobs:
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v2
uses: actions/checkout@v3

-
name: Validate composer.json
run: composer validate

-
name: Cache composer dependencies
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.composer/cache
key: composer
Expand All @@ -34,25 +34,27 @@ jobs:
run: composer lint:editorconfig


test:
test-unit:
runs-on: ubuntu-latest

strategy:
max-parallel: 2
matrix:
php-versions: [7.4, 7.3]
typo3-versions: [11, 10, 9]
php-versions: [8.2, 8.1, 8.0]
typo3-versions: [12, 11]
exclude:
- php-versions: 7.3
typo3-versions: 11
- php-versions: 8.0
typo3-versions: 12
include:
- php-versions: 8
- php-versions: 7.4
typo3-versions: 11
- php-versions: 7.4
typo3-versions: 10

name: PHP ${{ matrix.php-versions }} with TYPO3 ${{ matrix.typo3-versions }}
name: Unit Testing (PHP ${{ matrix.php-versions }}, TYPO3 ${{ matrix.typo3-versions }})
steps:
-
uses: actions/checkout@v2
uses: actions/checkout@v3

-
name: Setup PHP
Expand All @@ -63,7 +65,48 @@ jobs:

-
name: Cache composer dependencies
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.composer/cache
key: php-${{ matrix.php-versions }}-typo3-${{ matrix.typo3-versions }}

-
name: Install composer dependencies
run: composer require typo3/minimal "^${{ matrix.typo3-versions }}" --prefer-dist --no-progress --no-suggest

-
name: Unit Testing
run: composer test:unit


test-functional:
runs-on: ubuntu-latest

strategy:
max-parallel: 1
matrix:
php-versions: [8.2, 8.1]
typo3-versions: [12]

name: Functional Testing (PHP ${{ matrix.php-versions }}, TYPO3 ${{ matrix.typo3-versions }})
steps:
-
uses: actions/checkout@v3

-
name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: intl, mbstring, pdo_sqlite

-
name: Setup GraphicsMagick
run: sudo apt-get install -y graphicsmagick

-
name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ~/.composer/cache
key: php-${{ matrix.php-versions }}-typo3-${{ matrix.typo3-versions }}
Expand All @@ -73,5 +116,5 @@ jobs:
run: composer require typo3/minimal "^${{ matrix.typo3-versions }}" --prefer-dist --no-progress --no-suggest

-
name: Automated Testing
run: composer test
name: Functional Testing
run: typo3DatabaseDriver=pdo_sqlite composer test:functional
27 changes: 27 additions & 0 deletions Build/Testing/FunctionalTests.xml
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
backupGlobals="true"
bootstrap="FunctionalTestsBootstrap.php"
colors="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
beStrictAboutTestsThatDoNotTestAnything="false"
failOnWarning="true"
cacheDirectory=".phpunit.cache"
requireCoverageMetadata="false"
>
<testsuites>
<testsuite name="Functional tests">
<directory>../../Tests/Functional/</directory>
</testsuite>
</testsuites>
<php>
<const name="TYPO3_MODE" value="BE"/>
<ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/>
</php>
</phpunit>
20 changes: 20 additions & 0 deletions Build/Testing/FunctionalTestsBootstrap.php
@@ -0,0 +1,20 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

call_user_func(function () {
$testbase = new \TYPO3\TestingFramework\Core\Testbase();
$testbase->defineOriginalRootPath();
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/tests');
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/transient');
});
28 changes: 28 additions & 0 deletions Build/Testing/UnitTests.xml
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
backupGlobals="true"
bootstrap="UnitTestsBootstrap.php"
colors="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
beStrictAboutTestsThatDoNotTestAnything="false"
failOnWarning="true"
cacheDirectory=".phpunit.cache"
requireCoverageMetadata="false"
>
<testsuites>
<testsuite name="Unit tests">
<directory>../../Tests/Unit/</directory>
</testsuite>
</testsuites>
<php>
<const name="TYPO3_MODE" value="BE"/>
<ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/>
</php>
</phpunit>
75 changes: 75 additions & 0 deletions Build/Testing/UnitTestsBootstrap.php
@@ -0,0 +1,75 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

call_user_func(function () {
$testbase = new \TYPO3\TestingFramework\Core\Testbase();

// These if's are for core testing (package typo3/cms) only. cms-composer-installer does
// not create the autoload-include.php file that sets these env vars and sets composer
// mode to true. testing-framework can not be used without composer anyway, so it is safe
// to do this here. This way it does not matter if 'bin/phpunit' or 'vendor/phpunit/phpunit/phpunit'
// is called to run the tests since the 'relative to entry script' path calculation within
// SystemEnvironmentBuilder is not used. However, the binary must be called from the document
// root since getWebRoot() uses 'getcwd()'.
if (!getenv('TYPO3_PATH_ROOT')) {
putenv('TYPO3_PATH_ROOT=' . rtrim($testbase->getWebRoot(), '/'));
}
if (!getenv('TYPO3_PATH_WEB')) {
putenv('TYPO3_PATH_WEB=' . rtrim($testbase->getWebRoot(), '/'));
}

$testbase->defineSitePath();

$requestType = \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_BE | \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_CLI;
\TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run(0, $requestType);

$testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3conf/ext');
$testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3temp/assets');
$testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3temp/var/tests');
$testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3temp/var/transient');

// Retrieve an instance of class loader and inject to core bootstrap
$classLoader = require $testbase->getPackagesPath() . '/autoload.php';
\TYPO3\CMS\Core\Core\Bootstrap::initializeClassLoader($classLoader);

// Initialize default TYPO3_CONF_VARS
$configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager();
$GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration();

$cache = new \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend(
'core',
new \TYPO3\CMS\Core\Cache\Backend\NullBackend('production', [])
);

// Set all packages to active
if (interface_exists(\TYPO3\CMS\Core\Package\Cache\PackageCacheInterface::class)) {
$packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager(
\TYPO3\CMS\Core\Package\UnitTestPackageManager::class,
\TYPO3\CMS\Core\Core\Bootstrap::createPackageCache($cache)
);
} else {
// v10 compatibility layer
$packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager(
\TYPO3\CMS\Core\Package\UnitTestPackageManager::class,
$cache
);
}

\TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Package\PackageManager::class, $packageManager);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::setPackageManager($packageManager);

$testbase->dumpClassLoadingInformation();

\TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances();
});
7 changes: 5 additions & 2 deletions Classes/Utility/ResponsiveImagesUtility.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Sitegeist\ResponsiveImages\Utility;

use TYPO3\CMS\Core\SingletonInterface;
Expand Down Expand Up @@ -128,7 +130,7 @@ public function createImageTagWithSrcset(
$absoluteUri,
$fileExtension
);
$srcsetMode = substr(key($srcsetImages), -1); // x or w
$srcsetMode = substr(key($srcsetImages) ?? 'w', -1); // x or w

// Add fallback image to source options
$fallbackWidthDescriptor = ($srcsetMode == 'x') ? '1x' : $referenceWidth . 'w';
Expand Down Expand Up @@ -305,7 +307,7 @@ public function createPictureSourceTag(
$absoluteUri,
$fileExtension
);
$srcsetMode = substr(key($srcsetImages), -1); // x or w
$srcsetMode = substr(key($srcsetImages) ?? 'w', -1); // x or w

// Create source tag for this breakpoint
$sourceTag = GeneralUtility::makeInstance(TagBuilder::class, 'source');
Expand Down Expand Up @@ -462,6 +464,7 @@ public function generateSrcsetImages(

$images = [];
foreach ($srcset as $widthDescriptor) {
$widthDescriptor = (string) $widthDescriptor;
// Determine image width
$srcsetMode = substr($widthDescriptor, -1);
switch ($srcsetMode) {
Expand Down

0 comments on commit 04cc0f9

Please sign in to comment.