diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ca7acc32e..9222be955 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Test +name: PHPUnit Tests env: COMPOSER_VERSION: "2" @@ -16,7 +16,6 @@ on: - develop jobs: - phpunit: name: ${{ matrix.php }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} @@ -27,30 +26,35 @@ jobs: os: [ ubuntu-latest ] steps: - - name: Checkout - uses: actions/checkout@v2.4.0 - - - name: Set standard 10up cache directories - run: | - composer config -g cache-dir "${{ env.COMPOSER_CACHE }}" - - - name: Prepare composer cache - uses: actions/cache@v2 - with: - path: ${{ env.COMPOSER_CACHE }} - key: composer-${{ env.COMPOSER_VERSION }}-${{ hashFiles('**/composer.lock') }} - restore-keys: | - composer-${{ env.COMPOSER_VERSION }}- - - - name: Set PHP version - uses: shivammathur/setup-php@2.17.0 - with: - php-version: ${{ matrix.php }} - coverage: none - tools: phpunit-polyfills, composer:v2 - - - name: Install dependencies - run: composer update -W - - - name: PHPUnit - run: './vendor/bin/phpunit' + - name: Checkout + uses: actions/checkout@v2.4.0 + + - name: Set standard 10up cache directories + run: | + composer config -g cache-dir "${{ env.COMPOSER_CACHE }}" + + - name: Prepare composer cache + uses: actions/cache@v2 + with: + path: ${{ env.COMPOSER_CACHE }} + key: composer-${{ env.COMPOSER_VERSION }}-${{ hashFiles('**/composer.lock') }} + restore-keys: | + composer-${{ env.COMPOSER_VERSION }}- + + - uses: getong/mariadb-action@v1.1 + + - name: Set PHP version + uses: shivammathur/setup-php@2.17.0 + with: + php-version: ${{ matrix.php }} + coverage: none + tools: phpunit-polyfills, composer:v2 + + - name: Install dependencies + run: composer update -W + + - name: Setup WP Tests + run: bash tests/bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 + + - name: PHPUnit + run: composer run test diff --git a/composer.json b/composer.json index f371bd3cf..0a79bfcc8 100644 --- a/composer.json +++ b/composer.json @@ -20,12 +20,16 @@ "Distributor\\": "includes/classes/" } }, + "autoload-dev": { + "psr-4": { + "Distributor\\Tests\\": "tests/php/" + } + }, "require-dev": { "10up/phpcs-composer": "dev-master", - "10up/wp_mock": "~0.4", - "phpunit/phpunit": ">=7.0 <9.0", - "yoast/phpunit-polyfills": "^1.0", - "automattic/vipwpcs": "^2.3" + "automattic/vipwpcs": "^2.3", + "php-stubs/wordpress-tests-stubs": "^6.3", + "yoast/phpunit-polyfills": "dev-main" }, "scripts": { "lint": "@php phpcs . --runtime-set testVersion 7.4-", @@ -38,6 +42,9 @@ "allow-plugins": { "composer/installers": true, "dealerdirect/phpcodesniffer-composer-installer": true + }, + "platform": { + "php": "7.4" } } } diff --git a/composer.lock b/composer.lock index 3a19644d9..f924f0c62 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9b7761af5ca3d71ef2395537f531b6ab", + "content-hash": "0724171bbfdaecc959aaf538d1d455ab", "packages": [ { "name": "yahnis-elsts/plugin-update-checker", @@ -64,15 +64,16 @@ "source": { "type": "git", "url": "https://github.com/10up/phpcs-composer.git", - "reference": "a3b05c0dafbb4a5df8b47f845074157c096e84a6" + "reference": "4a2f47d5ed0493836ef33ee2edad32192699fad6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/10up/phpcs-composer/zipball/a3b05c0dafbb4a5df8b47f845074157c096e84a6", - "reference": "a3b05c0dafbb4a5df8b47f845074157c096e84a6", + "url": "https://api.github.com/repos/10up/phpcs-composer/zipball/4a2f47d5ed0493836ef33ee2edad32192699fad6", + "reference": "4a2f47d5ed0493836ef33ee2edad32192699fad6", "shasum": "" }, "require": { + "automattic/vipwpcs": "^2.3", "dealerdirect/phpcodesniffer-composer-installer": "*", "phpcompatibility/phpcompatibility-wp": "^2", "squizlabs/php_codesniffer": "3.7.1", @@ -86,129 +87,41 @@ ], "authors": [ { - "name": "Ephraim Gregor", - "email": "ephraim.gregor@10up.com" + "name": "10up", + "homepage": "https://10up.com/" } ], + "description": "10up's PHP CodeSniffer Ruleset", "support": { "issues": "https://github.com/10up/phpcs-composer/issues", - "source": "https://github.com/10up/phpcs-composer/tree/master" + "source": "https://github.com/10up/phpcs-composer/tree/2.0.1" }, - "time": "2022-11-03T18:34:24+00:00" - }, - { - "name": "10up/wp_mock", - "version": "0.4.2", - "source": { - "type": "git", - "url": "https://github.com/10up/wp_mock.git", - "reference": "9019226eb50df275aa86bb15bfc98a619601ee49" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/10up/wp_mock/zipball/9019226eb50df275aa86bb15bfc98a619601ee49", - "reference": "9019226eb50df275aa86bb15bfc98a619601ee49", - "shasum": "" - }, - "require": { - "antecedent/patchwork": "^2.1", - "mockery/mockery": "^1.0", - "php": ">=7.1", - "phpunit/phpunit": ">=7.0" - }, - "require-dev": { - "behat/behat": "^3.0", - "php-coveralls/php-coveralls": "^2.1", - "sebastian/comparator": ">=1.2.3" - }, - "type": "library", - "autoload": { - "psr-4": { - "WP_Mock\\": "./php/WP_Mock" - }, - "classmap": [ - "php/WP_Mock.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "GPL-2.0-or-later" - ], - "description": "A mocking library to take the pain out of unit testing for WordPress", - "time": "2019-03-16T03:44:39+00:00" - }, - { - "name": "antecedent/patchwork", - "version": "2.1.21", - "source": { - "type": "git", - "url": "https://github.com/antecedent/patchwork.git", - "reference": "25c1fa0cd9a6e6d0d13863d8df8f050b6733f16d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/antecedent/patchwork/zipball/25c1fa0cd9a6e6d0d13863d8df8f050b6733f16d", - "reference": "25c1fa0cd9a6e6d0d13863d8df8f050b6733f16d", - "shasum": "" - }, - "require": { - "php": ">=5.4.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": "http://patchwork2.org/", - "keywords": [ - "aop", - "aspect", - "interception", - "monkeypatching", - "redefinition", - "runkit", - "testing" - ], - "support": { - "issues": "https://github.com/antecedent/patchwork/issues", - "source": "https://github.com/antecedent/patchwork/tree/2.1.21" - }, - "time": "2022-02-07T07:28:34+00:00" + "time": "2023-09-14T12:16:59+00:00" }, { "name": "automattic/vipwpcs", - "version": "2.3.3", + "version": "2.3.4", "source": { "type": "git", "url": "https://github.com/Automattic/VIP-Coding-Standards.git", - "reference": "6cd0a6a82bc0ac988dbf9d6a7c2e293dc8ac640b" + "reference": "b8610e3837f49c5f2fcc4b663b6c0a7c9b3509b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Automattic/VIP-Coding-Standards/zipball/6cd0a6a82bc0ac988dbf9d6a7c2e293dc8ac640b", - "reference": "6cd0a6a82bc0ac988dbf9d6a7c2e293dc8ac640b", + "url": "https://api.github.com/repos/Automattic/VIP-Coding-Standards/zipball/b8610e3837f49c5f2fcc4b663b6c0a7c9b3509b6", + "reference": "b8610e3837f49c5f2fcc4b663b6c0a7c9b3509b6", "shasum": "" }, "require": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7", + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", "php": ">=5.4", - "sirbrillig/phpcs-variable-analysis": "^2.11.1", - "squizlabs/php_codesniffer": "^3.5.5", + "sirbrillig/phpcs-variable-analysis": "^2.11.17", + "squizlabs/php_codesniffer": "^3.7.1", "wp-coding-standards/wpcs": "^2.3" }, "require-dev": { - "php-parallel-lint/php-console-highlighter": "^0.5", - "php-parallel-lint/php-parallel-lint": "^1.0", + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", "phpcompatibility/php-compatibility": "^9", "phpcsstandards/phpcsdevtools": "^1.0", "phpunit/phpunit": "^4 || ^5 || ^6 || ^7" @@ -228,6 +141,7 @@ "keywords": [ "phpcs", "standards", + "static analysis", "wordpress" ], "support": { @@ -235,39 +149,42 @@ "source": "https://github.com/Automattic/VIP-Coding-Standards", "wiki": "https://github.com/Automattic/VIP-Coding-Standards/wiki" }, - "time": "2021-09-29T16:20:23+00:00" + "time": "2023-08-24T15:11:13+00:00" }, { "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v0.7.2", + "version": "v1.0.0", "source": { "type": "git", - "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", - "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db" + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "4be43904336affa5c2f70744a348312336afd0da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", - "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", + "reference": "4be43904336affa5c2f70744a348312336afd0da", "shasum": "" }, "require": { "composer-plugin-api": "^1.0 || ^2.0", - "php": ">=5.3", + "php": ">=5.4", "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" }, "require-dev": { "composer/composer": "*", + "ext-json": "*", + "ext-zip": "*", "php-parallel-lint/php-parallel-lint": "^1.3.1", - "phpcompatibility/php-compatibility": "^9.0" + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" }, "type": "composer-plugin", "extra": { - "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" }, "autoload": { "psr-4": { - "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -283,7 +200,7 @@ }, { "name": "Contributors", - "homepage": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer/graphs/contributors" + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" } ], "description": "PHP_CodeSniffer Standards Composer Installer Plugin", @@ -307,37 +224,37 @@ "tests" ], "support": { - "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", - "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "source": "https://github.com/PHPCSStandards/composer-installer" }, - "time": "2022-02-04T12:51:07+00:00" + "time": "2023-01-05T11:28:13+00:00" }, { "name": "doctrine/instantiator", - "version": "1.4.1", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc" + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^9", + "doctrine/coding-standard": "^9 || ^11", "ext-pdo": "*", "ext-phar": "*", "phpbench/phpbench": "^0.16 || ^1", "phpstan/phpstan": "^1.4", "phpstan/phpstan-phpunit": "^1", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.22" + "vimeo/psalm": "^4.30 || ^5.4" }, "type": "library", "autoload": { @@ -364,7 +281,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.4.1" + "source": "https://github.com/doctrine/instantiator/tree/1.5.0" }, "funding": [ { @@ -380,93 +297,101 @@ "type": "tidelift" } ], - "time": "2022-03-03T08:28:38+00:00" + "time": "2022-12-30T00:15:36+00:00" }, { - "name": "hamcrest/hamcrest-php", - "version": "v2.0.1", + "name": "myclabs/deep-copy", + "version": "1.11.1", "source": { "type": "git", - "url": "https://github.com/hamcrest/hamcrest-php.git", - "reference": "8c3d0a3f6af734494ad8f6fbbee0ba92422859f3" + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/8c3d0a3f6af734494ad8f6fbbee0ba92422859f3", - "reference": "8c3d0a3f6af734494ad8f6fbbee0ba92422859f3", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", "shasum": "" }, "require": { - "php": "^5.3|^7.0|^8.0" + "php": "^7.1 || ^8.0" }, - "replace": { - "cordoval/hamcrest-php": "*", - "davedevelopment/hamcrest-php": "*", - "kodova/hamcrest-php": "*" + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3,<3.2.2" }, "require-dev": { - "phpunit/php-file-iterator": "^1.4 || ^2.0", - "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0" + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - }, "autoload": { - "classmap": [ - "hamcrest" - ] + "files": [ + "src/DeepCopy/deep_copy.php" + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "MIT" ], - "description": "This is the PHP port of Hamcrest Matchers", + "description": "Create deep copies (clones) of your objects", "keywords": [ - "test" + "clone", + "copy", + "duplicate", + "object", + "object graph" ], "support": { - "issues": "https://github.com/hamcrest/hamcrest-php/issues", - "source": "https://github.com/hamcrest/hamcrest-php/tree/v2.0.1" + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" }, - "time": "2020-07-09T08:09:16+00:00" + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2023-03-08T13:26:56+00:00" }, { - "name": "mockery/mockery", - "version": "1.5.0", + "name": "nikic/php-parser", + "version": "v4.17.1", "source": { "type": "git", - "url": "https://github.com/mockery/mockery.git", - "reference": "c10a5f6e06fc2470ab1822fa13fa2a7380f8fbac" + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/c10a5f6e06fc2470ab1822fa13fa2a7380f8fbac", - "reference": "c10a5f6e06fc2470ab1822fa13fa2a7380f8fbac", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", "shasum": "" }, "require": { - "hamcrest/hamcrest-php": "^2.0.1", - "lib-pcre": ">=7.0", - "php": "^7.3 || ^8.0" - }, - "conflict": { - "phpunit/phpunit": "<8.0" + "ext-tokenizer": "*", + "php": ">=7.0" }, "require-dev": { - "phpunit/phpunit": "^8.5 || ^9.3" + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" }, + "bin": [ + "bin/php-parse" + ], "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4.x-dev" + "dev-master": "4.9-dev" } }, "autoload": { - "psr-0": { - "Mockery": "library/" + "psr-4": { + "PhpParser\\": "lib/PhpParser" } }, "notification-url": "https://packagist.org/downloads/", @@ -475,94 +400,19 @@ ], "authors": [ { - "name": "Pádraic Brady", - "email": "padraic.brady@gmail.com", - "homepage": "http://blog.astrumfutura.com" - }, - { - "name": "Dave Marshall", - "email": "dave.marshall@atstsolutions.co.uk", - "homepage": "http://davedevelopment.co.uk" - } - ], - "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": { - "issues": "https://github.com/mockery/mockery/issues", - "source": "https://github.com/mockery/mockery/tree/1.5.0" - }, - "time": "2022-01-20T13:18:17+00:00" - }, - { - "name": "myclabs/deep-copy", - "version": "1.11.0", - "source": { - "type": "git", - "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614", - "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614", - "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", - "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/" + "name": "Nikita Popov" } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" ], - "description": "Create deep copies (clones) of your objects", + "description": "A PHP parser written in PHP", "keywords": [ - "clone", - "copy", - "duplicate", - "object", - "object graph" + "parser", + "php" ], "support": { - "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.11.0" + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1" }, - "funding": [ - { - "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", - "type": "tidelift" - } - ], - "time": "2022-03-03T13:19:32+00:00" + "time": "2023-08-13T19:53:39+00:00" }, { "name": "phar-io/manifest", @@ -675,6 +525,46 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "php-stubs/wordpress-tests-stubs", + "version": "v6.3.0", + "source": { + "type": "git", + "url": "https://github.com/php-stubs/wordpress-tests-stubs.git", + "reference": "c603908a8e70895ba3d5b5050ed791511cabc60f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-stubs/wordpress-tests-stubs/zipball/c603908a8e70895ba3d5b5050ed791511cabc60f", + "reference": "c603908a8e70895ba3d5b5050ed791511cabc60f", + "shasum": "" + }, + "require-dev": { + "php": "~7.3 || ~8.0", + "php-stubs/generator": "^0.8.0" + }, + "suggest": { + "symfony/polyfill-php73": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress Tests function and class declaration stubs for static analysis.", + "homepage": "https://github.com/php-stubs/wordpress-tests-stubs", + "keywords": [ + "PHPStan", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/php-stubs/wordpress-tests-stubs/issues", + "source": "https://github.com/php-stubs/wordpress-tests-stubs/tree/v6.3.0" + }, + "time": "2023-08-10T16:09:20+00:00" + }, { "name": "phpcompatibility/php-compatibility", "version": "9.3.5", @@ -850,268 +740,171 @@ "time": "2022-10-24T09:00:36+00:00" }, { - "name": "phpdocumentor/reflection-common", - "version": "2.2.0", + "name": "phpunit/php-code-coverage", + "version": "9.2.28", "source": { "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b" + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/1d01c49d4ed62f25aa84a747ad35d5a16924662b", - "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef", + "reference": "7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0" + "ext-dom": "*", + "ext-libxml": "*", + "ext-xmlwriter": "*", + "nikic/php-parser": "^4.15", + "php": ">=7.3", + "phpunit/php-file-iterator": "^3.0.3", + "phpunit/php-text-template": "^2.0.2", + "sebastian/code-unit-reverse-lookup": "^2.0.2", + "sebastian/complexity": "^2.0", + "sebastian/environment": "^5.1.2", + "sebastian/lines-of-code": "^1.0.3", + "sebastian/version": "^3.0.1", + "theseer/tokenizer": "^1.2.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "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-2.x": "2.x-dev" + "dev-master": "9.2-dev" } }, "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": "src/" - } + "classmap": [ + "src/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], "authors": [ { - "name": "Jaap van Otterdijk", - "email": "opensource@ijaap.nl" + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" } ], - "description": "Common reflection classes used by phpdocumentor to reflect the code structure", - "homepage": "http://www.phpdoc.org", + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", "keywords": [ - "FQSEN", - "phpDocumentor", - "phpdoc", - "reflection", - "static analysis" + "coverage", + "testing", + "xunit" ], "support": { - "issues": "https://github.com/phpDocumentor/ReflectionCommon/issues", - "source": "https://github.com/phpDocumentor/ReflectionCommon/tree/2.x" - }, - "time": "2020-06-27T09:03:43+00:00" - }, - { - "name": "phpdocumentor/reflection-docblock", - "version": "5.3.0", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "622548b623e81ca6d78b721c5e029f4ce664f170" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/622548b623e81ca6d78b721c5e029f4ce664f170", - "reference": "622548b623e81ca6d78b721c5e029f4ce664f170", - "shasum": "" - }, - "require": { - "ext-filter": "*", - "php": "^7.2 || ^8.0", - "phpdocumentor/reflection-common": "^2.2", - "phpdocumentor/type-resolver": "^1.3", - "webmozart/assert": "^1.9.1" - }, - "require-dev": { - "mockery/mockery": "~1.3.2", - "psalm/phar": "^4.8" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.x-dev" - } - }, - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": "src" - } + "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/9.2.28" }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mike van Riel", - "email": "me@mikevanriel.com" - }, + "funding": [ { - "name": "Jaap van Otterdijk", - "email": "account@ijaap.nl" + "url": "https://github.com/sebastianbergmann", + "type": "github" } ], - "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "support": { - "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.3.0" - }, - "time": "2021-10-19T17:43:47+00:00" + "time": "2023-09-12T14:36:20+00:00" }, { - "name": "phpdocumentor/type-resolver", - "version": "1.6.1", + "name": "phpunit/php-file-iterator", + "version": "3.0.6", "source": { "type": "git", - "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "77a32518733312af16a44300404e945338981de3" + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/77a32518733312af16a44300404e945338981de3", - "reference": "77a32518733312af16a44300404e945338981de3", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpdocumentor/reflection-common": "^2.0" + "php": ">=7.3" }, "require-dev": { - "ext-tokenizer": "*", - "psalm/phar": "^4.8" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-1.x": "1.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": "src" - } + "classmap": [ + "src/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], "authors": [ { - "name": "Mike van Riel", - "email": "me@mikevanriel.com" + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" } ], - "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "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/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.1" - }, - "time": "2022-03-15T21:29:03+00:00" - }, - { - "name": "phpspec/prophecy", - "version": "v1.15.0", - "source": { - "type": "git", - "url": "https://github.com/phpspec/prophecy.git", - "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/bbcd7380b0ebf3961ee21409db7b38bc31d69a13", - "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.2", - "php": "^7.2 || ~8.0, <8.2", - "phpdocumentor/reflection-docblock": "^5.2", - "sebastian/comparator": "^3.0 || ^4.0", - "sebastian/recursion-context": "^3.0 || ^4.0" - }, - "require-dev": { - "phpspec/phpspec": "^6.0 || ^7.0", - "phpunit/phpunit": "^8.0 || ^9.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Prophecy\\": "src/Prophecy" - } + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.6" }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - }, + "funding": [ { - "name": "Marcello Duarte", - "email": "marcello.duarte@gmail.com" + "url": "https://github.com/sebastianbergmann", + "type": "github" } ], - "description": "Highly opinionated mocking framework for PHP 5.3+", - "homepage": "https://github.com/phpspec/prophecy", - "keywords": [ - "Double", - "Dummy", - "fake", - "mock", - "spy", - "stub" - ], - "support": { - "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/v1.15.0" - }, - "time": "2021-12-08T12:19:24+00:00" + "time": "2021-12-02T12:48:52+00:00" }, { - "name": "phpunit/php-code-coverage", - "version": "7.0.15", + "name": "phpunit/php-invoker", + "version": "3.1.1", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "819f92bba8b001d4363065928088de22f25a3a48" + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/819f92bba8b001d4363065928088de22f25a3a48", - "reference": "819f92bba8b001d4363065928088de22f25a3a48", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/5a10147d0aaf65b58940a0b72f71c9ac0423cc67", + "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67", "shasum": "" }, "require": { - "ext-dom": "*", - "ext-xmlwriter": "*", - "php": ">=7.2", - "phpunit/php-file-iterator": "^2.0.2", - "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^3.1.3 || ^4.0", - "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^4.2.2", - "sebastian/version": "^2.0.1", - "theseer/tokenizer": "^1.1.3" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^8.2.2" + "ext-pcntl": "*", + "phpunit/phpunit": "^9.3" }, "suggest": { - "ext-xdebug": "^2.7.2" + "ext-pcntl": "*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "7.0-dev" + "dev-master": "3.1-dev" } }, "autoload": { @@ -1130,16 +923,14 @@ "role": "lead" } ], - "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", - "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", "keywords": [ - "coverage", - "testing", - "xunit" + "process" ], "support": { - "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/7.0.15" + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/3.1.1" }, "funding": [ { @@ -1147,32 +938,32 @@ "type": "github" } ], - "time": "2021-07-26T12:20:09+00:00" + "time": "2020-09-28T05:58:55+00:00" }, { - "name": "phpunit/php-file-iterator", - "version": "2.0.5", + "name": "phpunit/php-text-template", + "version": "2.0.4", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "42c5ba5220e6904cbfe8b1a1bda7c0cfdc8c12f5" + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/42c5ba5220e6904cbfe8b1a1bda7c0cfdc8c12f5", - "reference": "42c5ba5220e6904cbfe8b1a1bda7c0cfdc8c12f5", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28", + "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^8.5" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -1191,15 +982,14 @@ "role": "lead" } ], - "description": "FilterIterator implementation that filters files based on a list of suffixes.", - "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", "keywords": [ - "filesystem", - "iterator" + "template" ], "support": { - "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/2.0.5" + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/2.0.4" }, "funding": [ { @@ -1207,26 +997,34 @@ "type": "github" } ], - "time": "2021-12-02T12:42:26+00:00" + "time": "2020-10-26T05:33:50+00:00" }, { - "name": "phpunit/php-text-template", - "version": "1.2.1", + "name": "phpunit/php-timer", + "version": "5.0.3", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2", + "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, "autoload": { "classmap": [ "src/" @@ -1243,40 +1041,83 @@ "role": "lead" } ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", "keywords": [ - "template" + "timer" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/5.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } ], - "time": "2015-06-21T13:50:34+00:00" + "time": "2020-10-26T13:16:10+00:00" }, { - "name": "phpunit/php-timer", - "version": "2.1.3", + "name": "phpunit/phpunit", + "version": "9.6.12", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "2454ae1765516d20c4ffe103d85a58a9a3bd5662" + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "a122c2ebd469b751d774aa0f613dc0d67697653f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/2454ae1765516d20c4ffe103d85a58a9a3bd5662", - "reference": "2454ae1765516d20c4ffe103d85a58a9a3bd5662", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a122c2ebd469b751d774aa0f613dc0d67697653f", + "reference": "a122c2ebd469b751d774aa0f613dc0d67697653f", "shasum": "" }, "require": { - "php": ">=7.1" + "doctrine/instantiator": "^1.3.1 || ^2", + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.10.1", + "phar-io/manifest": "^2.0.3", + "phar-io/version": "^3.0.2", + "php": ">=7.3", + "phpunit/php-code-coverage": "^9.2.28", + "phpunit/php-file-iterator": "^3.0.5", + "phpunit/php-invoker": "^3.1.1", + "phpunit/php-text-template": "^2.0.3", + "phpunit/php-timer": "^5.0.2", + "sebastian/cli-parser": "^1.0.1", + "sebastian/code-unit": "^1.0.6", + "sebastian/comparator": "^4.0.8", + "sebastian/diff": "^4.0.3", + "sebastian/environment": "^5.1.3", + "sebastian/exporter": "^4.0.5", + "sebastian/global-state": "^5.0.1", + "sebastian/object-enumerator": "^4.0.3", + "sebastian/resource-operations": "^3.0.3", + "sebastian/type": "^3.2", + "sebastian/version": "^3.0.2" }, - "require-dev": { - "phpunit/phpunit": "^8.5" + "suggest": { + "ext-soap": "To be able to generate mocks based on WSDL files", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" }, + "bin": [ + "phpunit" + ], "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1-dev" + "dev-master": "9.6-dev" } }, "autoload": { + "files": [ + "src/Framework/Assert/Functions.php" + ], "classmap": [ "src/" ] @@ -1292,48 +1133,58 @@ "role": "lead" } ], - "description": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", "keywords": [ - "timer" + "phpunit", + "testing", + "xunit" ], "support": { - "issues": "https://github.com/sebastianbergmann/php-timer/issues", - "source": "https://github.com/sebastianbergmann/php-timer/tree/2.1.3" + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "security": "https://github.com/sebastianbergmann/phpunit/security/policy", + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.12" }, "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": "2020-11-30T08:20:02+00:00" + "time": "2023-09-12T14:39:31+00:00" }, { - "name": "phpunit/php-token-stream", - "version": "4.0.4", + "name": "sebastian/cli-parser", + "version": "1.0.1", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "a853a0e183b9db7eed023d7933a858fa1c8d25a3" + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/a853a0e183b9db7eed023d7933a858fa1c8d25a3", - "reference": "a853a0e183b9db7eed023d7933a858fa1c8d25a3", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/442e7c7e687e42adc03470c7b668bc4b2402c0b2", + "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2", "shasum": "" }, "require": { - "ext-tokenizer": "*", - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-master": "1.0-dev" } }, "autoload": { @@ -1348,17 +1199,15 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" + "email": "sebastian@phpunit.de", + "role": "lead" } ], - "description": "Wrapper around PHP's tokenizer extension.", - "homepage": "https://github.com/sebastianbergmann/php-token-stream/", - "keywords": [ - "tokenizer" - ], + "description": "Library for parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", "support": { - "issues": "https://github.com/sebastianbergmann/php-token-stream/issues", - "source": "https://github.com/sebastianbergmann/php-token-stream/tree/master" + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.1" }, "funding": [ { @@ -1366,65 +1215,32 @@ "type": "github" } ], - "abandoned": true, - "time": "2020-08-04T08:28:15+00:00" + "time": "2020-09-28T06:08:49+00:00" }, { - "name": "phpunit/phpunit", - "version": "8.5.26", + "name": "sebastian/code-unit", + "version": "1.0.8", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "ef117c59fc4c54a979021b26d08a3373e386606d" + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ef117c59fc4c54a979021b26d08a3373e386606d", - "reference": "ef117c59fc4c54a979021b26d08a3373e386606d", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/1fc9f64c0927627ef78ba436c9b17d967e68e120", + "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.3.1", - "ext-dom": "*", - "ext-json": "*", - "ext-libxml": "*", - "ext-mbstring": "*", - "ext-xml": "*", - "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.10.0", - "phar-io/manifest": "^2.0.3", - "phar-io/version": "^3.0.2", - "php": ">=7.2", - "phpspec/prophecy": "^1.10.3", - "phpunit/php-code-coverage": "^7.0.12", - "phpunit/php-file-iterator": "^2.0.4", - "phpunit/php-text-template": "^1.2.1", - "phpunit/php-timer": "^2.1.2", - "sebastian/comparator": "^3.0.2", - "sebastian/diff": "^3.0.2", - "sebastian/environment": "^4.2.3", - "sebastian/exporter": "^3.1.2", - "sebastian/global-state": "^3.0.0", - "sebastian/object-enumerator": "^3.0.3", - "sebastian/resource-operations": "^2.0.1", - "sebastian/type": "^1.1.3", - "sebastian/version": "^2.0.1" + "php": ">=7.3" }, "require-dev": { - "ext-pdo": "*" - }, - "suggest": { - "ext-soap": "*", - "ext-xdebug": "*", - "phpunit/php-invoker": "^2.0.0" + "phpunit/phpunit": "^9.3" }, - "bin": [ - "phpunit" - ], "type": "library", "extra": { "branch-alias": { - "dev-master": "8.5-dev" + "dev-master": "1.0-dev" } }, "autoload": { @@ -1443,53 +1259,44 @@ "role": "lead" } ], - "description": "The PHP Unit Testing framework.", - "homepage": "https://phpunit.de/", - "keywords": [ - "phpunit", - "testing", - "xunit" - ], + "description": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", "support": { - "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/8.5.26" + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "source": "https://github.com/sebastianbergmann/code-unit/tree/1.0.8" }, "funding": [ - { - "url": "https://phpunit.de/sponsors.html", - "type": "custom" - }, { "url": "https://github.com/sebastianbergmann", "type": "github" } ], - "time": "2022-04-01T12:34:39+00:00" + "time": "2020-10-26T13:08:54+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", - "version": "1.0.2", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619" + "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/1de8cd5c010cb153fcd68b8d0f64606f523f7619", - "reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", + "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", "shasum": "" }, "require": { - "php": ">=5.6" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^8.5" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -1511,7 +1318,7 @@ "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", "support": { "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", - "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/1.0.2" + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/2.0.3" }, "funding": [ { @@ -1519,34 +1326,34 @@ "type": "github" } ], - "time": "2020-11-30T08:15:22+00:00" + "time": "2020-09-28T05:30:19+00:00" }, { "name": "sebastian/comparator", - "version": "3.0.3", + "version": "4.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "1071dfcef776a57013124ff35e1fc41ccd294758" + "reference": "fa0f136dd2334583309d32b62544682ee972b51a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1071dfcef776a57013124ff35e1fc41ccd294758", - "reference": "1071dfcef776a57013124ff35e1fc41ccd294758", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/fa0f136dd2334583309d32b62544682ee972b51a", + "reference": "fa0f136dd2334583309d32b62544682ee972b51a", "shasum": "" }, "require": { - "php": ">=7.1", - "sebastian/diff": "^3.0", - "sebastian/exporter": "^3.1" + "php": ">=7.3", + "sebastian/diff": "^4.0", + "sebastian/exporter": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^8.5" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1585,7 +1392,64 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", - "source": "https://github.com/sebastianbergmann/comparator/tree/3.0.3" + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.8" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2022-09-14T12:41:17+00:00" + }, + { + "name": "sebastian/complexity", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/complexity.git", + "reference": "739b35e53379900cc9ac327b2147867b8b6efd88" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/739b35e53379900cc9ac327b2147867b8b6efd88", + "reference": "739b35e53379900cc9ac327b2147867b8b6efd88", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.7", + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.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", + "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.2" }, "funding": [ { @@ -1593,33 +1457,33 @@ "type": "github" } ], - "time": "2020-11-30T08:04:30+00:00" + "time": "2020-10-26T15:52:27+00:00" }, { "name": "sebastian/diff", - "version": "3.0.3", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "14f72dd46eaf2f2293cbe79c93cc0bc43161a211" + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/14f72dd46eaf2f2293cbe79c93cc0bc43161a211", - "reference": "14f72dd46eaf2f2293cbe79c93cc0bc43161a211", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/74be17022044ebaaecfdf0c5cd504fc9cd5a7131", + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^7.5 || ^8.0", - "symfony/process": "^2 || ^3.3 || ^4" + "phpunit/phpunit": "^9.3", + "symfony/process": "^4.2 || ^5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1651,7 +1515,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/3.0.3" + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.5" }, "funding": [ { @@ -1659,27 +1523,27 @@ "type": "github" } ], - "time": "2020-11-30T07:59:04+00:00" + "time": "2023-05-07T05:35:17+00:00" }, { "name": "sebastian/environment", - "version": "4.2.4", + "version": "5.1.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "d47bbbad83711771f167c72d4e3f25f7fcc1f8b0" + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/d47bbbad83711771f167c72d4e3f25f7fcc1f8b0", - "reference": "d47bbbad83711771f167c72d4e3f25f7fcc1f8b0", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^7.5" + "phpunit/phpunit": "^9.3" }, "suggest": { "ext-posix": "*" @@ -1687,7 +1551,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "5.1-dev" } }, "autoload": { @@ -1714,7 +1578,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/4.2.4" + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.5" }, "funding": [ { @@ -1722,34 +1586,34 @@ "type": "github" } ], - "time": "2020-11-30T07:53:42+00:00" + "time": "2023-02-03T06:03:51+00:00" }, { "name": "sebastian/exporter", - "version": "3.1.4", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "0c32ea2e40dbf59de29f3b49bf375176ce7dd8db" + "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/0c32ea2e40dbf59de29f3b49bf375176ce7dd8db", - "reference": "0c32ea2e40dbf59de29f3b49bf375176ce7dd8db", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", + "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", "shasum": "" }, "require": { - "php": ">=7.0", - "sebastian/recursion-context": "^3.0" + "php": ">=7.3", + "sebastian/recursion-context": "^4.0" }, "require-dev": { "ext-mbstring": "*", - "phpunit/phpunit": "^8.5" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1.x-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1784,14 +1648,14 @@ } ], "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "http://www.github.com/sebastianbergmann/exporter", + "homepage": "https://www.github.com/sebastianbergmann/exporter", "keywords": [ "export", "exporter" ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/3.1.4" + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.5" }, "funding": [ { @@ -1799,30 +1663,30 @@ "type": "github" } ], - "time": "2021-11-11T13:51:24+00:00" + "time": "2022-09-14T06:03:37+00:00" }, { "name": "sebastian/global-state", - "version": "3.0.2", + "version": "5.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "de036ec91d55d2a9e0db2ba975b512cdb1c23921" + "reference": "bde739e7565280bda77be70044ac1047bc007e34" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/de036ec91d55d2a9e0db2ba975b512cdb1c23921", - "reference": "de036ec91d55d2a9e0db2ba975b512cdb1c23921", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34", + "reference": "bde739e7565280bda77be70044ac1047bc007e34", "shasum": "" }, "require": { - "php": ">=7.2", - "sebastian/object-reflector": "^1.1.1", - "sebastian/recursion-context": "^3.0" + "php": ">=7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" }, "require-dev": { "ext-dom": "*", - "phpunit/phpunit": "^8.0" + "phpunit/phpunit": "^9.3" }, "suggest": { "ext-uopz": "*" @@ -1830,7 +1694,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -1855,7 +1719,64 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/3.0.2" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.6" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-08-02T09:26:13+00:00" + }, + { + "name": "sebastian/lines-of-code", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/lines-of-code.git", + "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.6", + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.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", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.3" }, "funding": [ { @@ -1863,34 +1784,34 @@ "type": "github" } ], - "time": "2022-02-10T06:55:38+00:00" + "time": "2020-11-28T06:42:11+00:00" }, { "name": "sebastian/object-enumerator", - "version": "3.0.4", + "version": "4.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2" + "reference": "5c9eeac41b290a3712d88851518825ad78f45c71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2", - "reference": "e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71", + "reference": "5c9eeac41b290a3712d88851518825ad78f45c71", "shasum": "" }, "require": { - "php": ">=7.0", - "sebastian/object-reflector": "^1.1.1", - "sebastian/recursion-context": "^3.0" + "php": ">=7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1912,7 +1833,7 @@ "homepage": "https://github.com/sebastianbergmann/object-enumerator/", "support": { "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", - "source": "https://github.com/sebastianbergmann/object-enumerator/tree/3.0.4" + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/4.0.4" }, "funding": [ { @@ -1920,32 +1841,32 @@ "type": "github" } ], - "time": "2020-11-30T07:40:27+00:00" + "time": "2020-10-26T13:12:34+00:00" }, { "name": "sebastian/object-reflector", - "version": "1.1.2", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-reflector.git", - "reference": "9b8772b9cbd456ab45d4a598d2dd1a1bced6363d" + "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/9b8772b9cbd456ab45d4a598d2dd1a1bced6363d", - "reference": "9b8772b9cbd456ab45d4a598d2dd1a1bced6363d", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7", + "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7", "shasum": "" }, "require": { - "php": ">=7.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -1967,7 +1888,7 @@ "homepage": "https://github.com/sebastianbergmann/object-reflector/", "support": { "issues": "https://github.com/sebastianbergmann/object-reflector/issues", - "source": "https://github.com/sebastianbergmann/object-reflector/tree/1.1.2" + "source": "https://github.com/sebastianbergmann/object-reflector/tree/2.0.4" }, "funding": [ { @@ -1975,32 +1896,32 @@ "type": "github" } ], - "time": "2020-11-30T07:37:18+00:00" + "time": "2020-10-26T13:14:26+00:00" }, { "name": "sebastian/recursion-context", - "version": "3.0.1", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "367dcba38d6e1977be014dc4b22f47a484dac7fb" + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/367dcba38d6e1977be014dc4b22f47a484dac7fb", - "reference": "367dcba38d6e1977be014dc4b22f47a484dac7fb", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", "shasum": "" }, "require": { - "php": ">=7.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -2027,10 +1948,10 @@ } ], "description": "Provides functionality to recursively process PHP variables", - "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "homepage": "https://github.com/sebastianbergmann/recursion-context", "support": { "issues": "https://github.com/sebastianbergmann/recursion-context/issues", - "source": "https://github.com/sebastianbergmann/recursion-context/tree/3.0.1" + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.5" }, "funding": [ { @@ -2038,29 +1959,32 @@ "type": "github" } ], - "time": "2020-11-30T07:34:24+00:00" + "time": "2023-02-03T06:07:39+00:00" }, { "name": "sebastian/resource-operations", - "version": "2.0.2", + "version": "3.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "31d35ca87926450c44eae7e2611d45a7a65ea8b3" + "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/31d35ca87926450c44eae7e2611d45a7a65ea8b3", - "reference": "31d35ca87926450c44eae7e2611d45a7a65ea8b3", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", + "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -2082,7 +2006,7 @@ "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "support": { "issues": "https://github.com/sebastianbergmann/resource-operations/issues", - "source": "https://github.com/sebastianbergmann/resource-operations/tree/2.0.2" + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.3" }, "funding": [ { @@ -2090,32 +2014,32 @@ "type": "github" } ], - "time": "2020-11-30T07:30:19+00:00" + "time": "2020-09-28T06:45:17+00:00" }, { "name": "sebastian/type", - "version": "1.1.4", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "0150cfbc4495ed2df3872fb31b26781e4e077eb4" + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/0150cfbc4495ed2df3872fb31b26781e4e077eb4", - "reference": "0150cfbc4495ed2df3872fb31b26781e4e077eb4", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", "shasum": "" }, "require": { - "php": ">=7.2" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^8.2" + "phpunit/phpunit": "^9.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1-dev" + "dev-master": "3.2-dev" } }, "autoload": { @@ -2138,7 +2062,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/1.1.4" + "source": "https://github.com/sebastianbergmann/type/tree/3.2.1" }, "funding": [ { @@ -2146,29 +2070,29 @@ "type": "github" } ], - "time": "2020-11-30T07:25:11+00:00" + "time": "2023-02-03T06:13:03+00:00" }, { "name": "sebastian/version", - "version": "2.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + "reference": "c6c1022351a901512170118436c764e473f6de8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c", + "reference": "c6c1022351a901512170118436c764e473f6de8c", "shasum": "" }, "require": { - "php": ">=5.6" + "php": ">=7.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -2189,32 +2113,43 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-10-03T07:35:21+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/3.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T06:39:44+00:00" }, { "name": "sirbrillig/phpcs-variable-analysis", - "version": "v2.11.3", + "version": "v2.11.17", "source": { "type": "git", "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", - "reference": "c921498b474212fe4552928bbeb68d70250ce5e8" + "reference": "3b71162a6bf0cde2bff1752e40a1788d8273d049" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/c921498b474212fe4552928bbeb68d70250ce5e8", - "reference": "c921498b474212fe4552928bbeb68d70250ce5e8", + "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/3b71162a6bf0cde2bff1752e40a1788d8273d049", + "reference": "3b71162a6bf0cde2bff1752e40a1788d8273d049", "shasum": "" }, "require": { "php": ">=5.4.0", - "squizlabs/php_codesniffer": "^3.5" + "squizlabs/php_codesniffer": "^3.5.6" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", - "limedeck/phpunit-detailed-printer": "^3.1 || ^4.0 || ^5.0", - "phpstan/phpstan": "^0.11.8", - "phpunit/phpunit": "^5.0 || ^6.5 || ^7.0 || ^8.0", - "sirbrillig/phpcs-import-detection": "^1.1" + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", + "phpcsstandards/phpcsdevcs": "^1.1", + "phpstan/phpstan": "^1.7", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.5 || ^7.0 || ^8.0 || ^9.0", + "sirbrillig/phpcs-import-detection": "^1.1", + "vimeo/psalm": "^0.2 || ^0.3 || ^1.1 || ^4.24 || ^5.0@beta" }, "type": "phpcodesniffer-standard", "autoload": { @@ -2237,12 +2172,16 @@ } ], "description": "A PHPCS sniff to detect problems with variables.", + "keywords": [ + "phpcs", + "static analysis" + ], "support": { "issues": "https://github.com/sirbrillig/phpcs-variable-analysis/issues", "source": "https://github.com/sirbrillig/phpcs-variable-analysis", "wiki": "https://github.com/sirbrillig/phpcs-variable-analysis/wiki" }, - "time": "2022-02-21T17:01:13+00:00" + "time": "2023-08-05T23:46:11+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -2350,64 +2289,6 @@ ], "time": "2021-07-28T10:34:58+00:00" }, - { - "name": "webmozart/assert", - "version": "1.11.0", - "source": { - "type": "git", - "url": "https://github.com/webmozarts/assert.git", - "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991", - "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991", - "shasum": "" - }, - "require": { - "ext-ctype": "*", - "php": "^7.2 || ^8.0" - }, - "conflict": { - "phpstan/phpstan": "<0.12.20", - "vimeo/psalm": "<4.6.1 || 4.6.2" - }, - "require-dev": { - "phpunit/phpunit": "^8.5.13" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.10-dev" - } - }, - "autoload": { - "psr-4": { - "Webmozart\\Assert\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "Assertions to validate method input/output with nice error messages.", - "keywords": [ - "assert", - "check", - "validate" - ], - "support": { - "issues": "https://github.com/webmozarts/assert/issues", - "source": "https://github.com/webmozarts/assert/tree/1.11.0" - }, - "time": "2022-06-03T18:03:27+00:00" - }, { "name": "wp-coding-standards/wpcs", "version": "2.3.0", @@ -2461,30 +2342,29 @@ }, { "name": "yoast/phpunit-polyfills", - "version": "1.0.3", + "version": "dev-main", "source": { "type": "git", "url": "https://github.com/Yoast/PHPUnit-Polyfills.git", - "reference": "5ea3536428944955f969bc764bbe09738e151ada" + "reference": "c758753e8f9dac251fed396a73c8305af3f17922" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/5ea3536428944955f969bc764bbe09738e151ada", - "reference": "5ea3536428944955f969bc764bbe09738e151ada", + "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/c758753e8f9dac251fed396a73c8305af3f17922", + "reference": "c758753e8f9dac251fed396a73c8305af3f17922", "shasum": "" }, "require": { - "php": ">=5.4", - "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + "php": ">=5.6", + "phpunit/phpunit": "^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0" }, "require-dev": { - "yoast/yoastcs": "^2.2.0" + "yoast/yoastcs": "^2.3.0" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "1.x-dev", - "dev-develop": "1.x-dev" + "dev-main": "2.x-dev" } }, "autoload": { @@ -2518,13 +2398,14 @@ "issues": "https://github.com/Yoast/PHPUnit-Polyfills/issues", "source": "https://github.com/Yoast/PHPUnit-Polyfills" }, - "time": "2021-11-23T01:37:03+00:00" + "time": "2023-06-06T20:28:24+00:00" } ], "aliases": [], "minimum-stability": "dev", "stability-flags": { - "10up/phpcs-composer": 20 + "10up/phpcs-composer": 20, + "yoast/phpunit-polyfills": 20 }, "prefer-stable": true, "prefer-lowest": false, @@ -2533,5 +2414,8 @@ "ext-json": "*" }, "platform-dev": [], + "platform-overrides": { + "php": "7.4" + }, "plugin-api-version": "2.3.0" } diff --git a/includes/classes/Connections.php b/includes/classes/Connections.php index ec5b15a96..6ac80160e 100644 --- a/includes/classes/Connections.php +++ b/includes/classes/Connections.php @@ -52,7 +52,7 @@ public function get_registered() { * Singleton-ish class * * @since 0.8 - * @return object + * @return self */ public static function factory() { static $instance; diff --git a/includes/classes/DistributorPost.php b/includes/classes/DistributorPost.php index fef6d0c18..40044c948 100644 --- a/includes/classes/DistributorPost.php +++ b/includes/classes/DistributorPost.php @@ -27,25 +27,6 @@ * shown in IDEs. * * @since 2.0.0 - * - * @method bool has_blocks() - * @method bool has_block( string $block_name ) - * @method int get_the_ID() - * @method string get_permalink() - * @method string get_post_type() - * @method int|false get_post_thumbnail_id() - * @method string|false get_post_thumbnail_url( string $size = 'post-thumbnail' ) - * @method string|false get_the_post_thumbnail( string $size = 'post-thumbnail', array $attr = '' ) - * @method string get_canonical_url( string $canonical_url = '' ) - * @method string get_author_name( string $author_name = '' ) - * @method string get_author_link( string $author_link = '' ) - * @method array get_meta() - * @method array get_terms() - * @method array get_media() - * @method array post_data() - * @method array to_insert( array $args = [] ) - * @method array to_pull_list( array $args = [] ) - * @method array to_rest( array $args = [] ) */ class DistributorPost { /** diff --git a/includes/debug-info.php b/includes/debug-info.php index 076465f41..ff2ca4f8a 100644 --- a/includes/debug-info.php +++ b/includes/debug-info.php @@ -78,10 +78,9 @@ function enqueue_scripts( $hook ) { * @return array Filtered debug information. */ function add_debug_info( $info ) { + $text_domain = 'distributor'; - $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . DT_PLUGIN_FILE ); - $text_domain = $plugin_data['TextDomain']; - $defaults = [ + $defaults = [ 'email' => '', 'valid_license' => false, 'license_key' => '', @@ -97,7 +96,7 @@ function add_debug_info( $info ) { $fields = [ [ 'label' => __( 'Version', 'distributor' ), - 'value' => $plugin_data['Version'], + 'value' => DT_VERSION, ], ]; @@ -134,7 +133,7 @@ function add_debug_info( $info ) { ); $info[ $text_domain ] = [ - 'label' => $plugin_data['Name'], + 'label' => 'Distributor', 'fields' => $fields, ]; diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f4dd771df..53b407062 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,7 +2,13 @@ bootstrap="./tests/php/bootstrap.php" backupGlobals="false" colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" > + + + ./tests/php/ diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 000000000..8850bb63d --- /dev/null +++ b/tests/README.md @@ -0,0 +1,45 @@ +# Distributor Tests + +This document discusses unit tests. + +## Initial Setup + +### Setup instructions + +"cd" into `plugins/distributor` directory and run the following: + +1. Install [PHPUnit](http://phpunit.de/) via Composer by running: + ``` + $ composer install + ``` + +2. Install WordPress and the WP Unit Test lib using the `install.sh` script: + ``` + $ tests/bin/install-wp-tests.sh [db-host] + ``` + +You may need to quote strings with backslashes to prevent them from being processed by the shell or other programs. + +Example: + + $ tests/bin/install-wp-tests.sh distributor_tests root root + + # ditributor_tests is the database name and root is both the MySQL user and its password. + +**Important**: The `` database will be created if it doesn't exist and all data will be removed during testing. + +## Running Unit Tests + +Change to the plugin root directory and type: + + $ vendor/bin/phpunit + +The tests will execute and you'll be presented with a summary. + +You can run specific tests by providing the path and filename to the test class: + + $ vendor/bin/phpunit tests/php/ConnectionsTest.php + +A text code coverage summary can be displayed using the `--coverage-text` option: + + $ vendor/bin/phpunit --coverage-text diff --git a/tests/bin/install-wp-tests.sh b/tests/bin/install-wp-tests.sh new file mode 100755 index 000000000..14fa26978 --- /dev/null +++ b/tests/bin/install-wp-tests.sh @@ -0,0 +1,157 @@ +#!/usr/bin/env bash + +if [ $# -lt 3 ]; then + echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" + exit 1 +fi + +DB_NAME=$1 +DB_USER=$2 +DB_PASS=$3 +DB_HOST=${4-localhost} +WP_VERSION=${5-latest} +SKIP_DB_CREATE=${6-false} + +TMPDIR=${TMPDIR-/tmp} +TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") +WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} +WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} + +download() { + if [ `which curl` ]; then + curl -s "$1" > "$2"; + elif [ `which wget` ]; then + wget -nv -O "$2" "$1" + fi +} + +if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then + WP_TESTS_TAG="branches/$WP_VERSION" +elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then + if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then + # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x + WP_TESTS_TAG="tags/${WP_VERSION%??}" + else + WP_TESTS_TAG="tags/$WP_VERSION" + fi +elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then + WP_TESTS_TAG="trunk" +else + # http serves a single offer, whereas https serves multiple. we only want one + download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json + grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json + LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') + if [[ -z "$LATEST_VERSION" ]]; then + echo "Latest WordPress version could not be found" + exit 1 + fi + WP_TESTS_TAG="tags/$LATEST_VERSION" +fi + +set -ex + +install_wp() { + + if [ -d $WP_CORE_DIR ]; then + return; + fi + + mkdir -p $WP_CORE_DIR + + if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then + mkdir -p $TMPDIR/wordpress-nightly + download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip + unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/ + mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR + else + if [ $WP_VERSION == 'latest' ]; then + local ARCHIVE_NAME='latest' + elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then + # https serves multiple offers, whereas http serves single. + download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json + if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then + # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x + LATEST_VERSION=${WP_VERSION%??} + else + # otherwise, scan the releases and get the most up to date minor version of the major release + local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'` + LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1) + fi + if [[ -z "$LATEST_VERSION" ]]; then + local ARCHIVE_NAME="wordpress-$WP_VERSION" + else + local ARCHIVE_NAME="wordpress-$LATEST_VERSION" + fi + else + local ARCHIVE_NAME="wordpress-$WP_VERSION" + fi + download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz + tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR + fi + + download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php +} + +install_test_suite() { + # portable in-place argument for both GNU sed and Mac OSX sed + if [[ $(uname -s) == 'Darwin' ]]; then + local ioption='-i .bak' + else + local ioption='-i' + fi + + # set up testing suite if it doesn't yet exist + if [ ! -d $WP_TESTS_DIR ]; then + # set up testing suite + mkdir -p $WP_TESTS_DIR + svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes + svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data + fi + + if [ ! -f wp-tests-config.php ]; then + download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php + # remove all forward slashes in the end + WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") + sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php + fi + +} + +install_db() { + + if [ ${SKIP_DB_CREATE} = "true" ]; then + return 0 + fi + + # parse DB_HOST for port or socket references + local PARTS=(${DB_HOST//\:/ }) + local DB_HOSTNAME=${PARTS[0]}; + local DB_SOCK_OR_PORT=${PARTS[1]}; + local EXTRA="" + + if ! [ -z $DB_HOSTNAME ] ; then + if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then + EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" + elif ! [ -z $DB_SOCK_OR_PORT ] ; then + EXTRA=" --socket=$DB_SOCK_OR_PORT" + elif ! [ -z $DB_HOSTNAME ] ; then + EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" + fi + fi + + # create database + if [ -z $DB_PASS ] ; then + echo 'No DB password' + mysqladmin create $DB_NAME --user="$DB_USER" $EXTRA + else + mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA + fi +} + +install_wp +install_test_suite +install_db diff --git a/tests/php/ConnectionsTest.php b/tests/php/ConnectionsTest.php index c188b0576..3c28a37ee 100644 --- a/tests/php/ConnectionsTest.php +++ b/tests/php/ConnectionsTest.php @@ -1,24 +1,30 @@ register( '\TestExternalConnection' ); + public function test_register(): void { + Connections::factory()->register( TestExternalConnection::class ); - $this->assertEquals( '\TestExternalConnection', Connections::factory()->get_registered()['test-external-connection'] ); + $this->assertEquals( TestExternalConnection::class, + Connections::factory()->get_registered()['test-external-connection'] ); - Connections::factory()->register( '\TestInternalConnection', 'internal' ); + Connections::factory()->register( TestInternalConnection::class, 'internal' ); - $this->assertEquals( '\TestInternalConnection', Connections::factory()->get_registered()['test-internal-connection'] ); + $this->assertEquals( TestInternalConnection::class, + Connections::factory()->get_registered()['test-internal-connection'] ); } } diff --git a/tests/php/DebugInfoTest.php b/tests/php/DebugInfoTest.php index 98b9aa9ac..558c16c21 100644 --- a/tests/php/DebugInfoTest.php +++ b/tests/php/DebugInfoTest.php @@ -1,69 +1,18 @@ 1, - 'args' => [ \WP_Mock\Functions::type( 'string' ) ], - 'return' => [ - 'Name' => 'Distributor', - 'Version' => '1.6.0', - 'TextDomain' => 'distributor' - ], - ] - ); - - \WP_Mock::userFunction( - 'wp_parse_args', - [ - 'times' => 1, - 'args' => [ \WP_Mock\Functions::type( 'array' ), \WP_Mock\Functions::type( 'array' ) ], - 'return' => [ - 'email' => '', - 'valid_license' => false, - 'license_key' => '', - 'override_author_byline' => true, - 'media_handling' => 'featured', - ], - ] - ); - - \WP_Mock::userFunction( - 'get_option', - [ - 'times' => 1, - 'args' => [ \WP_Mock\Functions::type( 'string' ) ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'wp_json_encode', - [ - 'args' => [ [] ], - 'return' => '[false]', - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', - [ - 'args' => [ \WP_Mock\Functions::type( 'object' ), \WP_Mock\Functions::type( 'string' ), true ], - 'return' => 'none', - ] - ); - - $info = DebugInfo\add_debug_info( [] ); + /** + * @covers \Distributor\DebugInfo\add_debug_info + */ + public function test_add_debug_info(): void { + $info = \Distributor\DebugInfo\add_debug_info( [] ); $this->assertArrayHasKey( 'distributor', $info ); $this->assertArrayHasKey( 'label', $info['distributor'] ); $this->assertArrayHasKey( 'fields', $info['distributor'] ); diff --git a/tests/php/DistributorPostTest.php b/tests/php/DistributorPostTest.php index ebfd858d7..a5203e00b 100644 --- a/tests/php/DistributorPostTest.php +++ b/tests/php/DistributorPostTest.php @@ -1,132 +1,29 @@ setup_common(); - } - - public function setup_common() { - \WP_Mock::userFunction( - 'apply_filters_deprecated', - [ - 'return' => function( $name, $args ) { - return $args[0]; - }, - ] - ); - - \WP_Mock::userFunction( - 'get_current_blog_id', - [ - 'return' => 1, - ] - ); - - // Return voids. - \WP_Mock::userFunction( '_prime_post_caches' ); - \WP_Mock::userFunction( 'update_object_term_cache' ); - \WP_Mock::userFunction( 'update_postmeta_cache' ); - \WP_Mock::userFunction( 'switch_to_blog' ); - \WP_Mock::userFunction( 'restore_current_blog' ); - } - - /** - * Helper function to mock get_post. - */ - public function setup_post_mock( $post_overrides = array() ) { - $defaults = array( - 'ID' => 1, - 'post_title' => 'Test Post', - 'post_content' => 'Test Content', - 'post_excerpt' => 'Test Excerpt', - 'post_status' => 'publish', - 'post_type' => 'post', - 'post_author' => 1, - 'post_date' => '2020-01-01 00:00:00', - 'post_date_gmt' => '2020-01-01 00:00:00', - 'post_modified' => '2020-01-01 00:00:00', - 'post_modified_gmt' => '2020-01-01 00:00:00', - 'post_parent' => 0, - 'post_mime_type' => '', - 'comment_count' => 0, - 'comment_status' => 'open', - 'ping_status' => 'open', - 'guid' => 'http://example.org/?p=1', - 'menu_order' => 0, - 'pinged' => '', - 'to_ping' => '', - 'post_password' => '', - 'post_name' => 'test-post', - 'post_content_filtered' => '', - ); - - $post = array_merge( $defaults, $post_overrides ); - - \WP_Mock::userFunction( - 'get_post', - array( - 'return' => (object) $post, - ) - ); - } - - /** - * Helper function to mock get_post_meta. - */ - public function setup_post_meta_mock( $post_meta ) { - $get_post_meta = function( $post_id, $key = '', $single = false ) use ( $post_meta ) { - if ( empty( $key ) ) { - return $post_meta; - } - - if ( isset( $post_meta[ $key ] ) ) { - if ( $single ) { - return $post_meta[ $key ][0]; - } - return $post_meta[ $key ]; - } - - return ''; - }; - - \WP_Mock::userFunction( - 'get_post_meta', - array( - 'return' => $get_post_meta, - ) - ); - } - +class DistributorPostTest extends \WP_UnitTestCase { /** * Test the DistributorPost object for public methods. * * Only magic methods are expected to be public as the class uses the * __call() method to handle all other methods. * - * @covers ::__construct - * @runInSeparateProcess + * @covers \Distributor\DistributorPost::__construct */ - public function test_public_methods() { - $actual_methods = get_class_methods( 'Distributor\DistributorPost' ); + public function test_public_methods(): void { + $actual_methods = get_class_methods( DistributorPost::class ); $expected_methods = array( '__construct', '__call', @@ -142,480 +39,295 @@ public function test_public_methods() { /** * Test the DistributorPost object for internal connections. * - * @covers ::__construct - * @runInSeparateProcess - */ - public function test_internal_connection() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_blog_id' => array( '2' ), - 'dt_syndicate_time' => array ( '1670383190' ), - 'dt_original_post_url' => array ( 'http://origin.example.org/?p=10' ), - ) - ); - - \WP_Mock::userFunction( - 'get_current_blog_id', - array( - 'return' => 1, - ) + * @covers \Distributor\DistributorPost::__construct + * @dataProvider internal_connection_data_provider + */ + public function test_internal_connection( $data ): void { + $dt_post = new DistributorPost( + ( new PostGenerator() ) + ->create() + ->withMeta( array( + 'dt_original_post_id' => $data->post->ID, + 'dt_original_blog_id' => $data->blog->blog_id, + 'dt_syndicate_time' => time(), + 'dt_original_post_url' => $data->post_url, + ) ) + ->getPost() + ); + + $this->assertSame( + $data->post->ID, + $dt_post->original_post_id, + 'Origin post ID does not match expected value.' + ); + $this->assertTrue( $dt_post->is_linked, 'Origin post is not linked.' ); + $this->assertSame( + $data->post_url, + $dt_post->original_post_url, + 'Origin post URL does not match expected value.' + ); + $this->assertEquals( + $data->blog->blog_id, + $dt_post->connection_id, + 'Origin site ID does not match expected value.' + ); + $this->assertSame( + 'bidirectional', + $dt_post->connection_direction, + 'Connection direction does not match expected value.' ); - - \WP_Mock::userFunction( - 'get_bloginfo', - array( - 'return' => function( $info ) { - switch ( $info ) { - case 'charset': - return 'UTF-8'; - case 'name': - return 'Test Internal Origin'; - default: - return ''; - } - }, - ) - ); - - // Generic values for the origin site. - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://origin.example.org/?p=10', - ) + $this->assertSame( 'internal', $dt_post->connection_type, 'Connection type is incorrect.' ); + $this->assertSame( + $data->blog->home, + $dt_post->source_site['home_url'], + 'Original home_url does not match expected value.' ); - - \WP_Mock::userFunction( - 'home_url', - array( - 'return' => 'http://origin.example.org/', - ) + $this->assertSame( + $data->blog->blogname, + $dt_post->source_site['name'], + 'Original site name does not match expected value.' ); - - $dt_post = new DistributorPost( 1 ); - - $this->assertSame( 10, $dt_post->original_post_id, 'Origin post ID does not match expected value.' ); - $this->assertSame( true, $dt_post->is_linked, 'Origin post is not linked.' ); - $this->assertSame( 'http://origin.example.org/?p=10', $dt_post->original_post_url, 'Origin post URL does not match expected value.' ); - $this->assertSame( 2, $dt_post->connection_id, 'Origin site ID does not match expected value.' ); - $this->assertSame( 'bidirectional', $dt_post->connection_direction, 'Connection direction does not match expected value.' ); - $this->assertSame( 'internal', $dt_post->connection_type, 'Connection type is incorrect.' ); - $this->assertSame( 'http://origin.example.org/', $dt_post->source_site['home_url'], 'Original home_url does not match expected value.' ); - $this->assertSame( 'Test Internal Origin', $dt_post->source_site['name'], 'Original site name does not match expected value.' ); - $this->assertSame( false, $dt_post->is_source, 'Post is incorrectly marked as the source.' ); + $this->assertFalse( $dt_post->is_source, 'Post is incorrectly marked as the source.' ); } /** * Test the DistributorPost object for external, pushed posts. * - * @covers ::__construct - * @runInSeparateProcess - */ - public function test_external_connection_with_pushed_post() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pushed Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=10' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '1' ), - 'dt_original_source_id' => array( '2' ), - ) - ); - - $dt_post = new DistributorPost( 1 ); - - $this->assertSame( 10, $dt_post->original_post_id, 'Origin post ID does not match expected value.' ); - $this->assertSame( true, $dt_post->is_linked, 'Origin post is not linked.' ); - $this->assertSame( 'http://origin.example.org/?p=10', $dt_post->original_post_url, 'Origin post URL does not match expected value.' ); - $this->assertSame( 'http://origin.example.org/', $dt_post->connection_id, 'Origin connection ID does not match source URL.' ); - $this->assertSame( 'pushed', $dt_post->connection_direction, 'Connection direction does not match expected value.' ); + * @covers \Distributor\DistributorPost::__construct + * @dataProvider internal_connection_data_provider + */ + public function test_external_connection_with_pushed_post( $data ): void { + $dt_post = new DistributorPost( + ( new PostGenerator() ) + ->create() + ->withMeta( array( + 'dt_original_post_id' => $data->post->ID, + 'dt_original_site_name' => $data->blog->blogname, + 'dt_original_site_url' => $data->blog->home, + 'dt_original_post_url' => $data->post_url, + 'dt_subscription_signature' => 'abcdefghijklmnopqrstuvwxyz', + 'dt_syndicate_time' => time(), + 'dt_full_connection' => '1', + 'dt_original_source_id' => $data->blog->id, + ) ) + ->getPost() + ); + + $this->assertSame( $data->post->ID, + $dt_post->original_post_id, + 'Origin post ID does not match expected value.' ); + $this->assertTrue( $dt_post->is_linked, 'Origin post is not linked.' ); + $this->assertSame( $data->post_url, + $dt_post->original_post_url, + 'Origin post URL does not match expected value.' ); + $this->assertSame( $data->blog->home, + $dt_post->connection_id, + 'Origin connection ID does not match source URL.' ); + $this->assertSame( 'pushed', + $dt_post->connection_direction, + 'Connection direction does not match expected value.' ); $this->assertSame( 'external', $dt_post->connection_type, 'Connection type is incorrect.' ); - $this->assertSame( 'http://origin.example.org/', $dt_post->source_site['home_url'], 'Original home_url does not match expected value.' ); - $this->assertSame( 'Test External, Pushed Origin', $dt_post->source_site['name'], 'Original site name does not match expected value.' ); - $this->assertSame( false, $dt_post->is_source, 'Post is incorrectly marked as the source.' ); + $this->assertSame( $data->blog->home, + $dt_post->source_site['home_url'], + 'Original home_url does not match expected value.' ); + $this->assertSame( $data->blog->blogname, + $dt_post->source_site['name'], + 'Original site name does not match expected value.' ); + $this->assertFalse( $dt_post->is_source, 'Post is incorrectly marked as the source.' ); } /** * Test the DistributorPost object for external, pushed posts. * - * @covers ::__construct - * @runInSeparateProcess - */ - public function test_external_connection_with_pulled_post() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pulled Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=10' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '' ), - 'dt_original_source_id' => array( '3' ), - ) - ); - - $dt_post = new DistributorPost( 1 ); - - $this->assertSame( 10, $dt_post->original_post_id, 'Origin post ID does not match expected value.' ); - $this->assertSame( true, $dt_post->is_linked, 'Origin post is not linked.' ); - $this->assertSame( 'http://origin.example.org/?p=10', $dt_post->original_post_url, 'Origin post URL does not match expected value.' ); - $this->assertSame( 3, $dt_post->connection_id, 'Origin connection ID does not match expected value.' ); - $this->assertSame( 'pulled', $dt_post->connection_direction, 'Connection direction does not match expected value.' ); + * @covers \Distributor\DistributorPost::__construct + * @dataProvider internal_connection_data_provider + */ + public function test_external_connection_with_pulled_post( $data ): void { + $dt_post = new DistributorPost( + ( new PostGenerator() ) + ->create() + ->withMeta( array( + 'dt_original_post_id' => $data->post->ID, + 'dt_original_site_name' => $data->blog->blogname, + 'dt_original_site_url' => $data->blog->home, + 'dt_original_post_url' => $data->post_url, + 'dt_subscription_signature' => 'abcdefghijklmnopqrstuvwxyz', + 'dt_syndicate_time' => time(), + 'dt_full_connection' => '', + 'dt_original_source_id' => $data->blog->id, + ) ) + ->getPost() + ); + + $this->assertSame( $data->post->ID, + $dt_post->original_post_id, + 'Origin post ID does not match expected value.' ); + $this->assertTrue( $dt_post->is_linked, 'Origin post is not linked.' ); + $this->assertSame( $data->post_url, + $dt_post->original_post_url, + 'Origin post URL does not match expected value.' ); + $this->assertSame( $data->blog->id, + $dt_post->connection_id, + 'Origin connection ID does not match source URL.' ); + $this->assertSame( 'pulled', + $dt_post->connection_direction, + 'Connection direction does not match expected value.' ); $this->assertSame( 'external', $dt_post->connection_type, 'Connection type is incorrect.' ); - $this->assertSame( 'http://origin.example.org/', $dt_post->source_site['home_url'], 'Original home_url does not match expected value.' ); - $this->assertSame( 'Test External, Pulled Origin', $dt_post->source_site['name'], 'Original site name does not match expected value.' ); - $this->assertSame( false, $dt_post->is_source, 'Post is incorrectly marked as the source.' ); + $this->assertSame( $data->blog->home, + $dt_post->source_site['home_url'], + 'Original home_url does not match expected value.' ); + $this->assertSame( $data->blog->blogname, + $dt_post->source_site['name'], + 'Original site name does not match expected value.' ); + $this->assertFalse( $dt_post->is_source, 'Post is incorrectly marked as the source.' ); } /** * Test the DistributorPost object a source post. * - * @covers ::__construct - * @runInSeparateProcess + * @covers \Distributor\DistributorPost::__construct */ - public function test_source_post() { - $this->setup_post_mock(); - // There is no post meta to mock for a source post. - $this->setup_post_meta_mock( array() ); + public function test_source_post(): void { + $post = ( new PostGenerator() )->create()->getPost(); + $dt_post = new DistributorPost( $post ); - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://example.org/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'home_url', - array( - 'return' => 'http://example.org/', - ) - ); - - \WP_Mock::userFunction( - 'get_bloginfo', - array( - 'return' => function( $info ) { - switch ( $info ) { - case 'charset': - return 'UTF-8'; - case 'name': - return 'Example Dot Org'; - default: - return ''; - } - }, - ) - ); - - $dt_post = new DistributorPost( 1 ); - - $this->assertSame( 1, $dt_post->original_post_id, 'Origin post ID does not match expected value.' ); - $this->assertSame( true, $dt_post->is_linked, 'Origin post is not linked.' ); + $this->assertSame( $post->ID, $dt_post->original_post_id, 'Origin post ID does not match expected value.' ); + $this->assertTrue( $dt_post->is_linked, 'Origin post is not linked.' ); $this->assertSame( 0, $dt_post->connection_id, 'Origin connection ID does not match expected value.' ); $this->assertSame( '', $dt_post->connection_direction, 'Connection direction does not match expected value.' ); $this->assertSame( '', $dt_post->connection_type, 'Connection type is incorrect.' ); - $this->assertSame( 'http://example.org/', $dt_post->source_site['home_url'], 'Original home_url does not match expected value.' ); - $this->assertSame( 'Example Dot Org', $dt_post->source_site['name'], 'Original site name does not match expected value.' ); - $this->assertSame( true, $dt_post->is_source, 'Post is incorrectly marked as distributed.' ); + $this->assertSame( + home_url(), + $dt_post->source_site['home_url'], + 'Original home_url does not match expected value.' + ); + $this->assertSame( + get_bloginfo( 'name' ), + $dt_post->source_site['name'], + 'Original site name does not match expected value.' + ); + $this->assertTrue( $dt_post->is_source, 'Post is incorrectly marked as distributed.' ); } /** * Test the get_the_id() method. * - * @covers ::get_the_id - * @runInSeparateProcess + * @covers \Distributor\DistributorPost::get_the_id */ - public function test_get_the_id() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( array() ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://example.org/?p=1', - ) - ); - $dt_post = new DistributorPost( 1 ); + public function test_get_the_id(): void { + $post = ( new PostGenerator() )->create()->getPost(); + $dt_post = new DistributorPost( $post ); - $this->assertSame( 1, $dt_post->get_the_id() ); + $this->assertSame( $post->ID, $dt_post->get_the_id() ); } /** * Test the get_permalink() method. * - * @covers ::get_permalink - * @runInSeparateProcess + * @covers \Distributor\DistributorPost::get_permalink */ - public function test_get_permalink() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( array() ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://example.org/?p=1', - ) - ); - $dt_post = new DistributorPost( 1 ); + public function test_get_permalink(): void { + $post = ( new PostGenerator() )->create()->getPost(); + $dt_post = new DistributorPost( $post ); - $this->assertSame( 'http://example.org/?p=1', $dt_post->get_permalink() ); + $this->assertSame( get_permalink( $post ), $dt_post->get_permalink() ); } /** * Test the get_post_type() method. * - * @covers ::get_post_type - * @runInSeparateProcess + * @covers \Distributor\DistributorPost::get_post_type */ - public function test_get_post_type() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( array() ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://example.org/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'get_post_type', - array( - 'return' => 'post', - ) - ); - $dt_post = new DistributorPost( 1 ); + public function test_get_post_type(): void { + $post = ( new PostGenerator() )->create()->getPost(); + $dt_post = new DistributorPost( $post ); - $this->assertSame( 'post', $dt_post->get_post_type() ); + $this->assertSame( get_post_type( $post ), $dt_post->get_post_type() ); } /** * Test the get_post_thumbnail_id() method. * - * @covers ::get_post_thumbnail_id - * @runInSeparateProcess + * @covers \Distributor\DistributorPost::get_post_thumbnail_id */ - public function test_get_post_thumbnail_id() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( array() ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://example.org/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'get_post_thumbnail_id', - array( - 'return' => 4, - ) - ); - $dt_post = new DistributorPost( 1 ); + public function test_get_post_thumbnail_id(): void { + $post = ( new PostGenerator() )->create()->getPost(); + $dt_post = new DistributorPost( $post ); - $this->assertSame( 4, $dt_post->get_post_thumbnail_id() ); + $this->assertSame( get_post_thumbnail_id( $post ), $dt_post->get_post_thumbnail_id() ); } /** * Test the get_post_thumbnail_url() method. * - * @covers ::get_post_thumbnail_url - * @runInSeparateProcess + * @covers \Distributor\DistributorPost::get_post_thumbnail_url */ - public function test_get_post_thumbnail_url() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( array() ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://example.org/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'get_the_post_thumbnail_url', - array( - 'return' => 'http://example.org/wp-content/uploads/2018/01/featured-image.jpg', - ) - ); - $dt_post = new DistributorPost( 1 ); + public function test_get_post_thumbnail_url(): void { + $post = ( new PostGenerator() )->create()->getPost(); + $dt_post = new DistributorPost( $post ); - $this->assertSame( 'http://example.org/wp-content/uploads/2018/01/featured-image.jpg', $dt_post->get_post_thumbnail_url() ); + $this->assertSame( get_the_post_thumbnail_url( $post ), $dt_post->get_post_thumbnail_url() ); } /** * Test the get_the_post_thumbnail() method. * - * @covers ::get_the_post_thumbnail - * @runInSeparateProcess + * @covers \Distributor\DistributorPost::get_the_post_thumbnail */ - public function test_get_the_post_thumbnail() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( array() ); - $thumbnail = ''; - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://example.org/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'get_the_post_thumbnail', - array( - 'return' => $thumbnail, - ) - ); - $dt_post = new DistributorPost( 1 ); + public function test_get_the_post_thumbnail(): void { + $post = ( new PostGenerator() )->create()->getPost(); + $dt_post = new DistributorPost( $post ); - $this->assertSame( $thumbnail, $dt_post->get_the_post_thumbnail() ); + $this->assertSame( get_the_post_thumbnail( $post ), $dt_post->get_the_post_thumbnail() ); } /** * Test the get_meta() method. * - * @covers ::get_meta - * @runInSeparateProcess + * @covers \Distributor\DistributorPost::get_meta */ - public function test_get_meta() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pulled Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=10' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '' ), - 'dt_original_source_id' => array( '3' ), - 'distributable_meta_data' => array( 'This will be distributed.' ), + public function test_get_meta(): void { + $post = ( new PostGenerator() )->create()->withMeta( + array( + 'dt_original_post_id' => '10', + 'dt_original_site_name' => 'Test External, Pulled Origin', + 'dt_original_site_url' => 'http://origin.example.org/', + 'dt_original_post_url' => 'http://origin.example.org/?p=10', + 'dt_subscription_signature' => 'abcdefghijklmnopqrstuvwxyz', + 'dt_syndicate_time' => time(), + 'dt_full_connection' => '', + 'dt_original_source_id' => '3', + 'distributable_meta_data' => 'This will be distributed.', ) - ); + )->getPost(); + + $dt_post = new DistributorPost( $post->ID ); - $dt_post = new DistributorPost( 1 ); - $excluded_meta = Utils\excluded_meta(); + $excluded_meta = excluded_meta(); $distributable_meta = $dt_post->get_meta(); - $this->assertArrayHasKey( 'distributable_meta_data', $distributable_meta, 'Distributable meta should be included.' ); + $this->assertArrayHasKey( + 'distributable_meta_data', + $distributable_meta, + 'Distributable meta should be included.' + ); - foreach( $excluded_meta as $meta_key ) { - $this->assertArrayNotHasKey( $meta_key, $distributable_meta, "Excluded meta '{$meta_key}' should not be included." ); + foreach ( $excluded_meta as $meta_key ) { + $this->assertArrayNotHasKey( + $meta_key, + $distributable_meta, + "Excluded meta '{$meta_key}' should not be included." + ); } } /** * Test the get_terms() method. * - * @covers ::get_terms - * @runInSeparateProcess + * @covers \Distributor\DistributorPost::get_terms */ - public function test_get_terms() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pulled Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=10' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '' ), - 'dt_original_source_id' => array( '3' ), - 'distributable_meta_data' => array( 'This will be distributed.' ), - ) - ); - - \WP_Mock::userFunction( - 'get_taxonomies', - array( - 'return' => array( 'category', 'post_tag' ), - ) - ); - - \WP_Mock::userFunction( - 'wp_get_object_terms', - array( - 'return_in_order' => array( - array( - (object) array( - 'term_id' => 1, - 'name' => 'Test Category', - 'slug' => 'test-category', - 'term_group' => 0, - 'term_taxonomy_id' => 1, - 'taxonomy' => 'category', - 'description' => '', - 'parent' => 0, - 'count' => 1, - 'filter' => 'raw', - ) - ), - array( - (object) array( - 'term_id' => 2, - 'name' => 'Test Tag', - 'slug' => 'test-tag', - 'term_group' => 0, - 'term_taxonomy_id' => 2, - 'taxonomy' => 'post_tag', - 'description' => '', - 'parent' => 0, - 'count' => 1, - 'filter' => 'raw' - ) - ), - ), - ) - ); - - $dt_post = new DistributorPost( 1 ); - $distributable_terms = $dt_post->get_terms(); - - $expected_terms = array( - 'category' => array( - (object) array( - 'term_id' => 1, - 'name' => 'Test Category', - 'slug' => 'test-category', - 'term_group' => 0, - 'term_taxonomy_id' => 1, - 'taxonomy' => 'category', - 'description' => '', - 'parent' => 0, - 'count' => 1, - 'filter' => 'raw', - ) - ), - 'post_tag' => array( - (object) array( - 'term_id' => 2, - 'name' => 'Test Tag', - 'slug' => 'test-tag', - 'term_group' => 0, - 'term_taxonomy_id' => 2, - 'taxonomy' => 'post_tag', - 'description' => '', - 'parent' => 0, - 'count' => 1, - 'filter' => 'raw' - ) - ), - ); - - $this->assertEquals( $expected_terms, $distributable_terms ); + public function test_get_terms(): void { + $this->markTestIncomplete(); } /** @@ -624,408 +336,9 @@ public function test_get_terms() { * @covers ::get_media * @covers ::parse_media_blocks * @covers ::parse_blocks_for_attachment_id - * @runInSeparateProcess */ - public function test_get_media_with_blocks() { - $post_content = ' -
- - -
- - -
- - '; - - $this->setup_post_meta_mock( array() ); - - \WP_Mock::userFunction( - 'get_post', - array( - 'return_in_order' => array( - (object) array( - 'ID' => 1, - 'post_title' => 'Block post with media', - 'post_content' => $post_content, - 'post_excerpt' => '', - 'guid' => 'http://example.org/?p=1', - 'post_name' => 'test-post', - ), - (object) array( - 'ID' => 11, - 'post_title' => 'deh-platt', - 'post_content' => '', - 'post_excerpt' => '', - 'guid' => 'http://example.org/?p=11', - 'post_name' => 'deh-platt', - 'post_parent' => 0, - 'post_mime_type' => 'image/jpeg', - ), - (object) array( - 'ID' => 12, - 'post_title' => 'mp3-5mg', - 'post_content' => '', - 'post_excerpt' => '', - 'guid' => 'http://example.org/?p=12', - 'post_name' => 'mp3-5mg', - 'post_parent' => 0, - 'post_mime_type' => 'audio/mpeg', - ), - (object) array( - 'ID' => 13, - 'post_title' => 'sample-mp4', - 'post_content' => '', - 'post_excerpt' => '', - 'guid' => 'http://example.org/?p=13', - 'post_name' => 'sample-mp4', - 'post_parent' => 0, - 'post_mime_type' => 'video/mp4', - ), - ), - ) - ); - - \WP_Mock::userFunction( - 'wp_attachment_is_image', - array( - 'return_in_order' => array( - true, - false, - false, - ), - ) - ); - - \WP_Mock::userFunction( - 'wp_get_attachment_metadata', - array( - 'return_in_order' => array( - array( - 'file' => '2022/12/deh-platt.jpg', - 'width' => 1024, - 'height' => 683, - 'filesize' => 404298, - 'sizes' => array( - 'thumbnail' => array( - 'file' => 'deh-platt-150x150.jpg', - 'width' => 150, - 'height' => 150, - 'mime-type' => 'image/jpeg', - ), - 'medium' => array( - 'file' => 'deh-platt-300x200.jpg', - 'width' => 300, - 'height' => 200, - 'mime-type' => 'image/jpeg', - ), - 'medium_large' => array( - 'file' => 'deh-platt-768x512.jpg', - 'width' => 768, - 'height' => 512, - 'mime-type' => 'image/jpeg', - ), - 'large' => array( - 'file' => 'deh-platt-1024x683.jpg', - 'width' => 1024, - 'height' => 683, - 'mime-type' => 'image/jpeg', - ), - ), - ), - array ( - 'dataformat' => 'mp3', - 'channels' => 2, - 'sample_rate' => 44100, - 'bitrate' => 320000, - 'channelmode' => 'stereo', - 'bitrate_mode' => 'cbr', - 'codec' => 'LAME', - 'encoder' => 'LAME3.99r', - 'lossless' => false, - 'encoder_options' => '--preset insane', - 'compression_ratio' => 0.22675736961451248, - 'fileformat' => 'mp3', - 'filesize' => 5289384, - 'mime_type' => 'audio/mpeg', - 'length' => 132, - 'length_formatted' => '2:12', - 'genre' => 'Cinematic', - 'album' => 'YouTube Audio Library', - 'title' => 'Impact Moderato', - 'artist' => 'Kevin MacLeod', - ), - array ( - 'filesize' => 1570024, - 'mime_type' => 'video/mp4', - 'length' => 31, - 'length_formatted' => '0:31', - 'width' => 480, - 'height' => 270, - 'fileformat' => 'mp4', - 'dataformat' => 'quicktime', - 'audio' => array ( - 'dataformat' => 'mp4', - 'codec' => 'ISO/IEC 14496-3 AAC', - 'sample_rate' => 48000.0, - 'channels' => 2, - 'bits_per_sample' => 16, - 'lossless' => false, - 'channelmode' => 'stereo', - ), - 'created_timestamp' => 1438938782, - ), - ), - ) - ); - - \WP_Mock::userFunction( - 'wp_get_attachment_url', - array( - 'return_in_order' => array( - 'http://xu-distributor.local/wp-content/uploads/2022/12/deh-platt.jpg', - 'http://xu-distributor.local/wp-content/uploads/2022/12/mp3-5mg.mp3', - 'http://xu-distributor.local/wp-content/uploads/2022/12/sample-mp4.mp4', - ), - ) - ); - - \WP_Mock::userFunction( - 'get_attached_file', - array( - 'return_in_order' => array( - '/var/www/html/wp-content/uploads/2022/12/deh-platt.jpg', - '/var/www/html/wp-content/uploads/2022/12/mp3-5mg.mp3', - '/var/www/html/wp-content/uploads/2022/12/sample-mp4.mp4', - ), - ) - ); - - \WP_Mock::userFunction( - 'has_blocks', - array( - 'return' => true, - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return_in_order' => array( - 'http://xu-distributor.local/?p=2', - 'http://xu-distributor.local/?p=11', - 'http://xu-distributor.local/?p=12', - 'http://xu-distributor.local/?p=13', - ), - ), - ); - - \WP_Mock::userFunction( - 'get_post_thumbnail_id', - array( - 'return' => false, - ) - ); - - \WP_Mock::userFunction( - 'wp_cache_get', - array( - 'return' => false - ) - ); - - \WP_Mock::userFunction( - 'wp_cache_set', - array( - 'return' => false - ) - ); - - $blocks = array( - array( - 'blockName' => 'core/image', - 'attrs' => array( - 'id' => 11, - 'sizeSlug' => 'large', - 'linkDestination' => 'none', - ), - 'innerBlocks' => array(), - 'innerHTML' => '
', - 'innerContent' => array( - '
', - ), - ), - array( - 'blockName' => 'core/audio', - 'attrs' => array( - 'id' => 12, - ), - 'innerBlocks' => array(), - 'innerHTML' => '
', - 'innerContent' => array( - '
', - ), - ), - array( - 'blockName' => 'core/video', - 'attrs' => array( - 'id' => 13, - ), - 'innerBlocks' => array(), - 'innerHTML' => '
', - 'innerContent' => array( - '
', - ), - ), - ); - - \WP_Mock::userFunction( - 'parse_blocks', - array( - 'return' => $blocks, - ) - ); - - - $dt_post = new DistributorPost( 1 ); - $post_media_actual = $dt_post->get_media(); - - $post_media_expected = array( - array( - 'id' => 11, - 'title' => 'deh-platt', - 'featured' => false, - 'description' => array( - 'raw' => '', - 'rendered' => '', - ), - 'caption' => array( - 'raw' => '', - ), - 'alt_text' => '', - 'media_type' => 'image', - 'mime_type' => 'image/jpeg', - 'post' => 0, - 'source_url' => 'http://xu-distributor.local/wp-content/uploads/2022/12/deh-platt.jpg', - 'source_file' => '/var/www/html/wp-content/uploads/2022/12/deh-platt.jpg', - 'meta' => array(), - 'media_details' => array( - 'width' => 1024, - 'height' => 683, - 'file' => '2022/12/deh-platt.jpg', - 'filesize' => 404298, - 'sizes' => array( - 'thumbnail' => array( - 'file' => 'deh-platt-150x150.jpg', - 'width' => 150, - 'height' => 150, - 'mime-type' => 'image/jpeg', - ), - 'medium' => array( - 'file' => 'deh-platt-300x200.jpg', - 'width' => 300, - 'height' => 200, - 'mime-type' => 'image/jpeg', - ), - 'medium_large' => array( - 'file' => 'deh-platt-768x512.jpg', - 'width' => 768, - 'height' => 512, - 'mime-type' => 'image/jpeg', - ), - 'large' => array( - 'file' => 'deh-platt-1024x683.jpg', - 'width' => 1024, - 'height' => 683, - 'mime-type' => 'image/jpeg', - ), - ), - ), - ), - array( - 'id' => 12, - 'title' => 'mp3-5mg', - 'featured' => false, - 'description' => array( - 'raw' => '', - 'rendered' => '', - ), - 'caption' => array( - 'raw' => '', - ), - 'alt_text' => '', - 'media_type' => 'file', - 'mime_type' => 'audio/mpeg', - 'post' => 0, - 'source_url' => 'http://xu-distributor.local/wp-content/uploads/2022/12/mp3-5mg.mp3', - 'source_file' => '/var/www/html/wp-content/uploads/2022/12/mp3-5mg.mp3', - 'meta' => array(), - 'media_details' => array ( - 'dataformat' => 'mp3', - 'channels' => 2, - 'sample_rate' => 44100, - 'bitrate' => 320000, - 'channelmode' => 'stereo', - 'bitrate_mode' => 'cbr', - 'codec' => 'LAME', - 'encoder' => 'LAME3.99r', - 'lossless' => false, - 'encoder_options' => '--preset insane', - 'compression_ratio' => 0.22675736961451248, - 'fileformat' => 'mp3', - 'filesize' => 5289384, - 'mime_type' => 'audio/mpeg', - 'length' => 132, - 'length_formatted' => '2:12', - 'genre' => 'Cinematic', - 'album' => 'YouTube Audio Library', - 'title' => 'Impact Moderato', - 'artist' => 'Kevin MacLeod', - ), - ), - array( - 'id' => 13, - 'title' => 'sample-mp4', - 'featured' => false, - 'description' => array( - 'raw' => '', - 'rendered' => '', - ), - 'caption' => array( - 'raw' => '', - ), - 'alt_text' => '', - 'media_type' => 'file', - 'mime_type' => 'video/mp4', - 'media_details' => array ( - 'filesize' => 1570024, - 'mime_type' => 'video/mp4', - 'length' => 31, - 'length_formatted' => '0:31', - 'width' => 480, - 'height' => 270, - 'fileformat' => 'mp4', - 'dataformat' => 'quicktime', - 'audio' => array ( - 'dataformat' => 'mp4', - 'codec' => 'ISO/IEC 14496-3 AAC', - 'sample_rate' => 48000.0, - 'channels' => 2, - 'bits_per_sample' => 16, - 'lossless' => false, - 'channelmode' => 'stereo', - ), - 'created_timestamp' => 1438938782, - ), - 'post' => 0, - 'source_url' => 'http://xu-distributor.local/wp-content/uploads/2022/12/sample-mp4.mp4', - 'source_file' => '/var/www/html/wp-content/uploads/2022/12/sample-mp4.mp4', - 'meta' => array(), - - ), - ); - - $this->assertEquals( $post_media_expected, $post_media_actual ); + public function test_get_media_with_blocks(): void { + $this->markTestIncomplete(); } /** @@ -1035,345 +348,9 @@ public function test_get_media_with_blocks() { * authored in the classic editor. * * @covers ::get_media() - * @runInSeparateProcess */ - public function test_get_media_with_attachments() { - $this->setup_post_meta_mock( array() ); - - \WP_Mock::userFunction( - 'get_post', - array( - 'return_in_order' => array( - (object) array( - 'ID' => 1, - 'post_title' => 'Classic editor post with media', - 'post_content' => 'No content, just child posts.', - 'post_excerpt' => '', - 'guid' => 'http://example.org/?p=1', - 'post_name' => 'test-post', - ), - ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return_in_order' => array( - 'http://xu-distributor.local/?p=2', - 'http://xu-distributor.local/?p=11', - 'http://xu-distributor.local/?p=12', - 'http://xu-distributor.local/?p=13', - ), - ), - ); - - \WP_Mock::userFunction( - 'has_blocks', - array( - 'return' => false, - ) - ); - - \WP_Mock::userFunction( - 'get_attached_media', - array( - 'return' => array( - (object) array( - 'ID' => 11, - 'post_title' => 'deh-platt', - 'post_content' => '', - 'post_excerpt' => '', - 'guid' => 'http://example.org/?p=11', - 'post_name' => 'deh-platt', - 'post_parent' => 1, - 'post_mime_type' => 'image/jpeg', - ), - (object) array( - 'ID' => 12, - 'post_title' => 'mp3-5mg', - 'post_content' => '', - 'post_excerpt' => '', - 'guid' => 'http://example.org/?p=12', - 'post_name' => 'mp3-5mg', - 'post_parent' => 1, - 'post_mime_type' => 'audio/mpeg', - ), - (object) array( - 'ID' => 13, - 'post_title' => 'sample-mp4', - 'post_content' => '', - 'post_excerpt' => '', - 'guid' => 'http://example.org/?p=13', - 'post_name' => 'sample-mp4', - 'post_parent' => 1, - 'post_mime_type' => 'video/mp4', - ), - ), - ) - ); - - \WP_Mock::userFunction( - 'get_post_thumbnail_id', - array( - 'return' => false, - ) - ); - - \WP_Mock::userFunction( - 'wp_attachment_is_image', - array( - 'return_in_order' => array( - true, - false, - false, - ), - ) - ); - - \WP_Mock::userFunction( - 'wp_get_attachment_metadata', - array( - 'return_in_order' => array( - array( - 'file' => '2022/12/deh-platt.jpg', - 'width' => 1024, - 'height' => 683, - 'filesize' => 404298, - 'sizes' => array( - 'thumbnail' => array( - 'file' => 'deh-platt-150x150.jpg', - 'width' => 150, - 'height' => 150, - 'mime-type' => 'image/jpeg', - ), - 'medium' => array( - 'file' => 'deh-platt-300x200.jpg', - 'width' => 300, - 'height' => 200, - 'mime-type' => 'image/jpeg', - ), - 'medium_large' => array( - 'file' => 'deh-platt-768x512.jpg', - 'width' => 768, - 'height' => 512, - 'mime-type' => 'image/jpeg', - ), - 'large' => array( - 'file' => 'deh-platt-1024x683.jpg', - 'width' => 1024, - 'height' => 683, - 'mime-type' => 'image/jpeg', - ), - ), - ), - array ( - 'dataformat' => 'mp3', - 'channels' => 2, - 'sample_rate' => 44100, - 'bitrate' => 320000, - 'channelmode' => 'stereo', - 'bitrate_mode' => 'cbr', - 'codec' => 'LAME', - 'encoder' => 'LAME3.99r', - 'lossless' => false, - 'encoder_options' => '--preset insane', - 'compression_ratio' => 0.22675736961451248, - 'fileformat' => 'mp3', - 'filesize' => 5289384, - 'mime_type' => 'audio/mpeg', - 'length' => 132, - 'length_formatted' => '2:12', - 'genre' => 'Cinematic', - 'album' => 'YouTube Audio Library', - 'title' => 'Impact Moderato', - 'artist' => 'Kevin MacLeod', - ), - array ( - 'filesize' => 1570024, - 'mime_type' => 'video/mp4', - 'length' => 31, - 'length_formatted' => '0:31', - 'width' => 480, - 'height' => 270, - 'fileformat' => 'mp4', - 'dataformat' => 'quicktime', - 'audio' => array ( - 'dataformat' => 'mp4', - 'codec' => 'ISO/IEC 14496-3 AAC', - 'sample_rate' => 48000.0, - 'channels' => 2, - 'bits_per_sample' => 16, - 'lossless' => false, - 'channelmode' => 'stereo', - ), - 'created_timestamp' => 1438938782, - ), - ), - ) - ); - - \WP_Mock::userFunction( - 'wp_get_attachment_url', - array( - 'return_in_order' => array( - 'http://xu-distributor.local/wp-content/uploads/2022/12/deh-platt.jpg', - 'http://xu-distributor.local/wp-content/uploads/2022/12/mp3-5mg.mp3', - 'http://xu-distributor.local/wp-content/uploads/2022/12/sample-mp4.mp4', - ), - ) - ); - - \WP_Mock::userFunction( - 'get_attached_file', - array( - 'return_in_order' => array( - '/var/www/html/wp-content/uploads/2022/12/deh-platt.jpg', - '/var/www/html/wp-content/uploads/2022/12/mp3-5mg.mp3', - '/var/www/html/wp-content/uploads/2022/12/sample-mp4.mp4', - ), - ) - ); - - $dt_post = new DistributorPost( 1 ); - $post_media_actual = $dt_post->get_media(); - - $post_media_expected = array( - array( - 'id' => 11, - 'title' => 'deh-platt', - 'featured' => false, - 'description' => array( - 'raw' => '', - 'rendered' => '', - ), - 'caption' => array( - 'raw' => '', - ), - 'alt_text' => '', - 'media_type' => 'image', - 'mime_type' => 'image/jpeg', - 'post' => 1, - 'source_url' => 'http://xu-distributor.local/wp-content/uploads/2022/12/deh-platt.jpg', - 'source_file' => '/var/www/html/wp-content/uploads/2022/12/deh-platt.jpg', - 'meta' => array(), - 'media_details' => array( - 'width' => 1024, - 'height' => 683, - 'file' => '2022/12/deh-platt.jpg', - 'filesize' => 404298, - 'sizes' => array( - 'thumbnail' => array( - 'file' => 'deh-platt-150x150.jpg', - 'width' => 150, - 'height' => 150, - 'mime-type' => 'image/jpeg', - ), - 'medium' => array( - 'file' => 'deh-platt-300x200.jpg', - 'width' => 300, - 'height' => 200, - 'mime-type' => 'image/jpeg', - ), - 'medium_large' => array( - 'file' => 'deh-platt-768x512.jpg', - 'width' => 768, - 'height' => 512, - 'mime-type' => 'image/jpeg', - ), - 'large' => array( - 'file' => 'deh-platt-1024x683.jpg', - 'width' => 1024, - 'height' => 683, - 'mime-type' => 'image/jpeg', - ), - ), - ), - ), - array( - 'id' => 12, - 'title' => 'mp3-5mg', - 'featured' => false, - 'description' => array( - 'raw' => '', - 'rendered' => '', - ), - 'caption' => array( - 'raw' => '', - ), - 'alt_text' => '', - 'media_type' => 'file', - 'mime_type' => 'audio/mpeg', - 'post' => 1, - 'source_url' => 'http://xu-distributor.local/wp-content/uploads/2022/12/mp3-5mg.mp3', - 'source_file' => '/var/www/html/wp-content/uploads/2022/12/mp3-5mg.mp3', - 'meta' => array(), - 'media_details' => array ( - 'dataformat' => 'mp3', - 'channels' => 2, - 'sample_rate' => 44100, - 'bitrate' => 320000, - 'channelmode' => 'stereo', - 'bitrate_mode' => 'cbr', - 'codec' => 'LAME', - 'encoder' => 'LAME3.99r', - 'lossless' => false, - 'encoder_options' => '--preset insane', - 'compression_ratio' => 0.22675736961451248, - 'fileformat' => 'mp3', - 'filesize' => 5289384, - 'mime_type' => 'audio/mpeg', - 'length' => 132, - 'length_formatted' => '2:12', - 'genre' => 'Cinematic', - 'album' => 'YouTube Audio Library', - 'title' => 'Impact Moderato', - 'artist' => 'Kevin MacLeod', - ), - ), - array( - 'id' => 13, - 'title' => 'sample-mp4', - 'featured' => false, - 'description' => array( - 'raw' => '', - 'rendered' => '', - ), - 'caption' => array( - 'raw' => '', - ), - 'alt_text' => '', - 'media_type' => 'file', - 'mime_type' => 'video/mp4', - 'media_details' => array ( - 'filesize' => 1570024, - 'mime_type' => 'video/mp4', - 'length' => 31, - 'length_formatted' => '0:31', - 'width' => 480, - 'height' => 270, - 'fileformat' => 'mp4', - 'dataformat' => 'quicktime', - 'audio' => array ( - 'dataformat' => 'mp4', - 'codec' => 'ISO/IEC 14496-3 AAC', - 'sample_rate' => 48000.0, - 'channels' => 2, - 'bits_per_sample' => 16, - 'lossless' => false, - 'channelmode' => 'stereo', - ), - 'created_timestamp' => 1438938782, - ), - 'post' => 1, - 'source_url' => 'http://xu-distributor.local/wp-content/uploads/2022/12/sample-mp4.mp4', - 'source_file' => '/var/www/html/wp-content/uploads/2022/12/sample-mp4.mp4', - 'meta' => array(), - - ), - ); - - $this->assertEquals( $post_media_expected, $post_media_actual ); + public function test_get_media_with_attachments(): void { + $this->markTestIncomplete(); } /** @@ -1382,244 +359,22 @@ public function test_get_media_with_attachments() { * @covers ::get_media * @covers ::parse_media_blocks * @covers ::parse_blocks_for_attachment_id - * @runInSeparateProcess * @doesNotPerformAssertions */ public function test_get_media_sets_cache() { - $post_content = ' -
- - -
- - '; - - $this->setup_post_meta_mock( array() ); - - \WP_Mock::userFunction( - 'get_post', - array( - 'return_in_order' => array( - (object) array( - 'ID' => 33, - 'post_title' => 'Block post with media', - 'post_content' => $post_content, - 'post_excerpt' => '', - 'guid' => 'http://example.org/?p=1', - 'post_name' => 'test-post', - ), - (object) array( - 'ID' => 21, - 'post_title' => 'deh-platt', - 'post_content' => '', - 'post_excerpt' => '', - 'guid' => 'http://example.org/?p=11', - 'post_name' => 'deh-platt', - 'post_parent' => 0, - 'post_mime_type' => 'image/jpeg', - ), - (object) array( - 'ID' => 22, - 'post_title' => 'dah-platt', - 'post_content' => '', - 'post_excerpt' => '', - 'guid' => 'http://example.org/?p=22', - 'post_name' => 'dah-platt', - 'post_parent' => 0, - 'post_mime_type' => 'image/jpeg', - ), - ), - ) - ); + $this->markTestIncomplete(); + } - \WP_Mock::userFunction( - 'wp_attachment_is_image', - array( - 'return_in_order' => array( - true, - true, - ), - ) - ); - - \WP_Mock::userFunction( - 'wp_get_attachment_metadata', - array( - 'return_in_order' => array( - array( - 'file' => '2022/12/deh-platt.jpg', - 'width' => 1024, - 'height' => 683, - 'filesize' => 404298, - 'sizes' => array( - 'thumbnail' => array( - 'file' => 'deh-platt-150x150.jpg', - 'width' => 150, - 'height' => 150, - 'mime-type' => 'image/jpeg', - ), - 'medium' => array( - 'file' => 'deh-platt-300x200.jpg', - 'width' => 300, - 'height' => 200, - 'mime-type' => 'image/jpeg', - ), - 'medium_large' => array( - 'file' => 'deh-platt-768x512.jpg', - 'width' => 768, - 'height' => 512, - 'mime-type' => 'image/jpeg', - ), - 'large' => array( - 'file' => 'deh-platt-1024x683.jpg', - 'width' => 1024, - 'height' => 683, - 'mime-type' => 'image/jpeg', - ), - ), - ), - array( - 'file' => '2022/12/dah-platt.jpg', - 'width' => 1024, - 'height' => 683, - 'filesize' => 404298, - 'sizes' => array( - 'thumbnail' => array( - 'file' => 'dah-platt-150x150.jpg', - 'width' => 150, - 'height' => 150, - 'mime-type' => 'image/jpeg', - ), - 'medium' => array( - 'file' => 'dah-platt-300x200.jpg', - 'width' => 300, - 'height' => 200, - 'mime-type' => 'image/jpeg', - ), - 'medium_large' => array( - 'file' => 'dah-platt-768x512.jpg', - 'width' => 768, - 'height' => 512, - 'mime-type' => 'image/jpeg', - ), - 'large' => array( - 'file' => 'dah-platt-1024x683.jpg', - 'width' => 1024, - 'height' => 683, - 'mime-type' => 'image/jpeg', - ), - ), - ), - ), - ) - ); - - \WP_Mock::userFunction( - 'wp_get_attachment_url', - array( - 'return_in_order' => array( - 'http://xu-distributor.local/wp-content/uploads/2022/12/deh-platt.jpg', - 'http://xu-distributor.local/wp-content/uploads/2022/12/dah-platt.jpg', - ), - ) - ); - - \WP_Mock::userFunction( - 'get_attached_file', - array( - 'return_in_order' => array( - '/var/www/html/wp-content/uploads/2022/12/deh-platt.jpg', - '/var/www/html/wp-content/uploads/2022/12/dah-platt.jpg', - ), - ) - ); - - \WP_Mock::userFunction( - 'has_blocks', - array( - 'return' => true, - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return_in_order' => array( - 'http://xu-distributor.local/?p=2', - 'http://xu-distributor.local/?p=21', - 'http://xu-distributor.local/?p=22', - ), - ), - ); - - \WP_Mock::userFunction( - 'get_post_thumbnail_id', - array( - 'return' => false, - ) - ); - - \WP_Mock::userFunction( - 'wp_cache_get', - array( - 'return' => false, - ) - ); - - $blocks = array( - array( - 'blockName' => 'core/image', - 'attrs' => array( - 'id' => 21, - 'sizeSlug' => 'large', - 'linkDestination' => 'none', - ), - 'innerBlocks' => array(), - 'innerHTML' => '
', - 'innerContent' => array( - '
', - ), - ), - array( - 'blockName' => 'core/image', - 'attrs' => array( - 'id' => 22, - 'sizeSlug' => 'large', - 'linkDestination' => 'none', - ), - 'innerBlocks' => array(), - 'innerHTML' => '
', - 'innerContent' => array( - '
', - ), - ), - ); - - \WP_Mock::userFunction( - 'parse_blocks', - array( - 'return' => $blocks, - ) - ); - - // Add assertions to wp_cache_set mock. - \WP_Mock::userFunction( - 'wp_cache_set', - array( - 'return' => true, - 'times' => 1, - 'args' => array( - 'dt_media::33', - array( 21, 22 ), - 'dt::post' - ), - ) - ); - - $dt_post = new DistributorPost( 33 ); - $dt_post->get_media(); - - } + /** + * Test methods for formatting the post data without blocks. + * + * @covers ::post_data() + * @covers ::to_insert() + * @covers ::to_json() + */ + public function test_scheduled_post_data_without_blocks() { + $this->markTestIncomplete(); + } /** * Test methods for formatting the post data without blocks. @@ -1627,322 +382,9 @@ public function test_get_media_sets_cache() { * @covers ::post_data() * @covers ::to_insert() * @covers ::to_json() - * @runInSeparateProcess */ - public function test_scheduled_post_data_without_blocks() { - $this->setup_post_mock( - array( - 'post_status' => 'future', - 'post_date' => '2120-01-01 00:00:00', - 'post_date_gmt' => '2120-01-01 00:00:00', - 'post_modified' => '2120-01-01 00:00:00', - 'post_modified_gmt' => '2120-01-01 00:00:00', - ) - ); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_blog_id' => array( '2' ), - 'dt_syndicate_time' => array ( '1670383190' ), - 'dt_original_post_url' => array ( 'http://origin.example.org/?p=10' ), - ) - ); - - \WP_Mock::userFunction( - 'get_the_title', - array( - 'return' => 'Test Post', - ) - ); - \WP_Mock::userFunction( - 'get_bloginfo', - array( - 'return' => function( $info ) { - switch ( $info ) { - case 'charset': - return 'UTF-8'; - case 'name': - return 'Test Internal Origin'; - default: - return ''; - } - }, - ) - ); - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://example.org/?p=1', - ) - ); - - // Get Media: mock empty set as method is tested above. - \WP_Mock::userFunction( - 'has_blocks', - array( - 'return' => false, - ) - ); - \WP_Mock::userFunction( - 'get_attached_media', - array( - 'return' => array(), - ) - ); - \WP_Mock::userFunction( - 'get_post_thumbnail_id', - array( - 'return' => false, - ) - ); - - // Get Terms: mock empty set as method is tested above. - \WP_Mock::userFunction( - 'get_taxonomies', - array( - 'return' => array( 'category', 'post_tag' ), - ) - ); - \WP_Mock::userFunction( - 'wp_get_object_terms', - array( - 'return' => array(), - ) - ); - - $dt_post = new DistributorPost( 1 ); - $post_data_actual = $dt_post->post_data(); - - $post_data_expected = array( - 'title' => 'Test Post', - 'slug' => 'test-post', - 'type' => 'post', - 'content' => 'Test Content', - 'excerpt' => 'Test Excerpt', - 'parent' => 0, - 'status' => 'future', - 'date' => '2120-01-01 00:00:00', - 'date_gmt' => '2120-01-01 00:00:00', - 'distributor_media' => array(), - 'distributor_terms' => array( - 'category' => array(), - 'post_tag' => array(), - ), - 'distributor_meta' => array(), - 'distributor_original_site_name' => 'Test Internal Origin', - 'distributor_original_site_url' => 'http://test.com', - 'distributor_original_post_url' => 'http://example.org/?p=1', - 'distributor_original_post_id' => 1, - ); - - $this->assertSame( $post_data_expected, $post_data_actual, 'Post data is not in an expected form' ); - - // Make sure it looks good to insert. - $to_insert_actual = $dt_post->to_insert(); - $to_insert_expected = array( - 'post_title' => 'Test Post', - 'post_name' => 'test-post', - 'post_type' => 'post', - 'post_content' => 'Test Content', - 'post_excerpt' => 'Test Excerpt', - 'post_status' => 'future', - 'terms' => array( - 'category' => array(), - 'post_tag' => array(), - ), - 'meta' => array(), - 'media' => array(), - 'post_author' => 1, - 'post_date' => '2120-01-01 00:00:00', - 'post_date_gmt' => '2120-01-01 00:00:00', - 'meta_input' => array( - 'dt_original_post_id' => 1, - 'dt_original_post_url' => 'http://example.org/?p=1', - ), - ); - - $this->assertSame( $to_insert_expected, $to_insert_actual, 'Insert post data is not in an expected form' ); - - // Make sure it looks correct for a REST request. - $to_rest_actual = $dt_post->to_rest(); - $to_rest_expected = array( - 'title' => 'Test Post', - 'slug' => 'test-post', - 'type' => 'post', - 'content' => 'Test Content', - 'excerpt' => 'Test Excerpt', - 'status' => 'future', - 'distributor_media' => array(), - 'distributor_terms' => array( - 'category' => array(), - 'post_tag' => array(), - ), - 'distributor_meta' => array(), - 'distributor_original_site_name' => 'Test Internal Origin', - 'distributor_original_site_url' => 'http://test.com', - 'distributor_original_post_url' => 'http://example.org/?p=1', - 'distributor_remote_post_id' => 1, - - ); - - $this->assertSame( $to_rest_expected, $to_rest_actual, 'REST API data is not in an expected form' ); - } - - /** - * Test methods for formatting the post data without blocks. - * - * @covers ::post_data() - * @covers ::to_insert() - * @covers ::to_json() - * @runInSeparateProcess - */ - public function test_post_data_without_blocks() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_blog_id' => array( '2' ), - 'dt_syndicate_time' => array ( '1670383190' ), - 'dt_original_post_url' => array ( 'http://origin.example.org/?p=10' ), - ) - ); - - \WP_Mock::userFunction( - 'get_the_title', - array( - 'return' => 'Test Post', - ) - ); - \WP_Mock::userFunction( - 'get_bloginfo', - array( - 'return' => function( $info ) { - switch ( $info ) { - case 'charset': - return 'UTF-8'; - case 'name': - return 'Test Internal Origin'; - default: - return ''; - } - }, - ) - ); - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://example.org/?p=1', - ) - ); - - // Get Media: mock empty set as method is tested above. - \WP_Mock::userFunction( - 'has_blocks', - array( - 'return' => false, - ) - ); - \WP_Mock::userFunction( - 'get_attached_media', - array( - 'return' => array(), - ) - ); - \WP_Mock::userFunction( - 'get_post_thumbnail_id', - array( - 'return' => false, - ) - ); - - // Get Terms: mock empty set as method is tested above. - \WP_Mock::userFunction( - 'get_taxonomies', - array( - 'return' => array( 'category', 'post_tag' ), - ) - ); - \WP_Mock::userFunction( - 'wp_get_object_terms', - array( - 'return' => array(), - ) - ); - - $dt_post = new DistributorPost( 1 ); - $post_data_actual = $dt_post->post_data(); - - $post_data_expected = array( - 'title' => 'Test Post', - 'slug' => 'test-post', - 'type' => 'post', - 'content' => 'Test Content', - 'excerpt' => 'Test Excerpt', - 'parent' => 0, - 'status' => 'publish', - 'date' => '2020-01-01 00:00:00', - 'date_gmt' => '2020-01-01 00:00:00', - 'distributor_media' => array(), - 'distributor_terms' => array( - 'category' => array(), - 'post_tag' => array(), - ), - 'distributor_meta' => array(), - 'distributor_original_site_name' => 'Test Internal Origin', - 'distributor_original_site_url' => 'http://test.com', - 'distributor_original_post_url' => 'http://example.org/?p=1', - 'distributor_original_post_id' => 1, - ); - - $this->assertSame( $post_data_expected, $post_data_actual, 'Post data is not in an expected form' ); - - // Make sure it looks good to insert. - $to_insert_actual = $dt_post->to_insert(); - $to_insert_expected = array( - 'post_title' => 'Test Post', - 'post_name' => 'test-post', - 'post_type' => 'post', - 'post_content' => 'Test Content', - 'post_excerpt' => 'Test Excerpt', - 'post_status' => 'publish', - 'terms' => array( - 'category' => array(), - 'post_tag' => array(), - ), - 'meta' => array(), - 'media' => array(), - 'post_author' => 1, - 'meta_input' => array( - 'dt_original_post_id' => 1, - 'dt_original_post_url' => 'http://example.org/?p=1', - ), - ); - - $this->assertSame( $to_insert_expected, $to_insert_actual, 'Insert post data is not in an expected form' ); - - // Make sure it looks correct for a REST request. - $to_rest_actual = $dt_post->to_rest(); - $to_rest_expected = array( - 'title' => 'Test Post', - 'slug' => 'test-post', - 'type' => 'post', - 'content' => 'Test Content', - 'excerpt' => 'Test Excerpt', - 'status' => 'publish', - 'distributor_media' => array(), - 'distributor_terms' => array( - 'category' => array(), - 'post_tag' => array(), - ), - 'distributor_meta' => array(), - 'distributor_original_site_name' => 'Test Internal Origin', - 'distributor_original_site_url' => 'http://test.com', - 'distributor_original_post_url' => 'http://example.org/?p=1', - 'distributor_remote_post_id' => 1, - - ); - - $this->assertSame( $to_rest_expected, $to_rest_actual, 'REST API data is not in an expected form' ); + public function test_post_data_without_blocks(): void { + $this->markTestIncomplete(); } /** @@ -1951,178 +393,9 @@ public function test_post_data_without_blocks() { * @covers ::post_data() * @covers ::to_insert() * @covers ::to_json() - * @runInSeparateProcess */ - public function test_post_data_with_blocks() { - $block_content = '

