style: integrate CHRNX navigation and footer

This commit is contained in:
chrnx committed 2026-08-12 15:08:07 -05:00
1 parent 5a49cc5137
commit c7de54995f
8 files changed
+437 -26

No files matched your search

+178
View File
@@ -175,6 +175,171 @@ class BlockRenderingTest extends WP_UnitTestCase {
$this->assertStringNotContainsString( '<form', $output );
}
/** Exact destination pages map to their canonical local navigation URLs. */
public function test_current_navigation_destination_maps_exact_destination_pages() {
$this->assertTrue( function_exists( 'chrnx_get_current_navigation_destination' ) );
if ( ! function_exists( 'chrnx_get_current_navigation_destination' ) ) {
return;
}
foreach ( array( 'journal', 'projects', 'music', 'podcasts', 'about' ) as $slug ) {
$page_id = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => $slug,
'post_title' => ucfirst( $slug ),
)
);
$this->go_to( get_permalink( $page_id ) );
$this->assertSame( home_url( '/' . $slug . '/' ), chrnx_get_current_navigation_destination(), $slug );
}
}
/** Editorial requests all map to Journal, including every public editorial taxonomy. */
public function test_current_navigation_destination_maps_all_journal_contexts() {
$this->assertTrue( function_exists( 'chrnx_get_current_navigation_destination' ) );
if ( ! function_exists( 'chrnx_get_current_navigation_destination' ) ) {
return;
}
$post_id = self::factory()->post->create(
array(
'post_status' => 'publish',
'post_name' => 'journal-entry',
)
);
$this->go_to( get_permalink( $post_id ) );
$this->assertSame( home_url( '/journal/' ), chrnx_get_current_navigation_destination(), 'post single' );
$this->go_to( home_url( '/?s=editorial' ) );
$this->assertSame( home_url( '/journal/' ), chrnx_get_current_navigation_destination(), 'search' );
foreach (
array(
'chrnx_topic' => 'code',
'chrnx_language' => 'en',
'chrnx_show' => 'silicon-ranch',
) as $taxonomy => $slug
) {
$term = get_term_by( 'slug', $slug, $taxonomy );
$this->assertInstanceOf( WP_Term::class, $term );
$this->go_to( get_term_link( $term ) );
$this->assertSame( home_url( '/journal/' ), chrnx_get_current_navigation_destination(), $taxonomy );
}
$previous_show_on_front = get_option( 'show_on_front' );
$previous_page_for_posts = get_option( 'page_for_posts' );
try {
update_option( 'show_on_front', 'posts' );
update_option( 'page_for_posts', 0 );
$this->go_to( home_url( '/' ) );
$this->assertTrue( is_home() );
$this->assertSame( home_url( '/journal/' ), chrnx_get_current_navigation_destination(), 'Journal listing' );
} finally {
update_option( 'show_on_front', $previous_show_on_front );
update_option( 'page_for_posts', $previous_page_for_posts );
}
}
/** Front, unrelated, boundary-lookalike, and missing requests select no destination. */
public function test_current_navigation_destination_rejects_false_positives() {
$this->assertTrue( function_exists( 'chrnx_get_current_navigation_destination' ) );
if ( ! function_exists( 'chrnx_get_current_navigation_destination' ) ) {
return;
}
$previous_show_on_front = get_option( 'show_on_front' );
$previous_page_on_front = get_option( 'page_on_front' );
$front_id = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => 'home',
)
);
try {
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', $front_id );
$this->go_to( home_url( '/' ) );
$this->assertTrue( is_front_page() );
$this->assertSame( '', chrnx_get_current_navigation_destination(), 'front page' );
} finally {
update_option( 'show_on_front', $previous_show_on_front );
update_option( 'page_on_front', $previous_page_on_front );
}
foreach ( array( 'contact', 'music-notes' ) as $slug ) {
$page_id = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => $slug,
)
);
$this->go_to( get_permalink( $page_id ) );
$this->assertSame( '', chrnx_get_current_navigation_destination(), '/' . $slug . '/' );
}
$parent_id = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => 'collection',
)
);
$nested_id = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => 'music',
'post_parent' => $parent_id,
)
);
$this->go_to( get_permalink( $nested_id ) );
$this->assertSame( '', chrnx_get_current_navigation_destination(), '/collection/music/' );
$this->go_to( home_url( '/definitely-missing-chrnx-route/' ) );
$GLOBALS['wp_query']->is_404 = true;
$this->assertTrue( is_404() );
$this->assertSame( '', chrnx_get_current_navigation_destination(), '404' );
}
/** Header and footer each expose exactly one matching aria-current link. */
public function test_navigation_blocks_render_one_current_page_for_the_active_destination() {
$music_id = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => 'music',
'post_title' => 'Music',
)
);
$this->go_to( get_permalink( $music_id ) );
foreach ( array( 'chrnx/header-tools', 'chrnx/footer-content' ) as $block_name ) {
$output = $this->render_navigation_block( $block_name );
$this->assertSame( 1, substr_count( $output, 'aria-current="page"' ), $block_name );
$this->assertMatchesRegularExpression( '/<a[^>]+href="' . preg_quote( esc_url( home_url( '/music/' ) ), '/' ) . '"[^>]+aria-current="page"[^>]*>Music<\/a>/', $output );
}
}
/** Journal semantics apply to post singles without marking lookalike destinations. */
public function test_navigation_blocks_mark_only_journal_for_post_singles() {
$post_id = self::factory()->post->create(
array(
'post_status' => 'publish',
'post_name' => 'music-notes',
)
);
$this->go_to( get_permalink( $post_id ) );
foreach ( array( 'chrnx/header-tools', 'chrnx/footer-content' ) as $block_name ) {
$output = $this->render_navigation_block( $block_name );
$this->assertSame( 1, substr_count( $output, 'aria-current="page"' ), $block_name );
$this->assertMatchesRegularExpression( '/<a[^>]+href="' . preg_quote( esc_url( home_url( '/journal/' ) ), '/' ) . '"[^>]+aria-current="page"[^>]*>Journal<\/a>/', $output );
$this->assertDoesNotMatchRegularExpression( '/href="[^"]*music[^"]*"[^>]+aria-current="page"/', $output );
}
}
/** The approved local wordmark links to the portable site home URL. */
public function test_site_brand_renders_escaped_local_home_and_wordmark_urls() {
$output = render_block(
@@ -906,6 +1071,19 @@ class BlockRenderingTest extends WP_UnitTestCase {
);
}
/** Render one navigation block for the current main query. */
private function render_navigation_block( $block_name ) {
return render_block(
array(
'blockName' => $block_name,
'attrs' => array(),
'innerBlocks' => array(),
'innerHTML' => '',
'innerContent' => array(),
)
);
}
/** Render one dynamic post-context block for a specific post. */
private function render_for_post( $block_name, $post_id ) {
global $post;