feat: add editorial query blocks

This commit is contained in:
chrnx committed 2026-08-11 15:27:44 -05:00
1 parent 835fb74ebf
commit 89dcc53e02
24 files changed
+1421

No files matched your search

+106
View File
@@ -0,0 +1,106 @@
<?php
/**
* Tests for Reading settings.
*
* @package CHRNX
*/
/** Verify the subscribe page setting and public URL helper. */
class SettingsTest extends WP_UnitTestCase {
/** Reset state before each test. */
public function set_up() {
parent::set_up();
delete_option( 'chrnx_subscribe_page_id' );
wp_set_current_user( 0 );
if ( function_exists( 'chrnx_register_subscribe_setting' ) ) {
chrnx_register_subscribe_setting();
}
}
/** Setting registration uses an integer sanitizer and a Reading field. */
public function test_subscribe_setting_is_registered_on_reading_screen() {
global $wp_settings_fields;
$this->assertTrue( function_exists( 'chrnx_register_subscribe_setting' ) );
$registered = get_registered_settings();
$this->assertSame( 'integer', $registered['chrnx_subscribe_page_id']['type'] );
$this->assertSame( 0, call_user_func( $registered['chrnx_subscribe_page_id']['sanitize_callback'], 12345 ) );
$this->assertArrayHasKey( 'chrnx_subscribe_page_id', $wp_settings_fields['reading']['default'] );
}
/** Sanitizer accepts only a page editable by the current user. */
public function test_subscribe_setting_sanitizer_requires_an_editable_page() {
$admin = self::factory()->user->create( array( 'role' => 'administrator' ) );
$page = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
)
);
$post = self::factory()->post->create(
array(
'post_type' => 'post',
'post_status' => 'publish',
)
);
wp_set_current_user( $admin );
$this->assertSame( $page, chrnx_sanitize_subscribe_page_id( $page ) );
$this->assertSame( 0, chrnx_sanitize_subscribe_page_id( $post ) );
wp_set_current_user( 0 );
$this->assertSame( 0, chrnx_sanitize_subscribe_page_id( $page ) );
}
/** Public helper returns only a published configured Page permalink. */
public function test_subscribe_url_requires_a_published_page() {
$admin = self::factory()->user->create( array( 'role' => 'administrator' ) );
$page = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
)
);
$this->assertSame( '', chrnx_get_subscribe_url() );
wp_set_current_user( $admin );
update_option( 'chrnx_subscribe_page_id', $page );
$this->assertSame( get_permalink( $page ), chrnx_get_subscribe_url() );
wp_update_post(
array(
'ID' => $page,
'post_status' => 'draft',
)
);
$this->assertSame( '', chrnx_get_subscribe_url() );
wp_delete_post( $page, true );
$this->assertSame( '', chrnx_get_subscribe_url() );
$post = self::factory()->post->create(
array(
'post_type' => 'post',
'post_status' => 'publish',
)
);
update_option( 'chrnx_subscribe_page_id', $post );
$this->assertSame( '', chrnx_get_subscribe_url() );
}
/** Field callback uses the core page dropdown and escaped description. */
public function test_subscribe_field_renders_a_core_page_dropdown() {
self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
)
);
ob_start();
chrnx_render_subscribe_page_field();
$output = ob_get_clean();
$this->assertMatchesRegularExpression( '/name=[\'\"]chrnx_subscribe_page_id[\'\"]/', $output );
$this->assertStringContainsString( '<select', $output );
$this->assertStringContainsString( 'description', $output );
}
}