Files
chrnx-dev-wp/tests/php/ResponsiveMediaTest.php
chrnxandClaude Opus 5 cb491adae6 test: cover the new content models and stop duplicate terms
Seeding guarded with term_exists(), which reads a cache that is not
always warm during activation and let a second activation insert
gaming-2, literature-2 and silicon-ranch-2. It asks the taxonomy
directly now, by slug and by name.

Fixtures gain projects and tracks, and the suites follow the assets to
their generated derivatives. Also widens the Site Editor poll, which
threw instead of retrying while the editor was still booting.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-13 19:42:07 -05:00

79 lines
4.6 KiB
PHP

<?php
/**
* Responsive theme media tests.
*
* @package CHRNX
*/
/** Responsive asset helper coverage. */
class ResponsiveMediaTest extends WP_UnitTestCase {
/** The podcast atmosphere resolves only to its fixed local master and dimensions. */
public function test_podcast_atmosphere_asset_is_allowlisted_with_exact_dimensions() {
$this->assertSame( 'assets/images/podcast-frequency-grunge.png', chrnx_get_topic_art_asset( 'podcast-frequency' ) );
$this->assertSame( array( 1536, 1024 ), chrnx_get_topic_art_dimensions( 'podcast-frequency' ) );
}
/** Podcast atmosphere markup exposes all modern widths and a decorative fallback. */
public function test_podcast_atmosphere_markup_is_responsive_and_decorative() {
$markup = chrnx_get_atmosphere_markup( 'podcast-frequency', 'chrnx-character-stage__frequency' );
$this->assertStringContainsString( '<picture', $markup );
$this->assertStringContainsString( 'class="chrnx-responsive-atmosphere"', $markup );
$this->assertStringContainsString( 'aria-hidden="true"', $markup );
$this->assertStringContainsString( 'type="image/avif"', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-384.avif 384w', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-768.avif 768w', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-1536.avif 1536w', $markup );
$this->assertStringContainsString( 'type="image/webp"', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-384.webp 384w', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-768.webp 768w', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-1536.webp 1536w', $markup );
$this->assertStringContainsString( 'sizes="(max-width: 780px) 100vw, 1200px"', $markup );
$this->assertStringContainsString( 'src="http://', $markup );
$this->assertDoesNotMatchRegularExpression( '#src="[^"]*/assets/images/podcast-frequency-grunge\.png"#', $markup );
$this->assertStringContainsString( 'class="chrnx-character-stage__frequency"', $markup );
$this->assertStringContainsString( 'width="1536"', $markup );
$this->assertStringContainsString( 'height="1024"', $markup );
$this->assertStringContainsString( 'loading="lazy"', $markup );
$this->assertStringContainsString( 'decoding="async"', $markup );
$this->assertStringContainsString( 'alt=""', $markup );
}
/** Unknown atmosphere keys cannot synthesize asset paths or markup. */
public function test_unknown_atmosphere_returns_empty_markup() {
$this->assertSame( '', chrnx_get_atmosphere_markup( '../../private', 'unsafe class' ) );
}
/** Approved topic portraits render a compact picture element with a WebP 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 );
// The fallback is a generated derivative, never the design master.
$this->assertStringContainsString( 'generated/alter-ego-code-768.webp', $markup );
$this->assertDoesNotMatchRegularExpression( '#src="[^"]*/assets/images/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', '', '' ) );
}
/** Above-fold art opts into eager high-priority loading while defaults remain lazy. */
public function test_topic_portrait_loading_is_explicitly_allowlisted() {
$eager = chrnx_get_topic_portrait_markup( 'code', '', '', 'eager' );
$this->assertStringContainsString( 'loading="eager"', $eager );
$this->assertStringContainsString( 'fetchpriority="high"', $eager );
$this->assertStringContainsString( 'loading="lazy"', chrnx_get_topic_portrait_markup( 'code' ) );
$this->assertStringNotContainsString( 'fetchpriority="high"', chrnx_get_topic_portrait_markup( 'code', '', '', 'invalid' ) );
}
}