From 4db0551895bc87782e6339a020b5f4b51882e5de Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Wed, 2 Dec 2026 13:27:55 -0500 Subject: [PATCH 1/2] Recognize the upstream VarDumper fix in 3.8.1. --- include/install.php | 29 ++++++---- tests/Unit/InstallAssetsTest.php | 96 ++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 11 deletions(-) create mode 100644 tests/Unit/InstallAssetsTest.php diff --git a/include/install.php b/include/install.php index 6efb203..9f51246 100644 --- a/include/install.php +++ b/include/install.php @@ -409,6 +409,7 @@ function _debugbar_patch_vendor_assets(string $destDir): bool [ " if (v._vd) return (v._vd[2] || '') + ' {…}';", " if (v._vd) return this.esc(v._vd[2] || '') + ' {…}';", + " if (vd) return (typeof vd[2] === 'string' ? this.esc(vd[2]) : '') + ' {…}';", ], ], 'widgets/mails/widget.js' => [ @@ -423,7 +424,10 @@ function _debugbar_patch_vendor_assets(string $destDir): bool ], 'widgets/http/widget.js' => [ [ - ' PhpDebugBar.Widgets.renderValueInto(valueTd, request.details[key]);', + [ + ' PhpDebugBar.Widgets.renderValueInto(valueTd, request.details[key]);', + ' PhpDebugBar.Widgets.renderValueInto(valueTd, request.details[key], false, request.details_html);', + ], ' PhpDebugBar.Widgets.renderSafeValueInto(valueTd, request.details[key]);', ], ], @@ -433,7 +437,10 @@ function _debugbar_patch_vendor_assets(string $destDir): bool " name.textContent = String(tpl.name ?? tpl.html ?? '');", ], [ - ' PhpDebugBar.Widgets.renderValueInto(valueTd, tpl.params[key]);', + [ + ' PhpDebugBar.Widgets.renderValueInto(valueTd, tpl.params[key]);', + ' PhpDebugBar.Widgets.renderValueInto(valueTd, tpl.params[key], false, tpl.params_html);', + ], ' PhpDebugBar.Widgets.renderSafeValueInto(valueTd, tpl.params[key]);', ], ], @@ -458,15 +465,15 @@ function _debugbar_patch_vendor_assets(string $destDir): bool } $patched = $contents; - foreach ($replacements as [$search, $replacement]) { - if (str_contains($patched, $search)) { - $patched = str_replace($search, $replacement, $patched); - - continue; - } - - // Keep direct calls idempotent while still detecting vendor drift. - if (str_contains($patched, $replacement)) { + foreach ($replacements as $patch) { + [$search, $replacement] = $patch; + $patched = str_replace($search, $replacement, $patched, $matches); + + // Recognize our replacement and the upstream VarDumper fix in 3.8.1. + $upstreamReplacement = $patch[2] ?? null; + if ($matches > 0 || str_contains($patched, $replacement) + || ($upstreamReplacement !== null && str_contains($patched, $upstreamReplacement)) + ) { continue; } diff --git a/tests/Unit/InstallAssetsTest.php b/tests/Unit/InstallAssetsTest.php new file mode 100644 index 0000000..ab4e108 --- /dev/null +++ b/tests/Unit/InstallAssetsTest.php @@ -0,0 +1,96 @@ + */ + public static function vendorLayouts(): iterable + { + yield '3.8.0' => [false]; + yield '3.8.1 (XOOPS 2.7.5 Beta 2)' => [true]; + } + + #[DataProvider('vendorLayouts')] + #[RunInSeparateProcess] + #[PreserveGlobalState(false)] + public function testPatchesVendorAssets(bool $hasUpstreamFix): void + { + $root = dirname(__DIR__, 2); + $assets = sys_get_temp_dir() . '/debugbar-assets-' . bin2hex(random_bytes(8)); + if (! defined('XOOPS_ROOT_PATH')) { + define('XOOPS_ROOT_PATH', $root); + } + require_once $root . '/include/install.php'; + + self::assertTrue(mkdir($assets)); + + try { + $vendor = $root . '/vendor/php-debugbar/php-debugbar/resources'; + foreach (['openhandler.js', 'highlight.css', 'vardumper.css', 'widgets/mails/widget.js'] as $file) { + $dir = dirname($assets . '/' . $file); + if (! is_dir($dir)) { + self::assertTrue(mkdir($dir, 0755, true)); + } + self::assertTrue(copy($vendor . '/' . $file, $assets . '/' . $file)); + } + + $preview = $hasUpstreamFix + ? " if (vd) return (typeof vd[2] === 'string' ? this.esc(vd[2]) : '') + ' {…}';" + : " if (v._vd) return (v._vd[2] || '') + ' {…}';"; + file_put_contents($assets . '/vardumper.js', $preview); + $templateTitle = " if (tpl.html) {\n name.innerHTML = tpl.html;\n" + . " } else {\n name.textContent = tpl.name;\n }\n"; + foreach ([ + 'http' => ['request.details[key]', 'request.details_html', ''], + 'templates' => ['tpl.params[key]', 'tpl.params_html', $templateTitle], + ] as $widget => [$value, $htmlFlag, $source]) { + self::assertTrue(mkdir($assets . '/widgets/' . $widget)); + $args = $hasUpstreamFix ? ", false, $htmlFlag" : ''; + file_put_contents( + $assets . '/widgets/' . $widget . '/widget.js', + $source . " PhpDebugBar.Widgets.renderValueInto(valueTd, $value$args);" + ); + } + + self::assertTrue(_debugbar_patch_vendor_assets($assets)); + self::assertTrue(_debugbar_patch_vendor_assets($assets)); + self::assertStringEqualsFile( + $assets . '/vardumper.js', + $hasUpstreamFix ? $preview : " if (v._vd) return this.esc(v._vd[2] || '') + ' {…}';" + ); + self::assertStringEqualsFile( + $assets . '/widgets/http/widget.js', + ' PhpDebugBar.Widgets.renderSafeValueInto(valueTd, request.details[key]);' + ); + self::assertStringEqualsFile( + $assets . '/widgets/templates/widget.js', + " name.textContent = String(tpl.name ?? tpl.html ?? '');\n" + . ' PhpDebugBar.Widgets.renderSafeValueInto(valueTd, tpl.params[key]);' + ); + } finally { + $entries = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($assets, FilesystemIterator::SKIP_DOTS), + RecursiveIteratorIterator::CHILD_FIRST + ); + foreach ($entries as $entry) { + if ($entry->isDir()) { + rmdir($entry->getPathname()); + } else { + unlink($entry->getPathname()); + } + } + rmdir($assets); + } + } +} From b31f9acdf379413e3c8ba2cd8a466f1b0275b521 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Wed, 2 Dec 2026 13:38:28 -0500 Subject: [PATCH 2/2] allow PHPUnit ^11.0 || ^13.4. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f6d7852..6930ae5 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "phpstan/phpstan": "^2.0", "phpstan/phpstan-deprecation-rules": "^2.0", "phpstan/phpstan-strict-rules": "^2.0", - "phpunit/phpunit": "^13.4.6", + "phpunit/phpunit": "^11.0 || ^13.4.6", "rector/rector": "^2.0", "xoops/rector-xoops": "^1.0@alpha" },