Make WordPress Core

Ticket #41816: 41816-unit-tests.diff

File 41816-unit-tests.diff, 4.6 KB (added by pbiron, 6 years ago)
  • tests/phpunit/tests/media.php

    From 5e779db43c0ce7254e93d7929e878e8090e76e55 Mon Sep 17 00:00:00 2001
    From: Paul Biron <paul@sparrowhawkcomputing.com>
    Date: Wed, 6 Sep 2017 09:47:09 -0600
    Subject: [PATCH] unit tests
    
    ---
     tests/phpunit/tests/media.php | 83 +++++++++++++++++++++++++++++--------------
     1 file changed, 56 insertions(+), 27 deletions(-)
    
    diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php
    index 392c039..4be585c 100644
    a b VIDEO; 
    876876
    877877        /**
    878878         * @ticket 30346
     879         * @ticket 41816
    879880         */
    880881        function test_attachment_url_to_postid() {
    881                 $image_path = '2014/11/' . $this->img_name;
    882                 $attachment_id = self::factory()->attachment->create_object( $image_path, 0, array(
    883                         'post_mime_type' => 'image/jpeg',
    884                         'post_type'      => 'attachment',
    885                 ) );
     882                $filename = DIR_TESTDATA . '/images/canola.jpg';
     883                $attachment_id = self::factory()->attachment->create_upload_object( $filename );
     884                $this->assertEquals( $attachment_id, attachment_url_to_postid( wp_get_attachment_url( $attachment_id ) ) );
     885        }
    886886
    887                 $image_url  = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path;
    888                 $this->assertEquals( $attachment_id, attachment_url_to_postid( $image_url ) );
     887        /**
     888         * @ticket 41816
     889         */
     890        function test_attachment_url_to_postid_intermediate_size() {
     891                $filename = DIR_TESTDATA . '/images/canola.jpg';
     892                $attachment_id = self::factory()->attachment->create_upload_object( $filename );
     893                $image = image_downsize( $attachment_id, 'thumbnail' );
     894                $this->assertEquals( $attachment_id, attachment_url_to_postid( $image[0] ) );
    889895        }
    890896
    891         function test_attachment_url_to_postid_schemes() {
    892                 $image_path = '2014/11/' . $this->img_name;
    893                 $attachment_id = self::factory()->attachment->create_object( $image_path, 0, array(
    894                         'post_mime_type' => 'image/jpeg',
    895                         'post_type'      => 'attachment',
    896                 ) );
    897897
    898                 /**
    899                  * @ticket 33109 Testing protocols not matching
    900                  */
    901                 $image_url  = 'https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path;
    902                 $this->assertEquals( $attachment_id, attachment_url_to_postid( $image_url ) );
     898        /**
     899         * @ticket 41816
     900         */
     901        function test_attachment_url_to_postid_non_existent_intermediate_size() {
     902                $filename = DIR_TESTDATA . '/images/canola.jpg';
     903                $attachment_id = self::factory()->attachment->create_upload_object( $filename );
     904                $image = image_downsize( $attachment_id, 'thumbnail' );
     905                // mod the URL to a non-existent size
     906                $width = get_option( 'thumbnail_size_w' );
     907                $height = get_option( 'thumbnail_size_h' );
     908                $image[0] = str_replace( "{$width}x{$height}", '0x0', $image[0] );
     909                // should not find the post_id
     910                $this->assertEquals( 0, attachment_url_to_postid( $image[0] ) );
    903911        }
    904912
    905         function test_attachment_url_to_postid_filtered() {
    906                 $image_path = '2014/11/' . $this->img_name;
    907                 $attachment_id = self::factory()->attachment->create_object( $image_path, 0, array(
    908                         'post_mime_type' => 'image/jpeg',
    909                         'post_type'      => 'attachment',
    910                 ) );
     913        /**
     914         * @ticket 41816
     915         */
     916        function test_attachment_url_to_postid_audio_video() {
     917                $filename = DIR_TESTDATA . '/uploads/small-audio.mp3';
     918                $attachment_id = self::factory()->attachment->create_upload_object( $filename );
     919                $this->assertEquals( $attachment_id, attachment_url_to_postid( wp_get_attachment_url( $attachment_id ) ) );
     920
     921                $filename = DIR_TESTDATA . '/uploads/small-video.mp4';
     922                $attachment_id = self::factory()->attachment->create_upload_object( $filename );
     923                $this->assertEquals( $attachment_id, attachment_url_to_postid( wp_get_attachment_url( $attachment_id ) ) );
     924        }
     925
     926        /**
     927         * @ticket 33109 Testing protocols not matching
     928         * @ticket 41816
     929         */
     930        function test_attachment_url_to_postid_schemes() {
     931                $filename = DIR_TESTDATA . '/images/canola.jpg';
     932                $attachment_id = self::factory()->attachment->create_upload_object( $filename );
     933                $this->assertEquals( $attachment_id, attachment_url_to_postid( set_url_scheme( wp_get_attachment_url( $attachment_id ), 'https' ) ) );
     934        }
    911935
    912                 add_filter( 'upload_dir', array( $this, '_upload_dir' ) );
    913                 $image_url = 'http://192.168.1.20.com/wp-content/uploads/' . $image_path;
    914                 $this->assertEquals( $attachment_id, attachment_url_to_postid( $image_url ) );
     936        /**
     937         * @ticket 41816
     938         */
     939        function test_attachment_url_to_postid_filtered() {
     940                add_filter( 'upload_dir', array( $this, '_upload_dir' ) );
     941                $filename = DIR_TESTDATA . '/images/canola.jpg';
     942                $attachment_id = self::factory()->attachment->create_upload_object( $filename );
     943                $this->assertEquals( $attachment_id, attachment_url_to_postid( wp_get_attachment_url( $attachment_id ) ) );
    915944                remove_filter( 'upload_dir', array( $this, '_upload_dir' ) );
    916945        }
    917946