diff --git a/Classes/Domain/Model/Frontend/Offer.php b/Classes/Domain/Model/Frontend/Offer.php index e270b3f..19a93e5 100644 --- a/Classes/Domain/Model/Frontend/Offer.php +++ b/Classes/Domain/Model/Frontend/Offer.php @@ -23,6 +23,8 @@ declare(strict_types=1); namespace WerkraumMedia\ThueCat\Domain\Model\Frontend; +use TYPO3\CMS\Core\Utility\ArrayUtility; + class Offer { /** @@ -56,7 +58,8 @@ class Offer public static function createFromArray(array $rawData) { $prices = []; - foreach ($rawData['prices'] as $price) { + + foreach (ArrayUtility::sortArraysByKey($rawData['prices'], 'title') as $price) { $prices[] = Price::createFromArray($price); } diff --git a/Tests/Functional/Fixtures/Frontend/TouristAttractionWithPrices.xml b/Tests/Functional/Fixtures/Frontend/TouristAttractionWithPrices.xml new file mode 100644 index 0000000..6f8ca76 --- /dev/null +++ b/Tests/Functional/Fixtures/Frontend/TouristAttractionWithPrices.xml @@ -0,0 +1,10 @@ + + + + 1 + 3 + Attraktion mit Preisen + [{"prices":[{"currency":"EUR","description":"","price":8,"rule":"PerGroup","title":"Schulklassen"},{"currency":"EUR","description":"","price":8,"rule":"PerPerson","title":"Erwachsene"},{"currency":"EUR","description":"","price":5,"rule":"PerPerson","title":"Familienkarte B"},{"currency":"EUR","description":"","price":5,"rule":"PerPerson","title":"Familienkarte A"}],"description":"","title":"Führungen"}] + + + diff --git a/Tests/Functional/FrontendTest.php b/Tests/Functional/FrontendTest.php index 7067feb..406aaad 100644 --- a/Tests/Functional/FrontendTest.php +++ b/Tests/Functional/FrontendTest.php @@ -89,4 +89,37 @@ class FrontendTest extends FunctionalTestCase self::assertStringContainsString('8,00 EUR', (string)$result->getBody()); self::assertStringContainsString('pro Person', (string)$result->getBody()); } + + /** + * @test + */ + public function pricesAreSorted(): void + { + $this->importDataSet('EXT:thuecat/Tests/Functional/Fixtures/Frontend/TouristAttractionWithPrices.xml'); + + $request = new InternalRequest(); + $request = $request->withPageId(2); + + $result = $this->executeFrontendRequest($request); + + self::assertSame(200, $result->getStatusCode()); + + self::assertStringContainsString('Attraktion mit Preisen', (string)$result->getBody()); + + self::assertLessThan( + mb_strpos((string)$result->getBody(), 'Familienkarte A'), + mb_strpos((string)$result->getBody(), 'Erwachsene'), + '"Familienkarte A" is rendered before "Erwachsene"' + ); + self::assertLessThan( + mb_strpos((string)$result->getBody(), 'Familienkarte B'), + mb_strpos((string)$result->getBody(), 'Familienkarte A'), + '"Familienkarte B" is rendered before "Familienkarte A"' + ); + self::assertLessThan( + mb_strpos((string)$result->getBody(), 'Schulklassen'), + mb_strpos((string)$result->getBody(), 'Familienkarte B'), + '"Schulklassen" is rendered before "Familienkarte B"' + ); + } }