The theme switch was three labelled radios that wrapped the header onto a second line with long translations. It is three SVG buttons now, with search and menu sharing the same language: no resting outline, a filled chip for the active choice. Radios gave arrow-key roving for free, so the group reimplements it rather than losing it. The first chip colour put accent on accent and failed WCAG AA; the label carries full contrast instead. Mobile targets sit at 45px because a floor of exactly 44 rounds to 43.99997 in Firefox. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
77 lines
3.2 KiB
PHP
77 lines
3.2 KiB
PHP
<?php
|
|
/**
|
|
* Tests for the early theme preference bootstrap.
|
|
*
|
|
* @package CHRNX
|
|
*/
|
|
|
|
/** Verify no-flash bootstrap and toggle block contracts. */
|
|
class ThemePreferenceTest extends WP_UnitTestCase {
|
|
/** Bootstrap runs at the earliest wp_head priority. */
|
|
public function test_bootstrap_is_registered_at_priority_zero() {
|
|
$this->assertSame( 0, has_action( 'wp_head', 'chrnx_print_theme_preference_bootstrap' ) );
|
|
}
|
|
|
|
/** Bootstrap applies theme before enqueued stylesheet markup. */
|
|
public function test_bootstrap_precedes_styles_and_uses_only_local_preference_inputs() {
|
|
ob_start();
|
|
do_action( 'wp_head' );
|
|
$output = ob_get_clean();
|
|
|
|
$this->assertStringContainsString( 'chrnx-theme', $output );
|
|
$this->assertStringContainsString( 'prefers-color-scheme: dark', $output );
|
|
$this->assertStringContainsString( 'dataset.theme', $output );
|
|
$this->assertStringContainsString( 'colorScheme', $output );
|
|
$this->assertLessThan( strpos( $output, '<link' ), strpos( $output, 'dataset.theme' ) );
|
|
$this->assertStringNotContainsString( 'cookie', strtolower( $output ) );
|
|
$this->assertStringNotContainsString( 'fetch(', $output );
|
|
}
|
|
|
|
/** Standard inline-script filters can add CSP attributes without replacing the bootstrap. */
|
|
public function test_bootstrap_uses_filterable_wordpress_inline_script_tag() {
|
|
$filter = static function ( $attributes ) {
|
|
$attributes['nonce'] = 'test-nonce';
|
|
$attributes['data-test-policy'] = 'allowed';
|
|
return $attributes;
|
|
};
|
|
add_filter( 'wp_inline_script_attributes', $filter );
|
|
try {
|
|
ob_start();
|
|
chrnx_print_theme_preference_bootstrap();
|
|
$output = ob_get_clean();
|
|
} finally {
|
|
remove_filter( 'wp_inline_script_attributes', $filter );
|
|
}
|
|
|
|
$this->assertStringContainsString( 'nonce="test-nonce"', $output );
|
|
$this->assertStringContainsString( 'data-test-policy="allowed"', $output );
|
|
$this->assertStringContainsString( 'document.documentElement.dataset.theme=t', $output );
|
|
}
|
|
|
|
/** Toggle uses a labeled group of native toggle buttons with a live status. */
|
|
public function test_toggle_renders_accessible_native_controls() {
|
|
do_action( 'init' );
|
|
$output = render_block(
|
|
array(
|
|
'blockName' => 'chrnx/theme-toggle',
|
|
'attrs' => array(),
|
|
'innerBlocks' => array(),
|
|
'innerHTML' => '',
|
|
'innerContent' => array(),
|
|
)
|
|
);
|
|
|
|
$this->assertStringContainsString( 'role="group"', $output );
|
|
$this->assertStringContainsString( 'aria-labelledby="chrnx-theme-legend-', $output );
|
|
$this->assertSame( 3, substr_count( $output, 'data-chrnx-theme-value="' ) );
|
|
$this->assertSame( 1, substr_count( $output, 'aria-pressed="true"' ) );
|
|
$this->assertStringContainsString( 'data-chrnx-theme-value="light"', $output );
|
|
$this->assertStringContainsString( 'data-chrnx-theme-value="dark"', $output );
|
|
$this->assertStringContainsString( 'data-chrnx-theme-value="system"', $output );
|
|
$this->assertStringContainsString( 'aria-live="polite"', $output );
|
|
$this->assertStringContainsString( 'data-status-system-light="Light theme active, following system preference"', $output );
|
|
$this->assertStringContainsString( 'data-status-system-dark="Dark theme active, following system preference"', $output );
|
|
$this->assertStringContainsString( '<noscript>', $output );
|
|
}
|
|
}
|