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/general/paginateLinks.php

    r41371 r42343  
    1212
    1313    function test_defaults() {
    14         $page2 = get_pagenum_link( 2 );
    15         $page3 = get_pagenum_link( 3 );
     14        $page2  = get_pagenum_link( 2 );
     15        $page3  = get_pagenum_link( 3 );
    1616        $page50 = get_pagenum_link( 50 );
    1717
    18         $expected =<<<EXPECTED
     18        $expected = <<<EXPECTED
    1919<span aria-current='page' class='page-numbers current'>1</span>
    2020<a class='page-numbers' href='$page2'>2</a>
     
    3030
    3131    function test_format() {
    32         $page2 = home_url( '/page/2/' );
    33         $page3 = home_url( '/page/3/' );
     32        $page2  = home_url( '/page/2/' );
     33        $page3  = home_url( '/page/3/' );
    3434        $page50 = home_url( '/page/50/' );
    3535
    36         $expected =<<<EXPECTED
     36        $expected = <<<EXPECTED
    3737<span aria-current='page' class='page-numbers current'>1</span>
    3838<a class='page-numbers' href='$page2'>2</a>
     
    4343EXPECTED;
    4444
    45         $links = paginate_links( array( 'total' => 50, 'format' => 'page/%#%/' ) );
     45        $links = paginate_links(
     46            array(
     47                'total'  => 50,
     48                'format' => 'page/%#%/',
     49            )
     50        );
    4651        $this->assertEquals( $expected, $links );
    4752    }
    4853
    4954    function test_prev_next_false() {
    50         $home = home_url( '/' );
    51         $page3 = get_pagenum_link( 3 );
    52         $page4 = get_pagenum_link( 4 );
     55        $home   = home_url( '/' );
     56        $page3  = get_pagenum_link( 3 );
     57        $page4  = get_pagenum_link( 4 );
    5358        $page50 = get_pagenum_link( 50 );
    5459
    55         $expected =<<<EXPECTED
     60        $expected = <<<EXPECTED
    5661<a class='page-numbers' href='$home'>1</a>
    5762<span aria-current='page' class='page-numbers current'>2</span>
     
    6267EXPECTED;
    6368
    64         $links = paginate_links( array( 'total' => 50, 'prev_next' => false, 'current' => 2 ) );
     69        $links = paginate_links(
     70            array(
     71                'total'     => 50,
     72                'prev_next' => false,
     73                'current'   => 2,
     74            )
     75        );
    6576        $this->assertEquals( $expected, $links );
    6677    }
    6778
    6879    function test_prev_next_true() {
    69         $home = home_url( '/' );
    70         $page3 = get_pagenum_link( 3 );
    71         $page4 = get_pagenum_link( 4 );
     80        $home   = home_url( '/' );
     81        $page3  = get_pagenum_link( 3 );
     82        $page4  = get_pagenum_link( 4 );
    7283        $page50 = get_pagenum_link( 50 );
    7384
    74         $expected =<<<EXPECTED
     85        $expected = <<<EXPECTED
    7586<a class="prev page-numbers" href="$home">&laquo; Previous</a>
    7687<a class='page-numbers' href='$home'>1</a>
     
    8394EXPECTED;
    8495
    85         $links = paginate_links( array( 'total' => 50, 'prev_next' => true, 'current' => 2 ) );
     96        $links = paginate_links(
     97            array(
     98                'total'     => 50,
     99                'prev_next' => true,
     100                'current'   => 2,
     101            )
     102        );
    86103        $this->assertEquals( $expected, $links );
    87104    }
     
    97114        $this->i18n_count = 0;
    98115        add_filter( 'number_format_i18n', array( $this, 'increment_i18n_count' ) );
    99         paginate_links( array(
    100             'total'     => 100,
    101             'current'   => 50,
    102             'show_all'  => false,
    103             'prev_next' => true,
    104             'end_size'  => 1,
    105             'mid_size'  => 1,
    106         ) );
     116        paginate_links(
     117            array(
     118                'total'     => 100,
     119                'current'   => 50,
     120                'show_all'  => false,
     121                'prev_next' => true,
     122                'end_size'  => 1,
     123                'mid_size'  => 1,
     124            )
     125        );
    107126        // The links should be:
    108127        // < Previous 1 ... 49 50 51 ... 100 Next >
     
    117136
    118137        // Current page: 2
    119         $links = paginate_links( array(
    120             'current'  => 2,
    121             'total'    => 5,
    122             'end_size' => 1,
    123             'mid_size' => 1,
    124             'type'     => 'array',
    125         ) );
     138        $links = paginate_links(
     139            array(
     140                'current'  => 2,
     141                'total'    => 5,
     142                'end_size' => 1,
     143                'mid_size' => 1,
     144                'type'     => 'array',
     145            )
     146        );
    126147
    127148        $expected_attributes = array(
    128149            array(
    129150                'href'  => home_url( '/' ),
    130                 'class' => 'prev page-numbers'
     151                'class' => 'prev page-numbers',
    131152            ),
    132153            array(
    133154                'href'  => home_url( '/' ),
    134                 'class' => 'page-numbers'
    135             )
    136         );
    137 
    138         $document = new DOMDocument();
     155                'class' => 'page-numbers',
     156            ),
     157        );
     158
     159        $document                     = new DOMDocument();
    139160        $document->preserveWhiteSpace = false;
    140161
     
    142163        foreach ( $expected_attributes as $link_idx => $attributes ) {
    143164
    144             $document->loadHTML( $links[$link_idx] );
     165            $document->loadHTML( $links[ $link_idx ] );
    145166            $tag = $document->getElementsByTagName( 'a' )->item( 0 );
    146167
     
    155176
    156177        // Current page: 1
    157         $links = paginate_links( array(
    158             'current'  => 1,
    159             'total'    => 5,
    160             'end_size' => 1,
    161             'mid_size' => 1,
    162             'type'     => 'array',
    163         ) );
     178        $links = paginate_links(
     179            array(
     180                'current'  => 1,
     181                'total'    => 5,
     182                'end_size' => 1,
     183                'mid_size' => 1,
     184                'type'     => 'array',
     185            )
     186        );
    164187
    165188        $document->loadHTML( $links[0] );
     
    179202
    180203    function add_query_arg( $url ) {
    181         return add_query_arg( array(
    182             'foo' => 'bar',
    183             's'   => 'search+term',
    184         ), $url );
     204        return add_query_arg(
     205            array(
     206                'foo' => 'bar',
     207                's'   => 'search+term',
     208            ), $url
     209        );
    185210    }
    186211
     
    190215    function test_paginate_links_query_args() {
    191216        add_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) );
    192         $links = paginate_links( array(
    193             'current'  => 2,
    194             'total'    => 5,
    195             'end_size' => 1,
    196             'mid_size' => 1,
    197             'type'     => 'array',
    198         ) );
     217        $links = paginate_links(
     218            array(
     219                'current'  => 2,
     220                'total'    => 5,
     221                'end_size' => 1,
     222                'mid_size' => 1,
     223                'type'     => 'array',
     224            )
     225        );
    199226        remove_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) );
    200227
    201         $document = new DOMDocument();
     228        $document                     = new DOMDocument();
    202229        $document->preserveWhiteSpace = false;
    203230
     
    226253    function test_paginate_links_with_custom_query_args() {
    227254        add_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) );
    228         $links = paginate_links( array(
    229             'current'  => 2,
    230             'total'    => 5,
    231             'end_size' => 1,
    232             'mid_size' => 1,
    233             'type'     => 'array',
    234             'add_args' => array(
    235                 'baz' => 'qux',
    236             ),
    237         ) );
     255        $links = paginate_links(
     256            array(
     257                'current'  => 2,
     258                'total'    => 5,
     259                'end_size' => 1,
     260                'mid_size' => 1,
     261                'type'     => 'array',
     262                'add_args' => array(
     263                    'baz' => 'qux',
     264                ),
     265            )
     266        );
    238267        remove_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) );
    239268
    240         $document = new DOMDocument();
     269        $document                     = new DOMDocument();
    241270        $document->preserveWhiteSpace = false;
    242271
     
    264293    public function test_paginate_links_should_allow_non_default_format_without_add_args() {
    265294        // Fake the query params.
    266         $request_uri = $_SERVER['REQUEST_URI'];
     295        $request_uri            = $_SERVER['REQUEST_URI'];
    267296        $_SERVER['REQUEST_URI'] = add_query_arg( 'foo', 3, home_url() );
    268297
    269         $links = paginate_links( array(
    270             'base'    => add_query_arg( 'foo', '%#%' ),
    271             'format'  => '',
    272             'total'   => 5,
    273             'current' => 3,
    274             'type'    => 'array',
    275         ) );
     298        $links = paginate_links(
     299            array(
     300                'base'    => add_query_arg( 'foo', '%#%' ),
     301                'format'  => '',
     302                'total'   => 5,
     303                'current' => 3,
     304                'type'    => 'array',
     305            )
     306        );
    276307
    277308        $this->assertContains( '?foo=1', $links[1] );
     
    288319    public function test_paginate_links_should_allow_add_args_to_be_bool_false() {
    289320        // Fake the query params.
    290         $request_uri = $_SERVER['REQUEST_URI'];
     321        $request_uri            = $_SERVER['REQUEST_URI'];
    291322        $_SERVER['REQUEST_URI'] = add_query_arg( 'foo', 3, home_url() );
    292323
    293         $links = paginate_links( array(
    294             'add_args' => false,
    295             'base'    => add_query_arg( 'foo', '%#%' ),
    296             'format'  => '',
    297             'total'   => 5,
    298             'current' => 3,
    299             'type'    => 'array',
    300         ) );
     324        $links = paginate_links(
     325            array(
     326                'add_args' => false,
     327                'base'     => add_query_arg( 'foo', '%#%' ),
     328                'format'   => '',
     329                'total'    => 5,
     330                'current'  => 3,
     331                'type'     => 'array',
     332            )
     333        );
    301334
    302335        $this->assertContains( "<span aria-current='page' class='page-numbers current'>3</span>", $links );
     
    308341    public function test_custom_base_query_arg_should_be_stripped_from_current_url_before_generating_pag_links() {
    309342        // Fake the current URL: example.com?foo
    310         $request_uri = $_SERVER['REQUEST_URI'];
     343        $request_uri            = $_SERVER['REQUEST_URI'];
    311344        $_SERVER['REQUEST_URI'] = add_query_arg( 'foo', '', $request_uri );
    312345
    313         $links = paginate_links( array(
    314             'base'    => add_query_arg( 'foo', '%_%', home_url() ),
    315             'format'  => '%#%',
    316             'total'   => 5,
    317             'current' => 1,
    318             'type'    => 'array',
    319         ) );
     346        $links = paginate_links(
     347            array(
     348                'base'    => add_query_arg( 'foo', '%_%', home_url() ),
     349                'format'  => '%#%',
     350                'total'   => 5,
     351                'current' => 1,
     352                'type'    => 'array',
     353            )
     354        );
    320355
    321356        $page_2_url = home_url() . '?foo=2';
Note: See TracChangeset for help on using the changeset viewer.