Make WordPress Core


Ignore:
Timestamp:
06/05/2014 02:09:12 AM (11 years ago)
Author:
SergeyBiryukov
Message:

Avoid an empty href attribute in paginate_links(). Add unit tests.

props obenland, Nessworthy.
fixes #24606.

File:
1 edited

Legend:

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

    r28397 r28671  
    8080        remove_filter( 'number_format_i18n', array( $this, 'increment_i18n_count' ) );
    8181    }
     82
     83    /**
     84     * @ticket 24606
     85     */
     86    function test_paginate_links_base_value() {
     87
     88        // Current page: 2
     89        $links = paginate_links( array(
     90            'current'  => 2,
     91            'total'    => 5,
     92            'end_size' => 1,
     93            'mid_size' => 1,
     94            'type'     => 'array',
     95        ) );
     96
     97        // 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] );
     100
     101        // It's not supposed to have an empty href.
     102        $this->assertNotTag( array( 'tag' => 'a', 'attributes' => array( 'class' => 'prev page-numbers', 'href' => '' ) ), $links[0] );
     103        $this->assertNotTag( array( 'tag' => 'a', 'attributes' => array( 'class' => 'page-numbers',      'href' => '' ) ), $links[1] );
     104
     105        // Current page: 1
     106        $links = paginate_links( array(
     107            'current'  => 1,
     108            'total'    => 5,
     109            'end_size' => 1,
     110            'mid_size' => 1,
     111            'type'     => 'array',
     112        ) );
     113
     114        $this->assertTag( array( 'tag' => 'span', 'attributes' => array( 'class' => 'current' ) ), $links[0] );
     115        $this->assertTag( array( 'tag' => 'a',    'attributes' => array( 'href' => '?page=2'  ) ), $links[1] );
     116    }
     117
    82118}
Note: See TracChangeset for help on using the changeset viewer.