Skip to content

Commit 0ffc5a5

Browse files
Fix existing bulk integration test without crazy fixture setup.
1 parent bc41f25 commit 0ffc5a5

10 files changed

Lines changed: 54 additions & 139 deletions

src/views/bulk-optimization-chart.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
$chart['dash-stroke'] = $chart['radius'] / 4;
1717
$chart['inner-radius'] = $chart['radius'] - $chart['stroke'] / 2;
1818
$chart['circle-size'] = 2 * pi() * $chart['radius'];
19-
$chart['dash_array_size'] = $chart['percentage'] / 100 * $chart['circle-size'];
19+
$chart['dash-array-size'] = $chart['percentage'] / 100 * $chart['circle-size'];
2020

2121
?>
2222
<style>
2323

2424
div.savings div.chart svg circle.main {
2525
stroke-width: <?php echo $chart['dash-stroke'] ?>;
26-
stroke-dasharray: <?php echo $chart['dash_array_size'] . ' ' . $chart['circle-size'] ?>;
26+
stroke-dasharray: <?php echo $chart['dash-array-size'] . ' ' . $chart['circle-size'] ?>;
2727
}
2828

2929
div.tiny-bulk-optimization div.savings div.chart div.value {
@@ -35,16 +35,16 @@
3535
stroke-dasharray: <?php echo '0' . ' ' . $chart['circle-size'] ?>
3636
}
3737
to {
38-
stroke-dasharray: <?php echo $chart['dash_array_size'] . ' ' . $chart['circle-size'] ?>
38+
stroke-dasharray: <?php echo $chart['dash-array-size'] . ' ' . $chart['circle-size'] ?>
3939
}
4040
}
4141

4242
</style>
4343

4444
<div id="optimization-chart" class="chart" data-full-circle-size="<?php echo $chart['circle-size'] ?>" data-percentage-factor="<?php echo $chart['radius'] ?>" >
4545
<svg width="<?php echo $chart['size'] ?>" height="<?php echo $chart['size'] ?>">
46-
<circle class="main" transform="rotate(-90, <?php echo $chart['center'] ?>, <?php echo $chart['center'] ?>)" r="<?php echo $chart['main-radius'] ?>" cx="<?php echo $chart['center'] ?>" cy="<?php echo $chart['center'] ?>"/>
47-
<circle class="inner" r="<?php echo $chart['inner-radius'] ?>" cx="<?php echo $chart['center'] ?>" cy="<?php echo $chart['center'] ?>" />
46+
<circle class="main" transform="rotate(-90, <?php echo $chart['center'] ?>, <?php echo $chart['center'] ?>)" r="<?php echo $chart['main-radius'] ?>" cx="<?php echo $chart['center'] ?>" cy="<?php echo $chart['center'] ?>"/>
47+
<circle class="inner" r="<?php echo $chart['inner-radius'] ?>" cx="<?php echo $chart['center'] ?>" cy="<?php echo $chart['center'] ?>" />
4848
</svg>
4949
<div class="value">
5050
<div class="percentage" id="savings-percentage"><?php echo $chart['percentage'] ?>%</div>

test/fixtures/input-example.jpg

468 KB
Loading
Lines changed: 32 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,34 @@
11
<?php
22

