From 96a650c5aa58ab51c1e51273755106b861360b1a Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Fri, 9 Sep 2022 08:50:24 +0000 Subject: [PATCH] Do not fetch dates without available event --- Classes/Domain/Repository/DateRepository.php | 17 +++- Documentation/Changelog/2.6.3.rst | 33 +++++++ Tests/Functional/Frontend/DatesTest.php | 87 +++++++++++++++++++ ...rnsOnlyDatesWithAvailableEventByDemand.csv | 11 +++ Tests/Functional/Frontend/FilterTest.php | 2 +- .../Fixtures/Database/SiteStructure.csv | 4 + .../Fixtures/Database/SiteStructure.xml | 15 ---- ext_emconf.php | 2 +- 8 files changed, 150 insertions(+), 21 deletions(-) create mode 100644 Documentation/Changelog/2.6.3.rst create mode 100644 Tests/Functional/Frontend/DatesTest.php create mode 100644 Tests/Functional/Frontend/DatesTestFixtures/ReturnsOnlyDatesWithAvailableEventByDemand.csv create mode 100644 Tests/Functional/Frontend/Fixtures/Database/SiteStructure.csv delete mode 100644 Tests/Functional/Frontend/Fixtures/Database/SiteStructure.xml diff --git a/Classes/Domain/Repository/DateRepository.php b/Classes/Domain/Repository/DateRepository.php index 492895e..99b30da 100644 --- a/Classes/Domain/Repository/DateRepository.php +++ b/Classes/Domain/Repository/DateRepository.php @@ -44,7 +44,9 @@ class DateRepository extends Repository protected function createDemandQuery(DateDemand $demand): QueryInterface { $query = $this->createQuery(); - $constraints = []; + $constraints = [ + $this->createEventConstraint($query), + ]; $categoriesConstraint = $this->createCategoryConstraint($query, $demand); if ($categoriesConstraint instanceof ConstraintInterface) { @@ -122,9 +124,7 @@ class DateRepository extends Repository $query->setLimit((int) $demand->getLimit()); } - if (!empty($constraints)) { - $query->matching($query->logicalAnd($constraints)); - } + $query->matching($query->logicalAnd($constraints)); $query->setOrderings([$demand->getSortBy() => $demand->getSortOrder()]); @@ -233,4 +233,13 @@ class DateRepository extends Repository return $statement->execute()->fetchAll(); } + + private function createEventConstraint( + QueryInterface $query + ): ConstraintInterface { + return $query->logicalAnd( + // Use sub property to trigger join and pulling in event table constraints (hidden) + $query->logicalNot($query->equals('event.uid', null)) + ); + } } diff --git a/Documentation/Changelog/2.6.3.rst b/Documentation/Changelog/2.6.3.rst new file mode 100644 index 0000000..cafbd23 --- /dev/null +++ b/Documentation/Changelog/2.6.3.rst @@ -0,0 +1,33 @@ +2.6.3 +===== + +Breaking +-------- + +Nothing + +Features +-------- + +Nothing + +Fixes +----- + +* Do not fetch dates without available event + + As dates don't make sense without an available event. + The event provides necessary info like the title. + Events might be hidden within system, while dates are still available. + + Relates: #10075 + +Tasks +----- + +Nothing + +Deprecation +----------- + +Nothing diff --git a/Tests/Functional/Frontend/DatesTest.php b/Tests/Functional/Frontend/DatesTest.php new file mode 100644 index 0000000..789ba04 --- /dev/null +++ b/Tests/Functional/Frontend/DatesTest.php @@ -0,0 +1,87 @@ + + * + * 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. + */ + +namespace Wrm\Events\Tests\Functional\Frontend; + +use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; +use Wrm\Events\Frontend\Daest; + +/** + * @covers \Wrm\Events\Frontend\Daest + */ +class DatesTest extends FunctionalTestCase +{ + protected $testExtensionsToLoad = [ + 'typo3conf/ext/events', + ]; + + protected $coreExtensionsToLoad = [ + 'fluid_styled_content', + ]; + + protected $pathsToProvideInTestInstance = [ + 'typo3conf/ext/events/Tests/Functional/Frontend/Fixtures/Sites/' => 'typo3conf/sites', + ]; + + protected function setUp(): void + { + parent::setUp(); + + $this->importCSVDataSet(__DIR__ . '/Fixtures/Database/SiteStructure.csv'); + $this->setUpFrontendRootPage(1, [ + 'constants' => [ + 'EXT:events/Configuration/TypoScript/constants.typoscript', + ], + 'setup' => [ + 'EXT:fluid_styled_content/Configuration/TypoScript/setup.typoscript', + 'EXT:events/Configuration/TypoScript/setup.typoscript', + 'EXT:events/Tests/Functional/Frontend/Fixtures/TypoScript/Rendering.typoscript' + ], + ]); + } + + /** + * Covers issue https://redmine.werkraum-media.de/issues/10075. + * Editors can disable events. Dates will still be available. + * Dates don't make any sense without an event, as they not even have a name. + * + * They therefore should not be fetched from persistence. + * + * @test + */ + public function returnsOnlyDatesWithAvailableEventByDemand(): void + { + $this->importCSVDataSet(__DIR__ . '/DatesTestFixtures/ReturnsOnlyDatesWithAvailableEventByDemand.csv'); + + $request = new InternalRequest(); + $request = $request->withPageId(1); + $response = $this->executeFrontendRequest($request); + + self::assertSame(200, $response->getStatusCode()); + $html = (string) $response->getBody(); + + self::assertStringNotContainsString('Event 1 hidden', $html); + self::assertStringContainsString('Event 2 visible', $html); + } +} diff --git a/Tests/Functional/Frontend/DatesTestFixtures/ReturnsOnlyDatesWithAvailableEventByDemand.csv b/Tests/Functional/Frontend/DatesTestFixtures/ReturnsOnlyDatesWithAvailableEventByDemand.csv new file mode 100644 index 0000000..c6d98b9 --- /dev/null +++ b/Tests/Functional/Frontend/DatesTestFixtures/ReturnsOnlyDatesWithAvailableEventByDemand.csv @@ -0,0 +1,11 @@ +tt_content +,uid,pid,CType,list_type,header +,1,1,list,events_datelist,All Dates +tx_events_domain_model_event +,uid,pid,title,hidden +,1,2,Event 1 hidden,1 +,2,2,Event 2 visible,0 +tx_events_domain_model_date +,uid,pid,event,start,end +,1,2,1,1662458400,1662469200 +,2,2,2,1662458400,1662469200 diff --git a/Tests/Functional/Frontend/FilterTest.php b/Tests/Functional/Frontend/FilterTest.php index 397edf1..fcad57d 100644 --- a/Tests/Functional/Frontend/FilterTest.php +++ b/Tests/Functional/Frontend/FilterTest.php @@ -29,7 +29,7 @@ class FilterTest extends FunctionalTestCase { parent::setUp(); - $this->importDataSet('EXT:events/Tests/Functional/Frontend/Fixtures/Database/SiteStructure.xml'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/Database/SiteStructure.csv'); $this->setUpFrontendRootPage(1, [ 'constants' => [ 'EXT:events/Configuration/TypoScript/constants.typoscript', diff --git a/Tests/Functional/Frontend/Fixtures/Database/SiteStructure.csv b/Tests/Functional/Frontend/Fixtures/Database/SiteStructure.csv new file mode 100644 index 0000000..ab41e76 --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/Database/SiteStructure.csv @@ -0,0 +1,4 @@ +pages +,uid,pid,title,slug +,1,0,Page 1,/ +,2,1,Storage,/storage diff --git a/Tests/Functional/Frontend/Fixtures/Database/SiteStructure.xml b/Tests/Functional/Frontend/Fixtures/Database/SiteStructure.xml deleted file mode 100644 index e395656..0000000 --- a/Tests/Functional/Frontend/Fixtures/Database/SiteStructure.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - 0 - 1 - Page 1 - / - - - 1 - 2 - Storage - /storage - - diff --git a/ext_emconf.php b/ext_emconf.php index 2b15ee8..f32f6a4 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -9,7 +9,7 @@ $EM_CONF['events'] = [ 'state' => 'alpha', 'createDirs' => '', 'clearCacheOnLoad' => 0, - 'version' => '2.6.2', + 'version' => '2.6.3', 'constraints' => [ 'depends' => [ 'typo3' => '10.4.00-11.5.99',