assertFileExists( $path, $name ); $source = file_get_contents( $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local test fixture. $this->assertMatchesRegularExpression( '/^\s*<\?php\s*\/\*\*.*?\*\sTitle:\s*.+$/ms', $source, $name ); $this->assertMatchesRegularExpression( '/^\s*\*\sSlug:\s*chrnx\/' . preg_quote( $name, '/' ) . '\s*$/m', $source, $name ); $this->assertMatchesRegularExpression( '/^\s*\*\sCategories:\s*\S.+$/m', $source, $name ); $this->assertMatchesRegularExpression( '/^\s*\*\sDescription:\s*\S.+$/m', $source, $name ); $this->assertMatchesRegularExpression( '/^\s*\*\sInserter:\s*(?:yes|no)\s*$/m', $source, $name ); if ( preg_match( '/(?:__|_e)\s*\(/', $source ) ) { $this->assertStringContainsString( "'chrnx'", $source, $name ); } $content = $this->render_pattern( $path ); $blocks = parse_blocks( $content ); $this->assertNotEmpty( $blocks, $name ); $this->assertSame( trim( $content ), trim( serialize_blocks( $blocks ) ), $name ); foreach ( $blocks as $parsed_block ) { if ( null === $parsed_block['blockName'] ) { $this->assertSame( '', trim( $parsed_block['innerHTML'] ), $name . ' has non-block content' ); } } $this->assertStringContainsString( '\s* 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' ), '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', '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', '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 ); 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 ); $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( '