WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/20/2014 05:11:14 PM (6 years ago)
Author:
wonderboymusic
Message:

Cleanup after [28671]:

  • Set better defaults in paginate_links(), so that themes don't have to calculate them on their own, like Twenty Fourteen does now.
  • Don't set page 1 to ?page=1 or /page/1/ - that will force a canonical redirect.
  • Add and cleanup unit tests

Props obenland, SergeyBiryukov, wonderboymusic.
Fixes #24606.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/general/paginateLinks.php

    r28671 r28785  
    55    private $i18n_count = 0;
    66
     7    function setUp() {
     8        parent::setUp();
     9
     10        $this->go_to( home_url( '/' ) );
     11    }
     12
    713    function test_defaults() {
     14        $page2 = get_pagenum_link( 2 );
     15        $page3 = get_pagenum_link( 3 );
     16        $page50 = get_pagenum_link( 50 );
     17
    818        $expected =<<<EXPECTED
    9 <a class='page-numbers' href=''>1</a>
     19<span class='page-numbers current'>1</span>
     20<a class='page-numbers' href='$page2'>2</a>
     21<a class='page-numbers' href='$page3'>3</a>
    1022<span class="page-numbers dots">&hellip;</span>
    11 <a class='page-numbers' href='?page=50'>50</a>
     23<a class='page-numbers' href='$page50'>50</a>
     24<a class="next page-numbers" href="$page2">Next &raquo;</a>
    1225EXPECTED;
    1326
     
    1730
    1831    function test_format() {
     32        $page2 = home_url( '/page/2/' );
     33        $page3 = home_url( '/page/3/' );
     34        $page50 = home_url( '/page/50/' );
     35
    1936        $expected =<<<EXPECTED
    20 <a class='page-numbers' href=''>1</a>
     37<span class='page-numbers current'>1</span>
     38<a class='page-numbers' href='$page2'>2</a>
     39<a class='page-numbers' href='$page3'>3</a>
    2140<span class="page-numbers dots">&hellip;</span>
    22 <a class='page-numbers' href='/page/50/'>50</a>
     41<a class='page-numbers' href='$page50'>50</a>
     42<a class="next page-numbers" href="$page2">Next &raquo;</a>
    2343EXPECTED;
    2444
    25         $links = paginate_links( array( 'total' => 50, 'format' => '/page/%#%/' ) );
     45        $links = paginate_links( array( 'total' => 50, 'format' => 'page/%#%/' ) );
    2646        $this->assertEquals( $expected, $links );
    2747    }
    2848
    2949    function test_prev_next_false() {
     50        $home = home_url( '/' );
     51        $page3 = get_pagenum_link( 3 );
     52        $page4 = get_pagenum_link( 4 );
     53        $page50 = get_pagenum_link( 50 );
     54
    3055        $expected =<<<EXPECTED
    31 <a class='page-numbers' href=''>1</a>
     56<a class='page-numbers' href='$home'>1</a>
    3257<span class='page-numbers current'>2</span>
    33 <a class='page-numbers' href='?page=3'>3</a>
    34 <a class='page-numbers' href='?page=4'>4</a>
     58<a class='page-numbers' href='$page3'>3</a>
     59<a class='page-numbers' href='$page4'>4</a>
    3560<span class="page-numbers dots">&hellip;</span>
    36 <a class='page-numbers' href='?page=50'>50</a>
     61<a class='page-numbers' href='$page50'>50</a>
    3762EXPECTED;
    3863
     
    4267
    4368    function test_prev_next_true() {
     69        $home = home_url( '/' );
     70        $page3 = get_pagenum_link( 3 );
     71        $page4 = get_pagenum_link( 4 );
     72        $page50 = get_pagenum_link( 50 );
     73
    4474        $expected =<<<EXPECTED
    45 <a class="prev page-numbers" href="">&laquo; Previous</a>
    46 <a class='page-numbers' href=''>1</a>
     75<a class="prev page-numbers" href="$home">&laquo; Previous</a>
     76<a class='page-numbers' href='$home'>1</a>
    4777<span class='page-numbers current'>2</span>
    48 <a class='page-numbers' href='?page=3'>3</a>
    49 <a class='page-numbers' href='?page=4'>4</a>
     78<a class='page-numbers' href='$page3'>3</a>
     79<a class='page-numbers' href='$page4'>4</a>
    5080<span class="page-numbers dots">&hellip;</span>
    51 <a class='page-numbers' href='?page=50'>50</a>
    52 <a class="next page-numbers" href="?page=3">Next &raquo;</a>
     81<a class='page-numbers' href='$page50'>50</a>
     82<a class="next page-numbers" href="$page3">Next &raquo;</a>
    5383EXPECTED;
    5484
     
    96126
    97127        // It's supposed to link to page 1:
    98         $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => '?page=1' ) ), $links[0] );
    99         $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => '?page=1' ) ), $links[1] );
     128        $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => 'http://' . WP_TESTS_DOMAIN . '/' ) ), $links[0] );
     129        $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => 'http://' . WP_TESTS_DOMAIN . '/' ) ), $links[1] );
    100130
    101131        // It's not supposed to have an empty href.
     
    113143
    114144        $this->assertTag( array( 'tag' => 'span', 'attributes' => array( 'class' => 'current' ) ), $links[0] );
    115         $this->assertTag( array( 'tag' => 'a',    'attributes' => array( 'href' => '?page=2' ) ), $links[1] );
     145        $this->assertTag( array( 'tag' => 'a',    'attributes' => array( 'href' => get_pagenum_link( 2 ) ) ), $links[1] );
    116146    }
    117147
Note: See TracChangeset for help on using the changeset viewer.