Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r41261 r42343  
    33/**
    44 * Test the WP_Image_Editor_GD class
     5 *
    56 * @group image
    67 * @group media
     
    3435    public function test_supports_mime_type_jpeg() {
    3536        $gd_image_editor = new WP_Image_Editor_GD( null );
    36         $expected = imagetypes() & IMG_JPG;
     37        $expected        = imagetypes() & IMG_JPG;
    3738        $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/jpeg' ) );
    3839    }
     
    4041    public function test_supports_mime_type_png() {
    4142        $gd_image_editor = new WP_Image_Editor_GD( null );
    42         $expected = imagetypes() & IMG_PNG;
     43        $expected        = imagetypes() & IMG_PNG;
    4344        $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/png' ) );
    4445    }
     
    4647    public function test_supports_mime_type_gif() {
    4748        $gd_image_editor = new WP_Image_Editor_GD( null );
    48         $expected = imagetypes() & IMG_GIF;
     49        $expected        = imagetypes() & IMG_GIF;
    4950        $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/gif' ) );
    5051    }
     
    7980        $gd_image_editor->load();
    8081
    81         $sizes_array =  array(
     82        $sizes_array = array(
    8283            array(
    8384                'width'  => 50,
     
    101102
    102103        // Now, verify real dimensions are as expected
    103         $image_path = DIR_TESTDATA . '/images/'. $resized[0]['file'];
     104        $image_path = DIR_TESTDATA . '/images/' . $resized[0]['file'];
    104105        $this->assertImageDimensions(
    105106            $image_path,
     
    150151            ),
    151152            array(
    152                 'width'  => 0,
    153             ),
    154             array(
    155                 'width'  => 0,
    156                 'crop'   => true,
    157             ),
    158             array(
    159                 'width'  => null,
    160             ),
    161             array(
    162                 'width'  => null,
    163                 'crop'   => true,
    164             ),
    165             array(
    166                 'width'  => '',
    167             ),
    168             array(
    169                 'width'  => '',
    170                 'crop'   => true,
     153                'width' => 0,
     154            ),
     155            array(
     156                'width' => 0,
     157                'crop'  => true,
     158            ),
     159            array(
     160                'width' => null,
     161            ),
     162            array(
     163                'width' => null,
     164                'crop'  => true,
     165            ),
     166            array(
     167                'width' => '',
     168            ),
     169            array(
     170                'width' => '',
     171                'crop'  => true,
    171172            ),
    172173        );
     
    372373        $this->assertEquals( $expected_array, $resized );
    373374
    374         foreach( $resized as $key => $image_data ){
     375        foreach ( $resized as $key => $image_data ) {
    375376            $image_path = DIR_TESTDATA . '/images/' . $image_data['file'];
    376377
     
    378379            $this->assertImageDimensions(
    379380                $image_path,
    380                 $expected_array[$key]['width'],
    381                 $expected_array[$key]['height']
     381                $expected_array[ $key ]['width'],
     382                $expected_array[ $key ]['height']
    382383            );
    383384        }
     
    417418        $this->assertEquals(
    418419            array(
    419                 'width' => 50,
     420                'width'  => 50,
    420421                'height' => 50,
    421422            ),
     
    484485        $editor->save( $save_to_file );
    485486
    486         $this->assertImageAlphaAtPointGD( $save_to_file, array( 0,0 ), 127 );
     487        $this->assertImageAlphaAtPointGD( $save_to_file, array( 0, 0 ), 127 );
    487488
    488489        unlink( $save_to_file );
     
    511512        $editor->save( $save_to_file );
    512513
    513         $this->assertImageAlphaAtPointGD( $save_to_file, array( 0,0 ), 127 );
     514        $this->assertImageAlphaAtPointGD( $save_to_file, array( 0, 0 ), 127 );
    514515
    515516        unlink( $save_to_file );
     
    517518
    518519    /**
    519      *
    520520     * @ticket 30596
    521521     */
     
    527527        $file = DIR_TESTDATA . '/images/transparent.png';
    528528
    529         $image = imagecreatefrompng( $file );
    530         $rgb = imagecolorat( $image, 0, 0 );
     529        $image    = imagecreatefrompng( $file );
     530        $rgb      = imagecolorat( $image, 0, 0 );
    531531        $expected = imagecolorsforindex( $image, $rgb );
    532532
    533533        $editor = new WP_Image_Editor_GD( $file );
    534                 $this->assertNotInstanceOf( 'WP_Error', $editor );
    535                 $editor->load();
    536                 $editor->rotate( 180 );
    537                 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
    538 
    539                 $editor->save( $save_to_file );
    540 
    541                 $this->assertImageAlphaAtPointGD( $save_to_file, array( 0,0 ), $expected['alpha'] );
    542                 unlink( $save_to_file );
     534                $this->assertNotInstanceOf( 'WP_Error', $editor );
     535                $editor->load();
     536                $editor->rotate( 180 );
     537                $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
     538
     539                $editor->save( $save_to_file );
     540
     541                $this->assertImageAlphaAtPointGD( $save_to_file, array( 0, 0 ), $expected['alpha'] );
     542                unlink( $save_to_file );
    543543
    544544    }
     
    546546    /**
    547547     * Test WP_Image_Editor_GD handles extension-less images
     548     *
    548549     * @ticket 39195
    549550     */
    550551    public function test_image_non_existent_extension() {
    551         $image_editor = new WP_Image_Editor_GD( DIR_TESTDATA.'/images/test-image-no-extension' );
    552         $result = $image_editor->load();
     552        $image_editor = new WP_Image_Editor_GD( DIR_TESTDATA . '/images/test-image-no-extension' );
     553        $result       = $image_editor->load();
    553554
    554555        $this->assertTrue( $result );
Note: See TracChangeset for help on using the changeset viewer.