52 lines
1.9 KiB
PHP
52 lines
1.9 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 );
|
|
}
|
|
|
|
/** Toggle uses a labeled native radio group 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( '<fieldset', $output );
|
|
$this->assertStringContainsString( '<legend', $output );
|
|
$this->assertSame( 3, substr_count( $output, 'type="radio"' ) );
|
|
$this->assertStringContainsString( 'value="light"', $output );
|
|
$this->assertStringContainsString( 'value="dark"', $output );
|
|
$this->assertStringContainsString( 'value="system"', $output );
|
|
$this->assertStringContainsString( 'aria-live="polite"', $output );
|
|
}
|
|
}
|