fix: align CHRNX title eligibility

This commit is contained in:
chrnx committed 2026-08-11 16:06:47 -05:00
1 parent dab82cfa06
commit a769228c01
3 files changed
+66 -29

No files matched your search

+43 -25
View File
@@ -275,42 +275,60 @@ class EditorialQueriesTest extends WP_UnitTestCase {
$this->assertSame( array( $newer ), chrnx_get_featured_story_ids( 1 ) );
}
/** Tag-only titles are ineligible while marked-up titles with visible text remain eligible. */
public function test_tag_only_titles_are_excluded_from_featured_and_related_surfaces() {
$tag_only = $this->create_post( '<b></b>', '2026-06-05 10:00:00', 'research' );
$nested = $this->create_post( '<span><b> </b></span>', '2026-06-04 10:00:00', 'code' );
$visible = $this->create_post( '<b>Visible story</b>', '2026-06-03 10:00:00', 'life' );
update_option( 'sticky_posts', array( $tag_only, $nested ) );
/** Literal stored markup is nonempty title text and cannot make bounded selectors underfill. */
public function test_stored_markup_titles_are_eligible_for_featured_and_related_surfaces() {
$comment = $this->create_post( '<!-- > x -->', '2026-06-05 10:00:00', 'research' );
$attribute = $this->create_post( '<b title="> x"></b>', '2026-06-04 10:00:00', 'code' );
$nested = $this->create_post( '<span><b> </b></span>', '2026-06-03 10:00:00', 'life' );
update_option( 'sticky_posts', array( $comment ) );
$this->assertSame( array( $visible ), chrnx_get_featured_story_ids( 1 ) );
foreach ( array( $comment, $attribute, $nested ) as $post_id ) {
$this->assertTrue( chrnx_is_eligible_editorial_post( $post_id ) );
}
$this->assertSame( array( $comment, $attribute, $nested ), chrnx_get_featured_story_ids( 3 ) );
$current = $this->create_post( 'Current tags', '2026-06-06 10:00:00', 'research' );
$this->assertSame( array( $visible ), chrnx_get_related_post_ids( $current, 1 ) );
$this->assertSame( array( $comment, $attribute, $nested ), chrnx_get_related_post_ids( $current, 3 ) );
}
/** Journal and Show counts exclude tag-only titles without hiding visible marked-up titles. */
public function test_tag_only_titles_are_excluded_from_journal_and_show_queries() {
$tag_only = $this->create_post( '<b></b>', '2026-07-03 10:00:00', 'podcasts' );
$visible = $this->create_post( '<b>Visible episode</b>', '2026-07-02 10:00:00', 'podcasts' );
wp_set_object_terms( $tag_only, 'silicon-ranch', 'chrnx_show' );
wp_set_object_terms( $visible, 'silicon-ranch', 'chrnx_show' );
/** PHP uses the same POSIX whitespace definition as the prepared SQL predicate. */
public function test_php_title_eligibility_matches_sql_whitespace_semantics() {
$post = get_post( $this->create_post( 'Temporary title', '2026-06-07 10:00:00' ) );
$post->post_title = "\f";
$this->assertFalse( chrnx_is_eligible_editorial_post( $post ) );
$post->post_title = "\fX";
$this->assertTrue( chrnx_is_eligible_editorial_post( $post ) );
}
$journal = function_exists( 'chrnx_run_eligible_query' )
/** Journal and Show SQL use the same literal stored-title contract as PHP. */
public function test_stored_markup_titles_are_eligible_in_journal_and_show_queries() {
$comment = $this->create_post( '<!-- > x -->', '2026-07-03 10:00:00', 'podcasts' );
$attribute = $this->create_post( '<b title="> x"></b>', '2026-07-02 10:00:00', 'podcasts' );
$nested = $this->create_post( '<span><b> </b></span>', '2026-07-01 10:00:00', 'podcasts' );
$whitespace = $this->create_post( "\f", '2026-07-04 10:00:00', 'podcasts' );
foreach ( array( $comment, $attribute, $nested ) as $post_id ) {
wp_set_object_terms( $post_id, 'silicon-ranch', 'chrnx_show' );
}
wp_set_object_terms( $whitespace, 'silicon-ranch', 'chrnx_show' );
$this->assertFalse( chrnx_is_eligible_editorial_post( $whitespace ) );
$journal = function_exists( 'chrnx_run_eligible_query' )
? chrnx_run_eligible_query( chrnx_get_journal_query_args( array() ) )
: new WP_Query( chrnx_get_journal_query_args( array() ) );
$this->assertSame( array( $visible ), array_map( 'absint', wp_list_pluck( $journal->posts, 'ID' ) ) );
$this->assertSame( 1, (int) $journal->found_posts );
$this->assertSame( array( $visible ), $this->get_eligible_query_ids( chrnx_get_show_query_args( 'silicon-ranch' ) ) );
$expected = array( $comment, $attribute, $nested );
$this->assertSame( $expected, array_map( 'absint', wp_list_pluck( $journal->posts, 'ID' ) ) );
$this->assertSame( 3, (int) $journal->found_posts );
$this->assertSame( $expected, $this->get_eligible_query_ids( chrnx_get_show_query_args( 'silicon-ranch' ) ) );
}
/** Latest Podcast excludes tag-only titles and retains marked-up visible titles. */
public function test_tag_only_titles_are_excluded_from_latest_podcast() {
$visible = $this->create_post( '<b>Visible podcast</b>', '2026-08-01 10:00:00', 'podcasts' );
$tag_only = $this->create_post( '<b><span> </span></b>', '2026-08-02 10:00:00', 'podcasts' );
wp_set_object_terms( $visible, 'silicon-ranch', 'chrnx_show' );
wp_set_object_terms( $tag_only, 'silicon-ranch', 'chrnx_show' );
/** Latest Podcast treats nested stored markup as a nonempty literal title. */
public function test_stored_nested_markup_title_is_eligible_for_latest_podcast() {
$older = $this->create_post( 'Older podcast', '2026-08-01 10:00:00', 'podcasts' );
$nested = $this->create_post( '<b><span> </span></b>', '2026-08-02 10:00:00', 'podcasts' );
wp_set_object_terms( $older, 'silicon-ranch', 'chrnx_show' );
wp_set_object_terms( $nested, 'silicon-ranch', 'chrnx_show' );
$this->assertSame( $visible, chrnx_get_latest_podcast_id() );
$this->assertSame( $nested, chrnx_get_latest_podcast_id() );
}
/** Eligible SQL filtering is absent outside the focused wrapper, including exceptions. */