From 2abc84d1aef65b7426f7e5762b2eb689a471f491 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 12 Jul 2022 09:50:34 +0200 Subject: [PATCH] Get rid of legacy region property within demand Only use new way but provide compatibility. --- Classes/Domain/Model/Dto/DateDemand.php | 15 ++-------- .../Domain/Model/Dto/DateDemandFactory.php | 3 +- .../Unit/Domain/Model/Dto/DateDemandTest.php | 29 +++++++++++++++++++ 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/Classes/Domain/Model/Dto/DateDemand.php b/Classes/Domain/Model/Dto/DateDemand.php index 56d076e..296fd27 100644 --- a/Classes/Domain/Model/Dto/DateDemand.php +++ b/Classes/Domain/Model/Dto/DateDemand.php @@ -41,12 +41,6 @@ class DateDemand */ protected $categoryCombination = ''; - /** - * @var string - * Legacy, superceeded by regions which allows multi select / filter. - */ - protected $region = ''; - /** * @var int[] */ @@ -109,7 +103,7 @@ class DateDemand $instance->setSearchword($submittedValues['searchword'] ?? ''); $instance->setSynonyms($settings['synonyms'] ?? []); - $instance->setRegion($submittedValues['region'] ?? ''); + $instance->setRegions(GeneralUtility::intExplode(',', $submittedValues['region'] ?? '', true)); if (isset($submittedValues['regions']) && is_array($submittedValues['regions'])) { $instance->setRegions($submittedValues['regions']); } @@ -231,12 +225,7 @@ class DateDemand public function getRegion(): string { - return $this->region; - } - - public function setRegion(string $region): void - { - $this->region = $region; + return implode(',', $this->regions); } /** diff --git a/Classes/Domain/Model/Dto/DateDemandFactory.php b/Classes/Domain/Model/Dto/DateDemandFactory.php index 7435cdc..7323dec 100644 --- a/Classes/Domain/Model/Dto/DateDemandFactory.php +++ b/Classes/Domain/Model/Dto/DateDemandFactory.php @@ -22,6 +22,7 @@ namespace Wrm\Events\Domain\Model\Dto; */ use TYPO3\CMS\Core\TypoScript\TypoScriptService; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; class DateDemandFactory @@ -59,7 +60,7 @@ class DateDemandFactory } } - $demand->setRegion((string)$settings['region']); + $demand->setRegions(GeneralUtility::intExplode(',', (string)$settings['region'], true)); $demand->setCategories((string)$settings['categories']); $categoryCombination = (int)$settings['categoryCombination'] === 1 ? 'or' : 'and'; $demand->setCategoryCombination($categoryCombination); diff --git a/Tests/Unit/Domain/Model/Dto/DateDemandTest.php b/Tests/Unit/Domain/Model/Dto/DateDemandTest.php index ff9ddcc..a4aefd5 100644 --- a/Tests/Unit/Domain/Model/Dto/DateDemandTest.php +++ b/Tests/Unit/Domain/Model/Dto/DateDemandTest.php @@ -126,6 +126,31 @@ class DateDemandTest extends TestCase ); } + /** + * @test + */ + public function regionIsSetByRequest(): void + { + $result = DateDemand::createFromRequestValues( + [ + 'region' => '10', + ], + [ + ] + ); + + self::assertSame( + [ + 10, + ], + $result->getRegions() + ); + self::assertSame( + '10', + $result->getRegion() + ); + } + /** * @test */ @@ -148,6 +173,10 @@ class DateDemandTest extends TestCase ], $result->getRegions() ); + self::assertSame( + '10,20', + $result->getRegion() + ); } /**