Skip to content

Commit 2af697d

Browse files
committed
Tidy up tests a bit to include href portion of links.
1 parent 417f21d commit 2af697d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

tests/phpunit/tests/general/paginateLinks.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,13 @@ public function test_permalinks_with_trailing_slash_produce_links_with_trailing_
417417
// For some reason current isn't picked up.
418418
$links = paginate_links( array( 'current' => 2 ) );
419419

420-
$this->assertMatchesRegularExpression( '/\/categorized\/page\/[0-9]\/"/', $links, 'Pagination links with trailing slashes should be included.' );
421-
$this->assertDoesNotMatchRegularExpression( '/\/categorized\/page\/[0-9]"/', $links, 'Pagination links without trailing slashes should not be included.' );
420+
$base_url = untrailingslashit( home_url( '/category/categorized/' ) );
421+
$this->assertStringContainsString( "href=\"{$base_url}/\"", $links, 'The links should link to page one with a trailing slash.' );
422+
$this->assertStringNotContainsString( "href=\"{$base_url}\"", $links, 'The links should not link to page one without a trailing slash.' );
422423

423-
$this->assertStringContainsString( '/category/categorized/"', $links, 'The links should link to page one with a trailing slash.' );
424-
$this->assertStringNotContainsString( '/category/categorized"', $links, 'No links to page on should lack a trailing slash.' );
424+
$base_url_regex = preg_quote( $base_url, '/' );
425+
$this->assertMatchesRegularExpression( "/href=\"{$base_url_regex}\/page\/[0-9]\/\"/", $links, 'Pagination links with trailing slashes should be included.' );
426+
$this->assertDoesNotMatchRegularExpression( "/href=\"{$base_url_regex}\/page\/[0-9]\"/", $links, 'Pagination links without trailing slashes should not be included.' );
425427
}
426428

427429
/**
@@ -438,11 +440,13 @@ public function test_permalinks_without_trailing_slash_produce_links_without_tra
438440
// For some reason current isn't picked up.
439441
$links = paginate_links( array( 'current' => 2 ) );
440442

441-
$this->assertDoesNotMatchRegularExpression( '/\/categorized\/page\/[0-9]\/"/', $links, 'Pagination links with trailing slashes should not be included.' );
442-
$this->assertMatchesRegularExpression( '/\/categorized\/page\/[0-9]"/', $links, 'Pagination links without trailing slashes should be included.' );
443+
$base_url = untrailingslashit( home_url( '/category/categorized/' ) );
444+
$this->assertStringNotContainsString( "href=\"{$base_url}/\"", $links, 'The links should link to page one without a trailing slash.' );
445+
$this->assertStringContainsString( "href=\"{$base_url}\"", $links, 'The links should not link to page one with a trailing slash.' );
443446

444-
$this->assertStringNotContainsString( '/category/categorized/"', $links, 'The links should link to page one should not contain a trailing slash.' );
445-
$this->assertStringContainsString( '/category/categorized"', $links, 'The links to page one should not include a trailing slash.' );
447+
$base_url_regex = preg_quote( $base_url, '/' );
448+
$this->assertDoesNotMatchRegularExpression( "/href=\"$base_url_regex}\/page\/[0-9]\/\"/", $links, 'Pagination links with trailing slashes should not be included.' );
449+
$this->assertMatchesRegularExpression( "/href=\"{$base_url_regex}\/page\/[0-9]\"/", $links, 'Pagination links without trailing slashes should be included.' );
446450
}
447451

448452
/**

0 commit comments

Comments
 (0)