@@ -63,6 +63,52 @@ public function test_feedzy_retrieve_image_with_enclosure_image() {
6363 $ this ->assertEquals ('https://example.com/image.jpg ' , $ result );
6464 }
6565
66+ /**
67+ * Test feedzy_retrieve_image method with enclosure containing image which has query parameters.
68+ */
69+ public function test_feedzy_retrieve_image_with_enclosure_image_and_query_params () {
70+ // Create a SimplePie feed with test data
71+ $ feed = new SimplePie ();
72+ // Reference: https://heavy.com/author/jgbuck/feed/
73+ $ feed ->set_raw_data ('<?xml version="1.0" encoding="UTF-8"?>
74+ <rss version="2.0"
75+ xmlns:content="http://purl.org/rss/1.0/modules/content/"
76+ xmlns:wfw="http://wellformedweb.org/CommentAPI/"
77+ xmlns:dc="http://purl.org/dc/elements/1.1/"
78+ xmlns:atom="http://www.w3.org/2005/Atom"
79+ xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
80+ xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
81+
82+ xmlns:georss="http://www.georss.org/georss"
83+ xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
84+ xmlns:media="http://search.yahoo.com/mrss/"
85+ >
86+ <channel>
87+ <title>Test Feed</title>
88+ <item>
89+ <title>Test Item</title>
90+ <media:thumbnail url="https://heavy.com/wp-content/uploads/2025/05/GettyImages-2172500144.jpg?quality=65&strip=all" />
91+ <media:content url="https://heavy.com/wp-content/uploads/2025/05/GettyImages-2172500144.jpg?quality=65&strip=all" medium="image" type="image/*">
92+ <media:title type="html">Houston Texans head coach DeMeco Ryans reacts before a game against the Chicago Bears.</media:title>
93+
94+ <media:credit>Getty</media:credit>
95+ </media:content>
96+ </item>
97+ </channel>
98+ </rss> ' );
99+ $ feed ->init ();
100+
101+ $ items = $ feed ->get_items ();
102+
103+ // Check if we have items before accessing
104+ $ this ->assertNotEmpty ($ items , 'No items found in feed ' );
105+ $ item = $ items [0 ];
106+
107+ $ result = $ this ->feedzy_abstract ->feedzy_retrieve_image ($ item );
108+
109+ $ this ->assertEquals ('https://heavy.com/wp-content/uploads/2025/05/GettyImages-2172500144.jpg?quality=65&strip=all ' , $ result );
110+ }
111+
66112 /**
67113 * Test feedzy_retrieve_image method with iTunes podcast image.
68114 */
@@ -506,4 +552,76 @@ public function test_extract_image_from_enclosure_with_media_thumbnail() {
506552 $ this ->assertEquals ('https://example.com/thumb.jpg ' , $ result );
507553 }
508554 }
555+
556+ /**
557+ * Test feedzy_image_encode method with regular image URLs.
558+ */
559+ public function test_feedzy_image_encode_regular_urls () {
560+ $ test_cases = array (
561+ // [input, expected]
562+ ['https://example.com/image.jpg ' , 'https://example.com/image.jpg ' ],
563+ ['https://example.com/simple-image.png ' , 'https://example.com/simple-image.png ' ],
564+ ['not-a-valid-url ' , 'http://not-a-valid-url ' ], // esc_url adds http://
565+ ['' , '' ] // Empty URL
566+ );
567+
568+ foreach ($ test_cases as [$ input , $ expected ]) {
569+ $ result = $ this ->feedzy_abstract ->feedzy_image_encode ($ input );
570+ $ this ->assertEquals ($ expected , $ result , "Failed for URL: $ input " );
571+ }
572+ }
573+
574+ /**
575+ * Test feedzy_image_encode method with query parameter extraction.
576+ */
577+ public function test_feedzy_image_encode_query_parameter_extraction () {
578+ $ test_cases = array (
579+ // [input_url, expected_result]
580+ ['https://example.com/proxy?url=https://cdn.example.com/image.jpg&width=300 ' , 'https://cdn.example.com/image.jpg ' ],
581+ ['https://proxy.example.com/image?src=https://secure.example.com/photo.png ' , 'https://secure.example.com/photo.png ' ],
582+ ['https://example.com/proxy?url=http://legacy.example.com/photo.gif ' , 'http://legacy.example.com/photo.gif ' ],
583+ ['https://example.com/proxy?callback=jsonp&url=https://cdn.example.com/uploads/2023/image.jpg&format=json ' , 'https://cdn.example.com/uploads/2023/image.jpg ' ],
584+ );
585+
586+ foreach ($ test_cases as [$ input , $ expected ]) {
587+ $ result = $ this ->feedzy_abstract ->feedzy_image_encode ($ input );
588+ $ this ->assertEquals ($ expected , $ result , "Failed for input: $ input " );
589+ }
590+ }
591+
592+ /**
593+ * Test feedzy_image_encode method with various image extensions.
594+ */
595+ public function test_feedzy_image_encode_image_extensions () {
596+ $ extensions = ['jpeg ' , 'PNG ' , 'webp ' , 'WEBP ' , 'avif ' , 'AVIF ' , 'gif ' , 'GIF ' ];
597+
598+ foreach ($ extensions as $ ext ) {
599+ $ url = "https://example.com/proxy?url=https://cdn.example.com/image. $ ext " ;
600+ $ expected = "https://cdn.example.com/image. $ ext " ;
601+
602+ $ result = $ this ->feedzy_abstract ->feedzy_image_encode ($ url );
603+ $ this ->assertEquals ($ expected , $ result , "Failed for extension: $ ext " );
604+ }
605+ }
606+
607+ /**
608+ * Test feedzy_image_encode method with non-image and edge cases.
609+ */
610+ public function test_feedzy_image_encode_edge_cases () {
611+ $ test_cases = array (
612+ // Non-image URL in query - should return original (with & escaped)
613+ ['https://example.com/proxy?url=https://example.com/document.pdf&width=300 ' , 'https://example.com/proxy?url=https://example.com/document.pdf&width=300 ' ],
614+ // URL with image separated by spaces (more realistic test case)
615+ ['https://example.com/proxy?description=Check this image: https://example.com/image.jpg out ' , 'https://example.com/image.jpg ' ],
616+ // Invalid image format in query (with & escaped)
617+ ['https://example.com/proxy?url=https://example.com/image&format=jpg ' , 'https://example.com/proxy?url=https://example.com/image&format=jpg ' ],
618+ // URL with special characters - this should extract the image
619+ ['https://example.com/proxy?url=https://example.com/images/file%20name.jpg ' , 'https://example.com/images/file%20name.jpg ' ],
620+ );
621+
622+ foreach ($ test_cases as [$ input , $ expected ]) {
623+ $ result = $ this ->feedzy_abstract ->feedzy_image_encode ($ input );
624+ $ this ->assertEquals ($ expected , $ result , "Failed for input: $ input " );
625+ }
626+ }
509627}
0 commit comments