Merge branch 'feature/character-led-sections' into feature/music-podcast-grunge-stages

This commit is contained in:
chrnx committed 2026-08-13 00:21:36 -05:00
commit 7480f9c21e
20 files changed
+1313 -76

No files matched your search

+57 -1
View File
@@ -367,7 +367,7 @@ class BlockRenderingTest extends WP_UnitTestCase {
'music' => 'the-no-names-musician-cutout.png',
'podcasts' => 'alter-ego-podcasts.png',
'life' => 'alter-ego-life.png',
'gaming' => 'alter-ego-gaming.png',
'gaming' => 'alter-ego-gaming-half-body.png',
);
foreach ( $expected as $slug => $filename ) {
$this->assertSame( 'assets/images/' . $filename, chrnx_get_topic_art_asset( $slug ) );
@@ -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(
@@ -651,6 +654,59 @@ class BlockRenderingTest extends WP_UnitTestCase {
);
$this->assertStringContainsString( 'width="1024"', $gaming );
$this->assertStringContainsString( 'height="1536"', $gaming );
$this->assertStringContainsString( 'alter-ego-gaming-half-body', $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. */
+172 -2
View File
@@ -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,176 @@ 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',
),
'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-half-body.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( '<picture class="chrnx-responsive-portrait" aria-hidden="true">', $art_markup, $name );
} else {
$this->assertStringNotContainsString( '<picture class="chrnx-responsive-portrait" aria-hidden=', $art_markup, $name );
}
$this->assertSame( 1, substr_count( $dom->saveHTML( $children[1] ), '>' . $contract['heading'] . '</h2>' ), $name );
$this->assertStringNotContainsString( '<h1', strtolower( $content ), $name );
$plain = wp_strip_all_tags( $dom->saveHTML( $children[1] ) );
$previous = -1;
foreach ( $contract['order'] as $copy ) {
$position = strpos( $plain, $copy );
$this->assertNotFalse( $position, $name . ':' . $copy );
$this->assertGreaterThan( $previous, $position, $name . ':' . $copy );
$previous = $position;
}
if ( isset( $contract['atmosphere'] ) ) {
$atmosphere_markup = $dom->saveHTML( $children[0] );
$this->assertStringContainsString( $contract['atmosphere'], $atmosphere_markup, $name );
$this->assertStringContainsString( 'loading="lazy"', $atmosphere_markup, $name );
$this->assertStringContainsString( 'type="image/avif"', $atmosphere_markup, $name );
$this->assertStringContainsString( 'type="image/webp"', $atmosphere_markup, $name );
$this->assertStringContainsString( 'alt="' . ( $contract['atmos_alt'] ?? '' ) . '"', $atmosphere_markup, $name );
}
$this->assertCount( 0, $xpath->query( './/*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-facets ")]', $stage ), $name );
$facets = $xpath->query( '//*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-facets ")]' );
if ( isset( $contract['facets'] ) ) {
$this->assertCount( 1, $facets, $name );
$this->assertSame( $stage->parentNode, $facets->item( 0 )->parentNode, $name ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property.
$following_element = $stage->nextSibling; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property.
while ( $following_element && XML_ELEMENT_NODE !== $following_element->nodeType ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property.
$following_element = $following_element->nextSibling; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property.
}
$this->assertSame( $facets->item( 0 ), $following_element, $name );
$facets_markup = $dom->saveHTML( $facets->item( 0 ) );
foreach ( $contract['facets'] as $asset ) {
$this->assertStringContainsString( $asset, $facets_markup, $name );
}
$this->assertSame( 2, substr_count( $facets_markup, 'aria-hidden="true"' ), $name );
} else {
$this->assertCount( 0, $facets, $name );
}
}
}
/** Meaningful Music collage text remains exposed to assistive technology. */
public function test_music_landing_meaningful_collage_is_not_hidden_by_the_atmosphere_layer() {
$content = $this->render_pattern( get_theme_file_path( 'patterns/music-landing.php' ) );
$dom = $this->load_html_fragment( $content );
$xpath = new DOMXPath( $dom );
$stage = $xpath->query( '//*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage ")]' )->item( 0 );
$collage = $xpath->query( '//img[@alt="The No Names collage"]' )->item( 0 );
$this->assertInstanceOf( DOMElement::class, $stage );
$this->assertInstanceOf( DOMElement::class, $collage );
$this->assertCount( 3, $xpath->query( './*', $stage ) );
$this->assertCount( 0, $xpath->query( 'ancestor::*[@aria-hidden="true"]', $collage ) );
$this->assertCount( 1, $xpath->query( 'ancestor::*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage__content ")]', $collage ) );
$this->assertCount( 0, $xpath->query( './*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage__atmosphere ")]//picture', $stage ) );
$this->assertCount( 1, $xpath->query( './*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage__art ")]//picture', $stage ) );
}
/** Rendered pattern content survives parse/serialize without block-tree drift. */
public function test_character_led_patterns_preserve_editor_fidelity() {
foreach ( array( 'home-projects', 'home-music', 'music-landing', 'podcast-landing', 'about' ) as $name ) {
$content = $this->render_pattern( get_theme_file_path( 'patterns/' . $name . '.php' ) );
$parsed = parse_blocks( $content );
$serialized = serialize_blocks( $parsed );
$reparsed = parse_blocks( $serialized );
$initial_tree = $this->block_name_tree( $parsed, $name );
$round_trip = $this->block_name_tree( $reparsed, $name );
$this->assertSame( $initial_tree, $round_trip, $name );
$this->assertSame( 1, substr_count( strtolower( $content ), '<h2' ), $name );
$this->assertStringNotContainsString( '<h1', strtolower( $content ), $name );
}
}
/** Parse an HTML fragment for structural assertions. */
private function load_html_fragment( $content ) {
$dom = new DOMDocument();
$dom->loadHTML( '<?xml encoding="utf-8" ?><div id="chrnx-test-root">' . $content . '</div>', LIBXML_NOERROR | LIBXML_NOWARNING );
return $dom;
}
/** Assert a DOM element carries one class token. */
private function assert_element_has_class( DOMElement $element, $class_name, $message ) {
$this->assertContains( $class_name, preg_split( '/\s+/', trim( $element->getAttribute( 'class' ) ) ), $message );
}
/** Return the ordered nested block-name tree while rejecting non-whitespace freeform nodes. */
private function block_name_tree( array $blocks, $message ) {
$tree = array();
foreach ( $blocks as $block ) {
if ( null === $block['blockName'] ) {
$this->assertSame( '', trim( $block['innerHTML'] ), $message . ' has freeform corruption' );
continue;
}
$tree[] = array( $block['blockName'], $this->block_name_tree( $block['innerBlocks'], $message ) );
}
return $tree;
}
/** Render a pattern file exactly as WordPress does. */
private function render_pattern( $path ) {
ob_start();