Skip to content

Commit

Permalink
Tests: Use assertSame() in wp_read_image_metadata() tests.
Browse files Browse the repository at this point in the history
This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable.

Follow-up to [49/tests], [198/tests], [34374], [48937], [52269].

Props costdev.
See #59655.

git-svn-id: https://develop.svn.wordpress.org/trunk@57673 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Feb 20, 2024
1 parent c58cb01 commit bd78247
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions tests/phpunit/tests/image/meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public function test_exif_d70() {
// Exif from a Nikon D70.
$out = wp_read_image_metadata( DIR_TESTDATA . '/images/2004-07-22-DSC_0008.jpg' );

$this->assertEquals( 6.3, $out['aperture'], 'Aperture value not equivalent' );
$this->assertSame( '6.3', $out['aperture'], 'Aperture value not equivalent' );
$this->assertSame( '', $out['credit'], 'Credit value not the same' );
$this->assertSame( 'NIKON D70', $out['camera'], 'Camera value not the same' );
$this->assertSame( '', $out['caption'], 'Caption value not the same' );
$this->assertEquals( strtotime( '2004-07-22 17:14:59' ), $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( (string) strtotime( '2004-07-22 17:14:59' ), $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( '', $out['copyright'], 'Copyright value not the same' );
$this->assertEquals( 27, $out['focal_length'], 'Focal length value not equivalent' );
$this->assertEquals( 400, $out['iso'], 'Iso value not equivalent' );
$this->assertEquals( 1 / 40, $out['shutter_speed'], 'Shutter speed value not equivalent' );
$this->assertSame( '27', $out['focal_length'], 'Focal length value not equivalent' );
$this->assertSame( '400', $out['iso'], 'Iso value not equivalent' );
$this->assertSame( (string) ( 1 / 40 ), $out['shutter_speed'], 'Shutter speed value not equivalent' );
$this->assertSame( '', $out['title'], 'Title value not the same' );
}

Expand All @@ -52,11 +52,11 @@ public function test_exif_d70_mf() {
$this->assertSame( '', $out['credit'], 'Credit value not the same' );
$this->assertSame( 'NIKON D70', $out['camera'], 'Camera value not the same' );
$this->assertSame( 'Copyright Alex Shiels', $out['caption'], 'Caption value not the same' );
$this->assertEquals( strtotime( '2007-06-17 21:18:00' ), $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( (string) strtotime( '2007-06-17 21:18:00' ), $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( '', $out['copyright'], 'Copyright value not the same' );
$this->assertEquals( 0, $out['focal_length'], 'Focal length value not equivalent' );
$this->assertEquals( 0, $out['iso'], 'Iso value not equivalent' ); // Interesting - a Nikon bug?
$this->assertEquals( 1 / 500, $out['shutter_speed'], 'Shutter speed value not equivalent' );
$this->assertSame( '0', $out['focal_length'], 'Focal length value not equivalent' );
$this->assertSame( '0', $out['iso'], 'Iso value not equivalent' ); // Interesting - a Nikon bug?
$this->assertSame( (string) ( 1 / 500 ), $out['shutter_speed'], 'Shutter speed value not equivalent' );
$this->assertSame( 'Copyright Alex Shiels', $out['title'], 'Title value not the same' );
// $this->assertSame( array( 'Flowers' ), $out['keywords'] );
}
Expand All @@ -65,31 +65,31 @@ public function test_exif_d70_iptc() {
// Exif from a Nikon D70 with IPTC data added later.
$out = wp_read_image_metadata( DIR_TESTDATA . '/images/2004-07-22-DSC_0007.jpg' );

$this->assertEquals( 6.3, $out['aperture'], 'Aperture value not equivalent' );
$this->assertSame( '6.3', $out['aperture'], 'Aperture value not equivalent' );
$this->assertSame( 'IPTC Creator', $out['credit'], 'Credit value not the same' );
$this->assertSame( 'NIKON D70', $out['camera'], 'Camera value not the same' );
$this->assertSame( 'IPTC Caption', $out['caption'], 'Caption value not the same' );
$this->assertEquals( strtotime( '2004-07-22 17:14:35' ), $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( (string) strtotime( '2004-07-22 17:14:35' ), $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( 'IPTC Copyright', $out['copyright'], 'Copyright value not the same' );
$this->assertEquals( 18, $out['focal_length'], 'Focal length value not equivalent' );
$this->assertEquals( 200, $out['iso'], 'Iso value not equivalent' );
$this->assertEquals( 1 / 25, $out['shutter_speed'], 'Shutter speed value not equivalent' );
$this->assertSame( '18', $out['focal_length'], 'Focal length value not equivalent' );
$this->assertSame( '200', $out['iso'], 'Iso value not equivalent' );
$this->assertSame( (string) ( 1 / 25 ), $out['shutter_speed'], 'Shutter speed value not equivalent' );
$this->assertSame( 'IPTC Headline', $out['title'], 'Title value not the same' );
}

public function test_exif_fuji() {
// Exif from a Fuji FinePix S5600 (thanks Mark).
$out = wp_read_image_metadata( DIR_TESTDATA . '/images/a2-small.jpg' );

$this->assertEquals( 4.5, $out['aperture'], 'Aperture value not equivalent' );
$this->assertSame( '4.5', $out['aperture'], 'Aperture value not equivalent' );
$this->assertSame( '', $out['credit'], 'Credit value not the same' );
$this->assertSame( 'FinePix S5600', $out['camera'], 'Camera value not the same' );
$this->assertSame( '', $out['caption'], 'Caption value not the same' );
$this->assertEquals( strtotime( '2007-09-03 10:17:03' ), $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( (string) strtotime( '2007-09-03 10:17:03' ), $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( '', $out['copyright'], 'Copyright value not the same' );
$this->assertEquals( 6.3, $out['focal_length'], 'Focal length value not equivalent' );
$this->assertEquals( 64, $out['iso'], 'Iso value not equivalent' );
$this->assertEquals( 1 / 320, $out['shutter_speed'], 'Shutter speed value not equivalent' );
$this->assertSame( '6.3', $out['focal_length'], 'Focal length value not equivalent' );
$this->assertSame( '64', $out['iso'], 'Iso value not equivalent' );
$this->assertSame( (string) ( 1 / 320 ), $out['shutter_speed'], 'Shutter speed value not equivalent' );
$this->assertSame( '', $out['title'], 'Title value not the same' );
}

Expand All @@ -101,31 +101,31 @@ public function test_exif_error() {
// This triggers a warning mesage when reading the Exif block.
$out = wp_read_image_metadata( DIR_TESTDATA . '/images/waffles.jpg' );

$this->assertEquals( 0, $out['aperture'], 'Aperture value not equivalent' );
$this->assertSame( '0', $out['aperture'], 'Aperture value not equivalent' );
$this->assertSame( '', $out['credit'], 'Credit value not the same' );
$this->assertSame( '', $out['camera'], 'Camera value not the same' );
$this->assertSame( '', $out['caption'], 'Caption value not the same' );
$this->assertEquals( 0, $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( '0', $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( '', $out['copyright'], 'Copyright value not the same' );
$this->assertEquals( 0, $out['focal_length'], 'Focal length value not equivalent' );
$this->assertEquals( 0, $out['iso'], 'Iso value not equivalent' );
$this->assertEquals( 0, $out['shutter_speed'], 'Shutter speed value not equivalent' );
$this->assertSame( '0', $out['focal_length'], 'Focal length value not equivalent' );
$this->assertSame( '0', $out['iso'], 'Iso value not equivalent' );
$this->assertSame( '0', $out['shutter_speed'], 'Shutter speed value not equivalent' );
$this->assertSame( '', $out['title'], 'Title value not the same' );
}

public function test_exif_no_data() {
// No Exif data in this image (from burningwell.org).
$out = wp_read_image_metadata( DIR_TESTDATA . '/images/canola.jpg' );

$this->assertEquals( 0, $out['aperture'], 'Aperture value not equivalent' );
$this->assertSame( '0', $out['aperture'], 'Aperture value not equivalent' );
$this->assertSame( '', $out['credit'], 'Credit value not the same' );
$this->assertSame( '', $out['camera'], 'Camera value not the same' );
$this->assertSame( '', $out['caption'], 'Caption value not the same' );
$this->assertEquals( 0, $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( '0', $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( '', $out['copyright'], 'Copyright value not the same' );
$this->assertEquals( 0, $out['focal_length'], 'Focal length value not equivalent' );
$this->assertEquals( 0, $out['iso'], 'Iso value not equivalent' );
$this->assertEquals( 0, $out['shutter_speed'], 'Shutter speed value not equivalent' );
$this->assertSame( '0', $out['focal_length'], 'Focal length value not equivalent' );
$this->assertSame( '0', $out['iso'], 'Iso value not equivalent' );
$this->assertSame( '0', $out['shutter_speed'], 'Shutter speed value not equivalent' );
$this->assertSame( '', $out['title'], 'Title value not the same' );
}

Expand Down Expand Up @@ -158,13 +158,13 @@ public function test_exif_keywords() {
$this->assertSame( 'Photoshop Author', $out['credit'], 'Credit value not the same' );
$this->assertSame( 'DMC-LX2', $out['camera'], 'Camera value not the same' );
$this->assertSame( 'Photoshop Description', $out['caption'], 'Caption value not the same' );
$this->assertEquals( 1306315327, $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( '1306315327', $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( 'Photoshop Copyrright Notice', $out['copyright'], 'Copyright value not the same' );
$this->assertSame( '6.3', $out['focal_length'], 'Focal length value not the same' );
$this->assertSame( '100', $out['iso'], 'Iso value not the same' );
$this->assertSame( '0.0025', $out['shutter_speed'], 'Shutter speed value not the same' );
$this->assertSame( 'Photoshop Document Ttitle', $out['title'], 'Title value not the same' );
$this->assertEquals( 1, $out['orientation'], 'Orientation value not equivalent' );
$this->assertSame( '1', $out['orientation'], 'Orientation value not equivalent' );
$this->assertSame( array( 'beach', 'baywatch', 'LA', 'sunset' ), $out['keywords'], 'Keywords not the same' );
}

Expand Down Expand Up @@ -246,15 +246,15 @@ public function test_exif_unexpected_data() {
// Unexpected Exif data: FNumber is "0/0", aperture should be 0.
$out = wp_read_image_metadata( DIR_TESTDATA . '/images/sugarloaf-mountain.jpg' );

$this->assertEquals( 0, $out['aperture'], 'Aperture value not equivalent' );
$this->assertSame( '0', $out['aperture'], 'Aperture value not equivalent' );
$this->assertSame( '', $out['credit'], 'Credit value not the same' );
$this->assertSame( 'X-T1', $out['camera'], 'Camera value not the same' );
$this->assertSame( '', $out['caption'], 'Caption value not the same' );
$this->assertEquals( 0, $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( '0', $out['created_timestamp'], 'Timestamp value not equivalent' );
$this->assertSame( '', $out['copyright'], 'Copyright value not the same' );
$this->assertEquals( 50, $out['focal_length'], 'Focal length value not equivalent' );
$this->assertEquals( 200, $out['iso'], 'Iso value not equivalent' );
$this->assertEquals( 2, $out['shutter_speed'], 'Shutter speed value not equivalent' );
$this->assertSame( '50', $out['focal_length'], 'Focal length value not equivalent' );
$this->assertSame( '200', $out['iso'], 'Iso value not equivalent' );
$this->assertSame( '2', $out['shutter_speed'], 'Shutter speed value not equivalent' );
$this->assertSame( 'Sugarloaf Panorama', $out['title'], 'Title value not the same' );
}
}

0 comments on commit bd78247

Please sign in to comment.