feat: complete CHRNX responsive content states
This commit is contained in:
60 files changed
+1699
-22
No files matched your search
@@ -59,10 +59,11 @@ class PatternsTest extends WP_UnitTestCase {
|
||||
/** Local art is generated through escaped theme URIs with intrinsic dimensions. */
|
||||
public function test_art_patterns_use_only_escaped_local_theme_images() {
|
||||
foreach ( array( 'home-music', 'music-landing', 'podcast-landing', 'podcast-show' ) as $name ) {
|
||||
$source = file_get_contents( get_theme_file_path( 'patterns/' . $name . '.php' ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local test fixture.
|
||||
$content = $this->render_pattern( get_theme_file_path( 'patterns/' . $name . '.php' ) );
|
||||
$this->assertStringContainsString( 'get_theme_file_uri(', $source, $name );
|
||||
$this->assertStringContainsString( 'esc_url(', $source, $name );
|
||||
$source = file_get_contents( get_theme_file_path( 'patterns/' . $name . '.php' ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local test fixture.
|
||||
$content = $this->render_pattern( get_theme_file_path( 'patterns/' . $name . '.php' ) );
|
||||
$uses_responsive_helper = str_contains( $source, 'chrnx_get_topic_portrait_markup(' );
|
||||
$uses_direct_uri = str_contains( $source, 'get_theme_file_uri(' ) && str_contains( $source, 'esc_url(' );
|
||||
$this->assertTrue( $uses_responsive_helper || $uses_direct_uri, $name );
|
||||
$this->assertMatchesRegularExpression( '/<img\b[^>]*\bwidth="1122"[^>]*\bheight="1402"/i', $content, $name );
|
||||
$this->assertMatchesRegularExpression( '/<img\b[^>]*\bloading="lazy"[^>]*\bdecoding="async"/i', $content, $name );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Responsive theme media tests.
|
||||
*
|
||||
* @package CHRNX
|
||||
*/
|
||||
|
||||
/** Responsive asset helper coverage. */
|
||||
class ResponsiveMediaTest extends WP_UnitTestCase {
|
||||
/** Approved topic portraits render a compact picture element with a PNG fallback. */
|
||||
public function test_topic_portrait_picture_markup_has_modern_sources_and_dimensions() {
|
||||
$markup = chrnx_get_topic_portrait_markup( 'code', 'Code workshop portrait', 'chrnx-section-portrait' );
|
||||
|
||||
$this->assertStringContainsString( '<picture', $markup );
|
||||
$this->assertStringContainsString( 'type="image/avif"', $markup );
|
||||
$this->assertStringContainsString( 'type="image/webp"', $markup );
|
||||
$this->assertStringContainsString( 'alter-ego-code.png', $markup );
|
||||
$this->assertStringContainsString( 'width="1122"', $markup );
|
||||
$this->assertStringContainsString( 'height="1402"', $markup );
|
||||
$this->assertStringContainsString( 'loading="lazy"', $markup );
|
||||
$this->assertStringContainsString( 'decoding="async"', $markup );
|
||||
$this->assertStringContainsString( 'sizes="(max-width: 599px) 70vw, 384px"', $markup );
|
||||
$this->assertStringContainsString( 'alt="Code workshop portrait"', $markup );
|
||||
}
|
||||
|
||||
/** Unknown topic values cannot synthesize asset paths. */
|
||||
public function test_unknown_topic_portrait_returns_empty_markup() {
|
||||
$this->assertSame( '', chrnx_get_topic_portrait_markup( '../../private', '', '' ) );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user