Skip to content

Commit 65f76dc

Browse files
committed
test(integration): cover bootstrap public plugin path recovery
Verified WordPress plugin path behavior against local core 7.0-beta5 in wp-includes/plugin.php and wp-admin/includes/plugin.php.
1 parent fd6c3b3 commit 65f76dc

4 files changed

Lines changed: 81 additions & 12 deletions

File tree

docs/current-metrics.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ Verification environment: local repo checkout at `/Users/danknauss/Documents/Git
1111
|---|---:|---|
1212
| Unit tests | 503 tests | `composer test:unit` |
1313
| Unit assertions | 1307 assertions | `composer test:unit` |
14-
| Integration tests in suite | 132 test methods | `rg -c "function test" tests/Integration/*.php | awk -F: '{sum+=$2} END{print sum}'` |
14+
| Integration tests in suite | 134 test methods | `rg -c "function test" tests/Integration/*.php | awk -F: '{sum+=$2} END{print sum}'` |
1515
| Unit test files | 19 | `ls tests/Unit/*.php | wc -l` |
16-
| Integration test files | 18 | `ls tests/Integration/*.php | wc -l` |
16+
| Integration test files | 19 | `ls tests/Integration/*.php | wc -l` |
1717

1818
## Size Metrics
1919

2020
| Metric | Value | Verification |
2121
|---|---:|---|
22-
| Production PHP lines (`includes/`, `wp-sudo.php`, `uninstall.php`, `mu-plugin/`, `bridges/`) | 8,809 | `find ./includes ./wp-sudo.php ./uninstall.php ./mu-plugin ./bridges -type f -name "*.php" -print0 | xargs -0 wc -l | tail -1` |
23-
| Tests PHP lines (`tests/`) | 16,392 | `find ./tests -type f -name "*.php" -print0 | xargs -0 wc -l | tail -1` |
24-
| Production + tests PHP lines | 25,201 | sum of the two rows above |
25-
| Test-to-production ratio | 1.86:1 | `16392 / 8809` |
26-
| Total repo PHP lines (excluding `vendor/`, `vendor_test/`, `.tmp/`, `.git/`) | 25,258 | `find . -type f -name "*.php" ! -path "*/vendor/*" ! -path "*/vendor_test/*" ! -path "*/.tmp/*" ! -path "*/.git/*" -print0 | xargs -0 wc -l | tail -1` |
22+
| Production PHP lines (`includes/`, `wp-sudo.php`, `uninstall.php`, `mu-plugin/`, `bridges/`) | 8,812 | `find ./includes ./wp-sudo.php ./uninstall.php ./mu-plugin ./bridges -type f -name "*.php" -print0 | xargs -0 wc -l | tail -1` |
23+
| Tests PHP lines (`tests/`) | 16,458 | `find ./tests -type f -name "*.php" -print0 | xargs -0 wc -l | tail -1` |
24+
| Production + tests PHP lines | 25,270 | sum of the two rows above |
25+
| Test-to-production ratio | 1.87:1 | `16458 / 8812` |
26+
| Total repo PHP lines (excluding `vendor/`, `vendor_test/`, `.tmp/`, `.git/`) | 25,327 | `find . -type f -name "*.php" ! -path "*/vendor/*" ! -path "*/vendor_test/*" ! -path "*/.tmp/*" ! -path "*/.git/*" -print0 | xargs -0 wc -l | tail -1` |
2727

2828
## Architectural Facts
2929

@@ -67,8 +67,8 @@ Source: `.github/workflows/phpunit.yml`
6767
## Verification Notes
6868

6969
- `composer test:unit` passed on 2026-03-15 (`503 tests`, `1307 assertions`).
70-
- `composer test:integration` passed on 2026-03-15 (`137 tests`, `430 assertions`, `8 skipped`) after resetting the local test database (`wordpress_test`) during setup.
71-
- `WP_MULTISITE=1 composer test:integration` passed on 2026-03-15 (`137 tests`, `438 assertions`, `2 skipped`).
70+
- `composer test:integration` passed on 2026-03-15 (`139 tests`, `432 assertions`, `8 skipped`) after resetting the local test database (`wordpress_test`) during setup.
71+
- `WP_MULTISITE=1 composer test:integration` passed on 2026-03-15 (`139 tests`, `440 assertions`, `2 skipped`).
7272
- `composer analyse:phpstan`, `composer analyse:psalm`, and `composer lint` passed on 2026-03-15.
7373

7474
## Update Procedure

includes/class-bootstrap.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public static function plugin_basename( string $plugin_file ): string {
5252
* @return string
5353
*/
5454
public static function plugin_dir_url( string $plugin_file ): string {
55-
return trailingslashit( plugins_url( '', self::public_plugin_file( $plugin_file ) ) );
55+
$plugin_dirname = dirname( self::plugin_basename( $plugin_file ) );
56+
$plugin_path = '.' === $plugin_dirname ? 'plugins' : 'plugins/' . trim( $plugin_dirname, '/' );
57+
58+
return trailingslashit( content_url( $plugin_path ) );
5659
}
5760

