Files
2meet-data-optimizer/tests/unit/DeprecatedAddonsNoticeTest.php
T
wpdev c70dc99bf9 refactor(2meet-data-optimizer): stop registering the sso group in core
- 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
2026-09-26 03:39:58 +08:00

84 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* The 8 AddOns for in-house 2meet plugins are deprecated: each partner plugin
* registers its own tables and fields with the TMDO_Anti_EAV_Aware trait
* (docs/PARTNER-REGISTRATION.md). Admins running one get told so.
*/
class DeprecatedAddonsNoticeTest extends TestCase {
protected function setUp(): void {
if ( ! class_exists( 'TMDO_Deprecated_Addons_Notice' ) ) {
require_once TMDO_PATH . 'admin/class-tmdo-deprecated-addons-notice.php';
}
$GLOBALS['_wp_options'] = array();
$GLOBALS['_wp_current_user_can'] = array( 'manage_options' => true );
$GLOBALS['_wp_is_multisite'] = false;
}
private function activate( string ...$slugs ): void {
$GLOBALS['_wp_options']['active_plugins'] = array_map(
static fn( $s ) => "2meet-data-optimizer-{$s}-addon/2meet-data-optimizer-{$s}-addon.php",
$slugs
);
}
public function test_lists_only_active_deprecated_addons(): void {
$this->activate( 'spoke', 'hivepress', 'bookings' );
$this->assertSame( array( 'bookings', 'spoke' ), TMDO_Deprecated_Addons_Notice::active() );
}
public function test_notice_names_the_addons_and_points_to_the_guide(): void {
$this->activate( 'spoke' );
ob_start();
TMDO_Deprecated_Addons_Notice::render();
$html = (string) ob_get_clean();
$this->assertStringContainsString( '2meet-data-optimizer-spoke-addon', $html );
$this->assertStringContainsString( 'PARTNER-REGISTRATION.md', $html );
}
public function test_hub_and_spoke_point_to_the_sso_addon(): void {
$GLOBALS['_wp_options']['active_plugins'] = array( '2meet-data-optimizer-spoke-addon/2meet-data-optimizer-spoke-addon.php' );
ob_start();
TMDO_Deprecated_Addons_Notice::render();
$html = (string) ob_get_clean();
$this->assertStringContainsString( '2meet-data-optimizer-spoke-addon', $html );
$this->assertStringContainsString( '2meet-data-optimizer-sso-addon', $html );
}
public function test_no_notice_when_none_active_or_user_cannot_manage(): void {
ob_start();
TMDO_Deprecated_Addons_Notice::render();
$this->assertSame( '', ob_get_clean() );
$this->activate( 'spoke' );
$GLOBALS['_wp_current_user_can'] = array();
ob_start();
TMDO_Deprecated_Addons_Notice::render();
$this->assertSame( '', ob_get_clean() );
}
public function test_trait_passes_post_type_scope_to_the_registry(): void {
TMDO_Entity_Registry::init();
TMDO_Entity_Registry::register_adapter( 'post', $this->createMock( TMDO_Entity_Adapter_Interface::class ) );
$partner = new class() {
use TMDO_Anti_EAV_Aware;
public function run(): bool {
return $this->register_entity_fields( 'post', 'x_item', array( array( 'key' => 'x_price', 'type' => 'decimal' ) ), array( 'post_types' => array( 'x_item' ) ) );
}
};
$this->assertTrue( $partner->run() );
$this->assertSame( array( 'x_item' ), TMDO_Entity_Registry::get_group_post_types( 'post', 'x_item' ) );
}
}