feat(2meet-data-optimizer): warn when HivePress / WooCommerce run without their AddOn
- TMDO_Compatibility::missing_integration_addons() reports active HivePress / WooCommerce whose AddOn bootstrap class is absent - Surface it as Site Health test wpdo_missing_integration_addons (also on the admin Doctor tab) and an administrator notice (TMDO_Missing_Addons_Notice) - Verify: MissingIntegrationAddonsTest (5, class stand-ins in separate processes); core unit 651 / integration 449, HP 148, WC 10 OK; read-only check: dev20/21 HivePress+WooCommerce, dev22 HivePress, others clean - PR: PR-035
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<?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_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() );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user