Files
2meet-data-optimizer/tests/unit/DeprecatedAddonsNoticeTest.php
T
wpdev 3d650eb848 docs(2meet-data-optimizer): partner self-registration guide and deprecated AddOn notice
- Add docs/PARTNER-REGISTRATION.md: TMDO_Anti_EAV_Aware bridge setup (plugins_loaded:3), table and entity-group registration with post_types scopes, frozen definitions, and the AddOn → self-registration migration checked with [COLLISION]/[ORPHAN]
- TMDO_Deprecated_Addons_Notice warns administrators while any of the 8 in-house partner AddOns is active (site or network)
- Trait register_entity_fields() forwards an optional $args (post_types) to the registry
- Verify: DeprecatedAddonsNoticeTest (4); core unit 645 / integration 449, HP 148, WC 10 OK
- PR: PR-021
2026-09-26 00:31:34 +08:00

73 lines
2.4 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_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' ) );
}
}