fix: clarify fixed CHRNX archive filters
This commit is contained in:
4 files changed
+160
-39
No files matched your search
@@ -270,6 +270,64 @@ class BlockRenderingTest extends WP_UnitTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/** Fixed archive dimensions render as context while the other selector and clear exit remain usable. */
|
||||
public function test_topic_archive_hides_inoperable_filter_and_keeps_language_and_clear_actions() {
|
||||
$code_es = self::factory()->post->create( array( 'post_title' => 'Code Spanish' ) );
|
||||
$code_en = self::factory()->post->create( array( 'post_title' => 'Code English' ) );
|
||||
$life_es = self::factory()->post->create( array( 'post_title' => 'Life Spanish' ) );
|
||||
foreach ( array( $code_es, $code_en ) as $post_id ) {
|
||||
wp_set_object_terms( $post_id, 'code', 'chrnx_topic' );
|
||||
}
|
||||
wp_set_object_terms( $life_es, 'life', 'chrnx_topic' );
|
||||
wp_set_object_terms( $code_es, 'es', 'chrnx_language' );
|
||||
wp_set_object_terms( $code_en, 'en', 'chrnx_language' );
|
||||
wp_set_object_terms( $life_es, 'es', 'chrnx_language' );
|
||||
$journal_page = self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'post_name' => 'journal',
|
||||
'post_title' => 'Journal',
|
||||
)
|
||||
);
|
||||
$this->go_to( get_term_link( get_term_by( 'slug', 'code', 'chrnx_topic' ) ) );
|
||||
$portable_home = static function ( $url, $path ) {
|
||||
return 'https://example.test/subdirectory/' . ltrim( (string) $path, '/' );
|
||||
};
|
||||
$previous_get = $_GET; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Synthetic read-only requests.
|
||||
add_filter( 'home_url', $portable_home, 10, 2 );
|
||||
try {
|
||||
// A conflicting fixed-topic submit must remain on Code while the free language filter works.
|
||||
$_GET = array( // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Synthetic read-only request.
|
||||
'chrnx_topic' => 'life',
|
||||
'chrnx_language' => 'es',
|
||||
);
|
||||
$filtered = $this->render_journal_stream();
|
||||
$this->assertStringNotContainsString( '<select name="chrnx_topic">', $filtered );
|
||||
$this->assertStringNotContainsString( '>All topics<', $filtered );
|
||||
$this->assertMatchesRegularExpression( '/chrnx-journal-stream__fixed-filter[^>]*>.*Topic.*Code/s', $filtered );
|
||||
$this->assertStringContainsString( '<select name="chrnx_language">', $filtered );
|
||||
$this->assertMatchesRegularExpression( '/value="es"\s+selected=[\'\"]selected[\'\"]/', $filtered );
|
||||
$this->assertStringContainsString( 'Code Spanish', $filtered );
|
||||
$this->assertStringNotContainsString( 'Code English', $filtered );
|
||||
$this->assertStringNotContainsString( 'Life Spanish', $filtered );
|
||||
|
||||
// Submitting All for the fixed dimension cannot clear the route context or create a dead control.
|
||||
$_GET = array( 'chrnx_topic' => '' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Synthetic read-only request.
|
||||
$all = $this->render_journal_stream();
|
||||
$this->assertStringNotContainsString( '<select name="chrnx_topic">', $all );
|
||||
$this->assertStringNotContainsString( '>All topics<', $all );
|
||||
$this->assertStringContainsString( 'Code Spanish', $all );
|
||||
$this->assertStringContainsString( 'Code English', $all );
|
||||
$this->assertStringNotContainsString( 'Life Spanish', $all );
|
||||
$this->assertStringContainsString( 'class="chrnx-journal-stream__clear"', $all );
|
||||
$this->assertStringContainsString( 'href="' . esc_url( get_permalink( $journal_page ) ) . '"', $all );
|
||||
} finally {
|
||||
$_GET = $previous_get;
|
||||
remove_filter( 'home_url', $portable_home, 10 );
|
||||
}
|
||||
}
|
||||
|
||||
/** Podcast metadata renders known text and HTTPS links, never embed HTML. */
|
||||
public function test_podcast_meta_renders_only_known_escaped_fields() {
|
||||
$post_id = self::factory()->post->create( array( 'post_title' => 'Episode' ) );
|
||||
@@ -710,6 +768,19 @@ class BlockRenderingTest extends WP_UnitTestCase {
|
||||
$this->assertNotSame( $first_label[1] ?? '', $second_label[1] ?? '' );
|
||||
}
|
||||
|
||||
/** Render the Journal stream block for the current request. */
|
||||
private function render_journal_stream() {
|
||||
return render_block(
|
||||
array(
|
||||
'blockName' => 'chrnx/journal-stream',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '',
|
||||
'innerContent' => array(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/** Render one dynamic post-context block for a specific post. */
|
||||
private function render_for_post( $block_name, $post_id ) {
|
||||
global $post;
|
||||
|
||||
Reference in new issue
Block a user