Skip to content

Commit

Permalink
TASK: Check if container extension is installed (#11)
Browse files Browse the repository at this point in the history
Related: #7

Co-authored-by: Daniel Gohlke <[email protected]>
  • Loading branch information
extcode and d-g-codappix authored Mar 19, 2024
1 parent 7dbf519 commit 445ccfd
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 37 deletions.
15 changes: 9 additions & 6 deletions Classes/Sizes/Rootline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<INCLUDE_TYPOSCRIPT: source="DIR:EXT:base_example/Configuration/TypoScript/ContentElements/">
<INCLUDE_TYPOSCRIPT: source="DIR:EXT:base_example/Configuration/TypoScript/Extensions/">
32 changes: 32 additions & 0 deletions Tests/Fixtures/base_example/Test/Fixtures/0colDatabase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

return [
'tt_content' => [
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',
],
],
];
15 changes: 15 additions & 0 deletions Tests/Fixtures/base_example/composer.json
Original file line number Diff line number Diff line change
@@ -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/responsive-images": "*"
},
"extra": {
"typo3/cms": {
"extension-key": "base_example"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ plugin.tx_responsiveimages {
}
}
}

tt_content.example_container-1col < lib.containerElement
tt_content.example_container-1col {
templateName = 1col
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ plugin.tx_responsiveimages {
}
}
}

tt_content.example_container-3col < lib.containerElement
tt_content.example_container-3col {
templateName = 3col
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<INCLUDE_TYPOSCRIPT: source="DIR:EXT:container_example/Configuration/TypoScript/Container/">
<INCLUDE_TYPOSCRIPT: source="DIR:EXT:container_example/Configuration/TypoScript/ContentElements/">
<INCLUDE_TYPOSCRIPT: source="DIR:EXT:container_example/Configuration/TypoScript/Extensions/">

lib.containerElement =< lib.contentElement
lib.containerElement {
layoutRootPaths {
Expand All @@ -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
}
<INCLUDE_TYPOSCRIPT: source="DIR:EXT:container_example/Configuration/TypoScript/Container/">
94 changes: 94 additions & 0 deletions Tests/Functional/BaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

declare(strict_types=1);

namespace Codappix\ResponsiveImages\Tests;

/*
* Copyright (C) 2024 Daniel Gohlke <[email protected]>
*
* 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/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());
}
}
}
4 changes: 3 additions & 1 deletion Tests/Functional/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected function setUp(): void
$this->testExtensionsToLoad = [
'b13/container',
'codappix/responsive-images',
'typo3conf/ext/responsive_images/Tests/Fixtures/base_example',
'typo3conf/ext/responsive_images/Tests/Fixtures/container_example',
];

Expand All @@ -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',
]);
}

Expand Down

0 comments on commit 445ccfd

Please sign in to comment.