Skip to content

Commit

Permalink
[FEATURE] Add first functional test using a request (#1021)
Browse files Browse the repository at this point in the history
That way the extension serves as an example on how to use the TYPO3
internal requests provided by the TYPO3 testing framework.
Those can be used as integration tests.
They are also often easier to set up on existing projects and allow to
refactor the code base, compared to functional and unit tests.

Resolves: #859
  • Loading branch information
DanielSiepmann authored Nov 27, 2023
1 parent 8587bc8 commit 555c43e
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tt_content
,uid,pid,CType,header,list_type
,1,1,list,Teas Index,tea_teaindex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pages
,uid,pid,title,slug
,1,0,Rootpage,/
,2,1,Storage,/storage
4 changes: 4 additions & 0 deletions Tests/Functional/Controller/Fixtures/Database/Teas.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"tx_tea_domain_model_product_tea"
,"uid","pid","title"
,1,2,"Godesberger Burgtee"
,2,2,"Oolong"
16 changes: 16 additions & 0 deletions Tests/Functional/Controller/Fixtures/Sites/default/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
base: '/'
languages:
-
title: English
enabled: true
languageId: '0'
base: /
typo3Language: default
locale: en_US.utf8
iso-639-1: en
navigationTitle: English
hreflang: en-us
direction: ltr
flag: us
websiteTitle: ''
rootPageId: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
page = PAGE
page {
10 < styles.content.get
}
52 changes: 52 additions & 0 deletions Tests/Functional/Controller/TeaControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace TTN\Tea\Tests\Functional\Controller;

use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

/**
* @covers \TTN\Tea\Controller\TeaController
*/
final class TeaControllerTest extends FunctionalTestCase
{
protected array $testExtensionsToLoad = ['ttn/tea'];

protected array $coreExtensionsToLoad = ['typo3/cms-fluid-styled-content'];

protected array $pathsToLinkInTestInstance = [
'typo3conf/ext/tea/Tests/Functional/Controller/Fixtures/Sites/' => 'typo3conf/sites',
];

protected function setUp(): void
{
parent::setUp();

$this->importCSVDataSet(__DIR__ . '/Fixtures/Database/SiteStructure.csv');
$this->setUpFrontendRootPage(1, [
'setup' => [
'EXT:fluid_styled_content/Configuration/TypoScript/setup.typoscript',
'EXT:tea/Tests/Functional/Controller/Fixtures/TypoScript/Rendering.typoscript',
],
]);
}

/**
* @test
*/
public function indexActionRendersAllAvailableTeas(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/Database/ContentElementTeaIndex.csv');
$this->importCSVDataSet(__DIR__ . '/Fixtures/Database/Teas.csv');

$request = new InternalRequest();
$request = $request->withPageId(1);

$html = $this->executeFrontendRequest($request)->getBody()->__toString();

self::assertStringContainsString('Godesberger Burgtee', $html);
self::assertStringContainsString('Oolong', $html);
}
}

0 comments on commit 555c43e

Please sign in to comment.