fix: make CHRNX header fully progressive

This commit is contained in:
chrnx committed 2026-08-11 17:26:48 -05:00
1 parent e1579657d6
commit f983cec4f9
13 files changed
+414 -36

No files matched your search

+49 -2
View File
@@ -15,9 +15,9 @@ class BlockRenderingTest extends WP_UnitTestCase {
delete_option( 'chrnx_subscribe_page_id' );
}
/** All eleven block types register from metadata. */
/** All twelve block types register from metadata. */
public function test_all_editorial_blocks_are_registered() {
$names = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand', 'mobile-menu-toggle', 'footer-content' );
$names = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand', 'mobile-menu-toggle', 'footer-content', 'header-tools' );
foreach ( $names as $name ) {
$type = WP_Block_Type_Registry::get_instance()->get_registered( 'chrnx/' . $name );
$this->assertInstanceOf( WP_Block_Type::class, $type, $name );
@@ -25,6 +25,53 @@ class BlockRenderingTest extends WP_UnitTestCase {
}
}
/** Header navigation and search use translated labels and portable home URLs. */
public function test_header_tools_render_localized_portable_navigation_and_search() {
$translate = static function ( $translated, $text, $domain ) {
if ( 'chrnx' !== $domain ) {
return $translated;
}
return array(
'Primary navigation' => 'Navegación principal',
'Journal' => 'Diario',
'Search' => 'Buscar',
'Open search' => 'Abrir búsqueda',
)[ $text ] ?? $translated;
};
$portable_home = static function ( $url, $path ) {
return 'https://example.test/subdirectory/' . ltrim( (string) $path, '/' );
};
add_filter( 'gettext', $translate, 10, 3 );
add_filter( 'home_url', $portable_home, 10, 2 );
try {
$output = render_block(
array(
'blockName' => 'chrnx/header-tools',
'attrs' => array(),
'innerBlocks' => array(),
'innerHTML' => '',
'innerContent' => array(),
)
);
} finally {
remove_filter( 'home_url', $portable_home, 10 );
remove_filter( 'gettext', $translate, 10 );
}
$this->assertSame( 1, substr_count( $output, '<nav ' ) );
$this->assertStringContainsString( 'aria-label="Navegación principal"', $output );
$this->assertSame( 1, substr_count( $output, 'aria-label="Navegación principal"' ) );
$this->assertStringContainsString( '>Diario</a>', $output );
foreach ( array( 'journal', 'projects', 'music', 'podcasts', 'about' ) as $path ) {
$this->assertStringContainsString( 'href="https://example.test/subdirectory/' . $path . '/"', $output );
}
$this->assertStringContainsString( 'role="search"', $output );
$this->assertStringContainsString( 'action="https://example.test/subdirectory/"', $output );
$this->assertStringContainsString( 'name="s"', $output );
$this->assertStringContainsString( 'chrnx-screen-reader-text">Buscar</span>', $output );
$this->assertStringContainsString( 'data-label-open="Abrir búsqueda"', $output );
}
/** Mobile menu control is localized, initially hidden, and targets the one primary navigation. */
public function test_mobile_menu_toggle_renders_progressive_control() {
$output = render_block(