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

    r38951 r42343  
    88    function test_wp_link_pages() {
    99        $contents = array( 'One', 'Two', 'Three' );
    10         $content = join( '<!--nextpage-->', $contents );
    11         $post_id = self::factory()->post->create( array( 'post_content' => $content ) );
     10        $content  = join( '<!--nextpage-->', $contents );
     11        $post_id  = self::factory()->post->create( array( 'post_content' => $content ) );
    1212
    1313        $this->go_to( '?p=' . $post_id );
     
    1616
    1717        $permalink = sprintf( '<a href="%s">', get_permalink() );
    18         $page2 = _wp_link_page( 2 );
    19         $page3 = _wp_link_page( 3 );
     18        $page2     = _wp_link_page( 2 );
     19        $page3     = _wp_link_page( 3 );
    2020
    2121        $expected = "<p>Pages: 1 {$page2}2</a> {$page3}3</a></p>";
    22         $output = wp_link_pages( array( 'echo' => 0 ) );
     22        $output   = wp_link_pages( array( 'echo' => 0 ) );
    2323
    2424        $this->assertEquals( $expected, $output );
    2525
    2626        $before_after = " 1 {$page2}2</a> {$page3}3</a>";
    27         $output = wp_link_pages( array( 'echo' => 0, 'before' => '', 'after' => '' ) );
     27        $output       = wp_link_pages(
     28            array(
     29                'echo'   => 0,
     30                'before' => '',
     31                'after'  => '',
     32            )
     33        );
    2834
    2935        $this->assertEquals( $before_after, $output );
    3036
    3137        $separator = " 1{$page2}2</a>{$page3}3</a>";
    32         $output = wp_link_pages( array( 'echo' => 0, 'before' => '', 'after' => '', 'separator' => '' ) );
     38        $output    = wp_link_pages(
     39            array(
     40                'echo'      => 0,
     41                'before'    => '',
     42                'after'     => '',
     43                'separator' => '',
     44            )
     45        );
    3346
    3447        $this->assertEquals( $separator, $output );
    3548
    36         $link = " <em>1</em>{$page2}<em>2</em></a>{$page3}<em>3</em></a>";
    37         $output = wp_link_pages( array( 'echo' => 0, 'before' => '', 'after' => '', 'separator' => '',
    38             'link_before' => '<em>', 'link_after' => '</em>'
    39         ) );
     49        $link   = " <em>1</em>{$page2}<em>2</em></a>{$page3}<em>3</em></a>";
     50        $output = wp_link_pages(
     51            array(
     52                'echo'        => 0,
     53                'before'      => '',
     54                'after'       => '',
     55                'separator'   => '',
     56                'link_before' => '<em>',
     57                'link_after'  => '</em>',
     58            )
     59        );
    4060
    4161        $this->assertEquals( $link, $output );
    4262
    43         $next = "{$page2}<em>Next page</em></a>";
    44         $output = wp_link_pages( array( 'echo' => 0, 'before' => '', 'after' => '', 'separator' => '',
    45             'link_before' => '<em>', 'link_after' => '</em>', 'next_or_number' => 'next'
    46         ) );
     63        $next   = "{$page2}<em>Next page</em></a>";
     64        $output = wp_link_pages(
     65            array(
     66                'echo'           => 0,
     67                'before'         => '',
     68                'after'          => '',
     69                'separator'      => '',
     70                'link_before'    => '<em>',
     71                'link_after'     => '</em>',
     72                'next_or_number' => 'next',
     73            )
     74        );
    4775
    4876        $this->assertEquals( $next, $output );
    4977
    5078        $GLOBALS['page'] = 2;
    51         $next_prev = "{$permalink}<em>Previous page</em></a>{$page3}<em>Next page</em></a>";
    52         $output = wp_link_pages( array( 'echo' => 0, 'before' => '', 'after' => '', 'separator' => '',
    53             'link_before' => '<em>', 'link_after' => '</em>', 'next_or_number' => 'next'
    54         ) );
     79        $next_prev       = "{$permalink}<em>Previous page</em></a>{$page3}<em>Next page</em></a>";
     80        $output          = wp_link_pages(
     81            array(
     82                'echo'           => 0,
     83                'before'         => '',
     84                'after'          => '',
     85                'separator'      => '',
     86                'link_before'    => '<em>',
     87                'link_after'     => '</em>',
     88                'next_or_number' => 'next',
     89            )
     90        );
    5591
    5692        $this->assertEquals( $next_prev, $output );
    5793
    5894        $next_prev_link = "{$permalink}Woo page</a>{$page3}Hoo page</a>";
    59         $output = wp_link_pages( array( 'echo' => 0, 'before' => '', 'after' => '', 'separator' => '',
    60             'next_or_number' => 'next', 'nextpagelink' => 'Hoo page', 'previouspagelink' => 'Woo page'
    61         ) );
     95        $output         = wp_link_pages(
     96            array(
     97                'echo'             => 0,
     98                'before'           => '',
     99                'after'            => '',
     100                'separator'        => '',
     101                'next_or_number'   => 'next',
     102                'nextpagelink'     => 'Hoo page',
     103                'previouspagelink' => 'Woo page',
     104            )
     105        );
    62106
    63107        $this->assertEquals( $next_prev_link, $output );
    64108
    65109        $GLOBALS['page'] = 1;
    66         $separator = "<p>Pages: 1 | {$page2}2</a> | {$page3}3</a></p>";
    67         $output = wp_link_pages( array( 'echo' => 0, 'separator' => ' | ' ) );
     110        $separator       = "<p>Pages: 1 | {$page2}2</a> | {$page3}3</a></p>";
     111        $output          = wp_link_pages(
     112            array(
     113                'echo'      => 0,
     114                'separator' => ' | ',
     115            )
     116        );
    68117
    69118        $this->assertEquals( $separator, $output );
    70119
    71120        $pagelink = " Page 1 | {$page2}Page 2</a> | {$page3}Page 3</a>";
    72         $output = wp_link_pages( array( 'echo' => 0, 'separator' => ' | ', 'before' => '', 'after' => '',
    73             'pagelink' => 'Page %'
    74         ) );
     121        $output   = wp_link_pages(
     122            array(
     123                'echo'      => 0,
     124                'separator' => ' | ',
     125                'before'    => '',
     126                'after'     => '',
     127                'pagelink'  => 'Page %',
     128            )
     129        );
    75130
    76131        $this->assertEquals( $pagelink, $output );
     
    81136        $this->assertEmpty( $none );
    82137
    83         $bump = '&nbsp;&nbsp;&nbsp;';
    84         $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
    85         $child_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id ) );
    86         $grandchild_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $child_id ) );
     138        $bump          = '&nbsp;&nbsp;&nbsp;';
     139        $page_id       = self::factory()->post->create( array( 'post_type' => 'page' ) );
     140        $child_id      = self::factory()->post->create(
     141            array(
     142                'post_type'   => 'page',
     143                'post_parent' => $page_id,
     144            )
     145        );
     146        $grandchild_id = self::factory()->post->create(
     147            array(
     148                'post_type'   => 'page',
     149                'post_parent' => $child_id,
     150            )
     151        );
    87152
    88153        $title1 = get_post( $page_id )->post_title;
     
    90155        $title3 = get_post( $grandchild_id )->post_title;
    91156
    92         $lineage =<<<LINEAGE
     157        $lineage = <<<LINEAGE
    93158<select name='page_id' id='page_id'>
    94159    <option class="level-0" value="$page_id">$title1</option>
     
    102167        $this->assertEquals( $lineage, $output );
    103168
    104         $depth =<<<DEPTH
     169        $depth = <<<DEPTH
    105170<select name='page_id' id='page_id'>
    106171    <option class="level-0" value="$page_id">$title1</option>
     
    109174DEPTH;
    110175
    111         $output = wp_dropdown_pages( array( 'echo' => 0, 'depth' => 1 ) );
     176        $output = wp_dropdown_pages(
     177            array(
     178                'echo'  => 0,
     179                'depth' => 1,
     180            )
     181        );
    112182        $this->assertEquals( $depth, $output );
    113183
    114         $option_none =<<<NONE
     184        $option_none = <<<NONE
    115185<select name='page_id' id='page_id'>
    116186    <option value="Woo">Hoo</option>
     
    120190NONE;
    121191
    122         $output = wp_dropdown_pages( array( 'echo' => 0, 'depth' => 1,
    123             'show_option_none' => 'Hoo', 'option_none_value' => 'Woo'
    124         ) );
     192        $output = wp_dropdown_pages(
     193            array(
     194                'echo'              => 0,
     195                'depth'             => 1,
     196                'show_option_none'  => 'Hoo',
     197                'option_none_value' => 'Woo',
     198            )
     199        );
    125200        $this->assertEquals( $option_none, $output );
    126201
    127         $option_no_change =<<<NO
     202        $option_no_change = <<<NO
    128203<select name='page_id' id='page_id'>
    129204    <option value="-1">Burrito</option>
     
    133208
    134209NO;
    135         $output = wp_dropdown_pages( array( 'echo' => 0, 'depth' => 1,
    136             'show_option_none' => 'Hoo', 'option_none_value' => 'Woo',
    137             'show_option_no_change' => 'Burrito'
    138         ) );
     210        $output           = wp_dropdown_pages(
     211            array(
     212                'echo'                  => 0,
     213                'depth'                 => 1,
     214                'show_option_none'      => 'Hoo',
     215                'option_none_value'     => 'Woo',
     216                'show_option_no_change' => 'Burrito',
     217            )
     218        );
    139219        $this->assertEquals( $option_no_change, $output );
    140220    }
     
    144224     */
    145225    public function test_wp_dropdown_pages_value_field_should_default_to_ID() {
    146         $p = self::factory()->post->create( array(
    147             'post_type' => 'page',
    148         ) );
    149 
    150         $found = wp_dropdown_pages( array(
    151             'echo' => 0,
    152         ) );
     226        $p = self::factory()->post->create(
     227            array(
     228                'post_type' => 'page',
     229            )
     230        );
     231
     232        $found = wp_dropdown_pages(
     233            array(
     234                'echo' => 0,
     235            )
     236        );
    153237
    154238        // Should contain page ID by default.
     
    160244     */
    161245    public function test_wp_dropdown_pages_value_field_ID() {
    162         $p = self::factory()->post->create( array(
    163             'post_type' => 'page',
    164         ) );
    165 
    166         $found = wp_dropdown_pages( array(
    167             'echo' => 0,
    168             'value_field' => 'ID',
    169         ) );
     246        $p = self::factory()->post->create(
     247            array(
     248                'post_type' => 'page',
     249            )
     250        );
     251
     252        $found = wp_dropdown_pages(
     253            array(
     254                'echo'        => 0,
     255                'value_field' => 'ID',
     256            )
     257        );
    170258
    171259        $this->assertContains( 'value="' . $p . '"', $found );
     
    176264     */
    177265    public function test_wp_dropdown_pages_value_field_post_name() {
    178         $p = self::factory()->post->create( array(
    179             'post_type' => 'page',
    180             'post_name' => 'foo',
    181         ) );
    182 
    183         $found = wp_dropdown_pages( array(
    184             'echo' => 0,
    185             'value_field' => 'post_name',
    186         ) );
     266        $p = self::factory()->post->create(
     267            array(
     268                'post_type' => 'page',
     269                'post_name' => 'foo',
     270            )
     271        );
     272
     273        $found = wp_dropdown_pages(
     274            array(
     275                'echo'        => 0,
     276                'value_field' => 'post_name',
     277            )
     278        );
    187279
    188280        $this->assertContains( 'value="foo"', $found );
     
    193285     */
    194286    public function test_wp_dropdown_pages_value_field_should_fall_back_on_ID_when_an_invalid_value_is_provided() {
    195         $p = self::factory()->post->create( array(
    196             'post_type' => 'page',
    197             'post_name' => 'foo',
    198         ) );
    199 
    200         $found = wp_dropdown_pages( array(
    201             'echo' => 0,
    202             'value_field' => 'foo',
    203         ) );
     287        $p = self::factory()->post->create(
     288            array(
     289                'post_type' => 'page',
     290                'post_name' => 'foo',
     291            )
     292        );
     293
     294        $found = wp_dropdown_pages(
     295            array(
     296                'echo'        => 0,
     297                'value_field' => 'foo',
     298            )
     299        );
    204300
    205301        $this->assertContains( 'value="' . $p . '"', $found );
     
    210306     */
    211307    public function test_wp_dropdown_pages_should_not_contain_class_attribute_when_no_class_is_passed() {
    212         $p = self::factory()->post->create( array(
    213             'post_type' => 'page',
    214             'post_name' => 'foo',
    215         ) );
    216 
    217         $found = wp_dropdown_pages( array(
    218             'echo' => 0,
    219         ) );
     308        $p = self::factory()->post->create(
     309            array(
     310                'post_type' => 'page',
     311                'post_name' => 'foo',
     312            )
     313        );
     314
     315        $found = wp_dropdown_pages(
     316            array(
     317                'echo' => 0,
     318            )
     319        );
    220320
    221321        $this->assertNotRegExp( '/<select[^>]+class=\'/', $found );
     
    226326     */
    227327    public function test_wp_dropdown_pages_should_obey_class_parameter() {
    228         $p = self::factory()->post->create( array(
    229             'post_type' => 'page',
    230             'post_name' => 'foo',
    231         ) );
    232 
    233         $found = wp_dropdown_pages( array(
    234             'echo' => 0,
    235             'class' => 'bar',
    236         ) );
     328        $p = self::factory()->post->create(
     329            array(
     330                'post_type' => 'page',
     331                'post_name' => 'foo',
     332            )
     333        );
     334
     335        $found = wp_dropdown_pages(
     336            array(
     337                'echo'  => 0,
     338                'class' => 'bar',
     339            )
     340        );
    237341
    238342        $this->assertRegExp( '/<select[^>]+class=\'bar\'/', $found );
     
    243347     */
    244348    public function test_get_page_template_slug_by_id() {
    245         $page_id = self::factory()->post->create( array(
    246             'post_type' => 'page',
    247         ) );
     349        $page_id = self::factory()->post->create(
     350            array(
     351                'post_type' => 'page',
     352            )
     353        );
    248354
    249355        $this->assertEquals( '', get_page_template_slug( $page_id ) );
     
    260366     */
    261367    public function test_get_page_template_slug_from_loop() {
    262         $page_id = self::factory()->post->create( array(
    263             'post_type' => 'page',
    264         ) );
     368        $page_id = self::factory()->post->create(
     369            array(
     370                'post_type' => 'page',
     371            )
     372        );
    265373
    266374        update_post_meta( $page_id, '_wp_page_template', 'example.php' );
     
    321429
    322430        // No menus + wp_nav_menu() falls back to wp_page_menu(), this time without a container.
    323         $menu = wp_nav_menu( array(
    324             'echo'      => false,
    325             'container' => false,
    326         ) );
     431        $menu = wp_nav_menu(
     432            array(
     433                'echo'      => false,
     434                'container' => false,
     435            )
     436        );
    327437
    328438        // After falling back, the empty 'container' argument should still return a container element.
     
    330440
    331441        // No menus + wp_nav_menu() falls back to wp_page_menu(), this time without white-space.
    332         $menu = wp_nav_menu( array(
    333             'echo'         => false,
    334             'item_spacing' => 'discard',
    335         ) );
     442        $menu = wp_nav_menu(
     443            array(
     444                'echo'         => false,
     445                'item_spacing' => 'discard',
     446            )
     447        );
    336448
    337449        // After falling back, the markup should not include whitespace around <li>s
Note: See TracChangeset for help on using the changeset viewer.