chore: initial snapshot of 2meet-data-optimizer v0.1.0
Baseline before backporting wp-data-optimizer v3.0.1-v3.4.6. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Unit test: WPDO_Capability (v2.14.0).
|
||||
*
|
||||
* Verifies the multisite-aware admin capability gate:
|
||||
* - Single-site: only `manage_options` decides
|
||||
* - Multisite per-site: only `manage_options` decides
|
||||
* - Multisite network: super admin always passes; site admin still passes
|
||||
* on their own site if they hold `manage_options`
|
||||
*/
|
||||
class CapabilityTest extends TestCase {
|
||||
|
||||
protected function setUp(): void {
|
||||
// Reset all multisite globals before each test.
|
||||
unset(
|
||||
$GLOBALS['_wp_is_multisite'],
|
||||
$GLOBALS['_wp_is_super_admin'],
|
||||
$GLOBALS['_wp_current_user_can']
|
||||
);
|
||||
}
|
||||
|
||||
// ── Single-site behaviour ────────────────────────────────────────────────
|
||||
|
||||
public function test_single_site_admin_passes(): void {
|
||||
$GLOBALS['_wp_is_multisite'] = false;
|
||||
$GLOBALS['_wp_current_user_can'] = array( 'manage_options' => true );
|
||||
|
||||
$this->assertTrue( WPDO_Capability::current_user_can_admin() );
|
||||
}
|
||||
|
||||
public function test_single_site_subscriber_blocked(): void {
|
||||
$GLOBALS['_wp_is_multisite'] = false;
|
||||
$GLOBALS['_wp_current_user_can'] = array( 'manage_options' => false );
|
||||
|
||||
$this->assertFalse( WPDO_Capability::current_user_can_admin() );
|
||||
}
|
||||
|
||||
// ── Multisite per-site behaviour ─────────────────────────────────────────
|
||||
|
||||
public function test_multisite_site_admin_passes_with_manage_options(): void {
|
||||
$GLOBALS['_wp_is_multisite'] = true;
|
||||
$GLOBALS['_wp_is_super_admin'] = false;
|
||||
$GLOBALS['_wp_current_user_can'] = array( 'manage_options' => true );
|
||||
|
||||
$this->assertTrue( WPDO_Capability::current_user_can_admin() );
|
||||
}
|
||||
|
||||
public function test_multisite_subscriber_blocked(): void {
|
||||
$GLOBALS['_wp_is_multisite'] = true;
|
||||
$GLOBALS['_wp_is_super_admin'] = false;
|
||||
$GLOBALS['_wp_current_user_can'] = array( 'manage_options' => false );
|
||||
|
||||
$this->assertFalse( WPDO_Capability::current_user_can_admin() );
|
||||
}
|
||||
|
||||
// ── Multisite super-admin behaviour ──────────────────────────────────────
|
||||
|
||||
public function test_multisite_super_admin_passes_without_manage_options(): void {
|
||||
// Pre-v2.14.0 this returned false because super admins don't auto-have
|
||||
// `manage_options` in network admin context. v2.14.0 fixes this.
|
||||
$GLOBALS['_wp_is_multisite'] = true;
|
||||
$GLOBALS['_wp_is_super_admin'] = true;
|
||||
$GLOBALS['_wp_current_user_can'] = array( 'manage_options' => false );
|
||||
|
||||
$this->assertTrue( WPDO_Capability::current_user_can_admin() );
|
||||
}
|
||||
|
||||
public function test_multisite_super_admin_passes_with_manage_options(): void {
|
||||
$GLOBALS['_wp_is_multisite'] = true;
|
||||
$GLOBALS['_wp_is_super_admin'] = true;
|
||||
$GLOBALS['_wp_current_user_can'] = array( 'manage_options' => true );
|
||||
|
||||
$this->assertTrue( WPDO_Capability::current_user_can_admin() );
|
||||
}
|
||||
|
||||
// ── Edge: super admin flag set on single-site (shouldn't be possible
|
||||
// but should be defensive) ────────────────────────────────────────
|
||||
|
||||
public function test_super_admin_flag_ignored_on_single_site(): void {
|
||||
// Super admin only exists on multisite; on single-site fall back to
|
||||
// manage_options check.
|
||||
$GLOBALS['_wp_is_multisite'] = false;
|
||||
$GLOBALS['_wp_is_super_admin'] = true;
|
||||
$GLOBALS['_wp_current_user_can'] = array( 'manage_options' => false );
|
||||
|
||||
$this->assertFalse( WPDO_Capability::current_user_can_admin() );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user