Skip to content

Commit 2eac368

Browse files
committed
feat: Application Layer changes to enable registration of multi-country World Heritage sites
1 parent 967c4aa commit 2eac368

4 files changed

Lines changed: 234 additions & 195 deletions

File tree

src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDto.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public function __construct(
2323
private readonly ?float $bufferZoneHectares = null,
2424
private readonly ?string $shortDescription = null,
2525
private readonly ?string $imageUrl = null,
26-
private readonly ?string $unescoSiteUrl = null
26+
private readonly ?string $unescoSiteUrl = null,
27+
private readonly array $statePartyCodes = [],
28+
private readonly array $statePartiesMeta = [],
2729
){}
2830

2931
public function getId(): int
@@ -121,6 +123,40 @@ public function getUnescoSiteUrl(): ?string
121123
return $this->unescoSiteUrl;
122124
}
123125

126+
public function getStatePartyCodes(): array
127+
{
128+
return $this->statePartyCodes ?: $this->getStatePartyCodesOrFallback();
129+
}
130+
131+
public function getStatePartiesMeta(): array
132+
{
133+
return $this->statePartiesMeta;
134+
}
135+
136+
public function getPrimaryStatePartyCode(): ?string
137+
{
138+
return $this->primaryStatePartyCode;
139+
}
140+
141+
public function isTransnational(): bool
142+
{
143+
return $this->isTransnational;
144+
}
145+
146+
public function getStatePartyCodesOrFallback(): array
147+
{
148+
if ($this->statePartyCodes)
149+
return $this->statePartyCodes;
150+
151+
if (!$this->stateParty)
152+
return [];
153+
154+
$parts = preg_split('/[;,\s]+/', strtoupper($this->stateParty));
155+
$codes = array_filter($parts, fn($country) => preg_match('/^[A-Z]{2}$/', $country));
156+
157+
return array_values(array_unique($codes));
158+
}
159+
124160
public function toArray(): array
125161
{
126162
return [
@@ -142,7 +178,11 @@ public function toArray(): array
142178
'buffer_zone_hectares' => $this->getBufferZoneHectares(),
143179
'short_description' => $this->getShortDescription(),
144180
'image_url' => $this->getImageUrl(),
145-
'unesco_site_url' => $this->getUnescoSiteUrl()
181+
'unesco_site_url' => $this->getUnescoSiteUrl(),
182+
'state_parties' => $this->getStatePartyCodes(),
183+
'state_parties_meta' => $this->getStatePartiesMeta(),
184+
'primary_state_party_code' => $this->getPrimaryStatePartyCode(),
185+
'is_transnational' => $this->isTransnational()
146186
];
147187
}
148188
}

src/app/Packages/Features/QueryUseCases/Tests/CreateWorldHeritageUseCaseTest.php

Lines changed: 17 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Packages\Features\QueryUseCases\Tests;
44

5+
use Database\Seeders\CountrySeeder;
56
use Illuminate\Support\Facades\DB;
67
use Mockery;
78
use Tests\TestCase;
@@ -10,15 +11,15 @@
1011
use App\Packages\Features\QueryUseCases\Dto\WorldHeritageDto;
1112
use App\Packages\Domains\WorldHeritageEntity;
1213
use App\Packages\Domains\WorldHeritageRepositoryInterface;
13-
use App\Packages\Features\QueryUseCases\Factory\WorldHeritageListQueryFactory;
14-
use App\Packages\Features\QueryUseCases\ListQuery\WorldHeritageListQuery;
1514

