Make WordPress Core

Changeset 29780


Ignore:
Timestamp:
09/29/2014 04:02:23 AM (12 years ago)
Author:
wonderboymusic
Message:

In paginate_links(), ensure that query string args are propagated to the resulting paginated links.

Adds unit tests that use DOMDocument since assertTag is being deprecated - see #29545, [29746].

Props obenland, wonderboymusic.
Fixes #29636.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r29344 r29780  
    24862486                'mid_size' => 2,
    24872487                'type' => 'plain',
    2488                 'add_args' => false, // array of query args to add
     2488                'add_args' => $query_args, // array of query args to add
    24892489                'add_fragment' => '',
    24902490                'before_page_number' => '',
  • trunk/tests/phpunit/tests/general/paginateLinks.php

    r29746 r29780  
    127127                $expected_attributes = array(
    128128                        array(
    129                                 'href'  => 'http://' . WP_TESTS_DOMAIN . '/',
     129                                'href'  => home_url( '/' ),
    130130                                'class' => 'prev page-numbers'
    131131                        ),
    132132                        array(
    133                                 'href'  => 'http://' . WP_TESTS_DOMAIN . '/',
     133                                'href'  => home_url( '/' ),
    134134                                'class' => 'page-numbers'
    135135                        )
     
    178178        }
    179179
     180        function add_query_arg( $url ) {
     181                return add_query_arg( array( 'foo' => 'bar' ), $url );
     182        }
     183
     184        /**
     185         * @ticket 29636
     186         */
     187        function test_paginate_links_query_args() {
     188                add_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) );
     189                $links = paginate_links( array(
     190                        'current'  => 2,
     191                        'total'    => 5,
     192                        'end_size' => 1,
     193                        'mid_size' => 1,
     194                        'type'     => 'array',
     195                ) );
     196                remove_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) );
     197
     198                $document = new DOMDocument();
     199                $document->preserveWhiteSpace = false;
     200
     201                // All links should have foo=bar arguments:
     202                $data = array(
     203                        0 => home_url( '/?foo=bar' ),
     204                        1 => home_url( '/?foo=bar' ),
     205                        3 => home_url( '/?paged=3&foo=bar' ),
     206                        5 => home_url( '/?paged=5&foo=bar' ),
     207                        6 => home_url( '/?paged=3&foo=bar' ),
     208                );
     209
     210                foreach ( $data as $index => $expected_href ) {
     211                        $document->loadHTML( $links[ $index ] );
     212                        $tag = $document->getElementsByTagName( 'a' )->item( 0 );
     213                        $this->assertNotNull( $tag );
     214
     215                        $href = $tag->attributes->getNamedItem( 'href' )->value;
     216                        $this->assertEquals( $expected_href, $href );
     217                }
     218        }
    180219}
Note: See TracChangeset for help on using the changeset viewer.