diff --git a/Classes/Domain/Model/Frontend/Place.php b/Classes/Domain/Model/Frontend/Place.php index c06b86f..00c1cac 100644 --- a/Classes/Domain/Model/Frontend/Place.php +++ b/Classes/Domain/Model/Frontend/Place.php @@ -113,6 +113,16 @@ abstract class Place extends Base return $this->parkingFacilityNearBy; } + public function getParkingFacilitiesNearBySortedByAlphabet(): array + { + $facilities = $this->parkingFacilityNearBy->toArray(); + usort($facilities, function (ParkingFacility $a, ParkingFacility $b) { + return $a->getTitle() <=> $b->getTitle(); + }); + + return $facilities; + } + public function getSanitation(): array { return GeneralUtility::trimExplode(',', $this->sanitation, true); diff --git a/Documentation/Changelog/1.3.0.rst b/Documentation/Changelog/1.3.0.rst index 7f5629f..de0df57 100644 --- a/Documentation/Changelog/1.3.0.rst +++ b/Documentation/Changelog/1.3.0.rst @@ -37,6 +37,9 @@ Features * Allow to hide parking facilities. +* Parking facilities can now be rendered sorted by alphabet. + Use new method ``getParkingFacilitiesNearBySortedByAlphabet()``. + Fixes ----- diff --git a/Tests/Unit/Domain/Model/Frontend/TouristAttractionTest.php b/Tests/Unit/Domain/Model/Frontend/TouristAttractionTest.php new file mode 100644 index 0000000..74b619f --- /dev/null +++ b/Tests/Unit/Domain/Model/Frontend/TouristAttractionTest.php @@ -0,0 +1,62 @@ + + * + * 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 WerkraumMedia\ThueCat\Tests\Unit\Domain\Model\Frontend; + +use TYPO3\CMS\Extbase\Persistence\ObjectStorage; +use WerkraumMedia\ThueCat\Domain\Model\Frontend\ParkingFacility; +use WerkraumMedia\ThueCat\Domain\Model\Frontend\TouristAttraction; +use PHPUnit\Framework\TestCase; + +/** + * @covers \WerkraumMedia\ThueCat\Domain\Model\Frontend\TouristAttraction + */ +class TouristAttractionTest extends TestCase +{ + /** + * @test + */ + public function returnsParkingFacilitiesNearBySorted(): void + { + $unsortedFacilities = new ObjectStorage(); + $unsortedFacilities->attach($this->parkingFacilityWithTitle('P+R Anlage Zoopark')); + $unsortedFacilities->attach($this->parkingFacilityWithTitle('Parkhaus Domplatz')); + $unsortedFacilities->attach($this->parkingFacilityWithTitle('007 Parking')); + + $subject = new TouristAttraction(); + $subject->_setProperty('parkingFacilityNearBy', $unsortedFacilities); + + $result = $subject->getParkingFacilitiesNearBySortedByAlphabet(); + self::assertSame('007 Parking', $result[0]->getTitle()); + self::assertSame('P+R Anlage Zoopark', $result[1]->getTitle()); + self::assertSame('Parkhaus Domplatz', $result[2]->getTitle()); + } + + private function parkingFacilityWithTitle(string $title): ParkingFacility + { + $facility = new ParkingFacility(); + $facility->_setProperty('title', $title); + + return $facility; + } +}