1212use Illuminate \Support \Facades \DB ;
1313use Tests \TestCase ;
1414use App \Models \Image ;
15- use App \Packages \Domains \Ports \SignedUrlPort ;
16- use Mockery ;
1715
1816class WorldHeritageQueryService_getByIdTest extends TestCase
1917{
@@ -55,51 +53,74 @@ private function refresh(): void
5553 }
5654 }
5755
58- private function arrayData (): array
56+ private function seedImages (): void
5957 {
60- return
58+ DB ::table ('world_heritage_site_images ' )->insert ([
59+ [
60+ 'world_heritage_site_id ' => 1133 ,
61+ 'url ' => 'https://example.com/image1.jpg ' ,
62+ 'url_hash ' => hash ('sha256 ' , 'https://example.com/image1.jpg ' ),
63+ 'sort_order ' => 0 ,
64+ 'is_primary ' => true ,
65+ 'created_at ' => now (),
66+ 'updated_at ' => now (),
67+ ],
6168 [
62- 'id ' => 1133 ,
63- 'official_name ' => "Ancient and Primeval Beech Forests of the Carpathians and Other Regions of Europe " ,
64- 'name ' => "Ancient and Primeval Beech Forests " ,
65- 'heritage_name_jp ' => "カルパティア山脈とヨーロッパ各地の古代及び原生ブナ林 " ,
66- 'country ' => 'Slovakia ' ,
67- 'study_region ' => 'Europe ' ,
68- 'category ' => 'Natural ' ,
69- 'criteria ' => ['ix ' ],
70- 'state_party ' => null ,
71- 'year_inscribed ' => 2007 ,
72- 'area_hectares ' => 99947.81 ,
73- 'buffer_zone_hectares ' => 296275.8 ,
74- 'is_endangered ' => false ,
75- 'latitude ' => 0.0 ,
76- 'longitude ' => 0.0 ,
77- 'short_description ' => '氷期後のブナの自然拡散史を示すヨーロッパ各地の原生的ブナ林群から成る越境・連続資産。 ' ,
78- 'unesco_site_url ' => 'https://whc.unesco.org/en/list/1133 ' ,
79- 'state_parties_codes ' => [
80- 'ALB ' ,'AUT ' ,'BEL ' ,'BIH ' ,'BGR ' ,'HRV ' ,'CZE ' ,'FRA ' ,'DEU ' ,'ITA ' ,'MKD ' ,'POL ' ,'ROU ' ,'SVK ' ,'SVN ' ,'ESP ' ,'CHE ' ,'UKR '
81- ],
82- 'state_parties_meta ' => [
83- 'ALB ' => ['is_primary ' => false ],
84- 'AUT ' => ['is_primary ' => false ],
85- 'BEL ' => ['is_primary ' => false ],
86- 'BIH ' => ['is_primary ' => false ],
87- 'BGR ' => ['is_primary ' => false ],
88- 'HRV ' => ['is_primary ' => false ],
89- 'CZE ' => ['is_primary ' => false ],
90- 'FRA ' => ['is_primary ' => false ],
91- 'DEU ' => ['is_primary ' => false ],
92- 'ITA ' => ['is_primary ' => false ],
93- 'MKD ' => ['is_primary ' => false ],
94- 'POL ' => ['is_primary ' => false ],
95- 'ROU ' => ['is_primary ' => false ],
96- 'SVK ' => ['is_primary ' => true ],
97- 'SVN ' => ['is_primary ' => false ],
98- 'ESP ' => ['is_primary ' => false ],
99- 'CHE ' => ['is_primary ' => false ],
100- 'UKR ' => ['is_primary ' => false ],
101- ]
102- ];
69+ 'world_heritage_site_id ' => 1133 ,
70+ 'url ' => 'https://example.com/image2.jpg ' ,
71+ 'url_hash ' => hash ('sha256 ' , 'https://example.com/image2.jpg ' ),
72+ 'sort_order ' => 1 ,
73+ 'is_primary ' => false ,
74+ 'created_at ' => now (),
75+ 'updated_at ' => now (),
76+ ],
77+ ]);
78+ }
79+
80+ private function arrayData (): array
81+ {
82+ return [
83+ 'id ' => 1133 ,
84+ 'official_name ' => "Ancient and Primeval Beech Forests of the Carpathians and Other Regions of Europe " ,
85+ 'name ' => "Ancient and Primeval Beech Forests " ,
86+ 'heritage_name_jp ' => "カルパティア山脈とヨーロッパ各地の古代及び原生ブナ林 " ,
87+ 'country ' => 'Slovakia ' ,
88+ 'study_region ' => 'Europe ' ,
89+ 'category ' => 'Natural ' ,
90+ 'criteria ' => ['ix ' ],
91+ 'state_party ' => null ,
92+ 'year_inscribed ' => 2007 ,
93+ 'area_hectares ' => 99947.81 ,
94+ 'buffer_zone_hectares ' => 296275.8 ,
95+ 'is_endangered ' => false ,
96+ 'latitude ' => 0.0 ,
97+ 'longitude ' => 0.0 ,
98+ 'short_description ' => '氷期後のブナの自然拡散史を示すヨーロッパ各地の原生的ブナ林群から成る越境・連続資産。 ' ,
99+ 'unesco_site_url ' => 'https://whc.unesco.org/en/list/1133 ' ,
100+ 'state_parties_codes ' => [
101+ 'ALB ' ,'AUT ' ,'BEL ' ,'BIH ' ,'BGR ' ,'HRV ' ,'CZE ' ,'FRA ' ,'DEU ' ,'ITA ' ,'MKD ' ,'POL ' ,'ROU ' ,'SVK ' ,'SVN ' ,'ESP ' ,'CHE ' ,'UKR '
102+ ],
103+ 'state_parties_meta ' => [
104+ 'ALB ' => ['is_primary ' => false ],
105+ 'AUT ' => ['is_primary ' => false ],
106+ 'BEL ' => ['is_primary ' => false ],
107+ 'BIH ' => ['is_primary ' => false ],
108+ 'BGR ' => ['is_primary ' => false ],
109+ 'HRV ' => ['is_primary ' => false ],
110+ 'CZE ' => ['is_primary ' => false ],
111+ 'FRA ' => ['is_primary ' => false ],
112+ 'DEU ' => ['is_primary ' => false ],
113+ 'ITA ' => ['is_primary ' => false ],
114+ 'MKD ' => ['is_primary ' => false ],
115+ 'POL ' => ['is_primary ' => false ],
116+ 'ROU ' => ['is_primary ' => false ],
117+ 'SVK ' => ['is_primary ' => true ],
118+ 'SVN ' => ['is_primary ' => false ],
119+ 'ESP ' => ['is_primary ' => false ],
120+ 'CHE ' => ['is_primary ' => false ],
121+ 'UKR ' => ['is_primary ' => false ],
122+ ]
123+ ];
103124 }
104125
105126 public function test_queryService_check (): void
@@ -163,13 +184,39 @@ public function test_check_data_value(): void
163184 $ this ->assertEquals ($ this ->arrayData ()['unesco_site_url ' ], $ result ->getUnescoSiteUrl ());
164185 $ this ->assertEquals ($ expectedCodes , $ result ->getStatePartyCodes ());
165186 $ this ->assertEquals ($ orderedExpected , $ result ->getStatePartiesMeta ());
166- foreach ($ result ->getImages () as $ img ) {
187+ }
188+
189+ public function test_images_contract (): void
190+ {
191+ $ result = $ this ->queryService ->getHeritageById ($ this ->arrayData ()['id ' ]);
192+ $ images = $ result ->getImages ();
193+
194+ $ this ->assertIsArray ($ images );
195+ $ this ->assertNotEmpty ($ images );
196+ $ this ->assertTrue ($ images [0 ]['is_primary ' ]);
197+ $ this ->assertEquals (0 , $ images [0 ]['sort_order ' ]);
198+ $ this ->assertFalse ($ images [1 ]['is_primary ' ]);
199+ $ this ->assertEquals (1 , $ images [1 ]['sort_order ' ]);
200+
201+ foreach ($ images as $ img ) {
167202 $ this ->assertArrayHasKey ('id ' , $ img );
168203 $ this ->assertArrayHasKey ('url ' , $ img );
169204 $ this ->assertArrayHasKey ('sort_order ' , $ img );
170205 $ this ->assertArrayHasKey ('is_primary ' , $ img );
171206 $ this ->assertIsBool ($ img ['is_primary ' ]);
172- $ this ->assertNotEmpty ($ img ['url ' ]);
173207 }
174208 }
209+
210+ public function test_images_empty_when_no_images (): void
211+ {
212+ DB ::table ('world_heritage_site_images ' )
213+ ->where ('world_heritage_site_id ' , 1133 )
214+ ->delete ();
215+
216+
217+ $ result = $ this ->queryService ->getHeritageById (1133 );
218+
219+ $ this ->assertIsArray ($ result ->getImages ());
220+ $ this ->assertEmpty ($ result ->getImages ());
221+ }
175222}
0 commit comments