diff --git a/.gitignore b/.gitignore index b338dcdd..ce35fa1e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ package-lock.json yarn.lock .DS_Store .idea -vendor \ No newline at end of file +vendor +.phpunit.result.cache +.phpunit.cache \ No newline at end of file diff --git a/composer.json b/composer.json index 5a1c8dd3..815a7520 100644 --- a/composer.json +++ b/composer.json @@ -26,5 +26,8 @@ "psr-4": { "MetaBox\\": "src/" } + }, + "require-dev": { + "phpunit/phpunit": "^11.3" } } diff --git a/composer.lock b/composer.lock index 345027e3..b3381ee7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,1642 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2ecfb313af70de53ae33703de60ea8aa", + "content-hash": "da83f796ba5551dd96e4d49699bbe54c", "packages": [], - "packages-dev": [], + "packages-dev": [ + { + "name": "myclabs/deep-copy", + "version": "1.12.0", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3 <3.2.2" + }, + "require-dev": { + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpspec/prophecy": "^1.10", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" + }, + "type": "library", + "autoload": { + "files": [ + "src/DeepCopy/deep_copy.php" + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2024-06-12T14:39:25+00:00" + }, + { + "name": "nikic/php-parser", + "version": "v5.1.0", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/683130c2ff8c2739f4822ff7ac5c873ec529abd1", + "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-json": "*", + "ext-tokenizer": "*", + "php": ">=7.4" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v5.1.0" + }, + "time": "2024-07-01T20:03:41+00:00" + }, + { + "name": "phar-io/manifest", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "54750ef60c58e43759730615a392c31c80e23176" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176", + "reference": "54750ef60c58e43759730615a392c31c80e23176", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-phar": "*", + "ext-xmlwriter": "*", + "phar-io/version": "^3.0.1", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:33:53+00:00" + }, + { + "name": "phar-io/version", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/3.2.1" + }, + "time": "2022-02-21T01:04:05+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "11.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "19b6365ab8b59a64438c0c3f4241feeb480c9861" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/19b6365ab8b59a64438c0c3f4241feeb480c9861", + "reference": "19b6365ab8b59a64438c0c3f4241feeb480c9861", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-xmlwriter": "*", + "nikic/php-parser": "^5.0", + "php": ">=8.2", + "phpunit/php-file-iterator": "^5.0", + "phpunit/php-text-template": "^4.0", + "sebastian/code-unit-reverse-lookup": "^4.0", + "sebastian/complexity": "^4.0", + "sebastian/environment": "^7.0", + "sebastian/lines-of-code": "^3.0", + "sebastian/version": "^5.0", + "theseer/tokenizer": "^1.2.0" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "suggest": { + "ext-pcov": "PHP extension that provides line coverage", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "11.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.5" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:05:37+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "5.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "6ed896bf50bbbfe4d504a33ed5886278c78e4a26" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6ed896bf50bbbfe4d504a33ed5886278c78e4a26", + "reference": "6ed896bf50bbbfe4d504a33ed5886278c78e4a26", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/5.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:06:37+00:00" + }, + { + "name": "phpunit/php-invoker", + "version": "5.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "c1ca3814734c07492b3d4c5f794f4b0995333da2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/c1ca3814734c07492b3d4c5f794f4b0995333da2", + "reference": "c1ca3814734c07492b3d4c5f794f4b0995333da2", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^11.0" + }, + "suggest": { + "ext-pcntl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", + "keywords": [ + "process" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "security": "https://github.com/sebastianbergmann/php-invoker/security/policy", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/5.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:07:44+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "3e0404dc6b300e6bf56415467ebcb3fe4f33e964" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/3e0404dc6b300e6bf56415467ebcb3fe4f33e964", + "reference": "3e0404dc6b300e6bf56415467ebcb3fe4f33e964", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "security": "https://github.com/sebastianbergmann/php-text-template/security/policy", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:08:43+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "7.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "3b415def83fbcb41f991d9ebf16ae4ad8b7837b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3b415def83fbcb41f991d9ebf16ae4ad8b7837b3", + "reference": "3b415def83fbcb41f991d9ebf16ae4ad8b7837b3", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "7.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "security": "https://github.com/sebastianbergmann/php-timer/security/policy", + "source": "https://github.com/sebastianbergmann/php-timer/tree/7.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:09:35+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "11.3.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "fe179875ef0c14e90b75617002767eae0a742641" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fe179875ef0c14e90b75617002767eae0a742641", + "reference": "fe179875ef0c14e90b75617002767eae0a742641", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.12.0", + "phar-io/manifest": "^2.0.4", + "phar-io/version": "^3.2.1", + "php": ">=8.2", + "phpunit/php-code-coverage": "^11.0.5", + "phpunit/php-file-iterator": "^5.0.1", + "phpunit/php-invoker": "^5.0.1", + "phpunit/php-text-template": "^4.0.1", + "phpunit/php-timer": "^7.0.1", + "sebastian/cli-parser": "^3.0.2", + "sebastian/code-unit": "^3.0.1", + "sebastian/comparator": "^6.0.2", + "sebastian/diff": "^6.0.2", + "sebastian/environment": "^7.2.0", + "sebastian/exporter": "^6.1.3", + "sebastian/global-state": "^7.0.2", + "sebastian/object-enumerator": "^6.0.1", + "sebastian/type": "^5.0.1", + "sebastian/version": "^5.0.1" + }, + "suggest": { + "ext-soap": "To be able to generate mocks based on WSDL files" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "11.3-dev" + } + }, + "autoload": { + "files": [ + "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "security": "https://github.com/sebastianbergmann/phpunit/security/policy", + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.3.1" + }, + "funding": [ + { + "url": "https://phpunit.de/sponsors.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", + "type": "tidelift" + } + ], + "time": "2024-08-13T06:14:23+00:00" + }, + { + "name": "sebastian/cli-parser", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "15c5dd40dc4f38794d383bb95465193f5e0ae180" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/15c5dd40dc4f38794d383bb95465193f5e0ae180", + "reference": "15c5dd40dc4f38794d383bb95465193f5e0ae180", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "security": "https://github.com/sebastianbergmann/cli-parser/security/policy", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/3.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:41:36+00:00" + }, + { + "name": "sebastian/code-unit", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "6bb7d09d6623567178cf54126afa9c2310114268" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/6bb7d09d6623567178cf54126afa9c2310114268", + "reference": "6bb7d09d6623567178cf54126afa9c2310114268", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "security": "https://github.com/sebastianbergmann/code-unit/security/policy", + "source": "https://github.com/sebastianbergmann/code-unit/tree/3.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:44:28+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "183a9b2632194febd219bb9246eee421dad8d45e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/183a9b2632194febd219bb9246eee421dad8d45e", + "reference": "183a9b2632194febd219bb9246eee421dad8d45e", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "security": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/security/policy", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:45:54+00:00" + }, + { + "name": "sebastian/comparator", + "version": "6.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "450d8f237bd611c45b5acf0733ce43e6bb280f81" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/450d8f237bd611c45b5acf0733ce43e6bb280f81", + "reference": "450d8f237bd611c45b5acf0733ce43e6bb280f81", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-mbstring": "*", + "php": ">=8.2", + "sebastian/diff": "^6.0", + "sebastian/exporter": "^6.0" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "security": "https://github.com/sebastianbergmann/comparator/security/policy", + "source": "https://github.com/sebastianbergmann/comparator/tree/6.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-08-12T06:07:25+00:00" + }, + { + "name": "sebastian/complexity", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/complexity.git", + "reference": "ee41d384ab1906c68852636b6de493846e13e5a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/ee41d384ab1906c68852636b6de493846e13e5a0", + "reference": "ee41d384ab1906c68852636b6de493846e13e5a0", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^5.0", + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for calculating the complexity of PHP code units", + "homepage": "https://github.com/sebastianbergmann/complexity", + "support": { + "issues": "https://github.com/sebastianbergmann/complexity/issues", + "security": "https://github.com/sebastianbergmann/complexity/security/policy", + "source": "https://github.com/sebastianbergmann/complexity/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:49:50+00:00" + }, + { + "name": "sebastian/diff", + "version": "6.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "b4ccd857127db5d41a5b676f24b51371d76d8544" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/b4ccd857127db5d41a5b676f24b51371d76d8544", + "reference": "b4ccd857127db5d41a5b676f24b51371d76d8544", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0", + "symfony/process": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "security": "https://github.com/sebastianbergmann/diff/security/policy", + "source": "https://github.com/sebastianbergmann/diff/tree/6.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:53:05+00:00" + }, + { + "name": "sebastian/environment", + "version": "7.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "855f3ae0ab316bbafe1ba4e16e9f3c078d24a0c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/855f3ae0ab316bbafe1ba4e16e9f3c078d24a0c5", + "reference": "855f3ae0ab316bbafe1ba4e16e9f3c078d24a0c5", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "suggest": { + "ext-posix": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "7.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "https://github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "security": "https://github.com/sebastianbergmann/environment/security/policy", + "source": "https://github.com/sebastianbergmann/environment/tree/7.2.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:54:44+00:00" + }, + { + "name": "sebastian/exporter", + "version": "6.1.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e", + "reference": "c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=8.2", + "sebastian/recursion-context": "^6.0" + }, + "require-dev": { + "phpunit/phpunit": "^11.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "https://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "security": "https://github.com/sebastianbergmann/exporter/security/policy", + "source": "https://github.com/sebastianbergmann/exporter/tree/6.1.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:56:19+00:00" + }, + { + "name": "sebastian/global-state", + "version": "7.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "3be331570a721f9a4b5917f4209773de17f747d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/3be331570a721f9a4b5917f4209773de17f747d7", + "reference": "3be331570a721f9a4b5917f4209773de17f747d7", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "sebastian/object-reflector": "^4.0", + "sebastian/recursion-context": "^6.0" + }, + "require-dev": { + "ext-dom": "*", + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "7.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "https://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "security": "https://github.com/sebastianbergmann/global-state/security/policy", + "source": "https://github.com/sebastianbergmann/global-state/tree/7.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:57:36+00:00" + }, + { + "name": "sebastian/lines-of-code", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/lines-of-code.git", + "reference": "d36ad0d782e5756913e42ad87cb2890f4ffe467a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/d36ad0d782e5756913e42ad87cb2890f4ffe467a", + "reference": "d36ad0d782e5756913e42ad87cb2890f4ffe467a", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^5.0", + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for counting the lines of code in PHP source code", + "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "support": { + "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", + "security": "https://github.com/sebastianbergmann/lines-of-code/security/policy", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/3.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:58:38+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "6.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "f5b498e631a74204185071eb41f33f38d64608aa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/f5b498e631a74204185071eb41f33f38d64608aa", + "reference": "f5b498e631a74204185071eb41f33f38d64608aa", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "sebastian/object-reflector": "^4.0", + "sebastian/recursion-context": "^6.0" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "security": "https://github.com/sebastianbergmann/object-enumerator/security/policy", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/6.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:00:13+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "6e1a43b411b2ad34146dee7524cb13a068bb35f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/6e1a43b411b2ad34146dee7524cb13a068bb35f9", + "reference": "6e1a43b411b2ad34146dee7524cb13a068bb35f9", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "security": "https://github.com/sebastianbergmann/object-reflector/security/policy", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:01:32+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "6.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "694d156164372abbd149a4b85ccda2e4670c0e16" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/694d156164372abbd149a4b85ccda2e4670c0e16", + "reference": "694d156164372abbd149a4b85ccda2e4670c0e16", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "https://github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "security": "https://github.com/sebastianbergmann/recursion-context/security/policy", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/6.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:10:34+00:00" + }, + { + "name": "sebastian/type", + "version": "5.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "fb6a6566f9589e86661291d13eba708cce5eb4aa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/fb6a6566f9589e86661291d13eba708cce5eb4aa", + "reference": "fb6a6566f9589e86661291d13eba708cce5eb4aa", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "security": "https://github.com/sebastianbergmann/type/security/policy", + "source": "https://github.com/sebastianbergmann/type/tree/5.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:11:49+00:00" + }, + { + "name": "sebastian/version", + "version": "5.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "45c9debb7d039ce9b97de2f749c2cf5832a06ac4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/45c9debb7d039ce9b97de2f749c2cf5832a06ac4", + "reference": "45c9debb7d039ce9b97de2f749c2cf5832a06ac4", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "security": "https://github.com/sebastianbergmann/version/security/policy", + "source": "https://github.com/sebastianbergmann/version/tree/5.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:13:08+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.2.3", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/1.2.3" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:36:25+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], @@ -14,5 +1647,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/inc/field.php b/inc/field.php index 19052516..0c5140b6 100644 --- a/inc/field.php +++ b/inc/field.php @@ -317,6 +317,7 @@ public static function normalize( $field ) { 'attributes' => [], 'sanitize_callback' => null, + 'register_meta' => false, ] ); // Store the original ID to run correct filters for the clonable field. @@ -575,4 +576,106 @@ public static function filter() { return $value; } + + public static function register_meta( array $field, array $meta_box, string $post_type ): void { + // Bail early if the field is implicitly not registered as meta. + if ( ! $field['register_meta'] ) { + return; + } + + // Bail if the meta box storage is custom table. + if ( ! isset( $field['storage'] ) || ! $field['storage'] instanceof RWMB_Post_Storage ) { + return; + } + + $revisions_enabled = $meta_box['revision'] ?? false; + + $args = [ + 'object_subtype' => $post_type, + 'type' => 'string', + 'description' => $field['desc'] ?: $field['label_description'], + 'single' => ! $field['multiple'], + 'default' => '', + 'show_in_rest' => true, + 'revisions_enabled' => $revisions_enabled, + ]; + + $args = array_merge( $args, self::get_register_meta_args( $field ) ); + + if ( $args['type'] === 'null' ) { + return; + } + + register_meta( 'post', $field['id'], $args ); + } + + private static function get_register_meta_args( array $field ): array { + // If the schema is explicitly defined, use it. + if ( is_array( $field['register_meta'] ) ) { + return $field['register_meta']; + } + + $schema = self::call( 'get_full_schema', $field ); + + $args['type'] = $schema['type']; + $args['default'] = self::get_validated_default_value( $field, $schema['type'] ); + + if ( in_array ( $schema['type'], [ 'array', 'object' ] ) ) { + $args['show_in_rest'] = [ + 'schema' => $schema + ]; + } + + return $args; + } + + protected static function get_full_schema( array $field ): array { + $schema = self::call( 'get_schema', $field ); + + if ( $field['clone'] ) { + $schema = [ + 'type' => 'array', + 'items' => $schema, + ]; + } + + return $schema; + } + + private static function get_validated_default_value( array $field, string $return_type ) { + $default = $field['std'] ?? ''; + + if ( 'array' === $return_type && ! is_array( $default ) ) { + return []; + } + + if ( 'boolean' === $return_type && ! is_bool( $default ) ) { + $default = false; + } + + if ( 'integer' === $return_type && ! is_int( $default ) ) { + $default = 0; + } + + if ( 'number' === $return_type && ! is_float( $default ) ) { + $default = 0.0; + } + + if ( 'object' === $return_type && ! is_object( $default ) ) { + $default = new stdClass(); + } + + return $default; + } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + return [ 'type' => 'string' ]; + } } diff --git a/inc/fields/background.php b/inc/fields/background.php index 4b622cc1..0cf545b6 100644 --- a/inc/fields/background.php +++ b/inc/fields/background.php @@ -155,4 +155,25 @@ public static function format_single_value( $field, $value, $args, $post_id ) { } return $output; } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + return [ + 'type' => 'object', + 'properties' => [ + 'color' => [ 'type' => 'string' ], + 'image' => [ 'type' => 'string' ], + 'repeat' => [ 'type' => 'string' ], + 'attachment' => [ 'type' => 'string' ], + 'position' => [ 'type' => 'string' ], + 'size' => [ 'type' => 'string' ], + ], + ]; + } } diff --git a/inc/fields/button.php b/inc/fields/button.php index 63d35854..3fc6fa4e 100644 --- a/inc/fields/button.php +++ b/inc/fields/button.php @@ -47,4 +47,17 @@ public static function get_attributes( $field, $value = null ) { return $attributes; } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + return [ + 'type' => 'null', + ]; + } } diff --git a/inc/fields/checkbox.php b/inc/fields/checkbox.php index 0997aa75..6adefcae 100644 --- a/inc/fields/checkbox.php +++ b/inc/fields/checkbox.php @@ -42,4 +42,17 @@ protected static function input_description( array $field ) : string { public static function format_single_value( $field, $value, $args, $post_id ) { return $value ? __( 'Yes', 'meta-box' ) : __( 'No', 'meta-box' ); } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + return [ + 'type' => 'integer', + ]; + } } diff --git a/inc/fields/choice.php b/inc/fields/choice.php index affb313e..def17a13 100644 --- a/inc/fields/choice.php +++ b/inc/fields/choice.php @@ -66,4 +66,22 @@ public static function format_single_value( $field, $value, $args, $post_id ) { $options = self::transform_options( $field['options'] ); return isset( $options[ $value ] ) ? $options[ $value ]->label : ''; } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + if ( $field['multiple'] ) { + return [ + 'type' => 'array', + 'items' => [ 'type' => 'string' ], + ]; + } + + return [ 'type' => 'string' ]; + } } diff --git a/inc/fields/custom-html.php b/inc/fields/custom-html.php index ad39844a..5be30f95 100644 --- a/inc/fields/custom-html.php +++ b/inc/fields/custom-html.php @@ -20,4 +20,16 @@ public static function html( $meta, $field ) { } return $html; } + + /** + * Get the schema for the field. + * + * @param array $field + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + return [ + 'type' => 'null', + ]; + } } diff --git a/inc/fields/divider.php b/inc/fields/divider.php index e382099d..c391e0cd 100644 --- a/inc/fields/divider.php +++ b/inc/fields/divider.php @@ -18,4 +18,17 @@ protected static function begin_html( array $field ) : string { public static function end_html( array $field ) : string { return ''; } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + return [ + 'type' => 'null', + ]; + } } diff --git a/inc/fields/fieldset-text.php b/inc/fields/fieldset-text.php index 69ab12a0..6f954210 100644 --- a/inc/fields/fieldset-text.php +++ b/inc/fields/fieldset-text.php @@ -102,4 +102,24 @@ public static function format_single_value( $field, $value, $args, $post_id ) { $output .= ''; return $output; } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + $properties = []; + + foreach ( $field['options'] as $key => $label ) { + $properties[ $key ] = [ 'type' => 'string' ]; + } + + return [ + 'type' => 'object', + 'properties' => $properties + ]; + } } diff --git a/inc/fields/file.php b/inc/fields/file.php index daa3628b..fa3b397a 100644 --- a/inc/fields/file.php +++ b/inc/fields/file.php @@ -446,7 +446,7 @@ public static function format_single_value( $field, $value, $args, $post_id ) { * @param string $file_id File ID in $_FILES when uploading. * @param array $field Field settings. * - * @return string URL to uploaded file. + * @return string|void URL to uploaded file. */ public static function handle_upload_custom_dir( $file_id, $field ) { // @codingStandardsIgnoreStart @@ -492,4 +492,18 @@ public static function convert_path_to_url( string $path ) : string { return home_url( $relative_path ); } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + return [ + 'type' => 'array', + 'items' => [ 'type' => 'integer' ], + ]; + } } diff --git a/inc/fields/heading.php b/inc/fields/heading.php index ea7eb3a6..7725ed25 100644 --- a/inc/fields/heading.php +++ b/inc/fields/heading.php @@ -18,4 +18,17 @@ protected static function begin_html( array $field ) : string { protected static function end_html( array $field ) : string { return self::input_description( $field ); } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + return [ + 'type' => 'null', + ]; + } } diff --git a/inc/fields/input.php b/inc/fields/input.php index eb3925d5..963f9695 100644 --- a/inc/fields/input.php +++ b/inc/fields/input.php @@ -109,4 +109,16 @@ protected static function datalist( array $field ) : string { $html .= ''; return $html; } + + /** + * Get the schema for the field. + * + * @param array $field + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + return [ + 'type' => 'string', + ]; + } } diff --git a/inc/fields/media.php b/inc/fields/media.php index 9f354204..5bc81e7e 100644 --- a/inc/fields/media.php +++ b/inc/fields/media.php @@ -212,4 +212,22 @@ public static function save( $new, $old, $post_id, $field ) { public static function print_templates() { require RWMB_INC_DIR . 'templates/media.php'; } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + if ( $field['multiple'] ) { + return [ + 'type' => 'array', + 'items' => [ 'type' => 'integer' ] + ]; + } + + return [ 'type' => 'integer' ]; + } } diff --git a/inc/fields/multiple-values.php b/inc/fields/multiple-values.php index 4307ea7a..ce865321 100644 --- a/inc/fields/multiple-values.php +++ b/inc/fields/multiple-values.php @@ -42,4 +42,20 @@ public static function normalize( $field ) { public static function format_single_value( $field, $value, $args, $post_id ) { return $field['options'][ $value ]; } + + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + * + * @return array + */ + protected static function get_schema( array $field ): array { + return [ + 'type' => 'array', + 'items' => [ + 'type' => 'string', + ], + ]; + } } diff --git a/inc/fields/number.php b/inc/fields/number.php index 7d8004af..695235ae 100644 --- a/inc/fields/number.php +++ b/inc/fields/number.php @@ -40,4 +40,15 @@ public static function get_attributes( $field, $value = null ) { ] ); return $attributes; } + + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + * + * @return array + */ + protected static function get_schema( array $field ): array { + return [ 'type' => 'number' ]; + } } diff --git a/inc/fields/post.php b/inc/fields/post.php index 665cfeba..65fafa76 100644 --- a/inc/fields/post.php +++ b/inc/fields/post.php @@ -248,4 +248,22 @@ public static function add_new_form( array $field ): string { esc_html( $post_type_object->labels->add_new_item ) ); } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + if ( $field['multiple'] ) { + return [ + 'type' => 'array', + 'items' => [ 'type' => 'integer' ], + ]; + } + + return [ 'type' => 'integer' ]; + } } diff --git a/inc/fields/range.php b/inc/fields/range.php index ecf526c5..368c5f07 100644 --- a/inc/fields/range.php +++ b/inc/fields/range.php @@ -66,4 +66,15 @@ public static function value( $new, $old, $post_id, $field ) { } return $new; } + + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + * + * @return array + */ + protected static function get_schema( array $field ): array { + return [ 'type' => 'number' ]; + } } diff --git a/inc/fields/slider.php b/inc/fields/slider.php index 42c4eacf..9a5570c9 100644 --- a/inc/fields/slider.php +++ b/inc/fields/slider.php @@ -69,4 +69,15 @@ public static function normalize( $field ) { return $field; } + + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + * + * @return array + */ + protected static function get_schema( array $field ): array { + return [ 'type' => 'number' ]; + } } diff --git a/inc/fields/switch.php b/inc/fields/switch.php index 80c06307..2e84fea6 100644 --- a/inc/fields/switch.php +++ b/inc/fields/switch.php @@ -85,4 +85,15 @@ public static function format_single_value( $field, $value, $args, $post_id ) { $off = $field['off_label'] ?: __( 'Off', 'meta-box' ); return $value ? $on : $off; } + + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + * + * @return array + */ + protected static function get_schema( array $field ): array { + return [ 'type' => 'integer' ]; + } } diff --git a/inc/fields/taxonomy-advanced.php b/inc/fields/taxonomy-advanced.php index 8f6bb6d0..655e9e7a 100644 --- a/inc/fields/taxonomy-advanced.php +++ b/inc/fields/taxonomy-advanced.php @@ -102,4 +102,19 @@ public static function terms_info( $field, $term_ids, $args ) { $info = is_array( $info ) ? $info : []; return $field['multiple'] ? $info : reset( $info ); } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + if ( $field['multiple'] ) { + return [ 'type' => 'string' ]; + } + + return [ 'type' => 'integer' ]; + } } diff --git a/inc/fields/taxonomy.php b/inc/fields/taxonomy.php index 382c0397..eaf06e57 100644 --- a/inc/fields/taxonomy.php +++ b/inc/fields/taxonomy.php @@ -323,4 +323,15 @@ protected static function get_taxonomy_singular_name( array $field ): string { return false === $taxonomy_object ? '' : $taxonomy_object->labels->singular_name; } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + return [ 'type' => 'integer' ]; + } } diff --git a/inc/fields/user.php b/inc/fields/user.php index f440bbfe..20875c40 100644 --- a/inc/fields/user.php +++ b/inc/fields/user.php @@ -189,4 +189,22 @@ public static function add_new_form( array $field ): string { esc_html__( 'Add New User', 'meta-box' ) ); } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + if ( $field['multiple'] ) { + return [ + 'type' => 'array', + 'items' => [ 'type' => 'integer' ], + ]; + } + + return [ 'type' => 'integer' ]; + } } diff --git a/inc/meta-box.php b/inc/meta-box.php index bb241143..a551fc4e 100644 --- a/inc/meta-box.php +++ b/inc/meta-box.php @@ -66,6 +66,8 @@ public function register_fields() { foreach ( $this->post_types as $post_type ) { foreach ( $this->fields as $field ) { $field_registry->add( $field, $post_type ); + + RWMB_Field::call( 'register_meta', $field, $this->meta_box, $post_type ); } } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..a4a16bf8 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,8 @@ + + + + + ./tests/phpunit + + + diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..8c558931 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,50 @@ + 'test-register-meta', + 'title' => 'Test Register Meta', + 'revision' => true, + 'fields' => [ + // RegisterMetaTest::testFieldNotRegisteredByDefault() + [ + 'name' => 'rmt_simple_text', + 'desc' => 'Basic text field', + 'id' => 'rmt_simple_text', + 'type' => 'text', + 'std' => 'Simple Text Default', + ], + // RegisterMetaTest::testRegisteredField() + [ + 'name' => 'rmt_text_register_meta', + 'desc' => 'Text No Register Meta Description', + 'id' => 'rmt_text_register_meta', + 'type' => 'text', + 'register_meta' => true + ], + // RegisterMetaTest::testOverrideArgs() + [ + 'id' => 'rmt_text_override', + 'type' => 'text', + 'name' => 'rmt_text_override', + 'register_meta' => [ + 'description' => 'This is an overridden description', + 'revisions_enabled' => false, // Should override value from meta box + 'single' => true, + 'show_in_rest' => false, + 'default' => 'This is a default value', + 'type' => 'string', + ], + ], + ], +]; + +$mb = new RW_Meta_Box($meta_boxes); +$mb->register_fields(); \ No newline at end of file diff --git a/tests/phpunit/FieldReturnTypeTest.php b/tests/phpunit/FieldReturnTypeTest.php new file mode 100644 index 00000000..414e0b06 --- /dev/null +++ b/tests/phpunit/FieldReturnTypeTest.php @@ -0,0 +1,142 @@ + 'array', + 'background' => 'object', // All fields that return key-value pairs should return an object + 'button' => 'null', + 'button_group' => 'string', + 'checkbox_list' => 'array', + 'checkbox' => 'integer', + 'color' => 'string', + 'custom_html' => 'null', + 'date' => 'string', + 'datetime' => 'string', + 'divider' => 'null', + 'file_advanced' => 'array', + 'file_input' => 'string', + 'file_upload' => 'array', + 'file' => 'array', + 'icon' => 'string', + 'image_advanced' => 'array', + 'image_select' => 'string', + 'image_upload' => 'array', + 'image' => 'array', + 'key_value' => 'string', + 'map' => 'string', + 'oembed' => 'string', + 'osm' => 'string', + 'post' => 'integer', + 'radio' => 'string', + 'range' => 'number', + 'select_advanced' => 'string', + 'select' => 'string', + 'sidebar' => 'string', + 'single_image' => 'integer', + 'switch' => 'integer', + 'taxonomy' => 'integer', + 'text_list' => 'array', + 'textarea' => 'string', + 'user' => 'integer', + 'video' => 'array', + 'wysiwyg' => 'string', + ]; + + private function setupField( $field_id, $props = [] ) { + $field = [ + 'id' => $field_id, + 'type' => $field_id, + ...$props, + ]; + + $field = RWMB_Field::call( 'normalize', $field ); + + return $field; + } + + public function testfieldShouldMatchReturnType() { + foreach ( $this->field_return_types as $field_id => $expected_return_type ) { + $field = $this->setupField( $field_id ); + $schema = RWMB_Field::call( 'get_schema', $field ); + $type = $schema['type'] ?? 'null'; + + $this->assertEquals( $expected_return_type, $type, "Field $field_id should return $expected_return_type" ); + } + } + + public function testCloneFieldShouldReturnArray() { + foreach ( $this->field_return_types as $field_id => $single_return_type ) { + $field = $this->setupField( $field_id, [ 'clone' => true ] ); + + $schema = RWMB_Field::call( 'get_full_schema', $field ); + + if ( ! $schema || ! isset( $schema['type'] ) ) { + continue; + } + + // Some fields don't have a clone property + if ( ! $field['clone'] ) { + continue; + } + + $type = $schema['type']; + + $this->assertEquals( 'array', $type, "Field $field_id should return array" ); + $this->assertEquals( $single_return_type, $schema['items']['type'], "Item in field $field_id should return $single_return_type" ); + } + } + + public function testGroupFieldShouldReturnObject() { + $field = $this->setupField( 'group', [ 'fields' => [ + $this->setupField( 'text' ), + $this->setupField( 'textarea' ), + ] ] ); + + $schema = RWMB_Field::call( 'get_full_schema', $field ); + + $this->assertEquals( 'object', $schema['type'], 'Group field should return object' ); + } + + public function testCloneableGroupShouldReturnArrayObject() { + $field = $this->setupField( 'group', [ 'fields' => [ + $this->setupField( 'text' ), + $this->setupField( 'textarea' ), + ], 'clone' => true ] ); + + $schema = RWMB_Field::call( 'get_full_schema', $field ); + + $this->assertEquals( 'array', $schema['type'], 'Cloneable group field should return array' ); + $this->assertEquals( 'object', $schema['items']['type'], 'Cloneable group field should return object' ); + } + + public function testFieldsetTextShouldReturnObject() { + $field = $this->setupField( 'fieldset_text', [ 'options' => [ 'name' => 'Name', 'email' => 'Email' ] ] ); + $schema = RWMB_Field::call( 'get_full_schema', $field ); + + $this->assertEquals( 'object', $schema['type'], 'Fieldset text field should return object' ); + $this->assertArrayHasKey('properties', $schema, 'Fieldset text field should have properties' ); + $this->assertArrayHasKey('name', $schema['properties'], 'Fieldset text field should have name property' ); + $this->assertArrayHasKey('email', $schema['properties'], 'Fieldset text field should have email property' ); + $this->assertEquals('string', $schema['properties']['name']['type'], 'Fieldset text field name property should return string' ); + $this->assertEquals('string', $schema['properties']['email']['type'], 'Fieldset text field email property should return string' ); + } + + public function testTaxonomyAdvancedField() { + $field_single = $this->setupField( 'taxonomy_advanced', [ 'taxonomy' => 'category' ] ); + $schema = RWMB_Field::call( 'get_full_schema', $field_single ); + + $this->assertEquals( 'integer', $schema['type'], 'Single taxonomy advanced should return integer' ); + + $field_multiple = $this->setupField( 'taxonomy_advanced_multiple', [ 'taxonomy' => 'category', 'multiple' => true ] ); + $schema_multiple = RWMB_Field::call( 'get_full_schema', $field_multiple ); + + $this->assertEquals( 'string', $schema_multiple['type'], 'Multiple taxonomy advanced should return CSV' ); + } +} \ No newline at end of file diff --git a/tests/phpunit/RegisterMetaTest.php b/tests/phpunit/RegisterMetaTest.php new file mode 100644 index 00000000..b8375557 --- /dev/null +++ b/tests/phpunit/RegisterMetaTest.php @@ -0,0 +1,92 @@ +meta = get_registered_meta_keys( 'post', 'post' ); + } + + public function testFieldNotRegisteredByDefault() { + $this->assertArrayNotHasKey( 'rmt_simple_text', $this->meta ); + } + + public function testRegisteredField() { + $this->assertArrayHasKey( 'rmt_text_register_meta', $this->meta ); + } + + /** + * If we set 'register_meta' to array, it should be merged with the default args + */ + public function testOverrideArgs() { + $this->assertArrayIsEqualToArrayIgnoringListOfKeys( $this->meta['rmt_text_override'], [ + 'description' => 'This is an overridden description', + 'revisions_enabled' => false, + 'single' => true, + 'show_in_rest' => false, + 'default' => 'This is a default value', + 'type' => 'string', + ], [ + 'sanitize_callback', + 'auth_callback', + ] ); + } + + /** + * 1. Revision should be set to inherit from the meta box (false) by default + * 2. If field['register_meta']['revisions_enabled'] is set, it should be used + */ + public function testRevisionArgument() { + // This inherits from the meta box + $this->assertEquals( true, $this->meta['rmt_text_register_meta']['revisions_enabled'] ); + + // This is set to false + $this->assertEquals( false, $this->meta['rmt_text_override']['revisions_enabled'] ); + } + + /** + * 1. $args['single'] should be inversion of $field['multiple'] + * 2. If $field['register_meta']['multiple'] is set, it should be used + */ + public function testSingleArgument() { + $this->assertEquals( true, $this->meta['rmt_text_register_meta']['single'] ); + } + + /** + * 1. By default, show_in_rest should be set to true + * 2. If $field['register_meta']['show_in_rest'] is set, it should be used + */ + public function testShowInRestArgument() { + $this->assertEquals( true, $this->meta['rmt_text_register_meta']['show_in_rest'] ); + + $this->assertEquals( false, $this->meta['rmt_text_override']['show_in_rest'] ); + } + + /** + * !IMPORTANT: Need more discussion about this + * + * It's ideal and possible to use rwmb_the_value() to get the value of the field for the schema so it matches the prepared value, + * match with MB Rest API. + * + * HOWEVER, we should not use rwmb_the_value() to get the value of the field because WP uses get_post_meta() to get the value + * and it doesn't have any filter to alter with rwmb_the_value() + * + * Although, we can use get_{$meta_type}_metadata filter to alter the value, it's still dangerous + * + * The same applies to "update_{$meta_type}_metadata", we define schema is an array but the POST value should be a string|number|boolean + * Need to test if possible to skip the schema validation on POST request + * + * Ref: function _block_bindings_post_meta_get_value( array $source_args, $block_instance ) { + * Ref: get_{$meta_type}_metadata + * Ref: update_{$meta_type}_metadata + * @return void + */ + public function testValidSchema() { + //$check = rest_validate_value_from_schema( $args['default'], $schema ); + + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} \ No newline at end of file