@@ -39,6 +39,11 @@ class BlcDashboardImagesPageTest extends TestCase
3939 */
4040 public array $ wpdbGetResultsQueries = [];
4141
42+ /**
43+ * @var array<int, array<string, mixed>>
44+ */
45+ public array $ wpdbResults = [];
46+
4247 protected function setUp (): void
4348 {
4449 parent ::setUp ();
@@ -68,7 +73,7 @@ protected function setUp(): void
6873 $ this ->wpdbPrepareCalls = [];
6974 $ this ->wpdbGetVarQueries = [];
7075 $ this ->wpdbGetResultsQueries = [];
71-
76+ $ this -> wpdbResults = [];
7277 $ GLOBALS ['wpdb ' ] = new class ($ this ) {
7378 /** @var string */
7479 public $ prefix = 'wp_ ' ;
@@ -98,7 +103,7 @@ public function get_results($query, $output = ARRAY_A)
98103 {
99104 $ this ->test_case ->wpdbGetResultsQueries [] = $ query ;
100105
101- return [] ;
106+ return $ this -> test_case -> getWpdbResults () ;
102107 }
103108 };
104109
@@ -123,8 +128,21 @@ public function get_results($query, $output = ARRAY_A)
123128 Functions \when ('number_format_i18n ' )->alias (static function ($ number , $ decimals = 0 ) {
124129 return number_format ((float ) $ number , (int ) $ decimals );
125130 });
131+ Functions \when ('wp_date ' )->alias (static function ($ format , $ timestamp = null , $ timezone = null ) {
132+ $ timestamp = $ timestamp ?? time ();
133+
134+ if ($ timezone instanceof \DateTimeZone) {
135+ $ date = new \DateTimeImmutable ('@ ' . (int ) $ timestamp );
136+ $ date = $ date ->setTimezone ($ timezone );
137+
138+ return $ date ->format ($ format );
139+ }
140+
141+ return gmdate ($ format , (int ) $ timestamp );
142+ });
126143
127144 require_once __DIR__ . '/../liens-morts-detector-jlg/includes/blc-admin-pages.php ' ;
145+ require_once __DIR__ . '/../liens-morts-detector-jlg/includes/class-blc-images-list-table.php ' ;
128146 }
129147
130148 protected function tearDown (): void
@@ -208,6 +226,44 @@ public function test_manual_image_check_shows_error_when_manual_trigger_fails():
208226 $ this ->assertStringContainsString ("Le déclenchement immédiat du cron a échoué " , $ output );
209227 }
210228
229+ public function test_dashboard_images_page_displays_thumbnail_preview_when_available (): void
230+ {
231+ Functions \when ('attachment_url_to_postid ' )->alias (static function ($ url ) {
232+ return 321 ;
233+ });
234+ Functions \when ('wp_get_attachment_image ' )->alias (static function ($ attachment_id , $ size = 'thumbnail ' , $ icon = false , $ attr = array ()) {
235+ $ attributes = '' ;
236+
237+ if (is_array ($ attr )) {
238+ foreach ($ attr as $ name => $ value ) {
239+ $ name = is_string ($ name ) ? $ name : (string ) $ name ;
240+ $ value = is_scalar ($ value ) ? (string ) $ value : '' ;
241+ $ attributes .= sprintf (' %s="%s" ' , esc_attr ($ name ), esc_attr ($ value ));
242+ }
243+ }
244+
245+ return sprintf ('<img src="https://example.com/uploads/thumb-%d.jpg"%s /> ' , (int ) $ attachment_id , $ attributes );
246+ });
247+ $ list_table = new \BLC_Images_List_Table ();
248+ $ reflection = new \ReflectionMethod (\BLC_Images_List_Table::class, 'column_image_details ' );
249+ $ reflection ->setAccessible (true );
250+
251+ $ item = [
252+ 'url ' => 'https://example.com/uploads/broken-image.jpg ' ,
253+ 'anchor ' => 'broken-image.jpg ' ,
254+ 'post_id ' => 42 ,
255+ 'post_title ' => 'Sample Post ' ,
256+ 'http_status ' => 404 ,
257+ 'last_checked_at ' => '2024-01-10 12:34:56 ' ,
258+ ];
259+
260+ $ output = (string ) $ reflection ->invoke ($ list_table , $ item );
261+
262+ $ this ->assertStringContainsString ('class="blc-image-preview" ' , $ output );
263+ $ this ->assertStringContainsString ('<img src="https://example.com/uploads/thumb-321.jpg" ' , $ output );
264+ $ this ->assertStringContainsString ('aria-hidden="false" ' , $ output );
265+ }
266+
211267 public function test_dashboard_images_page_handles_empty_dataset_row_types (): void
212268 {
213269 $ registered_filters = [];
@@ -275,6 +331,14 @@ public function test_dashboard_images_page_handles_empty_dataset_row_types(): vo
275331 $ this ->assertStringContainsString ('Jamais ' , $ output );
276332 }
277333
334+ /**
335+ * @return array<int, array<string, mixed>>
336+ */
337+ public function getWpdbResults (): array
338+ {
339+ return $ this ->wpdbResults ;
340+ }
341+
278342 /**
279343 * @param string $name
280344 * @param mixed $default
0 commit comments