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/post/thumbnails.php

    r41693 r42343  
    1010    protected static $attachment_id;
    1111
    12     protected $current_size_filter_data = null;
     12    protected $current_size_filter_data   = null;
    1313    protected $current_size_filter_result = null;
    1414
     
    1717        self::$different_post = $factory->post->create_and_get();
    1818
    19         $file = DIR_TESTDATA . '/images/canola.jpg';
    20         self::$attachment_id = $factory->attachment->create_upload_object( $file, self::$post->ID, array(
    21             'post_mime_type' => 'image/jpeg',
    22         ) );
     19        $file                = DIR_TESTDATA . '/images/canola.jpg';
     20        self::$attachment_id = $factory->attachment->create_upload_object(
     21            $file, self::$post->ID, array(
     22                'post_mime_type' => 'image/jpeg',
     23            )
     24        );
    2325    }
    2426
     
    6870        set_post_thumbnail( self::$post, self::$attachment_id );
    6971
    70         $WP_Query = new WP_Query( array(
    71             'post_type' => 'any',
    72             'post__in'  => array( self::$post->ID ),
    73             'orderby'   => 'post__in',
    74         ) );
     72        $WP_Query = new WP_Query(
     73            array(
     74                'post_type' => 'any',
     75                'post__in'  => array( self::$post->ID ),
     76                'orderby'   => 'post__in',
     77            )
     78        );
    7579
    7680        $this->assertFalse( $WP_Query->thumbnails_cached );
     
    8993        $caption = 'This is a caption.';
    9094
    91         $post_id = self::factory()->post->create();
    92         $attachment_id = self::factory()->attachment->create_object( 'image.jpg', $post_id, array(
    93             'post_mime_type' => 'image/jpeg',
    94             'post_type'      => 'attachment',
    95             'post_excerpt'   => $caption,
    96         ) );
     95        $post_id       = self::factory()->post->create();
     96        $attachment_id = self::factory()->attachment->create_object(
     97            'image.jpg', $post_id, array(
     98                'post_mime_type' => 'image/jpeg',
     99                'post_type'      => 'attachment',
     100                'post_excerpt'   => $caption,
     101            )
     102        );
    97103
    98104        set_post_thumbnail( $post_id, $attachment_id );
     
    105111     */
    106112    function test_get_the_post_thumbnail_caption_empty() {
    107         $post_id = self::factory()->post->create();
    108         $attachment_id = self::factory()->attachment->create_object( 'image.jpg', $post_id, array(
    109             'post_mime_type' => 'image/jpeg',
    110             'post_type'      => 'attachment',
    111             'post_excerpt'   => '',
    112         ) );
     113        $post_id       = self::factory()->post->create();
     114        $attachment_id = self::factory()->attachment->create_object(
     115            'image.jpg', $post_id, array(
     116                'post_mime_type' => 'image/jpeg',
     117                'post_type'      => 'attachment',
     118                'post_excerpt'   => '',
     119            )
     120        );
    113121
    114122        set_post_thumbnail( $post_id, $attachment_id );
     
    123131        $caption = 'This is a caption.';
    124132
    125         $post_id = self::factory()->post->create();
    126         $attachment_id = self::factory()->attachment->create_object( 'image.jpg', $post_id, array(
    127             'post_mime_type' => 'image/jpeg',
    128             'post_type'      => 'attachment',
    129             'post_excerpt'   => $caption,
    130         ) );
     133        $post_id       = self::factory()->post->create();
     134        $attachment_id = self::factory()->attachment->create_object(
     135            'image.jpg', $post_id, array(
     136                'post_mime_type' => 'image/jpeg',
     137                'post_type'      => 'attachment',
     138                'post_excerpt'   => $caption,
     139            )
     140        );
    131141
    132142        set_post_thumbnail( $post_id, $attachment_id );
     
    143153        set_post_thumbnail( self::$post, self::$attachment_id );
    144154
    145         $expected = wp_get_attachment_image( self::$attachment_id, 'post-thumbnail', false, array(
    146             'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image'
    147         ) );
     155        $expected = wp_get_attachment_image(
     156            self::$attachment_id, 'post-thumbnail', false, array(
     157                'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image',
     158            )
     159        );
    148160
    149161        $this->assertEquals( $expected, get_the_post_thumbnail( self::$post ) );
     
    171183        set_post_thumbnail( self::$post, self::$attachment_id );
    172184
    173         $expected = wp_get_attachment_image( self::$attachment_id, 'post-thumbnail', false, array(
    174             'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image'
    175         ) );
     185        $expected = wp_get_attachment_image(
     186            self::$attachment_id, 'post-thumbnail', false, array(
     187                'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image',
     188            )
     189        );
    176190
    177191        ob_start();
     
    247261        $old_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;
    248262
    249         $GLOBALS['post'] = self::$post;
     263        $GLOBALS['post']           = self::$post;
    250264        $_REQUEST['_thumbnail_id'] = self::$attachment_id;
    251         $_REQUEST['preview_id'] = self::$post->ID;
     265        $_REQUEST['preview_id']    = self::$post->ID;
    252266
    253267        $result = _wp_preview_post_thumbnail_filter( '', self::$post->ID, '_thumbnail_id' );
     
    267281        $old_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;
    268282
    269         $secondary_post = self::factory()->post->create( array(
     283        $secondary_post = self::factory()->post->create(
     284            array(
    270285                'post_stauts' => 'publish',
    271286            )
    272287        );
    273288
    274         $GLOBALS['post'] = self::$post;
     289        $GLOBALS['post']           = self::$post;
    275290        $_REQUEST['_thumbnail_id'] = self::$attachment_id;
    276         $_REQUEST['preview_id'] = $secondary_post;
     291        $_REQUEST['preview_id']    = $secondary_post;
    277292
    278293        $result = _wp_preview_post_thumbnail_filter( '', self::$post->ID, '_thumbnail_id' );
     
    290305     */
    291306    function test_insert_post_with_post_thumbnail() {
    292         $post_id = wp_insert_post( array(
    293             'ID'            => self::$post->ID,
    294             'post_status'   => 'publish',
    295             'post_content'  => 'Post content',
    296             'post_title'    => 'Post Title',
    297             '_thumbnail_id' => self::$attachment_id,
    298         ) );
     307        $post_id = wp_insert_post(
     308            array(
     309                'ID'            => self::$post->ID,
     310                'post_status'   => 'publish',
     311                'post_content'  => 'Post content',
     312                'post_title'    => 'Post Title',
     313                '_thumbnail_id' => self::$attachment_id,
     314            )
     315        );
    299316
    300317        $thumbnail_id = get_post_thumbnail_id( $post_id );
    301318        $this->assertEquals( self::$attachment_id, $thumbnail_id );
    302319
    303         $post_id = wp_insert_post( array(
    304             'ID'            => $post_id,
    305             'post_status'   => 'publish',
    306             'post_content'  => 'Post content',
    307             'post_title'    => 'Post Title',
    308             '_thumbnail_id' => - 1, // -1 removes post thumbnail.
    309         ) );
     320        $post_id = wp_insert_post(
     321            array(
     322                'ID'            => $post_id,
     323                'post_status'   => 'publish',
     324                'post_content'  => 'Post content',
     325                'post_title'    => 'Post Title',
     326                '_thumbnail_id' => - 1, // -1 removes post thumbnail.
     327            )
     328        );
    310329
    311330        $thumbnail_id = get_post_thumbnail_id( $post_id );
     
    318337    function test_insert_attachment_with_post_thumbnail() {
    319338        // Audio files support featured images.
    320         $post_id = wp_insert_post( array(
    321             'post_type'      => 'attachment',
    322             'post_status'    => 'inherit',
    323             'post_content'   => 'Post content',
    324             'post_title'     => 'Post Title',
    325             'post_mime_type' => 'audio/mpeg',
    326             'post_parent'    => 0,
    327             'file'           => DIR_TESTDATA . '/audio/test-noise.mp3', // File does not exist, but does not matter here.
    328             '_thumbnail_id'  => self::$attachment_id,
    329         ) );
     339        $post_id = wp_insert_post(
     340            array(
     341                'post_type'      => 'attachment',
     342                'post_status'    => 'inherit',
     343                'post_content'   => 'Post content',
     344                'post_title'     => 'Post Title',
     345                'post_mime_type' => 'audio/mpeg',
     346                'post_parent'    => 0,
     347                'file'           => DIR_TESTDATA . '/audio/test-noise.mp3', // File does not exist, but does not matter here.
     348                '_thumbnail_id'  => self::$attachment_id,
     349            )
     350        );
    330351
    331352        $thumbnail_id = get_post_thumbnail_id( $post_id );
     
    333354
    334355        // Images do not support featured images.
    335         $post_id = wp_insert_post( array(
    336             'post_type'      => 'attachment',
    337             'post_status'    => 'inherit',
    338             'post_content'   => 'Post content',
    339             'post_title'     => 'Post Title',
    340             'post_mime_type' => 'image/jpeg',
    341             'post_parent'    => 0,
    342             'file'           => DIR_TESTDATA . '/images/canola.jpg',
    343             '_thumbnail_id'  => self::$attachment_id,
    344         ) );
     356        $post_id = wp_insert_post(
     357            array(
     358                'post_type'      => 'attachment',
     359                'post_status'    => 'inherit',
     360                'post_content'   => 'Post content',
     361                'post_title'     => 'Post Title',
     362                'post_mime_type' => 'image/jpeg',
     363                'post_parent'    => 0,
     364                'file'           => DIR_TESTDATA . '/images/canola.jpg',
     365                '_thumbnail_id'  => self::$attachment_id,
     366            )
     367        );
    345368
    346369        $thumbnail_id = get_post_thumbnail_id( $post_id );
Note: See TracChangeset for help on using the changeset viewer.