@@ -23,16 +23,26 @@ public function test_image_import_url() {
23
23
$ try_save_featured_image ->setAccessible ( true );
24
24
25
25
// Check that NON-IMAGE URL returns invalid
26
- $ import_errors = array ();
27
26
$ import_info = array ();
28
- $ arguments = array ( 'a random string ' , 0 , 'Post Title ' , & $ import_errors , & $ import_info , array () );
27
+ $ arguments = array ( 'a random string ' , 0 , 'Post Title ' , $ import_info , array () );
29
28
$ response = $ try_save_featured_image ->invokeArgs ( $ feedzy , $ arguments );
30
29
31
30
$ this ->assertFalse ( $ response );
32
31
33
- $ this ->assertTrue ( count ( $ import_errors ) > 0 );
34
- $ this ->assertEquals ( 'Invalid Featured Image URL: a random string ' , $ import_errors [0 ] );
35
-
32
+ // Check that error was logged for invalid URL
33
+ $ logger = Feedzy_Rss_Feeds_Log::get_instance ();
34
+ $ recent_logs = $ logger ->get_recent_logs ( 5 , 'ERROR ' );
35
+ $ this ->assertNotEmpty ( $ recent_logs );
36
+
37
+ // Find the error log for invalid image URL
38
+ $ found_error = false ;
39
+ foreach ( $ recent_logs as $ log ) {
40
+ if ( strpos ( $ log ['message ' ], 'Invalid image URL ' ) !== false && strpos ( $ log ['message ' ], 'a random string ' ) !== false ) {
41
+ $ found_error = true ;
42
+ break ;
43
+ }
44
+ }
45
+ $ this ->assertTrue ( $ found_error , 'Expected error log for invalid image URL not found ' );
36
46
37
47
// For the next test, we will use a valid URL, but the image does not exist. We will check that the error is logged and is the expected one.
38
48
add_filter ( 'themeisle_log_event ' , function ( $ product , $ message , $ type , $ file , $ line ) {
@@ -41,23 +51,19 @@ public function test_image_import_url() {
41
51
}
42
52
}, 10 , 5 );
43
53
44
- $ import_errors = array ();
45
54
$ import_info = array ();
46
- $ arguments = array ( 'https://example.com/path_to_image/image.jpeg ' , 0 , 'Post Title ' , & $ import_errors , & $ import_info , array () );
55
+ $ arguments = array ( 'https://example.com/path_to_image/image.jpeg ' , 0 , 'Post Title ' , $ import_info , array () );
47
56
$ response = $ try_save_featured_image ->invokeArgs ( $ feedzy , $ arguments );
48
57
49
- // expected response is false because the image does not exist, but the URL is valid so no $import_errors should be set.
58
+ // expected response is false because the image does not exist, but the URL is valid so no errors should be logged for URL validation
50
59
$ this ->assertFalse ( $ response );
51
- $ this ->assertTrue ( empty ( $ import_errors ) );
52
60
53
- $ import_errors = array ();
54
61
$ import_info = array ();
55
- $ arguments = array ( 'https://example.com/path_to_image/image w space in name.jpeg ' , 0 , 'Post Title ' , & $ import_errors , & $ import_info , array () );
62
+ $ arguments = array ( 'https://example.com/path_to_image/image w space in name.jpeg ' , 0 , 'Post Title ' , $ import_info , array () );
56
63
$ response = $ try_save_featured_image ->invokeArgs ( $ feedzy , $ arguments );
57
64
58
- // expected response is false because the image does not exist, but the URL is valid so no $import_errors should be set.
65
+ // expected response is false because the image does not exist, but the URL is valid so no errors should be logged for URL validation
59
66
$ this ->assertFalse ( $ response );
60
- $ this ->assertTrue ( empty ( $ import_errors ) );
61
67
}
62
68
63
69
public function test_import_image_special_characters () {
0 commit comments