Skip to content

Commit e65393e

Browse files
committed
Tidy up tests a bit to include href portion of links.
1 parent 5c93224 commit e65393e

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

tests/phpunit/tests/general/paginateLinks.php

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

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

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

406408
/**
@@ -417,11 +419,13 @@ public function test_permalinks_without_trailing_slash_produce_links_without_tra
417419
// For some reason current isn't picked up.
418420
$links = paginate_links( array( 'current' => 2 ) );
419421

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

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

427431
/**

0 commit comments

Comments
 (0)