Make WordPress Core


Ignore:
Timestamp:
11/30/2014 07:53:18 PM (9 years ago)
Author:
wonderboymusic
Message:

Use round() instead of floor() when resizing image dimensions.

Updates unit tests.

Props SergeyBiryukov, kitchin.
Fixes #18532.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/size.php

    r27358 r30660  
    1414        // no constraint - should have no effect
    1515        $out = wp_constrain_dimensions(640, 480, 0, 0);
    16         $this->assertEquals(array(640, 480), $out);
     16        $this->assertSame( array( 640, 480 ), $out );
    1717
    1818        $out = wp_constrain_dimensions(640, 480);
    19         $this->assertEquals(array(640, 480), $out);
     19        $this->assertSame( array( 640, 480 ), $out );
    2020
    2121        $out = wp_constrain_dimensions(0, 0, 0, 0);
    22         $this->assertEquals(array(0, 0), $out);
     22        $this->assertSame( array( 0, 0 ), $out );
     23
     24        $out = wp_constrain_dimensions(465, 700, 177, 177);
     25        $this->assertSame( array( 118, 177 ), $out );
    2326    }
    2427
     
    2932        // image size is smaller than the constraint - no effect
    3033        $out = wp_constrain_dimensions(500, 600, 1024, 768);
    31         $this->assertEquals(array(500, 600), $out);
     34        $this->assertSame( array( 500, 600 ), $out );
    3235
    3336        $out = wp_constrain_dimensions(500, 600, 0, 768);
    34         $this->assertEquals(array(500, 600), $out);
     37        $this->assertSame( array( 500, 600 ), $out );
    3538
    3639        $out = wp_constrain_dimensions(500, 600, 1024, 0);
    37         $this->assertEquals(array(500, 600), $out);
     40        $this->assertSame( array( 500, 600 ), $out );
    3841    }
    3942
     
    4447        // image size is equal to the constraint - no effect
    4548        $out = wp_constrain_dimensions(1024, 768, 1024, 768);
    46         $this->assertequals(array(1024, 768), $out);
     49        $this->assertSame( array( 1024, 768 ), $out );
    4750
    4851        $out = wp_constrain_dimensions(1024, 768, 0, 768);
    49         $this->assertequals(array(1024, 768), $out);
     52        $this->assertSame( array( 1024, 768 ), $out );
    5053
    5154        $out = wp_constrain_dimensions(1024, 768, 1024, 0);
    52         $this->assertequals(array(1024, 768), $out);
     55        $this->assertSame( array( 1024, 768 ), $out );
    5356    }
    5457
     
    5962        // image size is larger than the constraint - result should be constrained
    6063        $out = wp_constrain_dimensions(1024, 768, 500, 600);
    61         $this->assertequals(array(500, 375), $out);
     64        $this->assertSame( array( 500, 375 ), $out );
    6265
    6366        $out = wp_constrain_dimensions(1024, 768, 0, 600);
    64         $this->assertequals(array(800, 600), $out);
     67        $this->assertSame( array( 800, 600 ), $out );
    6568
    6669        $out = wp_constrain_dimensions(1024, 768, 500, 0);
    67         $this->assertequals(array(500, 375), $out);
     70        $this->assertSame( array( 500, 375 ), $out );
    6871
    6972        // also try a portrait oriented image
    7073        $out = wp_constrain_dimensions(300, 800, 500, 600);
    71         $this->assertequals(array(225, 600), $out);
     74        $this->assertSame( array( 225, 600 ), $out );
    7275
    7376        $out = wp_constrain_dimensions(300, 800, 0, 600);
    74         $this->assertequals(array(225, 600), $out);
     77        $this->assertSame( array( 225, 600 ), $out );
    7578
    7679        $out = wp_constrain_dimensions(300, 800, 200, 0);
    77         $this->assertequals(array(200, 533), $out);
     80        $this->assertSame( array( 200, 533 ), $out );
    7881    }
    7982
     
    8487        // one dimension is larger than the constraint, one smaller - result should be constrained
    8588        $out = wp_constrain_dimensions(1024, 768, 500, 800);
    86         $this->assertequals(array(500, 375), $out);
     89        $this->assertSame( array( 500, 375 ), $out );
    8790
    8891        $out = wp_constrain_dimensions(1024, 768, 2000, 700);
    89         $this->assertequals(array(933, 700), $out);
     92        $this->assertSame( array( 933, 700 ), $out );
    9093
    9194        // portrait
    9295        $out = wp_constrain_dimensions(768, 1024, 800, 500);
    93         $this->assertequals(array(375, 500), $out);
     96        $this->assertSame( array( 375, 500 ), $out );
    9497
    9598        $out = wp_constrain_dimensions(768, 1024, 2000, 700);
    96         $this->assertequals(array(525, 700), $out);
     99        $this->assertSame( array( 525, 700 ), $out );
    97100    }
    98101
     
    102105    function test_shrink_dimensions_default() {
    103106        $out = wp_shrink_dimensions(640, 480);
    104         $this->assertEquals(array(128, 96), $out);
     107        $this->assertSame( array( 128, 96 ), $out );
    105108
    106109        $out = wp_shrink_dimensions(480, 640);
    107         $this->assertEquals(array(72, 96), $out);
     110        $this->assertSame( array( 72, 96 ), $out );
    108111    }
    109112
     
    114117        // image size is smaller than the constraint - no effect
    115118        $out = wp_shrink_dimensions(500, 600, 1024, 768);
    116         $this->assertEquals(array(500, 600), $out);
     119        $this->assertSame( array( 500, 600 ), $out );
    117120
    118121        $out = wp_shrink_dimensions(600, 500, 1024, 768);
    119         $this->assertEquals(array(600, 500), $out);
     122        $this->assertSame( array( 600, 500 ), $out );
    120123    }
    121124
     
    126129        // image size is equal to the constraint - no effect
    127130        $out = wp_shrink_dimensions(500, 600, 500, 600);
    128         $this->assertEquals(array(500, 600), $out);
     131        $this->assertSame( array( 500, 600 ), $out );
    129132
    130133        $out = wp_shrink_dimensions(600, 500, 600, 500);
    131         $this->assertEquals(array(600, 500), $out);
     134        $this->assertSame( array( 600, 500 ), $out );
    132135    }
    133136
     
    138141        // image size is larger than the constraint - result should be constrained
    139142        $out = wp_shrink_dimensions(1024, 768, 500, 600);
    140         $this->assertequals(array(500, 375), $out);
     143        $this->assertSame( array( 500, 375 ), $out );
    141144
    142145        $out = wp_shrink_dimensions(300, 800, 500, 600);
    143         $this->assertequals(array(225, 600), $out);
     146        $this->assertSame( array( 225, 600 ), $out );
    144147    }
    145148
     
    150153        // one dimension is larger than the constraint, one smaller - result should be constrained
    151154        $out = wp_shrink_dimensions(1024, 768, 500, 800);
    152         $this->assertequals(array(500, 375), $out);
     155        $this->assertSame( array( 500, 375 ), $out );
    153156
    154157        $out = wp_shrink_dimensions(1024, 768, 2000, 700);
    155         $this->assertequals(array(933, 700), $out);
     158        $this->assertSame( array( 933, 700 ), $out );
    156159
    157160        // portrait
    158161        $out = wp_shrink_dimensions(768, 1024, 800, 500);
    159         $this->assertequals(array(375, 500), $out);
     162        $this->assertSame( array( 375, 500 ), $out );
    160163
    161164        $out = wp_shrink_dimensions(768, 1024, 2000, 700);
    162         $this->assertequals(array(525, 700), $out);
     165        $this->assertSame( array( 525, 700 ), $out );
    163166    }
    164167
    165168    function test_constrain_size_for_editor_thumb() {
    166169        $out = image_constrain_size_for_editor(600, 400, 'thumb');
    167         $this->assertEquals(array(150, 100), $out);
     170        $this->assertSame( array( 150, 100 ), $out );
    168171
    169172        $out = image_constrain_size_for_editor(64, 64, 'thumb');
    170         $this->assertEquals(array(64, 64), $out);
     173        $this->assertSame( array( 64, 64 ), $out );
    171174    }
    172175
     
    182185
    183186        $out = image_constrain_size_for_editor(600, 400, 'medium');
    184         $this->assertEquals(array(500, 333), $out);
     187        $this->assertSame( array( 500, 333 ), $out );
    185188
    186189        $out = image_constrain_size_for_editor(400, 600, 'medium');
    187         $this->assertEquals(array(400, 600), $out);
     190        $this->assertSame( array( 400, 600 ), $out );
    188191
    189192        $out = image_constrain_size_for_editor(64, 64, 'medium');
    190         $this->assertEquals(array(64, 64), $out);
     193        $this->assertSame( array( 64, 64 ), $out );
    191194
    192195        // content_width should be ignored
    193196        $content_width = 350;
    194197        $out = image_constrain_size_for_editor(600, 400, 'medium');
    195         $this->assertEquals(array(500, 333), $out);
     198        $this->assertSame( array( 500, 333 ), $out );
    196199
    197200        $content_width = $_content_width;
     
    205208        $content_width = 400;
    206209        $out = image_constrain_size_for_editor(600, 400, 'full');
    207         $this->assertEquals(array(600, 400), $out);
     210        $this->assertSame( array( 600, 400 ), $out );
    208211
    209212        $out = image_constrain_size_for_editor(64, 64, 'full');
    210         $this->assertEquals(array(64, 64), $out);
     213        $this->assertSame( array( 64, 64 ), $out );
    211214
    212215        // content_width default is 500
     
    214217
    215218        $out = image_constrain_size_for_editor(600, 400, 'full');
    216         $this->assertEquals(array(600, 400), $out);
     219        $this->assertSame( array( 600, 400 ), $out );
    217220
    218221        $out = image_constrain_size_for_editor(64, 64, 'full');
    219         $this->assertEquals(array(64, 64), $out);
     222        $this->assertSame( array( 64, 64 ), $out );
    220223
    221224        $content_width = $_content_width;
Note: See TracChangeset for help on using the changeset viewer.