@@ -107,6 +107,43 @@ public function test_replacement_with_jetpack_photon() {
107
107
$ this ->assertNotContains ( 'i0.wp.com ' , $ replaced_content );
108
108
}
109
109
110
+ public function test_lazyload_only_gif () {
111
+ $ content = '<div class="before-footer">
112
+ <div class="codeinwp-container">
113
+ <p class="featuredon">Featured On</p>
114
+ <img class="sample-class" src="http://www.example.org/wp-content/uploads/2018/05/brands.gif">
115
+ <img src="http://www.example.org/wp-content/uploads/2018/05/brands2.gif">
116
+ <img src="http://www.example.org/wp-content/uploads/2018/05/brands.svg">
117
+ </div>
118
+ </div> ' ;
119
+
120
+ $ replaced_content = Optml_Manager::instance ()->replace_content ( $ content );
121
+ $ this ->assertEquals ( 6 , substr_count ( $ replaced_content , 'i.optimole.com ' ) );
122
+ $ this ->assertEquals ( 4 , substr_count ( $ replaced_content , 'optimole-lazy-only ' ) );
123
+ $ this ->assertEquals ( 3 , substr_count ( $ replaced_content , 'data:image/svg+xml ' ) );
124
+ }
125
+
126
+ public function test_lazyload_only_with_json () {
127
+ $ some_html_content = [
128
+ 'html ' => '<div class="before-footer">
129
+ <div class="codeinwp-container">
130
+ <p class="featuredon">Featured On</p>
131
+ <img class="sample-class" src="http://www.example.org/wp-content/uploads/2018/05/brands.gif">
132
+ <img src="http://www.example.org/wp-content/uploads/2018/05/brands2.gif">
133
+ <img src="http://www.example.org/wp-content/uploads/2018/05/brands.svg">
134
+ </div>
135
+ </div> '
136
+ ];
137
+ $ content = wp_json_encode ( $ some_html_content );
138
+ $ replaced_content = Optml_Manager::instance ()->replace_content ( $ content );
139
+ $ this ->assertEquals ( $ replaced_content , $ replaced_content );
140
+ $ this ->assertArrayHasKey ( 'html ' , json_decode ( $ replaced_content , true ) );
141
+ $ this ->assertEquals ( 6 , substr_count ( $ replaced_content , 'i.optimole.com ' ) );
142
+ $ this ->assertEquals ( 4 , substr_count ( $ replaced_content , 'optimole-lazy-only ' ) );
143
+ $ this ->assertEquals ( 3 , substr_count ( $ replaced_content , 'data:image/svg+xml ' ) );
144
+
145
+ }
146
+
110
147
public function test_replacement_wrong_extension_with_query_string () {
111
148
$ content = '
112
149
<img src="http://example.org/wp-content/plugins/test/generate-qr-code.php?3CRMB6qM1DvLswN6nxKjppX6W5ycjXpeZp">
@@ -191,6 +228,7 @@ public function test_check_with_no_script() {
191
228
$ this ->assertEquals ( 1 , substr_count ( $ replaced_content , '<noscript> ' ) );
192
229
$ this ->assertEquals ( 2 , substr_count ( $ replaced_content , 'i.optimole.com ' ) );
193
230
}
231
+
194
232
public function test_check_with_multiple_images_in_no_script () {
195
233
$ content = '<img width="1612" height="1116" src="data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=" data-lazy-src="http://example.org/wp-content/uploads/2018/11/gradient.png" class="attachment-twentyseventeen-featured-image size-twentyseventeen-featured-image wp-post-image" alt="" data-lazy-sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" />
196
234
<noscript>
@@ -263,11 +301,11 @@ public function test_lazyload_json_data_disabled() {
263
301
}
264
302
265
303
public function test_should_replace_query_string_url () {
266
- $ content = '<img src="https://example.org/photos/814499/pexels-photo-814499.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" alt=""> ' ;
267
- $ replaced_content = Optml_Manager::instance ()->replace_content ($ content );
268
- $ this ->assertContains ('i.optimole.com ' , $ replaced_content );
269
- $ this ->assertContains ('data-opt-src ' , $ replaced_content );
270
- $ this ->assertContains ('example.org ' , $ replaced_content );
304
+ $ content = '<img src="https://example.org/photos/814499/pexels-photo-814499.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" alt=""> ' ;
305
+ $ replaced_content = Optml_Manager::instance ()->replace_content ( $ content );
306
+ $ this ->assertContains ( 'i.optimole.com ' , $ replaced_content );
307
+ $ this ->assertContains ( 'data-opt-src ' , $ replaced_content );
308
+ $ this ->assertContains ( 'example.org ' , $ replaced_content );
271
309
}
272
310
273
311
}
0 commit comments