From b811ea1790e06d9ce4be09c027f5d8a4a82af011 Mon Sep 17 00:00:00 2001 From: Eike Starkmann Date: Wed, 31 Jul 2024 14:33:08 +0200 Subject: [PATCH 1/4] [TASK] Add functional tests for showAction Fixes #1228 --- .../Database/ContentElementTeaIndex.csv | 1 + .../Fixtures/Database/SiteStructure.csv | 1 + .../Controller/TeaControllerTest.php | 27 ++++++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Tests/Functional/Controller/Fixtures/Database/ContentElementTeaIndex.csv b/Tests/Functional/Controller/Fixtures/Database/ContentElementTeaIndex.csv index 0fe9c691..39af4b1b 100644 --- a/Tests/Functional/Controller/Fixtures/Database/ContentElementTeaIndex.csv +++ b/Tests/Functional/Controller/Fixtures/Database/ContentElementTeaIndex.csv @@ -1,3 +1,4 @@ "tt_content" ,"uid","pid","CType","header","list_type" ,1,1,"list","Tea index","tea_teaindex" +,2,3,"list","Tea show","tea_teashow" diff --git a/Tests/Functional/Controller/Fixtures/Database/SiteStructure.csv b/Tests/Functional/Controller/Fixtures/Database/SiteStructure.csv index f664e492..ce6f70ab 100644 --- a/Tests/Functional/Controller/Fixtures/Database/SiteStructure.csv +++ b/Tests/Functional/Controller/Fixtures/Database/SiteStructure.csv @@ -2,3 +2,4 @@ ,"uid","pid","title","slug" ,1,0,"Rootpage","/" ,2,1,"Storage","/storage" +,3,1,"Show","/show" diff --git a/Tests/Functional/Controller/TeaControllerTest.php b/Tests/Functional/Controller/TeaControllerTest.php index e4c1334a..3d006de7 100644 --- a/Tests/Functional/Controller/TeaControllerTest.php +++ b/Tests/Functional/Controller/TeaControllerTest.php @@ -4,6 +4,7 @@ namespace TTN\Tea\Tests\Functional\Controller; +use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; @@ -22,6 +23,14 @@ final class TeaControllerTest extends FunctionalTestCase protected function setUp(): void { + ArrayUtility::mergeRecursiveWithOverrule($this->configurationToUseInTestInstance, [ + 'FE' => [ + 'cacheHash' => [ + 'enforceValidation' => false, + ], + ] + ]); + parent::setUp(); $this->importCSVDataSet(__DIR__ . '/Fixtures/Database/SiteStructure.csv'); @@ -37,6 +46,8 @@ protected function setUp(): void 'EXT:tea/Tests/Functional/Controller/Fixtures/TypoScript/Setup/Rendering.typoscript', ], ]); + $this->importCSVDataSet(__DIR__ . '/Fixtures/Database/ContentElementTeaIndex.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/Database/Teas.csv'); } /** @@ -44,9 +55,6 @@ protected function setUp(): void */ public function indexActionRendersAllAvailableTeas(): void { - $this->importCSVDataSet(__DIR__ . '/Fixtures/Database/ContentElementTeaIndex.csv'); - $this->importCSVDataSet(__DIR__ . '/Fixtures/Database/Teas.csv'); - $request = (new InternalRequest())->withPageId(1); $html = (string)$this->executeFrontendSubRequest($request)->getBody(); @@ -54,4 +62,17 @@ public function indexActionRendersAllAvailableTeas(): void self::assertStringContainsString('Godesberger Burgtee', $html); self::assertStringContainsString('Oolong', $html); } + + /** + * @test + */ + public function showActionRendersTheGivenTeas(): void + { + $request = (new InternalRequest())->withPageId(1)->withQueryParameters(["tx_tea_teashow[tea]" => 1]); + + $html = (string)$this->executeFrontendSubRequest($request)->getBody(); + + self::assertStringContainsString('Godesberger Burgtee', $html); + self::assertStringNotContainsString('Oolong', $html); + } } From f455966bc1c0a08d4c9152f470851d2aaf570484 Mon Sep 17 00:00:00 2001 From: Eike Starkmann Date: Wed, 31 Jul 2024 19:38:49 +0200 Subject: [PATCH 2/4] [BUGFIX] Use single quotes Related: #1228 --- Tests/Functional/Controller/TeaControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Functional/Controller/TeaControllerTest.php b/Tests/Functional/Controller/TeaControllerTest.php index 3d006de7..fa8b87ed 100644 --- a/Tests/Functional/Controller/TeaControllerTest.php +++ b/Tests/Functional/Controller/TeaControllerTest.php @@ -68,7 +68,7 @@ public function indexActionRendersAllAvailableTeas(): void */ public function showActionRendersTheGivenTeas(): void { - $request = (new InternalRequest())->withPageId(1)->withQueryParameters(["tx_tea_teashow[tea]" => 1]); + $request = (new InternalRequest())->withPageId(1)->withQueryParameters(['tx_tea_teashow[tea]' => 1]); $html = (string)$this->executeFrontendSubRequest($request)->getBody(); From d4e930a3489416927e47a2baa5ebaebb93f4800f Mon Sep 17 00:00:00 2001 From: Eike Starkmann Date: Wed, 31 Jul 2024 19:55:03 +0200 Subject: [PATCH 3/4] [BUGFIX] Fix code style Related: #1228 --- Tests/Functional/Controller/TeaControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Functional/Controller/TeaControllerTest.php b/Tests/Functional/Controller/TeaControllerTest.php index fa8b87ed..0add1de5 100644 --- a/Tests/Functional/Controller/TeaControllerTest.php +++ b/Tests/Functional/Controller/TeaControllerTest.php @@ -28,7 +28,7 @@ protected function setUp(): void 'cacheHash' => [ 'enforceValidation' => false, ], - ] + ], ]); parent::setUp(); From fb28ba7edf88c083f35cd7511580d8fb4ae776b2 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 24 Dec 2024 11:06:07 +0100 Subject: [PATCH 4/4] Changes after review --- .../Controller/TeaControllerTest.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Tests/Functional/Controller/TeaControllerTest.php b/Tests/Functional/Controller/TeaControllerTest.php index 0add1de5..f55df849 100644 --- a/Tests/Functional/Controller/TeaControllerTest.php +++ b/Tests/Functional/Controller/TeaControllerTest.php @@ -4,7 +4,6 @@ namespace TTN\Tea\Tests\Functional\Controller; -use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; @@ -21,16 +20,16 @@ final class TeaControllerTest extends FunctionalTestCase 'typo3conf/ext/tea/Tests/Functional/Controller/Fixtures/Sites/' => 'typo3conf/sites', ]; - protected function setUp(): void - { - ArrayUtility::mergeRecursiveWithOverrule($this->configurationToUseInTestInstance, [ - 'FE' => [ - 'cacheHash' => [ - 'enforceValidation' => false, - ], + protected array $configurationToUseInTestInstance = [ + 'FE' => [ + 'cacheHash' => [ + 'enforceValidation' => false, ], - ]); + ], + ]; + protected function setUp(): void + { parent::setUp(); $this->importCSVDataSet(__DIR__ . '/Fixtures/Database/SiteStructure.csv'); @@ -68,7 +67,7 @@ public function indexActionRendersAllAvailableTeas(): void */ public function showActionRendersTheGivenTeas(): void { - $request = (new InternalRequest())->withPageId(1)->withQueryParameters(['tx_tea_teashow[tea]' => 1]); + $request = (new InternalRequest())->withPageId(3)->withQueryParameters(['tx_tea_teashow[tea]' => 1]); $html = (string)$this->executeFrontendSubRequest($request)->getBody();