refactor: unify CHRNX character stages

This commit is contained in:
chrnx committed 2026-08-12 17:19:20 -05:00
1 parent 7ffb1a72f2
commit 59e4f36846
9 files changed
+345 -61

No files matched your search

+55
View File
@@ -628,6 +628,9 @@ class BlockRenderingTest extends WP_UnitTestCase {
$this->assertStringContainsString( 'loading="eager"', $output );
$this->assertStringContainsString( 'fetchpriority="high"', $output );
$this->assertStringContainsString( 'decoding="async"', $output );
$this->assertStringContainsString( 'type="image/avif"', $output );
$this->assertStringContainsString( 'type="image/webp"', $output );
$this->assertStringContainsString( 'srcset="', $output );
$unsafe = render_block(
array(
@@ -653,6 +656,58 @@ class BlockRenderingTest extends WP_UnitTestCase {
$this->assertStringContainsString( 'height="1536"', $gaming );
}
/** Topic heroes share the three-layer stage and unknown topics retain a safe labeled fallback. */
public function test_topic_hero_uses_shared_stage_and_labels_unknown_fallbacks() {
$attributes = array(
'topic' => 'future-topic',
'headingLevel' => 2,
);
ob_start();
include get_theme_file_path( 'blocks/topic-hero/render.php' );
$output = (string) ob_get_clean();
$this->assertStringContainsString( 'chrnx-topic-hero', $output );
$this->assertStringContainsString( 'chrnx-character-stage', $output );
$this->assertStringContainsString( '>Future Topic</h2>', $output );
$this->assertMatchesRegularExpression( '/class="chrnx-topic-hero__fallback" aria-hidden="true"/', $output );
$this->assertStringNotContainsString( '<img', $output );
$dom = new DOMDocument();
$dom->loadHTML( '<?xml encoding="utf-8" ?>' . $output, LIBXML_NOERROR | LIBXML_NOWARNING );
$xpath = new DOMXPath( $dom );
$stage = $xpath->query( '//*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage ")]' )->item( 0 );
$children = array();
foreach ( $stage->childNodes as $child ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property.
if ( XML_ELEMENT_NODE === $child->nodeType ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property.
$children[] = $child;
}
}
$this->assertCount( 3, $children );
$this->assertStringContainsString( 'chrnx-character-stage__atmosphere', $children[0]->getAttribute( 'class' ) );
$this->assertSame( 'true', $children[0]->getAttribute( 'aria-hidden' ) );
$this->assertStringContainsString( 'chrnx-character-stage__content', $children[1]->getAttribute( 'class' ) );
$this->assertStringContainsString( 'chrnx-character-stage__art', $children[2]->getAttribute( 'class' ) );
}
/** Show archives use podcast art without replacing the visible show name. */
public function test_show_archive_uses_podcasts_art_and_keeps_silicon_ranch_title() {
$show = get_term_by( 'slug', 'silicon-ranch', 'chrnx_show' );
$this->assertInstanceOf( WP_Term::class, $show );
$this->go_to( get_term_link( $show ) );
$output = render_block(
array(
'blockName' => 'chrnx/topic-hero',
'attrs' => array(),
)
);
$this->assertStringContainsString( '>Silicon Ranch</h2>', $output );
$this->assertStringContainsString( 'alter-ego-podcasts.png', $output );
$this->assertStringNotContainsString( '>Podcasts</h2>', $output );
$this->assertSame( 1, substr_count( $output, 'class="chrnx-character-stage"' ) );
}
/** Subscribe CTA is exactly empty until a published Page is configured. */
public function test_subscribe_cta_requires_a_valid_published_page() {
$block = array(