3-
// require_once dirname( __FILE__ ) . '/IntegrationTestCase.php';
4-
//
5-
// use Facebook\WebDriver\WebDriverBy;
6-
// use Facebook\WebDriver\WebDriverExpectedCondition;
7-
//
8-
// class BulkOptimizationIntegrationTest extends IntegrationTestCase {
9-
//
10-
// public function set_up() {
11-
// parent::set_up();
12-
// $this->set_api_key( 'PNG123' );
13-
// $this->enable_compression_sizes( array( '0', 'thumbnail', 'medium', 'large') );
14-
// $this->setup_fixtures();
15-
// self::$driver->get( wordpress( '/wp-admin/upload.php?page=tiny-bulk-optimization' ) );
16-
// }
17-
//
18-
// public function tear_down() {
19-
// parent::tear_down();
20-
// clear_settings();
21-
// clear_uploads();
22-
// reset_webservice();
23-
// }
24-
//
25-
// public function setup_fixtures() {
26-
// $this->create_non_compressed_image( 1001, 'non-compressed.jpg' );
27-
// $this->create_partially_compressed_image( 1002, 'partially-compressed.jpg' );
28-
// $this->create_fully_compressed_image( 1003, 'fully-compressed.jpg' );
29-
// }
30-
//
31-
// // In one test because it is terribly slow
32-
// public function test_all_the_values() {
33-
// //testShouldShowUploadedImages() {
34-
// $this->assertEquals( '3', $this->find( '#uploaded-images' )->getText() );
35-
//
36-
// // testShouldShowUncompressedImageSizes() {
37-
// $this->assertEquals( '6', $this->find( '#optimizable-image-sizes' )->getText() );
38-
//
39-
// // TODO mock number of compressions done and better test cost estimation for large numbers.
40-
// // testShouldShowEstimatedCost() {
41-
// $this->assertEquals( '$ 0.00', $this->find( '#estimated-cost' )->getText() );
42-
//
43-
// // testShouldShowSavingsPercentage() {
44-
// $this->assertEquals( '35.18%', $this->find( '#savings-percentage' )->getText() );
45-
//
46-
// // testShouldShowImageSizesCompressed() {
47-
// $this->assertEquals( '4', $this->find( '#optimized-image-sizes' )->getText() );
48-
//
49-
// // testShouldShowTotalUnoptimizedSize() {
50-
// $this->assertEquals( '305.29 kB', $this->find( '#unoptimized-library-size' )->getText() );
51-
//
52-
// // testShouldShowTotalOptimizedSize() {
53-
// $this->assertEquals( '197.88 kB', $this->find( '#optimized-library-size' )->getText() );
54-
// }
55-
//
56-
// // SKIP TODO
57-
// public function test_should_show_progress_bar() {
58-
// }
59-
// }
3+
require_once dirname( __FILE__ ) . '/IntegrationTestCase.php';
4+
5+
class BulkOptimizationIntegrationTest extends IntegrationTestCase {
6+
public function tear_down() {
7+
parent::tear_down();
8+
clear_settings();
9+
clear_uploads();
10+
}
11+
12+
public function test_presence_of_summary_values() {
13+
$this->set_api_key( 'JPG123' );
14+
15+
$this->enable_compression_sizes( array() );
16+
$this->upload_media( 'test/fixtures/input-example.jpg' );
17+
18+
$this->enable_compression_sizes( array( '0' ) );
19+
$this->upload_media( 'test/fixtures/input-example.jpg' );
20+
21+
$this->enable_compression_sizes( array( '0', 'thumbnail', 'medium' ) );
22+
$this->upload_media( 'test/fixtures/input-example.jpg' );
23+
24+
$this->visit( '/wp-admin/upload.php?page=tiny-bulk-optimization' );
25+
26+
$this->assertEquals( '3', $this->find( '#uploaded-images' )->getText() );
27+
$this->assertEquals( '5', $this->find( '#optimizable-image-sizes' )->getText() );
28+
$this->assertEquals( '$ 0.00', $this->find( '#estimated-cost' )->getText() );
29+
$this->assertEquals( '24.4%', $this->find( '#savings-percentage' )->getText() );
30+
$this->assertEquals( '4', $this->find( '#optimized-image-sizes' )->getText() );
31+
$this->assertEquals( '2.82 MB', $this->find( '#unoptimized-library-size' )->getText() );
32+
$this->assertEquals( '2.13 MB', $this->find( '#optimized-library-size' )->getText() );
33+
}
34+
}

test/integration/CompressIntegrationTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function test_upload_with_limited_key_should_show_error() {
3939
}
4040