1615
class CreateWorldHeritageUseCaseTest extends TestCase
1716
{
1817
protected function setUp(): void
1918
{
2019
parent::setUp();
2120
$this->refresh();
21+
$seeder = new CountrySeeder();
22+
$seeder->run();
2223
}
2324

2425
protected function tearDown(): void
@@ -39,15 +40,16 @@ private function refresh(): void
3940
private function arrayData(): array
4041
{
4142
return [
43+
'id' => 1,
4244
'unesco_id' => '668',
4345
'official_name' => 'Historic Monuments of Ancient Nara',
4446
'name' => 'Historic Monuments of Ancient Nara',
4547
'name_jp' => '古都奈良の文化財',
4648
'country' => 'Japan',
4749
'region' => 'Asia',
48-
'state_party' => 'JP',
4950
'category' => 'cultural',
5051
'criteria' => ['ii', 'iii', 'v'],
52+
'state_party' => null,
5153
'year_inscribed' => 1998,
5254
'area_hectares' => 442.0,
5355
'buffer_zone_hectares' => 320.0,
@@ -57,92 +59,16 @@ private function arrayData(): array
5759
'short_description' => 'Temples and shrines of the first permanent capital of Japan.',
5860
'image_url' => '',
5961
'unesco_site_url' => 'https://whc.unesco.org/en/list/668/',
62+
'state_parties' => ['JP'],
63+
'state_parties_meta' => [
64+
'JP' => [
65+
'is_primary' => true,
66+
'inscription_year' => 1998,
67+
],
68+
],
6069
];
6170
}
6271

63-
private function mockEntity(): WorldHeritageEntity
64-
{
65-
$mock = Mockery::mock(WorldHeritageEntity::class);
66-
67-
$mock
68-
->shouldReceive('getId')
69-
->andReturn($this->arrayData()['id'] ?? null);
70-
71-
$mock
72-
->shouldReceive('getUnescoId')
73-
->andReturn($this->arrayData()['unesco_id']);
74-
75-
$mock
76-
->shouldReceive('getOfficialName')
77-
->andReturn($this->arrayData()['official_name']);
78-
79-
$mock
80-
->shouldReceive('getName')
81-
->andReturn($this->arrayData()['name']);
82-
83-
$mock
84-
->shouldReceive('getCountry')
85-
->andReturn($this->arrayData()['country']);
86-
87-
$mock
88-
->shouldReceive('getRegion')
89-
->andReturn($this->arrayData()['region']);
90-
91-
$mock
92-
->shouldReceive('getStateParty')
93-
->andReturn($this->arrayData()['state_party']);
94-
95-
$mock
96-
->shouldReceive('getCategory')
97-
->andReturn($this->arrayData()['category']);
98-
99-
$mock
100-
->shouldReceive('getCriteria')
101-
->andReturn($this->arrayData()['criteria']);
102-
103-
$mock
104-
->shouldReceive('getYearInscribed')
105-
->andReturn($this->arrayData()['year_inscribed']);
106-
107-
$mock
108-
->shouldReceive('getAreaHectares')
109-
->andReturn($this->arrayData()['area_hectares']);
110-
111-
$mock
112-
->shouldReceive('getBufferZoneHectares')
113-
->andReturn($this->arrayData()['buffer_zone_hectares']);
114-
115-
$mock
116-
->shouldReceive('getLatitude')
117-
->andReturn($this->arrayData()['latitude']);
118-
119-
$mock
120-
->shouldReceive('getLongitude')
121-
->andReturn($this->arrayData()['longitude']);
122-
123-
$mock
124-
->shouldReceive('isEndangered')
125-
->andReturn($this->arrayData()['is_endangered']);
126-
127-
$mock
128-
->shouldReceive('getNameJp')
129-
->andReturn($this->arrayData()['name_jp']);
130-
131-
$mock
132-
->shouldReceive('getShortDescription')
133-
->andReturn($this->arrayData()['short_description']);
134-
135-
$mock
136-
->shouldReceive('getImageUrl')
137-
->andReturn($this->arrayData()['image_url']);
138-
139-
$mock
140-
->shouldReceive('getUnescoSiteUrl')
141-
->andReturn($this->arrayData()['unesco_site_url']);
142-
143-
return $mock;
144-
}
145-
14672
private function mockRepository(): WorldHeritageRepositoryInterface
14773
{
14874
$mock = Mockery::mock(WorldHeritageRepositoryInterface::class);
@@ -170,101 +96,15 @@ private function mockRepository(): WorldHeritageRepositoryInterface
17096
bufferZoneHectares: $this->arrayData()['buffer_zone_hectares'],
17197
shortDescription: $this->arrayData()['short_description'],
17298
imageUrl: $this->arrayData()['image_url'],
173-
unescoSiteUrl: $this->arrayData()['unesco_site_url']
99+
unescoSiteUrl: $this->arrayData()['unesco_site_url'],
100+
statePartyCodes: $this->arrayData()['state_parties'],
101+
statePartyMeta: $this->arrayData()['state_parties_meta'] ?? []
174102
)
175103
);
176104

