refactor: compose CHRNX music and podcast stages
This commit is contained in:
8 files changed
+543
-19
No files matched your search
@@ -604,6 +604,24 @@ class BlockRenderingTest extends WP_UnitTestCase {
|
||||
$this->assertStringNotContainsString( '<iframe', $output );
|
||||
}
|
||||
|
||||
/** Podcast landing owns one dynamic latest block and renders one supporting card. */
|
||||
public function test_podcast_landing_renders_exactly_one_latest_podcast_card() {
|
||||
$post_id = self::factory()->post->create( array( 'post_title' => 'One landing conversation' ) );
|
||||
wp_set_object_terms( $post_id, 'podcasts', 'chrnx_topic' );
|
||||
wp_set_object_terms( $post_id, 'silicon-ranch', 'chrnx_show' );
|
||||
|
||||
ob_start();
|
||||
include get_theme_file_path( 'patterns/podcast-landing.php' );
|
||||
$content = (string) ob_get_clean();
|
||||
$output = do_blocks( $content );
|
||||
|
||||
$this->assertSame( 1, substr_count( $content, '<!-- wp:chrnx/latest-podcast /-->' ) );
|
||||
$this->assertSame( 1, preg_match_all( '/<section\b[^>]*class="[^"]*\bchrnx-latest-podcast\b[^"]*"/', $output ) );
|
||||
$this->assertSame( 1, substr_count( $output, 'One landing conversation' ) );
|
||||
$this->assertStringNotContainsString( '<audio', $output );
|
||||
$this->assertStringNotContainsString( '<iframe', $output );
|
||||
}
|
||||
|
||||
/** Topic hero uses approved decorative art for mapped topics and rejects arbitrary paths. */
|
||||
public function test_topic_hero_rejects_paths_and_uses_approved_decorative_art() {
|
||||
$output = render_block(
|
||||
|
||||
+77
-11
@@ -215,16 +215,20 @@ class PatternsTest extends WP_UnitTestCase {
|
||||
'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',
|
||||
'heading' => 'The No Names',
|
||||
'order' => array( 'The No Names', 'Grunge mexicano para cerebros que no se callan.', 'The No Names es una banda activa' ),
|
||||
'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',
|
||||
'atmosphere_hidden' => false,
|
||||
),
|
||||
'podcast-landing' => array(
|
||||
'heading' => 'Podcasts',
|
||||
'order' => array( 'Podcasts' ),
|
||||
'art' => 'alter-ego-podcasts.png',
|
||||
'art_alt' => '',
|
||||
'heading' => 'Podcasts',
|
||||
'order' => array( 'Podcasts', 'Conversations about the work behind software, research, music, and games.' ),
|
||||
'art' => 'alter-ego-podcasts.png',
|
||||
'art_alt' => '',
|
||||
'atmosphere' => 'chrnx-character-stage__frequency',
|
||||
),
|
||||
'about' => array(
|
||||
'heading' => 'About',
|
||||
@@ -251,7 +255,11 @@ class PatternsTest extends WP_UnitTestCase {
|
||||
}
|
||||
$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 );
|
||||
if ( false === ( $contract['atmosphere_hidden'] ?? true ) ) {
|
||||
$this->assertFalse( $children[0]->hasAttribute( 'aria-hidden' ), $name );
|
||||
} else {
|
||||
$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 );
|
||||
@@ -321,11 +329,60 @@ class PatternsTest extends WP_UnitTestCase {
|
||||
$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( 0, $xpath->query( 'ancestor::*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage__content ")]', $collage ) );
|
||||
$this->assertCount( 1, $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 ) );
|
||||
}
|
||||
|
||||
/** Music and Podcast compose their complete landing structures around one exact stage. */
|
||||
public function test_music_and_podcast_landing_compositions_are_structurally_complete() {
|
||||
$music = $this->render_pattern( get_theme_file_path( 'patterns/music-landing.php' ) );
|
||||
$music_dom = $this->load_html_fragment( $music );
|
||||
$music_xpath = new DOMXPath( $music_dom );
|
||||
$music_stage = $music_xpath->query( '//*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage ")]' )->item( 0 );
|
||||
$music_root = $music_xpath->query( '//*[@id="chrnx-test-root"]/*[1]' )->item( 0 );
|
||||
|
||||
$this->assertInstanceOf( DOMElement::class, $music_stage );
|
||||
$this->assertSame( 1, substr_count( $music, 'the-no-names-collage.jpeg' ) );
|
||||
$this->assertSame( 1, substr_count( $music, 'the-no-names-musician-cutout.png' ) );
|
||||
$this->assertSame( 1, $music_xpath->query( './*[1]//img[@alt="The No Names collage"]', $music_stage )->length );
|
||||
$this->assertSame( 0, $music_xpath->query( './*[2]//img[contains(@class,"chrnx-character-stage__collage")]', $music_stage )->length );
|
||||
$this->assertSame( 1, $music_xpath->query( './*[3]//img[@alt="The No Names musician portrait"]', $music_stage )->length );
|
||||
$this->assertSame( 3, $music_xpath->query( './*[2]/*[self::h2 or self::p]', $music_stage )->length );
|
||||
$process = $music_xpath->query( './p[contains(.,"El proceso usa generative AI")]', $music_root )->item( 0 );
|
||||
$releases = $music_xpath->query( './h3[normalize-space()="Releases in progress"]', $music_root )->item( 0 );
|
||||
$this->assertInstanceOf( DOMElement::class, $process );
|
||||
$this->assertInstanceOf( DOMElement::class, $releases );
|
||||
$this->assertSame( $music_stage, $process->previousElementSibling ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property.
|
||||
$this->assertSame( $process, $releases->previousElementSibling ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property.
|
||||
$this->assertSame( array( 2, 3, 4, 4, 4 ), $this->heading_levels( $music_dom ) );
|
||||
|
||||
$podcast = $this->render_pattern( get_theme_file_path( 'patterns/podcast-landing.php' ) );
|
||||
$podcast_dom = $this->load_html_fragment( $podcast );
|
||||
$podcast_xpath = new DOMXPath( $podcast_dom );
|
||||
$podcast_stage = $podcast_xpath->query( '//*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage ")]' )->item( 0 );
|
||||
$this->assertInstanceOf( DOMElement::class, $podcast_stage );
|
||||
$this->assertSame( 1, substr_count( $podcast, 'podcast-frequency-grunge.png' ) );
|
||||
$podcast_atmosphere = $podcast_dom->saveHTML( $podcast_xpath->query( './*[1]', $podcast_stage )->item( 0 ) );
|
||||
$this->assertStringContainsString( '<picture class="chrnx-responsive-atmosphere" aria-hidden="true">', $podcast_atmosphere );
|
||||
$this->assertStringContainsString( 'alt=""', $podcast_atmosphere );
|
||||
$podcast_art = $podcast_dom->saveHTML( $podcast_xpath->query( './*[3]', $podcast_stage )->item( 0 ) );
|
||||
$this->assertStringContainsString( '<picture class="chrnx-responsive-portrait" aria-hidden="true">', $podcast_art );
|
||||
$this->assertStringContainsString( 'alter-ego-podcasts.png', $podcast_art );
|
||||
$this->assertStringContainsString( 'alt=""', $podcast_art );
|
||||
$this->assertSame( 1, substr_count( $podcast, '<!-- wp:chrnx/latest-podcast /-->' ) );
|
||||
$this->assertSame( 1, substr_count( $podcast, '"metadata":{"name":"chrnx/podcast-show-discovery"}' ) );
|
||||
$this->assertSame( 1, substr_count( $podcast, '"metadata":{"name":"chrnx/podcast-archive"}' ) );
|
||||
$this->assertStringNotContainsString( 'chrnx/podcast-latest', $podcast );
|
||||
$this->assertLessThan( strpos( $podcast, '<!-- wp:chrnx/latest-podcast /-->' ), strpos( $podcast, '<!-- /wp:group -->', strpos( $podcast, 'chrnx-character-stage__art' ) ) );
|
||||
|
||||
$pages = json_decode( (string) file_get_contents( get_theme_file_path( 'tests/fixtures/pages.json' ) ), true ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local JSON fixture.
|
||||
$podcasts = array_values( array_filter( $pages, static fn( $page ) => 'podcasts' === $page['slug'] ) );
|
||||
$this->assertCount( 7, $pages );
|
||||
$this->assertCount( 1, $podcasts );
|
||||
$this->assertSame( '<!-- wp:pattern {"slug":"chrnx/podcast-landing"} /-->', $podcasts[0]['content'] );
|
||||
}
|
||||
|
||||
/** 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 ) {
|
||||
@@ -354,6 +411,15 @@ class PatternsTest extends WP_UnitTestCase {
|
||||
$this->assertContains( $class_name, preg_split( '/\s+/', trim( $element->getAttribute( 'class' ) ) ), $message );
|
||||
}
|
||||
|
||||
/** Return heading levels in document order. */
|
||||
private function heading_levels( DOMDocument $dom ) {
|
||||
$levels = array();
|
||||
foreach ( ( new DOMXPath( $dom ) )->query( '//h1|//h2|//h3|//h4|//h5|//h6' ) as $heading ) {
|
||||
$levels[] = (int) substr( strtolower( $heading->tagName ), 1 ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property.
|
||||
}
|
||||
return $levels;
|
||||
}
|
||||
|
||||
/** Return the ordered nested block-name tree while rejecting non-whitespace freeform nodes. */
|
||||
private function block_name_tree( array $blocks, $message ) {
|
||||
$tree = array();
|
||||
|
||||
Reference in new issue
Block a user