@@ -20,17 +20,45 @@ public function test_admin_init_should_register_keys() {
2020 }
2121
2222 public function test_admin_init_should_add_settings_section () {
23- $ this ->assertEquals (array (
24- array ( 'tinypng_settings ' , 'JPEG and PNG optimization ' , array ($ this ->subject , 'render_section ' ), 'media ' ),
25- array ( 'section_end ' , '' , array ($ this ->subject , 'render_section_end ' ), 'media ' ),), $ this ->wp ->getCalls ( 'add_settings_section ' ) );
23+ $ this ->assertEquals ( array (
24+ array (
25+ 'tinypng_settings ' ,
26+ 'JPEG and PNG optimization ' ,
27+ array ( $ this ->subject , 'render_section ' ),
28+ 'media ' ,
29+ ),
30+ array (
31+ 'section_end ' ,
32+ '' ,
33+ array ( $ this ->subject , 'render_section_end ' ),
34+ 'media ' ,
35+ ),
36+ ), $ this ->wp ->getCalls ( 'add_settings_section ' ) );
2637 }
2738
2839 public function test_admin_init_should_add_settings_field () {
29- $ this ->assertEquals (array (
30- array ( 'tinypng_api_key ' , 'TinyPNG account ' , array ( $ this ->subject , 'render_pending_status ' ), 'media ' , 'tinypng_settings ' ),
31- array ( 'tinypng_sizes ' , 'File compression ' , array ( $ this ->subject , 'render_sizes ' ), 'media ' , 'tinypng_settings ' ),
32- array ( 'tinypng_resize_original ' , 'Original image ' , array ( $ this ->subject , 'render_resize ' ), 'media ' , 'tinypng_settings ' ),
33- ), $ this ->wp ->getCalls ( 'add_settings_field ' ));
40+ $ this ->assertEquals ( array (
41+ array (
42+ 'tinypng_api_key ' ,
43+ 'TinyPNG account ' ,
44+ array ( $ this ->subject , 'render_pending_status ' ),
45+ 'media ' ,
46+ 'tinypng_settings ' ,
47+ ),
48+ array (
49+ 'tinypng_sizes ' ,
50+ 'File compression ' , array ( $ this ->subject , 'render_sizes ' ),
51+ 'media ' ,
52+ 'tinypng_settings ' ,
53+ ),
54+ array (
55+ 'tinypng_resize_original ' ,
56+ 'Original image ' ,
57+ array ( $ this ->subject , 'render_resize ' ),
58+ 'media ' ,
59+ 'tinypng_settings ' ,
60+ ),
61+ ), $ this ->wp ->getCalls ( 'add_settings_field ' ) );
3462 }
3563
3664 public function test_should_retrieve_sizes_with_settings () {
@@ -39,9 +67,6 @@ public function test_should_retrieve_sizes_with_settings() {
3967 $ this ->wp ->addOption ( 'tinypng_sizes[post-thumbnail] ' , 'on ' );
4068 $ this ->wp ->addImageSize ( 'post-thumbnail ' , array ( 'width ' => 825 , 'height ' => 510 ) );
4169
42- global $ _wp_additional_image_sizes ;
43- $ _wp_additional_image_sizes = array ( 'post-thumbnail ' => array ( 'width ' => 825 , 'height ' => 510 ) );
44-
4570 $ this ->subject ->get_sizes ();
4671 $ this ->assertEquals (array (
4772 0 => array ( 'width ' => null , 'height ' => null , 'tinify ' => true ),
@@ -104,48 +129,97 @@ public function test_should_show_additional_size_without_width() {
104129 );
105130 }
106131
107- public function test_should_return_resize_enabled () {
132+ public function test_get_resize_enabled_should_return_true_if_enabled () {
108133 $ this ->wp ->addOption ( 'tinypng_resize_original ' , array ( 'enabled ' => 'on ' ) );
109134 $ this ->assertEquals ( true , $ this ->subject ->get_resize_enabled () );
110135 }
111136
112- public function test_should_return_resize_not_enabled_without_configuration () {
137+ public function test_get_resize_enabled_should_return_false_without_configuration () {
113138 $ this ->wp ->addOption ( 'tinypng_resize_original ' , array () );
114139 $ this ->assertEquals ( false , $ this ->subject ->get_resize_enabled () );
115140 }
116141
142+ public function test_get_resize_enabled_should_return_false_if_original_is_not_compressed () {
143+ $ this ->wp ->addOption ( 'tinypng_sizes[0] ' , 'off ' );
144+ $ this ->wp ->addOption ( 'tinypng_resize_original ' , array ( 'enabled ' => 'on ' ) );
145+ $ this ->assertEquals ( false , $ this ->subject ->get_resize_enabled () );
146+ }
147+
117148 public function test_should_return_resize_options_with_width_and_height () {
118- $ this ->wp ->addOption ( 'tinypng_resize_original ' , array ( 'enabled ' => 'on ' , 'width ' => '800 ' , 'height ' => '600 ' ) );
119- $ this ->assertEquals ( array ( 'method ' => 'fit ' , 'width ' => 800 , 'height ' => 600 ), $ this ->subject ->get_resize_options ( Tiny_Image::ORIGINAL ) );
149+ $ this ->wp ->addOption (
150+ 'tinypng_resize_original ' ,
151+ array ( 'enabled ' => 'on ' , 'width ' => '800 ' , 'height ' => '600 ' )
152+ );
153+
154+ $ this ->assertEquals (
155+ array ( 'method ' => 'fit ' , 'width ' => 800 , 'height ' => 600 ),
156+ $ this ->subject ->get_resize_options ( Tiny_Image::ORIGINAL )
157+ );
120158 }
121159
122160 public function test_should_return_resize_options_without_width () {
123- $ this ->wp ->addOption ( 'tinypng_resize_original ' , array ( 'enabled ' => 'on ' , 'width ' => '' , 'height ' => '600 ' ) );
124- $ this ->assertEquals ( array ( 'method ' => 'scale ' , 'height ' => 600 ), $ this ->subject ->get_resize_options ( Tiny_Image::ORIGINAL ) );
161+ $ this ->wp ->addOption (
162+ 'tinypng_resize_original ' ,
163+ array ( 'enabled ' => 'on ' , 'width ' => '' , 'height ' => '600 ' )
164+ );
165+
166+ $ this ->assertEquals (
167+ array ( 'method ' => 'scale ' , 'height ' => 600 ),
168+ $ this ->subject ->get_resize_options ( Tiny_Image::ORIGINAL )
169+ );
125170 }
126171
127172 public function test_should_return_resize_options_without_height () {
128- $ this ->wp ->addOption ( 'tinypng_resize_original ' , array ( 'enabled ' => 'on ' , 'width ' => '800 ' , 'height ' => '' ) );
129- $ this ->assertEquals ( array ( 'method ' => 'scale ' , 'width ' => 800 ), $ this ->subject ->get_resize_options ( Tiny_Image::ORIGINAL ) );
173+ $ this ->wp ->addOption (
174+ 'tinypng_resize_original ' ,
175+ array ( 'enabled ' => 'on ' , 'width ' => '800 ' , 'height ' => '' )
176+ );
177+
178+ $ this ->assertEquals (
179+ array ( 'method ' => 'scale ' , 'width ' => 800 ),
180+ $ this ->subject ->get_resize_options ( Tiny_Image::ORIGINAL )
181+ );
130182 }
131183
132184 public function test_should_return_resize_options_with_invaled_width () {
133- $ this ->wp ->addOption ( 'tinypng_resize_original ' , array ( 'enabled ' => 'on ' , 'width ' => '-1 ' , 'height ' => '600 ' ) );
134- $ this ->assertEquals ( array ( 'method ' => 'scale ' , 'height ' => 600 ), $ this ->subject ->get_resize_options ( Tiny_Image::ORIGINAL ) );
185+ $ this ->wp ->addOption (
186+ 'tinypng_resize_original ' ,
187+ array ( 'enabled ' => 'on ' , 'width ' => '-1 ' , 'height ' => '600 ' )
188+ );
189+
190+ $ this ->assertEquals (
191+ array ( 'method ' => 'scale ' , 'height ' => 600 ),
192+ $ this ->subject ->get_resize_options ( Tiny_Image::ORIGINAL )
193+ );
135194 }
136195
137196 public function test_should_return_resize_options_with_invaled_height () {
138- $ this ->wp ->addOption ( 'tinypng_resize_original ' , array ( 'enabled ' => 'on ' , 'width ' => '800 ' , 'height ' => '-1 ' ) );
139- $ this ->assertEquals ( array ( 'method ' => 'scale ' , 'width ' => 800 ), $ this ->subject ->get_resize_options ( Tiny_Image::ORIGINAL ) );
197+ $ this ->wp ->addOption (
198+ 'tinypng_resize_original ' ,
199+ array ( 'enabled ' => 'on ' , 'width ' => '800 ' , 'height ' => '-1 ' )
200+ );
201+
202+ $ this ->assertEquals (
203+ array ( 'method ' => 'scale ' , 'width ' => 800 ),
204+ $ this ->subject ->get_resize_options ( Tiny_Image::ORIGINAL )
205+ );
140206 }
141207
142208 public function test_should_not_return_resize_options_without_with_and_height () {
143- $ this ->wp ->addOption ( 'tinypng_resize_original ' , array ( 'enabled ' => 'on ' , 'width ' => '' , 'height ' => '' ) );
209+ $ this ->wp ->addOption (
210+ 'tinypng_resize_original ' ,
211+ array ( 'enabled ' => 'on ' , 'width ' => '' , 'height ' => '' )
212+ );
213+
144214 $ this ->assertEquals ( false , $ this ->subject ->get_resize_options ( Tiny_Image::ORIGINAL ) );
145215 }
146216
147217 public function test_should_not_return_resize_options_when_not_enabled () {
148- $ this ->wp ->addOption ( 'tinypng_resize_original ' , array ( 'width ' => '800 ' , 'height ' => '600 ' ) );
218+ $ this ->wp ->addOption (
219+ 'tinypng_resize_original ' ,
220+ array ( 'width ' => '800 ' , 'height ' => '600 ' )
221+ );
222+
149223 $ this ->assertEquals ( false , $ this ->subject ->get_resize_options ( Tiny_Image::ORIGINAL ) );
150224 }
151225
@@ -161,11 +235,19 @@ public function test_should_return_include_metadata_not_enabled_without_configur
161235
162236 public function test_should_return_preserve_options_when_enabled () {
163237 $ this ->wp ->addOption ( 'tinypng_preserve_data ' , array ( 'copyright ' => 'on ' ) );
164- $ this ->assertEquals ( array ( '0 ' => 'copyright ' ), $ this ->subject ->get_preserve_options ( Tiny_Image::ORIGINAL ) );
238+
239+ $ this ->assertEquals (
240+ array ( '0 ' => 'copyright ' ),
241+ $ this ->subject ->get_preserve_options ( Tiny_Image::ORIGINAL )
242+ );
165243 }
166244
167245 public function test_should_not_return_preserve_options_when_disabled () {
168246 $ this ->wp ->addOption ( 'tinypng_include_metadata ' , array () );
169- $ this ->assertEquals ( array (), $ this ->subject ->get_preserve_options ( Tiny_Image::ORIGINAL ) );
247+
248+ $ this ->assertEquals (
249+ array (),
250+ $ this ->subject ->get_preserve_options ( Tiny_Image::ORIGINAL )
251+ );
170252 }
171253}
0 commit comments