Provide method to get parking facilities sorted by alphabet (#95)

Relates: #10230
This commit is contained in:
Daniel Siepmann 2022-12-12 13:35:16 +01:00 committed by GitHub
parent 49fcf40bc8
commit f194220153
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 0 deletions

View file

@ -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);

View file

@ -37,6 +37,9 @@ Features
* Allow to hide parking facilities.
* Parking facilities can now be rendered sorted by alphabet.
Use new method ``getParkingFacilitiesNearBySortedByAlphabet()``.
Fixes
-----

View file

@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
/*
* Copyright (C) 2022 Daniel Siepmann <coding@daniel-siepmann.de>
*
* 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;
}
}