Test Content

'; - $this->setup_post_mock( array( 'post_content' => $block_content ) ); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_blog_id' => array( '2' ), - 'dt_syndicate_time' => array ( '1670383190' ), - 'dt_original_post_url' => array ( 'http://origin.example.org/?p=10' ), - ) - ); - - \WP_Mock::userFunction( - 'get_the_title', - array( - 'return' => 'Test Post', - ) - ); - \WP_Mock::userFunction( - 'get_bloginfo', - array( - 'return' => function( $info ) { - switch ( $info ) { - case 'charset': - return 'UTF-8'; - case 'name': - return 'Test Internal Origin'; - default: - return ''; - } - }, - ) - ); - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://example.org/?p=1', - ) - ); - - // Get Media: mock empty set as method is tested above. - \WP_Mock::userFunction( - 'has_blocks', - array( - 'return' => true, - ) - ); - \WP_Mock::userFunction( - 'wp_cache_get', - array( - 'return' => false - ) - ); - \WP_Mock::userFunction( - 'wp_cache_set', - array( - 'return' => false - ) - ); - $blocks = array( - array( - 'blockName' => 'core/paragraph', - 'attrs' => array(), - 'innerBlocks' => array(), - 'innerHtml' => '

Test Content

', - 'innerContent' => array( '

