@@ -44,4 +44,33 @@ public function test_filter_srcset( $source, $imageSrc, $attachmentId, $expected
4444
4545 $ this ->assertEquals ( $ expected , $ this ->test ->filter_srcset ( $ source , null , $ imageSrc , null , $ attachmentId ) );
4646 }
47+
48+ public static function dataprovider_filter_attachement_url (): array {
49+ $ generic_obj = (object ) array ( 'guid ' => 'http://example.com/image.jpg ' );
50+
51+ $ post_mock = \Mockery::mock ( '\WP_Post ' );
52+ $ post_mock ->guid = 'http://example.com/image.jpg ' ;
53+
54+ return array (
55+ array ( 'http://example.com/image.jpg ' , $ generic_obj , 42 ),
56+ array ( 'http://example.com/image.jpg ' , $ generic_obj , 0 ),
57+ array ( 'http://example.com/image.jpg ' , $ post_mock , 42 ),
58+ );
59+ }
60+
61+ /**
62+ * @dataProvider dataprovider_filter_attachement_url
63+ */
64+ public function test_filter_attachment_url ( string $ image_src , $ source_post , int $ attachment_id ): void {
65+ $ msls_imported = array (
66+ 'blog ' => 1 ,
67+ 'post ' => 1 ,
68+ );
69+
70+ Functions \expect ( 'get_post_meta ' )->zeroOrMoreTimes ()->andReturn ( $ msls_imported );
71+ Functions \expect ( 'delete_post_meta ' )->zeroOrMoreTimes ();
72+ Functions \expect ( 'get_blog_post ' )->zeroOrMoreTimes ()->andReturn ( $ source_post );
73+
74+ $ this ->assertEquals ( $ source_post ->guid , $ this ->test ->filter_attachment_url ( $ image_src , $ attachment_id ) );
75+ }
4776}
0 commit comments