Make WordPress Core

Ticket #29545: paginateLinks.php.diff

File paginateLinks.php.diff, 2.6 KB (added by jeffstieler, 10 years ago)
  • tests/phpunit/tests/general/paginateLinks.php

     
    124124                        'type'     => 'array',
    125125                ) );
    126126
    127                 // It's supposed to link to page 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] );
     127                $expected_attributes = array(
     128                        0 => array(
     129                                'href'  => 'http://' . WP_TESTS_DOMAIN . '/',
     130                                'class' => 'prev page-numbers'
     131                        ),
     132                        1 => array(
     133                                'href'  => 'http://' . WP_TESTS_DOMAIN . '/',
     134                                'class' => 'page-numbers'
     135                        )
     136                );
    130137
    131                 // It's not supposed to have an empty href.
    132                 $this->assertNotTag( array( 'tag' => 'a', 'attributes' => array( 'class' => 'prev page-numbers', 'href' => '' ) ), $links[0] );
    133                 $this->assertNotTag( array( 'tag' => 'a', 'attributes' => array( 'class' => 'page-numbers',      'href' => '' ) ), $links[1] );
     138                $document = new DOMDocument();
     139                $document->preserveWhiteSpace = false;
    134140
     141                // The first two links should link to page 1
     142                foreach ( $expected_attributes as $link_idx => $attributes ) {
     143
     144                        $document->loadHTML( $links[$link_idx] );
     145                        $tag = $document->getElementsByTagName( 'a' )->item( 0 );
     146
     147                        $this->assertNotNull( $tag );
     148
     149                        $href  = $tag->attributes->getNamedItem( 'href' )->value;
     150                        $class = $tag->attributes->getNamedItem( 'class' )->value;
     151
     152                        $this->assertEquals( $attributes['href'], $href );
     153                        $this->assertEquals( $attributes['class'], $class );
     154
     155                }
     156
    135157                // Current page: 1
    136158                $links = paginate_links( array(
    137159                        'current'  => 1,
     
    141163                        'type'     => 'array',
    142164                ) );
    143165
    144                 $this->assertTag( array( 'tag' => 'span', 'attributes' => array( 'class' => 'current' ) ), $links[0] );
    145                 $this->assertTag( array( 'tag' => 'a',    'attributes' => array( 'href' => get_pagenum_link( 2 ) ) ), $links[1] );
     166                $document->loadHTML( $links[0] );
     167                $tag = $document->getElementsByTagName( 'span' )->item( 0 );
     168
     169                $this->assertNotNull( $tag );
     170
     171                $class = $tag->attributes->getNamedItem( 'class' )->value;
     172
     173                $this->assertEquals( 'page-numbers current', $class );
     174
     175                $document->loadHTML( $links[1] );
     176                $tag = $document->getElementsByTagName( 'a' )->item( 0 );
     177
     178                $this->assertNotNull( $tag );
     179
     180                $href = $tag->attributes->getNamedItem( 'href' )->value;
     181
     182                $this->assertEquals( get_pagenum_link( 2 ), $href );
     183
    146184        }
    147185
    148186}