Skip to content

Commit 3f8302c

Browse files
committed
Test for plain permalinks.
1 parent 5785971 commit 3f8302c

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

tests/phpunit/tests/general/paginateLinks.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,42 @@ public function test_permalinks_without_trailing_slash_produce_links_without_tra
453453
$this->assertGreaterThan( 0, $found_links, 'There should be pagination links found.' );
454454
}
455455

456+
/**
457+
* Ensures pagination links do not include trailing slashes when the permalink structure is plain.
458+
*
459+
* @ticket 61393
460+
*/
461+
public function test_plain_permalinks_are_not_modified_with_trailing_slash(): void {
462+
update_option( 'posts_per_page', 2 );
463+
$this->set_permalink_structure( '' );
464+
465+
$category_id = get_category_by_slug( 'categorized' )->term_id;
466+
$this->go_to( "/?cat={$category_id}&paged=2" );
467+
468+
// `current` needs to be passed as it's not picked up from the query vars set by `go_to()` above.
469+
$links = paginate_links( array( 'current' => 2 ) );
470+
471+
$expected_links = array(
472+
home_url( "?cat={$category_id}" ), // Previous
473+
home_url( "?cat={$category_id}" ), // Page 1
474+
home_url( "?paged=3&cat={$category_id}" ), // Page 3
475+
home_url( "?paged=4&cat={$category_id}" ), // Page 4
476+
home_url( "?paged=5&cat={$category_id}" ), // Page 5
477+
home_url( "?paged=3&cat={$category_id}" ), // Next
478+
);
479+
480+
$processor = new WP_HTML_Tag_Processor( $links );
481+
$found_links = 0;
482+
while ( $processor->next_tag( 'A' ) ) {
483+
$expected_link = $expected_links[ $found_links ] ?? '';
484+
++$found_links;
485+
$href = (string) $processor->get_attribute( 'href' );
486+
$this->assertStringStartsWith( trailingslashit( home_url() ), $href, 'Pagination links should contain the home URL followed by a trailing slash, found: ' . $href );
487+
$this->assertSame( $expected_link, $href, "Pagination links should include the category query string, found: $href" );
488+
}
489+
$this->assertGreaterThan( 0, $found_links, 'There should be pagination links found.' );
490+
}
491+
456492
/**
457493
* Ensures the pagination links do not modify query strings (permalinks with trailing slash).
458494
*

0 commit comments

Comments
 (0)