feat: add CHRNX shell and theme preference
This commit is contained in:
18 files changed
+633
-16
No files matched your search
@@ -15,9 +15,9 @@ class BlockRenderingTest extends WP_UnitTestCase {
|
||||
delete_option( 'chrnx_subscribe_page_id' );
|
||||
}
|
||||
|
||||
/** All eight block types register from metadata. */
|
||||
/** All nine 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' );
|
||||
$names = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand' );
|
||||
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,24 @@ class BlockRenderingTest extends WP_UnitTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/** The approved local wordmark links to the portable site home URL. */
|
||||
public function test_site_brand_renders_escaped_local_home_and_wordmark_urls() {
|
||||
$output = render_block(
|
||||
array(
|
||||
'blockName' => 'chrnx/site-brand',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '',
|
||||
'innerContent' => array(),
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertStringContainsString( 'href="' . esc_url( home_url( '/' ) ) . '"', $output );
|
||||
$this->assertStringContainsString( 'src="' . esc_url( get_theme_file_uri( 'assets/icons/chrnx-wordmark.svg' ) ) . '"', $output );
|
||||
$this->assertStringContainsString( 'alt="CHRNX"', $output );
|
||||
$this->assertStringContainsString( 'href="#chrnx-main"', $output );
|
||||
}
|
||||
|
||||
/** Topic art is an exact fixed mapping and rejects arbitrary paths. */
|
||||
public function test_topic_art_uses_only_the_fixed_mapping() {
|
||||
$expected = array(
|
||||
|
||||
@@ -27,6 +27,27 @@ class ThemePreferenceTest extends WP_UnitTestCase {
|
||||
$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 native radio group with a live status. */
|
||||
public function test_toggle_renders_accessible_native_controls() {
|
||||
do_action( 'init' );
|
||||
@@ -47,5 +68,8 @@ class ThemePreferenceTest extends WP_UnitTestCase {
|
||||
$this->assertStringContainsString( 'value="dark"', $output );
|
||||
$this->assertStringContainsString( '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 );
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ class ThemeSetupTest extends WP_UnitTestCase {
|
||||
global $editor_styles;
|
||||
|
||||
$this->assertContains( 'assets/css/base.css', $editor_styles );
|
||||
$this->assertContains( 'assets/css/layout.css', $editor_styles );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,9 +55,14 @@ class ThemeSetupTest extends WP_UnitTestCase {
|
||||
|
||||
$this->assertSame( get_theme_file_uri( 'assets/css/base.css' ), $base->src );
|
||||
$this->assertSame( CHRNX_VERSION, $base->ver );
|
||||
$this->assertTrue( wp_style_is( 'chrnx-layout', 'enqueued' ) );
|
||||
$this->assertSame( array( 'chrnx-base' ), $styles->registered['chrnx-layout']->deps );
|
||||
$this->assertSame( get_theme_file_uri( 'assets/css/layout.css' ), $styles->registered['chrnx-layout']->src );
|
||||
} finally {
|
||||
wp_dequeue_style( 'chrnx-base' );
|
||||
wp_deregister_style( 'chrnx-base' );
|
||||
wp_dequeue_style( 'chrnx-layout' );
|
||||
wp_deregister_style( 'chrnx-layout' );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user