Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 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/widgets/media-video-widget.php

    r41198 r42343  
    2424                parent::clean_up_global_scope();
    2525                $wp_scripts = null;
    26                 $wp_styles = null;
     26                $wp_styles  = null;
    2727        }
    2828
     
    6565                $this->assertTrue( $widget->widget_options['customize_selective_refresh'] );
    6666                $this->assertEquals( 'video', $widget->widget_options['mime_type'] );
    67                 $this->assertEqualSets( array(
    68                         'add_to_widget',
    69                         'replace_media',
    70                         'unsupported_file_type',
    71                         'edit_media',
    72                         'media_library_state_multi',
    73                         'media_library_state_single',
    74                         'missing_attachment',
    75                         'no_media_selected',
    76                         'add_media',
    77                 ), array_keys( $widget->l10n ) );
     67                $this->assertEqualSets(
     68                        array(
     69                                'add_to_widget',
     70                                'replace_media',
     71                                'unsupported_file_type',
     72                                'edit_media',
     73                                'media_library_state_multi',
     74                                'media_library_state_single',
     75                                'missing_attachment',
     76                                'no_media_selected',
     77                                'add_media',
     78                        ), array_keys( $widget->l10n )
     79                );
    7880        }
    7981
     
    8486         */
    8587        function test_update() {
    86                 $widget = new WP_Widget_Media_Video();
     88                $widget   = new WP_Widget_Media_Video();
    8789                $instance = array();
    8890
     
    9193                        'attachment_id' => 1,
    9294                );
    93                 $result = $widget->update( $expected, $instance );
     95                $result   = $widget->update( $expected, $instance );
    9496                $this->assertSame( $result, $expected );
    9597
    9698                // Should filter invalid attachment ID.
    97                 $result = $widget->update( array(
    98                         'attachment_id' => 'media',
    99                 ), $instance );
     99                $result = $widget->update(
     100                        array(
     101                                'attachment_id' => 'media',
     102                        ), $instance
     103                );
    100104                $this->assertSame( $result, $instance );
    101105
     
    104108                        'url' => 'https://chickenandribs.org',
    105109                );
    106                 $result = $widget->update( $expected, $instance );
     110                $result   = $widget->update( $expected, $instance );
    107111                $this->assertSame( $result, $expected );
    108112
    109113                // Should filter invalid attachment url.
    110                 $result = $widget->update( array(
    111                         'url' => 'not_a_url',
    112                 ), $instance );
     114                $result = $widget->update(
     115                        array(
     116                                'url' => 'not_a_url',
     117                        ), $instance
     118                );
    113119                $this->assertNotSame( $result, $instance );
    114120                $this->assertStringStartsWith( 'http://', $result['url'] );
     
    118124                        'loop' => true,
    119125                );
    120                 $result = $widget->update( $expected, $instance );
     126                $result   = $widget->update( $expected, $instance );
    121127                $this->assertSame( $result, $expected );
    122128
    123129                // Should filter invalid loop setting.
    124                 $result = $widget->update( array(
    125                         'loop' => 'not-boolean',
    126                 ), $instance );
     130                $result = $widget->update(
     131                        array(
     132                                'loop' => 'not-boolean',
     133                        ), $instance
     134                );
    127135                $this->assertSame( $result, $instance );
    128136
     
    131139                        'title' => 'A video of goats',
    132140                );
    133                 $result = $widget->update( $expected, $instance );
     141                $result   = $widget->update( $expected, $instance );
    134142                $this->assertSame( $result, $expected );
    135143
    136144                // Should filter invalid attachment title.
    137                 $result = $widget->update( array(
    138                         'title' => '<h1>Cute Baby Goats</h1>',
    139                 ), $instance );
     145                $result = $widget->update(
     146                        array(
     147                                'title' => '<h1>Cute Baby Goats</h1>',
     148                        ), $instance
     149                );
    140150                $this->assertNotSame( $result, $instance );
    141151
     
    144154                        'preload' => 'none',
    145155                );
    146                 $result = $widget->update( $expected, $instance );
     156                $result   = $widget->update( $expected, $instance );
    147157                $this->assertSame( $result, $expected );
    148158
    149159                // Should filter invalid preload setting.
    150                 $result = $widget->update( array(
    151                         'preload' => 'nope',
    152                 ), $instance );
     160                $result = $widget->update(
     161                        array(
     162                                'preload' => 'nope',
     163                        ), $instance
     164                );
    153165                $this->assertSame( $result, $instance );
    154166
    155167                // Should filter invalid key.
    156                 $result = $widget->update( array(
    157                         'h4x' => 'value',
    158                 ), $instance );
     168                $result = $widget->update(
     169                        array(
     170                                'h4x' => 'value',
     171                        ), $instance
     172                );
    159173                $this->assertSame( $result, $instance );
    160174        }
     
    168182        function test_render_media() {
    169183                $test_movie_file = __FILE__ . '../../data/uploads/small-video.m4v';
    170                 $widget = new WP_Widget_Media_Video();
    171                 $attachment_id = self::factory()->attachment->create_object( array(
    172                         'file' => $test_movie_file,
    173                         'post_parent' => 0,
    174                         'post_mime_type' => 'video/mp4',
    175                         'post_title' => 'Test Video',
    176                 ) );
     184                $widget          = new WP_Widget_Media_Video();
     185                $attachment_id   = self::factory()->attachment->create_object(
     186                        array(
     187                                'file'           => $test_movie_file,
     188                                'post_parent'    => 0,
     189                                'post_mime_type' => 'video/mp4',
     190                                'post_title'     => 'Test Video',
     191                        )
     192                );
    177193                wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $test_movie_file ) );
    178194
     
    185201                // Should be empty when there is an invalid attachment_id.
    186202                ob_start();
    187                 $widget->render_media( array(
    188                         'attachment_id' => 777,
    189                 ) );
     203                $widget->render_media(
     204                        array(
     205                                'attachment_id' => 777,
     206                        )
     207                );
    190208                $output = ob_get_clean();
    191209                $this->assertEmpty( $output );
     
    193211                // Tests with video from library.
    194212                ob_start();
    195                 $widget->render_media( array(
    196                         'attachment_id' => $attachment_id,
    197                 ) );
     213                $widget->render_media(
     214                        array(
     215                                'attachment_id' => $attachment_id,
     216                        )
     217                );
    198218                $output = ob_get_clean();
    199219
     
    207227
    208228                ob_start();
    209                 $widget->render_media( array(
    210                         'attachment_id' => $attachment_id,
    211                         'title' => 'Open Source Cartoon',
    212                         'preload' => 'metadata',
    213                         'loop' => true,
    214                 ) );
     229                $widget->render_media(
     230                        array(
     231                                'attachment_id' => $attachment_id,
     232                                'title'         => 'Open Source Cartoon',
     233                                'preload'       => 'metadata',
     234                                'loop'          => true,
     235                        )
     236                );
    215237                $output = ob_get_clean();
    216238
     
    222244                ob_start();
    223245                $content = '<track srclang="en" label="English" kind="subtitles" src="http://example.com/wp-content/uploads/2017/04/subtitles-en.vtt">';
    224                 $widget->render_media( array(
    225                         'attachment_id' => null,
    226                         'loop' => false,
    227                         'url' => 'https://www.youtube.com/watch?v=OQSNhk5ICTI',
    228                         'content' => $content,
    229                 ) );
     246                $widget->render_media(
     247                        array(
     248                                'attachment_id' => null,
     249                                'loop'          => false,
     250                                'url'           => 'https://www.youtube.com/watch?v=OQSNhk5ICTI',
     251                                'content'       => $content,
     252                        )
     253                );
    230254                $output = ob_get_clean();
    231255
     
    248272
    249273                $wp_scripts = null;
    250                 $wp_styles = null;
     274                $wp_styles  = null;
    251275                $widget->enqueue_preview_scripts();
    252276                $this->assertTrue( wp_script_is( 'wp-mediaelement' ) );
     
    255279
    256280                $wp_scripts = null;
    257                 $wp_styles = null;
     281                $wp_styles  = null;
    258282                add_filter( 'wp_video_shortcode_library', '__return_empty_string' );
    259283                $widget->enqueue_preview_scripts();
Note: See TracChangeset for help on using the changeset viewer.