Loading tests/data/canola.jpg +174 KiB (198 KiB) Loading image diff... tests/test-s3-uploads.php +44 −0 Original line number Diff line number Diff line Loading @@ -67,4 +67,48 @@ class Test_S3_Uploads extends WP_UnitTestCase { $this->assertInstanceOf( 'Aws\\S3\\S3Client', $s3 ); } 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'; $attachment_id = $this->factory->attachment->create_object( $test_file, 0, array( 'post_mime_type' => 'image/jpeg', 'post_excerpt' => 'A sample caption', ) ); $meta_data = wp_generate_attachment_metadata( $attachment_id, $test_file ); $this->assertEquals( array( 'file' => 'canola-150x150.jpg', 'width' => 150, 'height' => 150, 'mime-type' => 'image/jpeg', ), $meta_data['sizes']['thumbnail'] ); $wp_upload_dir = wp_upload_dir(); $this->assertTrue( file_exists( $wp_upload_dir['path'] . '/canola-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'; $attachment_id = $this->factory->attachment->create_object( $test_file, 0, array( 'post_mime_type' => 'image/jpeg', 'post_excerpt' => 'A sample caption', ) ); $meta_data = wp_generate_attachment_metadata( $attachment_id, $test_file ); foreach ( $meta_data['sizes'] as $size ) { $this->assertTrue( file_exists( $upload_dir['path'] . '/' . $size['file'] ) ); } wp_delete_attachment( $attachment_id, true ); foreach ( $meta_data['sizes'] as $size ) { $this->assertFalse( file_exists( $upload_dir['path'] . '/' . $size['file'] ) ); } } } Loading
tests/test-s3-uploads.php +44 −0 Original line number Diff line number Diff line Loading @@ -67,4 +67,48 @@ class Test_S3_Uploads extends WP_UnitTestCase { $this->assertInstanceOf( 'Aws\\S3\\S3Client', $s3 ); } 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'; $attachment_id = $this->factory->attachment->create_object( $test_file, 0, array( 'post_mime_type' => 'image/jpeg', 'post_excerpt' => 'A sample caption', ) ); $meta_data = wp_generate_attachment_metadata( $attachment_id, $test_file ); $this->assertEquals( array( 'file' => 'canola-150x150.jpg', 'width' => 150, 'height' => 150, 'mime-type' => 'image/jpeg', ), $meta_data['sizes']['thumbnail'] ); $wp_upload_dir = wp_upload_dir(); $this->assertTrue( file_exists( $wp_upload_dir['path'] . '/canola-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'; $attachment_id = $this->factory->attachment->create_object( $test_file, 0, array( 'post_mime_type' => 'image/jpeg', 'post_excerpt' => 'A sample caption', ) ); $meta_data = wp_generate_attachment_metadata( $attachment_id, $test_file ); foreach ( $meta_data['sizes'] as $size ) { $this->assertTrue( file_exists( $upload_dir['path'] . '/' . $size['file'] ) ); } wp_delete_attachment( $attachment_id, true ); foreach ( $meta_data['sizes'] as $size ) { $this->assertFalse( file_exists( $upload_dir['path'] . '/' . $size['file'] ) ); } } }