From 59e4f36846190cd3061ce50ed8c4036da0c8f1d3 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Wed, 12 Aug 2026 17:19:20 -0500 Subject: [PATCH] refactor: unify CHRNX character stages --- blocks/topic-hero/render.php | 55 +++++--- patterns/about.php | 27 ++-- patterns/home-music.php | 18 +-- patterns/home-projects.php | 26 ++-- patterns/music-landing.php | 21 ++-- patterns/podcast-landing.php | 13 +- tests/php/BlockRenderingTest.php | 55 ++++++++ tests/php/PatternsTest.php | 159 +++++++++++++++++++++++- tests/smoke/visual-integration.test.mjs | 32 ++++- 9 files changed, 345 insertions(+), 61 deletions(-) diff --git a/blocks/topic-hero/render.php b/blocks/topic-hero/render.php index 7f93da8..c152bb1 100644 --- a/blocks/topic-hero/render.php +++ b/blocks/topic-hero/render.php @@ -6,28 +6,43 @@ */ $chrnx_topic = isset( $attributes['topic'] ) && is_string( $attributes['topic'] ) ? $attributes['topic'] : ''; -if ( '' === $chrnx_topic && is_tax( 'chrnx_topic' ) ) { - $chrnx_queried = get_queried_object(); - $chrnx_topic = $chrnx_queried instanceof WP_Term ? $chrnx_queried->slug : ''; -} -$chrnx_asset = chrnx_get_topic_art_asset( $chrnx_topic ); -$chrnx_size = chrnx_get_topic_art_dimensions( $chrnx_topic ); -if ( '' === $chrnx_asset || 2 !== count( $chrnx_size ) ) { +if ( '' !== $chrnx_topic && ! preg_match( '/^[a-z0-9]+(?:-[a-z0-9]+)*$/', $chrnx_topic ) ) { return; } -$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 ); -$chrnx_term = get_term_by( 'slug', $chrnx_topic, 'chrnx_topic' ); -$chrnx_label = $chrnx_term instanceof WP_Term ? $chrnx_term->name : ucfirst( $chrnx_topic ); +$chrnx_queried = get_queried_object(); +$chrnx_taxonomy = ''; +if ( '' === $chrnx_topic && $chrnx_queried instanceof WP_Term && in_array( $chrnx_queried->taxonomy, array( 'chrnx_topic', 'chrnx_show' ), true ) ) { + $chrnx_topic = $chrnx_queried->slug; + $chrnx_taxonomy = $chrnx_queried->taxonomy; +} +if ( '' === $chrnx_topic ) { + return; +} +$chrnx_art_topic = 'chrnx_show' === $chrnx_taxonomy ? 'podcasts' : $chrnx_topic; +$chrnx_asset = chrnx_get_topic_art_asset( $chrnx_art_topic ); +$chrnx_size = chrnx_get_topic_art_dimensions( $chrnx_art_topic ); +$chrnx_has_art = '' !== $chrnx_asset && 2 === count( $chrnx_size ); +$chrnx_has_image = $chrnx_has_art && is_readable( get_theme_file_path( $chrnx_asset ) ); +$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 ); +$chrnx_term = $chrnx_queried instanceof WP_Term && $chrnx_queried->slug === $chrnx_topic ? $chrnx_queried : get_term_by( 'slug', $chrnx_topic, 'chrnx_topic' ); +$chrnx_label = $chrnx_term instanceof WP_Term ? $chrnx_term->name : ucwords( str_replace( '-', ' ', $chrnx_topic ) ); +$chrnx_classes = 'chrnx-topic-hero is-topic-' . sanitize_html_class( $chrnx_topic ); +$chrnx_wrapper = isset( $block ) && $block instanceof WP_Block ? get_block_wrapper_attributes( array( 'class' => $chrnx_classes ) ) : 'class="' . esc_attr( $chrnx_classes ) . '"'; ?> -
'chrnx-topic-hero is-topic-' . sanitize_html_class( $chrnx_topic ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> -
- class="chrnx-topic-hero__title">> -
-
- - - - - +
> +
+ +
+ class="chrnx-topic-hero__title">> +
+
+ + + +
diff --git a/patterns/about.php b/patterns/about.php index 70d39b2..b5e43cf 100644 --- a/patterns/about.php +++ b/patterns/about.php @@ -12,18 +12,27 @@ $chrnx_research_url = esc_url( 'https://arxiv.org/abs/2603.05352' ); ?>
- -
- + +
+ + +
+

+

+

.

+

+

+

+
+ +
+
+ + +
-

-

-

.

-

-

-

diff --git a/patterns/home-music.php b/patterns/home-music.php index 5d9faa9..95df04f 100644 --- a/patterns/home-music.php +++ b/patterns/home-music.php @@ -11,18 +11,18 @@ ?>
- -
-
- + +
+ + +

-
-
- -
+
+ +
- +
diff --git a/patterns/home-projects.php b/patterns/home-projects.php index 7c9c276..964a36b 100644 --- a/patterns/home-projects.php +++ b/patterns/home-projects.php @@ -11,15 +11,23 @@ ?>
- -

- -
-

-

-

+ +
+ + +
+

+ +
+

+

+

+
+ +
+ +
- - +
diff --git a/patterns/music-landing.php b/patterns/music-landing.php index 4201155..8589c09 100644 --- a/patterns/music-landing.php +++ b/patterns/music-landing.php @@ -8,18 +8,21 @@ * * @package CHRNX */ -$chrnx_music_collage = get_theme_file_uri( 'assets/images/the-no-names-collage.jpeg' ); ?>
-

-

-

-

- -
- <?php echo esc_attr__( 'The No Names collage', 'chrnx' ); ?> - + +
+ + +
+

+

+

+

+
+ +

diff --git a/patterns/podcast-landing.php b/patterns/podcast-landing.php index 071a608..1ba0fd5 100644 --- a/patterns/podcast-landing.php +++ b/patterns/podcast-landing.php @@ -11,8 +11,17 @@ ?>
-

- + +
+ + +
+

+
+ +
+
+
diff --git a/tests/php/BlockRenderingTest.php b/tests/php/BlockRenderingTest.php index 6a8e5ff..63ad455 100644 --- a/tests/php/BlockRenderingTest.php +++ b/tests/php/BlockRenderingTest.php @@ -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', $output ); + $this->assertMatchesRegularExpression( '/class="chrnx-topic-hero__fallback" aria-hidden="true"/', $output ); + $this->assertStringNotContainsString( 'loadHTML( '' . $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', $output ); + $this->assertStringContainsString( 'alter-ego-podcasts.png', $output ); + $this->assertStringNotContainsString( '>Podcasts', $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( diff --git a/tests/php/PatternsTest.php b/tests/php/PatternsTest.php index b0e4dfc..8489080 100644 --- a/tests/php/PatternsTest.php +++ b/tests/php/PatternsTest.php @@ -84,11 +84,11 @@ class PatternsTest extends WP_UnitTestCase { $content = $this->render_pattern( get_theme_file_path( 'patterns/home-music.php' ) ); $this->assertStringContainsString( "chrnx_get_topic_portrait_markup( 'music-collage'", $source ); - $this->assertStringContainsString( 'chrnx-home-music__collage-layer', $content ); + $this->assertStringContainsString( 'chrnx-character-stage__atmosphere', $content ); $this->assertStringContainsString( 'the-no-names-collage-384.avif 384w', $content ); $this->assertStringContainsString( 'the-no-names-collage-768.webp 768w', $content ); $this->assertStringContainsString( 'sizes="(max-width: 599px) 100vw, 720px"', $content ); - $this->assertMatchesRegularExpression( '/class="chrnx-home-music__collage"[^>]*loading="lazy"[^>]*alt=""/', $content ); + $this->assertMatchesRegularExpression( '/class="chrnx-character-stage__collage"[^>]*loading="lazy"[^>]*alt=""/', $content ); $this->assertStringContainsString( 'the-no-names-musician-cutout.png', $content ); $this->assertLessThan( strpos( $content, 'the-no-names-musician-cutout.png' ), @@ -197,6 +197,161 @@ class PatternsTest extends WP_UnitTestCase { } } + /** Section openings expose one block-valid three-layer character stage. */ + public function test_character_led_patterns_use_the_exact_shared_stage_api() { + $contracts = array( + 'home-projects' => array( + 'heading' => 'Selected work', + 'order' => array( 'Selected work', 'Expressive Tea', 'Ailed', 'Published research' ), + 'art' => 'alter-ego-code.png', + 'art_alt' => '', + 'atmosphere' => 'chrnx-character-stage__secondary-art', + ), + 'home-music' => array( + 'heading' => 'The No Names', + 'order' => array( 'The No Names', 'Grunge mexicano para cerebros que no se callan.', 'Un proyecto de banda activo hecho en Sinaloa: estudio crudo, cero live.' ), + 'art' => 'the-no-names-musician-cutout.png', + 'art_alt' => 'The No Names musician portrait', + 'atmosphere' => 'chrnx-character-stage__collage', + ), + 'music-landing' => array( + 'heading' => 'The No Names', + 'order' => array( 'The No Names', 'Grunge mexicano para cerebros que no se callan.', 'The No Names es una banda activa', 'El proceso usa generative AI' ), + 'art' => 'the-no-names-musician-cutout.png', + 'art_alt' => 'The No Names musician portrait', + 'atmosphere' => 'chrnx-character-stage__collage', + 'atmos_alt' => 'The No Names collage', + ), + 'podcast-landing' => array( + 'heading' => 'Podcasts', + 'order' => array( 'Podcasts' ), + 'art' => 'alter-ego-podcasts.png', + 'art_alt' => '', + ), + 'about' => array( + 'heading' => 'About', + 'order' => array( 'About', 'I work as Lead Developer @Expressive Tea', 'I am a published researcher.', 'I am an autistic Level 1 software developer and researcher.', 'Beyond the work', 'I am the father of three wonderful children' ), + 'art' => 'alter-ego-life.png', + 'art_alt' => '', + 'facets' => array( 'alter-ego-literature.png', 'alter-ego-gaming.png' ), + ), + ); + + foreach ( $contracts as $name => $contract ) { + $content = $this->render_pattern( get_theme_file_path( 'patterns/' . $name . '.php' ) ); + $dom = $this->load_html_fragment( $content ); + $xpath = new DOMXPath( $dom ); + $stages = $xpath->query( '//*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage ")]' ); + + $this->assertCount( 1, $stages, $name ); + $stage = $stages->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, $name ); + $this->assert_element_has_class( $children[0], 'chrnx-character-stage__atmosphere', $name ); + $this->assertSame( 'true', $children[0]->getAttribute( 'aria-hidden' ), $name ); + $this->assert_element_has_class( $children[1], 'chrnx-character-stage__content', $name ); + $this->assert_element_has_class( $children[2], 'chrnx-character-stage__art', $name ); + $this->assertCount( 1, $xpath->query( './/picture', $children[2] ), $name ); + $art_markup = $dom->saveHTML( $children[2] ); + $this->assertStringContainsString( $contract['art'], $art_markup, $name ); + $this->assertStringContainsString( 'type="image/avif"', $art_markup, $name ); + $this->assertStringContainsString( 'type="image/webp"', $art_markup, $name ); + $this->assertStringContainsString( 'srcset="', $art_markup, $name ); + $this->assertStringContainsString( 'loading="lazy"', $art_markup, $name ); + $this->assertStringContainsString( 'alt="' . $contract['art_alt'] . '"', $art_markup, $name ); + if ( '' === $contract['art_alt'] ) { + $this->assertStringContainsString( '