22
33namespace App \Packages \Domains \Test ;
44
5+ use App \Models \Country ;
6+ use App \Models \WorldHeritage ;
57use App \Packages \Domains \WorldHeritageEntityCollection ;
8+ use Database \Seeders \CountrySeeder ;
9+ use Illuminate \Support \Facades \DB ;
610use Tests \TestCase ;
711use App \Packages \Domains \WorldHeritageEntity ;
812
@@ -11,14 +15,29 @@ class WorldHeritageEntityCollectionTest extends TestCase
1115 protected function setUp (): void
1216 {
1317 parent ::setUp ();
18+ $ this ->refresh ();
19+ $ seeder = new CountrySeeder ();
20+ $ seeder ->run ();
1421 }
1522
1623 protected function tearDown (): void
1724 {
25+ $ this ->refresh ();
1826 parent ::tearDown ();
1927 }
2028
21- private function arrayData (): array
29+ private function refresh (): void
30+ {
31+ if (env ('APP_ENV ' ) === 'testing ' ) {
32+ DB ::connection ('mysql ' )->statement ('SET FOREIGN_KEY_CHECKS=0; ' );
33+ WorldHeritage::truncate ();
34+ Country::truncate ();
35+ DB ::table ('site_state_parties ' )->truncate ();
36+ DB ::connection ('mysql ' )->statement ('SET FOREIGN_KEY_CHECKS=1; ' );
37+ }
38+ }
39+
40+ private static function arraySingleData (): array
2241 {
2342 return [
2443 [
@@ -29,7 +48,11 @@ private function arrayData(): array
2948 'name_jp ' => '古都奈良の文化財 ' ,
3049 'country ' => 'Japan ' ,
3150 'region ' => 'Asia ' ,
32- 'state_party ' => 'JP ' ,
51+ 'state_party ' => 'JP ' , // DB用(string)
52+ 'state_parties ' => ['JP ' ], // 配列
53+ 'state_parties_meta ' => [ // メタ
54+ 'JP ' => ['is_primary ' => true , 'inscription_year ' => 1998 ],
55+ ],
3356 'category ' => 'cultural ' ,
3457 'criteria ' => ['ii ' , 'iii ' , 'v ' ],
3558 'year_inscribed ' => 1998 ,
@@ -51,6 +74,10 @@ private function arrayData(): array
5174 'country ' => 'Japan ' ,
5275 'region ' => 'Asia ' ,
5376 'state_party ' => 'JP ' ,
77+ 'state_parties ' => ['JP ' ],
78+ 'state_parties_meta ' => [
79+ 'JP ' => ['is_primary ' => true , 'inscription_year ' => 2000 ],
80+ ],
5481 'category ' => 'natural ' ,
5582 'criteria ' => ['vii ' , 'viii ' ],
5683 'year_inscribed ' => 2000 ,
@@ -72,6 +99,10 @@ private function arrayData(): array
7299 'country ' => 'Japan ' ,
73100 'region ' => 'Asia ' ,
74101 'state_party ' => 'JP ' ,
102+ 'state_parties ' => ['JP ' ],
103+ 'state_parties_meta ' => [
104+ 'JP ' => ['is_primary ' => true , 'inscription_year ' => 1999 ],
105+ ],
75106 'category ' => 'cultural ' ,
76107 'criteria ' => ['ii ' , 'iii ' , 'v ' ],
77108 'year_inscribed ' => 1999 ,
@@ -87,6 +118,86 @@ private function arrayData(): array
87118 ];
88119 }
89120
121+ private static function arrayMultiData (): array
122+ {
123+ return [
124+ // 既存: ブナ林(ヨーロッパ各地)
125+ [
126+ 'unesco_id ' => 1133 ,
127+ 'official_name ' => "Ancient and Primeval Beech Forests of the Carpathians and Other Regions of Europe " ,
128+ 'name ' => "Ancient and Primeval Beech Forests " ,
129+ 'name_jp ' => null ,
130+ 'country ' => 'Slovakia ' , // 便宜上代表国(実際は汎欧州の連続資産)
131+ 'region ' => 'Europe ' ,
132+ 'category ' => 'natural ' ,
133+ 'criteria ' => ['ix ' ],
134+ 'state_party ' => null ,
135+ 'year_inscribed ' => 2007 ,
136+ 'area_hectares ' => 99947.81 ,
137+ 'buffer_zone_hectares ' => 296275.8 ,
138+ 'is_endangered ' => false ,
139+ 'latitude ' => 0.0 ,
140+ 'longitude ' => 0.0 ,
141+ 'short_description ' => 'Transnational serial property of European beech forests illustrating post-glacial expansion and ecological processes across Europe. ' ,
142+ 'image_url ' => '' ,
143+ 'unesco_site_url ' => 'https://whc.unesco.org/en/list/1133/ ' ,
144+ 'state_parties ' => [
145+ 'AL ' ,'AT ' ,'BE ' ,'BA ' ,'BG ' ,'HR ' ,'CZ ' ,'FR ' ,'DE ' ,'IT ' ,'MK ' ,'PL ' ,'RO ' ,'SK ' ,'SI ' ,'ES ' ,'CH ' ,'UA '
146+ ],
147+ 'state_parties_meta ' => [
148+ 'AL ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
149+ 'AT ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
150+ 'BE ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
151+ 'BA ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
152+ 'BG ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
153+ 'HR ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
154+ 'CZ ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
155+ 'FR ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
156+ 'DE ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
157+ 'IT ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
158+ 'MK ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
159+ 'PL ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
160+ 'RO ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
161+ 'SK ' => ['is_primary ' => true , 'inscription_year ' => 2007 ],
162+ 'SI ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
163+ 'ES ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
164+ 'CH ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
165+ 'UA ' => ['is_primary ' => false , 'inscription_year ' => 2007 ],
166+ ],
167+ ],
168+
169+ // 追加: シルクロード(長安–天山回廊)
170+ [
171+ 'unesco_id ' => 1442 ,
172+ 'official_name ' => "Silk Roads: the Routes Network of Chang'an-Tianshan Corridor " ,
173+ 'name ' => "Silk Roads: Chang'an–Tianshan Corridor " ,
174+ 'name_jp ' => 'シルクロード:長安-天山回廊の交易路網 ' ,
175+ 'country ' => 'China, Kazakhstan, Kyrgyzstan ' ,
176+ 'region ' => 'Asia ' ,
177+ 'category ' => 'cultural ' ,
178+ 'criteria ' => ['ii ' ,'iii ' ,'vi ' ],
179+ 'state_party ' => null ,
180+ 'year_inscribed ' => 2014 ,
181+ 'area_hectares ' => 0.0 ,
182+ 'buffer_zone_hectares ' => 0.0 ,
183+ 'is_endangered ' => false ,
184+ 'latitude ' => 0.0 ,
185+ 'longitude ' => 0.0 ,
186+ 'short_description ' => 'Transnational Silk Road corridor across China, Kazakhstan and Kyrgyzstan illustrating exchange of goods, ideas and beliefs. ' ,
187+ 'image_url ' => '' ,
188+ 'unesco_site_url ' => 'https://whc.unesco.org/en/list/1442/ ' ,
189+ 'state_parties ' => ['CN ' ,'KZ ' ,'KG ' ],
190+ 'state_parties_meta ' => [
191+ 'CN ' => ['is_primary ' => true , 'inscription_year ' => 2014 ],
192+ 'KZ ' => ['is_primary ' => false , 'inscription_year ' => 2014 ],
193+ 'KG ' => ['is_primary ' => false , 'inscription_year ' => 2014 ],
194+ ],
195+ ],
196+ ];
197+ }
198+
199+
200+
90201 public function test_collection_check_type (): void
91202 {
92203 $ collection = new WorldHeritageEntityCollection (
@@ -110,9 +221,11 @@ public function test_collection_check_type(): void
110221 $ data ['buffer_zone_hectares ' ] ?? null ,
111222 $ data ['short_description ' ] ?? null ,
112223 $ data ['image_url ' ] ?? null ,
113- $ data ['unesco_site_url ' ] ?? null
224+ $ data ['unesco_site_url ' ] ?? null ,
225+ $ data ['state_parties ' ] ?? [],
226+ $ data ['state_parties_meta ' ] ?? []
114227 );
115- }, $ this ->arrayData ())
228+ }, $ this ->arraySingleData ())
116229 );
117230
118231 $ this ->assertInstanceOf (WorldHeritageEntityCollection::class, $ collection );
@@ -147,11 +260,79 @@ public function test_collection_check_count_value(): void
147260 $ data ['buffer_zone_hectares ' ] ?? null ,
148261 $ data ['short_description ' ] ?? null ,
149262 $ data ['image_url ' ] ?? null ,
150- $ data ['unesco_site_url ' ] ?? null
263+ $ data ['unesco_site_url ' ] ?? null ,
264+ $ data ['state_parties ' ] ?? [],
265+ $ data ['state_parties_meta ' ] ?? []
151266 );
152- }, $ this ->arrayData ())
267+ }, $ this ->arraySingleData ())
153268 );
154269
155270 $ this ->assertCount (3 , $ collection ->getAllHeritages ());
156271 }
272+
273+ public function test_multi_collection_check_type (): void
274+ {
275+ $ collection = new WorldHeritageEntityCollection (
276+ array_map (function ($ data ) {
277+ return new WorldHeritageEntity (
278+ null , // IDは自動生成されるためnull
279+ $ data ['unesco_id ' ],
280+ $ data ['official_name ' ],
281+ $ data ['name ' ],
282+ $ data ['country ' ],
283+ $ data ['region ' ],
284+ $ data ['category ' ],
285+ $ data ['year_inscribed ' ],
286+ $ data ['latitude ' ] ?? null ,
287+ $ data ['longitude ' ] ?? null ,
288+ $ data ['is_endangered ' ] ?? false ,
289+ $ data ['name_jp ' ] ?? null ,
290+ $ data ['state_party ' ] ?? null ,
291+ $ data ['criteria ' ] ?? null ,
292+ $ data ['area_hectares ' ] ?? null ,
293+ $ data ['buffer_zone_hectares ' ] ?? null ,
294+ $ data ['short_description ' ] ?? null ,
295+ $ data ['image_url ' ] ?? null ,
296+ $ data ['unesco_site_url ' ] ?? null ,
297+ $ data ['state_parties ' ] ?? [],
298+ $ data ['state_parties_meta ' ] ?? []
299+ );
300+ }, self ::arrayMultiData ())
301+ );
302+
303+ $ this ->assertInstanceOf (WorldHeritageEntityCollection::class, $ collection );
304+ }
305+
306+ public function test_multi_collection_check_count_value (): void
307+ {
308+ $ collection = new WorldHeritageEntityCollection (
309+ array_map (function ($ data ) {
310+ return new WorldHeritageEntity (
311+ null ,
312+ $ data ['unesco_id ' ],
313+ $ data ['official_name ' ],
314+ $ data ['name ' ],
315+ $ data ['country ' ],
316+ $ data ['region ' ],
317+ $ data ['category ' ],
318+ $ data ['year_inscribed ' ],
319+ $ data ['latitude ' ] ?? null ,
320+ $ data ['longitude ' ] ?? null ,
321+ $ data ['is_endangered ' ] ?? false ,
322+ $ data ['name_jp ' ] ?? null ,
323+ $ data ['state_party ' ] ?? null ,
324+ $ data ['criteria ' ] ?? null ,
325+ $ data ['area_hectares ' ] ?? null ,
326+ $ data ['buffer_zone_hectares ' ] ?? null ,
327+ $ data ['short_description ' ] ?? null ,
328+ $ data ['image_url ' ] ?? null ,
329+ $ data ['unesco_site_url ' ] ?? null ,
330+ $ data ['state_parties ' ] ?? [],
331+ $ data ['state_parties_meta ' ] ?? []
332+ );
333+ }, self ::arrayMultiData ())
334+ );
335+
336+ $ this ->assertCount (2 , $ collection ->getAllHeritages ());
337+ }
157338}
0 commit comments