fix: harden CHRNX archive and pattern composition
This commit is contained in:
11 files changed
+214
-16
No files matched your search
@@ -181,6 +181,61 @@ class EditorialQueriesTest extends WP_UnitTestCase {
|
||||
$this->assertSame( 'es', $args['tax_query'][1]['terms'] );
|
||||
}
|
||||
|
||||
/** Real topic archives override conflicting request filters and never mix terms. */
|
||||
public function test_topic_archive_context_drives_journal_query_and_selector() {
|
||||
$code = self::factory()->post->create( array( 'post_title' => 'Code archive story' ) );
|
||||
$life = self::factory()->post->create( array( 'post_title' => 'Life archive story' ) );
|
||||
wp_set_object_terms( $code, 'code', 'chrnx_topic' );
|
||||
wp_set_object_terms( $life, 'life', 'chrnx_topic' );
|
||||
$term = get_term_by( 'slug', 'code', 'chrnx_topic' );
|
||||
$this->go_to( get_term_link( $term ) );
|
||||
|
||||
$previous_get = $_GET; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Synthetic read-only request.
|
||||
$_GET = array( 'chrnx_topic' => 'life' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Synthetic read-only request.
|
||||
try {
|
||||
$context = chrnx_get_journal_request_context( $_GET ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Synthetic read-only request.
|
||||
$output = render_block(
|
||||
array(
|
||||
'blockName' => 'chrnx/journal-stream',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '',
|
||||
'innerContent' => array(),
|
||||
)
|
||||
);
|
||||
} finally {
|
||||
$_GET = $previous_get;
|
||||
}
|
||||
|
||||
$this->assertSame( 'code', $context['chrnx_topic'] );
|
||||
$this->assertMatchesRegularExpression( '/value="code"\s+selected=[\'\"]selected[\'\"]/', $output );
|
||||
$this->assertStringContainsString( 'Code archive story', $output );
|
||||
$this->assertStringNotContainsString( 'Life archive story', $output );
|
||||
$this->assertStringContainsString( 'action="' . esc_url( get_term_link( $term ) ) . '"', $output );
|
||||
}
|
||||
|
||||
/** Language archives constrain results while unsupported taxonomy archives are ignored. */
|
||||
public function test_language_archive_context_is_allowlisted_and_other_taxonomies_are_not() {
|
||||
$spanish = self::factory()->post->create( array( 'post_title' => 'Historia en español' ) );
|
||||
$english = self::factory()->post->create( array( 'post_title' => 'English story' ) );
|
||||
wp_set_object_terms( $spanish, 'es', 'chrnx_language' );
|
||||
wp_set_object_terms( $english, 'en', 'chrnx_language' );
|
||||
$spanish_term = get_term_by( 'slug', 'es', 'chrnx_language' );
|
||||
$this->go_to( get_term_link( $spanish_term ) );
|
||||
|
||||
$context = chrnx_get_journal_request_context( array( 'chrnx_language' => 'en' ) );
|
||||
$args = chrnx_get_journal_query_args( $context );
|
||||
$query = chrnx_run_eligible_query( $args );
|
||||
$this->assertSame( 'es', $context['chrnx_language'] );
|
||||
$this->assertSame( array( $spanish ), array_map( 'absint', wp_list_pluck( $query->posts, 'ID' ) ) );
|
||||
|
||||
$tag = self::factory()->tag->create_and_get( array( 'slug' => 'not-allowlisted' ) );
|
||||
$this->go_to( get_term_link( $tag ) );
|
||||
$unsupported = chrnx_get_journal_request_context( array() );
|
||||
$this->assertArrayNotHasKey( 'post_tag', $unsupported );
|
||||
$this->assertArrayNotHasKey( 'tax_query', chrnx_get_journal_query_args( $unsupported ) );
|
||||
}
|
||||
|
||||
/** Malformed journal request values are ignored and never copied into query args. */
|
||||
public function test_journal_query_ignores_malformed_filters_and_caps_search() {
|
||||
$args = chrnx_get_journal_query_args(
|
||||
|
||||
Reference in new issue
Block a user