feat: define compact CHRNX header controls
This commit is contained in:
5 files changed
+100
-6
No files matched your search
@@ -70,6 +70,63 @@ class BlockRenderingTest extends WP_UnitTestCase {
|
||||
$this->assertStringContainsString( 'name="s"', $output );
|
||||
$this->assertStringContainsString( 'chrnx-screen-reader-text">Buscar</span>', $output );
|
||||
$this->assertStringContainsString( 'data-label-open="Abrir búsqueda"', $output );
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/data-chrnx-search-button[^>]+aria-controls="([^"]+)"[^>]+aria-expanded="false"/',
|
||||
$output
|
||||
);
|
||||
preg_match( '/data-chrnx-search-button[^>]+aria-controls="([^"]+)"/', $output, $search_control );
|
||||
$this->assertNotEmpty( $search_control[1] );
|
||||
$this->assertSame( 1, substr_count( $output, 'id="' . $search_control[1] . '"' ) );
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/<[^>]+id="' . preg_quote( $search_control[1], '/' ) . '"[^>]+data-chrnx-search-panel/',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/** Theme preference keeps native controls behind one translated mobile trigger. */
|
||||
public function test_theme_toggle_renders_accessible_mobile_trigger_and_native_panel() {
|
||||
$translate = static function ( $translated, $text, $domain ) {
|
||||
if ( 'chrnx' === $domain && 'Choose color theme' === $text ) {
|
||||
return 'Elegir tema de color';
|
||||
}
|
||||
return $translated;
|
||||
};
|
||||
add_filter( 'gettext', $translate, 10, 3 );
|
||||
try {
|
||||
$output = render_block(
|
||||
array(
|
||||
'blockName' => 'chrnx/theme-toggle',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '',
|
||||
'innerContent' => array(),
|
||||
)
|
||||
);
|
||||
} finally {
|
||||
remove_filter( 'gettext', $translate, 10 );
|
||||
}
|
||||
|
||||
$this->assertSame( 1, substr_count( $output, 'data-chrnx-theme-button' ) );
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/data-chrnx-theme-button[^>]+aria-controls="([^"]+)"[^>]+aria-expanded="false"[^>]+aria-label="Elegir tema de color"/',
|
||||
$output
|
||||
);
|
||||
preg_match( '/data-chrnx-theme-button[^>]+aria-controls="([^"]+)"/', $output, $theme_control );
|
||||
$this->assertNotEmpty( $theme_control[1] );
|
||||
$this->assertSame( 1, substr_count( $output, 'id="' . $theme_control[1] . '"' ) );
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/<fieldset[^>]+id="' . preg_quote( $theme_control[1], '/' ) . '"[^>]+data-chrnx-theme-toggle[^>]+data-chrnx-theme-panel/',
|
||||
$output
|
||||
);
|
||||
$this->assertSame( 3, substr_count( $output, 'type="radio"' ) );
|
||||
foreach ( array( 'light', 'dark', 'system' ) as $value ) {
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/<input[^>]+type="radio"[^>]+value="' . $value . '"/',
|
||||
$output
|
||||
);
|
||||
}
|
||||
$this->assertStringContainsString( 'data-chrnx-theme-status', $output );
|
||||
$this->assertStringContainsString( '<noscript>', $output );
|
||||
}
|
||||
|
||||
/** Mobile menu control is localized, initially hidden, and targets the one primary navigation. */
|
||||
|
||||
Reference in new issue
Block a user