Files
2meet-data-optimizer/tests/unit/MissingIntegrationAddonsTest.php
T
wpdev ecf4ff4938 refactor(2meet-data-optimizer): retire the SSO AddOn recommendation
- missing_integration_addons() no longer asks for the SSO AddOn when
  2meet-hub-core / 2meet-spoke-sso are active: they register their own
  tables and the `sso` values belong in usermeta (benchmark: no
  measurable gain from the flat table for by-user-id access).
- `sso` joins the deprecated AddOns; for hub / spoke / sso the notice says
  they go without replacement and to run
  `wp tmdo bridge-restore-native user --group=sso --retire` first.
- Verify: core unit 658 / integration 479 green, phpcs clean
- PR: PR-043
2026-09-26 04:07:40 +08:00

106 lines
3.6 KiB
PHP

<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* HivePress / WooCommerce running without their AddOn.
*
* Core knows nothing about either plugin: without the AddOn their fields are
* not optimised (and aeav_only data only survives through the orphan-group
* restore). Admins are warned in Site Health and with an admin notice.
*
* Tests that declare HivePress / WooCommerce / AddOn stand-in classes run in
* their own process so those classes do not leak into other tests.
*/
class MissingIntegrationAddonsTest extends TestCase {
protected function setUp(): void {
if ( ! class_exists( 'TMDO_Site_Health' ) ) {
require_once TMDO_PATH . 'includes/diagnostic/class-tmdo-site-health.php';
}
if ( ! class_exists( 'TMDO_Missing_Addons_Notice' ) ) {
require_once TMDO_PATH . 'admin/class-tmdo-missing-addons-notice.php';
}
if ( ! function_exists( 'admin_url' ) ) {
// Site Health failure envelopes link to the admin page; a fresh process lacks the stub.
eval( 'function admin_url( $path = "" ) { return "/wp-admin/" . $path; }' );
}
$GLOBALS['_wp_options'] = array();
$GLOBALS['_wp_current_user_can'] = array( 'manage_options' => true );
}
public function test_nothing_missing_without_the_integrations(): void {
$this->assertSame( array(), TMDO_Compatibility::missing_integration_addons() );
$this->assertSame( 'good', TMDO_Site_Health::check_missing_integration_addons()['status'] );
$this->assertArrayHasKey( 'wpdo_missing_integration_addons', TMDO_Site_Health::register_tests( array() )['direct'] );
ob_start();
TMDO_Missing_Addons_Notice::render();
$this->assertSame( '', ob_get_clean() );
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_hivepress_without_its_addon_is_reported(): void {
eval( 'namespace HivePress; class Core {}' );
$this->assertSame( array( 'HivePress' => '2meet-data-optimizer-hivepress-addon' ), TMDO_Compatibility::missing_integration_addons() );
$result = TMDO_Site_Health::check_missing_integration_addons();
$this->assertSame( 'recommended', $result['status'] );
$this->assertStringContainsString( '2meet-data-optimizer-hivepress-addon', $result['description'] );
ob_start();
TMDO_Missing_Addons_Notice::render();
$this->assertStringContainsString( '2meet-data-optimizer-hivepress-addon', (string) ob_get_clean() );
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_hivepress_with_its_addon_is_fine(): void {
eval( 'namespace HivePress; class Core {}' );
eval( 'final class TMDO_HP_Bootstrap {}' );
$this->assertSame( array(), TMDO_Compatibility::missing_integration_addons() );
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_woocommerce_without_its_addon_is_reported(): void {
eval( 'class WooCommerce {}' );
$this->assertSame( array( 'WooCommerce' => '2meet-data-optimizer-woocommerce-addon' ), TMDO_Compatibility::missing_integration_addons() );
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_hub_and_spoke_need_no_addon(): void {
eval( 'final class TMHC_Plugin {}' );
eval( 'final class TMSO_Plugin {}' );
$this->assertSame( array(), TMDO_Compatibility::missing_integration_addons() );
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_notice_is_for_administrators_only(): void {
eval( 'class WooCommerce {}' );
$GLOBALS['_wp_current_user_can'] = array();
ob_start();
TMDO_Missing_Addons_Notice::render();
$this->assertSame( '', ob_get_clean() );
}
}