Make WordPress Core

Ticket #26823: ticket_26823_and unit_tests.patch

File ticket_26823_and unit_tests.patch, 16.8 KB (added by pbearne, 12 years ago)

combined patches and test for 3.9

  • src/wp-includes/class-wp-image-editor-gd.php

     
    205205                $orig_size = $this->size;
    206206
    207207                foreach ( $sizes as $size => $size_data ) {
    208                         if ( ! ( isset( $size_data['width'] ) && isset( $size_data['height'] ) ) )
     208                        if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) )
    209209                                continue;
    210210
     211                        if ( ! isset( $size_data['width'] ) )
     212                                $size_data['width'] = 0;
     213                        if ( ! isset( $size_data['height'] ) )
     214                                $size_data['height'] = 0;
     215
    211216                        if ( ! isset( $size_data['crop'] ) )
    212217                                $size_data['crop'] = false;
    213218
  • src/wp-includes/class-wp-image-editor-imagick.php

     
    272272                        if ( ! $this->image )
    273273                                $this->image = $orig_image->getImage();
    274274
    275                         if ( ! ( isset( $size_data['width'] ) && isset( $size_data['height'] ) ) )
     275                        if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) )
    276276                                continue;
    277277
     278                        if ( ! isset( $size_data['width'] ) )
     279                                $size_data['width'] = 0;
     280                        if ( ! isset( $size_data['height'] ) )
     281                                $size_data['height'] = 0;
     282
     283
    278284                        if ( ! isset( $size_data['crop'] ) )
    279285                                $size_data['crop'] = false;
    280286
  • tests/phpunit/tests/image/editor_gd.php

     
    3434         */
    3535        public function test_resize() {
    3636
    37                 $file = DIR_TESTDATA . '/images/gradient-square.jpg';
     37                $file = DIR_TESTDATA . '/images/waffles.jpg';
    3838
    3939                $gd_image_editor = new WP_Image_Editor_GD( $file );
    4040                $gd_image_editor->load();
     
    4141
    4242                $gd_image_editor->resize( 100, 50 );
    4343
    44                 $this->assertEquals( array( 'width' => 50, 'height' => 50 ), $gd_image_editor->get_size() );
     44                $this->assertEquals( array( 'width' => 75, 'height' => 50 ), $gd_image_editor->get_size() );
    4545        }
    4646
    4747        /**
     48         * Test resizing an multi resizong image, not using crop
     49         *
     50         */
     51        public function test_multi_resize() {
     52
     53                $file = DIR_TESTDATA . '/images/waffles.jpg';
     54
     55                $gd_image_editor = new WP_Image_Editor_GD( $file );
     56                $gd_image_editor->load();
     57                $sizes_array =  array(
     58                                        array ('width' => 50, 'height' => 50 )
     59                                        );
     60                $resized = $gd_image_editor->multi_resize( $sizes_array );
     61
     62                $expected_array = array(
     63                                        array ( 'file' => 'waffles-50x33.jpg',
     64                                                        'width' => 50,
     65                                                        'height' => 33,
     66                                                        'mime-type' => 'image/jpeg')
     67                                        );
     68
     69                $this->assertEquals( $expected_array, $resized );
     70        }
     71
     72        /**
     73         * Test resizing an multi resizong image, and then load the image to check size
     74         *
     75         */
     76        public function test_multi_resize_check_is_resized() {
     77
     78                $file = DIR_TESTDATA . '/images/waffles.jpg';
     79
     80                $gd_image_editor = new WP_Image_Editor_GD( $file );
     81                $gd_image_editor->load();
     82                $sizes_array =  array(
     83                                        array ('width' => 50, 'height' => 50 )
     84                                        );
     85                $resized = $gd_image_editor->multi_resize( $sizes_array );
     86
     87       
     88                $gd_image_output = new WP_Image_Editor_GD( DIR_TESTDATA . '/images/'. $resized[0]['file'] );
     89                $gd_image_output->load();
     90
     91                $this->assertEquals( array( 'width' => 50, 'height' => 33  ), $gd_image_output->get_size() );
     92        }
     93
     94        /**
     95         * Test resizing an multi resizong image array in array out
     96         *
     97         */
     98        public function test_multi_resize_array() {
     99
     100                $file = DIR_TESTDATA . '/images/waffles.jpg';
     101
     102                $gd_image_editor = new WP_Image_Editor_GD( $file );
     103                $gd_image_editor->load();
     104                $sizes_array =     array(
     105                // #1 - resizes to 100x100 pixel, square-cropped image
     106                array ('width' => 10, 'height' => 10, 'crop' => false),
     107                // #2 - resizes to 200 pixel max width/height, non-cropped image
     108                array ('width' => 75, 'height' => 50, 'crop' => true),
     109                // #3 - resizes to 200 pixel max height, non-cropped image
     110                array ('width' => 9999, 'height' => 20, 'crop' => false),
     111                // #3 - resizes to 450 pixel max width, non-cropped image
     112                array ('width' => 45, 'height' => 9999, 'crop' => true)
     113            );
     114         
     115            $resized = $gd_image_editor->multi_resize( $sizes_array );
     116
     117            $expected_array = array(
     118                // #1 - resizes to 100x100 pixel, square-cropped image
     119                array ( 'file' => 'waffles-10x6.jpg',
     120                                'width' => 10,
     121                                'height' => 6 ,
     122                                'mime-type' => 'image/jpeg'),
     123                // #2 - resizes to 200 pixel max width/height, square-cropped image
     124                array ( 'file' => 'waffles-75x50.jpg',
     125                                'width' => 75,
     126                                'height' => 50,
     127                                'mime-type' => 'image/jpeg'),
     128                // #3 - resizes to 200 pixel max height, non-cropped image
     129                array ( 'file' => 'waffles-30x20.jpg',
     130                                'width' => 30,
     131                                'height' => 20,
     132                                'mime-type' => 'image/jpeg'),
     133                // #3 - resizes to 450 pixel max width, non-cropped image
     134                array ( 'file' => 'waffles-45x400.jpg',
     135                                'width' => 45,
     136                                'height' => 400,
     137                                'mime-type' => 'image/jpeg')
     138            );
     139
     140
     141                $this->assertEquals( $expected_array, $resized );
     142        }
     143
     144        /**
     145         * Test resizing an image, no height
     146         *
     147         */
     148        public function test_multi_resize_mising_height() {
     149
     150                $file = DIR_TESTDATA . '/images/waffles.jpg';
     151
     152                $gd_image_editor = new WP_Image_Editor_GD( $file );
     153                $gd_image_editor->load();
     154                $sizes_array =  array(
     155                                        array ('width' => 50)
     156                                        );
     157                $resized =  $gd_image_editor->multi_resize( $sizes_array );
     158
     159                $expected_array = array(
     160                                        array ( 'file' => 'waffles-50x33.jpg',
     161                                                        'width' => 50,
     162                                                        'height' => 33,
     163                                                        'mime-type' => 'image/jpeg')
     164                                        );
     165
     166                $this->assertEquals( $expected_array, $resized );
     167        }
     168        // /**
     169        //  * Test resizing an multi resize image, no width
     170        //  *
     171        //  */
     172        public function test_multi_resize_mising_width() {
     173
     174                $file = DIR_TESTDATA . '/images/waffles.jpg';
     175
     176                $gd_image_editor = new WP_Image_Editor_GD( $file );
     177                $gd_image_editor->load();
     178                $sizes_array =  array(
     179                                        array ( 'height' => 50 )
     180                                        );
     181                $resized =  $gd_image_editor->multi_resize( $sizes_array );
     182
     183                $expected_array = array(
     184                                        array ( 'file' => 'waffles-75x50.jpg',
     185                                                        'width' => 75,
     186                                                        'height' => 50,
     187                                                        'mime-type' => 'image/jpeg')
     188                                        );
     189
     190                $this->assertEquals( $expected_array, $resized );
     191        }
     192       
     193        // /**
     194        //  * Test resizing an multi resize image, null input
     195        //  *
     196        //  */
     197        public function test_multi_resize_width_set_to_null() {
     198
     199                $file = DIR_TESTDATA . '/images/waffles.jpg';
     200
     201                $gd_image_editor = new WP_Image_Editor_GD( $file );
     202                $gd_image_editor->load();
     203                $sizes_array =  array(
     204                                        array ( 'height' => 50,'width' => null )
     205                                        );
     206                $resized =  $gd_image_editor->multi_resize( $sizes_array );
     207
     208                $expected_array = array(
     209                                        array ( 'file' => 'waffles-75x50.jpg',
     210                                                        'width' => 75,
     211                                                        'height' => 50,
     212                                                        'mime-type' => 'image/jpeg')
     213                                        );
     214
     215                $this->assertEquals( $expected_array, $resized );
     216        }
     217        // /**
     218        //  * Test resizing an multi resize image, Null import
     219        //  *
     220        //  */
     221        public function test_multi_resize_height_set_to_null() {
     222
     223                $file = DIR_TESTDATA . '/images/waffles.jpg';
     224
     225                $gd_image_editor = new WP_Image_Editor_GD( $file );
     226                $gd_image_editor->load();
     227                $sizes_array =  array(
     228                                        array ( 'height' => null,'width' => 50 )
     229                                        );
     230                $resized =  $gd_image_editor->multi_resize( $sizes_array );
     231
     232                $expected_array = array(
     233                                        array ( 'file' => 'waffles-50x33.jpg',
     234                                                        'width' => 50,
     235                                                        'height' => 33,
     236                                                        'mime-type' => 'image/jpeg')
     237                                        );
     238
     239                $this->assertEquals( $expected_array, $resized );
     240        }
     241       
     242        // /**
     243        //  * Test resizing an multi resize image, missus value
     244        //  *
     245        //  */
     246        public function test_multi_resize_width_set_to_missus() {
     247
     248                $file = DIR_TESTDATA . '/images/waffles.jpg';
     249
     250                $gd_image_editor = new WP_Image_Editor_GD( $file );
     251                $gd_image_editor->load();
     252                $sizes_array =  array(
     253                                        array ( 'height' => 50,'width' => -50 )
     254                                        );
     255                $resized =  $gd_image_editor->multi_resize( $sizes_array );
     256
     257                $expected_array = array(
     258                                        array ( 'file' => 'waffles-75x50.jpg',
     259                                                        'width' => 75,
     260                                                        'height' => 50,
     261                                                        'mime-type' => 'image/jpeg')
     262                                        );
     263
     264                $this->assertEquals( $expected_array, $resized );
     265        }
     266        // /**
     267        //  * Test resizing an multi resize image, missus value
     268        //  *
     269        //  */
     270        public function test_multi_resize_height_set_to_missus() {
     271
     272                $file = DIR_TESTDATA . '/images/waffles.jpg';
     273
     274                $gd_image_editor = new WP_Image_Editor_GD( $file );
     275                $gd_image_editor->load();
     276                $sizes_array =  array(
     277                                        array ( 'height' => -65119,'width' => 200 )
     278                                        );
     279                $resized =  $gd_image_editor->multi_resize( $sizes_array );
     280
     281                $expected_array = array(
     282                                        array ( 'file' => 'waffles-200x133.jpg',
     283                                                        'width' => 200,
     284                                                        'height' => 133,
     285                                                        'mime-type' => 'image/jpeg')
     286                                        );
     287
     288                $this->assertEquals( $expected_array, $resized );
     289        }
     290
     291
     292
     293        /**
    48294         * Test resizing an image including cropping
    49295         *
    50296         */
  • tests/phpunit/tests/image/editor_imagick.php

     
    5151
    5252                $this->assertEquals( array( 'width' => 50, 'height' => 50 ), $imagick_image_editor->get_size() );
    5353        }
     54/**
     55         * Test resizing an multi resizong image, not using crop
     56         *
     57         */
     58        public function test_multi_resize() {
    5459
     60                $file = DIR_TESTDATA . '/images/waffles.jpg';
     61
     62                $gd_image_editor = new WP_Image_Editor_Imagick( $file );
     63                $gd_image_editor->load();
     64                $sizes_array =  array(
     65                                        array ('width' => 50, 'height' => 50 )
     66                                        );
     67                $resized = $gd_image_editor->multi_resize( $sizes_array );
     68
     69                $expected_array = array(
     70                                        array ( 'file' => 'waffles-50x33.jpg',
     71                                                        'width' => 50,
     72                                                        'height' => 33,
     73                                                        'mime-type' => 'image/jpeg')
     74                                        );
     75
     76                $this->assertEquals( $expected_array, $resized );
     77        }
     78
    5579        /**
     80         * Test resizing an multi resizong image, and then load the image to check size
     81         *
     82         */
     83        public function test_multi_resize_check_is_resized() {
     84
     85                $file = DIR_TESTDATA . '/images/waffles.jpg';
     86
     87                $gd_image_editor = new WP_Image_Editor_Imagick( $file );
     88                $gd_image_editor->load();
     89                $sizes_array =  array(
     90                                        array ('width' => 50, 'height' => 50 )
     91                                        );
     92                $resized = $gd_image_editor->multi_resize( $sizes_array );
     93
     94       
     95                $gd_image_output = new WP_Image_Editor_Imagick( DIR_TESTDATA . '/images/'. $resized[0]['file'] );
     96                $gd_image_output->load();
     97
     98                $this->assertEquals( array( 'width' => 50, 'height' => 33  ), $gd_image_output->get_size() );
     99        }
     100
     101        /**
     102         * Test resizing an multi resizong image array in array out
     103         *
     104         */
     105        public function test_multi_resize_array() {
     106
     107                $file = DIR_TESTDATA . '/images/waffles.jpg';
     108
     109                $gd_image_editor = new WP_Image_Editor_Imagick( $file );
     110                $gd_image_editor->load();
     111                $sizes_array =     array(
     112                // #1 - resizes to 100x100 pixel, square-cropped image
     113                array ('width' => 10, 'height' => 10, 'crop' => false),
     114                // #2 - resizes to 200 pixel max width/height, non-cropped image
     115                array ('width' => 75, 'height' => 50, 'crop' => true),
     116                // #3 - resizes to 200 pixel max height, non-cropped image
     117                array ('width' => 9999, 'height' => 20, 'crop' => false),
     118                // #3 - resizes to 450 pixel max width, non-cropped image
     119                array ('width' => 45, 'height' => 9999, 'crop' => true)
     120            );
     121         
     122            $resized = $gd_image_editor->multi_resize( $sizes_array );
     123
     124            $expected_array = array(
     125                // #1 - resizes to 100x100 pixel, square-cropped image
     126                array ( 'file' => 'waffles-10x6.jpg',
     127                                'width' => 10,
     128                                'height' => 6 ,
     129                                'mime-type' => 'image/jpeg'),
     130                // #2 - resizes to 200 pixel max width/height, square-cropped image
     131                array ( 'file' => 'waffles-75x50.jpg',
     132                                'width' => 75,
     133                                'height' => 50,
     134                                'mime-type' => 'image/jpeg'),
     135                // #3 - resizes to 200 pixel max height, non-cropped image
     136                array ( 'file' => 'waffles-30x20.jpg',
     137                                'width' => 30,
     138                                'height' => 20,
     139                                'mime-type' => 'image/jpeg'),
     140                // #3 - resizes to 450 pixel max width, non-cropped image
     141                array ( 'file' => 'waffles-45x400.jpg',
     142                                'width' => 45,
     143                                'height' => 400,
     144                                'mime-type' => 'image/jpeg')
     145            );
     146
     147
     148                $this->assertEquals( $expected_array, $resized );
     149        }
     150
     151        /**
     152         * Test resizing an image, no height
     153         *
     154         */
     155        public function test_multi_resize_mising_height() {
     156
     157                $file = DIR_TESTDATA . '/images/waffles.jpg';
     158
     159                $gd_image_editor = new WP_Image_Editor_Imagick( $file );
     160                $gd_image_editor->load();
     161                $sizes_array =  array(
     162                                        array ('width' => 50)
     163                                        );
     164                $resized =  $gd_image_editor->multi_resize( $sizes_array );
     165
     166                $expected_array = array(
     167                                        array ( 'file' => 'waffles-50x33.jpg',
     168                                                        'width' => 50,
     169                                                        'height' => 33,
     170                                                        'mime-type' => 'image/jpeg')
     171                                        );
     172
     173                $this->assertEquals( $expected_array, $resized );
     174        }
     175        // /**
     176        //  * Test resizing an multi resize image, no width
     177        //  *
     178        //  */
     179        public function test_multi_resize_mising_width() {
     180
     181                $file = DIR_TESTDATA . '/images/waffles.jpg';
     182
     183                $gd_image_editor = new WP_Image_Editor_Imagick( $file );
     184                $gd_image_editor->load();
     185                $sizes_array =  array(
     186                                        array ( 'height' => 50 )
     187                                        );
     188                $resized =  $gd_image_editor->multi_resize( $sizes_array );
     189
     190                $expected_array = array(
     191                                        array ( 'file' => 'waffles-75x50.jpg',
     192                                                        'width' => 75,
     193                                                        'height' => 50,
     194                                                        'mime-type' => 'image/jpeg')
     195                                        );
     196
     197                $this->assertEquals( $expected_array, $resized );
     198        }
     199       
     200        // /**
     201        //  * Test resizing an multi resize image, null input
     202        //  *
     203        //  */
     204        public function test_multi_resize_width_set_to_null() {
     205
     206                $file = DIR_TESTDATA . '/images/waffles.jpg';
     207
     208                $gd_image_editor = new WP_Image_Editor_Imagick( $file );
     209                $gd_image_editor->load();
     210                $sizes_array =  array(
     211                                        array ( 'height' => 50,'width' => null )
     212                                        );
     213                $resized =  $gd_image_editor->multi_resize( $sizes_array );
     214
     215                $expected_array = array(
     216                                        array ( 'file' => 'waffles-75x50.jpg',
     217                                                        'width' => 75,
     218                                                        'height' => 50,
     219                                                        'mime-type' => 'image/jpeg')
     220                                        );
     221
     222                $this->assertEquals( $expected_array, $resized );
     223        }
     224        // /**
     225        //  * Test resizing an multi resize image, Null import
     226        //  *
     227        //  */
     228        public function test_multi_resize_height_set_to_null() {
     229
     230                $file = DIR_TESTDATA . '/images/waffles.jpg';
     231
     232                $gd_image_editor = new WP_Image_Editor_Imagick( $file );
     233                $gd_image_editor->load();
     234                $sizes_array =  array(
     235                                        array ( 'height' => null,'width' => 50 )
     236                                        );
     237                $resized =  $gd_image_editor->multi_resize( $sizes_array );
     238
     239                $expected_array = array(
     240                                        array ( 'file' => 'waffles-50x33.jpg',
     241                                                        'width' => 50,
     242                                                        'height' => 33,
     243                                                        'mime-type' => 'image/jpeg')
     244                                        );
     245
     246                $this->assertEquals( $expected_array, $resized );
     247        }
     248       
     249        // /**
     250        //  * Test resizing an multi resize image, missus value
     251        //  *
     252        //  */
     253        public function test_multi_resize_width_set_to_missus() {
     254
     255                $file = DIR_TESTDATA . '/images/waffles.jpg';
     256
     257                $gd_image_editor = new WP_Image_Editor_Imagick( $file );
     258                $gd_image_editor->load();
     259                $sizes_array =  array(
     260                                        array ( 'height' => 50,'width' => -50 )
     261                                        );
     262                $resized =  $gd_image_editor->multi_resize( $sizes_array );
     263
     264                $expected_array = array(
     265                                        array ( 'file' => 'waffles-75x50.jpg',
     266                                                        'width' => 75,
     267                                                        'height' => 50,
     268                                                        'mime-type' => 'image/jpeg')
     269                                        );
     270
     271                $this->assertEquals( $expected_array, $resized );
     272        }
     273        // /**
     274        //  * Test resizing an multi resize image, missus value
     275        //  *
     276        //  */
     277        public function test_multi_resize_height_set_to_missus() {
     278
     279                $file = DIR_TESTDATA . '/images/waffles.jpg';
     280
     281                $gd_image_editor = new WP_Image_Editor_Imagick( $file );
     282                $gd_image_editor->load();
     283                $sizes_array =  array(
     284                                        array ( 'height' => -65119,'width' => 200 )
     285                                        );
     286                $resized =  $gd_image_editor->multi_resize( $sizes_array );
     287
     288                $expected_array = array(
     289                                        array ( 'file' => 'waffles-200x133.jpg',
     290                                                        'width' => 200,
     291                                                        'height' => 133,
     292                                                        'mime-type' => 'image/jpeg')
     293                                        );
     294
     295                $this->assertEquals( $expected_array, $resized );
     296        }
     297
     298
     299
     300        /**
    56301         * Test resizing an image including cropping
    57302         *
    58303         */