59c9b698b7
從 wp-data-optimizer v3.4.6 移植 5 個 integration 測試檔,並新增 tests/integration/bootstrap.php(複用核心的 integration bootstrap,不重複 與 WP stub)+ phpunit-integration.xml + CI integration job。
132 lines
6.0 KiB
PHP
132 lines
6.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Integration test: WPDO_Hivepress_Term_Comment_Fields (v2.12.2 Phase 2).
|
|
*
|
|
* Verifies that the field group registration:
|
|
* - Hooks correctly into wpdo_register_entity_fields action
|
|
* - Calls register_group() exactly once per group
|
|
* - Registers expected keys with correct types/searchable flags
|
|
* - is_managed() returns true for registered keys
|
|
* - is_managed() returns false for unregistered keys (pass-through)
|
|
*
|
|
* Schema_Manager auto-creation of flat tables is exercised live in dev10
|
|
* smoke tests (see CHANGELOG); these tests focus on registry contract.
|
|
*/
|
|
class HivepressTermCommentFieldsTest extends TestCase {
|
|
|
|
public static function setUpBeforeClass(): void {
|
|
// Load adapter interface + term/comment adapters so register_group
|
|
// passes the adapter-presence guard (line 102 of entity-registry.php).
|
|
|
|
// Register adapters once for the whole test class (idempotent —
|
|
// register_adapter overwrites if entity_type already present).
|
|
WPDO_Entity_Registry::register_adapter( 'term', new WPDO_Adapter_Term() );
|
|
WPDO_Entity_Registry::register_adapter( 'comment', new WPDO_Adapter_Comment() );
|
|
|
|
// Register field groups once. register_group is guarded against
|
|
// duplicate registration (line 108 of entity-registry.php), so
|
|
// re-running register_entity_fields() in subsequent tests is no-op.
|
|
WPDO_Hivepress_Term_Comment_Fields::register_entity_fields();
|
|
}
|
|
|
|
protected function setUp(): void {
|
|
// Re-run registration for idempotency tests; no-op for already-registered groups.
|
|
WPDO_Hivepress_Term_Comment_Fields::register_entity_fields();
|
|
}
|
|
|
|
// ── Registration ────────────────────────────────────────────────────────
|
|
|
|
public function test_term_hp_taxonomy_group_registered(): void {
|
|
$keys = WPDO_Entity_Registry::get_group_keys( 'term', 'hp_taxonomy' );
|
|
$this->assertContains( 'hp_sort_order', $keys );
|
|
$this->assertContains( 'hp_default', $keys );
|
|
$this->assertContains( 'hp_icon', $keys );
|
|
$this->assertCount( 3, $keys );
|
|
}
|
|
|
|
public function test_comment_hp_review_group_registered(): void {
|
|
$keys = WPDO_Entity_Registry::get_group_keys( 'comment', 'hp_review' );
|
|
$this->assertContains( 'hp_rating', $keys );
|
|
$this->assertCount( 1, $keys );
|
|
}
|
|
|
|
// ── is_managed contract ─────────────────────────────────────────────────
|
|
|
|
public function test_term_hp_keys_are_managed(): void {
|
|
$this->assertTrue( WPDO_Entity_Registry::is_managed( 'term', 'hp_sort_order' ) );
|
|
$this->assertTrue( WPDO_Entity_Registry::is_managed( 'term', 'hp_default' ) );
|
|
$this->assertTrue( WPDO_Entity_Registry::is_managed( 'term', 'hp_icon' ) );
|
|
}
|
|
|
|
public function test_comment_hp_keys_are_managed(): void {
|
|
$this->assertTrue( WPDO_Entity_Registry::is_managed( 'comment', 'hp_rating' ) );
|
|
}
|
|
|
|
public function test_unregistered_term_keys_pass_through(): void {
|
|
$this->assertFalse( WPDO_Entity_Registry::is_managed( 'term', 'note_group' ) );
|
|
$this->assertFalse( WPDO_Entity_Registry::is_managed( 'term', 'product_count_product_cat' ) );
|
|
$this->assertFalse( WPDO_Entity_Registry::is_managed( 'term', '_wxr_import_user' ) );
|
|
}
|
|
|
|
public function test_unregistered_comment_keys_pass_through(): void {
|
|
$this->assertFalse( WPDO_Entity_Registry::is_managed( 'comment', 'note_group' ) );
|
|
$this->assertFalse( WPDO_Entity_Registry::is_managed( 'comment', '_wxr_import_user' ) );
|
|
}
|
|
|
|
public function test_term_keys_not_treated_as_comment_keys(): void {
|
|
// hp_sort_order is term-only; comment side should not see it as managed.
|
|
$this->assertFalse( WPDO_Entity_Registry::is_managed( 'comment', 'hp_sort_order' ) );
|
|
}
|
|
|
|
public function test_comment_keys_not_treated_as_term_keys(): void {
|
|
// hp_rating is comment-only; term side should not see it as managed.
|
|
$this->assertFalse( WPDO_Entity_Registry::is_managed( 'term', 'hp_rating' ) );
|
|
}
|
|
|
|
// ── Field metadata contract ─────────────────────────────────────────────
|
|
|
|
public function test_hp_sort_order_field_metadata(): void {
|
|
$field = WPDO_Entity_Registry::get_field( 'term', 'hp_sort_order' );
|
|
$this->assertNotNull( $field );
|
|
$this->assertSame( 'hp_sort_order', $field['key'] );
|
|
$this->assertSame( 'integer', $field['type'] );
|
|
$this->assertTrue( ! empty( $field['searchable'] ) );
|
|
}
|
|
|
|
public function test_hp_rating_field_metadata(): void {
|
|
$field = WPDO_Entity_Registry::get_field( 'comment', 'hp_rating' );
|
|
$this->assertNotNull( $field );
|
|
$this->assertSame( 'hp_rating', $field['key'] );
|
|
$this->assertSame( 'integer', $field['type'] );
|
|
$this->assertTrue( ! empty( $field['searchable'] ) );
|
|
}
|
|
|
|
public function test_hp_default_is_enum_with_options(): void {
|
|
$field = WPDO_Entity_Registry::get_field( 'term', 'hp_default' );
|
|
$this->assertSame( 'enum', $field['type'] );
|
|
$this->assertSame( array( '0', '1' ), $field['options'] ?? array() );
|
|
}
|
|
|
|
// ── get_field returns null for unregistered ─────────────────────────────
|
|
|
|
public function test_get_field_returns_null_for_unregistered(): void {
|
|
$this->assertNull( WPDO_Entity_Registry::get_field( 'term', 'unregistered_key' ) );
|
|
$this->assertNull( WPDO_Entity_Registry::get_field( 'comment', 'unregistered_key' ) );
|
|
}
|
|
|
|
// ── Bootstrap idempotency ───────────────────────────────────────────────
|
|
|
|
public function test_register_entity_fields_is_idempotent(): void {
|
|
// Re-running registration should not duplicate fields.
|
|
WPDO_Hivepress_Term_Comment_Fields::register_entity_fields();
|
|
WPDO_Hivepress_Term_Comment_Fields::register_entity_fields();
|
|
|
|
$keys = WPDO_Entity_Registry::get_group_keys( 'term', 'hp_taxonomy' );
|
|
$this->assertCount( 3, $keys, 'Re-registration must not duplicate keys' );
|
|
}
|
|
}
|