Test Content

' ), - ), - ); - \WP_Mock::userFunction( - 'parse_blocks', - array( - 'return' => $blocks, - ) - ); - \WP_Mock::userFunction( - 'get_post_thumbnail_id', - array( - 'return' => false, - ) - ); - - - // Get Terms: mock empty set as method is tested above. - \WP_Mock::userFunction( - 'get_taxonomies', - array( - 'return' => array( 'category', 'post_tag' ), - ) - ); - \WP_Mock::userFunction( - 'wp_get_object_terms', - array( - 'return' => array(), - ) - ); - - $dt_post = new DistributorPost( 1 ); - $post_data_actual = $dt_post->post_data(); - - $post_data_expected = array( - 'title' => 'Test Post', - 'slug' => 'test-post', - 'type' => 'post', - 'content' => '

Test Content

', - 'excerpt' => 'Test Excerpt', - 'parent' => 0, - 'status' => 'publish', - 'date' => '2020-01-01 00:00:00', - 'date_gmt' => '2020-01-01 00:00:00', - 'distributor_media' => array(), - 'distributor_terms' => array( - 'category' => array(), - 'post_tag' => array(), - ), - 'distributor_meta' => array(), - 'distributor_original_site_name' => 'Test Internal Origin', - 'distributor_original_site_url' => 'http://test.com', - 'distributor_original_post_url' => 'http://example.org/?p=1', - 'distributor_original_post_id' => 1, - ); - - $this->assertSame( $post_data_expected, $post_data_actual, 'Post data is not in an expected form' ); - - // Make sure it looks good to insert. - $to_insert_actual = $dt_post->to_insert(); - $to_insert_expected = array( - 'post_title' => 'Test Post', - 'post_name' => 'test-post', - 'post_type' => 'post', - 'post_content' => '

