fix: isolate CHRNX local integration state

This commit is contained in:
chrnx committed 2026-08-12 09:48:12 -05:00
1 parent 21da6da227
commit 6e93c0ad20
16 files changed
+536 -65

No files matched your search

+51
View File
@@ -712,6 +712,57 @@ class BlockRenderingTest extends WP_UnitTestCase {
}
}
/** Show archive pagination keeps canonical archive routing and rejects raw show filters. */
public function test_show_archive_pagination_preserves_internal_routing_only() {
global $wp_rewrite;
$previous_structure = get_option( 'permalink_structure' );
$term = get_term_by( 'slug', 'silicon-ranch', 'chrnx_show' );
for ( $index = 1; $index <= 12; ++$index ) {
$post_id = self::factory()->post->create( array( 'post_title' => 'Show archive result ' . $index ) );
wp_set_object_terms( $post_id, 'podcasts', 'chrnx_topic' );
wp_set_object_terms( $post_id, 'silicon-ranch', 'chrnx_show' );
}
$previous_get = $_GET; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Synthetic read-only request.
$pretty_link = static function ( $url, $term_object, $taxonomy ) {
if ( 'chrnx_show' === $taxonomy && 'silicon-ranch' === $term_object->slug ) {
return 'https://example.test/subdirectory/show/silicon-ranch/';
}
return $url;
};
try {
$wp_rewrite->set_permalink_structure( '/%postname%/' );
$this->go_to( get_term_link( $term ) );
add_filter( 'term_link', $pretty_link, 10, 3 );
$_GET = array( // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Synthetic read-only request.
'chrnx_show' => 'invented-show',
'evil' => 'drop-me',
);
$output = $this->render_journal_stream();
preg_match( '/chrnx-journal-stream__pagination.*?href="([^"]+)".*?<\/nav>/s', $output, $pretty_match );
$pretty_href = html_entity_decode( $pretty_match[1] ?? '', ENT_QUOTES | ENT_HTML5, 'UTF-8' );
$this->assertSame( '/subdirectory/show/silicon-ranch/', wp_parse_url( $pretty_href, PHP_URL_PATH ) );
parse_str( (string) wp_parse_url( $pretty_href, PHP_URL_QUERY ), $pretty_query );
$this->assertSame( 'silicon-ranch', $pretty_query['chrnx_show'] ?? '' );
$this->assertArrayNotHasKey( 'evil', $pretty_query );
remove_filter( 'term_link', $pretty_link, 10 );
$wp_rewrite->set_permalink_structure( '' );
$this->go_to( get_term_link( $term ) );
$output = $this->render_journal_stream();
preg_match( '/chrnx-journal-stream__pagination.*?href="([^"]+)".*?<\/nav>/s', $output, $plain_match );
$plain_href = html_entity_decode( $plain_match[1] ?? '', ENT_QUOTES | ENT_HTML5, 'UTF-8' );
parse_str( (string) wp_parse_url( $plain_href, PHP_URL_QUERY ), $plain_query );
$this->assertSame( 'silicon-ranch', $plain_query['chrnx_show'] ?? '' );
$this->assertSame( '2', (string) ( $plain_query['paged'] ?? '' ) );
$this->assertArrayNotHasKey( 'evil', $plain_query );
} finally {
remove_filter( 'term_link', $pretty_link, 10 );
$_GET = $previous_get;
$wp_rewrite->set_permalink_structure( $previous_structure );
$this->go_to( '/' );
}
}
/** Plain-permalink Journal links preserve Page routing and only validated public filters. */
public function test_journal_pagination_preserves_plain_page_routing() {
global $wp_rewrite;