c70dc99bf9
- TMDO_Member_Fields no longer registers user/sso; the definition moved unchanged (hash 03543f19) to 2meet-data-optimizer-sso-addon. - missing_integration_addons(): 2meet-hub-core or 2meet-spoke-sso without the SSO AddOn is reported (admin notice + Site Health). - The deprecated-AddOn notice points hub / spoke users to the SSO AddOn. - Sites must activate the SSO AddOn before this ships (PR-041); aeav_only sites without it fall back to orphan-group restore. - Verify: core unit 659 / integration 475, SSO 6, HP 142/49, WC 10/22 green, phpcs clean - PR: PR-040
182 lines
7.3 KiB
PHP
182 lines
7.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Unit tests for WPDO_Member_Fields entity group registration.
|
|
*
|
|
* Verifies that register_entity_fields() correctly registers all four
|
|
* user groups with the expected field counts, types, and attributes.
|
|
*/
|
|
class MemberFieldsRegistrationTest extends TestCase {
|
|
|
|
protected function setUp(): void {
|
|
// Load the class under test if not already loaded.
|
|
if ( ! class_exists( 'WPDO_Member_Fields' ) ) {
|
|
require_once WPDO_PLUGIN_DIR . 'includes/integrations/class-tmdo-member-fields.php';
|
|
}
|
|
if ( ! class_exists( 'WPDO_Adapter_User' ) ) {
|
|
require_once WPDO_PLUGIN_DIR . 'includes/adapters/class-tmdo-adapter-user.php';
|
|
}
|
|
|
|
// Reset Entity Registry and register the user adapter.
|
|
WPDO_Entity_Registry::init();
|
|
WPDO_Entity_Registry::register_adapter( 'user', new WPDO_Adapter_User() );
|
|
}
|
|
|
|
// ── Group presence ───────────────────────────────────────────────────────
|
|
|
|
public function test_register_entity_fields_returns_early_without_entity_registry(): void {
|
|
// Class_exists('WPDO_Entity_Registry') will be true here, so we just
|
|
// confirm calling the method twice (dedup guard) returns false the 2nd time.
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
// Second call: groups already registered — register_group() returns false (dedup).
|
|
// No assertion needed: simply must not throw.
|
|
$this->assertTrue( true );
|
|
}
|
|
|
|
public function test_all_four_groups_are_registered(): void {
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
|
|
foreach ( array( 'membership', 'activity', 'profile' ) as $group ) {
|
|
$fields = WPDO_Entity_Registry::get_group_fields( 'user', $group );
|
|
$this->assertNotEmpty( $fields, "Group '{$group}' should have registered fields." );
|
|
}
|
|
}
|
|
|
|
public function test_core_leaves_the_sso_group_to_the_sso_addon(): void {
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
|
|
$this->assertSame( array(), WPDO_Entity_Registry::get_group_fields( 'user', 'sso' ) );
|
|
}
|
|
|
|
public function test_core_registers_no_hp_user_group(): void {
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
|
|
$this->assertSame( array(), WPDO_Entity_Registry::get_group_fields( 'user', 'hp_user' ), 'hp_user is owned by the HivePress AddOn' );
|
|
}
|
|
|
|
// ── membership group ─────────────────────────────────────────────────────
|
|
|
|
public function test_membership_group_has_six_fields(): void {
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
$fields = WPDO_Entity_Registry::get_group_fields( 'user', 'membership' );
|
|
$this->assertCount( 6, $fields );
|
|
}
|
|
|
|
public function test_membership_level_is_enum_with_five_options(): void {
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
$fields = WPDO_Entity_Registry::get_group_fields( 'user', 'membership' );
|
|
$level = $this->find_field( $fields, 'membership_level' );
|
|
|
|
$this->assertNotNull( $level );
|
|
$this->assertSame( 'enum', $level['type'] );
|
|
$this->assertCount( 5, $level['options'] );
|
|
$this->assertContains( 'gold', $level['options'] );
|
|
$this->assertContains( 'platinum', $level['options'] );
|
|
}
|
|
|
|
public function test_membership_level_is_searchable(): void {
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
$fields = WPDO_Entity_Registry::get_group_fields( 'user', 'membership' );
|
|
$level = $this->find_field( $fields, 'membership_level' );
|
|
|
|
$this->assertTrue( (bool) $level['searchable'] );
|
|
}
|
|
|
|
public function test_points_balance_is_integer_searchable(): void {
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
$fields = WPDO_Entity_Registry::get_group_fields( 'user', 'membership' );
|
|
$field = $this->find_field( $fields, 'points_balance' );
|
|
|
|
$this->assertSame( 'integer', $field['type'] );
|
|
$this->assertTrue( (bool) $field['searchable'] );
|
|
$this->assertSame( 0, $field['default'] );
|
|
}
|
|
|
|
public function test_membership_expires_at_is_datetime_searchable(): void {
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
$fields = WPDO_Entity_Registry::get_group_fields( 'user', 'membership' );
|
|
$field = $this->find_field( $fields, 'membership_expires_at' );
|
|
|
|
$this->assertSame( 'datetime', $field['type'] );
|
|
$this->assertTrue( (bool) $field['searchable'] );
|
|
}
|
|
|
|
// ── activity group ───────────────────────────────────────────────────────
|
|
|
|
public function test_activity_group_has_six_fields(): void {
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
$fields = WPDO_Entity_Registry::get_group_fields( 'user', 'activity' );
|
|
$this->assertCount( 6, $fields );
|
|
}
|
|
|
|
public function test_login_count_has_integer_type_and_zero_default(): void {
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
$fields = WPDO_Entity_Registry::get_group_fields( 'user', 'activity' );
|
|
$field = $this->find_field( $fields, 'login_count' );
|
|
|
|
$this->assertSame( 'integer', $field['type'] );
|
|
$this->assertSame( 0, $field['default'] );
|
|
}
|
|
|
|
public function test_account_flags_is_integer(): void {
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
$fields = WPDO_Entity_Registry::get_group_fields( 'user', 'activity' );
|
|
$field = $this->find_field( $fields, 'account_flags' );
|
|
|
|
$this->assertSame( 'integer', $field['type'] );
|
|
}
|
|
|
|
// ── profile group ────────────────────────────────────────────────────────
|
|
|
|
public function test_profile_group_has_five_fields(): void {
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
$fields = WPDO_Entity_Registry::get_group_fields( 'user', 'profile' );
|
|
$this->assertCount( 5, $fields );
|
|
}
|
|
|
|
public function test_specialties_is_json_type(): void {
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
$fields = WPDO_Entity_Registry::get_group_fields( 'user', 'profile' );
|
|
$field = $this->find_field( $fields, 'specialties' );
|
|
|
|
$this->assertSame( 'json', $field['type'] );
|
|
}
|
|
|
|
public function test_display_name_custom_is_fulltext_searchable(): void {
|
|
WPDO_Member_Fields::register_entity_fields();
|
|
$fields = WPDO_Entity_Registry::get_group_fields( 'user', 'profile' );
|
|
$field = $this->find_field( $fields, 'display_name_custom' );
|
|
|
|
$this->assertTrue( (bool) $field['searchable'] );
|
|
$this->assertTrue( (bool) $field['fulltext'] );
|
|
}
|
|
|
|
// ── register() hooks add_action ──────────────────────────────────────────
|
|
|
|
public function test_register_hooks_wpdo_register_entity_fields(): void {
|
|
// add_action is a no-op stub in test bootstrap; just confirm no exception.
|
|
$this->assertNull( WPDO_Member_Fields::register() );
|
|
}
|
|
|
|
// ── helper ───────────────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* Find a field definition by key within a fields array.
|
|
*
|
|
* @param array $fields Array of field definitions.
|
|
* @param string $key Meta key to find.
|
|
* @return array|null
|
|
*/
|
|
private function find_field( array $fields, string $key ): ?array {
|
|
foreach ( $fields as $field ) {
|
|
if ( $field['key'] === $key ) {
|
|
return $field;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|