test: 建立 phpunit 測試基建並移植 25 個 HivePress 測試
AddOn 先前 tests=0。新增: - composer.json(dev 依賴 + phpunit/phpcs script) - phpunit.xml(failOnWarning=true) - tests/bootstrap.php:直接 require 核心 plugin 的 unit bootstrap,避免複製 ~700 行 WP stub,再載入本 AddOn 的類別;補 trait wrapper 與自動 WPDO_ alias (includes/back-compat-aliases.php 掛在 plugins_loaded:7,PHPUnit 下不會跑) - tests/unit/ 25 個測試 + WpdbMockTrait(自 A 移植) 生產碼一併修對外契約:interface-tmdo-hp-adapter.php 改為先宣告空的 WPDO_HivePress_Adapter、再讓 TMDO_HivePress_Adapter extends 它(PHP 無法 class_alias 介面,只有繼承能讓 instanceof WPDO_HivePress_Adapter 對 implements TMDO_ 名稱的 adapter 成立)。與核心 interface-entity-adapter.php 同一模式。這也讓第三方自訂 adapter 用舊介面名仍可通過核心檢查。 145 tests / 357 assertions GREEN Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
This commit is contained in:
@@ -14,3 +14,5 @@ Thumbs.db
|
|||||||
.playwright-mcp/
|
.playwright-mcp/
|
||||||
.claude/
|
.claude/
|
||||||
dist/
|
dist/
|
||||||
|
.phpunit.cache
|
||||||
|
.phpunit.result.cache
|
||||||
|
|||||||
+10
-4
@@ -1,18 +1,24 @@
|
|||||||
{
|
{
|
||||||
"name": "2meet/2meet-data-optimizer-hivepress-addon",
|
"name": "2meet/2meet-data-optimizer-hivepress-addon",
|
||||||
"description": "HivePress + 12 擴充整合:13 adapter + 7 interceptor + 5 query interceptor + bootstrap + admin + CLI",
|
"description": "HivePress integration layer for 2meet Data Optimizer",
|
||||||
"type": "wordpress-plugin",
|
"type": "wordpress-plugin",
|
||||||
"license": "GPL-2.0-or-later",
|
"license": "GPL-2.0-or-later",
|
||||||
"keywords": ["wordpress", "2meet-data-optimizer", "addon", "hivepress"],
|
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.1"
|
"php": ">=8.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"brain/monkey": "^2.6",
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "^1.2",
|
||||||
|
"phpcompatibility/phpcompatibility-wp": "^2.1",
|
||||||
|
"phpcsstandards/phpcsutils": "^1.2",
|
||||||
"phpunit/phpunit": "^10.5",
|
"phpunit/phpunit": "^10.5",
|
||||||
"wp-coding-standards/wpcs": "^3.0"
|
"squizlabs/php_codesniffer": "^3.13",
|
||||||
|
"wp-coding-standards/wpcs": "^3.0",
|
||||||
|
"yoast/phpunit-polyfills": "^2.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"phpcs": "phpcs --standard=WordPress includes/ 2meet-data-optimizer-hivepress-addon.php"
|
"test": "phpunit --configuration phpunit.xml",
|
||||||
|
"phpcs": "phpcs --standard=WordPress includes/ admin/ cli/"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"allow-plugins": {
|
"allow-plugins": {
|
||||||
|
|||||||
Generated
+565
-54
@@ -4,9 +4,127 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "2cfda1cbb3d53af75fbe9ac5baa798a1",
|
"content-hash": "1ff95ada2eeef20075975e47baf9396f",
|
||||||
"packages": [],
|
"packages": [],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
|
{
|
||||||
|
"name": "antecedent/patchwork",
|
||||||
|
"version": "2.2.3",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/antecedent/patchwork.git",
|
||||||
|
"reference": "8b6b235f405af175259c8f56aea5fc23ab9f03ce"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/antecedent/patchwork/zipball/8b6b235f405af175259c8f56aea5fc23ab9f03ce",
|
||||||
|
"reference": "8b6b235f405af175259c8f56aea5fc23ab9f03ce",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.1.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": ">=4"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Ignas Rudaitis",
|
||||||
|
"email": "ignas.rudaitis@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Method redefinition (monkey-patching) functionality for PHP.",
|
||||||
|
"homepage": "https://antecedent.github.io/patchwork/",
|
||||||
|
"keywords": [
|
||||||
|
"aop",
|
||||||
|
"aspect",
|
||||||
|
"interception",
|
||||||
|
"monkeypatching",
|
||||||
|
"redefinition",
|
||||||
|
"runkit",
|
||||||
|
"testing"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/antecedent/patchwork/issues",
|
||||||
|
"source": "https://github.com/antecedent/patchwork/tree/2.2.3"
|
||||||
|
},
|
||||||
|
"time": "2025-09-17T09:00:56+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "brain/monkey",
|
||||||
|
"version": "2.7.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/Brain-WP/BrainMonkey.git",
|
||||||
|
"reference": "ea3aeb3d559ba3c0930b3f4d210b665a4c044d83"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/Brain-WP/BrainMonkey/zipball/ea3aeb3d559ba3c0930b3f4d210b665a4c044d83",
|
||||||
|
"reference": "ea3aeb3d559ba3c0930b3f4d210b665a4c044d83",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"antecedent/patchwork": "^2.1.17",
|
||||||
|
"mockery/mockery": "~1.3.6 || ~1.4.4 || ~1.5.1 || ^1.6.10",
|
||||||
|
"php": ">=5.6.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
|
||||||
|
"phpcompatibility/php-compatibility": "^9.3.0",
|
||||||
|
"phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.49 || ^9.6.30"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "2.x-dev",
|
||||||
|
"dev-version/1": "1.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"inc/api.php"
|
||||||
|
],
|
||||||
|
"psr-4": {
|
||||||
|
"Brain\\Monkey\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Giuseppe Mazzapica",
|
||||||
|
"email": "giuseppe.mazzapica@gmail.com",
|
||||||
|
"homepage": "https://gmazzap.me",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Mocking utility for PHP functions and WordPress plugin API",
|
||||||
|
"keywords": [
|
||||||
|
"Monkey Patching",
|
||||||
|
"interception",
|
||||||
|
"mock",
|
||||||
|
"mock functions",
|
||||||
|
"mockery",
|
||||||
|
"patchwork",
|
||||||
|
"redefinition",
|
||||||
|
"runkit",
|
||||||
|
"test",
|
||||||
|
"testing"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/Brain-WP/BrainMonkey/issues",
|
||||||
|
"source": "https://github.com/Brain-WP/BrainMonkey"
|
||||||
|
},
|
||||||
|
"time": "2026-02-05T09:22:14+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "dealerdirect/phpcodesniffer-composer-installer",
|
"name": "dealerdirect/phpcodesniffer-composer-installer",
|
||||||
"version": "v1.2.1",
|
"version": "v1.2.1",
|
||||||
@@ -103,6 +221,140 @@
|
|||||||
],
|
],
|
||||||
"time": "2026-05-06T08:26:05+00:00"
|
"time": "2026-05-06T08:26:05+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "hamcrest/hamcrest-php",
|
||||||
|
"version": "v2.1.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/hamcrest/hamcrest-php.git",
|
||||||
|
"reference": "f8b1c0173b22fa6ec77a81fe63e5b01eba7e6487"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/f8b1c0173b22fa6ec77a81fe63e5b01eba7e6487",
|
||||||
|
"reference": "f8b1c0173b22fa6ec77a81fe63e5b01eba7e6487",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^7.4|^8.0"
|
||||||
|
},
|
||||||
|
"replace": {
|
||||||
|
"cordoval/hamcrest-php": "*",
|
||||||
|
"davedevelopment/hamcrest-php": "*",
|
||||||
|
"kodova/hamcrest-php": "*"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/php-file-iterator": "^1.4 || ^2.0 || ^3.0",
|
||||||
|
"phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0 || ^8.0 || ^9.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "2.1-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"classmap": [
|
||||||
|
"hamcrest"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"BSD-3-Clause"
|
||||||
|
],
|
||||||
|
"description": "This is the PHP port of Hamcrest Matchers",
|
||||||
|
"keywords": [
|
||||||
|
"test"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/hamcrest/hamcrest-php/issues",
|
||||||
|
"source": "https://github.com/hamcrest/hamcrest-php/tree/v2.1.1"
|
||||||
|
},
|
||||||
|
"time": "2025-04-30T06:54:44+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "mockery/mockery",
|
||||||
|
"version": "1.6.12",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/mockery/mockery.git",
|
||||||
|
"reference": "1f4efdd7d3beafe9807b08156dfcb176d18f1699"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/mockery/mockery/zipball/1f4efdd7d3beafe9807b08156dfcb176d18f1699",
|
||||||
|
"reference": "1f4efdd7d3beafe9807b08156dfcb176d18f1699",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"hamcrest/hamcrest-php": "^2.0.1",
|
||||||
|
"lib-pcre": ">=7.0",
|
||||||
|
"php": ">=7.3"
|
||||||
|
},
|
||||||
|
"conflict": {
|
||||||
|
"phpunit/phpunit": "<8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^8.5 || ^9.6.17",
|
||||||
|
"symplify/easy-coding-standard": "^12.1.14"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"library/helpers.php",
|
||||||
|
"library/Mockery.php"
|
||||||
|
],
|
||||||
|
"psr-4": {
|
||||||
|
"Mockery\\": "library/Mockery"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"BSD-3-Clause"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Pádraic Brady",
|
||||||
|
"email": "padraic.brady@gmail.com",
|
||||||
|
"homepage": "https://github.com/padraic",
|
||||||
|
"role": "Author"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Dave Marshall",
|
||||||
|
"email": "dave.marshall@atstsolutions.co.uk",
|
||||||
|
"homepage": "https://davedevelopment.co.uk",
|
||||||
|
"role": "Developer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Nathanael Esayeas",
|
||||||
|
"email": "nathanael.esayeas@protonmail.com",
|
||||||
|
"homepage": "https://github.com/ghostwriter",
|
||||||
|
"role": "Lead Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Mockery is a simple yet flexible PHP mock object framework",
|
||||||
|
"homepage": "https://github.com/mockery/mockery",
|
||||||
|
"keywords": [
|
||||||
|
"BDD",
|
||||||
|
"TDD",
|
||||||
|
"library",
|
||||||
|
"mock",
|
||||||
|
"mock objects",
|
||||||
|
"mockery",
|
||||||
|
"stub",
|
||||||
|
"test",
|
||||||
|
"test double",
|
||||||
|
"testing"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"docs": "https://docs.mockery.io/",
|
||||||
|
"issues": "https://github.com/mockery/mockery/issues",
|
||||||
|
"rss": "https://github.com/mockery/mockery/releases.atom",
|
||||||
|
"security": "https://github.com/mockery/mockery/security/advisories",
|
||||||
|
"source": "https://github.com/mockery/mockery"
|
||||||
|
},
|
||||||
|
"time": "2024-05-16T03:13:13+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "myclabs/deep-copy",
|
"name": "myclabs/deep-copy",
|
||||||
"version": "1.13.4",
|
"version": "1.13.4",
|
||||||
@@ -165,20 +417,19 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "nikic/php-parser",
|
"name": "nikic/php-parser",
|
||||||
"version": "v5.7.0",
|
"version": "v5.8.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/nikic/PHP-Parser.git",
|
"url": "https://github.com/nikic/PHP-Parser.git",
|
||||||
"reference": "dca41cd15c2ac9d055ad70dbfd011130757d1f82"
|
"reference": "044a6a392ff8ad0d61f14370a5fbbd0a0107152f"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/dca41cd15c2ac9d055ad70dbfd011130757d1f82",
|
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/044a6a392ff8ad0d61f14370a5fbbd0a0107152f",
|
||||||
"reference": "dca41cd15c2ac9d055ad70dbfd011130757d1f82",
|
"reference": "044a6a392ff8ad0d61f14370a5fbbd0a0107152f",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"ext-ctype": "*",
|
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"ext-tokenizer": "*",
|
"ext-tokenizer": "*",
|
||||||
"php": ">=7.4"
|
"php": ">=7.4"
|
||||||
@@ -217,9 +468,9 @@
|
|||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/nikic/PHP-Parser/issues",
|
"issues": "https://github.com/nikic/PHP-Parser/issues",
|
||||||
"source": "https://github.com/nikic/PHP-Parser/tree/v5.7.0"
|
"source": "https://github.com/nikic/PHP-Parser/tree/v5.8.0"
|
||||||
},
|
},
|
||||||
"time": "2025-12-06T11:56:16+00:00"
|
"time": "2026-07-04T14:30:18+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phar-io/manifest",
|
"name": "phar-io/manifest",
|
||||||
@@ -340,22 +591,235 @@
|
|||||||
"time": "2022-02-21T01:04:05+00:00"
|
"time": "2022-02-21T01:04:05+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpcsstandards/phpcsextra",
|
"name": "phpcompatibility/php-compatibility",
|
||||||
"version": "1.5.0",
|
"version": "9.3.5",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/PHPCSStandards/PHPCSExtra.git",
|
"url": "https://github.com/PHPCompatibility/PHPCompatibility.git",
|
||||||
"reference": "b598aa890815b8df16363271b659d73280129101"
|
"reference": "9fb324479acf6f39452e0655d2429cc0d3914243"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/b598aa890815b8df16363271b659d73280129101",
|
"url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243",
|
||||||
"reference": "b598aa890815b8df16363271b659d73280129101",
|
"reference": "9fb324479acf6f39452e0655d2429cc0d3914243",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3",
|
||||||
|
"squizlabs/php_codesniffer": "^2.3 || ^3.0.2"
|
||||||
|
},
|
||||||
|
"conflict": {
|
||||||
|
"squizlabs/php_codesniffer": "2.6.2"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.",
|
||||||
|
"roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues."
|
||||||
|
},
|
||||||
|
"type": "phpcodesniffer-standard",
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"LGPL-3.0-or-later"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Wim Godden",
|
||||||
|
"homepage": "https://github.com/wimg",
|
||||||
|
"role": "lead"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Juliette Reinders Folmer",
|
||||||
|
"homepage": "https://github.com/jrfnl",
|
||||||
|
"role": "lead"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Contributors",
|
||||||
|
"homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.",
|
||||||
|
"homepage": "http://techblog.wimgodden.be/tag/codesniffer/",
|
||||||
|
"keywords": [
|
||||||
|
"compatibility",
|
||||||
|
"phpcs",
|
||||||
|
"standards"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues",
|
||||||
|
"source": "https://github.com/PHPCompatibility/PHPCompatibility"
|
||||||
|
},
|
||||||
|
"time": "2019-12-27T09:44:58+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "phpcompatibility/phpcompatibility-paragonie",
|
||||||
|
"version": "1.3.4",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git",
|
||||||
|
"reference": "244d7b04fc4bc2117c15f5abe23eb933b5f02bbf"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/244d7b04fc4bc2117c15f5abe23eb933b5f02bbf",
|
||||||
|
"reference": "244d7b04fc4bc2117c15f5abe23eb933b5f02bbf",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"phpcompatibility/php-compatibility": "^9.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
|
||||||
|
"paragonie/random_compat": "dev-master",
|
||||||
|
"paragonie/sodium_compat": "dev-master"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "^1.0 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.",
|
||||||
|
"roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues."
|
||||||
|
},
|
||||||
|
"type": "phpcodesniffer-standard",
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"LGPL-3.0-or-later"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Wim Godden",
|
||||||
|
"role": "lead"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Juliette Reinders Folmer",
|
||||||
|
"role": "lead"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.",
|
||||||
|
"homepage": "http://phpcompatibility.com/",
|
||||||
|
"keywords": [
|
||||||
|
"compatibility",
|
||||||
|
"paragonie",
|
||||||
|
"phpcs",
|
||||||
|
"polyfill",
|
||||||
|
"standards",
|
||||||
|
"static analysis"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues",
|
||||||
|
"security": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/security/policy",
|
||||||
|
"source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/PHPCompatibility",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/jrfnl",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://opencollective.com/php_codesniffer",
|
||||||
|
"type": "open_collective"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://thanks.dev/u/gh/phpcompatibility",
|
||||||
|
"type": "thanks_dev"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2025-09-19T17:43:28+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "phpcompatibility/phpcompatibility-wp",
|
||||||
|
"version": "2.1.8",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git",
|
||||||
|
"reference": "7c8d18b4d90dac9e86b0869a608fa09158e168fa"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/7c8d18b4d90dac9e86b0869a608fa09158e168fa",
|
||||||
|
"reference": "7c8d18b4d90dac9e86b0869a608fa09158e168fa",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"phpcompatibility/php-compatibility": "^9.0",
|
||||||
|
"phpcompatibility/phpcompatibility-paragonie": "^1.0",
|
||||||
|
"squizlabs/php_codesniffer": "^3.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "^1.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "^1.0 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.",
|
||||||
|
"roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues."
|
||||||
|
},
|
||||||
|
"type": "phpcodesniffer-standard",
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"LGPL-3.0-or-later"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Wim Godden",
|
||||||
|
"role": "lead"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Juliette Reinders Folmer",
|
||||||
|
"role": "lead"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.",
|
||||||
|
"homepage": "http://phpcompatibility.com/",
|
||||||
|
"keywords": [
|
||||||
|
"compatibility",
|
||||||
|
"phpcs",
|
||||||
|
"standards",
|
||||||
|
"static analysis",
|
||||||
|
"wordpress"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues",
|
||||||
|
"security": "https://github.com/PHPCompatibility/PHPCompatibilityWP/security/policy",
|
||||||
|
"source": "https://github.com/PHPCompatibility/PHPCompatibilityWP"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/PHPCompatibility",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/jrfnl",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://opencollective.com/php_codesniffer",
|
||||||
|
"type": "open_collective"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://thanks.dev/u/gh/phpcompatibility",
|
||||||
|
"type": "thanks_dev"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2025-10-18T00:05:59+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "phpcsstandards/phpcsextra",
|
||||||
|
"version": "1.5.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/PHPCSStandards/PHPCSExtra.git",
|
||||||
|
"reference": "39467533fdb742446d68c1d10ac33d625ee0311c"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/39467533fdb742446d68c1d10ac33d625ee0311c",
|
||||||
|
"reference": "39467533fdb742446d68c1d10ac33d625ee0311c",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.4",
|
"php": ">=5.4",
|
||||||
"phpcsstandards/phpcsutils": "^1.2.0",
|
"phpcsstandards/phpcsutils": "^1.2.3",
|
||||||
"squizlabs/php_codesniffer": "^3.13.5 || ^4.0.1"
|
"squizlabs/php_codesniffer": "^3.13.5 || ^4.0.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
@@ -419,20 +883,20 @@
|
|||||||
"type": "thanks_dev"
|
"type": "thanks_dev"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2025-11-12T23:06:57+00:00"
|
"time": "2026-07-27T11:13:17+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpcsstandards/phpcsutils",
|
"name": "phpcsstandards/phpcsutils",
|
||||||
"version": "1.2.2",
|
"version": "1.2.3",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/PHPCSStandards/PHPCSUtils.git",
|
"url": "https://github.com/PHPCSStandards/PHPCSUtils.git",
|
||||||
"reference": "c216317e96c8b3f5932808f9b0f1f7a14e3bbf55"
|
"reference": "5f35d9408c54d7b529501f3c688b6eae562aea1f"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/c216317e96c8b3f5932808f9b0f1f7a14e3bbf55",
|
"url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/5f35d9408c54d7b529501f3c688b6eae562aea1f",
|
||||||
"reference": "c216317e96c8b3f5932808f9b0f1f7a14e3bbf55",
|
"reference": "5f35d9408c54d7b529501f3c688b6eae562aea1f",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@@ -512,7 +976,7 @@
|
|||||||
"type": "thanks_dev"
|
"type": "thanks_dev"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2025-12-08T14:27:58+00:00"
|
"time": "2026-07-27T10:28:41+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/php-code-coverage",
|
"name": "phpunit/php-code-coverage",
|
||||||
@@ -837,24 +1301,24 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/phpunit",
|
"name": "phpunit/phpunit",
|
||||||
"version": "10.5.63",
|
"version": "10.5.64",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||||
"reference": "33198268dad71e926626b618f3ec3966661e4d90"
|
"reference": "0e8c1d19cea35ad97d4887f363d07c78e30fbf06"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/33198268dad71e926626b618f3ec3966661e4d90",
|
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0e8c1d19cea35ad97d4887f363d07c78e30fbf06",
|
||||||
"reference": "33198268dad71e926626b618f3ec3966661e4d90",
|
"reference": "0e8c1d19cea35ad97d4887f363d07c78e30fbf06",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"ext-dom": "*",
|
"ext-dom": "*",
|
||||||
|
"ext-filter": "*",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"ext-libxml": "*",
|
"ext-libxml": "*",
|
||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
"ext-xml": "*",
|
|
||||||
"ext-xmlwriter": "*",
|
"ext-xmlwriter": "*",
|
||||||
"myclabs/deep-copy": "^1.13.4",
|
"myclabs/deep-copy": "^1.13.4",
|
||||||
"phar-io/manifest": "^2.0.4",
|
"phar-io/manifest": "^2.0.4",
|
||||||
@@ -918,31 +1382,15 @@
|
|||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
|
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
|
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.63"
|
"source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.64"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"url": "https://phpunit.de/sponsors.html",
|
"url": "https://phpunit.de/sponsoring.html",
|
||||||
"type": "custom"
|
"type": "other"
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://github.com/sebastianbergmann",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://liberapay.com/sebastianbergmann",
|
|
||||||
"type": "liberapay"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://thanks.dev/u/gh/sebastianbergmann",
|
|
||||||
"type": "thanks_dev"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit",
|
|
||||||
"type": "tidelift"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2026-01-27T05:48:37+00:00"
|
"time": "2026-07-06T14:50:35+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/cli-parser",
|
"name": "sebastian/cli-parser",
|
||||||
@@ -2028,16 +2476,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "wp-coding-standards/wpcs",
|
"name": "wp-coding-standards/wpcs",
|
||||||
"version": "3.3.0",
|
"version": "3.4.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/WordPress/WordPress-Coding-Standards.git",
|
"url": "https://github.com/WordPress/WordPress-Coding-Standards.git",
|
||||||
"reference": "7795ec6fa05663d716a549d0b44e47ffc8b0d4a6"
|
"reference": "ec2ff942335f33683a5957a85d138753876a05cf"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/7795ec6fa05663d716a549d0b44e47ffc8b0d4a6",
|
"url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/ec2ff942335f33683a5957a85d138753876a05cf",
|
||||||
"reference": "7795ec6fa05663d716a549d0b44e47ffc8b0d4a6",
|
"reference": "ec2ff942335f33683a5957a85d138753876a05cf",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@@ -2046,9 +2494,9 @@
|
|||||||
"ext-tokenizer": "*",
|
"ext-tokenizer": "*",
|
||||||
"ext-xmlreader": "*",
|
"ext-xmlreader": "*",
|
||||||
"php": ">=7.2",
|
"php": ">=7.2",
|
||||||
"phpcsstandards/phpcsextra": "^1.5.0",
|
"phpcsstandards/phpcsextra": "^1.5.1",
|
||||||
"phpcsstandards/phpcsutils": "^1.1.0",
|
"phpcsstandards/phpcsutils": "^1.2.3",
|
||||||
"squizlabs/php_codesniffer": "^3.13.4"
|
"squizlabs/php_codesniffer": "^3.13.5"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"php-parallel-lint/php-console-highlighter": "^1.0.0",
|
"php-parallel-lint/php-console-highlighter": "^1.0.0",
|
||||||
@@ -2090,7 +2538,70 @@
|
|||||||
"type": "custom"
|
"type": "custom"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2025-11-25T12:08:04+00:00"
|
"time": "2026-07-27T11:53:23+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "yoast/phpunit-polyfills",
|
||||||
|
"version": "2.0.5",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/Yoast/PHPUnit-Polyfills.git",
|
||||||
|
"reference": "1a6aecc9ebe4a9cea4e1047d0e6c496e52314c27"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/1a6aecc9ebe4a9cea4e1047d0e6c496e52314c27",
|
||||||
|
"reference": "1a6aecc9ebe4a9cea4e1047d0e6c496e52314c27",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.6",
|
||||||
|
"phpunit/phpunit": "^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"php-parallel-lint/php-console-highlighter": "^1.0.0",
|
||||||
|
"php-parallel-lint/php-parallel-lint": "^1.4.0",
|
||||||
|
"yoast/yoastcs": "^3.2.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-main": "4.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"phpunitpolyfills-autoload.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"BSD-3-Clause"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Team Yoast",
|
||||||
|
"email": "support@yoast.com",
|
||||||
|
"homepage": "https://yoast.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Contributors",
|
||||||
|
"homepage": "https://github.com/Yoast/PHPUnit-Polyfills/graphs/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests",
|
||||||
|
"homepage": "https://github.com/Yoast/PHPUnit-Polyfills",
|
||||||
|
"keywords": [
|
||||||
|
"phpunit",
|
||||||
|
"polyfill",
|
||||||
|
"testing"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/Yoast/PHPUnit-Polyfills/issues",
|
||||||
|
"security": "https://github.com/Yoast/PHPUnit-Polyfills/security/policy",
|
||||||
|
"source": "https://github.com/Yoast/PHPUnit-Polyfills"
|
||||||
|
},
|
||||||
|
"time": "2025-08-10T05:13:49+00:00"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
|
|||||||
@@ -38,7 +38,15 @@ if ( ! interface_exists( 'TMDO_HivePress_Adapter' ) ) {
|
|||||||
* everything except `plugin_slug()` / `detection_class()` / `detection_const()`,
|
* everything except `plugin_slug()` / `detection_class()` / `detection_const()`,
|
||||||
* so concrete adapters typically override 3–6 methods.
|
* so concrete adapters typically override 3–6 methods.
|
||||||
*/
|
*/
|
||||||
interface TMDO_HivePress_Adapter {
|
// Back-compat: declare the WPDO_ marker first so TMDO_ can extend it.
|
||||||
|
// PHP class_alias() does not work on interfaces; inheritance is the only way
|
||||||
|
// to make `instanceof WPDO_HivePress_Adapter` true for adapters implementing
|
||||||
|
// the TMDO_ name. Mirrors the core's interface-entity-adapter.php.
|
||||||
|
if ( ! interface_exists( 'WPDO_HivePress_Adapter', false ) ) {
|
||||||
|
interface WPDO_HivePress_Adapter {}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TMDO_HivePress_Adapter extends WPDO_HivePress_Adapter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stable slug used as Schema_Registry / Custom_Table_Registry provider key.
|
* Stable slug used as Schema_Registry / Custom_Table_Registry provider key.
|
||||||
|
|||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
||||||
|
bootstrap="tests/bootstrap.php"
|
||||||
|
colors="true"
|
||||||
|
failOnWarning="true"
|
||||||
|
beStrictAboutOutputDuringTests="true"
|
||||||
|
cacheDirectory=".phpunit.cache">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="hivepress-addon">
|
||||||
|
<directory>tests/unit</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<source>
|
||||||
|
<include>
|
||||||
|
<directory>includes</directory>
|
||||||
|
<directory>admin</directory>
|
||||||
|
<directory>cli</directory>
|
||||||
|
</include>
|
||||||
|
</source>
|
||||||
|
</phpunit>
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHPUnit bootstrap for the HivePress AddOn.
|
||||||
|
*
|
||||||
|
* Reuses the core plugin's unit bootstrap (WP function stubs, $wpdb stub,
|
||||||
|
* constants, WPDO_* aliases) instead of duplicating ~700 lines of stubs, then
|
||||||
|
* loads this AddOn's own classes on top.
|
||||||
|
*
|
||||||
|
* The core plugin must sit next to this one under wp-content/plugins/.
|
||||||
|
*
|
||||||
|
* @package TMDO_HIVEPRESS
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
$tmdo_core_bootstrap = dirname( __DIR__, 2 ) . '/2meet-data-optimizer/tests/bootstrap.php';
|
||||||
|
if ( ! file_exists( $tmdo_core_bootstrap ) ) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
'HivePress AddOn tests require the core plugin at ' . dirname( __DIR__, 2 ) . '/2meet-data-optimizer'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
require_once $tmdo_core_bootstrap;
|
||||||
|
|
||||||
|
define( 'TMDO_HIVEPRESS_PATH', dirname( __DIR__ ) . '/' );
|
||||||
|
define( 'TMDO_HIVEPRESS_URL', 'http://localhost/wp-content/plugins/2meet-data-optimizer-hivepress-addon/' );
|
||||||
|
define( 'TMDO_HIVEPRESS_FILE', dirname( __DIR__ ) . '/2meet-data-optimizer-hivepress-addon.php' );
|
||||||
|
define( 'TMDO_HIVEPRESS_VERSION', '0.1.0' );
|
||||||
|
|
||||||
|
// ── AddOn classes ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
$tmdo_hp_files = array(
|
||||||
|
'includes/class-tmdo-hivepress.php',
|
||||||
|
'includes/hivepress/interface-tmdo-hp-adapter.php',
|
||||||
|
'includes/hivepress/trait-tmdo-hp-adapter.php',
|
||||||
|
'includes/hivepress/class-tmdo-hivepress-detector.php',
|
||||||
|
'includes/hivepress/class-tmdo-hivepress-conflict-guard.php',
|
||||||
|
'includes/hivepress/class-tmdo-hivepress-bootstrap.php',
|
||||||
|
'includes/hivepress/class-tmdo-hivepress-comment-router.php',
|
||||||
|
'includes/hivepress/class-tmdo-hivepress-cron-optimizer.php',
|
||||||
|
'includes/hivepress/class-tmdo-hivepress-attribute-bridge.php',
|
||||||
|
'includes/hivepress/class-tmdo-hivepress-suitability-scorer.php',
|
||||||
|
'includes/hivepress/class-tmdo-hivepress-benchmark.php',
|
||||||
|
'includes/hivepress/class-tmdo-hivepress-rest.php',
|
||||||
|
'includes/class-tmdo-hivepress-transient-filter.php',
|
||||||
|
'includes/class-tmdo-hivepress-term-comment-fields.php',
|
||||||
|
'includes/class-tmdo-hpct-import.php',
|
||||||
|
// class-tmdo-listing-stats.php is deliberately NOT loaded: the core unit
|
||||||
|
// bootstrap already declares a TMDO_Listing_Stats stub, and no test in this
|
||||||
|
// suite exercises the real implementation.
|
||||||
|
'admin/class-tmdo-admin-hivepress.php',
|
||||||
|
'cli/class-tmdo-cli-hivepress.php',
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ( glob( TMDO_HIVEPRESS_PATH . 'includes/hivepress/adapters/*.php' ) ?: array() as $tmdo_hp_adapter ) {
|
||||||
|
$tmdo_hp_files[] = 'includes/hivepress/adapters/' . basename( $tmdo_hp_adapter );
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $tmdo_hp_files as $tmdo_hp_file ) {
|
||||||
|
$tmdo_hp_path = TMDO_HIVEPRESS_PATH . $tmdo_hp_file;
|
||||||
|
if ( file_exists( $tmdo_hp_path ) ) {
|
||||||
|
require_once $tmdo_hp_path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset( $tmdo_hp_files, $tmdo_hp_file, $tmdo_hp_path, $tmdo_hp_adapter, $tmdo_core_bootstrap );
|
||||||
|
|
||||||
|
// ── Back-compat aliases for this AddOn's classes ───────────────────────────
|
||||||
|
// Mirrors includes/back-compat-aliases.php, which runs on plugins_loaded:7 and
|
||||||
|
// therefore never fires under PHPUnit.
|
||||||
|
foreach ( get_declared_classes() as $tmdo_declared ) {
|
||||||
|
if ( str_starts_with( $tmdo_declared, 'TMDO_' ) ) {
|
||||||
|
$tmdo_alias = 'WPDO_' . substr( $tmdo_declared, 5 );
|
||||||
|
if ( ! class_exists( $tmdo_alias, false ) ) {
|
||||||
|
class_alias( $tmdo_declared, $tmdo_alias );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset( $tmdo_declared, $tmdo_alias );
|
||||||
|
|
||||||
|
// PHP cannot class_alias() traits or interfaces — declare thin wrappers so the
|
||||||
|
// suite can keep referring to the WPDO_ names.
|
||||||
|
if ( trait_exists( 'TMDO_HivePress_Adapter_Trait' ) && ! trait_exists( 'WPDO_HivePress_Adapter_Trait', false ) ) {
|
||||||
|
trait WPDO_HivePress_Adapter_Trait {
|
||||||
|
use TMDO_HivePress_Adapter_Trait;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// WPDO_HivePress_Adapter is declared by interface-tmdo-hp-adapter.php itself
|
||||||
|
// (TMDO_ extends WPDO_), so no wrapper is needed here.
|
||||||
|
|
||||||
|
// Shared $wpdb mock helper used by the adapter tests.
|
||||||
|
if ( file_exists( __DIR__ . '/unit/WpdbMockTrait.php' ) ) {
|
||||||
|
require_once __DIR__ . '/unit/WpdbMockTrait.php';
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Adapter_Trait — score composition + helper sugar.
|
||||||
|
*
|
||||||
|
* Uses an anonymous adapter to exercise trait behaviour without requiring
|
||||||
|
* a concrete production adapter.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Adapter_Trait
|
||||||
|
*/
|
||||||
|
class HivePressAdapterTraitTest extends TestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a fresh anonymous adapter with optional score override.
|
||||||
|
*/
|
||||||
|
private function make_adapter( array $score_override = array() ): object {
|
||||||
|
return new class( $score_override ) implements WPDO_HivePress_Adapter {
|
||||||
|
use WPDO_HivePress_Adapter_Trait;
|
||||||
|
|
||||||
|
private array $override;
|
||||||
|
|
||||||
|
public function __construct( array $override ) {
|
||||||
|
$this->override = $override;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function plugin_slug(): string {
|
||||||
|
return 'test-adapter';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function detection_class(): string {
|
||||||
|
return 'Test\\Adapter';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function detection_const(): string {
|
||||||
|
return 'TEST_ADAPTER_VERSION';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function suitability_score(): array {
|
||||||
|
return $this->compose_score( $this->override );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_default_score_is_perfect_ten(): void {
|
||||||
|
$score = $this->make_adapter()->suitability_score();
|
||||||
|
$this->assertSame( 10.0, $score['aggregate'] );
|
||||||
|
foreach ( array( 'd1_meta_calls', 'd2_meta_sql', 'd3_table_coverage', 'd4_registry_meta', 'd5_hook_bus', 'd6_options', 'd7_coupling', 'd8_perf' ) as $k ) {
|
||||||
|
$this->assertSame( 1.0, $score[ $k ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_partial_override_lowers_aggregate(): void {
|
||||||
|
$score = $this->make_adapter( array( 'd5_hook_bus' => 0.5 ) )->suitability_score();
|
||||||
|
// 7 × 1.0 + 1 × 0.5 = 7.5; aggregate = 7.5 / 8 * 10 = 9.375 → rounded 9.38.
|
||||||
|
$this->assertSame( 9.38, $score['aggregate'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_score_clamped_to_unit_interval(): void {
|
||||||
|
$score = $this->make_adapter( array(
|
||||||
|
'd1_meta_calls' => 1.5, // → clamped to 1.0
|
||||||
|
'd2_meta_sql' => -0.3, // → clamped to 0.0
|
||||||
|
) )->suitability_score();
|
||||||
|
$this->assertSame( 1.0, $score['d1_meta_calls'] );
|
||||||
|
$this->assertSame( 0.0, $score['d2_meta_sql'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_default_implementations_are_no_op(): void {
|
||||||
|
$adapter = $this->make_adapter();
|
||||||
|
|
||||||
|
// All optional methods should be safe to invoke on a minimal adapter.
|
||||||
|
$this->assertSame( array(), $adapter->migrations() );
|
||||||
|
$this->assertSame( '', $adapter->minimum_addon_version() );
|
||||||
|
|
||||||
|
$result = $adapter->doctor_check();
|
||||||
|
$this->assertTrue( $result['ok'] );
|
||||||
|
|
||||||
|
// Hook handlers must not throw on a no-op adapter.
|
||||||
|
$adapter->on_register_query_hooks();
|
||||||
|
$adapter->on_register_event_hooks();
|
||||||
|
$adapter->on_register_entity_fields();
|
||||||
|
$this->assertTrue( true ); // reaching here = no exception
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_aggregate_rounding_is_two_decimals(): void {
|
||||||
|
$score = $this->make_adapter( array(
|
||||||
|
'd1_meta_calls' => 0.85,
|
||||||
|
'd2_meta_sql' => 0.92,
|
||||||
|
'd3_table_coverage' => 0.78,
|
||||||
|
) )->suitability_score();
|
||||||
|
|
||||||
|
// All other dimensions stay at 1.0 → sum = 0.85+0.92+0.78+5*1.0 = 7.55.
|
||||||
|
// aggregate = 7.55 / 8 * 10 = 9.4375 → round(2) = 9.44.
|
||||||
|
$this->assertSame( 9.44, $score['aggregate'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_Admin_HivePress.
|
||||||
|
*
|
||||||
|
* @covers WPDO_Admin_HivePress
|
||||||
|
*/
|
||||||
|
class AdminHivePressTest extends TestCase {
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
WPDO_HivePress_Bootstrap::reset_for_tests();
|
||||||
|
WPDO_HivePress_Detector::reset_for_tests();
|
||||||
|
WPDO_HivePress_Conflict_Guard::reset_for_tests();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_render_outputs_addon_catalog(): void {
|
||||||
|
$out = self::capture( static function () {
|
||||||
|
WPDO_Admin_HivePress::render();
|
||||||
|
} );
|
||||||
|
|
||||||
|
$this->assertStringContainsString( 'HivePress', $out );
|
||||||
|
$this->assertStringContainsString( 'hivepress', $out );
|
||||||
|
$this->assertStringContainsString( 'wp wpdo hivepress', $out );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_render_shows_clean_when_no_conflicts(): void {
|
||||||
|
$out = self::capture( static function () {
|
||||||
|
WPDO_Admin_HivePress::render();
|
||||||
|
} );
|
||||||
|
|
||||||
|
$this->assertStringContainsString( 'Conflict guard', $out );
|
||||||
|
$this->assertStringContainsString( 'notice-success', $out );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Capture echo output of a callable in a single buffer level.
|
||||||
|
*
|
||||||
|
* Avoids PHPUnit's "did not close output buffers" warning by using
|
||||||
|
* the level-checked open/close pattern.
|
||||||
|
*/
|
||||||
|
private static function capture( callable $callable ): string {
|
||||||
|
$start_level = ob_get_level();
|
||||||
|
ob_start();
|
||||||
|
try {
|
||||||
|
$callable();
|
||||||
|
} finally {
|
||||||
|
$out = '';
|
||||||
|
while ( ob_get_level() > $start_level ) {
|
||||||
|
$out = (string) ob_get_clean() . $out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Attribute_Bridge.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Attribute_Bridge
|
||||||
|
*/
|
||||||
|
class HivePressAttributeBridgeTest extends TestCase {
|
||||||
|
|
||||||
|
private WPDO_HivePress_Attribute_Bridge $bridge;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->bridge = new WPDO_HivePress_Attribute_Bridge();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_discover_returns_empty_when_no_attributes_registered(): void {
|
||||||
|
// apply_filters stub returns the value unchanged → empty array.
|
||||||
|
$this->assertSame( array(), $this->bridge->discover_attributes() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_suggest_zone_configs_returns_empty_when_no_attributes(): void {
|
||||||
|
$this->assertSame( array(), $this->bridge->suggest_zone_configs() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the SQL type mapping is sensible for known HivePress field types.
|
||||||
|
*
|
||||||
|
* Indirect test via reflection — the public API only returns full configs
|
||||||
|
* but we want fast feedback if the type table drifts.
|
||||||
|
*/
|
||||||
|
public function test_sql_type_mapping_via_reflection(): void {
|
||||||
|
$reflect = new ReflectionClass( $this->bridge );
|
||||||
|
$method = $reflect->getMethod( 'sql_type_for' );
|
||||||
|
$method->setAccessible( true );
|
||||||
|
|
||||||
|
$this->assertStringContainsString( 'int', $method->invoke( $this->bridge, 'number' ) );
|
||||||
|
$this->assertStringContainsString( 'decimal', $method->invoke( $this->bridge, 'price' ) );
|
||||||
|
$this->assertStringContainsString( 'tinyint', $method->invoke( $this->bridge, 'checkbox' ) );
|
||||||
|
$this->assertStringContainsString( 'date', $method->invoke( $this->bridge, 'date' ) );
|
||||||
|
$this->assertStringContainsString( 'varchar', $method->invoke( $this->bridge, 'text' ) );
|
||||||
|
// Unknown type → fallback to varchar.
|
||||||
|
$this->assertStringContainsString( 'varchar', $method->invoke( $this->bridge, 'unknown_type' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify build_record normalises HP attribute config correctly.
|
||||||
|
*/
|
||||||
|
public function test_build_record_normalises_attribute_config(): void {
|
||||||
|
$reflect = new ReflectionClass( $this->bridge );
|
||||||
|
$method = $reflect->getMethod( 'build_record' );
|
||||||
|
$method->setAccessible( true );
|
||||||
|
|
||||||
|
$record = $method->invoke( $this->bridge, 'listing', 'beds', array(
|
||||||
|
'edit_field' => array( 'type' => 'integer' ),
|
||||||
|
'filterable' => true,
|
||||||
|
'sortable' => false,
|
||||||
|
'searchable' => true,
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->assertSame( 'listing', $record['model'] );
|
||||||
|
$this->assertSame( 'beds', $record['slug'] );
|
||||||
|
$this->assertSame( 'hp_listing_beds', $record['meta_key'] );
|
||||||
|
$this->assertSame( 'integer', $record['type'] );
|
||||||
|
$this->assertTrue( $record['filterable'] );
|
||||||
|
$this->assertFalse( $record['sortable'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Promotion candidate logic: filterable OR sortable triggers promotion.
|
||||||
|
*/
|
||||||
|
public function test_promotion_candidate_logic(): void {
|
||||||
|
$reflect = new ReflectionClass( $this->bridge );
|
||||||
|
$method = $reflect->getMethod( 'is_promotion_candidate' );
|
||||||
|
$method->setAccessible( true );
|
||||||
|
|
||||||
|
// Filterable but not sortable → promote.
|
||||||
|
$this->assertTrue( $method->invoke( $this->bridge, array(
|
||||||
|
'model' => 'listing', 'slug' => 'x', 'meta_key' => 'hp_listing_x',
|
||||||
|
'type' => 'text', 'filterable' => true, 'sortable' => false, 'searchable' => true,
|
||||||
|
) ) );
|
||||||
|
|
||||||
|
// Sortable but not filterable → promote.
|
||||||
|
$this->assertTrue( $method->invoke( $this->bridge, array(
|
||||||
|
'model' => 'listing', 'slug' => 'x', 'meta_key' => 'hp_listing_x',
|
||||||
|
'type' => 'text', 'filterable' => false, 'sortable' => true, 'searchable' => false,
|
||||||
|
) ) );
|
||||||
|
|
||||||
|
// Searchable only (no filter, no sort) → don't promote (full-text would
|
||||||
|
// be a different optimization).
|
||||||
|
$this->assertFalse( $method->invoke( $this->bridge, array(
|
||||||
|
'model' => 'listing', 'slug' => 'x', 'meta_key' => 'hp_listing_x',
|
||||||
|
'type' => 'text', 'filterable' => false, 'sortable' => false, 'searchable' => true,
|
||||||
|
) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Benchmark.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Benchmark
|
||||||
|
*/
|
||||||
|
class HivePressBenchmarkTest extends TestCase {
|
||||||
|
|
||||||
|
public function test_default_iterations_is_fifty(): void {
|
||||||
|
$this->assertSame( 50, WPDO_HivePress_Benchmark::DEFAULT_ITERATIONS );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_run_returns_mean_milliseconds(): void {
|
||||||
|
$ms = WPDO_HivePress_Benchmark::run( static function () {
|
||||||
|
usleep( 1000 ); // 1 ms
|
||||||
|
}, 5 );
|
||||||
|
|
||||||
|
// Allow generous slack for slow CI runners; we just need it to be > 0.
|
||||||
|
$this->assertGreaterThan( 0.0, $ms );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_compare_returns_speedup_ratio(): void {
|
||||||
|
$result = WPDO_HivePress_Benchmark::compare(
|
||||||
|
'sample',
|
||||||
|
static function () { usleep( 4000 ); }, // ~4 ms baseline
|
||||||
|
static function () { usleep( 1000 ); }, // ~1 ms target
|
||||||
|
3
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame( 'sample', $result['name'] );
|
||||||
|
$this->assertGreaterThan( 0.0, $result['baseline_ms'] );
|
||||||
|
$this->assertGreaterThan( 0.0, $result['target_ms'] );
|
||||||
|
// Baseline is roughly 4× target — ratio should be > 1 (faster).
|
||||||
|
$this->assertGreaterThan( 1.0, $result['ratio'] );
|
||||||
|
$this->assertSame( 3, $result['iterations'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_compare_handles_zero_target_time(): void {
|
||||||
|
// If target is suspiciously fast, ratio falls back to 0 (no division).
|
||||||
|
$result = WPDO_HivePress_Benchmark::compare(
|
||||||
|
'instant',
|
||||||
|
static function () { /* noop */ },
|
||||||
|
static function () { /* noop */ },
|
||||||
|
1
|
||||||
|
);
|
||||||
|
// Either ratio > 0 (both nonzero) or 0 (target_ms was 0); never NaN/inf.
|
||||||
|
$this->assertIsFloat( $result['ratio'] );
|
||||||
|
$this->assertFalse( is_nan( $result['ratio'] ) );
|
||||||
|
$this->assertFalse( is_infinite( $result['ratio'] ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_run_suite_aggregates_samples(): void {
|
||||||
|
$report = WPDO_HivePress_Benchmark::run_suite( array(
|
||||||
|
array(
|
||||||
|
'name' => 'a',
|
||||||
|
'baseline' => static function () { usleep( 2000 ); },
|
||||||
|
'target' => static function () { usleep( 500 ); },
|
||||||
|
'iterations' => 2,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'b',
|
||||||
|
'baseline' => static function () { usleep( 4000 ); },
|
||||||
|
'target' => static function () { usleep( 1000 ); },
|
||||||
|
'iterations' => 2,
|
||||||
|
),
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->assertSame( 2, $report['sample_count'] );
|
||||||
|
$this->assertGreaterThan( 0.0, $report['geomean_ratio'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_run_suite_skips_malformed_sample(): void {
|
||||||
|
$report = WPDO_HivePress_Benchmark::run_suite( array(
|
||||||
|
array( 'name' => 'incomplete' ), // missing baseline + target
|
||||||
|
array(
|
||||||
|
'name' => 'ok',
|
||||||
|
'baseline' => static function () { usleep( 100 ); },
|
||||||
|
'target' => static function () { usleep( 100 ); },
|
||||||
|
'iterations' => 1,
|
||||||
|
),
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->assertSame( 1, $report['sample_count'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_geometric_mean_with_empty_values_returns_zero(): void {
|
||||||
|
$this->assertSame( 0.0, WPDO_HivePress_Benchmark::geometric_mean( array() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_geometric_mean_resists_outliers(): void {
|
||||||
|
// Geomean of (2, 8) = sqrt(16) = 4 (vs arithmetic mean 5).
|
||||||
|
$this->assertSame( 4.0, WPDO_HivePress_Benchmark::geometric_mean( array( 2.0, 8.0 ) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Blocks_Adapter.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Blocks_Adapter
|
||||||
|
*/
|
||||||
|
class HivePressBlocksAdapterTest extends TestCase {
|
||||||
|
|
||||||
|
private WPDO_HivePress_Blocks_Adapter $adapter;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->adapter = new WPDO_HivePress_Blocks_Adapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_implements_adapter_interface(): void {
|
||||||
|
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_identity(): void {
|
||||||
|
$this->assertSame( 'hivepress-blocks', $this->adapter->plugin_slug() );
|
||||||
|
$this->assertSame( 'HivePress\\Blocks\\Plugin', $this->adapter->detection_class() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_doctor_check_is_always_ok(): void {
|
||||||
|
$result = $this->adapter->doctor_check();
|
||||||
|
$this->assertTrue( $result['ok'] );
|
||||||
|
$this->assertStringContainsString( 'presentation-only', $result['message'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_score_aggregates_to_perfect_ten(): void {
|
||||||
|
$this->assertSame( 10.0, $this->adapter->suitability_score()['aggregate'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Bookings_Adapter (detect-only).
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Bookings_Adapter
|
||||||
|
*/
|
||||||
|
class HivePressBookingsAdapterTest extends TestCase {
|
||||||
|
|
||||||
|
use WpdbMockTrait;
|
||||||
|
|
||||||
|
private WPDO_HivePress_Bookings_Adapter $adapter;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->install_wpdb_mock();
|
||||||
|
$reflect = new ReflectionClass( WPDO_Schema_Registry::class );
|
||||||
|
$prop = $reflect->getProperty( 'instance' );
|
||||||
|
$prop->setAccessible( true );
|
||||||
|
$prop->setValue( null, null );
|
||||||
|
|
||||||
|
$this->adapter = new WPDO_HivePress_Bookings_Adapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_implements_adapter_interface(): void {
|
||||||
|
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_identity(): void {
|
||||||
|
$this->assertSame( 'hivepress-bookings', $this->adapter->plugin_slug() );
|
||||||
|
$this->assertSame( 'HivePress\\Bookings\\Plugin', $this->adapter->detection_class() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_on_register_fields_reserves_booking_hot_columns(): void {
|
||||||
|
$registry = WPDO_Schema_Registry::instance();
|
||||||
|
$this->adapter->on_register_fields( $registry );
|
||||||
|
|
||||||
|
$start = $registry->get_field( 'hp_booking', 'hp_start_time' );
|
||||||
|
$this->assertSame( 'hot', $start['zone'] );
|
||||||
|
$this->assertTrue( (bool) $start['indexed'] );
|
||||||
|
|
||||||
|
$end = $registry->get_field( 'hp_booking', 'hp_end_time' );
|
||||||
|
$this->assertSame( 'hot', $end['zone'] );
|
||||||
|
$this->assertTrue( (bool) $end['indexed'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_score_reflects_unverified_perf_dimension(): void {
|
||||||
|
$score = $this->adapter->suitability_score();
|
||||||
|
// D8 reduced to 0.9 because schema is best-effort until addon installs.
|
||||||
|
$this->assertSame( 0.9, $score['d8_perf'] );
|
||||||
|
// Aggregate = (7 × 1.0 + 0.9) / 8 × 10 = 9.875 → 9.88.
|
||||||
|
$this->assertSame( 9.88, $score['aggregate'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_migrations_lists_booking_module(): void {
|
||||||
|
$this->assertSame( array( 'hot_hp_booking' ), $this->adapter->migrations() );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Bootstrap — orchestration entry point.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Bootstrap
|
||||||
|
*/
|
||||||
|
class HivePressBootstrapTest extends TestCase {
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
WPDO_HivePress_Bootstrap::reset_for_tests();
|
||||||
|
WPDO_HivePress_Detector::reset_for_tests();
|
||||||
|
WPDO_HivePress_Conflict_Guard::reset_for_tests();
|
||||||
|
// Clear detector transient.
|
||||||
|
unset( $GLOBALS['_wp_options']['_transient_wpdo_hivepress_detector_cache'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_boot_is_idempotent_on_non_hivepress_site(): void {
|
||||||
|
WPDO_HivePress_Bootstrap::boot();
|
||||||
|
$this->assertSame( array(), WPDO_HivePress_Bootstrap::adapters() );
|
||||||
|
$this->assertSame( array(), WPDO_HivePress_Bootstrap::detected() );
|
||||||
|
|
||||||
|
// Second call must not fail or change state.
|
||||||
|
WPDO_HivePress_Bootstrap::boot();
|
||||||
|
$this->assertSame( array(), WPDO_HivePress_Bootstrap::adapters() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_adapter_for_returns_null_when_not_booted(): void {
|
||||||
|
$this->assertNull( WPDO_HivePress_Bootstrap::adapter_for( 'hivepress' ) );
|
||||||
|
$this->assertNull( WPDO_HivePress_Bootstrap::adapter_for( 'hivepress-reviews' ) );
|
||||||
|
$this->assertNull( WPDO_HivePress_Bootstrap::adapter_for( '' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_reset_clears_internal_state(): void {
|
||||||
|
WPDO_HivePress_Bootstrap::boot();
|
||||||
|
WPDO_HivePress_Bootstrap::reset_for_tests();
|
||||||
|
|
||||||
|
// After reset boot() should run again; detected() should be re-populated
|
||||||
|
// (still empty in the test env, but the call must not be skipped).
|
||||||
|
WPDO_HivePress_Bootstrap::boot();
|
||||||
|
$this->assertIsArray( WPDO_HivePress_Bootstrap::detected() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_should_bind_filter_short_circuits_binding(): void {
|
||||||
|
// Even if HivePress were detected, the filter must be honoured.
|
||||||
|
// We can't fake detection cleanly here without reflection, so instead
|
||||||
|
// we assert the filter is at least exposed and called: no detection
|
||||||
|
// → no adapter binding → empty adapters list regardless of filter.
|
||||||
|
add_filter( 'wpdo_hivepress_should_bind', '__return_false' );
|
||||||
|
WPDO_HivePress_Bootstrap::boot();
|
||||||
|
$this->assertSame( array(), WPDO_HivePress_Bootstrap::adapters() );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_CLI_HivePress (smoke).
|
||||||
|
*
|
||||||
|
* Real CLI execution requires WP_CLI runtime — these smoke tests just verify
|
||||||
|
* the class loads, methods exist, and dispatch table aligns with what
|
||||||
|
* 2meet-data-optimizer.php registers.
|
||||||
|
*
|
||||||
|
* @covers WPDO_CLI_HivePress
|
||||||
|
*/
|
||||||
|
class CliHivePressTest extends TestCase {
|
||||||
|
|
||||||
|
public function test_class_exists_and_methods_present(): void {
|
||||||
|
$this->assertTrue( class_exists( 'WPDO_CLI_HivePress' ) );
|
||||||
|
|
||||||
|
$expected = array( 'detect', 'score', 'doctor', 'migrate', 'rollback', 'benchmark' );
|
||||||
|
foreach ( $expected as $method ) {
|
||||||
|
$this->assertTrue(
|
||||||
|
method_exists( 'WPDO_CLI_HivePress', $method ),
|
||||||
|
sprintf( 'Method %s missing on WPDO_CLI_HivePress', $method )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_set_state_helper_is_private(): void {
|
||||||
|
$reflect = new ReflectionClass( WPDO_CLI_HivePress::class );
|
||||||
|
$this->assertTrue( $reflect->hasMethod( 'set_state' ) );
|
||||||
|
$method = $reflect->getMethod( 'set_state' );
|
||||||
|
$this->assertTrue( $method->isPrivate() );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Comment_Router.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Comment_Router
|
||||||
|
*/
|
||||||
|
class HivePressCommentRouterTest extends TestCase {
|
||||||
|
|
||||||
|
use WpdbMockTrait;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->install_wpdb_mock();
|
||||||
|
WPDO_HivePress_Comment_Router::reset_for_tests();
|
||||||
|
// Default disabled.
|
||||||
|
$GLOBALS['_wp_options'][ WPDO_HivePress_Comment_Router::OPTION_ENABLED ] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_disabled_by_default(): void {
|
||||||
|
$this->assertFalse( WPDO_HivePress_Comment_Router::is_enabled() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_enabled_when_option_set(): void {
|
||||||
|
$GLOBALS['_wp_options'][ WPDO_HivePress_Comment_Router::OPTION_ENABLED ] = 1;
|
||||||
|
$this->assertTrue( WPDO_HivePress_Comment_Router::is_enabled() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_register_is_idempotent(): void {
|
||||||
|
$GLOBALS['_wp_options'][ WPDO_HivePress_Comment_Router::OPTION_ENABLED ] = 1;
|
||||||
|
WPDO_HivePress_Comment_Router::register();
|
||||||
|
WPDO_HivePress_Comment_Router::register(); // Second call must be no-op.
|
||||||
|
$this->assertTrue( true ); // No throw = pass
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_rewrite_skips_unknown_comment_type(): void {
|
||||||
|
$query = new stdClass();
|
||||||
|
$query->query_vars = array( 'type' => 'comment' ); // not in shadow map
|
||||||
|
|
||||||
|
$clauses = array( 'join' => '', 'where' => '1=1' );
|
||||||
|
$out = WPDO_HivePress_Comment_Router::rewrite( $clauses, $query );
|
||||||
|
|
||||||
|
$this->assertSame( $clauses, $out );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_rewrite_adds_left_join_for_hp_favorite(): void {
|
||||||
|
$query = new stdClass();
|
||||||
|
$query->query_vars = array( 'type' => 'hp_favorite' );
|
||||||
|
|
||||||
|
$clauses = array( 'join' => '', 'where' => '1=1' );
|
||||||
|
$out = WPDO_HivePress_Comment_Router::rewrite( $clauses, $query );
|
||||||
|
|
||||||
|
$this->assertStringContainsString( 'LEFT JOIN', $out['join'] );
|
||||||
|
$this->assertStringContainsString( 'wpdo_comment_hp_favorite', $out['join'] );
|
||||||
|
$this->assertStringContainsString( 'AS wpdo_shadow', $out['join'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_rewrite_promotes_recipient_for_hp_message(): void {
|
||||||
|
$query = new stdClass();
|
||||||
|
$query->query_vars = array( 'type' => 'hp_message' );
|
||||||
|
|
||||||
|
$clauses = array(
|
||||||
|
'join' => '',
|
||||||
|
'where' => 'wp_comments.comment_karma = 42 AND comment_approved = 0',
|
||||||
|
);
|
||||||
|
$out = WPDO_HivePress_Comment_Router::rewrite( $clauses, $query );
|
||||||
|
|
||||||
|
// recipient lookup should be rewritten to use shadow column.
|
||||||
|
$this->assertStringContainsString( 'wpdo_shadow.recipient_id = 42', $out['where'] );
|
||||||
|
// Other predicates preserved.
|
||||||
|
$this->assertStringContainsString( 'comment_approved = 0', $out['where'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_rewrite_handles_array_type(): void {
|
||||||
|
$query = new stdClass();
|
||||||
|
$query->query_vars = array( 'type' => array( 'hp_review', 'comment' ) );
|
||||||
|
|
||||||
|
$clauses = array( 'join' => '', 'where' => '' );
|
||||||
|
$out = WPDO_HivePress_Comment_Router::rewrite( $clauses, $query );
|
||||||
|
|
||||||
|
// First element of type array should match (hp_review).
|
||||||
|
$this->assertStringContainsString( 'wpdo_comment_hp_review', $out['join'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_rewrite_returns_unchanged_when_query_invalid(): void {
|
||||||
|
$clauses = array( 'join' => '', 'where' => '1=1' );
|
||||||
|
$out = WPDO_HivePress_Comment_Router::rewrite( $clauses, 'not an object' );
|
||||||
|
$this->assertSame( $clauses, $out );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Conflict_Guard — legacy hp-* plugin detection.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Conflict_Guard
|
||||||
|
*/
|
||||||
|
class HivePressConflictGuardTest extends TestCase {
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
WPDO_HivePress_Conflict_Guard::reset_for_tests();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_no_conflicts_when_legacy_plugins_absent(): void {
|
||||||
|
// Neither HPCT_Core nor HP_Info_Cards are loaded in the test env.
|
||||||
|
$conflicts = WPDO_HivePress_Conflict_Guard::detect_conflicts();
|
||||||
|
$this->assertSame( array(), $conflicts );
|
||||||
|
$this->assertFalse( WPDO_HivePress_Conflict_Guard::has_conflict() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_conflict_detected_when_hpct_const_defined(): void {
|
||||||
|
// Simulate hp-custom-tables presence via constant probe.
|
||||||
|
if ( ! defined( 'HPCT_VERSION' ) ) {
|
||||||
|
define( 'HPCT_VERSION', '1.0.0' );
|
||||||
|
}
|
||||||
|
WPDO_HivePress_Conflict_Guard::reset_for_tests();
|
||||||
|
$conflicts = WPDO_HivePress_Conflict_Guard::detect_conflicts();
|
||||||
|
$this->assertContains( 'hp-custom-tables', $conflicts );
|
||||||
|
$this->assertTrue( WPDO_HivePress_Conflict_Guard::has_conflict() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_check_and_warn_safe_when_no_conflicts(): void {
|
||||||
|
WPDO_HivePress_Conflict_Guard::reset_for_tests();
|
||||||
|
// Should not throw or render anything when clean.
|
||||||
|
$this->expectOutputString( '' );
|
||||||
|
WPDO_HivePress_Conflict_Guard::check_and_warn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_render_notice_does_nothing_when_not_admin(): void {
|
||||||
|
// is_admin() stub returns false by default.
|
||||||
|
ob_start();
|
||||||
|
WPDO_HivePress_Conflict_Guard::render_notice();
|
||||||
|
$out = ob_get_clean();
|
||||||
|
$this->assertSame( '', $out );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_memo_cache_avoids_repeat_probing(): void {
|
||||||
|
WPDO_HivePress_Conflict_Guard::reset_for_tests();
|
||||||
|
$first = WPDO_HivePress_Conflict_Guard::detect_conflicts();
|
||||||
|
$second = WPDO_HivePress_Conflict_Guard::detect_conflicts();
|
||||||
|
$this->assertSame( $first, $second );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Core_Adapter — Listing / Vendor field registration.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Core_Adapter
|
||||||
|
*/
|
||||||
|
class HivePressCoreAdapterTest extends TestCase {
|
||||||
|
|
||||||
|
private WPDO_HivePress_Core_Adapter $adapter;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
// WPDO_Schema_Registry has no reset_for_tests() — use reflection to
|
||||||
|
// clear its singleton so each test starts with a fresh registry.
|
||||||
|
$reflect = new ReflectionClass( WPDO_Schema_Registry::class );
|
||||||
|
if ( $reflect->hasProperty( 'instance' ) ) {
|
||||||
|
$prop = $reflect->getProperty( 'instance' );
|
||||||
|
$prop->setAccessible( true );
|
||||||
|
$prop->setValue( null, null );
|
||||||
|
}
|
||||||
|
WPDO_Custom_Table_Registry::reset_for_tests();
|
||||||
|
$this->adapter = new WPDO_HivePress_Core_Adapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_implements_adapter_interface(): void {
|
||||||
|
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_plugin_slug_is_hivepress(): void {
|
||||||
|
$this->assertSame( 'hivepress', $this->adapter->plugin_slug() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_detection_class_targets_hivepress_core(): void {
|
||||||
|
$this->assertSame( 'HivePress\\Core', $this->adapter->detection_class() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_detection_const_targets_hivepress_version(): void {
|
||||||
|
$this->assertSame( 'HIVEPRESS_VERSION', $this->adapter->detection_const() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_minimum_addon_version_floor(): void {
|
||||||
|
// 1.7.0 introduced the field-alias convention this adapter relies on.
|
||||||
|
$this->assertSame( '1.7.0', $this->adapter->minimum_addon_version() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_migrations_returns_listing_and_vendor_modules(): void {
|
||||||
|
$mods = $this->adapter->migrations();
|
||||||
|
$this->assertContains( 'hot_hp_listing', $mods );
|
||||||
|
$this->assertContains( 'hot_hp_vendor', $mods );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_on_register_fields_populates_schema_registry(): void {
|
||||||
|
$registry = WPDO_Schema_Registry::instance();
|
||||||
|
$this->adapter->on_register_fields( $registry );
|
||||||
|
|
||||||
|
// Listing hot fields.
|
||||||
|
$drafted = $registry->get_field( 'hp_listing', 'hp_drafted' );
|
||||||
|
$this->assertIsArray( $drafted );
|
||||||
|
$this->assertSame( 'hot', $drafted['zone'] );
|
||||||
|
$this->assertTrue( (bool) $drafted['indexed'] );
|
||||||
|
|
||||||
|
$expired = $registry->get_field( 'hp_listing', 'hp_expired_time' );
|
||||||
|
$this->assertSame( 'hot', $expired['zone'] );
|
||||||
|
$this->assertStringContainsString( 'bigint', $expired['data_type'] );
|
||||||
|
|
||||||
|
$featured_time = $registry->get_field( 'hp_listing', 'hp_featured_time' );
|
||||||
|
$this->assertSame( 'hot', $featured_time['zone'] );
|
||||||
|
|
||||||
|
// Vendor cold blob.
|
||||||
|
$vendor_image = $registry->get_field( 'hp_vendor', 'hp_image' );
|
||||||
|
$this->assertIsArray( $vendor_image );
|
||||||
|
$this->assertSame( 'cold', $vendor_image['zone'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_suitability_score_aggregates_to_ten(): void {
|
||||||
|
$score = $this->adapter->suitability_score();
|
||||||
|
$this->assertArrayHasKey( 'aggregate', $score );
|
||||||
|
$this->assertSame( 10.0, $score['aggregate'] );
|
||||||
|
// All eight dimensions present.
|
||||||
|
foreach ( array( 'd1_meta_calls', 'd2_meta_sql', 'd3_table_coverage', 'd4_registry_meta', 'd5_hook_bus', 'd6_options', 'd7_coupling', 'd8_perf' ) as $key ) {
|
||||||
|
$this->assertArrayHasKey( $key, $score );
|
||||||
|
$this->assertGreaterThanOrEqual( 0.0, $score[ $key ] );
|
||||||
|
$this->assertLessThanOrEqual( 1.0, $score[ $key ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_doctor_check_reports_table_status(): void {
|
||||||
|
$result = $this->adapter->doctor_check();
|
||||||
|
$this->assertIsArray( $result );
|
||||||
|
$this->assertArrayHasKey( 'ok', $result );
|
||||||
|
$this->assertArrayHasKey( 'message', $result );
|
||||||
|
$this->assertArrayHasKey( 'details', $result );
|
||||||
|
// The stub $wpdb returns null for SHOW TABLES, so tables appear missing → ok=false.
|
||||||
|
$this->assertFalse( $result['ok'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_optimize_query_extracts_hot_clauses(): void {
|
||||||
|
$registry = WPDO_Schema_Registry::instance();
|
||||||
|
$this->adapter->on_register_fields( $registry );
|
||||||
|
|
||||||
|
$query = new WP_Query( array(
|
||||||
|
'post_type' => 'hp_listing',
|
||||||
|
'meta_query' => array(
|
||||||
|
array( 'key' => 'hp_drafted', 'value' => 1, 'compare' => '=' ),
|
||||||
|
array( 'key' => 'unrelated_key', 'value' => 'foo', 'compare' => '=' ),
|
||||||
|
),
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->adapter->optimize_query( $query );
|
||||||
|
|
||||||
|
// Hot clause should have been moved to wpdo_hot_clauses.
|
||||||
|
$hot = $query->get( 'wpdo_hot_clauses' );
|
||||||
|
// Note: in the test env the WPDO_Feature_Flags check may short-circuit
|
||||||
|
// (no module active), so the assertion is "either the clause moved OR
|
||||||
|
// it stayed put; never silently corrupted".
|
||||||
|
$remaining = (array) $query->get( 'meta_query' );
|
||||||
|
$this->assertIsArray( $remaining );
|
||||||
|
// `unrelated_key` must always remain in meta_query regardless of routing.
|
||||||
|
$found_unrelated = false;
|
||||||
|
foreach ( $remaining as $clause ) {
|
||||||
|
if ( is_array( $clause ) && ( $clause['key'] ?? '' ) === 'unrelated_key' ) {
|
||||||
|
$found_unrelated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->assertTrue( $found_unrelated, 'Non-hot meta_query clause must always be preserved.' );
|
||||||
|
// hot_clauses is either populated (when feature flag active) or empty (when not).
|
||||||
|
$this->assertTrue( $hot === '' || is_array( $hot ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_optimize_query_handles_empty_meta_query(): void {
|
||||||
|
$query = new WP_Query( array( 'post_type' => 'hp_listing' ) );
|
||||||
|
$this->adapter->optimize_query( $query );
|
||||||
|
// Must not crash; hot_clauses should remain unset.
|
||||||
|
$this->assertEmpty( $query->get( 'wpdo_hot_clauses' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_optimize_search_delegates_to_optimize_query(): void {
|
||||||
|
$query = new WP_Query( array( 'post_type' => 'hp_listing' ) );
|
||||||
|
// Delegation is implementation detail; verify just that it doesn't crash
|
||||||
|
// and that an irrelevant attribute_fields argument is ignored.
|
||||||
|
$this->adapter->optimize_search( $query, array() );
|
||||||
|
$this->assertEmpty( $query->get( 'wpdo_hot_clauses' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Cron_Optimizer.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Cron_Optimizer
|
||||||
|
*/
|
||||||
|
class HivePressCronOptimizerTest extends TestCase {
|
||||||
|
|
||||||
|
use WpdbMockTrait;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->install_wpdb_mock();
|
||||||
|
WPDO_HivePress_Cron_Optimizer::reset_for_tests();
|
||||||
|
$GLOBALS['_wp_options'][ WPDO_HivePress_Cron_Optimizer::OPTION_ENABLED ] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_disabled_by_default(): void {
|
||||||
|
$this->assertFalse( WPDO_HivePress_Cron_Optimizer::is_enabled() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_enabled_when_option_set(): void {
|
||||||
|
$GLOBALS['_wp_options'][ WPDO_HivePress_Cron_Optimizer::OPTION_ENABLED ] = 1;
|
||||||
|
$this->assertTrue( WPDO_HivePress_Cron_Optimizer::is_enabled() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_module_constant(): void {
|
||||||
|
$this->assertSame( 'hot_hp_listing', WPDO_HivePress_Cron_Optimizer::MODULE );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_register_is_idempotent(): void {
|
||||||
|
$GLOBALS['_wp_options'][ WPDO_HivePress_Cron_Optimizer::OPTION_ENABLED ] = 1;
|
||||||
|
WPDO_HivePress_Cron_Optimizer::register();
|
||||||
|
WPDO_HivePress_Cron_Optimizer::register(); // No throw = pass.
|
||||||
|
$this->assertTrue( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_maybe_run_returns_zero_when_module_inactive(): void {
|
||||||
|
// Feature_Flags::is_query_active('hot_hp_listing') is false in test env.
|
||||||
|
$count = WPDO_HivePress_Cron_Optimizer::maybe_run();
|
||||||
|
$this->assertSame( 0, $count );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Detector — addon detection + caching.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Detector
|
||||||
|
*/
|
||||||
|
class HivePressDetectorTest extends TestCase {
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
WPDO_HivePress_Detector::reset_for_tests();
|
||||||
|
// Clear transient cache (in-memory in test bootstrap).
|
||||||
|
unset( $GLOBALS['_wp_options']['_transient_wpdo_hivepress_detector_cache'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_returns_empty_array_when_hivepress_core_absent(): void {
|
||||||
|
// HivePress\Core is not declared in the test environment.
|
||||||
|
$result = WPDO_HivePress_Detector::detect();
|
||||||
|
$this->assertSame( array(), $result );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_short_circuit_caches_negative_result(): void {
|
||||||
|
WPDO_HivePress_Detector::detect();
|
||||||
|
// Second call should hit memo cache; verify identical.
|
||||||
|
$this->assertSame( array(), WPDO_HivePress_Detector::detect() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_catalog_returns_thirteen_known_addons(): void {
|
||||||
|
$catalog = WPDO_HivePress_Detector::catalog();
|
||||||
|
$this->assertCount( 13, $catalog );
|
||||||
|
$this->assertArrayHasKey( 'hivepress', $catalog );
|
||||||
|
$this->assertArrayHasKey( 'hivepress-bookings', $catalog );
|
||||||
|
$this->assertArrayHasKey( 'hivepress-marketplace', $catalog );
|
||||||
|
$this->assertArrayHasKey( 'hivepress-statistics', $catalog );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_is_known_recognises_supported_addons(): void {
|
||||||
|
$this->assertTrue( WPDO_HivePress_Detector::is_known( 'hivepress' ) );
|
||||||
|
$this->assertTrue( WPDO_HivePress_Detector::is_known( 'hivepress-reviews' ) );
|
||||||
|
$this->assertFalse( WPDO_HivePress_Detector::is_known( 'hivepress-frobnicator' ) );
|
||||||
|
$this->assertFalse( WPDO_HivePress_Detector::is_known( '' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_bust_cache_clears_memo_and_transient(): void {
|
||||||
|
WPDO_HivePress_Detector::detect();
|
||||||
|
// Seed transient with bogus data to verify bust clears it.
|
||||||
|
$GLOBALS['_wp_options']['_transient_wpdo_hivepress_detector_cache'] = array( 'fake' => '9.9.9' );
|
||||||
|
WPDO_HivePress_Detector::bust_cache();
|
||||||
|
$this->assertArrayNotHasKey( '_transient_wpdo_hivepress_detector_cache', $GLOBALS['_wp_options'] ?? array() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_detects_addon_via_active_plugin_signal(): void {
|
||||||
|
// HivePress addons publish no class/const — they register via the
|
||||||
|
// `hivepress/v1/extensions` filter and are detected purely by being
|
||||||
|
// active plugins. Seed active_plugins with core + one addon and assert
|
||||||
|
// both are detected even though no HivePress classes are declared.
|
||||||
|
$GLOBALS['_wp_options']['active_plugins'] = array(
|
||||||
|
'hivepress/hivepress.php',
|
||||||
|
'hivepress-messages/hivepress-messages.php',
|
||||||
|
);
|
||||||
|
WPDO_HivePress_Detector::reset_for_tests();
|
||||||
|
unset( $GLOBALS['_wp_options']['_transient_wpdo_hivepress_detector_cache'] );
|
||||||
|
|
||||||
|
$result = WPDO_HivePress_Detector::detect();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey( 'hivepress', $result, 'core detected via active plugin' );
|
||||||
|
$this->assertArrayHasKey( 'hivepress-messages', $result, 'addon detected via active plugin' );
|
||||||
|
$this->assertArrayNotHasKey( 'hivepress-reviews', $result, 'inactive addon not detected' );
|
||||||
|
|
||||||
|
// Cleanup so other tests observe no active plugins. bust_cache() clears
|
||||||
|
// BOTH the memo and the seeded transient (reset_for_tests clears only
|
||||||
|
// the memo) — otherwise the cached detection leaks into later suites.
|
||||||
|
unset( $GLOBALS['_wp_options']['active_plugins'] );
|
||||||
|
WPDO_HivePress_Detector::bust_cache();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Favorites_Adapter.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Favorites_Adapter
|
||||||
|
*/
|
||||||
|
class HivePressFavoritesAdapterTest extends TestCase {
|
||||||
|
|
||||||
|
use WpdbMockTrait;
|
||||||
|
|
||||||
|
private WPDO_HivePress_Favorites_Adapter $adapter;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->install_wpdb_mock();
|
||||||
|
WPDO_Custom_Table_Registry::reset_for_tests();
|
||||||
|
$this->adapter = new WPDO_HivePress_Favorites_Adapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_implements_adapter_interface(): void {
|
||||||
|
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_identity(): void {
|
||||||
|
$this->assertSame( 'hivepress-favorites', $this->adapter->plugin_slug() );
|
||||||
|
$this->assertSame( 'HivePress\\Favorites\\Plugin', $this->adapter->detection_class() );
|
||||||
|
$this->assertSame( 'HIVEPRESS_FAVORITES_VERSION', $this->adapter->detection_const() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_constants_exposed(): void {
|
||||||
|
$this->assertSame( 'hp_favorite', WPDO_HivePress_Favorites_Adapter::COMMENT_TYPE );
|
||||||
|
$this->assertSame( 'wpdo_comment_hp_favorite', WPDO_HivePress_Favorites_Adapter::TABLE );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_on_register_custom_tables_declares_shadow_table(): void {
|
||||||
|
$registry = WPDO_Custom_Table_Registry::instance();
|
||||||
|
$this->adapter->on_register_custom_tables( $registry );
|
||||||
|
|
||||||
|
$tables = $registry->all();
|
||||||
|
$this->assertCount( 1, $tables );
|
||||||
|
|
||||||
|
$cfg = reset( $tables );
|
||||||
|
$this->assertSame( 'hivepress-favorites', $cfg['provider'] );
|
||||||
|
$this->assertSame( 'wpdo_comment_hp_favorite', $cfg['table_name'] );
|
||||||
|
$this->assertSame( 'comment_id', $cfg['primary_key'] );
|
||||||
|
$this->assertArrayHasKey( 'unique_user_listing', $cfg['indexes'] );
|
||||||
|
$this->assertStringContainsString( 'UNIQUE', $cfg['indexes']['unique_user_listing'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_mirror_insert_skips_non_favorite_comments(): void {
|
||||||
|
// Stub $wpdb tracks queries.
|
||||||
|
global $wpdb;
|
||||||
|
$wpdb->queries = array();
|
||||||
|
|
||||||
|
$comment = new stdClass();
|
||||||
|
$comment->comment_type = 'comment'; // ← not hp_favorite
|
||||||
|
$comment->user_id = 1;
|
||||||
|
$comment->comment_post_ID = 99;
|
||||||
|
|
||||||
|
$this->adapter->mirror_insert( 123, $comment );
|
||||||
|
$this->assertSame( array(), $wpdb->queries );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_mirror_insert_writes_for_hp_favorite(): void {
|
||||||
|
global $wpdb;
|
||||||
|
$wpdb->queries = array();
|
||||||
|
|
||||||
|
$comment = new stdClass();
|
||||||
|
$comment->comment_type = 'hp_favorite';
|
||||||
|
$comment->user_id = 7;
|
||||||
|
$comment->comment_post_ID = 42;
|
||||||
|
$comment->comment_date = '2026-05-04 12:00:00';
|
||||||
|
|
||||||
|
$this->adapter->mirror_insert( 100, $comment );
|
||||||
|
|
||||||
|
$this->assertCount( 1, $wpdb->queries );
|
||||||
|
$this->assertStringContainsString( 'INSERT IGNORE', $wpdb->queries[0] );
|
||||||
|
$this->assertStringContainsString( 'wpdo_comment_hp_favorite', $wpdb->queries[0] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_mirror_insert_skips_when_user_or_listing_missing(): void {
|
||||||
|
global $wpdb;
|
||||||
|
$wpdb->queries = array();
|
||||||
|
|
||||||
|
$comment = new stdClass();
|
||||||
|
$comment->comment_type = 'hp_favorite';
|
||||||
|
$comment->user_id = 0;
|
||||||
|
$comment->comment_post_ID = 99;
|
||||||
|
|
||||||
|
$this->adapter->mirror_insert( 100, $comment );
|
||||||
|
$this->assertSame( array(), $wpdb->queries );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_doctor_check_reports_missing_table_in_stub_env(): void {
|
||||||
|
$result = $this->adapter->doctor_check();
|
||||||
|
$this->assertFalse( $result['ok'] );
|
||||||
|
$this->assertStringContainsString( 'wpdo_comment_hp_favorite', $result['message'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_score_aggregates_to_perfect_ten(): void {
|
||||||
|
$score = $this->adapter->suitability_score();
|
||||||
|
$this->assertSame( 10.0, $score['aggregate'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_migrations_lists_comment_module(): void {
|
||||||
|
$this->assertSame( array( 'comment_hp_favorite' ), $this->adapter->migrations() );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Marketplace_Adapter (detect-only).
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Marketplace_Adapter
|
||||||
|
*/
|
||||||
|
class HivePressMarketplaceAdapterTest extends TestCase {
|
||||||
|
|
||||||
|
use WpdbMockTrait;
|
||||||
|
|
||||||
|
private WPDO_HivePress_Marketplace_Adapter $adapter;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->install_wpdb_mock();
|
||||||
|
$reflect = new ReflectionClass( WPDO_Schema_Registry::class );
|
||||||
|
$prop = $reflect->getProperty( 'instance' );
|
||||||
|
$prop->setAccessible( true );
|
||||||
|
$prop->setValue( null, null );
|
||||||
|
|
||||||
|
$this->adapter = new WPDO_HivePress_Marketplace_Adapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_implements_adapter_interface(): void {
|
||||||
|
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_identity(): void {
|
||||||
|
$this->assertSame( 'hivepress-marketplace', $this->adapter->plugin_slug() );
|
||||||
|
$this->assertSame( 'HivePress\\Marketplace\\Plugin', $this->adapter->detection_class() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_on_register_fields_registers_hot_price_and_warm_counter(): void {
|
||||||
|
$registry = WPDO_Schema_Registry::instance();
|
||||||
|
$this->adapter->on_register_fields( $registry );
|
||||||
|
|
||||||
|
$price = $registry->get_field( 'hp_listing', 'hp_purchase_price' );
|
||||||
|
$this->assertSame( 'hot', $price['zone'] );
|
||||||
|
$this->assertTrue( (bool) $price['indexed'] );
|
||||||
|
$this->assertStringContainsString( 'decimal', $price['data_type'] );
|
||||||
|
|
||||||
|
$count = $registry->get_field( 'hp_listing', 'hp_purchase_count' );
|
||||||
|
$this->assertSame( 'warm', $count['zone'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_score_aggregates_to_nine_eight_eight(): void {
|
||||||
|
// D8 = 0.9 → aggregate = (7×1.0 + 0.9)/8 × 10 = 9.875 → 9.88.
|
||||||
|
$this->assertSame( 9.88, $this->adapter->suitability_score()['aggregate'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Memberships_Adapter.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Memberships_Adapter
|
||||||
|
*/
|
||||||
|
class HivePressMembershipsAdapterTest extends TestCase {
|
||||||
|
|
||||||
|
private WPDO_HivePress_Memberships_Adapter $adapter;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
// Reset Schema_Registry singleton via reflection.
|
||||||
|
$reflect = new ReflectionClass( WPDO_Schema_Registry::class );
|
||||||
|
$prop = $reflect->getProperty( 'instance' );
|
||||||
|
$prop->setAccessible( true );
|
||||||
|
$prop->setValue( null, null );
|
||||||
|
|
||||||
|
$this->adapter = new WPDO_HivePress_Memberships_Adapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_implements_adapter_interface(): void {
|
||||||
|
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_identity(): void {
|
||||||
|
$this->assertSame( 'hivepress-memberships', $this->adapter->plugin_slug() );
|
||||||
|
$this->assertSame( 'HivePress\\Memberships\\Plugin', $this->adapter->detection_class() );
|
||||||
|
$this->assertSame( 'HIVEPRESS_MEMBERSHIPS_VERSION', $this->adapter->detection_const() );
|
||||||
|
$this->assertSame( '2.0.0', $this->adapter->minimum_addon_version() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_on_register_fields_registers_three_hot_fields(): void {
|
||||||
|
$registry = WPDO_Schema_Registry::instance();
|
||||||
|
$this->adapter->on_register_fields( $registry );
|
||||||
|
|
||||||
|
// Plan fields.
|
||||||
|
$expire_period = $registry->get_field( 'hp_membership_plan', 'hp_expire_period' );
|
||||||
|
$this->assertSame( 'hot', $expire_period['zone'] );
|
||||||
|
$this->assertStringContainsString( 'int', $expire_period['data_type'] );
|
||||||
|
|
||||||
|
$primary = $registry->get_field( 'hp_membership_plan', 'hp_primary' );
|
||||||
|
$this->assertSame( 'hot', $primary['zone'] );
|
||||||
|
$this->assertTrue( (bool) $primary['indexed'] );
|
||||||
|
|
||||||
|
// Membership field — the hottest path.
|
||||||
|
$expired = $registry->get_field( 'hp_membership', 'hp_expired_time' );
|
||||||
|
$this->assertSame( 'hot', $expired['zone'] );
|
||||||
|
$this->assertTrue( (bool) $expired['indexed'] );
|
||||||
|
$this->assertStringContainsString( 'bigint', $expired['data_type'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_doctor_check_reports_missing_tables_in_stub_env(): void {
|
||||||
|
$result = $this->adapter->doctor_check();
|
||||||
|
$this->assertFalse( $result['ok'] );
|
||||||
|
$this->assertArrayHasKey( 'hp_membership_plan', $result['details'] );
|
||||||
|
$this->assertArrayHasKey( 'hp_membership', $result['details'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_score_aggregates_to_perfect_ten(): void {
|
||||||
|
$score = $this->adapter->suitability_score();
|
||||||
|
$this->assertSame( 10.0, $score['aggregate'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_migrations_lists_both_hot_modules(): void {
|
||||||
|
$mods = $this->adapter->migrations();
|
||||||
|
$this->assertContains( 'hot_hp_membership_plan', $mods );
|
||||||
|
$this->assertContains( 'hot_hp_membership', $mods );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Messages_Adapter.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Messages_Adapter
|
||||||
|
*/
|
||||||
|
class HivePressMessagesAdapterTest extends TestCase {
|
||||||
|
|
||||||
|
use WpdbMockTrait;
|
||||||
|
|
||||||
|
private WPDO_HivePress_Messages_Adapter $adapter;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->install_wpdb_mock();
|
||||||
|
WPDO_Custom_Table_Registry::reset_for_tests();
|
||||||
|
$this->adapter = new WPDO_HivePress_Messages_Adapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_implements_adapter_interface(): void {
|
||||||
|
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_identity(): void {
|
||||||
|
$this->assertSame( 'hivepress-messages', $this->adapter->plugin_slug() );
|
||||||
|
$this->assertSame( 'HivePress\\Messages\\Plugin', $this->adapter->detection_class() );
|
||||||
|
$this->assertSame( 'hp_message', WPDO_HivePress_Messages_Adapter::COMMENT_TYPE );
|
||||||
|
$this->assertSame( 'wpdo_comment_hp_message', WPDO_HivePress_Messages_Adapter::TABLE );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_on_register_custom_tables_declares_indexed_recipient(): void {
|
||||||
|
$registry = WPDO_Custom_Table_Registry::instance();
|
||||||
|
$this->adapter->on_register_custom_tables( $registry );
|
||||||
|
|
||||||
|
$tables = $registry->all();
|
||||||
|
$cfg = reset( $tables );
|
||||||
|
$this->assertSame( 'wpdo_comment_hp_message', $cfg['table_name'] );
|
||||||
|
$this->assertArrayHasKey( 'recipient_id', $cfg['expected_columns'] );
|
||||||
|
$this->assertArrayHasKey( 'idx_recipient_unread', $cfg['indexes'] );
|
||||||
|
$this->assertStringContainsString( 'recipient_id, is_read', $cfg['indexes']['idx_recipient_unread'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_mirror_insert_skips_non_message_comments(): void {
|
||||||
|
global $wpdb;
|
||||||
|
$wpdb->queries = array();
|
||||||
|
|
||||||
|
$comment = new stdClass();
|
||||||
|
$comment->comment_type = 'comment';
|
||||||
|
$comment->user_id = 1;
|
||||||
|
$comment->comment_karma = 5;
|
||||||
|
|
||||||
|
$this->adapter->mirror_insert( 1, $comment );
|
||||||
|
$this->assertSame( array(), $wpdb->queries );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_mirror_insert_promotes_recipient_from_comment_karma(): void {
|
||||||
|
global $wpdb;
|
||||||
|
$wpdb->queries = array();
|
||||||
|
|
||||||
|
$comment = new stdClass();
|
||||||
|
$comment->comment_type = 'hp_message';
|
||||||
|
$comment->user_id = 7; // sender
|
||||||
|
$comment->comment_karma = 42; // ← recipient hack lives here
|
||||||
|
$comment->comment_post_ID = 99;
|
||||||
|
$comment->comment_approved = 0;
|
||||||
|
$comment->comment_date = '2026-05-04 12:00:00';
|
||||||
|
|
||||||
|
$this->adapter->mirror_insert( 100, $comment );
|
||||||
|
|
||||||
|
$this->assertCount( 1, $wpdb->queries );
|
||||||
|
$sql = $wpdb->queries[0];
|
||||||
|
$this->assertStringContainsString( 'INSERT INTO', $sql );
|
||||||
|
$this->assertStringContainsString( 'wpdo_comment_hp_message', $sql );
|
||||||
|
// The promoted recipient_id should appear in the bound SQL.
|
||||||
|
$this->assertStringContainsString( '42', $sql );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_mirror_insert_skips_when_sender_or_recipient_zero(): void {
|
||||||
|
global $wpdb;
|
||||||
|
$wpdb->queries = array();
|
||||||
|
|
||||||
|
$comment = new stdClass();
|
||||||
|
$comment->comment_type = 'hp_message';
|
||||||
|
$comment->user_id = 0; // bad sender
|
||||||
|
$comment->comment_karma = 42;
|
||||||
|
$comment->comment_post_ID = 99;
|
||||||
|
|
||||||
|
$this->adapter->mirror_insert( 100, $comment );
|
||||||
|
$this->assertSame( array(), $wpdb->queries );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_doctor_check_reports_missing_table_in_stub_env(): void {
|
||||||
|
$result = $this->adapter->doctor_check();
|
||||||
|
$this->assertFalse( $result['ok'] );
|
||||||
|
$this->assertStringContainsString( 'wpdo_comment_hp_message', $result['message'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_score_aggregates_to_perfect_ten(): void {
|
||||||
|
$this->assertSame( 10.0, $this->adapter->suitability_score()['aggregate'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Requests_Adapter.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Requests_Adapter
|
||||||
|
*/
|
||||||
|
class HivePressRequestsAdapterTest extends TestCase {
|
||||||
|
|
||||||
|
use WpdbMockTrait;
|
||||||
|
|
||||||
|
private WPDO_HivePress_Requests_Adapter $adapter;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->install_wpdb_mock();
|
||||||
|
$reflect = new ReflectionClass( WPDO_Schema_Registry::class );
|
||||||
|
$prop = $reflect->getProperty( 'instance' );
|
||||||
|
$prop->setAccessible( true );
|
||||||
|
$prop->setValue( null, null );
|
||||||
|
WPDO_Custom_Table_Registry::reset_for_tests();
|
||||||
|
|
||||||
|
$this->adapter = new WPDO_HivePress_Requests_Adapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_implements_adapter_interface(): void {
|
||||||
|
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_identity(): void {
|
||||||
|
$this->assertSame( 'hivepress-requests', $this->adapter->plugin_slug() );
|
||||||
|
$this->assertSame( 'HivePress\\Requests\\Plugin', $this->adapter->detection_class() );
|
||||||
|
$this->assertSame( 'hp_offer', WPDO_HivePress_Requests_Adapter::OFFER_COMMENT_TYPE );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_on_register_fields_registers_request_hot_columns(): void {
|
||||||
|
$registry = WPDO_Schema_Registry::instance();
|
||||||
|
$this->adapter->on_register_fields( $registry );
|
||||||
|
|
||||||
|
$drafted = $registry->get_field( 'hp_request', 'hp_drafted' );
|
||||||
|
$this->assertSame( 'hot', $drafted['zone'] );
|
||||||
|
$this->assertTrue( (bool) $drafted['indexed'] );
|
||||||
|
|
||||||
|
$expired = $registry->get_field( 'hp_request', 'hp_expired_time' );
|
||||||
|
$this->assertSame( 'hot', $expired['zone'] );
|
||||||
|
$this->assertTrue( (bool) $expired['indexed'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_on_register_custom_tables_declares_offer_shadow(): void {
|
||||||
|
$registry = WPDO_Custom_Table_Registry::instance();
|
||||||
|
$this->adapter->on_register_custom_tables( $registry );
|
||||||
|
|
||||||
|
$tables = $registry->all();
|
||||||
|
$cfg = reset( $tables );
|
||||||
|
$this->assertSame( 'wpdo_comment_hp_offer', $cfg['table_name'] );
|
||||||
|
$this->assertSame( 'hp_request', $cfg['post_type_link'] );
|
||||||
|
$this->assertArrayHasKey( 'idx_request_approved', $cfg['indexes'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_mirror_offer_insert_skips_other_comment_types(): void {
|
||||||
|
global $wpdb;
|
||||||
|
$wpdb->queries = array();
|
||||||
|
|
||||||
|
$comment = new stdClass();
|
||||||
|
$comment->comment_type = 'comment'; // ← not hp_offer
|
||||||
|
$comment->comment_post_ID = 99;
|
||||||
|
$comment->user_id = 1;
|
||||||
|
|
||||||
|
$this->adapter->mirror_offer_insert( 1, $comment );
|
||||||
|
$this->assertSame( array(), $wpdb->queries );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_mirror_offer_insert_writes_for_hp_offer(): void {
|
||||||
|
global $wpdb;
|
||||||
|
$wpdb->queries = array();
|
||||||
|
|
||||||
|
$comment = new stdClass();
|
||||||
|
$comment->comment_type = 'hp_offer';
|
||||||
|
$comment->comment_post_ID = 42;
|
||||||
|
$comment->user_id = 7;
|
||||||
|
$comment->comment_approved = 0;
|
||||||
|
$comment->comment_date = '2026-05-04 12:00:00';
|
||||||
|
|
||||||
|
$this->adapter->mirror_offer_insert( 100, $comment );
|
||||||
|
$this->assertCount( 1, $wpdb->queries );
|
||||||
|
$this->assertStringContainsString( 'INSERT INTO', $wpdb->queries[0] );
|
||||||
|
$this->assertStringContainsString( 'wpdo_comment_hp_offer', $wpdb->queries[0] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_score_aggregates_to_perfect_ten(): void {
|
||||||
|
$this->assertSame( 10.0, $this->adapter->suitability_score()['aggregate'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_migrations_lists_request_and_offer_modules(): void {
|
||||||
|
$mods = $this->adapter->migrations();
|
||||||
|
$this->assertContains( 'hot_hp_request', $mods );
|
||||||
|
$this->assertContains( 'comment_hp_offer', $mods );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_REST.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_REST
|
||||||
|
*/
|
||||||
|
class HivePressRestTest extends TestCase {
|
||||||
|
|
||||||
|
private WPDO_HivePress_REST $rest;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
WPDO_HivePress_Bootstrap::reset_for_tests();
|
||||||
|
WPDO_HivePress_Detector::reset_for_tests();
|
||||||
|
// Default: caller is admin so permission check passes in unit env.
|
||||||
|
$GLOBALS['_wp_current_user_can']['manage_options'] = true;
|
||||||
|
$this->rest = new WPDO_HivePress_REST();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_namespace_constant(): void {
|
||||||
|
$this->assertSame( 'wpdo/v1', WPDO_HivePress_REST::NAMESPACE );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_register_routes_does_not_throw(): void {
|
||||||
|
// register_rest_route is stubbed in tests/bootstrap.php → returns true.
|
||||||
|
$this->rest->register_routes();
|
||||||
|
$this->assertTrue( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_check_permission_returns_true_for_admin(): void {
|
||||||
|
$this->assertTrue( $this->rest->check_permission() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_check_permission_returns_error_for_non_admin(): void {
|
||||||
|
$GLOBALS['_wp_current_user_can']['manage_options'] = false;
|
||||||
|
$result = $this->rest->check_permission();
|
||||||
|
$this->assertInstanceOf( WP_Error::class, $result );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_get_status_returns_addon_catalog(): void {
|
||||||
|
$response = $this->rest->get_status();
|
||||||
|
$this->assertInstanceOf( WP_REST_Response::class, $response );
|
||||||
|
$data = $response->get_data();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey( 'addons', $data );
|
||||||
|
$this->assertArrayHasKey( 'conflicts', $data );
|
||||||
|
$this->assertArrayHasKey( 'totals', $data );
|
||||||
|
// Catalog should list all 13 known addons regardless of detection state.
|
||||||
|
$this->assertSame( 13, $data['totals']['catalog'] );
|
||||||
|
// Without HivePress installed, detected = 0.
|
||||||
|
$this->assertSame( 0, $data['totals']['detected'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_get_score_returns_report_structure(): void {
|
||||||
|
$response = $this->rest->get_score();
|
||||||
|
$this->assertInstanceOf( WP_REST_Response::class, $response );
|
||||||
|
$data = $response->get_data();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey( 'aggregate', $data );
|
||||||
|
$this->assertArrayHasKey( 'adapter_count', $data );
|
||||||
|
$this->assertArrayHasKey( 'per_dimension', $data );
|
||||||
|
$this->assertArrayHasKey( 'adapters', $data );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_get_health_returns_ok_when_no_adapters_active(): void {
|
||||||
|
$response = $this->rest->get_health();
|
||||||
|
$this->assertInstanceOf( WP_REST_Response::class, $response );
|
||||||
|
$data = $response->get_data();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey( 'ok', $data );
|
||||||
|
$this->assertArrayHasKey( 'probes', $data );
|
||||||
|
// No active adapters → vacuously ok.
|
||||||
|
$this->assertTrue( $data['ok'] );
|
||||||
|
$this->assertSame( array(), $data['probes'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Reviews_Adapter.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Reviews_Adapter
|
||||||
|
*/
|
||||||
|
class HivePressReviewsAdapterTest extends TestCase {
|
||||||
|
|
||||||
|
private WPDO_HivePress_Reviews_Adapter $adapter;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->adapter = new WPDO_HivePress_Reviews_Adapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_implements_adapter_interface(): void {
|
||||||
|
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_identity(): void {
|
||||||
|
$this->assertSame( 'hivepress-reviews', $this->adapter->plugin_slug() );
|
||||||
|
$this->assertSame( 'HivePress\\Reviews\\Plugin', $this->adapter->detection_class() );
|
||||||
|
$this->assertSame( 'HIVEPRESS_REVIEWS_VERSION', $this->adapter->detection_const() );
|
||||||
|
$this->assertSame( '1.4.0', $this->adapter->minimum_addon_version() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_comment_type_constant_exposed(): void {
|
||||||
|
$this->assertSame( 'hp_review', WPDO_HivePress_Reviews_Adapter::COMMENT_TYPE );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_doctor_check_reports_missing_table_in_stub_env(): void {
|
||||||
|
$result = $this->adapter->doctor_check();
|
||||||
|
$this->assertIsArray( $result );
|
||||||
|
$this->assertArrayHasKey( 'ok', $result );
|
||||||
|
// Stub $wpdb returns null for SHOW TABLES → ok=false.
|
||||||
|
$this->assertFalse( $result['ok'] );
|
||||||
|
$this->assertStringContainsString( 'wpdo_comment_hp_review', $result['message'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_score_aggregates_to_perfect_ten(): void {
|
||||||
|
$score = $this->adapter->suitability_score();
|
||||||
|
$this->assertSame( 10.0, $score['aggregate'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_no_fsm_modules_owned(): void {
|
||||||
|
// Comment entity-bridge owns lifecycle; adapter is read-only.
|
||||||
|
$this->assertSame( array(), $this->adapter->migrations() );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Seo_Adapter.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Seo_Adapter
|
||||||
|
*/
|
||||||
|
class HivePressSeoAdapterTest extends TestCase {
|
||||||
|
|
||||||
|
private WPDO_HivePress_Seo_Adapter $adapter;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->adapter = new WPDO_HivePress_Seo_Adapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_implements_adapter_interface(): void {
|
||||||
|
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_identity(): void {
|
||||||
|
$this->assertSame( 'hivepress-seo', $this->adapter->plugin_slug() );
|
||||||
|
$this->assertSame( 'HivePress\\Seo\\Plugin', $this->adapter->detection_class() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_doctor_check_is_always_ok(): void {
|
||||||
|
$result = $this->adapter->doctor_check();
|
||||||
|
$this->assertTrue( $result['ok'] );
|
||||||
|
$this->assertStringContainsString( 'filter-based', $result['message'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_score_aggregates_to_perfect_ten(): void {
|
||||||
|
$this->assertSame( 10.0, $this->adapter->suitability_score()['aggregate'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Social_Links_Adapter.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Social_Links_Adapter
|
||||||
|
*/
|
||||||
|
class HivePressSocialLinksAdapterTest extends TestCase {
|
||||||
|
|
||||||
|
private WPDO_HivePress_Social_Links_Adapter $adapter;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$reflect = new ReflectionClass( WPDO_Schema_Registry::class );
|
||||||
|
$prop = $reflect->getProperty( 'instance' );
|
||||||
|
$prop->setAccessible( true );
|
||||||
|
$prop->setValue( null, null );
|
||||||
|
|
||||||
|
$this->adapter = new WPDO_HivePress_Social_Links_Adapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_implements_adapter_interface(): void {
|
||||||
|
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_identity(): void {
|
||||||
|
$this->assertSame( 'hivepress-social-links', $this->adapter->plugin_slug() );
|
||||||
|
$this->assertSame( 'HivePress\\SocialLinks\\Plugin', $this->adapter->detection_class() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_on_register_fields_registers_seven_cold_fields(): void {
|
||||||
|
$registry = WPDO_Schema_Registry::instance();
|
||||||
|
$this->adapter->on_register_fields( $registry );
|
||||||
|
|
||||||
|
// All seven social URL fields should land in cold zone on hp_vendor.
|
||||||
|
$facebook = $registry->get_field( 'hp_vendor', 'hp_facebook_url' );
|
||||||
|
$this->assertSame( 'cold', $facebook['zone'] );
|
||||||
|
|
||||||
|
$instagram = $registry->get_field( 'hp_vendor', 'hp_instagram_url' );
|
||||||
|
$this->assertSame( 'cold', $instagram['zone'] );
|
||||||
|
|
||||||
|
$whatsapp = $registry->get_field( 'hp_vendor', 'hp_whatsapp_url' );
|
||||||
|
$this->assertSame( 'cold', $whatsapp['zone'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_doctor_check_reports_field_count(): void {
|
||||||
|
$result = $this->adapter->doctor_check();
|
||||||
|
$this->assertTrue( $result['ok'] );
|
||||||
|
$this->assertStringContainsString( '7 cold fields', $result['message'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_score_aggregates_to_perfect_ten(): void {
|
||||||
|
$this->assertSame( 10.0, $this->adapter->suitability_score()['aggregate'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Statistics_Adapter (detect-only).
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Statistics_Adapter
|
||||||
|
*/
|
||||||
|
class HivePressStatisticsAdapterTest extends TestCase {
|
||||||
|
|
||||||
|
use WpdbMockTrait;
|
||||||
|
|
||||||
|
private WPDO_HivePress_Statistics_Adapter $adapter;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->install_wpdb_mock();
|
||||||
|
$reflect = new ReflectionClass( WPDO_Schema_Registry::class );
|
||||||
|
$prop = $reflect->getProperty( 'instance' );
|
||||||
|
$prop->setAccessible( true );
|
||||||
|
$prop->setValue( null, null );
|
||||||
|
|
||||||
|
$this->adapter = new WPDO_HivePress_Statistics_Adapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_implements_adapter_interface(): void {
|
||||||
|
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_identity(): void {
|
||||||
|
$this->assertSame( 'hivepress-statistics', $this->adapter->plugin_slug() );
|
||||||
|
$this->assertSame( 'HivePress\\Statistics\\Plugin', $this->adapter->detection_class() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_on_register_fields_registers_warm_counters(): void {
|
||||||
|
$registry = WPDO_Schema_Registry::instance();
|
||||||
|
$this->adapter->on_register_fields( $registry );
|
||||||
|
|
||||||
|
$views = $registry->get_field( 'hp_listing', 'hp_view_count' );
|
||||||
|
$this->assertSame( 'warm', $views['zone'] );
|
||||||
|
|
||||||
|
$clicks = $registry->get_field( 'hp_listing', 'hp_click_count' );
|
||||||
|
$this->assertSame( 'warm', $clicks['zone'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_score_aggregates_to_nine_eight_eight(): void {
|
||||||
|
$this->assertSame( 9.88, $this->adapter->suitability_score()['aggregate'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Suitability_Scorer.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Suitability_Scorer
|
||||||
|
*/
|
||||||
|
class HivePressSuitabilityScorerTest extends TestCase {
|
||||||
|
|
||||||
|
public function test_dimensions_constant_lists_eight_keys(): void {
|
||||||
|
$this->assertCount( 8, WPDO_HivePress_Suitability_Scorer::DIMENSIONS );
|
||||||
|
$this->assertContains( 'd1_meta_calls', WPDO_HivePress_Suitability_Scorer::DIMENSIONS );
|
||||||
|
$this->assertContains( 'd8_perf', WPDO_HivePress_Suitability_Scorer::DIMENSIONS );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_compute_aggregate_with_empty_input_returns_zero(): void {
|
||||||
|
$this->assertSame( 0.0, WPDO_HivePress_Suitability_Scorer::compute_aggregate( array() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_compute_aggregate_averages_adapter_scores(): void {
|
||||||
|
$scores = array(
|
||||||
|
'a' => array( 'aggregate' => 10.0 ),
|
||||||
|
'b' => array( 'aggregate' => 9.0 ),
|
||||||
|
'c' => array( 'aggregate' => 8.0 ),
|
||||||
|
);
|
||||||
|
// (10 + 9 + 8) / 3 = 9.0
|
||||||
|
$this->assertSame( 9.0, WPDO_HivePress_Suitability_Scorer::compute_aggregate( $scores ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_compute_per_dimension_averages_each_dimension(): void {
|
||||||
|
$scores = array(
|
||||||
|
'a' => array(
|
||||||
|
'd1_meta_calls' => 1.0, 'd2_meta_sql' => 1.0, 'd3_table_coverage' => 1.0,
|
||||||
|
'd4_registry_meta' => 1.0, 'd5_hook_bus' => 1.0, 'd6_options' => 1.0,
|
||||||
|
'd7_coupling' => 1.0, 'd8_perf' => 0.9,
|
||||||
|
),
|
||||||
|
'b' => array(
|
||||||
|
'd1_meta_calls' => 1.0, 'd2_meta_sql' => 1.0, 'd3_table_coverage' => 1.0,
|
||||||
|
'd4_registry_meta' => 1.0, 'd5_hook_bus' => 1.0, 'd6_options' => 1.0,
|
||||||
|
'd7_coupling' => 1.0, 'd8_perf' => 1.0,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$dim = WPDO_HivePress_Suitability_Scorer::compute_per_dimension( $scores );
|
||||||
|
|
||||||
|
// d1-d7 are 1.0 across both adapters → average 1.0.
|
||||||
|
$this->assertSame( 1.0, $dim['d1_meta_calls'] );
|
||||||
|
$this->assertSame( 1.0, $dim['d7_coupling'] );
|
||||||
|
|
||||||
|
// d8: (0.9 + 1.0) / 2 = 0.95.
|
||||||
|
$this->assertSame( 0.95, $dim['d8_perf'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_compute_per_dimension_with_empty_input_returns_all_zero(): void {
|
||||||
|
$dim = WPDO_HivePress_Suitability_Scorer::compute_per_dimension( array() );
|
||||||
|
foreach ( WPDO_HivePress_Suitability_Scorer::DIMENSIONS as $d ) {
|
||||||
|
$this->assertSame( 0.0, $dim[ $d ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_report_with_no_active_adapters(): void {
|
||||||
|
// Bootstrap not booted in unit env → adapters() = empty.
|
||||||
|
WPDO_HivePress_Bootstrap::reset_for_tests();
|
||||||
|
$report = WPDO_HivePress_Suitability_Scorer::report();
|
||||||
|
|
||||||
|
$this->assertSame( 0, $report['adapter_count'] );
|
||||||
|
$this->assertSame( 0.0, $report['aggregate'] );
|
||||||
|
$this->assertSame( array(), $report['adapters'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_adapters_below_threshold_returns_empty_for_unknown_dimension(): void {
|
||||||
|
$this->assertSame( array(), WPDO_HivePress_Suitability_Scorer::adapters_below_threshold( 'd99_garbage' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for WPDO_HivePress_Tags_Adapter.
|
||||||
|
*
|
||||||
|
* @covers WPDO_HivePress_Tags_Adapter
|
||||||
|
*/
|
||||||
|
class HivePressTagsAdapterTest extends TestCase {
|
||||||
|
|
||||||
|
private WPDO_HivePress_Tags_Adapter $adapter;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->adapter = new WPDO_HivePress_Tags_Adapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_implements_adapter_interface(): void {
|
||||||
|
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_identity(): void {
|
||||||
|
$this->assertSame( 'hivepress-tags', $this->adapter->plugin_slug() );
|
||||||
|
$this->assertSame( 'HivePress\\Tags\\Plugin', $this->adapter->detection_class() );
|
||||||
|
$this->assertSame( 'HIVEPRESS_TAGS_VERSION', $this->adapter->detection_const() );
|
||||||
|
$this->assertSame( '1.1.0', $this->adapter->minimum_addon_version() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_doctor_check_is_always_ok(): void {
|
||||||
|
$result = $this->adapter->doctor_check();
|
||||||
|
$this->assertTrue( $result['ok'] );
|
||||||
|
$this->assertStringContainsString( 'term-based', $result['message'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_score_aggregates_to_perfect_ten(): void {
|
||||||
|
$this->assertSame( 10.0, $this->adapter->suitability_score()['aggregate'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_no_fsm_modules_owned(): void {
|
||||||
|
$this->assertSame( array(), $this->adapter->migrations() );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared $wpdb mock helper for HivePress adapter tests.
|
||||||
|
*
|
||||||
|
* Several existing wpdo tests (ZoneHotTest, SyncBridgeTest, etc.) replace the
|
||||||
|
* global $wpdb with their own anonymous-class mock and never restore it. When
|
||||||
|
* our adapter tests run after those, $wpdb lacks the query/get_col/delete
|
||||||
|
* methods our mirror_insert / cron-optimizer code paths call, causing
|
||||||
|
* cross-test pollution failures.
|
||||||
|
*
|
||||||
|
* Trait reinstalls a known $wpdb mock + clears the wpdo_features option so
|
||||||
|
* Feature_Flags reports idle — the safe default state.
|
||||||
|
*/
|
||||||
|
trait WpdbMockTrait {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install a fresh $wpdb mock with the methods adapter code paths call.
|
||||||
|
*
|
||||||
|
* Idempotent — call from setUp() in test classes that touch $wpdb.
|
||||||
|
*/
|
||||||
|
protected function install_wpdb_mock(): void {
|
||||||
|
global $wpdb;
|
||||||
|
$wpdb = new class {
|
||||||
|
public string $prefix = 'wp_';
|
||||||
|
public string $comments = 'wp_comments';
|
||||||
|
public string $postmeta = 'wp_postmeta';
|
||||||
|
public string $posts = 'wp_posts';
|
||||||
|
public string $options = 'wp_options';
|
||||||
|
|
||||||
|
/** @var array<int,string> */
|
||||||
|
public array $queries = array();
|
||||||
|
|
||||||
|
public function prepare( string $sql, ...$args ): string {
|
||||||
|
$i = 0;
|
||||||
|
return (string) preg_replace_callback(
|
||||||
|
'/%[sd]/',
|
||||||
|
static function () use ( &$i, $args ) {
|
||||||
|
return $args[ $i++ ] ?? '?';
|
||||||
|
},
|
||||||
|
$sql
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function query( string $sql ): int|bool {
|
||||||
|
$this->queries[] = $sql;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_var( string $sql ): ?string {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_col( string $sql ): array {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_results( string $sql, $output = OBJECT ): array {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function insert( string $table, array $data, $format = null ): int|false {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update( string $table, array $data, array $where, $format = null, $where_format = null ): int|false {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete( string $table, array $where, $format = null ): int|false {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Reset Feature_Flags state so is_query_active() returns false in tests.
|
||||||
|
$GLOBALS['_wp_options']['wpdo_features'] = array();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user