Test Content

', - 'post_excerpt' => 'Test Excerpt', - 'post_status' => 'publish', - 'terms' => array( - 'category' => array(), - 'post_tag' => array(), - ), - 'meta' => array(), - 'media' => array(), - 'post_author' => 1, - 'meta_input' => array( - 'dt_original_post_id' => 1, - 'dt_original_post_url' => 'http://example.org/?p=1', - ), - ); - - $this->assertSame( $to_insert_expected, $to_insert_actual, 'Insert post data is not in an expected form' ); - - // Make sure it looks correct for a REST request. - $to_rest_actual = $dt_post->to_rest(); - $to_rest_expected = array( - 'title' => 'Test Post', - 'slug' => 'test-post', - 'type' => 'post', - 'content' => '

Test Content

', - 'excerpt' => 'Test Excerpt', - 'status' => 'publish', - 'distributor_media' => array(), - 'distributor_terms' => array( - 'category' => array(), - 'post_tag' => array(), - ), - 'distributor_meta' => array(), - 'distributor_original_site_name' => 'Test Internal Origin', - 'distributor_original_site_url' => 'http://test.com', - 'distributor_original_post_url' => 'http://example.org/?p=1', - 'distributor_remote_post_id' => 1, - 'distributor_raw_content' => '

Test Content

