fix: address CHRNX editorial review findings

This commit is contained in:
chrnx committed 2026-08-11 18:18:05 -05:00
1 parent 247f9a7915
commit 7297523e26
17 files changed
+236 -10

No files matched your search

+78 -2
View File
@@ -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é &amp; 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. */