4141
public function test_upload_with_valid_key_should_show_sizes_compressed() {
42-
$this->set_api_key( 'PNG123' );
42+
$this->set_api_key( 'JPG123' );
4343
$this->upload_media( 'test/fixtures/input-example.jpg' );
4444

4545
$this->assertContains(
@@ -73,7 +73,7 @@ public function test_upload_with_incorrect_metadata_should_show_error() {
7373

7474
public function test_upload_should_show_details_in_edit_screen() {
7575
if ( ! $this->has_postbox_container() ) { return; }
76-
$this->set_api_key( 'PNG123' );
76+
$this->set_api_key( 'JPG123' );
7777
$this->enable_compression_sizes( array() );
7878
$this->upload_media( 'test/fixtures/input-example.jpg' );
7979
$this->enable_compression_sizes( array( 'medium', 'large' ) );
@@ -87,7 +87,7 @@ public function test_upload_should_show_details_in_edit_screen() {
8787

8888
public function test_upload_should_show_details_in_edit_screen_popup() {
8989
if ( ! $this->has_postbox_container() ) { return; }
90-
$this->set_api_key( 'JPG123' );
90+
$this->set_api_key( 'PNG123' );
9191
$this->enable_compression_sizes( array( 'medium', 'large') );
9292
$this->upload_media( 'test/fixtures/input-example.png' );
9393

@@ -102,7 +102,7 @@ public function test_upload_should_show_details_in_edit_screen_popup() {
102102

103103
public function test_upload_should_show_compression_details_in_edit_screen_popup() {
104104
if ( ! $this->has_postbox_container() ) { return; }
105-
$this->set_api_key( 'PNG123' );
105+
$this->set_api_key( 'JPG123' );
106106
$this->enable_compression_sizes( array( 'medium', 'large') );
107107
$this->upload_media( 'test/fixtures/input-example.jpg' );
108108

@@ -141,7 +141,7 @@ public function test_compress_button_in_edit_screen_should_compress_images() {
141141
if ( ! $this->has_postbox_container() ) { return; }
142142
$this->upload_media( 'test/fixtures/input-example.jpg' );
143143

144-
$this->set_api_key( 'PNG123' );
144+
$this->set_api_key( 'JPG123' );
145145
$this->enable_compression_sizes( array( 'medium', 'large') );
146146

147147
$this->find_link( 'input-example' )->click();
@@ -154,7 +154,7 @@ public function test_compress_button_in_edit_screen_should_compress_images() {
154154
}
155155

156156
public function test_compress_button_should_compress_uncompressed_sizes() {
157-
$this->set_api_key( 'PNG123' );
157+
$this->set_api_key( 'JPG123' );
158158

159159
$this->enable_compression_sizes( array( 'medium' ) );
160160
$this->upload_media( 'test/fixtures/input-example.jpg' );
@@ -206,7 +206,7 @@ public function test_limit_reached_dismiss_button_should_remove_error() {
206206
}
207207

208208
public function test_resize_fit_should_display_resized_text_in_library() {
209-
$this->set_api_key( 'PNG123' );
209+
$this->set_api_key( 'JPG123' );
210210
$this->enable_resize(array(
211211
'method' => 'fit',
212212
'width' => 300,
@@ -224,7 +224,7 @@ public function test_resize_fit_should_display_resized_text_in_library() {
224224

225225
public function test_resize_fit_should_display_resized_text_in_edit_screen() {
226226
if ( ! $this->has_postbox_container() ) { return; }
227-
$this->set_api_key( 'PNG123' );
227+
$this->set_api_key( 'JPG123' );
228228
$this->enable_resize(array(
229229
'method' => 'fit',
230230
'width' => 300,
@@ -241,7 +241,7 @@ public function test_resize_fit_should_display_resized_text_in_edit_screen() {
241241
}
242242

243243
public function test_resize_scale_should_display_resized_text_in_library() {
244-
$this->set_api_key( 'PNG123' );
244+
$this->set_api_key( 'JPG123' );
245245
$this->enable_resize(array(
246246
'method' => 'scale',
247247
'height' => 200,
@@ -258,7 +258,7 @@ public function test_resize_scale_should_display_resized_text_in_library() {
258258

259259
public function test_resize_scale_should_display_resized_text_in_edit_screen() {
260260
if ( ! $this->has_postbox_container() ) { return; }
261-
$this->set_api_key( 'PNG123' );
261+
$this->set_api_key( 'JPG123' );
262262
$this->enable_resize(array(
263263
'method' => 'scale',
264264
'height' => 200,
@@ -274,7 +274,7 @@ public function test_resize_scale_should_display_resized_text_in_edit_screen() {
274274
}
275275

276276
public function test_superfluous_resize_should_not_display_resized_text_in_library() {
277-
$this->set_api_key( 'PNG123' );
277+
$this->set_api_key( 'JPG123' );
278278
$this->enable_resize(array(
279279
'method' => 'fit',
280280
'width' => 15000,
@@ -292,7 +292,7 @@ public function test_superfluous_resize_should_not_display_resized_text_in_libra
292292

293293
public function test_superfluous_resize_should_display_original_dimensions_in_edit_screen() {
294294
if ( ! $this->has_postbox_container() ) { return; }
295-
$this->set_api_key( 'PNG123' );
295+
$this->set_api_key( 'JPG123' );
296296
$this->enable_resize(array(
297297
'method' => 'fit',
298298
'width' => 15000,
@@ -309,7 +309,7 @@ public function test_superfluous_resize_should_display_original_dimensions_in_ed
309309
}
310310

311311
public function test_resize_disabled_should_not_display_resized_text_in_library() {
312-
$this->set_api_key( 'PNG123' );
312+
$this->set_api_key( 'JPG123' );
313313
$this->disable_resize();
314314

315315
$this->upload_media( 'test/fixtures/input-example.jpg' );
@@ -323,7 +323,7 @@ public function test_resize_disabled_should_not_display_resized_text_in_library(
323323

324324
public function test_resize_disabled_should_display_original_dimensions_in_edit_screen() {
325325
if ( ! $this->has_postbox_container() ) { return; }
326-
$this->set_api_key( 'PNG123' );
326+
$this->set_api_key( 'JPG123' );
327327
$this->disable_resize();
328328

329329
$this->upload_media( 'test/fixtures/input-example.jpg' );

test/integration/IntegrationTestCase.php

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -153,64 +153,4 @@ protected function unset_option($name) {
153153
$query->bind_param( 's', $name );
154154
$query->execute();
155155
}
156-
157-
158-
// protected function disable_resize() {
159-
// $url = wordpress( '/wp-admin/options-media.php' );
160-
// if ( self::$driver->getCurrentUrl() != $url ) {
161-
// self::$driver->get( $url );
162-
// }
163-
// $element = self::$driver->findElement( WebDriverBy::id( 'tinypng_resize_original_enabled' ) );
164-
// if ( $element->getAttribute( 'checked' ) ) {
165-
// $element->click();
166-
// }
167-
// self::$driver->findElement( WebDriverBy::tagName( 'form' ) )->submit();
168-
// }
169-
170-
// protected function create_image_fixture($id, $name, $wp_meta, $tiny_meta = false) {
171-
// $db = new mysqli( getenv( 'HOST' ), 'root',
172-
// getenv( 'MYSQL_ROOT_PASSWORD' ),
173-
// getenv( 'WORDPRESS_DATABASE' )
174-
// );
175-
//
176-
// $db->prepare('
177-
// INSERT INTO wp_posts(ID, post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title,
178-
// post_status, comment_status, ping_status, post_name,
179-
// post_modified, post_modified_gmt, post_parent, guid,
180-
// menu_order, post_type, post_mime_type, comment_count)
181-
// VALUES(' . $id . ", 1, '2016-04-22 07:11:04', '2016-04-22 07:11:04', '', '', '" . $name . "',
182-
// 'inherit', 'open', 'closed', '" . $name . "',
183-
// '2016-04-22 07:11:04', '2016-04-22 07:11:04', 0, 'http://wordpress.dev/wp-content/uploads/2016/04/" . $name . ".png',
184-
// 0, 'attachment', 'image/png', '0');
185-
// ")->execute();
186-
//
187-
// $db->prepare('
188-
// INSERT INTO wp_postmeta(post_id, meta_key, meta_value)
189-
// VALUES(' . $id . ", '_wp_attachment_metadata', '" . $wp_meta . "');
190-
// ")->execute();
191-
//
192-
// if ( $tiny_meta ) {
193-
// $db->prepare('
194-
// INSERT INTO wp_postmeta(post_id, meta_key, meta_value)
195-
// VALUES(' . $id . ", 'tiny_compress_images', '" . $tiny_meta . "');
196-
// ")->execute();
197-
// }
198-
// }
199-
//
200-
// public function create_non_compressed_image($id, $name) {
201-
// $wp_meta = 'a:5:{s:5:"width";i:1490;s:6:"height";i:1500;s:4:"file";s:33:"2016/04/detective-panda-large.png";s:5:"sizes";a:4:{s:9:"thumbnail";a:4:{s:4:"file";s:33:"detective-panda-large-150x150.png";s:5:"width";i:150;s:6:"height";i:150;s:9:"mime-type";s:9:"image/png";}s:6:"medium";a:4:{s:4:"file";s:33:"detective-panda-large-298x300.png";s:5:"width";i:298;s:6:"height";i:300;s:9:"mime-type";s:9:"image/png";}s:5:"large";a:4:{s:4:"file";s:35:"detective-panda-large-1017x1024.png";s:5:"width";i:1017;s:6:"height";i:1024;s:9:"mime-type";s:9:"image/png";}s:14:"post-thumbnail";a:4:{s:4:"file";s:35:"detective-panda-large-1200x1208.png";s:5:"width";i:1200;s:6:"height";i:1208;s:9:"mime-type";s:9:"image/png";}}s:10:"image_meta";a:12:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";s:11:"orientation";s:1:"0";s:8:"keywords";a:0:{}}}';
202-
// $this->create_image_fixture( $id, $name, $wp_meta );
203-
// }
204-
//
205-
// public function create_partially_compressed_image($id, $name) {
206-
// $wp_meta = 'a:5:{s:5:"width";i:626;s:6:"height";i:603;s:4:"file";s:19:"2016/04/small-2.jpg";s:5:"sizes";a:2:{s:9:"thumbnail";a:4:{s:4:"file";s:19:"small-2-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";}s:6:"medium";a:4:{s:4:"file";s:19:"small-2-300x289.jpg";s:5:"width";i:300;s:6:"height";i:289;s:9:"mime-type";s:10:"image/jpeg";}}s:10:"image_meta";a:12:{s:8:"aperture";s:3:"5.6";s:6:"credit";s:0:"";s:6:"camera";s:6:"NEX-3N";s:7:"caption";s:0:"";s:17:"created_timestamp";s:10:"1428328340";s:9:"copyright";s:0:"";s:12:"focal_length";s:2:"43";s:3:"iso";s:4:"3200";s:13:"shutter_speed";s:6:"0.0125";s:5:"title";s:0:"";s:11:"orientation";s:1:"1";s:8:"keywords";a:0:{}}}';
207-
// $tiny_meta = 'a:1:{i:0;a:3:{s:5:"input";a:2:{s:4:"size";i:124538;s:4:"type";s:10:"image/jpeg";}s:6:"output";a:6:{s:4:"size";i:74432;s:5:"width";i:626;s:6:"height";i:603;s:5:"ratio";d:0.59770000000000001;s:4:"type";s:10:"image/jpeg";s:3:"url";s:50:"https://api.tinify.com/output/oq8j3ht4j6uf5okc.jpg";}s:3:"end";i:1461333048;}}';
208-
// $this->create_image_fixture( $id, $name, $wp_meta, $tiny_meta );
209-
// }
210-
//
211-
// public function create_fully_compressed_image($id, $name) {
212-
// $wp_meta = 'a:5:{s:5:"width";i:626;s:6:"height";i:603;s:4:"file";s:19:"2016/04/small-1.jpg";s:5:"sizes";a:2:{s:9:"thumbnail";a:4:{s:4:"file";s:19:"small-1-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";}s:6:"medium";a:4:{s:4:"file";s:19:"small-1-300x289.jpg";s:5:"width";i:300;s:6:"height";i:289;s:9:"mime-type";s:10:"image/jpeg";}}s:10:"image_meta";a:12:{s:8:"aperture";s:3:"5.6";s:6:"credit";s:0:"";s:6:"camera";s:6:"NEX-3N";s:7:"caption";s:0:"";s:17:"created_timestamp";s:10:"1428328340";s:9:"copyright";s:0:"";s:12:"focal_length";s:2:"43";s:3:"iso";s:4:"3200";s:13:"shutter_speed";s:6:"0.0125";s:5:"title";s:0:"";s:11:"orientation";s:1:"1";s:8:"keywords";a:0:{}}}';
213-
// $tiny_meta = 'a:3:{i:0;a:3:{s:5:"input";a:2:{s:4:"size";i:124538;s:4:"type";s:10:"image/jpeg";}s:6:"output";a:6:{s:4:"size";i:74432;s:5:"width";i:626;s:6:"height";i:603;s:5:"ratio";d:0.59770000000000001;s:4:"type";s:10:"image/jpeg";s:3:"url";s:50:"https://api.tinify.com/output/3t1cf2baqc7l9o24.jpg";}s:3:"end";i:1461332938;}s:9:"thumbnail";a:3:{s:5:"input";a:2:{s:4:"size";i:15623;s:4:"type";s:10:"image/jpeg";}s:6:"output";a:6:{s:4:"size";i:13033;s:5:"width";i:150;s:6:"height";i:150;s:5:"ratio";d:0.83420000000000005;s:4:"type";s:10:"image/jpeg";s:3:"url";s:50:"https://api.tinify.com/output/n3i3pp1slh5s6g9s.jpg";}s:3:"end";i:1461332940;}s:6:"medium";a:3:{s:5:"input";a:2:{s:4:"size";i:47920;s:4:"type";s:10:"image/jpeg";}s:6:"output";a:6:{s:4:"size";i:40728;s:5:"width";i:300;s:6:"height";i:289;s:5:"ratio";d:0.84989999999999999;s:4:"type";s:10:"image/jpeg";s:3:"url";s:50:"https://api.tinify.com/output/q9nhl1go1vakeorj.jpg";}s:3:"end";i:1461332950;}}';
214-
// $this->create_image_fixture( $id, $name, $wp_meta, $tiny_meta );
215-
// }
216156
}
134 KB
Loading
-134 KB
Loading
File renamed without changes.

test/mock-tinypng-webservice/shrink.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function mock_png_response() {
1515
header("Image-Height: 1080");
1616

1717
$response = array(
18-
"input" => array( "size" => 161885, "type" => "image/png" ),
18+
"input" => array( "size" => 641206, "type" => "image/png" ),
1919
"output" => array( "size" => 151021, "type" => "image/png", "ratio" => 0.933 )
2020
);
2121
return json_encode($response);

test/unit/TinyCompressSharedTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ public function test_compress_file_should_save_resized_file() {
205205
$this->assertEquals(
206206
array(
207207
'input' => array(
208-
'size' => 161885,
208+
'size' => 641206,
209209
'type' => 'image/png',
210210
),
211211
'output' => array(
212212
'size' => 5,
213213
'type' => 'image/png',
214214
'width' => 6,
215215
'height' => 9,
216-
'ratio' => round( 5 / 161885, 4 ),
216+
'ratio' => round( 5 / 641206, 4 ),
217217
'resized' => true,
218218
),
219219
),

0 commit comments

Comments
 (0)