Skip to content

Commit e7a8c3f

Browse files
committed
fix tests and add new ones
1 parent f5bd9c5 commit e7a8c3f

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

inc/dam.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ public function alter_attachment_for_js( $response, $attachment, $meta ) {
626626
}
627627

628628
$sizes = Optml_App_Replacer::image_sizes();
629+
629630
$meta = [];
630631
if ( isset( $response['width'] ) ) {
631632
$meta['width'] = $response['width'];
@@ -638,6 +639,7 @@ public function alter_attachment_for_js( $response, $attachment, $meta ) {
638639
continue;
639640
}
640641
$args = $this->size_to_dimension( $size, $meta );
642+
641643
$response['sizes'][ $size ] = array_merge(
642644
$args,
643645
[
@@ -710,7 +712,7 @@ public function alter_img_tag_w_h( $dimensions, $image_src, $image_meta, $attach
710712
* @return string
711713
*/
712714
public function replace_dam_url_args( $args, $subject ) {
713-
$args = wp_parse_args( $args, [ 'width' => 'auto', 'height' => 'auto', 'crop' => false, 'dam' => true ] );
715+
$args = wp_parse_args( $args, [ 'width' => 'auto', 'height' => 'auto', 'dam' => true ] );
714716

715717
$width = $args['width'];
716718
$height = $args['height'];
@@ -736,6 +738,7 @@ public function replace_dam_url_args( $args, $subject ) {
736738
if ( $crop === true ) {
737739
$replacement .= '/g:' . $gravity . '/rt:fill';
738740
} elseif ( is_array( $crop ) && ! empty( $crop ) ) {
741+
739742
$replacement .= '/' . ( new GravityProperty( $crop['gravity'] ) ) .
740743
'/' . new ResizeTypeProperty( $crop['type'] ) .
741744
( $crop['enlarge'] ? '/el:1' : '' );

tests/test-dam.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class Test_Dam extends WP_UnitTestCase {
6262
'orientation' => 'landscape',
6363
'crop' => true
6464
],
65+
'test_gravity' => [
66+
'width' => 200,
67+
'height' => 100,
68+
'crop' => ['left','top']
69+
],
6570
'test_portrait' => [
6671
'width' => 100,
6772
'height' => 200,
@@ -232,27 +237,28 @@ public function test_alter_attachment_image_src() {
232237
$this->assertStringContainsString( 'w:200/h:100/g:ce/rt:fill', $result[0] );
233238
$this->assertEquals( 200, $result[1] );
234239
$this->assertEquals( 100, $result[2] );
235-
$this->assertTrue( $result[3] );
240+
$this->assertFalse( $result[3] );
241+
$result = $this->dam->alter_attachment_image_src( false, $id, 'test_gravity', false );
242+
$this->assertStringContainsString( 'w:200/h:100/g:noea/rt:fill', $result[0] );
236243

237244
$result = $this->dam->alter_attachment_image_src( false, $id, 'test_portrait', false );
238245
$this->assertStringContainsString( 'w:100/h:200/g:ce/rt:fill', $result[0] );
239246
$this->assertEquals( 100, $result[1] );
240247
$this->assertEquals( 200, $result[2] );
241-
$this->assertTrue( $result[3] );
248+
$this->assertFalse( $result[3] );
242249

243250
$result = $this->dam->alter_attachment_image_src( false, $id, 'medium', false );
244-
$this->assertStringContainsString( 'w:300/h:300/', $result[0] );
251+
$this->assertStringContainsString( 'w:200/h:300/', $result[0] );
245252
$this->assertStringNotContainsString( 'g:ce/rt:fill', $result[0] );
246-
$this->assertEquals( 300, $result[1] );
253+
$this->assertEquals( 200, $result[1] );
247254
$this->assertEquals( 300, $result[2] );
248255
$this->assertFalse( $result[3] );
249256

250257
$result = $this->dam->alter_attachment_image_src( false, $id, [ 50, 20 ], false );
251-
$this->assertStringContainsString( 'w:50/h:20/g:ce/rt:fill', $result[0] );
252-
$this->assertEquals( 50, $result[1] );
258+
$this->assertStringContainsString( 'w:13/h:20/', $result[0] );
259+
$this->assertEquals( 13, $result[1] );
253260
$this->assertEquals( 20, $result[2] );
254-
$this->assertEquals( true, $result[3] );
255-
$this->assertTrue( $result[3] );
261+
$this->assertFalse( $result[3] );
256262
}
257263
}
258264

0 commit comments

Comments
 (0)