', - ); - - $this->assertSame( $to_rest_expected, $to_rest_actual, 'REST API data is not in an expected form' ); + public function test_post_data_with_blocks(): void { + $this->markTestIncomplete(); } /** @@ -2130,22 +403,8 @@ public function test_post_data_with_blocks() { * * @covers ::get_canonical_url() */ - public function test_get_canonical_url() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_blog_id' => array( '2' ), - 'dt_syndicate_time' => array ( '1670383190' ), - 'dt_original_post_url' => array ( 'http://origin.example.org/?p=10' ), - ) - ); - - $dt_post = new DistributorPost( 1 ); - $canonical_url_actual = $dt_post->get_canonical_url(); - $canonical_url_expected = 'http://origin.example.org/?p=10'; - - $this->assertSame( $canonical_url_expected, $canonical_url_actual ); + public function test_get_canonical_url(): void { + $this->markTestIncomplete(); } /** @@ -2153,30 +412,8 @@ public function test_get_canonical_url() { * * @covers ::get_canonical_url() */ - public function test_get_canonical_url_unlinked() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_blog_id' => array( '2' ), - 'dt_syndicate_time' => array ( '1670383190' ), - 'dt_original_post_url' => array ( 'http://origin.example.org/?p=10' ), - 'dt_unlinked' => array ( '1' ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://distributed.example.org/?p=1', - ) - ); - - $dt_post = new DistributorPost( 1 ); - $canonical_url_actual = $dt_post->get_canonical_url(); - $canonical_url_expected = 'http://distributed.example.org/?p=1'; - - $this->assertSame( $canonical_url_expected, $canonical_url_actual ); + public function test_get_canonical_url_unlinked(): void { + $this->markTestIncomplete(); } /** @@ -2184,22 +421,8 @@ public function test_get_canonical_url_unlinked() { * * @covers ::get_canonical_url() */ - public function test_get_canonical_url_source() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( array() ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://source.example.org/?p=1', - ) - ); - - $dt_post = new DistributorPost( 1 ); - $canonical_url_actual = $dt_post->get_canonical_url(); - $canonical_url_expected = 'http://source.example.org/?p=1'; - - $this->assertSame( $canonical_url_expected, $canonical_url_actual ); + public function test_get_canonical_url_source(): void { + $this->markTestIncomplete(); } /** @@ -2207,33 +430,8 @@ public function test_get_canonical_url_source() { * * @covers ::get_author_name() */ - public function test_get_author_name() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pushed Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=10' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '1' ), - 'dt_original_source_id' => array( '2' ), - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); - - $dt_post = new DistributorPost( 1 ); - $author_name_actual = $dt_post->get_author_name(); - $author_name_expected = 'Test External, Pushed Origin'; - - $this->assertSame( $author_name_expected, $author_name_actual ); + public function test_get_author_name(): void { + $this->markTestIncomplete(); } /** @@ -2241,45 +439,8 @@ public function test_get_author_name() { * * @covers ::get_author_name() */ - public function test_get_author_name_without_override() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pushed Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=10' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '1' ), - 'dt_original_source_id' => array( '2' ), - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array( 'override_author_byline' => false ), - ) - ); - - \WP_Mock::userFunction( - 'get_the_author_meta', - array( - 'return' => 'Distributed site author name', - ) - ); - - $dt_post = new DistributorPost( 1 ); - $author_name_actual = $dt_post->get_author_name(); - $author_name_expected = 'Distributed site author name'; - - $this->assertSame( $author_name_expected, $author_name_actual, 'Author name expected to point to distributed site.' ); - - $author_name_actual = $dt_post->get_author_name( 'Filtered author name' ); - $author_name_expected = 'Filtered author name'; - - $this->assertSame( $author_name_expected, $author_name_actual, 'Author name expected to use filtered value.' ); + public function test_get_author_name_without_override(): void { + $this->markTestIncomplete(); } /** @@ -2287,37 +448,8 @@ public function test_get_author_name_without_override() { * * @covers ::get_author_name() */ - public function test_get_author_name_unlinked() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_blog_id' => array( '2' ), - 'dt_syndicate_time' => array ( '1670383190' ), - 'dt_original_post_url' => array ( 'http://origin.example.org/?p=10' ), - 'dt_unlinked' => array ( '1' ), - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); - - \WP_Mock::userFunction( - 'get_the_author_meta', - array( - 'return' => 'Unlinked author name', - ) - ); - - $dt_post = new DistributorPost( 1 ); - $author_name_actual = $dt_post->get_author_name(); - $author_name_expected = 'Unlinked author name'; - - $this->assertSame( $author_name_expected, $author_name_actual ); + public function test_get_author_name_unlinked(): void { + $this->markTestIncomplete(); } /** @@ -2325,36 +457,8 @@ public function test_get_author_name_unlinked() { * * @covers ::get_author_name() */ - public function test_get_author_name_source() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( array() ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://source.example.org/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'get_the_author_meta', - array( - 'return' => 'Original site author name', - ) - ); - - $dt_post = new DistributorPost( 1 ); - $author_name_actual = $dt_post->get_author_name(); - $author_name_expected = 'Original site author name'; - - $this->assertSame( $author_name_expected, $author_name_actual ); + public function test_get_author_name_source(): void { + $this->markTestIncomplete(); } /** @@ -2362,33 +466,8 @@ public function test_get_author_name_source() { * * @covers ::get_author_link() */ - public function test_get_author_link() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pushed Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=10' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '1' ), - 'dt_original_source_id' => array( '2' ), - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); - - $dt_post = new DistributorPost( 1 ); - $author_link_actual = $dt_post->get_author_link(); - $author_link_expected = 'http://origin.example.org/'; - - $this->assertSame( $author_link_expected, $author_link_actual ); + public function test_get_author_link(): void { + $this->markTestIncomplete(); } /** @@ -2396,45 +475,8 @@ public function test_get_author_link() { * * @covers ::get_author_link() */ - public function test_get_author_link_without_override() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pushed Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=10' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '1' ), - 'dt_original_source_id' => array( '2' ), - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array( 'override_author_byline' => false ), - ) - ); - - \WP_Mock::userFunction( - 'get_author_posts_url', - array( - 'return' => 'http://destination.example.org/author/author-name/', - ) - ); - - $dt_post = new DistributorPost( 1 ); - $author_link_actual = $dt_post->get_author_link(); - $author_link_expected = 'http://destination.example.org/author/author-name/'; - - $this->assertSame( $author_link_expected, $author_link_actual, 'Author link should be the local author link' ); - - $author_link_actual = $dt_post->get_author_link( 'http://pre-filtered.example.org/' ); - $author_link_expected = 'http://pre-filtered.example.org/'; - - $this->assertSame( $author_link_expected, $author_link_actual, 'Author link should be use prefiltered value.' ); + public function test_get_author_link_without_override(): void { + $this->markTestIncomplete(); } /** @@ -2442,37 +484,8 @@ public function test_get_author_link_without_override() { * * @covers ::get_author_link() */ - public function test_get_author_link_unlinked() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_blog_id' => array( '2' ), - 'dt_syndicate_time' => array ( '1670383190' ), - 'dt_original_post_url' => array ( 'http://origin.example.org/?p=10' ), - 'dt_unlinked' => array ( '1' ), - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); - - \WP_Mock::userFunction( - 'get_author_posts_url', - array( - 'return' => 'http://destination.example.org/author/unlinked-author-name/', - ) - ); - - $dt_post = new DistributorPost( 1 ); - $author_link_actual = $dt_post->get_author_link(); - $author_link_expected = 'http://destination.example.org/author/unlinked-author-name/'; - - $this->assertSame( $author_link_expected, $author_link_actual ); + public function test_get_author_link_unlinked(): void { + $this->markTestIncomplete(); } /** @@ -2480,35 +493,34 @@ public function test_get_author_link_unlinked() { * * @covers ::get_author_link() */ - public function test_get_author_link_source() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( array() ); + public function test_get_author_link_source(): void { + $this->markTestIncomplete(); + } - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://source.example.org/?p=1', - ) - ); + /** + * This method provides data for the internal connection tests. + */ + public function internal_connection_data_provider(): array { + $data = new \stdClass(); - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); + $main_blog_id = get_site()->id; - \WP_Mock::userFunction( - 'get_author_posts_url', - array( - 'return' => 'http://source.example.org/author/original-author-name/', - ) - ); + // Create a new blog. + $data->blog = self::factory()->blog->create_and_get( array( + 'blog_id' => 2, + 'domain' => 'origin.example.org', + ) ); + + // Create a new post on the new blog. + switch_to_blog( $data->blog->blog_id ); + + $post_generator = new PostGenerator(); + $data->post = $post_generator->create()->getPost(); + $data->post_url = get_permalink( $data->post->ID ); - $dt_post = new DistributorPost( 1 ); - $author_link_actual = $dt_post->get_author_link(); - $author_link_expected = 'http://source.example.org/author/original-author-name/'; + // Reset to main blog. + switch_to_blog( $main_blog_id ); - $this->assertSame( $author_link_expected, $author_link_actual ); + return array( array( $data ) ); } } diff --git a/tests/php/EnqueueScriptTest.php b/tests/php/EnqueueScriptTest.php index 180ac3101..1c3496cdd 100644 --- a/tests/php/EnqueueScriptTest.php +++ b/tests/php/EnqueueScriptTest.php @@ -1,13 +1,13 @@ markTestIncomplete(); } diff --git a/tests/php/ExternalConnectionTest.php b/tests/php/ExternalConnectionTest.php index 747e6fd34..629a133f2 100644 --- a/tests/php/ExternalConnectionTest.php +++ b/tests/php/ExternalConnectionTest.php @@ -1,152 +1,80 @@ register( '\TestExternalConnection' ); - - \WP_Mock::userFunction( - 'get_post_meta', array( - 'times' => 1, - 'args' => array( \WP_Mock\Functions::type( 'int' ), 'dt_external_connection_type', true ), - 'return' => false, - ) - ); - - \WP_Mock::userFunction( - 'get_post_meta', array( - 'times' => 1, - 'args' => array( \WP_Mock\Functions::type( 'int' ), 'dt_external_connection_url', true ), - 'return' => false, - ) - ); - - \WP_Mock::userFunction( - 'get_post_meta', array( - 'times' => 1, - 'args' => array( \WP_Mock\Functions::type( 'int' ), 'dt_external_connection_auth', true ), - 'return' => false, - ) - ); - - \WP_Mock::userFunction( - 'get_the_title', array( - 'times' => 1, - 'args' => 1, - 'return' => '', - ) - ); - - // Test non-existent connection ID + public function test_instantiate_fail_type(): void { + /* @var WP_Error $external_connection */ $external_connection = ExternalConnection::instantiate( 1 ); - $this->assertEquals( 'external_connection_not_found', $external_connection->code ); + $this->assertArrayHasKey( 'external_connection_not_found', $external_connection->errors ); } /** * Text External Connection instantiation failure on not registered * * @since 0.8 - * @group ExternalConnection - * @runInSeparateProcess + * @group ExternalConnection */ - public function test_instantiate_fail_not_registered() { - Connections::factory()->register( '\TestExternalConnection' ); - - \WP_Mock::userFunction( - 'get_post_meta', array( - 'times' => 1, - 'args' => array( \WP_Mock\Functions::type( 'int' ), 'dt_external_connection_type', true ), - 'return' => 'fake', - ) + public function test_instantiate_fail_not_registered(): void { + $connectionId = ExternalConnectionPostGenerator::create( + [], // Use default post data. + [ 'dt_external_connection_type' => 'wp_non_existing_connection_type' ] // Set connection type. ); - \WP_Mock::userFunction( - 'get_post_meta', array( - 'times' => 1, - 'args' => array( \WP_Mock\Functions::type( 'int' ), 'dt_external_connection_url', true ), - 'return' => 'fake', - ) - ); + /* @var WP_Error $external_connection */ + $external_connection = ExternalConnection::instantiate( $connectionId ); - \WP_Mock::userFunction( - 'get_post_meta', array( - 'times' => 1, - 'args' => array( \WP_Mock\Functions::type( 'int' ), 'dt_external_connection_auth', true ), - 'return' => false, - ) - ); + $this->assertArrayHasKey( 'no_external_connection_type', $external_connection->errors ); + } - \WP_Mock::userFunction( - 'get_the_title', array( - 'times' => 1, - 'args' => 1, - 'return' => '', - ) - ); + /** + * Text External Connection instantiation success + * + * @since 0.8 + * @group ExternalConnection + */ + public function test_instantiate_success(): void { + Connections::factory()->register( WordPressExternalConnection::class ); + $connectionId = ExternalConnectionPostGenerator::create(); // Test non-existent connection ID - $external_connection = ExternalConnection::instantiate( 1 ); + $external_connection = ExternalConnection::instantiate( $connectionId ); - $this->assertEquals( 'no_external_connection_type', $external_connection->code ); + $this->assertTrue( is_a( $external_connection, ExternalConnection::class ) ); } /** * Text External Connection instantiation success * * @since 0.8 - * @group ExternalConnection - * @runInSeparateProcess + * @group ExternalConnection */ - public function test_instantiate_success() { - Connections::factory()->register( '\TestExternalConnection' ); + public function test_instantiate_success_customer_connection_type(): void { + Connections::factory()->register( TestExternalConnection::class ); - \WP_Mock::userFunction( - 'get_post_meta', array( - 'times' => 1, - 'args' => array( \WP_Mock\Functions::type( 'int' ), 'dt_external_connection_type', true ), - 'return' => 'test-external-connection', - ) - ); - - \WP_Mock::userFunction( - 'get_post_meta', array( - 'times' => 1, - 'args' => array( \WP_Mock\Functions::type( 'int' ), 'dt_external_connection_url', true ), - 'return' => 'fake', - ) - ); - - \WP_Mock::userFunction( - 'get_post_meta', array( - 'times' => 1, - 'args' => array( \WP_Mock\Functions::type( 'int' ), 'dt_external_connection_auth', true ), - 'return' => array(), - ) - ); - - \WP_Mock::userFunction( - 'get_the_title', array( - 'times' => 1, - 'args' => 1, - 'return' => '', - ) + $connectionId = ExternalConnectionPostGenerator::create( + [], // Use default post data. + [ 'dt_external_connection_type' => TestExternalConnection::$slug ] // Set connection type. ); // Test non-existent connection ID - $external_connection = ExternalConnection::instantiate( 1 ); + $external_connection = ExternalConnection::instantiate( $connectionId ); - $this->assertTrue( is_a( $external_connection, '\Distributor\ExternalConnection' ) ); + $this->assertTrue( is_a( $external_connection, TestExternalConnection::class ) ); } } diff --git a/tests/php/HooksTest.php b/tests/php/HooksTest.php index 2c35326d4..f77a71f1f 100644 --- a/tests/php/HooksTest.php +++ b/tests/php/HooksTest.php @@ -1,128 +1,17 @@ 1, - ] - ); - - // Return voids. - \WP_Mock::userFunction( '_prime_post_caches' ); - \WP_Mock::userFunction( 'update_object_term_cache' ); - \WP_Mock::userFunction( 'update_postmeta_cache' ); - } - - /** - * Helper function to mock get_post. - */ - public function setup_post_mock( $post_overrides = array() ) { - $defaults = array( - 'ID' => 1, - 'post_title' => 'Test Post', - 'post_content' => 'Test Content', - 'post_excerpt' => 'Test Excerpt', - 'post_status' => 'publish', - 'post_type' => 'post', - 'post_author' => 1, - 'post_date' => '2020-01-01 00:00:00', - 'post_date_gmt' => '2020-01-01 00:00:00', - 'post_modified' => '2020-01-01 00:00:00', - 'post_modified_gmt' => '2020-01-01 00:00:00', - 'post_parent' => 0, - 'post_mime_type' => '', - 'comment_count' => 0, - 'comment_status' => 'open', - 'ping_status' => 'open', - 'guid' => 'http://example.org/?p=1', - 'menu_order' => 0, - 'pinged' => '', - 'to_ping' => '', - 'post_password' => '', - 'post_name' => 'test-post', - 'post_content_filtered' => '', - ); - - $post = array_merge( $defaults, $post_overrides ); - - - \WP_Mock::userFunction( - 'get_post', - array( - 'return' => (object) $post, - ) - ); - } - - /** - * Helper function to mock get_post_meta. - */ - public function setup_post_meta_mock( $post_meta ) { - $get_post_meta = function( $post_id, $key = '', $single = false ) use ( $post_meta ) { - if ( empty( $key ) ) { - return $post_meta; - } - - if ( isset( $post_meta[ $key ] ) ) { - if ( $single ) { - return $post_meta[ $key ][0]; - } - return $post_meta[ $key ]; - } - - return ''; - }; - - \WP_Mock::userFunction( - 'get_post_meta', - array( - 'return' => $get_post_meta, - ) - ); - } - /** * Test get_canonical_url * * @since 2.0.0 */ - public function test_get_canonical_url_source() { - $this->setup_post_mock(); - $this->setup_post_meta_mock(array()); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - $actual = Hooks\get_canonical_url( 'https://example.com/?p=1', (object) array( 'ID' => 1 ) ); - $this->assertSame( 'https://example.com/?p=1', $actual ); + public function test_get_canonical_url_source(): void { + $this->markTestIncomplete(); } /** @@ -130,37 +19,8 @@ public function test_get_canonical_url_source() { * * @since 2.0.0 */ - public function test_get_canonical_url_external_pushed() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pushed Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=10' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '1' ), - 'dt_original_source_id' => array( '2' ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - $actual = Hooks\get_canonical_url( 'https://example.com/?p=1', (object) array( 'ID' => 1 ) ); - $this->assertSame( 'http://origin.example.org/?p=10', $actual ); + public function test_get_canonical_url_external_pushed(): void { + $this->markTestIncomplete(); } /** @@ -168,37 +28,8 @@ public function test_get_canonical_url_external_pushed() { * * @since 2.0.0 */ - public function test_get_canonical_url_external_pulled() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pulled Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=11' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '' ), - 'dt_original_source_id' => array( '3' ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - $actual = Hooks\get_canonical_url( 'https://example.com/?p=1', (object) array( 'ID' => 1 ) ); - $this->assertSame( 'http://origin.example.org/?p=11', $actual ); + public function test_get_canonical_url_external_pulled(): void { + $this->markTestIncomplete(); } /** @@ -206,33 +37,8 @@ public function test_get_canonical_url_external_pulled() { * * @since 2.0.0 */ - public function test_get_canonical_url_internal() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_blog_id' => array( '2' ), - 'dt_syndicate_time' => array ( '1670383190' ), - 'dt_original_post_url' => array ( 'http://origin.example.org/?p=12' ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - $actual = Hooks\get_canonical_url( 'https://example.com/?p=1', (object) array( 'ID' => 1 ) ); - $this->assertSame( 'http://origin.example.org/?p=12', $actual ); + public function test_get_canonical_url_internal(): void { + $this->markTestIncomplete(); } /** @@ -240,26 +46,8 @@ public function test_get_canonical_url_internal() { * * @since 2.0.0 */ - public function test_wpseo_canonical_source() { - $this->setup_post_mock(); - $this->setup_post_meta_mock(array()); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - $actual = Hooks\wpseo_canonical( 'https://example.com/?p=1' ); - $this->assertSame( 'https://example.com/?p=1', $actual ); + public function test_wpseo_canonical_source(): void { + $this->markTestIncomplete(); } /** @@ -267,37 +55,8 @@ public function test_wpseo_canonical_source() { * * @since 2.0.0 */ - public function test_wpseo_canonical_external_pushed() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pushed Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=10' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '1' ), - 'dt_original_source_id' => array( '2' ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - $actual = Hooks\wpseo_canonical( 'https://example.com/?p=1' ); - $this->assertSame( 'http://origin.example.org/?p=10', $actual ); + public function test_wpseo_canonical_external_pushed(): void { + $this->markTestIncomplete(); } /** @@ -305,37 +64,8 @@ public function test_wpseo_canonical_external_pushed() { * * @since 2.0.0 */ - public function test_wpseo_canonical_external_pulled() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pulled Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=11' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '' ), - 'dt_original_source_id' => array( '3' ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - $actual = Hooks\wpseo_canonical( 'https://example.com/?p=1' ); - $this->assertSame( 'http://origin.example.org/?p=11', $actual ); + public function test_wpseo_canonical_external_pulled(): void { + $this->markTestIncomplete(); } /** @@ -344,32 +74,7 @@ public function test_wpseo_canonical_external_pulled() { * @since 2.0.0 */ public function test_wpseo_canonical_internal() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_blog_id' => array( '2' ), - 'dt_syndicate_time' => array ( '1670383190' ), - 'dt_original_post_url' => array ( 'http://origin.example.org/?p=12' ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - $actual = Hooks\wpseo_canonical( 'https://example.com/?p=1' ); - $this->assertSame( 'http://origin.example.org/?p=12', $actual ); + $this->markTestIncomplete(); } /** @@ -377,26 +82,8 @@ public function test_wpseo_canonical_internal() { * * @since 2.0.0 */ - public function test_wpseo_opengraph_url_source() { - $this->setup_post_mock(); - $this->setup_post_meta_mock(array()); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - $actual = Hooks\wpseo_opengraph_url( 'https://example.com/?p=1' ); - $this->assertSame( 'https://example.com/?p=1', $actual ); + public function test_wpseo_opengraph_url_source(): void { + $this->markTestIncomplete(); } /** @@ -404,37 +91,8 @@ public function test_wpseo_opengraph_url_source() { * * @since 2.0.0 */ - public function test_wpseo_opengraph_url_external_pushed() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pushed Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=10' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '1' ), - 'dt_original_source_id' => array( '2' ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - $actual = Hooks\wpseo_opengraph_url( 'https://example.com/?p=1' ); - $this->assertSame( 'https://example.com/?p=1', $actual ); + public function test_wpseo_opengraph_url_external_pushed(): void { + $this->markTestIncomplete(); } /** @@ -442,37 +100,8 @@ public function test_wpseo_opengraph_url_external_pushed() { * * @since 2.0.0 */ - public function test_wpseo_opengraph_url_external_pulled() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pulled Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=11' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '' ), - 'dt_original_source_id' => array( '3' ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - $actual = Hooks\wpseo_opengraph_url( 'https://example.com/?p=1' ); - $this->assertSame( 'https://example.com/?p=1', $actual ); + public function test_wpseo_opengraph_url_external_pulled(): void { + $this->markTestIncomplete(); } /** @@ -480,33 +109,8 @@ public function test_wpseo_opengraph_url_external_pulled() { * * @since 2.0.0 */ - public function test_wpseo_opengraph_url_internal() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_blog_id' => array( '2' ), - 'dt_syndicate_time' => array ( '1670383190' ), - 'dt_original_post_url' => array ( 'http://origin.example.org/?p=12' ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - $actual = Hooks\wpseo_opengraph_url( 'https://example.com/?p=1' ); - $this->assertSame( 'https://example.com/?p=1', $actual ); + public function test_wpseo_opengraph_url_internal(): void { + $this->markTestIncomplete(); } /** @@ -514,33 +118,8 @@ public function test_wpseo_opengraph_url_internal() { * * @since 2.0.0 */ - public function test_filter_the_author_source() { - $this->setup_post_mock(); - $this->setup_post_meta_mock(array()); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); - - $actual = Hooks\filter_the_author( 'Alexander Hamilton' ); - $this->assertSame( 'Alexander Hamilton', $actual ); + public function test_filter_the_author_source(): void { + $this->markTestIncomplete(); } /** @@ -548,44 +127,8 @@ public function test_filter_the_author_source() { * * @since 2.0.0 */ - public function test_filter_the_author_external_pushed() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pushed Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=10' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '1' ), - 'dt_original_source_id' => array( '2' ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); - - $actual = Hooks\filter_the_author( 'George Washington' ); - $this->assertSame( 'Test External, Pushed Origin', $actual ); + public function test_filter_the_author_external_pushed(): void { + $this->markTestIncomplete(); } /** @@ -593,44 +136,8 @@ public function test_filter_the_author_external_pushed() { * * @since 2.0.0 */ - public function test_filter_the_author_external_pulled() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pulled Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=11' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '' ), - 'dt_original_source_id' => array( '3' ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); - - $actual = Hooks\filter_the_author( 'James Madison' ); - $this->assertSame( 'Test External, Pulled Origin', $actual ); + public function test_filter_the_author_external_pulled(): void { + $this->markTestIncomplete(); } /** @@ -638,71 +145,8 @@ public function test_filter_the_author_external_pulled() { * * @since 2.0.0 */ - public function test_filter_the_author_internal() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_blog_id' => array( '2' ), - 'dt_syndicate_time' => array ( '1670383190' ), - 'dt_original_post_url' => array ( 'http://origin.example.org/?p=12' ), - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); - - \WP_Mock::userFunction( - 'get_current_blog_id', - array( - 'return' => 1, - ) - ); - \WP_Mock::userFunction( 'switch_to_blog' ); - \WP_Mock::userFunction( 'restore_current_blog' ); - - \WP_Mock::userFunction( - 'get_bloginfo', - array( - 'return' => function( $info ) { - switch ( $info ) { - case 'name': - return 'Test Internal Origin'; - default: - return ''; - } - }, - ) - ); - - // Generic values for the origin site. - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://origin.example.org/?p=10', - ) - ); - - \WP_Mock::userFunction( - 'home_url', - array( - 'return' => 'http://origin.example.org/', - ) - ); - - $actual = Hooks\filter_the_author( 'Aaron Burr' ); - $this->assertSame( 'Test Internal Origin', $actual ); + public function test_filter_the_author_internal(): void { + $this->markTestIncomplete(); } /** @@ -710,36 +154,8 @@ public function test_filter_the_author_internal() { * * @since 2.0.0 */ - public function test_get_the_author_display_name_source() { - $this->setup_post_mock(); - $this->setup_post_meta_mock(array()); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); - - $actual = Hooks\get_the_author_display_name( 'Alexander Hamilton', 1, false ); - $this->assertSame( 'Alexander Hamilton', $actual, 'Unexpected value when 1 current post author.' ); - - $actual = Hooks\get_the_author_display_name( 'Alexander Hamilton', 1, 1 ); - $this->assertSame( 'Alexander Hamilton', $actual, 'Unexpected value when getting specific author.' ); + public function test_get_the_author_display_name_source(): void { + $this->markTestIncomplete(); } /** @@ -747,12 +163,8 @@ public function test_get_the_author_display_name_source() { * * @since 2.0.0 */ - public function test_get_the_author_display_name_no_post() { - $actual = Hooks\get_the_author_display_name( 'George Washington', 1, false ); - $this->assertSame( 'George Washington', $actual, 'Unexpected value when 1 current post author.' ); - - $actual = Hooks\get_the_author_display_name( 'George Washington', 1, 1 ); - $this->assertSame( 'George Washington', $actual, 'Unexpected value when getting specific author.' ); + public function test_get_the_author_display_name_no_post(): void { + $this->markTestIncomplete(); } /** @@ -760,44 +172,8 @@ public function test_get_the_author_display_name_no_post() { * * @since 2.0.0 */ - public function test_get_the_author_display_name_external_pushed() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pushed Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=10' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '1' ), - 'dt_original_source_id' => array( '2' ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); - - $actual = Hooks\get_the_author_display_name( 'George Washington', 1, false ); - $this->assertSame( 'Test External, Pushed Origin', $actual, 'Unexpected value when getting current post author.' ); + public function test_get_the_author_display_name_external_pushed(): void { + $this->markTestIncomplete(); } /** @@ -805,44 +181,8 @@ public function test_get_the_author_display_name_external_pushed() { * * @since 2.0.0 */ - public function test_get_the_author_display_name_external_pulled() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_site_name' => array( 'Test External, Pulled Origin' ), - 'dt_original_site_url' => array( 'http://origin.example.org/' ), - 'dt_original_post_url' => array( 'http://origin.example.org/?p=11' ), - 'dt_subscription_signature' => array( 'abcdefghijklmnopqrstuvwxyz' ), - 'dt_syndicate_time' => array( '1670384223' ), - 'dt_full_connection' => array( '' ), - 'dt_original_source_id' => array( '3' ), - ) - ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'https://example.com/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); - - $actual = Hooks\get_the_author_display_name( 'James Madison', 1, false ); - $this->assertSame( 'Test External, Pulled Origin', $actual, 'Unexpected value when getting current post author.' ); + public function test_get_the_author_display_name_external_pulled(): void { + $this->markTestIncomplete(); } /** @@ -850,70 +190,7 @@ public function test_get_the_author_display_name_external_pulled() { * * @since 2.0.0 */ - public function test_get_the_author_display_name_internal() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( - array ( - 'dt_original_post_id' => array( '10' ), - 'dt_original_blog_id' => array( '2' ), - 'dt_syndicate_time' => array ( '1670383190' ), - 'dt_original_post_url' => array ( 'http://origin.example.org/?p=12' ), - ) - ); - - \WP_Mock::userFunction( - 'is_singular', - array( - 'return' => true, - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); - - \WP_Mock::userFunction( - 'get_current_blog_id', - array( - 'return' => 1, - ) - ); - \WP_Mock::userFunction( 'switch_to_blog' ); - \WP_Mock::userFunction( 'restore_current_blog' ); - - \WP_Mock::userFunction( - 'get_bloginfo', - array( - 'return' => function( $info ) { - switch ( $info ) { - case 'name': - return 'Test Internal Origin'; - default: - return ''; - } - }, - ) - ); - - // Generic values for the origin site. - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://origin.example.org/?p=10', - ) - ); - - \WP_Mock::userFunction( - 'home_url', - array( - 'return' => 'http://origin.example.org/', - ) - ); - - $actual = Hooks\get_the_author_display_name( 'Aaron Burr', 1, false ); - $this->assertSame( 'Test Internal Origin', $actual, 'Unexpected value when getting current post author.' ); + public function test_get_the_author_display_name_internal(): void { + $this->markTestIncomplete(); } } diff --git a/tests/php/Mocks/TestExternalConnection.php b/tests/php/Mocks/TestExternalConnection.php new file mode 100644 index 000000000..dd5f014a7 --- /dev/null +++ b/tests/php/Mocks/TestExternalConnection.php @@ -0,0 +1,27 @@ +site_obj = \Mockery::mock( - '\WP_Site', [ - 'args' => 1, - 'return' => '', - ] - ); - - $this->connection_obj = new NetworkSiteConnection( $this->site_obj ); - } + parent::setUp(); - /** - * Helper function to mock get_post_meta. - */ - public function setup_post_meta_mock( $post_meta ) { - $get_post_meta = function( $post_id, $key = '', $single = false ) use ( $post_meta ) { - if ( empty( $key ) ) { - return $post_meta; - } - - if ( isset( $post_meta[ $key ] ) ) { - if ( $single ) { - return $post_meta[ $key ][0]; - } - return $post_meta[ $key ]; - } + // Create a new blog. + $data = new \stdClass(); + $data->blog = self::factory()->blog->create_and_get( array( + 'blog_id' => 2, + 'domain' => 'origin.example.org', + ) ); - return ''; - }; + // $this->site_obj = get_site(); + $this->site_obj = $data->blog; - \WP_Mock::userFunction( - 'get_post_meta', - array( - 'return' => $get_post_meta, - ) - ); + $this->connection_obj = new NetworkSiteConnection( $this->site_obj ); // Setting a connection for a second site. } + // public function + /** - * Push returns an post ID on success instance of WP Error on failure. + * Push returns an post array on success, Instance of WP Error on failure. * * @since 0.8 - * @group NetworkSiteConnection - * @runInSeparateProcess + * @group NetworkSiteConnection */ - public function test_push() { - // There is no post meta to mock for a source post. - $this->setup_post_meta_mock( array() ); - - \WP_Mock::userFunction( - 'get_post', [ - 'return' => (object) [ - 'ID' => 111, - 'post_content' => '', - 'post_excerpt' => '', - 'post_type' => '', - 'post_name' => '', - 'post_status' => 'publish', - 'post_date' => '2020-01-01 00:00:00', - 'post_date_gmt' => '2020-01-01 00:00:00', - ], - ] - ); - - \WP_Mock::userFunction( - 'has_blocks', [ - 'return' => false, - ] - ); - - \WP_Mock::userFunction( - 'get_current_blog_id', [ - 'return' => 925, - ] - ); - - \WP_Mock::userFunction( - 'get_bloginfo', - array( - 'return' => function( $info ) { - switch ( $info ) { - case 'charset': - return 'UTF-8'; - case 'name': - return 'Example Dot Org'; - default: - return ''; - } - }, - ) - ); - - \WP_Mock::userFunction( 'do_action_deprecated' ); - \WP_Mock::userFunction( 'get_current_user_id' ); - \WP_Mock::userFunction( 'switch_to_blog' ); - \WP_Mock::userFunction( 'add_filter' ); - \WP_Mock::userFunction( 'restore_current_blog' ); - \WP_Mock::userFunction( 'get_the_title' ); - \WP_Mock::userFunction( 'remove_filter' ); - \WP_Mock::userFunction( 'get_option' ); - \WP_Mock::passthruFunction( 'wp_slash' ); - \WP_Mock::passthruFunction( 'absint' ); - - $this->connection_obj->site->blog_id = 2; - - $original_url = 'original url'; - $new_post_id = 123; - - \WP_Mock::userFunction( - 'use_block_editor_for_post_type', [ - 'return' => true, - ] - ); - - \WP_Mock::userFunction( - 'wp_insert_post', [ - 'times' => 1, - 'args' => [ - [ - 'post_title' => '', - 'post_name' => '', - 'post_type' => '', - 'post_content' => '', - 'post_excerpt' => '', - 'post_status' => 'publish', - 'post_author' => null, - 'meta_input' => [ - 'dt_original_post_id' => 111, - 'dt_original_post_url' => $original_url, - ], - ], - ], - 'return' => $new_post_id, - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ $new_post_id, 'dt_original_blog_id', 925 ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ $new_post_id, 'dt_syndicate_time', \WP_Mock\Functions::type( 'int' ) ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'get_permalink', [ - 'return' => $original_url, - ] - ); - - \WP_Mock::userFunction( - 'get_transient', [ - 'return' => false, - ] - ); - - \WP_Mock::userFunction( - 'wp_cache_get', - array( - 'return' => false - ) - ); - \WP_Mock::userFunction( - 'wp_cache_set', - array( - 'return' => false - ) - ); - - /** - * We will test the util prepare/set functions later - */ - \WP_Mock::userFunction( - 'get_attached_media', - array( - 'return' => array(), - ) - ); - \WP_Mock::userFunction( - 'get_post_thumbnail_id', - array( - 'return' => false, - ) - ); - - \WP_Mock::userFunction( '\Distributor\Utils\prepare_media' ); - \WP_Mock::userFunction( '\Distributor\Utils\prepare_taxonomy_terms' ); - \WP_Mock::userFunction( '\Distributor\Utils\prepare_meta' ); - \WP_Mock::userFunction( '\Distributor\Utils\set_media' ); - \WP_Mock::userFunction( '\Distributor\Utils\set_taxonomy_terms' ); - \WP_Mock::userFunction( '\Distributor\Utils\set_meta' ); - - \WP_Mock::onFilter( 'the_content' ) - ->with( '' ) - ->reply( '' ); - - \WP_Mock::expectFilterAdded( 'wp_insert_post_data', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'maybe_set_modified_date' ), 10, 2 ); - - $this->assertIsArray( $this->connection_obj->push( 1 ) ); + public function test_push(): void { + $dt_post_gen = new PostGenerator(); + $dt_post = $dt_post_gen->create()->getPost(); + // Push current site's post to the second site. + $this->assertIsArray( $this->connection_obj->push( $dt_post->ID ) ); } /** @@ -235,269 +54,73 @@ public function test_push() { * three integers. * * @since 0.8 - * @group NetworkSiteConnection - * @runInSeparateProcess + * @covers \Distributor\InternalConnections\NetworkSiteConnection::pull + * @dataProvider network_connection_data_provider + * @group NetworkSiteConnection */ - public function test_pull() { - $this->setup_post_meta_mock( array( - 'dt_connection_map' => array( array() ) - ) ); - \WP_Mock::userFunction( - 'get_bloginfo', - array( - 'return' => function( $info ) { - switch ( $info ) { - case 'charset': - return 'UTF-8'; - case 'name': - return 'Test Internal Origin'; - default: - return ''; - } - }, - ) - ); - - $this->connection_obj->site->blog_id = 2; - - $original_url = 'original url'; - - \WP_Mock::userFunction( 'switch_to_blog' ); - \WP_Mock::userFunction( 'restore_current_blog' ); - \WP_Mock::userFunction( 'get_current_blog_id' ); - \WP_Mock::userFunction( 'remove_filter' ); - \WP_Mock::passthruFunction( 'wp_slash' ); - \WP_Mock::passthruFunction( 'sanitize_url' ); - - \WP_Mock::userFunction( - 'get_post', [ - 'return' => (object) [ - 'ID' => 111, - 'post_title' => 'My post title', - 'post_name' => 'my-post-title', - 'post_type' => 'post', - 'post_status' => 'publish', - 'post_content' => 'My post content', - 'post_excerpt' => 'My post excerpt', - 'post_date' => '2020-01-01 00:00:00', - 'post_date_gmt' => '2020-01-01 00:00:00', - 'meta' => [], - ], - ] - ); - \WP_Mock::userFunction( - 'get_the_title', [ - 'return' => 'My post title', - ] - ); - \WP_Mock::userFunction( - 'has_blocks', - array( - 'return' => false, - ) - ); - \WP_Mock::userFunction( - 'get_attached_media', - array( - 'return' => array(), - ) - ); - \WP_Mock::userFunction( - 'get_post_thumbnail_id', - array( - 'return' => false, - ) - ); - \WP_Mock::userFunction( - 'get_current_user_id', [ - 'return' => 1, - ] - ); - - \WP_Mock::userFunction( - 'get_permalink', [ - 'return' => $original_url, - ] - ); - - \WP_Mock::userFunction( - 'wp_insert_post', [ - 'return' => 123, - ] + public function test_pull( $data ): void { + $items = array( + array( 'remote_post_id' => $data->post->ID ), ); - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ \WP_Mock\Functions::type( 'int' ), 'dt_original_post_id', 111 ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ \WP_Mock\Functions::type( 'int' ), 'dt_original_blog_id', 2 ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ \WP_Mock\Functions::type( 'int' ), 'dt_original_post_url', $original_url ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ \WP_Mock\Functions::type( 'int' ), 'dt_syndicate_time', \WP_Mock\Functions::type( 'int' ) ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ \WP_Mock\Functions::type( 'int' ), 'dt_connection_map', \WP_Mock\Functions::type( 'array' ) ], - ] - ); - - /** - * We will test the util prepare/set functions later - */ - \WP_Mock::userFunction( '\Distributor\Utils\prepare_media' ); - \WP_Mock::userFunction( '\Distributor\Utils\prepare_taxonomy_terms' ); - \WP_Mock::userFunction( '\Distributor\Utils\prepare_meta' ); - \WP_Mock::userFunction( '\Distributor\Utils\set_media' ); - \WP_Mock::userFunction( '\Distributor\Utils\set_taxonomy_terms' ); - \WP_Mock::userFunction( '\Distributor\Utils\set_meta' ); - - $this->assertTrue( count( $this->connection_obj->pull( [ [ 'remote_post_id' => 2 ] ] ) ) === 1 ); - + $connection_obj = new NetworkSiteConnection( $data->blog ); + $this->assertIsArray( $connection_obj->pull( $items ) ); } /** * Verifies that when passed no id the request can still return items * * @since 0.8 + * @covers \Distributor\InternalConnections\NetworkSiteConnection::remote_get * @group NetworkSiteConnection - * @runInSeparateProcess */ - public function test_remote_get_empty_id() { - - $this->connection_obj->site->blog_id = 321; - - \WP_Mock::userFunction( 'get_option' ); - \WP_Mock::userFunction( 'switch_to_blog' ); - \WP_Mock::userFunction( 'restore_current_blog' ); - \WP_Mock::userFunction( 'get_permalink' ); - \WP_Mock::userFunction( 'get_post_meta' ); - \WP_Mock::userFunction( '\Distributor\Utils\prepare_media' ); - \WP_Mock::userFunction( '\Distributor\Utils\prepare_taxonomy_terms' ); - \WP_Mock::userFunction( '\Distributor\Utils\prepare_meta' ); - + public function test_remote_get_empty_id(): void { $this->assertArrayHasKey( 'total_items', $this->connection_obj->remote_get() ); - } /** * Verifies that the remote_get method returns an array containing the post title. * * @since 0.8 + * @covers \Distributor\InternalConnections\NetworkSiteConnection::remote_get + * @dataProvider network_connection_data_provider * @group NetworkSiteConnection - * @runInSeparateProcess */ - public function test_remote_get() { + public function test_remote_get( $data ): void { + $connection_obj = new NetworkSiteConnection( $data->blog ); + $this->assertArrayHasKey( + 'post_title', (array) $connection_obj->remote_get( + [ + 'id' => $data->post->ID, + ] + ) + ); + } - \WP_Mock::userFunction( 'get_option' ); - \WP_Mock::userFunction( 'switch_to_blog' ); - \WP_Mock::userFunction( 'restore_current_blog' ); - \WP_Mock::userFunction( 'get_permalink' ); - \WP_Mock::userFunction( 'get_post_meta' ); - \WP_Mock::userFunction( '\Distributor\Utils\prepare_media' ); - \WP_Mock::userFunction( '\Distributor\Utils\prepare_taxonomy_terms' ); - \WP_Mock::userFunction( '\Distributor\Utils\prepare_meta' ); + /** + * This method provides data for the internal connection tests. + */ + public function network_connection_data_provider(): array { + $data = new \stdClass(); - $this->connection_obj->site->blog_id = 321; + $main_blog_id = get_site()->id; - \WP_Mock::userFunction( - 'get_post', [ - 'return' => (object) [ - 'ID' => 111, - 'post_title' => 'my title', - 'post_name' => 'my-title', - 'post_type' => 'post', - 'post_status' => 'publish', - 'post_content' => 'My post content', - 'post_excerpt' => 'My post excerpt', - 'post_date' => '2020-01-01 00:00:00', - 'post_date_gmt' => '2020-01-01 00:00:00', - ], - ] - ); + // Create a new blog. + $data->blog = self::factory()->blog->create_and_get( array( + 'blog_id' => 2, + 'domain' => 'origin.example.org', + ) ); - \WP_Mock::userFunction( - 'get_bloginfo', - array( - 'return' => function( $info ) { - switch ( $info ) { - case 'charset': - return 'UTF-8'; - case 'name': - return 'Test Internal Origin'; - default: - return ''; - } - }, - ) - ); + // Create a new post on the new blog. + switch_to_blog( $data->blog->blog_id ); - \WP_Mock::userFunction( - 'get_current_blog_id', [ - 'return' => 1, - ] - ); + $post_generator = new PostGenerator(); + $data->post = $post_generator->create()->getPost(); + $data->post_url = get_permalink( $data->post->ID ); - \WP_Mock::userFunction( - 'get_the_title', [ - 'return' => 'my title', - ] - ); - \WP_Mock::userFunction( - 'has_blocks', - array( - 'return' => false, - ) - ); - \WP_Mock::userFunction( - 'get_attached_media', - array( - 'return' => array(), - ) - ); - \WP_Mock::userFunction( - 'get_post_thumbnail_id', - array( - 'return' => false, - ) - ); - \WP_Mock::userFunction( - 'get_current_user_id', [ - 'return' => 1, - ] - ); - - $this->assertArrayHasKey( - 'post_title', (array) $this->connection_obj->remote_get( - [ - 'id' => 123, - ] - ) - ); + // Reset to main blog. + switch_to_blog( $main_blog_id ); + return array( array( $data ) ); } - } diff --git a/tests/php/SubscriptionsTest.php b/tests/php/SubscriptionsTest.php index 089599def..00c3e8483 100644 --- a/tests/php/SubscriptionsTest.php +++ b/tests/php/SubscriptionsTest.php @@ -1,9 +1,8 @@ true, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'dt_original_source_id', true ], - 'return' => null, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'dt_original_post_id', true ], - 'return' => null, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'dt_subscriptions', true ], - 'return' => [ 9, 10 ], - ] - ); - - \WP_Mock::userFunction( - 'wp_delete_post', [ - 'times' => 1, - 'args' => [ 9, true ], - ] - ); - - \WP_Mock::userFunction( - 'wp_delete_post', [ - 'times' => 1, - 'args' => [ 10, true ], - ] - ); - - \WP_Mock::passthruFunction( 'untrailingslashit' ); - - $subscription_post_id = 9; - $remote_post_id = 100; - $target_url = 'http://target'; - $signature = 'signature'; - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 2, - 'args' => [ \WP_Mock\Functions::type( 'int' ), 'dt_subscription_signature', true ], - 'return' => $signature, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 2, - 'args' => [ \WP_Mock\Functions::type( 'int' ), 'dt_subscription_remote_post_id', true ], - 'return' => $remote_post_id, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 2, - 'args' => [ \WP_Mock\Functions::type( 'int' ), 'dt_subscription_target_url', true ], - 'return' => $target_url, - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_post', [ - 'times' => 2, - 'args' => [ - $target_url . '/wp/v2/dt_subscription/receive', - [ - 'timeout' => 5, - 'blocking' => \Distributor\Utils\is_dt_debug(), - 'headers' => [ - 'X-Distributor-Version' => DT_VERSION, - ], - 'body' => [ - 'post_id' => $remote_post_id, - 'signature' => $signature, - 'original_deleted' => true, - ], - ], - ], - ] - ); - - Subscriptions\delete_subscriptions( 1 ); - - $this->assertConditionsMet(); + public function test_delete_subscribed_post(): void { + $this->markTestIncomplete(); } /** * Test delete original subscribing * * @since 1.0 - * @group Subscriptions - * @runInSeparateProcess + * @group Subscriptions */ - public function test_delete_subscribing_post() { - \WP_Mock::userFunction( - 'current_user_can', [ - 'return' => true, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'dt_original_source_id', true ], - 'return' => 5, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'dt_original_post_id', true ], - 'return' => 6, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'dt_subscriptions', true ], - 'return' => null, - ] - ); - - // Called when external connection is instantiated - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 3, - ] - ); - - \WP_Mock::userFunction( - 'get_the_title', [ - 'times' => 1, - ] - ); - - // External connection comes back WP_Error and delete_subscription isn't actually called on connection - Subscriptions\delete_subscriptions( 1 ); - - $this->assertConditionsMet(); + public function test_delete_subscribing_post(): void { + $this->markTestIncomplete(); } /** * Test send notifications when no subscriptions * * @since 1.0 - * @group Subscriptions - * @runInSeparateProcess + * @group Subscriptions */ - public function test_send_notifications_none() { - - $post = (object) [ - 'ID' => 1, - 'post_type' => 'post', - ]; - - \WP_Mock::passthruFunction( 'absint' ); - \WP_Mock::userFunction( - 'get_post', [ - 'args' => [ Functions::anyOf( $post->ID, $post ) ], - 'return' => $post, - ] - ); - - \WP_Mock::userFunction( - 'get_option', [ - 'args' => [ 'page_for_posts' ], - 'return' => 0, - ] - ); - - \WP_Mock::userFunction( - 'use_block_editor_for_post_type', [ - 'return' => false, - ] - ); - - \WP_Mock::userFunction( - 'wp_is_post_revision', [ - 'return' => false, - ] - ); - - \WP_Mock::userFunction( - 'current_user_can', [ - 'return' => true, - ] - ); - - \WP_Mock::userFunction( - 'wp_is_post_revision', [ - 'return' => false, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'dt_subscriptions', true ], - 'return' => [], - ] - ); - - Subscriptions\send_notifications( $post->ID ); - - $this->assertConditionsMet(); + public function test_send_notifications_none(): void { + $this->markTestIncomplete(); } /** * Test send notifications when the remote post does not exist, should delete local subscription * * @since 1.0 - * @group Subscriptions - * @runInSeparateProcess + * @group Subscriptions */ - public function test_send_notifications_no_remote_post() { - $post_id = 1; - $subscription_post_id = 2; - $remote_post_id = 9; - $target_url = 'http://target'; - $signature = 'signature'; - - $post = new \stdClass(); - $post->post_content = 'content'; - $post->post_excerpt = 'excerpt'; - $post->post_name = 'slug'; - $post->post_type = 'post'; - $post->ID = $post_id; - - \WP_Mock::userFunction( - 'current_user_can', [ - 'return' => true, - ] - ); - - \WP_Mock::userFunction( - 'wp_is_post_revision', [ - 'return' => false, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $post_id, 'dt_subscriptions', true ], - 'return' => [ $subscription_post_id ], - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $subscription_post_id, 'dt_subscription_signature', true ], - 'return' => $signature, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $subscription_post_id, 'dt_subscription_remote_post_id', true ], - 'return' => $remote_post_id, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $subscription_post_id, 'dt_subscription_target_url', true ], - 'return' => $target_url, - ] - ); - - \WP_Mock::passthruFunction( 'untrailingslashit' ); - - \WP_Mock::userFunction( - 'get_the_title', [ - 'return' => 'title', - ] - ); - - /** - * We will test the util prepare functions later - */ - \WP_Mock::userFunction( - '\Distributor\Utils\prepare_media', [ - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - '\Distributor\Utils\prepare_taxonomy_terms', [ - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - '\Distributor\Utils\prepare_meta', [ - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'get_post', [ - 'args' => [ Functions::anyOf( $post->ID, $post ) ], - 'return' => $post, - ] - ); - - \WP_Mock::passthruFunction( 'absint' ); - - \WP_Mock::userFunction( - 'get_option', [ - 'args' => [ 'page_for_posts' ], - 'return' => 0, - ] - ); - - \WP_Mock::userFunction( - 'use_block_editor_for_post_type', [ - 'return' => false, - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_post', [ - 'times' => 1, - 'args' => [ - $target_url . '/wp/v2/dt_subscription/receive', - [ - 'timeout' => 5, - 'body' => wp_json_encode( [ - 'post_id' => $remote_post_id, - 'signature' => $signature, - 'post_data' => [ - 'title' => 'title', - 'slug' => 'slug', - 'post_type' => 'post', - 'content' => 'content', - 'excerpt' => 'excerpt', - 'distributor_media' => null, // Accounts for https://github.com/10up/wp_mock/issues/173 - 'distributor_terms' => null, // Accounts for https://github.com/10up/wp_mock/issues/173 - 'distributor_meta' => null, // Accounts for https://github.com/10up/wp_mock/issues/173 - ] - ] ), - 'headers' => [ - 'Content-Type' => 'application/json', - 'X-Distributor-Version' => DT_VERSION, - ], - ], - ], - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_retrieve_response_code', [ - 'return' => 404, - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_retrieve_headers', [ - 'return' => [ - 'X-Distributor-Post-Deleted' => true, - ], - ] - ); - - \WP_Mock::userFunction( - 'wp_delete_post', [ - 'times' => 1, - 'args' => [ $subscription_post_id, true ], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ $post_id, 'dt_subscriptions', [] ], - ] - ); - - \WP_Mock::userFunction( - 'remove_filter', [ - 'times' => 1, - ] - ); - - \WP_Mock::userFunction( - 'get_bloginfo', [ - 'args' => 'charset', - 'return' => 'UTF-8', - ] - ); - - Subscriptions\send_notifications( $post_id ); - - $this->assertConditionsMet(); + public function test_send_notifications_no_remote_post(): void { + $this->markTestIncomplete(); } /** * Test send notifications when the remote post does exist, should NOT delete local subscription * * @since 1.0 - * @group Subscriptions - * @runInSeparateProcess + * @group Subscriptions */ - public function test_send_notifications_remote_post_exists() { - $post_id = 1; - $subscription_post_id = 2; - $remote_post_id = 9; - $target_url = 'http://target'; - $signature = 'signature'; - - $post = new \stdClass(); - $post->post_content = 'content'; - $post->post_excerpt = 'excerpt'; - $post->post_name = 'slug'; - $post->post_type = 'post'; - $post->ID = $post_id; - - \WP_Mock::userFunction( - 'current_user_can', [ - 'return' => true, - ] - ); - - \WP_Mock::userFunction( - 'wp_is_post_revision', [ - 'return' => false, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $post_id, 'dt_subscriptions', true ], - 'return' => [ $subscription_post_id ], - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $subscription_post_id, 'dt_subscription_signature', true ], - 'return' => $signature, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $subscription_post_id, 'dt_subscription_remote_post_id', true ], - 'return' => $remote_post_id, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $subscription_post_id, 'dt_subscription_target_url', true ], - 'return' => $target_url, - ] - ); - - \WP_Mock::passthruFunction( 'untrailingslashit' ); - - \WP_Mock::userFunction( - 'get_the_title', [ - 'return' => 'title', - ] - ); - - /** - * We will test the util prepare functions later - */ - \WP_Mock::userFunction( - '\Distributor\Utils\prepare_media', [ - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - '\Distributor\Utils\prepare_taxonomy_terms', [ - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - '\Distributor\Utils\prepare_meta', [ - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'get_post', [ - 'args' => [ Functions::anyOf( $post->ID, $post ) ], - 'return' => $post, - ] - ); - - \WP_Mock::passthruFunction( 'absint' ); - - \WP_Mock::userFunction( - 'get_option', [ - 'args' => [ 'page_for_posts' ], - 'return' => 0, - ] - ); - - \WP_Mock::userFunction( - 'use_block_editor_for_post_type', [ - 'return' => false, - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_post', [ - 'times' => 1, - 'args' => [ - $target_url . '/wp/v2/dt_subscription/receive', - [ - 'timeout' => 5, - 'body' => wp_json_encode( [ - 'post_id' => $remote_post_id, - 'signature' => $signature, - 'post_data' => [ - 'title' => 'title', - 'slug' => 'slug', - 'post_type' => 'post', - 'content' => 'content', - 'excerpt' => 'excerpt', - 'distributor_media' => null, // Accounts for https://github.com/10up/wp_mock/issues/173 - 'distributor_terms' => null, // Accounts for https://github.com/10up/wp_mock/issues/173 - 'distributor_meta' => null, // Accounts for https://github.com/10up/wp_mock/issues/173 - ], - ] ), - 'headers' => [ - 'Content-Type' => 'application/json', - 'X-Distributor-Version' => DT_VERSION, - ] - ], - ], - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_retrieve_response_code', [ - 'return' => 200, - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_retrieve_headers', [ - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'wp_delete_post', [ - 'times' => 0, - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 0, - ] - ); - - \WP_Mock::userFunction( - 'remove_filter', [ - 'times' => 1, - ] - ); - - \WP_Mock::userFunction( - 'get_bloginfo', [ - 'args' => 'charset', - 'return' => 'UTF-8', - ] - ); - - Subscriptions\send_notifications( $post_id ); - - $this->assertConditionsMet(); + public function test_send_notifications_remote_post_exists(): void { + $this->markTestIncomplete(); } /** @@ -624,78 +61,10 @@ public function test_send_notifications_remote_post_exists() { * remote post has subscribed to * * @since 1.0 - * @group Subscriptions - * @runInSeparateProcess + * @group Subscriptions */ public function test_create_subscription() { - $post_id = 1; - $remote_post_id = 2; - $target_url = 'http://test.com'; - $signature = '12345'; - $subscription_post_id = 3; - - \WP_Mock::passThruFunction( 'sanitize_text_field' ); - - \WP_Mock::userFunction( - 'wp_insert_post', [ - 'times' => 1, - 'return' => $subscription_post_id, - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ $subscription_post_id, 'dt_subscription_post_id', $post_id ], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ $subscription_post_id, 'dt_subscription_signature', $signature ], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ $subscription_post_id, 'dt_subscription_remote_post_id', $remote_post_id ], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ $subscription_post_id, 'dt_subscription_target_url', $target_url ], - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $post_id, 'dt_subscriptions', true ], - 'return' => [ 'sig' => 5 ], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ - $post_id, - 'dt_subscriptions', - [ - 'sig' => 5, - md5( $signature ) => $subscription_post_id, - ], - ], - ] - ); - - Subscriptions\create_subscription( $post_id, $remote_post_id, $target_url, $signature ); - - $this->assertConditionsMet(); + $this->markTestIncomplete(); } /** @@ -703,124 +72,19 @@ public function test_create_subscription() { * local post has subscribed to * * @since 1.0 - * @group Subscriptions - * @runInSeparateProcess + * @group Subscriptions */ - public function test_create_remote_subscription() { - $post_id = 1; - $remote_post_id = 2; - $signature = '12345'; - - Connections::factory()->register( '\TestExternalConnection' ); - - \WP_Mock::userFunction( - 'get_post_meta', array( - 'args' => array( \WP_Mock\Functions::type( 'int' ), 'dt_external_connection_type', true ), - 'return' => 'test-external-connection', - ) - ); - - \WP_Mock::userFunction( - 'get_post_meta', array( - 'args' => array( \WP_Mock\Functions::type( 'int' ), 'dt_external_connection_url', true ), - 'return' => 'fake', - ) - ); - - \WP_Mock::userFunction( - 'get_post_meta', array( - 'args' => array( \WP_Mock\Functions::type( 'int' ), 'dt_external_connection_auth', true ), - 'return' => array(), - ) - ); - - \WP_Mock::userFunction( - 'get_the_title', array( - 'return' => '', - ) - ); - - $connection = ExternalConnection::instantiate( 1 ); - - \WP_Mock::passThruFunction( 'untrailingslashit' ); - \WP_Mock::passThruFunction( 'sanitize_text_field' ); - - \WP_Mock::userFunction( - 'wp_generate_password', array( - 'return' => $signature, - ) - ); - - \WP_Mock::userFunction( - 'update_post_meta', array( - 'times' => 1, - 'args' => array( $post_id, 'dt_subscription_signature', $signature ), - ) - ); - - \WP_Mock::userFunction( - 'wp_remote_post', [ - 'times' => 1, - 'args' => [ - \WP_Mock\Functions::type( 'string' ), - [ - 'timeout' => 5, - 'blocking' => \Distributor\Utils\is_dt_debug(), - 'headers' => [ - 'X-Distributor-Version' => DT_VERSION, - ], - 'body' => [ - 'post_id' => $remote_post_id, - 'remote_post_id' => $post_id, - 'signature' => $signature, - 'target_url' => home_url() . '/wp-json', - ], - ], - ], - ] - ); - - Subscriptions\create_remote_subscription( $connection, $remote_post_id, $post_id ); - - $this->assertConditionsMet(); + public function test_create_remote_subscription(): void { + $this->markTestIncomplete(); } /** * Test a local subscription given a signature * * @since 1.0 - * @group Subscriptions - * @runInSeparateProcess + * @group Subscriptions */ public function test_delete_subscription_local() { - $post_id = 1; - $subscription_id = 9; - $signature = 'signature'; - - \WP_Mock::userFunction( - 'get_post_meta', array( - 'times' => 1, - 'args' => array( $post_id, 'dt_subscriptions', true ), - 'return' => [ md5( $signature ) => $subscription_id ], - ) - ); - - \WP_Mock::userFunction( - 'wp_delete_post', array( - 'times' => 1, - 'args' => array( $subscription_id, true ), - ) - ); - - \WP_Mock::userFunction( - 'update_post_meta', array( - 'times' => 1, - 'args' => array( $post_id, 'dt_subscriptions', [] ), - ) - ); - - Subscriptions\delete_subscription( $post_id, $signature ); - - $this->assertConditionsMet(); + $this->markTestIncomplete(); } } diff --git a/tests/php/Utils/ExternalConnectionPostGenerator.php b/tests/php/Utils/ExternalConnectionPostGenerator.php new file mode 100644 index 000000000..ed003473d --- /dev/null +++ b/tests/php/Utils/ExternalConnectionPostGenerator.php @@ -0,0 +1,58 @@ + 'Subscription 1 1664535082', + 'post_content' => 'Test Content', + 'post_excerpt' => 'Test Excerpt', + 'post_status' => 'publish', + 'post_type' => 'dt_subscription', + 'post_author' => get_current_user_id(), + 'post_date' => '2020-01-01 00:00:00', + 'post_date_gmt' => '2020-01-01 00:00:00', + 'post_modified' => '2020-01-01 00:00:00', + 'post_modified_gmt' => '2020-01-01 00:00:00', + 'post_parent' => 0, + 'post_mime_type' => '', + 'comment_count' => 0, + 'comment_status' => 'closed', + 'ping_status' => 'closed', + 'menu_order' => 0, + 'pinged' => '', + 'to_ping' => '', + 'post_password' => '', + 'post_name' => 'subscription-1-1664535082', + 'post_content_filtered' => '', + ] + ); + + $postId = wp_insert_post( $postData ); + + // Insert meta data. + $metaData = wp_parse_args( + $metaData, + [ + 'dt_subscription_post_id' => 16, + 'dt_subscription_signature' => 'WDexP3lVEcbbPwBjAcSukLHe70', + 'dt_subscription_remote_post_id' => 23, + 'dt_external_connection_url' => 'https://destination.test/wp-json', + 'dt_external_connection_type' => 'wp' + ] + ); + + foreach ( $metaData as $metaKey => $metaValue ) { + update_post_meta( $postId, $metaKey, $metaValue ); + } + + return $postId; + } +} diff --git a/tests/php/Utils/PostGenerator.php b/tests/php/Utils/PostGenerator.php new file mode 100644 index 000000000..9ec7a083e --- /dev/null +++ b/tests/php/Utils/PostGenerator.php @@ -0,0 +1,61 @@ + 'Test Post', + 'post_content' => 'Test Content', + 'post_excerpt' => 'Test Excerpt', + 'post_status' => 'publish', + 'post_type' => 'post', + 'post_author' => 1, + 'post_date' => '2020-01-01 00:00:00', + 'post_date_gmt' => '2020-01-01 00:00:00', + 'post_modified' => '2020-01-01 00:00:00', + 'post_modified_gmt' => '2020-01-01 00:00:00', + 'post_parent' => 0, + 'post_mime_type' => '', + 'comment_count' => 0, + 'comment_status' => 'open', + 'ping_status' => 'open', + 'menu_order' => 0, + 'pinged' => '', + 'to_ping' => '', + 'post_password' => '', + 'post_content_filtered' => '', + ); + + $this->post = get_post( wp_insert_post( $postData ) ); + + return $this; + } + + /** + * This function should save meta to post. + */ + public function withMeta( array $metaData ): self { + foreach ( $metaData as $metaKey => $metaValue ) { + update_post_meta( $this->post->ID, $metaKey, $metaValue ); + } + + return $this; + } + + /** + * This function should return post. + */ + public function getPost(): \WP_Post { + return $this->post; + } +} diff --git a/tests/php/Utils/TestCase.php b/tests/php/Utils/TestCase.php new file mode 100644 index 000000000..45345a36c --- /dev/null +++ b/tests/php/Utils/TestCase.php @@ -0,0 +1,21 @@ +connections = array(); + } +} diff --git a/tests/php/includes/common.php b/tests/php/Utils/common.php similarity index 81% rename from tests/php/includes/common.php rename to tests/php/Utils/common.php index d7ba845c9..329d47fbd 100644 --- a/tests/php/includes/common.php +++ b/tests/php/Utils/common.php @@ -4,38 +4,33 @@ * Simple common WP classes/functions */ -/** - * Hollowed out WP_Error class for mocking - * - * @since 0.8 - */ -class WP_Error { - public function __construct( $code = '', $message = '' ) { - $this->code = $code; - $this->message = $message; - } -} +namespace Distributor\Tests\Utils; /** * Maybe unserialize variable. Pulled from WP core * - * @param mixed $original * @since 1.0 + * + * @param mixed $original + * * @return array */ function maybe_unserialize( $original ) { if ( is_serialized( $original ) ) { // don't attempt to unserialize data that wasn't serialized going in return @unserialize( $original ); } + return $original; } /** * Check if variable is serialized. Pulled from WP core * - * @param mixed $data - * @param bool $strict * @since 1.0 + * + * @param bool $strict + * @param mixed $data + * * @return bool */ function is_serialized( $data, $strict = true ) { @@ -54,7 +49,7 @@ function is_serialized( $data, $strict = true ) { return false; } if ( $strict ) { - $lastc = substr( $data, -1 ); + $lastc = substr( $data, - 1 ); if ( ';' !== $lastc && '}' !== $lastc ) { return false; } @@ -77,13 +72,13 @@ function is_serialized( $data, $strict = true ) { switch ( $token ) { case 's': if ( $strict ) { - if ( '"' !== substr( $data, -2, 1 ) ) { + if ( '"' !== substr( $data, - 2, 1 ) ) { return false; } } elseif ( false === strpos( $data, '"' ) ) { return false; } - // or else fall through + // or else fall through case 'a': case 'O': return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data ); @@ -91,8 +86,10 @@ function is_serialized( $data, $strict = true ) { case 'i': case 'd': $end = $strict ? '$' : ''; + return (bool) preg_match( "/^{$token}:[0-9.E-]+;$end/", $data ); } + return false; } @@ -103,7 +100,6 @@ function is_serialized( $data, $strict = true ) { */ class WP_Query { public function __construct( $args = array() ) { - $items = [ [ 'ID' => 2, @@ -131,16 +127,16 @@ public function __construct( $args = array() ) { $this->found_posts = count( $items ); $this->posts = $posts; - } - } /** * Check if object is WP_Error * - * @param Object $thing * @since 0.8 + * + * @param Object $thing + * * @return boolean */ function is_wp_error( $thing ) { @@ -154,7 +150,6 @@ function is_wp_error( $thing ) { * @return void */ function remote_get_setup() { - \WP_Mock::userFunction( 'get_option' ); $rest_response = [ @@ -188,7 +183,7 @@ function remote_get_setup() { ], ]; - $post_response = $rest_response[0]; + $post_response = $rest_response[0]; $post_response['original_site_name'] = $post_response['distributor_original_site_name']; $post_response['original_site_url'] = $post_response['distributor_original_site_url']; unset( $post_response['distributor_original_site_name'] ); @@ -274,9 +269,10 @@ function get_allowed_mime_types() { * * @since 2.0.0 * - * @param mixed $data Data to encode. + * @param mixed $data Data to encode. * @param int $options Optional. Options to be passed to json_encode(). Default 0. - * @param int $depth Optional. Maximum depth to walk through $data. + * @param int $depth Optional. Maximum depth to walk through $data. + * * @return string|false The JSON encoded string, or false if it cannot be encoded. */ function wp_json_encode( $data, $options = 0, $depth = 512 ) { @@ -290,6 +286,7 @@ function wp_json_encode( $data, $options = 0, $depth = 512 ) { * * @param array $settings Array of arguments. * @param array $defaults Array of default arguments. + * * @return array Array of parsed arguments. */ function wp_parse_args( $settings, $defaults ) { @@ -304,6 +301,7 @@ function wp_parse_args( $settings, $defaults ) { * @since 2.0.0 * * @param mixed $maybeint Data you wish to have converted to a non-negative integer. + * * @return int A non-negative integer. */ function absint( $maybeint ) { @@ -315,39 +313,5 @@ function absint( $maybeint ) { * * @return void */ -function remove_filter() { } - -/** - * Classes for testing connections - */ -class TestExternalConnection extends \Distributor\ExternalConnection { - static $slug = 'test-external-connection'; - static $auth_handler_class = '\Distributor\Authentications\WordPressBasicAuth'; - static $namespace = 'wp/v2'; - - public function push( $item_id, $args = array() ) { } - - public function pull( $items ) { } - - public function check_connections() { } - - public function remote_get( $args ) { } - - public function get_post_types() { } -} - -class TestInternalConnection extends \Distributor\Connection { - static $slug = 'test-internal-connection'; - - public function push( $item_id, $args = array() ) { } - - public function pull( $items ) { } - - public function remote_get( $args ) { } - - public function log_sync( array $item_id_mappings, $id, $overwrite ) {} - - public function get_sync_log( $id ) {} - - public function get_post_types() { } +function remove_filter() { } diff --git a/tests/php/UtilsTest.php b/tests/php/UtilsTest.php index 72c6fc1c0..db1063686 100644 --- a/tests/php/UtilsTest.php +++ b/tests/php/UtilsTest.php @@ -1,259 +1,40 @@ 1, - 'args' => [ 1 ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ 1 ], - 'return' => [ 'key' => [ 'value' ] ], - ] - ); - - \WP_Mock::userFunction( - 'add_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'key', 'value' ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'key', [ 'value' ], 'value' ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'wp_slash', [ - 'times' => 4, - 'return_arg' => 0, - ] - ); - - \WP_Mock::userFunction( - 'apply_filters_deprecated', - [ - 'return' => function( $name, $args ) { - return $args[0]; - }, - ] - ); - - \WP_Mock::expectAction( 'dt_after_set_meta', [ 'key' => [ 'value' ] ], [], 1 ); - - \WP_Mock::expectAction( 'dt_after_set_meta', [ 'key' => [ [ 'value' ] ] ], [ 'key' => [ 'value' ] ], 1 ); - - Utils\set_meta( - 1, [ - 'key' => [ 'value' ] - ] - ); - - Utils\set_meta( - 1, [ - 'key' => [ [ 'value' ] ], - ] - ); - - $this->assertConditionsMet(); + public function test_set_meta_simple(): void { + $this->markTestIncomplete(); } /** * Test set meta with multiple values * * @since 1.0 - * @group Utils - * @runInSeparateProcess + * @group Utils */ - public function test_set_meta_multi() { - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ 1 ], - 'return' => [ 'key' => [ 'value' ], 'key2' => [ 'value2' ] ], - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ 1 ], - 'return' => [ 'key' => [ 'value', 'value2' ], 'key2' => [ 'value3' ] ], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'key', 'value', 'value' ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'key2', 'value2', 'value2' ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'key', 'value', 'value' ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'key', 'value2', 'value2' ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'key2', 'value3', 'value3' ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'wp_slash', [ - 'times' => 10, - 'return_arg' => 0, - ] - ); - - \WP_Mock::userFunction( - 'apply_filters_deprecated', - [ - 'return' => function( $name, $args ) { - return $args[0]; - }, - ] - ); - - Utils\set_meta( - 1, [ - 'key' => [ 'value' ], - 'key2' => [ 'value2' ], - ] - ); - - Utils\set_meta( - 1, [ - 'key' => [ - 'value', - 'value2' - ], - 'key2' => [ 'value3' ], - ] - ); - - $this->assertConditionsMet(); + public function test_set_meta_multi(): void { + $this->markTestIncomplete(); } /** * Test set meta with serialized value * * @since 1.0 - * @group Utils - * @runInSeparateProcess + * @group Utils */ - public function test_set_meta_serialize() { - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ 1 ], - 'return' => [ 'key' => [ 'value' ], 'key2' => [ [ 0 => 'test' ] ] ], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'key', 'value', 'value' ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ 1, 'key2', [ 0 => 'test' ], [ 0 => 'test' ] ], - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'wp_slash', [ - 'times' => 4, - 'return_arg' => 0, - ] - ); - - \WP_Mock::userFunction( - 'apply_filters_deprecated', - [ - 'return' => function( $name, $args ) { - return $args[0]; - }, - ] - ); - - Utils\set_meta( - 1, [ - 'key' => [ 'value' ], - 'key2' => [ 'a:1:{i:0;s:4:"test";}' ], - ] - ); - - $this->assertConditionsMet(); + public function test_set_meta_serialize(): void { + $this->markTestIncomplete(); } /** @@ -261,84 +42,9 @@ public function test_set_meta_serialize() { * * @since 1.0 * @group Utils - * @runInSeparateProcess */ - public function test_set_taxonomy_terms_simple() { - $post_id = 1; - $term_id = 1; - $taxonomy = 'taxonomy'; - $slug = 'slug'; - $name = 'name'; - - \WP_Mock::userFunction( - 'taxonomy_exists', [ - 'times' => 1, - 'args' => [ $taxonomy ], - 'return' => true, - ] - ); - - \WP_Mock::userFunction( - 'get_term_by', [ - 'times' => 1, - 'args' => [ 'slug', $slug, $taxonomy ], - 'return' => function() use ( $term_id ) { - $term = new \stdClass(); - $term->term_id = $term_id; - - return $term; - }, - ] - ); - - /** - * Don't need to create any terms - */ - \WP_Mock::userFunction( - 'wp_insert_term', [ - 'times' => 0, - ] - ); - - \WP_Mock::userFunction( - 'wp_update_term', [ - 'times' => 1, - 'args' => [ - $term_id, - $taxonomy, - [ - 'parent' => '', - ] - ], - 'return' => [ 'term_id' => $term_id ], - ] - ); - - \WP_Mock::onFilter( 'dt_update_term_hierarchy' ) - ->with( true ) - ->reply( true ); - - \WP_Mock::userFunction( - 'wp_set_object_terms', [ - 'times' => 1, - 'args' => [ $post_id, [ $term_id ], $taxonomy ], - ] - ); - - Utils\set_taxonomy_terms( - $post_id, [ - $taxonomy => [ - [ - 'slug' => $slug, - 'name' => $name, - 'term_id' => $term_id, - 'parent' => 0, - ], - ], - ] - ); - - $this->assertConditionsMet(); + public function test_set_taxonomy_terms_simple(): void { + $this->markTestIncomplete(); } /** @@ -346,90 +52,9 @@ public function test_set_taxonomy_terms_simple() { * * @since 1.0 * @group Utils - * @runInSeparateProcess */ - public function test_set_taxonomy_terms_create_term() { - $post_id = 1; - $term_id = 1; - $taxonomy = 'taxonomy'; - $slug = 'slug'; - $name = 'name'; - $description = 'description'; - - \WP_Mock::userFunction( - 'taxonomy_exists', [ - 'times' => 1, - 'args' => [ $taxonomy ], - 'return' => true, - ] - ); - - \WP_Mock::userFunction( - 'get_term_by', [ - 'times' => 1, - 'args' => [ 'slug', $slug, $taxonomy ], - 'return' => false, - ] - ); - - /** - * Don't need to create any terms - */ - \WP_Mock::userFunction( - 'wp_insert_term', [ - 'times' => 1, - 'args' => [ - $name, - $taxonomy, - [ - 'slug' => $slug, - 'description' => $description - ] - ], - 'return' => [ 'term_id' => $term_id ], - ] - ); - - \WP_Mock::userFunction( - 'wp_update_term', [ - 'times' => 1, - 'args' => [ - $term_id, - $taxonomy, - [ - 'parent' => '', - ] - ], - 'return' => [ 'term_id' => $term_id ], - ] - ); - - \WP_Mock::onFilter( 'dt_update_term_hierarchy' ) - ->with( true ) - ->reply( true ); - - \WP_Mock::userFunction( - 'wp_set_object_terms', [ - 'times' => 1, - 'args' => [ $post_id, [ $term_id ], $taxonomy ], - ] - ); - - Utils\set_taxonomy_terms( - $post_id, [ - $taxonomy => [ - [ - 'slug' => $slug, - 'name' => $name, - 'term_id' => $term_id, - 'parent' => 0, - 'description' => $description, - ], - ], - ] - ); - - $this->assertConditionsMet(); + public function test_set_taxonomy_terms_create_term(): void { + $this->markTestIncomplete(); } /** @@ -437,144 +62,9 @@ public function test_set_taxonomy_terms_create_term() { * * @since 1.0 * @group Utils - * @runInSeparateProcess */ - public function test_set_taxonomy_terms_no_taxonomy() { - $post_id = 1; - $term_id = 1; - $taxonomy = 'taxonomy'; - $slug = 'slug'; - $name = 'name'; - - \WP_Mock::userFunction( - 'taxonomy_exists', [ - 'times' => 1, - 'args' => [ $taxonomy ], - 'return' => false, - ] - ); - - \WP_Mock::userFunction( - 'wp_set_object_terms', [ - 'times' => 0, - ] - ); - - Utils\set_taxonomy_terms( - $post_id, [ - $taxonomy => [ - [ - 'slug' => $slug, - 'name' => $name, - 'term_id' => $term_id, - 'parent' => 0, - ], - ], - ] - ); - - $this->assertConditionsMet(); - } - - /** - * Todo: Test set_taxonomy_terms hierarchical functionality - */ - - /** - * Test format media with no feature - * - * @since 1.0 - * @group Utils - * @runInSeparateProcess - */ - public function test_format_media_not_featured() { - $media_post = new \stdClass(); - $media_post->ID = 1; - $media_post->post_parent = 10; - $media_post->post_title = 'title'; - $media_post->post_content = 'content'; - $media_post->post_excerpt = 'excerpt'; - $media_post->post_mime_type = 'image/png'; - - \WP_Mock::userFunction( - 'get_post_thumbnail_id', [ - 'times' => 1, - 'args' => [ $media_post->post_parent ], - 'return' => 0, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $media_post->ID, '_wp_attachment_image_alt', true ], - 'return' => 'alt', - ] - ); - - \WP_Mock::userFunction( - 'wp_attachment_is_image', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => true, - ] - ); - - \WP_Mock::userFunction( - 'wp_get_attachment_metadata', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => [ 'test' => 1 ], - ] - ); - - \WP_Mock::userFunction( - 'wp_get_attachment_url', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => 'http://mediaitem.com', - ] - ); - - \WP_Mock::userFunction( - 'get_attached_file', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => '/var/www/html/wp-content/uploads/mediaitem.jpg', - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => [ - 'meta1' => [ true ], - 'meta2' => [ false ], - ], - ] - ); - - \WP_Mock::userFunction( - 'remove_filter', [ - 'times' => 1, - ] - ); - - \WP_Mock::userFunction( - 'apply_filters_deprecated', - [ - 'return' => function( $name, $args ) { - return $args[0]; - }, - ] - ); - - $formatted_media = Utils\format_media_post( $media_post ); - - $this->assertFalse( $formatted_media['featured'] ); - - return $formatted_media; + public function test_set_taxonomy_terms_no_taxonomy(): void { + $this->markTestIncomplete(); } /** @@ -582,193 +72,18 @@ public function test_format_media_not_featured() { * * @since 1.0 * @group Utils - * @runInSeparateProcess */ - public function test_format_media_featured() { - $media_post = new \stdClass(); - $media_post->ID = 1; - $media_post->post_parent = 10; - $media_post->post_title = 'title'; - $media_post->post_content = 'content'; - $media_post->post_excerpt = 'excerpt'; - $media_post->post_mime_type = 'image/png'; - - \WP_Mock::userFunction( - 'get_post_thumbnail_id', [ - 'times' => 1, - 'args' => [ $media_post->post_parent ], - 'return' => $media_post->ID, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $media_post->ID, '_wp_attachment_image_alt', true ], - 'return' => 'alt', - ] - ); - - \WP_Mock::userFunction( - 'wp_attachment_is_image', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => true, - ] - ); - - \WP_Mock::userFunction( - 'wp_get_attachment_metadata', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => [ 'test' => 1 ], - ] - ); - - \WP_Mock::userFunction( - 'wp_get_attachment_url', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => 'http://mediaitem.com', - ] - ); - - \WP_Mock::userFunction( - 'get_attached_file', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => '/var/www/html/wp-content/uploads/mediaitem.jpg', - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => [ - 'meta1' => [ true ], - 'meta2' => [ false ], - ], - ] - ); - - \WP_Mock::userFunction( - 'remove_filter', [ - 'times' => 1, - ] - ); - - \WP_Mock::userFunction( - 'apply_filters_deprecated', - [ - 'return' => function( $name, $args ) { - return $args[0]; - }, - ] - ); - - $formatted_media = Utils\format_media_post( $media_post ); - - $this->assertTrue( $formatted_media['featured'] ); - - return $formatted_media; + public function test_format_media_featured(): void { + $this->markTestIncomplete(); } /** * Test format media with no `_wp_attachment_metadata` * * @group Utils - * @runInSeparateProcess */ - public function test_format_media_no_attachment_meta() { - $media_post = new \stdClass(); - $media_post->ID = 1; - $media_post->post_parent = 10; - $media_post->post_title = 'title'; - $media_post->post_content = 'content'; - $media_post->post_excerpt = 'excerpt'; - $media_post->post_mime_type = 'image/png'; - - \WP_Mock::userFunction( - 'get_post_thumbnail_id', [ - 'times' => 1, - 'args' => [ $media_post->post_parent ], - 'return' => 0, - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $media_post->ID, '_wp_attachment_image_alt', true ], - 'return' => 'alt', - ] - ); - - \WP_Mock::userFunction( - 'wp_attachment_is_image', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => true, - ] - ); - - \WP_Mock::userFunction( - 'wp_get_attachment_metadata', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => [ 'test' => 1 ], - ] - ); - - \WP_Mock::userFunction( - 'wp_get_attachment_url', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => 'http://mediaitem.com', - ] - ); - - \WP_Mock::userFunction( - 'get_attached_file', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => '/var/www/html/wp-content/uploads/mediaitem.jpg', - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $media_post->ID ], - 'return' => [ - 'meta1' => [ true ], - 'meta2' => [ false ], - '_wp_attachment_metadata' => [ true ], - ], - ] - ); - - \WP_Mock::userFunction( - 'remove_filter', [ - 'times' => 1, - ] - ); - - \WP_Mock::userFunction( - 'apply_filters_deprecated', - [ - 'return' => function( $name, $args ) { - return $args[0]; - }, - ] - ); - - $formatted_media = Utils\format_media_post( $media_post ); - - $this->assertFalse( array_key_exists( '_wp_attachment_metadata', $formatted_media['meta'] ) ); - - return $formatted_media; + public function test_format_media_no_attachment_meta(): void { + $this->markTestIncomplete(); } /** @@ -776,166 +91,9 @@ public function test_format_media_no_attachment_meta() { * * @since 1.0 * @group Utils - * @runInSeparateProcess */ - public function test_set_media() { - $post_id = 1; - $media_item = $this->test_format_media_featured(); - - $new_image_id = 5; - - $attached_media_post = new \stdClass(); - $attached_media_post->ID = 3; - $attached_media_post->post_parent = 10; - $attached_media_post->post_title = 'title'; - $attached_media_post->post_content = 'content'; - $attached_media_post->post_excerpt = 'excerpt'; - $attached_media_post->post_mime_type = 'image/png'; - - \WP_Mock::userFunction( - 'Distributor\Utils\get_settings', [ - 'times' => 1, - 'return' => [ - 'override_author_byline' => true, - 'media_handling' => 'featured', - 'email' => '', - 'license_key' => '', - 'valid_license' => null, - ], - ] - ); - - \WP_Mock::userFunction( - 'get_attached_media', [ - 'times' => 1, - 'args' => [ get_allowed_mime_types(), $post_id ], - 'return' => [ $attached_media_post ], - ] - ); - - \WP_Mock::userFunction( - 'wp_parse_args', [ - 'times' => 1, - 'args' => [ - [ 'use_filesystem' => false ], - [ 'use_filesystem' => false ], - ], - 'return' => [ - 'use_filesystem' => false, - ], - ] - ); - - \WP_Mock::userFunction( - 'wp_delete_attachment', [ - 'times' => 1, - 'args' => [ $attached_media_post->ID, true ], - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $attached_media_post->ID, 'dt_original_media_url', true ], - 'return' => 'http://mediaitem.com', - ] - ); - - \WP_Mock::userFunction( - 'wp_list_pluck', [ - 'times' => 1, - 'args' => [ [ $media_item ], 'featured' ], - 'return' => [ 0 => true ], - ] - ); - - \WP_Mock::userFunction( - 'Distributor\Utils\process_media', [ - 'times' => 1, - 'args' => [ $media_item['source_url'], $post_id, - [ - 'source_file' => $media_item['source_file'], - 'use_filesystem' => false, - ] - ], - 'return' => $new_image_id, - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ $new_image_id, 'dt_original_media_url', $media_item['source_url'] ], - ] - ); - - \WP_Mock::userFunction( - 'set_post_thumbnail', [ - 'times' => 1, - 'args' => [ $post_id, $new_image_id ], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ $new_image_id, 'dt_original_media_id', $media_item['id'] ], - ] - ); - - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 1, - 'args' => [ $new_image_id ], - 'return' => [ 'meta1' => [ true ], 'meta2' => [ false ] ], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ $new_image_id, 'meta1', true, true ], - ] - ); - - \WP_Mock::userFunction( - 'update_post_meta', [ - 'times' => 1, - 'args' => [ $new_image_id, 'meta2', false, false ], - ] - ); - - \WP_Mock::userFunction( - 'wp_update_post', [ - 'times' => 1, - 'args' => [ - [ - 'ID' => $new_image_id, - 'post_title' => $attached_media_post->post_title, - 'post_content' => $attached_media_post->post_content, - 'post_excerpt' => $attached_media_post->post_excerpt, - ], - ], - ] - ); - - \WP_Mock::userFunction( - 'wp_slash', [ - 'times' => 4, - 'return_arg' => 0, - ] - ); - - \WP_Mock::userFunction( - 'apply_filters_deprecated', - [ - 'return' => function( $name, $args ) { - return $args[0]; - }, - ] - ); - - Utils\set_media( $post_id, [ $media_item ], [ 'use_filesystem' => false ] ); + public function test_set_media(): void { + $this->markTestIncomplete(); } /** @@ -946,12 +104,12 @@ public function test_set_media() { * Todo finish process_media */ - /** - * Test post_args_allow_list - * - * @since 1.7.0 - */ - function test_post_args_allow_list() { + /** + * Test post_args_allow_list + * + * @since 1.7.0 + */ + public function test_post_args_allow_list(): void { $post_args = [ 'post_title' => 'Test Title', 'post_type' => 'post', diff --git a/tests/php/WordPressExternalConnectionTest.php b/tests/php/WordPressExternalConnectionTest.php index e4cd9268b..34d21f8db 100644 --- a/tests/php/WordPressExternalConnectionTest.php +++ b/tests/php/WordPressExternalConnectionTest.php @@ -1,66 +1,42 @@ auth = new WordPressBasicAuth( array() ); $this->connection = new WordPressExternalConnection( 'name', 'url', 1, $this->auth ); - - } - - /** - * Helper function to mock get_post_meta. - */ - public function setup_post_meta_mock( $post_meta ) { - $get_post_meta = function( $post_id, $key = '', $single = false ) use ( $post_meta ) { - if ( empty( $key ) ) { - return $post_meta; - } - - if ( isset( $post_meta[ $key ] ) ) { - if ( $single ) { - return $post_meta[ $key ][0]; - } - return $post_meta[ $key ]; - } - - return ''; - }; - - \WP_Mock::userFunction( - 'get_post_meta', - array( - 'return' => $get_post_meta, - ) - ); } /** * Test creating a WordPressExternalConnection object * * @since 0.8 - * @group WordPressExternalConnection - * @runInSeparateProcess + * @group WordPressExternalConnection */ - public function test_construct() { + public function test_construct(): void { // Now test a successful creation $auth = new WordPressBasicAuth( array() ); $connection = new WordPressExternalConnection( 'name', 'url', 1, $auth ); - $this->assertTrue( is_a( $connection, '\Distributor\ExternalConnection' ) ); + $this->assertTrue( is_a( $connection, ExternalConnection::class ) ); // Check connection properties - $this->assertTrue( ! empty( $connection->name ) ); - $this->assertTrue( ! empty( $connection->base_url ) ); - $this->assertTrue( ! empty( $connection->id ) ); - $this->assertTrue( ! empty( $connection->auth_handler ) ); + $this->assertNotEmpty( $connection->name ); + $this->assertNotEmpty( $connection->base_url ); + $this->assertNotEmpty( $connection->id ); + $this->assertNotEmpty( $connection->auth_handler ); } /** @@ -74,306 +50,31 @@ public function test_construct() { * otherwise that method will return false, rending our test false as well. * Valid response body, with JSON encoded body * - * @group WordPressExternalConnection + * @group WordPressExternalConnection * @since 0.8 - * @runInSeparateProcess */ - public function test_push() { - $this->setup_post_meta_mock( array() ); - \WP_Mock::userFunction( 'do_action_deprecated' ); - \WP_Mock::userFunction( 'untrailingslashit' ); - \WP_Mock::userFunction( 'get_the_title' ); - \WP_Mock::userFunction( 'wp_remote_post' ); - \WP_Mock::userFunction( 'esc_html__' ); - \WP_Mock::userFunction( 'get_bloginfo' ); - \WP_Mock::passthruFunction( 'absint' ); - - \WP_Mock::userFunction( - 'get_current_blog_id', [ - 'return' => 1, - ] - ); - - \WP_Mock::userFunction( - 'get_option', [ - 'args' => [ 'page_for_posts' ], - 'return' => 0, - ] - ); - - \WP_Mock::userFunction( - 'use_block_editor_for_post_type', [ - 'return' => false, - ] - ); - - $post_type = 'foo'; - - $body = json_encode( - [ - 'id' => 123, - $post_type => [ - '_links' => [ - 'wp:items' => [ - 0 => [ - 'href' => 'http://url.com', - ], - ], - ], - ], - ] - ); - - $post = (object) [ - 'post_content' => 'my post content', - 'post_type' => $post_type, - 'post_excerpt' => 'post excerpt', - 'post_name' => 'slug', - 'post_status' => 'publish', - 'ID' => 1, - 'post_date' => '2020-01-01 00:00:00', - 'post_date_gmt' => '2020-01-01 00:00:00', - ]; - - \WP_Mock::userFunction( - 'get_post', [ - 'args' => [ Functions::anyOf( $post->ID, $post ) ], - 'return' => $post, - ] - ); - - \WP_Mock::userFunction( - 'get_post_type', [ - 'return' => $post_type, - ] - ); - - \WP_Mock::userFunction( - 'has_blocks', [ - 'return' => false, - ] - ); - - \WP_Mock::userFunction( - 'wp_generate_password', [ - 'return' => '12345', - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_request', [ - 'return' => $body, - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_retrieve_body', [ - 'return' => $body, - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_retrieve_headers', [ - 'return' => [], - ] - ); - - /** - * We will test the util prepare functions later - */ - - \WP_Mock::userFunction( - 'get_attached_media', [ - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'get_post_thumbnail_id', [ - 'return' => 0, - ] - ); - - \WP_Mock::userFunction( - '\Distributor\Utils\prepare_media', [ - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - '\Distributor\Utils\prepare_taxonomy_terms', [ - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - '\Distributor\Utils\prepare_meta', [ - 'return' => [], - ] - ); - - \WP_Mock::userFunction( 'get_permalink' ); - - \WP_Mock::userFunction( - 'remove_filter', [ - 'times' => 2, - ] - ); - - $this->assertInstanceOf( \WP_Error::class, $this->connection->push( 0 ) ); - $this->assertTrue( is_array( $this->connection->push( 1 ) ) ); - - /** - * Let's ensure \Distributor\Subscriptions\create_subscription is called when the X-Distributor header is - * returned by the remote API - */ - - \WP_Mock::userFunction( - 'wp_remote_retrieve_headers', [ - 'return' => [ - 'X-Distributor' => true, - ], - ] - ); - - \WP_Mock::userFunction( - '\Distributor\Subscriptions\create_subscription', [ - 'times' => 0, - 'return' => [ - 'X-Distributor' => true, - ], - ] - ); - - $this->assertTrue( is_array( $this->connection->push( 1 ) ) ); + public function test_push(): void { + $this->markTestIncomplete(); } /** * Test if the pull method returns an array. * * @since 0.8 - * @group WordPressExternalConnection - * @runInSeparateProcess + * @group WordPressExternalConnection */ public function test_pull() { - $this->setup_post_meta_mock( array() ); - $post_id = 123; - - \WP_Mock::userFunction( 'untrailingslashit' ); - \WP_Mock::userFunction( 'sanitize_text_field' ); - - remote_get_setup(); - - \WP_Mock::passthruFunction( 'wp_slash' ); - \WP_Mock::passthruFunction( 'update_post_meta' ); - \WP_Mock::userFunction( 'get_current_user_id' ); - \WP_Mock::userFunction( 'delete_post_meta' ); - - \WP_Mock::userFunction( - 'apply_filters_deprecated', - [ - 'return' => function( $name, $args ) { - return $args[0]; - }, - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_retrieve_headers', [ - 'return' => [ - 'X-Distributor' => 'yes', - ], - ] - ); - - \WP_Mock::userFunction( - 'wp_insert_post', [ - 'return' => 2, - ] - ); - - \WP_Mock::userFunction( - 'get_attached_media', [ - 'return' => [], - ] - ); - - \WP_Mock::userFunction( - 'get_allowed_mime_types', [ - 'return' => [], - ] - ); - - $pull_actual = $this->connection->pull( - [ - [ - 'remote_post_id' => $post_id, - 'post_type' => 'post', - ], - ] - ); - - $this->assertIsArray( $pull_actual ); + $this->markTestIncomplete(); } /** * Handles mocking the correct remote request to receive a WP_Post instance. * * @since 0.8 - * @group WordPressExternalConnection - * @runInSeparateProcess + * @group WordPressExternalConnection */ public function test_remote_get() { - - remote_get_setup(); - - \WP_Mock::passThruFunction( 'untrailingslashit' ); - \WP_Mock::userFunction( 'get_current_user_id' ); - - \WP_Mock::userFunction( - 'wp_remote_retrieve_response_code', [ - 'return' => 200, - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_retrieve_headers', [ - 'times' => 1, - 'return' => [ - 'X-Distributor' => true, - ], - ] - ); - - \WP_Mock::userFunction( - 'post_type_exists', [ - 'args' => [ '' ], - 'return' => false, - ] - ); - - \WP_Mock::userFunction( - 'post_type_exists', [ - 'args' => [ 'post' ], - 'return' => true, - ] - ); - - \WP_Mock::userFunction( - 'post_type_supports', [ - 'args' => [ \WP_Mock\Functions::type( 'string' ), 'editor' ], - 'return' => true, - ] - ); - - $actual = $this->connection->remote_get( - [ - 'id' => 111, - 'post_type' => 'post', - ] - ); - - $this->assertInstanceOf( \WP_Post::class, $actual ); + $this->markTestIncomplete(); } /** @@ -381,40 +82,9 @@ public function test_remote_get() { * * @since 0.8 * @group WordPressExternalConnection - * @runInSeparateProcess */ public function test_check_connections_no_errors() { - - \WP_Mock::userFunction( - 'wp_remote_retrieve_body', [ - 'return' => json_encode( - [ - 'routes' => 'my routes', - ] - ), - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_retrieve_headers', [ - 'return' => [ - 'Link' => null, - ], - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_retrieve_response_code', [ - 'return' => 200, - ] - ); - - \WP_Mock::userFunction( 'wp_remote_request' ); - \WP_Mock::userFunction( 'untrailingslashit' ); - - $check = $this->connection->check_connections(); - - $this->assertTrue( ! empty( $check['errors']['no_distributor'] ) ); + $this->markTestIncomplete(); } /** @@ -422,37 +92,8 @@ public function test_check_connections_no_errors() { * * @since 1.0 * @group WordPressExternalConnection - * @runInSeparateProcess */ public function test_check_connections_no_distributor() { - \WP_Mock::userFunction( - 'wp_remote_retrieve_body', [ - 'return' => json_encode( - [ - 'routes' => 'my routes', - ] - ), - ] - ); - - \WP_Mock::userFunction( 'wp_remote_request' ); - \WP_Mock::userFunction( 'untrailingslashit' ); - - \WP_Mock::userFunction( - 'wp_remote_retrieve_response_code', [ - 'return' => 200, - ] - ); - - \WP_Mock::userFunction( - 'wp_remote_retrieve_headers', [ - 'return' => [ - 'X-Distributor' => true, - 'Link' => null, - ], - ] - ); - - $this->assertTrue( empty( $this->connection->check_connections()['errors']['no_distributor'] ) ); + $this->markTestIncomplete(); } } diff --git a/tests/php/bootstrap.php b/tests/php/bootstrap.php index 002ce94ac..2c4e6bebe 100644 --- a/tests/php/bootstrap.php +++ b/tests/php/bootstrap.php @@ -1,23 +1,36 @@ setup_common(); - - // Reset registered connections - \Distributor\Connections::factory()->connections = array(); - } - - /** - * Tear down with WP_Mock - * - * @since 0.8 - */ - public function tear_down() { - \WP_Mock::tearDown(); - } - - /** - * Mock common functions - * - * @since 0.8 - */ - public function setup_common() { - \WP_Mock::userFunction( - '__', array( - 'return_arg' => 0, - ) - ); - - \WP_Mock::userFunction( - 'esc_html__', array( - 'return_arg' => 0, - ) - ); - - \WP_Mock::userFunction( - 'esc_html_e', array( - 'return_arg' => 0, - ) - ); - - \WP_Mock::userFunction( - '_e', array( - 'return_arg' => 0, - ) - ); - } -}