5861
/**
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Integration tests for bootstrap helpers.
4+
*
5+
* @package WP_Sudo\Tests\Integration
6+
*/
7+
8+
namespace WP_Sudo\Tests\Integration;
9+
10+
use WP_Sudo\Bootstrap;
11+
12+
/**
13+
* @covers \WP_Sudo\Bootstrap
14+
*/
15+
class BootstrapTest extends TestCase {
16+
17+
public function test_plugin_basename_uses_active_plugin_entry_as_public_path(): void {
18+
$public_basename = is_multisite()
19+
? 'network-public-dir/wp-sudo.php'
20+
: 'custom-public-dir/wp-sudo.php';
21+
22+
$this->arrange_public_plugin_basename( $public_basename );
23+
24+
$this->assertSame(
25+
$public_basename,
26+
Bootstrap::plugin_basename( '/tmp/symlinked-target/wp-sudo.php' )
27+
);
28+
}
29+
30+
public function test_plugin_dir_url_uses_recovered_public_plugin_path(): void {
31+
$public_basename = is_multisite()
32+
? 'network-public-dir/wp-sudo.php'
33+
: 'custom-public-dir/wp-sudo.php';
34+
35+
$this->arrange_public_plugin_basename( $public_basename );
36+
37+
$expected_url = content_url( 'plugins/' . dirname( $public_basename ) ) . '/';
38+
39+
$this->assertSame(
40+
$expected_url,
41+
Bootstrap::plugin_dir_url( '/tmp/symlinked-target/wp-sudo.php' )
42+
);
43+
}
44+
45+
/**
46+
* Arrange a synthetic public plugin basename in the same storage WordPress uses.
47+
*
48+
* @param string $public_basename Relative plugin basename as stored by WordPress.
49+
* @return void
50+
*/
51+
private function arrange_public_plugin_basename( string $public_basename ): void {
52+
update_option( 'active_plugins', array() );
53+
54+
if ( is_multisite() ) {
55+
update_site_option(
56+
'active_sitewide_plugins',
57+
array(
58+
$public_basename => time(),
59+
)
60+
);
61+
return;
62+
}
63+
64+
update_option( 'active_plugins', array( $public_basename ) );
65+
}
66+
}

tests/Unit/BootstrapTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public function test_plugin_dir_url_uses_public_plugin_basename(): void {
5353
$plugin_file = '/Users/danknauss/Documents/GitHub/wp-sudo/wp-sudo.php';
5454

5555
Functions\when( 'get_option' )->justReturn( array( 'custom-public-dir/wp-sudo.php' ) );
56-
Functions\expect( 'plugins_url' )
56+
Functions\expect( 'content_url' )
5757
->once()
58-
->with( '', '/tmp/fake-wordpress/wp-content/plugins/custom-public-dir/wp-sudo.php' )
58+
->with( 'plugins/custom-public-dir' )
5959
->andReturn( 'https://example.com/wp-content/plugins/custom-public-dir' );
6060

6161
$this->assertSame(

0 commit comments

Comments
 (0)