Commit aed3c2ee authored by Robert O'Rourke's avatar Robert O'Rourke
Browse files

update tests, image with exif data eg camera, iso etc

parent 1cf1f89f
Loading
Loading
Loading
Loading

tests/data/canola.jpg

deleted100644 → 0
−198 KiB
Loading image diff...
+58 KiB
Loading image diff...
+7 −7
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
class Test_S3_Uploads_Image_Editor_Imagick extends WP_UnitTestCase {

	public function setUp() {
		$this->image_path = dirname( __FILE__ ) . '/data/canola.jpg';
		$this->image_path = dirname( __FILE__ ) . '/data/sunflower.jpg';

		require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
		require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
@@ -26,13 +26,13 @@ class Test_S3_Uploads_Image_Editor_Imagick extends WP_UnitTestCase {
	public function test_save_image_with_inbuilt_fails() {

		$upload_dir = wp_upload_dir();
		$path = $upload_dir['basedir'] . '/canola.jpg';
		$path = $upload_dir['basedir'] . '/sunflower.jpg';
		copy( $this->image_path, $path );

		$image_editor = new WP_Image_Editor_Imagick( $path );

		$image_editor->load();
		$status = $image_editor->save( $upload_dir['basedir'] . '/canola-100x100.jpg' );
		$status = $image_editor->save( $upload_dir['basedir'] . '/sunflower-100x100.jpg' );

		$this->assertWPError( $status );
	}
@@ -40,19 +40,19 @@ class Test_S3_Uploads_Image_Editor_Imagick extends WP_UnitTestCase {
	public function test_save_image() {

		$upload_dir = wp_upload_dir();
		$path = $upload_dir['basedir'] . '/canola.jpg';
		$path = $upload_dir['basedir'] . '/sunflower.jpg';
		copy( $this->image_path, $path );

		$image_editor = new S3_Uploads_Image_Editor_Imagick( $path );

		$image_editor->load();
		$image_editor->resize( 100, 100, true );
		$status = $image_editor->save( $upload_dir['basedir'] . '/canola-100x100.jpg' );
		$status = $image_editor->save( $upload_dir['basedir'] . '/sunflower-100x100.jpg' );

		$this->assertNotInstanceOf( 'WP_Error', $status );

		$this->assertEquals( $upload_dir['basedir'] . '/canola-100x100.jpg', $status['path'] );
		$this->assertEquals( 'canola-100x100.jpg', $status['file'] );
		$this->assertEquals( $upload_dir['basedir'] . '/sunflower-100x100.jpg', $status['path'] );
		$this->assertEquals( 'sunflower-100x100.jpg', $status['file'] );
		$this->assertEquals( 100, $status['width'] );
		$this->assertEquals( 100, $status['height'] );

+22 −22
Original line number Diff line number Diff line
@@ -19,8 +19,8 @@ class Test_S3_Uploads_Stream_Wrapper extends WP_UnitTestCase {

	public function test_copy_via_stream_wrapper() {

		$local_path = dirname( __FILE__ ) . '/data/canola.jpg';
		$remote_path = 's3://' . S3_UPLOADS_BUCKET . '/canola.jpg';
		$local_path = dirname( __FILE__ ) . '/data/sunflower.jpg';
		$remote_path = 's3://' . S3_UPLOADS_BUCKET . '/sunflower.jpg';
		$result = copy( $local_path, $remote_path );
		$this->assertTrue( $result );
		$this->assertEquals( file_get_contents( $local_path ), file_get_contents( $remote_path ) );
@@ -28,18 +28,18 @@ class Test_S3_Uploads_Stream_Wrapper extends WP_UnitTestCase {

	public function test_rename_via_stream_wrapper() {

		copy( dirname( __FILE__ ) . '/data/canola.jpg', 's3://' . S3_UPLOADS_BUCKET . '/canola.jpg' );
		$result = rename( 's3://' . S3_UPLOADS_BUCKET . '/canola.jpg', 's3://' . S3_UPLOADS_BUCKET . '/canola-test.jpg' );
		copy( dirname( __FILE__ ) . '/data/sunflower.jpg', 's3://' . S3_UPLOADS_BUCKET . '/sunflower.jpg' );
		$result = rename( 's3://' . S3_UPLOADS_BUCKET . '/sunflower.jpg', 's3://' . S3_UPLOADS_BUCKET . '/sunflower-test.jpg' );
		$this->assertTrue( $result );
		$this->assertTrue( file_exists( 's3://' . S3_UPLOADS_BUCKET . '/canola-test.jpg' ) );
		$this->assertTrue( file_exists( 's3://' . S3_UPLOADS_BUCKET . '/sunflower-test.jpg' ) );
	}

	public function test_unlink_via_stream_wrapper() {

		copy( dirname( __FILE__ ) . '/data/canola.jpg', 's3://' . S3_UPLOADS_BUCKET . '/canola.jpg' );
		$result = unlink( 's3://' . S3_UPLOADS_BUCKET . '/canola.jpg' );
		copy( dirname( __FILE__ ) . '/data/sunflower.jpg', 's3://' . S3_UPLOADS_BUCKET . '/sunflower.jpg' );
		$result = unlink( 's3://' . S3_UPLOADS_BUCKET . '/sunflower.jpg' );
		$this->assertTrue( $result );
		$this->assertFalse( file_exists( 's3://' . S3_UPLOADS_BUCKET . '/canola.jpg' ) );
		$this->assertFalse( file_exists( 's3://' . S3_UPLOADS_BUCKET . '/sunflower.jpg' ) );
	}

	public function test_copy_via_stream_wrapper_fails_on_invalid_permission() {
@@ -50,14 +50,14 @@ class Test_S3_Uploads_Stream_Wrapper extends WP_UnitTestCase {
		$uploads->register_stream_wrapper();

		$bucket_root = strtok( S3_UPLOADS_BUCKET, '/' );
		$result = @copy( dirname( __FILE__ ) . '/data/canola.jpg', 's3://' . $bucket_root . '/canola.jpg' );
		$result = @copy( dirname( __FILE__ ) . '/data/sunflower.jpg', 's3://' . $bucket_root . '/sunflower.jpg' );

		$this->assertFalse( $result );
	}

	public function test_rename_via_stream_wrapper_fails_on_invalid_permission() {

		copy( dirname( __FILE__ ) . '/data/canola.jpg', 's3://' . S3_UPLOADS_BUCKET . '/canola.jpg' );
		copy( dirname( __FILE__ ) . '/data/sunflower.jpg', 's3://' . S3_UPLOADS_BUCKET . '/sunflower.jpg' );

		stream_wrapper_unregister( 's3' );

@@ -65,7 +65,7 @@ class Test_S3_Uploads_Stream_Wrapper extends WP_UnitTestCase {
		$uploads->register_stream_wrapper();

		$bucket_root = strtok( S3_UPLOADS_BUCKET, '/' );
		$result = @rename( 's3://' . S3_UPLOADS_BUCKET . '/canola.jpg', 's3://' . $bucket_root . '/canola.jpg' );
		$result = @rename( 's3://' . S3_UPLOADS_BUCKET . '/sunflower.jpg', 's3://' . $bucket_root . '/sunflower.jpg' );

		$this->assertFalse( $result );
	}
@@ -87,23 +87,23 @@ class Test_S3_Uploads_Stream_Wrapper extends WP_UnitTestCase {
	}

	public function get_file_exists_via_stream_wrapper() {
		copy( dirname( __FILE__ ) . '/data/canola.jpg', 's3://' . S3_UPLOADS_BUCKET . '/canola.jpg' );
		$this->assertTrue( file_exists( 's3://' . S3_UPLOADS_BUCKET . '/canola.jpg' ) );
		$this->assertFalse( file_exists( 's3://' . S3_UPLOADS_BUCKET . '/canola-missing.jpg' ) );
		copy( dirname( __FILE__ ) . '/data/sunflower.jpg', 's3://' . S3_UPLOADS_BUCKET . '/sunflower.jpg' );
		$this->assertTrue( file_exists( 's3://' . S3_UPLOADS_BUCKET . '/sunflower.jpg' ) );
		$this->assertFalse( file_exists( 's3://' . S3_UPLOADS_BUCKET . '/sunflower-missing.jpg' ) );
	}

	public function test_getimagesize_via_stream_wrapper() {

		copy( dirname( __FILE__ ) . '/data/canola.jpg', 's3://' . S3_UPLOADS_BUCKET . '/canola.jpg' );
		$file = 's3://' . S3_UPLOADS_BUCKET . '/canola.jpg';
		copy( dirname( __FILE__ ) . '/data/sunflower.jpg', 's3://' . S3_UPLOADS_BUCKET . '/sunflower.jpg' );
		$file = 's3://' . S3_UPLOADS_BUCKET . '/sunflower.jpg';

		$image = getimagesize( $file );

		$this->assertEquals( array(
			640,
			480,
			419,
			2,
			'width="640" height="480"',
			'width="640" height="419"',
			'bits' => 8,
			'channels' => 3,
			'mime' => 'image/jpeg',
@@ -112,8 +112,8 @@ class Test_S3_Uploads_Stream_Wrapper extends WP_UnitTestCase {

	public function test_stream_wrapper_supports_seeking() {

		$file = 's3://' . S3_UPLOADS_BUCKET . '/canola.jpg';
		copy( dirname( __FILE__ ) . '/data/canola.jpg', $file );
		$file = 's3://' . S3_UPLOADS_BUCKET . '/sunflower.jpg';
		copy( dirname( __FILE__ ) . '/data/sunflower.jpg', $file );

		$f = fopen( $file, 'r' );
		$result = fseek( $f, 0, SEEK_END );
@@ -124,8 +124,8 @@ class Test_S3_Uploads_Stream_Wrapper extends WP_UnitTestCase {

	public function test_wp_handle_upload() {

		$path = tempnam( sys_get_temp_dir(), 'canola' ) . '.jpg';
		copy( dirname( __FILE__ ) . '/data/canola.jpg', $path );
		$path = tempnam( sys_get_temp_dir(), 'sunflower' ) . '.jpg';
		copy( dirname( __FILE__ ) . '/data/sunflower.jpg', $path );
		$contents = file_get_contents( $path );
		$file = array(
			'error'    => null,
+9 −6
Original line number Diff line number Diff line
@@ -71,8 +71,8 @@ class Test_S3_Uploads extends WP_UnitTestCase {
	public function test_generate_attachment_metadata() {
		S3_Uploads::get_instance()->setup();
		$upload_dir = wp_upload_dir();
		copy( dirname( __FILE__ ) . '/data/canola.jpg', $upload_dir['path'] . '/canola.jpg' );
		$test_file = $upload_dir['path'] . '/canola.jpg';
		copy( dirname( __FILE__ ) . '/data/sunflower.jpg', $upload_dir['path'] . '/sunflower.jpg' );
		$test_file = $upload_dir['path'] . '/sunflower.jpg';
		$attachment_id = $this->factory->attachment->create_object( $test_file, 0, array(
			'post_mime_type' => 'image/jpeg',
			'post_excerpt'   => 'A sample caption',
@@ -81,21 +81,24 @@ class Test_S3_Uploads extends WP_UnitTestCase {
		$meta_data = wp_generate_attachment_metadata( $attachment_id, $test_file );

		$this->assertEquals( array(
			'file'      => 'canola-150x150.jpg',
			'file'      => 'sunflower-150x150.jpg',
			'width'     => 150,
			'height'    => 150,
			'mime-type' => 'image/jpeg',
		), $meta_data['sizes']['thumbnail'] );

		$this->assertTrue( 'X-T10' === $meta_data['image_meta']['camera'] );
		$this->assertTrue( '500' === $meta_data['image_meta']['iso'] );

		$wp_upload_dir = wp_upload_dir();
		$this->assertTrue( file_exists( $wp_upload_dir['path'] . '/canola-150x150.jpg' ) );
		$this->assertTrue( file_exists( $wp_upload_dir['path'] . '/sunflower-150x150.jpg' ) );
	}

	public function test_image_sizes_are_deleted_on_attachment_delete() {
		S3_Uploads::get_instance()->setup();
		$upload_dir = wp_upload_dir();
		copy( dirname( __FILE__ ) . '/data/canola.jpg', $upload_dir['path'] . '/canola.jpg' );
		$test_file = $upload_dir['path'] . '/canola.jpg';
		copy( dirname( __FILE__ ) . '/data/sunflower.jpg', $upload_dir['path'] . '/sunflower.jpg' );
		$test_file = $upload_dir['path'] . '/sunflower.jpg';
		$attachment_id = $this->factory->attachment->create_object( $test_file, 0, array(
			'post_mime_type' => 'image/jpeg',
			'post_excerpt'   => 'A sample caption',
+1 −1

File changed.

Contains only whitespace changes.

Loading