Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 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/oembed/WpEmbed.php

    r42009 r42343  
    2323
    2424    public function test_maybe_run_ajax_cache_should_return_nothing_if_there_is_no_post() {
    25         $this->expectOutputString('');
     25        $this->expectOutputString( '' );
    2626        $this->wp_embed->maybe_run_ajax_cache();
    2727    }
    2828
    2929    public function test_maybe_run_ajax_cache_should_return_nothing_if_there_is_no_message() {
    30         $GLOBALS['post'] = $this->factory()->post->create_and_get( array(
    31             'post_title' => 'Hello World',
    32         ) );
    33 
    34         $this->expectOutputString('');
     30        $GLOBALS['post'] = $this->factory()->post->create_and_get(
     31            array(
     32                'post_title' => 'Hello World',
     33            )
     34        );
     35
     36        $this->expectOutputString( '' );
    3537
    3638        $this->wp_embed->maybe_run_ajax_cache();
     
    3941
    4042    public function test_maybe_run_ajax_cache_should_return_javascript() {
    41         $GLOBALS['post'] = $this->factory()->post->create_and_get( array(
    42             'post_title' => 'Hello World',
    43         ) );
     43        $GLOBALS['post'] = $this->factory()->post->create_and_get(
     44            array(
     45                'post_title' => 'Hello World',
     46            )
     47        );
    4448        $_GET['message'] = 'foo';
    4549
     
    5559    public function test_wp_maybe_load_embeds() {
    5660        $this->assertEqualSets( array( 10, 9999 ), array_keys( $GLOBALS['wp_embed']->handlers ) );
    57         $this->assertEqualSets( array(
    58             'youtube_embed_url',
    59         ), array_keys( $GLOBALS['wp_embed']->handlers[10] ) );
    60         $this->assertEqualSets( array(
    61             'audio',
    62             'video',
    63         ), array_keys( $GLOBALS['wp_embed']->handlers[9999] ) );
     61        $this->assertEqualSets(
     62            array(
     63                'youtube_embed_url',
     64            ), array_keys( $GLOBALS['wp_embed']->handlers[10] )
     65        );
     66        $this->assertEqualSets(
     67            array(
     68                'audio',
     69                'video',
     70            ), array_keys( $GLOBALS['wp_embed']->handlers[9999] )
     71        );
    6472    }
    6573
     
    165173        global $post;
    166174
    167         $post = $this->factory()->post->create_and_get();
    168         $url             = 'https://example.com/';
    169         $expected        = '<b>Embedded content</b>';
    170         $key_suffix      = md5( $url . serialize( wp_embed_defaults( $url ) ) );
    171         $cachekey        = '_oembed_' . $key_suffix;
     175        $post       = $this->factory()->post->create_and_get();
     176        $url        = 'https://example.com/';
     177        $expected   = '<b>Embedded content</b>';
     178        $key_suffix = md5( $url . serialize( wp_embed_defaults( $url ) ) );
     179        $cachekey   = '_oembed_' . $key_suffix;
    172180
    173181        add_post_meta( $post->ID, $cachekey, $expected );
     
    192200        global $post;
    193201
    194         $post = $this->factory()->post->create_and_get();
    195         $url             = 'https://example.com/';
    196         $expected        = '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>';
    197         $key_suffix      = md5( $url . serialize( wp_embed_defaults( $url ) ) );
    198         $cachekey        = '_oembed_' . $key_suffix;
    199         $cachekey_time   = '_oembed_time_' . $key_suffix;
     202        $post          = $this->factory()->post->create_and_get();
     203        $url           = 'https://example.com/';
     204        $expected      = '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>';
     205        $key_suffix    = md5( $url . serialize( wp_embed_defaults( $url ) ) );
     206        $cachekey      = '_oembed_' . $key_suffix;
     207        $cachekey_time = '_oembed_time_' . $key_suffix;
    200208
    201209        add_post_meta( $post->ID, $cachekey, '{{unknown}}' );
     
    209217        $actual_2 = $this->wp_embed->shortcode( array(), $url );
    210218
    211         $cached = get_post_meta( $post->ID, $cachekey, true );
     219        $cached      = get_post_meta( $post->ID, $cachekey, true );
    212220        $cached_time = get_post_meta( $post->ID, $cachekey_time, true );
    213221
     
    234242
    235243        $oembed_post_id = $this->wp_embed->find_oembed_post_id( $key_suffix );
    236         $post_content = get_post( $oembed_post_id )->post_content;
     244        $post_content   = get_post( $oembed_post_id )->post_content;
    237245
    238246        // Result should be cached.
     
    260268
    261269        $oembed_post_id = $this->wp_embed->find_oembed_post_id( $key_suffix );
    262         $post_content = get_post( $oembed_post_id )->post_content;
     270        $post_content   = get_post( $oembed_post_id )->post_content;
    263271
    264272        // Result should be cached.
     
    293301        $this->assertSame( '{{unknown}}', get_post( $oembed_post_id )->post_content );
    294302
    295         $previous_usecache = $this->wp_embed->usecache;
     303        $previous_usecache        = $this->wp_embed->usecache;
    296304        $this->wp_embed->usecache = false;
    297305
Note: See TracChangeset for help on using the changeset viewer.