feat: add CHRNX theme preference and marks

This commit is contained in:
chrnx committed 2026-08-11 16:32:51 -05:00
1 parent ea62e9535d
commit aad237b211
11 files changed
+469 -3

No files matched your search

+2 -2
View File
@@ -15,9 +15,9 @@ class BlockRenderingTest extends WP_UnitTestCase {
delete_option( 'chrnx_subscribe_page_id' );
}
/** All seven block types register from metadata. */
/** All eight 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' );
$names = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle' );
foreach ( $names as $name ) {
$type = WP_Block_Type_Registry::get_instance()->get_registered( 'chrnx/' . $name );
$this->assertInstanceOf( WP_Block_Type::class, $type, $name );
+51
View File
@@ -0,0 +1,51 @@
<?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 );
}
}