Make WordPress Core

Ticket #58163: attachment-tests.diff

File attachment-tests.diff, 3.6 KB (added by Howdy_McGee, 22 months ago)

Unit Tests

  • tests/phpunit/tests/media.php

     
    39743974        }
    39753975
    39763976        /**
     3977         * Test that the attachment URL is correctly returned or FALSE when not found.
     3978         */
     3979        public function test_wp_get_attachment_url() {
     3980                $this->assertFalse( wp_get_attachment_url( 0 ) );
     3981
     3982                $str = wp_get_attachment_url( self::$large_id );
     3983                $this->assertNotEmpty( $str );
     3984        }
     3985
     3986        /**
     3987         * Test that the attachment metadata is correctly returning an associative array or FALSE when not found.
     3988         */
     3989        public function test_wp_get_attachment_metadata() {
     3990                $this->assertFalse( wp_get_attachment_metadata( 0 ) );
     3991
     3992                $arr = wp_get_attachment_metadata( self::$large_id );
     3993                $this->assertNotEmpty( $arr['filesize'] );
     3994        }
     3995
     3996        /**
     3997         * Test that the image downsize is correctly returning a flat array or FALSE when not found.
     3998         */
     3999        public function test_image_downsize() {
     4000                $this->assertFalse( image_downsize( 0 ) );
     4001
     4002                $arr = image_downsize( self::$large_id );
     4003                $this->assertNotEmpty( $arr[1] );
     4004        }
     4005
     4006        /**
     4007         * Test that the image tag is correctly returning an HTML IMG tag with a populated src attribute.
     4008         */
     4009        public function test_get_image_tag() {
     4010                $document = new \DOMDocument();
     4011                $img_tag  = get_image_tag( self::$large_id, 'foo', 'bar', 'center' );
     4012                $document->loadHTML( $img_tag );
     4013                $document_img = $document->getElementsByTagName( 'img' )->item( 0 );
     4014
     4015                $this->assertNotNull( $document_img );
     4016
     4017                $img_tag_src = $document_img->getAttribute( 'src' );
     4018
     4019                $this->assertNotEmpty( $img_tag_src );
     4020        }
     4021
     4022        /**
     4023         * Test that the image tag is returning an HTML IMG tag with an empty src attribute
     4024         * whenever the attachment does not exist.
     4025         */
     4026        public function test_get_image_tag_empty_src() {
     4027                $document = new \DOMDocument();
     4028                $img_tag  = get_image_tag( 0, 'foo', 'bar', 'center' );
     4029                $document->loadHTML( $img_tag );
     4030                $document_img = $document->getElementsByTagName( 'img' )->item( 0 );
     4031
     4032                $this->assertNotNull( $document_img );
     4033
     4034                $img_tag_src = $document_img->getAttribute( 'src' );
     4035
     4036                $this->assertEmpty( $img_tag_src );
     4037        }
     4038
     4039        /**
     4040         * Test that the intermediate size function is correctly returning an associative array or FALSE when not found.
     4041         */
     4042        public function test_image_get_intermediate_size() {
     4043                $this->assertFalse( image_get_intermediate_size( 0 ) );
     4044
     4045                $arr = image_get_intermediate_size( self::$large_id );
     4046                $this->assertNotEmpty( $arr['file'] );
     4047        }
     4048
     4049        /**
     4050         * Test that the attachment image src function is correctly returning a flat array or FALSE when not found.
     4051         */
     4052        public function test_wp_get_attachment_image_src() {
     4053                $this->assertFalse( wp_get_attachment_image_src( 0 ) );
     4054
     4055                $arr = wp_get_attachment_image_src( self::$large_id );
     4056                $this->assertNotEmpty( $arr[1] );
     4057        }
     4058
     4059        /**
     4060         * Test that the attachment image is correctly returning an HTML IMG tag with a populated src attribute.
     4061         * Otherwise, return an empty string if the attachment is not found.
     4062         */
     4063        public function test_wp_get_attachment_image() {
     4064                $this->assertEmpty( wp_get_attachment_image( 0 ) );
     4065
     4066                $document = new \DOMDocument();
     4067                $img_tag  = wp_get_attachment_image( self::$large_id );
     4068                $document->loadHTML( $img_tag );
     4069                $document_img = $document->getElementsByTagName( 'img' )->item( 0 );
     4070
     4071                $this->assertNotNull( $document_img );
     4072
     4073                $img_tag_src = $document_img->getAttribute( 'src' );
     4074
     4075                $this->assertNotEmpty( $img_tag_src );
     4076        }
     4077
     4078        /**
    39774079         * Add threshold to create a `-scaled` output image for testing.
    39784080         */
    39794081        public function add_big_image_size_threshold() {