@@ -156,16 +156,76 @@ public function test_get_latest_error_should_return_trimmed_message_if_message_i
156156 }
157157
158158 public function test_get_statistics () {
159- $ active_sizes = $ this ->settings ->get_sizes ();
160- $ active_tinify_sizes = $ this ->settings ->get_active_tinify_sizes ();
159+ $ this ->wp ->addOption ( 'tinypng_convert_format ' , array (
160+ 'convert ' => 'off ' ,
161+ ) );
162+ $ settings = new Tiny_Settings ();
163+ $ subject = new Tiny_Image ( $ settings , 1 , $ this ->json ( '_wp_attachment_metadata ' ) );
164+
165+ $ active_sizes = $ settings ->get_sizes ();
166+ $ active_tinify_sizes = $ settings ->get_active_tinify_sizes ();
167+ $ stats = $ subject ->get_statistics ( $ active_sizes , $ active_tinify_sizes );
168+
169+ $ this ->assertEquals ( array (
170+ 'initial_total_size ' => 360542 ,
171+ 'compressed_total_size ' => 328670 ,
172+ 'image_sizes_compressed ' => 3 ,
173+ 'available_uncompressed_sizes ' => 1 ,
174+ 'image_sizes_converted ' => 0 ,
175+ 'available_unconverted_sizes ' => 4 ,
176+ 'image_sizes_optimized ' => 3 ,
177+ 'available_unoptimized_sizes ' => 1 ,
178+ ), $ stats );
179+ }
180+
181+ public function test_get_statistics_with_conversion_enabled () {
182+ $ this ->wp ->addOption ( 'tinypng_convert_format ' , array (
183+ 'convert ' => 'on ' ,
184+ 'convert_to ' => 'smallest ' ,
185+ ) );
186+ $ settings = new Tiny_Settings ();
187+ $ subject = new Tiny_Image ( $ settings , 1 , $ this ->json ( '_wp_attachment_metadata ' ) );
188+
189+ $ active_sizes = $ settings ->get_sizes ();
190+ $ active_tinify_sizes = $ settings ->get_active_tinify_sizes ();
191+ $ stats = $ subject ->get_statistics ( $ active_sizes , $ active_tinify_sizes );
192+
161193 $ this ->assertEquals ( array (
162194 'initial_total_size ' => 360542 ,
163195 'compressed_total_size ' => 328670 ,
164196 'image_sizes_compressed ' => 3 ,
165197 'available_uncompressed_sizes ' => 1 ,
166198 'image_sizes_converted ' => 0 ,
167- 'available_unconverted_sizes ' => 4
168- ), $ this ->subject ->get_statistics ( $ active_sizes , $ active_tinify_sizes ) );
199+ 'available_unconverted_sizes ' => 4 ,
200+ 'image_sizes_optimized ' => 0 ,
201+ 'available_unoptimized_sizes ' => 4 ,
202+ ), $ stats );
203+ }
204+
205+ public function test_image_sizes_optimized_is_independent_of_image_sizes_compressed_when_conversion_is_pending () {
206+ $ this ->wp ->addOption ( 'tinypng_convert_format ' , array (
207+ 'convert ' => 'on ' ,
208+ 'convert_to ' => 'smallest ' ,
209+ ) );
210+ $ settings = new Tiny_Settings ();
211+ $ subject = new Tiny_Image ( $ settings , 1 , $ this ->json ( '_wp_attachment_metadata ' ) );
212+
213+ $ stats = $ subject ->get_statistics (
214+ $ settings ->get_sizes (),
215+ $ settings ->get_active_tinify_sizes ()
216+ );
217+
218+ $ this ->assertEquals ( 3 , $ stats ['image_sizes_compressed ' ],
219+ 'Three sizes have been compressed. '
220+ );
221+ $ this ->assertEquals ( 0 , $ stats ['image_sizes_optimized ' ],
222+ 'No sizes count as fully optimized because conversion has not been done but has been enabled. '
223+ );
224+ $ this ->assertNotEquals (
225+ $ stats ['image_sizes_compressed ' ],
226+ $ stats ['image_sizes_optimized ' ],
227+ 'the number of compressed images should not be equal to the number of optimized images. '
228+ );
169229 }
170230
171231 public function test_get_image_sizes_available_for_compression_when_file_modified () {
0 commit comments