fix: address CHRNX editorial review findings
This commit is contained in:
17 files changed
+236
-10
No files matched your search
@@ -15,9 +15,9 @@ class BlockRenderingTest extends WP_UnitTestCase {
|
||||
delete_option( 'chrnx_subscribe_page_id' );
|
||||
}
|
||||
|
||||
/** All twelve block types register from metadata. */
|
||||
/** All fourteen block types register from metadata. */
|
||||
public function test_all_editorial_blocks_are_registered() {
|
||||
$names = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand', 'mobile-menu-toggle', 'footer-content', 'header-tools' );
|
||||
$names = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand', 'mobile-menu-toggle', 'footer-content', 'header-tools', 'reading-time', 'journal-link' );
|
||||
foreach ( $names as $name ) {
|
||||
$type = WP_Block_Type_Registry::get_instance()->get_registered( 'chrnx/' . $name );
|
||||
$this->assertInstanceOf( WP_Block_Type::class, $type, $name );
|
||||
@@ -145,9 +145,73 @@ class BlockRenderingTest extends WP_UnitTestCase {
|
||||
);
|
||||
foreach ( $expected as $slug => $filename ) {
|
||||
$this->assertSame( 'assets/images/' . $filename, chrnx_get_topic_art_asset( $slug ) );
|
||||
$this->assertSame( 'gaming' === $slug ? array( 1024, 1536 ) : array( 1122, 1402 ), chrnx_get_topic_art_dimensions( $slug ) );
|
||||
}
|
||||
foreach ( array( '', 'unknown', '../secret.png', 'assets/images/anything.png' ) as $value ) {
|
||||
$this->assertSame( '', chrnx_get_topic_art_asset( $value ) );
|
||||
$this->assertSame( array(), chrnx_get_topic_art_dimensions( $value ) );
|
||||
}
|
||||
}
|
||||
|
||||
/** Reading time counts real Unicode words, ignores markup, and localizes singular/plural labels. */
|
||||
public function test_reading_time_is_robust_and_localized() {
|
||||
$this->assertSame( 0, chrnx_get_reading_time_minutes( '' ) );
|
||||
$this->assertSame( 1, chrnx_get_reading_time_minutes( '<!-- wp:paragraph --><p>Árbol, café & código.</p><!-- /wp:paragraph -->' ) );
|
||||
$this->assertSame( 2, chrnx_get_reading_time_minutes( implode( ' ', array_fill( 0, 201, 'palabra' ) ) ) );
|
||||
|
||||
$post_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_content' => implode( ' ', array_fill( 0, 201, 'palabra' ) ),
|
||||
)
|
||||
);
|
||||
$translate = static function ( $translation, $single, $plural, $number, $domain ) {
|
||||
if ( 'chrnx' === $domain && '%s minute read' === $single ) {
|
||||
return 1 === $number ? '%s minuto de lectura' : '%s minutos de lectura';
|
||||
}
|
||||
return $translation;
|
||||
};
|
||||
add_filter( 'ngettext', $translate, 10, 5 );
|
||||
try {
|
||||
$output = $this->render_for_post( 'chrnx/reading-time', $post_id );
|
||||
} finally {
|
||||
remove_filter( 'ngettext', $translate, 10 );
|
||||
}
|
||||
$this->assertStringContainsString( '2 minutos de lectura', $output );
|
||||
$this->assertStringNotContainsString( 'palabra', $output );
|
||||
}
|
||||
|
||||
/** Empty/recovery links always point directly to a portable full Journal URL. */
|
||||
public function test_journal_recovery_links_are_localized_and_portable() {
|
||||
$portable_home = static function ( $url, $path ) {
|
||||
return 'https://example.test/subdirectory/' . ltrim( (string) $path, '/' );
|
||||
};
|
||||
add_filter( 'home_url', $portable_home, 10, 2 );
|
||||
try {
|
||||
$link = render_block(
|
||||
array(
|
||||
'blockName' => 'chrnx/journal-link',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '',
|
||||
'innerContent' => array(),
|
||||
)
|
||||
);
|
||||
$this->assertStringContainsString( 'href="https://example.test/subdirectory/journal/"', $link );
|
||||
$this->assertStringContainsString( 'Browse the full Journal', $link );
|
||||
|
||||
$stream = render_block(
|
||||
array(
|
||||
'blockName' => 'chrnx/journal-stream',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '',
|
||||
'innerContent' => array(),
|
||||
)
|
||||
);
|
||||
$this->assertStringContainsString( 'href="https://example.test/subdirectory/journal/"', $stream );
|
||||
$this->assertStringContainsString( 'Browse the full Journal', $stream );
|
||||
} finally {
|
||||
remove_filter( 'home_url', $portable_home, 10 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,6 +299,18 @@ class BlockRenderingTest extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
$this->assertSame( '', $unsafe );
|
||||
|
||||
$gaming = render_block(
|
||||
array(
|
||||
'blockName' => 'chrnx/topic-hero',
|
||||
'attrs' => array( 'topic' => 'gaming' ),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '',
|
||||
'innerContent' => array(),
|
||||
)
|
||||
);
|
||||
$this->assertStringContainsString( 'width="1024"', $gaming );
|
||||
$this->assertStringContainsString( 'height="1536"', $gaming );
|
||||
}
|
||||
|
||||
/** Subscribe CTA is exactly empty until a published Page is configured. */
|
||||
|
||||
@@ -58,7 +58,7 @@ 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' ) as $name ) {
|
||||
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 );
|
||||
@@ -66,6 +66,15 @@ class PatternsTest extends WP_UnitTestCase {
|
||||
$this->assertMatchesRegularExpression( '/<img\b[^>]*\bwidth="1122"[^>]*\bheight="1402"/i', $content, $name );
|
||||
$this->assertMatchesRegularExpression( '/<img\b[^>]*\bloading="lazy"[^>]*\bdecoding="async"/i', $content, $name );
|
||||
}
|
||||
$music = $this->render_pattern( get_theme_file_path( 'patterns/music-landing.php' ) );
|
||||
$this->assertStringContainsString( 'the-no-names-collage.jpeg', $music );
|
||||
$this->assertStringContainsString( 'the-no-names-musician-cutout.png', $music );
|
||||
$this->assertSame( 2, substr_count( $music, '<img' ) );
|
||||
|
||||
$show = $this->render_pattern( get_theme_file_path( 'patterns/podcast-show.php' ) );
|
||||
$this->assertStringContainsString( 'alter-ego-podcasts.png', $show );
|
||||
$this->assertStringContainsString( 'alt=""', $show );
|
||||
$this->assertStringContainsString( 'aria-hidden="true"', $show );
|
||||
}
|
||||
|
||||
/** Music copy contains only the exact approved public facts and release statuses. */
|
||||
@@ -102,6 +111,10 @@ class PatternsTest extends WP_UnitTestCase {
|
||||
$this->assertStringContainsString( 'target="_blank"', $content );
|
||||
$this->assertStringContainsString( 'rel="noopener noreferrer external"', $content );
|
||||
$this->assertDoesNotMatchRegularExpression( '/diagnos|inspir|overcame|despite/i', $content );
|
||||
$plain = wp_strip_all_tags( $content );
|
||||
$this->assertLessThan( strpos( $plain, 'autistic Level 1' ), strpos( $plain, 'Lead Developer @Expressive Tea' ) );
|
||||
$this->assertLessThan( strpos( $plain, 'autistic Level 1' ), strpos( $plain, 'emotion modeling and game AI' ) );
|
||||
$this->assertLessThan( strpos( $plain, 'father of three wonderful children' ), strpos( $plain, 'autistic Level 1' ) );
|
||||
}
|
||||
|
||||
/** Reusable project/release/show/episode structures do not invent visible starter data. */
|
||||
|
||||
Reference in new issue
Block a user