fix: harden CHRNX archive and pattern composition

This commit is contained in:
chrnx committed 2026-08-11 18:27:22 -05:00
1 parent 7297523e26
commit 2230731e1b
11 files changed
+214 -16

No files matched your search

+58 -3
View File
@@ -182,12 +182,21 @@ class BlockRenderingTest extends WP_UnitTestCase {
/** Empty/recovery links always point directly to a portable full Journal URL. */
public function test_journal_recovery_links_are_localized_and_portable() {
$journal_page = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => 'journal',
'post_title' => 'Journal',
)
);
$portable_home = static function ( $url, $path ) {
return 'https://example.test/subdirectory/' . ltrim( (string) $path, '/' );
};
add_filter( 'home_url', $portable_home, 10, 2 );
try {
$link = render_block(
$expected_url = esc_url( get_permalink( $journal_page ) );
$link = render_block(
array(
'blockName' => 'chrnx/journal-link',
'attrs' => array(),
@@ -196,7 +205,7 @@ class BlockRenderingTest extends WP_UnitTestCase {
'innerContent' => array(),
)
);
$this->assertStringContainsString( 'href="https://example.test/subdirectory/journal/"', $link );
$this->assertStringContainsString( 'href="' . $expected_url . '"', $link );
$this->assertStringContainsString( 'Browse the full Journal', $link );
$stream = render_block(
@@ -208,13 +217,59 @@ class BlockRenderingTest extends WP_UnitTestCase {
'innerContent' => array(),
)
);
$this->assertStringContainsString( 'href="https://example.test/subdirectory/journal/"', $stream );
$this->assertStringContainsString( 'href="' . $expected_url . '"', $stream );
$this->assertStringContainsString( 'Browse the full Journal', $stream );
} finally {
remove_filter( 'home_url', $portable_home, 10 );
}
}
/** Journal recovery falls back to a valid posts Page and then site home, never a guessed route. */
public function test_full_journal_url_has_non_404_plain_pretty_and_subdirectory_fallbacks() {
global $wp_rewrite;
$previous_structure = get_option( 'permalink_structure' );
$previous_posts_page = get_option( 'page_for_posts' );
$portable_home = static function ( $url, $path ) {
return 'https://example.test/subdirectory/' . ltrim( (string) $path, '/' );
};
$existing_journal = get_page_by_path( 'journal', OBJECT, 'page' );
if ( $existing_journal instanceof WP_Post ) {
wp_delete_post( $existing_journal->ID, true );
}
$posts_page = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => 'writing',
'post_title' => 'Writing',
)
);
update_option( 'page_for_posts', $posts_page );
try {
$wp_rewrite->set_permalink_structure( '' );
$this->assertSame( get_permalink( $posts_page ), chrnx_get_full_journal_url() );
$wp_rewrite->set_permalink_structure( '/%postname%/' );
$this->assertSame( get_permalink( $posts_page ), chrnx_get_full_journal_url() );
wp_update_post(
array(
'ID' => $posts_page,
'post_status' => 'draft',
)
);
add_filter( 'home_url', $portable_home, 10, 2 );
$this->assertSame( 'https://example.test/subdirectory/', chrnx_get_full_journal_url() );
$this->assertStringNotContainsString( '/journal/', chrnx_get_full_journal_url() );
remove_filter( 'home_url', $portable_home, 10 );
} finally {
remove_filter( 'home_url', $portable_home, 10 );
update_option( 'page_for_posts', $previous_posts_page );
$wp_rewrite->set_permalink_structure( $previous_structure );
}
}
/** Podcast metadata renders known text and HTTPS links, never embed HTML. */
public function test_podcast_meta_renders_only_known_escaped_fields() {
$post_id = self::factory()->post->create( array( 'post_title' => 'Episode' ) );