Skip to content

Commit

Permalink
TASK: Add frontend tests for b13/container extension (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
justusmoroni committed Mar 20, 2024
1 parent 41c2179 commit 26d634c
Show file tree
Hide file tree
Showing 37 changed files with 1,128 additions and 10 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/composer.lock
/.php-cs-fixer.cache
/.phpunit.cache
/.Build/
/public/
/vendor/
/vendor/
36 changes: 36 additions & 0 deletions Classes/Sizes/Rootline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
74 changes: 74 additions & 0 deletions Tests/Fixtures/BaseDatabase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

use TYPO3\CMS\Core\Domain\Repository\PageRepository;

return [
'pages' => [
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' => '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3FlexForms>
<data>
<sheet index="sDEF">
<language index="lDEF">
<field index="basePath">
<value index="vDEF">fileadmin/</value>
</field>
<field index="pathType">
<value index="vDEF">relative</value>
</field>
<field index="baseUri">
<value index="vDEF"></value>
</field>
<field index="caseSensitive">
<value index="vDEF">1</value>
</field>
</language>
</sheet>
</data>
</T3FlexForms>',
],
],
'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',
],
],
];
19 changes: 19 additions & 0 deletions Tests/Fixtures/config/sites/default/config.yaml
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

use B13\Container\Tca\ContainerConfiguration;
use B13\Container\Tca\Registry;
use TYPO3\CMS\Core\Utility\GeneralUtility;

(static function (string $cType = 'example_container-1col'): void {
GeneralUtility::makeInstance(Registry::class)->configureContainer(new ContainerConfiguration(
$cType,
'1 Column: 100',
'(100%)',
[
[
[
'name' => 'Column 101',
'colPos' => 101,
],
],
]
));
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use B13\Container\Tca\ContainerConfiguration;
use B13\Container\Tca\Registry;
use TYPO3\CMS\Core\Utility\GeneralUtility;

(static function (string $cType = 'example_container-2col-33-66'): void {
GeneralUtility::makeInstance(Registry::class)->configureContainer(new ContainerConfiguration(
$cType,
'2 Column: 33-66',
'(33% / 66%)',
[
[
[
'name' => 'Column 101',
'colPos' => 101,
],
[
'name' => 'Column 102',
'colPos' => 102,
],
],
]
));
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use B13\Container\Tca\ContainerConfiguration;
use B13\Container\Tca\Registry;
use TYPO3\CMS\Core\Utility\GeneralUtility;

(static function (string $cType = 'example_container-2col-50-50'): void {
GeneralUtility::makeInstance(Registry::class)->configureContainer(new ContainerConfiguration(
$cType,
'2 Column: 50-50',
'(50% / 50%)',
[
[
[
'name' => 'Column 101',
'colPos' => 101,
],
[
'name' => 'Column 102',
'colPos' => 102,
],
],
]
));
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use B13\Container\Tca\ContainerConfiguration;
use B13\Container\Tca\Registry;
use TYPO3\CMS\Core\Utility\GeneralUtility;

(static function (string $cType = 'example_container-2col-66-33'): void {
GeneralUtility::makeInstance(Registry::class)->configureContainer(new ContainerConfiguration(
$cType,
'2 Column: 66-33',
'(66% / 33%)',
[
[
[
'name' => 'Column 101',
'colPos' => 101,
],
[
'name' => 'Column 102',
'colPos' => 102,
],
],
]
));
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

use B13\Container\Tca\ContainerConfiguration;
use B13\Container\Tca\Registry;
use TYPO3\CMS\Core\Utility\GeneralUtility;

(static function (string $cType = 'example_container-3col'): void {
GeneralUtility::makeInstance(Registry::class)->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,
],
],
]
));
})();
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugin.tx_responsiveimages {
settings {
example_container-1col {
columns {
101 {
multiplier {
xs = 1
sm = 1
md = 1
lg = 1
xl = 1
}
}
}
}
}
}
Loading

0 comments on commit 26d634c

Please sign in to comment.