177105
return $mock;
178106
}
179107

180-
private function mockListQuery(): WorldHeritageListQuery
181-
{
182-
$factory = Mockery::mock(
183-
'alias:' . WorldHeritageListQueryFactory::class
184-
);
185-
186-
$mock = Mockery::mock(WorldHeritageListQuery::class);
187-
188-
$factory
189-
->shouldReceive('build')
190-
->with(Mockery::type($this->arrayData()))
191-
->andReturn($mock);
192-
193-
$mock
194-
->shouldReceive('getUnescoId')
195-
->andReturn($this->arrayData()['unesco_id']);
196-
197-
$mock
198-
->shouldReceive('getOfficialName')
199-
->andReturn($this->arrayData()['official_name']);
200-
201-
$mock
202-
->shouldReceive('getName')
203-
->andReturn($this->arrayData()['name']);
204-
205-
$mock
206-
->shouldReceive('getCountry')
207-
->andReturn($this->arrayData()['country']);
208-
209-
$mock
210-
->shouldReceive('getRegion')
211-
->andReturn($this->arrayData()['region']);
212-
213-
$mock
214-
->shouldReceive('getStateParty')
215-
->andReturn($this->arrayData()['state_party']);
216-
217-
$mock
218-
->shouldReceive('getCategory')
219-
->andReturn($this->arrayData()['category']);
220-
221-
$mock
222-
->shouldReceive('getCriteria')
223-
->andReturn($this->arrayData()['criteria']);
224-
225-
$mock
226-
->shouldReceive('getYearInscribed')
227-
->andReturn($this->arrayData()['year_inscribed']);
228-
229-
$mock
230-
->shouldReceive('getAreaHectares')
231-
->andReturn($this->arrayData()['area_hectares']);
232-
233-
$mock
234-
->shouldReceive('getBufferZoneHectares')
235-
->andReturn($this->arrayData()['buffer_zone_hectares']);
236-
237-
$mock
238-
->shouldReceive('getLatitude')
239-
->andReturn($this->arrayData()['latitude']);
240-
241-
$mock
242-
->shouldReceive('getLongitude')
243-
->andReturn($this->arrayData()['longitude']);
244-
245-
$mock
246-
->shouldReceive('isEndangered')
247-
->andReturn($this->arrayData()['is_endangered']);
248-
249-
$mock
250-
->shouldReceive('getNameJp')
251-
->andReturn($this->arrayData()['name_jp']);
252-
253-
$mock
254-
->shouldReceive('getShortDescription')
255-
->andReturn($this->arrayData()['short_description']);
256-
257-
$mock
258-
->shouldReceive('getImageUrl')
259-
->andReturn($this->arrayData()['image_url']);
260-
261-
$mock
262-
->shouldReceive('getUnescoSiteUrl')
263-
->andReturn($this->arrayData()['unesco_site_url']);
264-
265-
return $mock;
266-
}
267-
268108
public function test_use_case_check_type(): void
269109
{
270110
$useCase = new CreateWorldHeritageUseCase(
@@ -303,5 +143,7 @@ public function test_use_case_check_value(): void
303143
$this->assertEquals($this->arrayData()['short_description'], $result->getShortDescription());
304144
$this->assertEquals($this->arrayData()['image_url'], $result->getImageUrl());
305145
$this->assertEquals($this->arrayData()['unesco_site_url'], $result->getUnescoSiteUrl());
146+
$this->assertEquals($this->arrayData()['state_parties'], $result->getStatePartyCodes());
147+
$this->assertEquals($this->arrayData()['state_parties_meta'], $result->getStatePartiesMeta());
306148
}
307149
}

0 commit comments

Comments
 (0)