Files
2meet-data-optimizer/tests/unit/MissingIntegrationAddonsTest.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

116 lines
3.9 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_or_spoke_without_the_sso_addon_is_reported(): void {
eval( 'final class TMSO_Plugin {}' );
$this->assertSame( array( '2meet Hub / Spoke SSO' => '2meet-data-optimizer-sso-addon' ), TMDO_Compatibility::missing_integration_addons() );
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_hub_with_the_sso_addon_is_fine(): void {
eval( 'final class TMHC_Plugin {}' );
eval( 'final class TMDO_SSO_Integration {}' );
$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() );
}
}