From fd0b0d5f4fb5d0b8b660c6fe5777187d374d9cf9 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 15 Sep 2014 17:41:47 +0000 Subject: [PATCH] `assertTag()` has been deprecated in PHPUnit 4.2. Rewrite some of the tests in `Tests_Paginate_Links` to use `DOMDocument`. Props effstieler. Fixes #29545. git-svn-id: https://develop.svn.wordpress.org/trunk@29746 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/general/paginateLinks.php | 48 +++++++++++++++---- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/tests/general/paginateLinks.php b/tests/phpunit/tests/general/paginateLinks.php index da674d4807..972864db6e 100644 --- a/tests/phpunit/tests/general/paginateLinks.php +++ b/tests/phpunit/tests/general/paginateLinks.php @@ -124,13 +124,34 @@ EXPECTED; 'type' => 'array', ) ); - // It's supposed to link to page 1: - $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => 'http://' . WP_TESTS_DOMAIN . '/' ) ), $links[0] ); - $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => 'http://' . WP_TESTS_DOMAIN . '/' ) ), $links[1] ); + $expected_attributes = array( + array( + 'href' => 'http://' . WP_TESTS_DOMAIN . '/', + 'class' => 'prev page-numbers' + ), + array( + 'href' => 'http://' . WP_TESTS_DOMAIN . '/', + 'class' => 'page-numbers' + ) + ); - // It's not supposed to have an empty href. - $this->assertNotTag( array( 'tag' => 'a', 'attributes' => array( 'class' => 'prev page-numbers', 'href' => '' ) ), $links[0] ); - $this->assertNotTag( array( 'tag' => 'a', 'attributes' => array( 'class' => 'page-numbers', 'href' => '' ) ), $links[1] ); + $document = new DOMDocument(); + $document->preserveWhiteSpace = false; + + // The first two links should link to page 1 + foreach ( $expected_attributes as $link_idx => $attributes ) { + + $document->loadHTML( $links[$link_idx] ); + $tag = $document->getElementsByTagName( 'a' )->item( 0 ); + + $this->assertNotNull( $tag ); + + $href = $tag->attributes->getNamedItem( 'href' )->value; + $class = $tag->attributes->getNamedItem( 'class' )->value; + + $this->assertEquals( $attributes['href'], $href ); + $this->assertEquals( $attributes['class'], $class ); + } // Current page: 1 $links = paginate_links( array( @@ -141,8 +162,19 @@ EXPECTED; 'type' => 'array', ) ); - $this->assertTag( array( 'tag' => 'span', 'attributes' => array( 'class' => 'current' ) ), $links[0] ); - $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => get_pagenum_link( 2 ) ) ), $links[1] ); + $document->loadHTML( $links[0] ); + $tag = $document->getElementsByTagName( 'span' )->item( 0 ); + $this->assertNotNull( $tag ); + + $class = $tag->attributes->getNamedItem( 'class' )->value; + $this->assertEquals( 'page-numbers current', $class ); + + $document->loadHTML( $links[1] ); + $tag = $document->getElementsByTagName( 'a' )->item( 0 ); + $this->assertNotNull( $tag ); + + $href = $tag->attributes->getNamedItem( 'href' )->value; + $this->assertEquals( get_pagenum_link( 2 ), $href ); } }