From 6c2a201e09a5cb45db7427756a009a65944c25f4 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 9 Jun 2023 10:12:07 +0530 Subject: [PATCH 01/14] dev: add initial commit to migrate from mock phpunit test --- .github/workflows/test.yml | 3 + bin/install-wp-tests.sh | 157 ++ composer.json | 15 +- composer.lock | 1338 ++++++++--------- includes/debug-info.php | 7 +- phpunit.xml.dist | 3 + tests/php/ConnectionsTest.php | 16 +- tests/php/DebugInfoTest.php | 69 +- tests/php/DistributorPostTest.php | 21 +- tests/php/EnqueueScriptTest.php | 5 +- tests/php/ExternalConnectionTest.php | 7 +- tests/php/HooksTest.php | 5 +- tests/php/Mocks/TestExternalConnection.php | 22 + tests/php/Mocks/TestInternalConnection.php | 19 + tests/php/NetworkSiteConnectionsTest.php | 8 +- tests/php/SubscriptionsTest.php | 12 +- tests/php/Utils/TestCase.php | 21 + tests/php/{includes => Utils}/common.php | 37 +- tests/php/UtilsTest.php | 14 +- tests/php/WordPressExternalConnectionTest.php | 10 +- tests/php/bootstrap.php | 42 +- tests/php/includes/TestCase.php | 62 - 22 files changed, 911 insertions(+), 982 deletions(-) create mode 100755 bin/install-wp-tests.sh create mode 100644 tests/php/Mocks/TestExternalConnection.php create mode 100644 tests/php/Mocks/TestInternalConnection.php create mode 100644 tests/php/Utils/TestCase.php rename tests/php/{includes => Utils}/common.php (88%) delete mode 100644 tests/php/includes/TestCase.php diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fa78ef9a0..c769f53a6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,5 +54,8 @@ jobs: - name: Install dependencies run: composer update -W + - name: Setup WP Tests + run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 + - name: PHPUnit run: './vendor/bin/phpunit' diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh new file mode 100755 index 000000000..14fa26978 --- /dev/null +++ b/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/composer.json b/composer.json index 6ae962f07..340f8021d 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.2", + "yoast/phpunit-polyfills": "dev-main" }, "scripts": { "lint": "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 e297a9674..dca5515bc 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": "55cabc5871a7166db51644beffc3ac94", + "content-hash": "9e196f3dbfde4c92eca2154919e0e23d", "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": "9c085cf0554a0b5311623548663aa9e4d8f52587" }, "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/9c085cf0554a0b5311623548663aa9e4d8f52587", + "reference": "9c085cf0554a0b5311623548663aa9e4d8f52587", "shasum": "" }, "require": { + "automattic/vipwpcs": "^2.3", "dealerdirect/phpcodesniffer-composer-installer": "*", "phpcompatibility/phpcompatibility-wp": "^2", "squizlabs/php_codesniffer": "3.7.1", @@ -94,96 +95,7 @@ "issues": "https://github.com/10up/phpcs-composer/issues", "source": "https://github.com/10up/phpcs-composer/tree/master" }, - "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-05-10T22:44:49+00:00" }, { "name": "automattic/vipwpcs", @@ -314,30 +226,30 @@ }, { "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 +276,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 +292,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.15.5", "source": { "type": "git", - "url": "https://github.com/mockery/mockery.git", - "reference": "c10a5f6e06fc2470ab1822fa13fa2a7380f8fbac" + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e" }, "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/11e2663a5bc9db5d714eedb4277ee300403b4a9e", + "reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e", "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 +395,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.15.5" }, - "funding": [ - { - "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", - "type": "tidelift" - } - ], - "time": "2022-03-03T13:19:32+00:00" + "time": "2023-05-19T20:20:00+00:00" }, { "name": "phar-io/manifest", @@ -675,6 +520,46 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "php-stubs/wordpress-tests-stubs", + "version": "v6.2.0", + "source": { + "type": "git", + "url": "https://github.com/php-stubs/wordpress-tests-stubs.git", + "reference": "175f395c814d9f52ebd2c1c64069a3b01ef764e8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-stubs/wordpress-tests-stubs/zipball/175f395c814d9f52ebd2c1c64069a3b01ef764e8", + "reference": "175f395c814d9f52ebd2c1c64069a3b01ef764e8", + "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.2.0" + }, + "time": "2023-05-15T07:50:52+00:00" + }, { "name": "phpcompatibility/php-compatibility", "version": "9.3.5", @@ -850,268 +735,170 @@ "time": "2022-10-24T09:00:36+00:00" }, { - "name": "phpdocumentor/reflection-common", - "version": "2.2.0", + "name": "phpunit/php-code-coverage", + "version": "9.2.26", "source": { "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b" + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "443bc6912c9bd5b409254a40f4b0f4ced7c80ea1" }, "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/443bc6912c9bd5b409254a40f4b0f4ced7c80ea1", + "reference": "443bc6912c9bd5b409254a40f4b0f4ced7c80ea1", "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", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.26" }, - "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-03-06T12:58:08+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 +917,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 +932,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 +976,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 +991,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 +1035,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.8", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "2454ae1765516d20c4ffe103d85a58a9a3bd5662" + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "17d621b3aff84d0c8b62539e269e87d8d5baa76e" }, "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/17d621b3aff84d0c8b62539e269e87d8d5baa76e", + "reference": "17d621b3aff84d0c8b62539e269e87d8d5baa76e", "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.13", + "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 +1127,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.8" }, "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-05-11T05:14:45+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 +1193,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 +1209,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 +1253,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 +1312,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 +1320,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 +1386,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 +1451,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 +1509,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 +1517,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 +1545,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "5.1-dev" } }, "autoload": { @@ -1714,7 +1572,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 +1580,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 +1642,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 +1657,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.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "de036ec91d55d2a9e0db2ba975b512cdb1c23921" + "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" }, "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/0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", "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 +1688,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -1855,7 +1713,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.5" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2022-02-14T08:28:10+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 +1778,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 +1827,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 +1835,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 +1882,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 +1890,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 +1942,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 +1953,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 +2000,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 +2008,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 +2056,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 +2064,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 +2107,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.16", "source": { "type": "git", "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", - "reference": "c921498b474212fe4552928bbeb68d70250ce5e8" + "reference": "dc5582dc5a93a235557af73e523c389aac9a8e88" }, "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/dc5582dc5a93a235557af73e523c389aac9a8e88", + "reference": "dc5582dc5a93a235557af73e523c389aac9a8e88", "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 +2166,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-03-31T16:46:32+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -2350,64 +2283,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 +2336,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 +2392,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 +2408,8 @@ "ext-json": "*" }, "platform-dev": [], + "platform-overrides": { + "php": "7.4" + }, "plugin-api-version": "2.3.0" } diff --git a/includes/debug-info.php b/includes/debug-info.php index 9ebd28e7c..4a262e38e 100644 --- a/includes/debug-info.php +++ b/includes/debug-info.php @@ -78,9 +78,8 @@ 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 = [ 'email' => '', 'valid_license' => false, @@ -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..599fc34fb 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,6 +2,9 @@ bootstrap="./tests/php/bootstrap.php" backupGlobals="false" colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" > diff --git a/tests/php/ConnectionsTest.php b/tests/php/ConnectionsTest.php index c188b0576..d68df2c5e 100644 --- a/tests/php/ConnectionsTest.php +++ b/tests/php/ConnectionsTest.php @@ -1,8 +1,11 @@ register( '\TestExternalConnection' ); + 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..fdc608618 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( [] ); + $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 efcc1d7fe..6c8c9a9a4 100644 --- a/tests/php/DistributorPostTest.php +++ b/tests/php/DistributorPostTest.php @@ -1,8 +1,8 @@ setup_post_mock(); @@ -211,7 +209,6 @@ public function test_internal_connection() { * Test the DistributorPost object for external, pushed posts. * * @covers ::__construct - * @runInSeparateProcess */ public function test_external_connection_with_pushed_post() { $this->setup_post_mock(); @@ -245,7 +242,6 @@ public function test_external_connection_with_pushed_post() { * Test the DistributorPost object for external, pushed posts. * * @covers ::__construct - * @runInSeparateProcess */ public function test_external_connection_with_pulled_post() { $this->setup_post_mock(); @@ -279,7 +275,6 @@ public function test_external_connection_with_pulled_post() { * Test the DistributorPost object a source post. * * @covers ::__construct - * @runInSeparateProcess */ public function test_source_post() { $this->setup_post_mock(); @@ -332,7 +327,6 @@ public function test_source_post() { * Test the get_the_id() method. * * @covers ::get_the_id - * @runInSeparateProcess */ public function test_get_the_id() { $this->setup_post_mock(); @@ -353,7 +347,6 @@ public function test_get_the_id() { * Test the get_permalink() method. * * @covers ::get_permalink - * @runInSeparateProcess */ public function test_get_permalink() { $this->setup_post_mock(); @@ -374,7 +367,6 @@ public function test_get_permalink() { * Test the get_post_type() method. * * @covers ::get_post_type - * @runInSeparateProcess */ public function test_get_post_type() { $this->setup_post_mock(); @@ -402,7 +394,6 @@ public function test_get_post_type() { * Test the get_post_thumbnail_id() method. * * @covers ::get_post_thumbnail_id - * @runInSeparateProcess */ public function test_get_post_thumbnail_id() { $this->setup_post_mock(); @@ -430,7 +421,6 @@ public function test_get_post_thumbnail_id() { * Test the get_post_thumbnail_url() method. * * @covers ::get_post_thumbnail_url - * @runInSeparateProcess */ public function test_get_post_thumbnail_url() { $this->setup_post_mock(); @@ -458,7 +448,6 @@ public function test_get_post_thumbnail_url() { * Test the get_the_post_thumbnail() method. * * @covers ::get_the_post_thumbnail - * @runInSeparateProcess */ public function test_get_the_post_thumbnail() { $this->setup_post_mock(); @@ -487,7 +476,6 @@ public function test_get_the_post_thumbnail() { * Test the get_meta() method. * * @covers ::get_meta - * @runInSeparateProcess */ public function test_get_meta() { $this->setup_post_mock(); @@ -520,7 +508,6 @@ public function test_get_meta() { * Test the get_terms() method. * * @covers ::get_terms - * @runInSeparateProcess */ public function test_get_terms() { $this->setup_post_mock(); @@ -624,7 +611,6 @@ 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 = ' @@ -1035,7 +1021,6 @@ 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() ); @@ -1382,7 +1367,6 @@ public function test_get_media_with_attachments() { * @covers ::post_data() * @covers ::to_insert() * @covers ::to_json() - * @runInSeparateProcess */ public function test_post_data_without_blocks() { $this->setup_post_mock(); @@ -1537,7 +1521,6 @@ 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

'; diff --git a/tests/php/EnqueueScriptTest.php b/tests/php/EnqueueScriptTest.php index 3a0c117af..2dab714eb 100644 --- a/tests/php/EnqueueScriptTest.php +++ b/tests/php/EnqueueScriptTest.php @@ -1,8 +1,9 @@ register( '\TestExternalConnection' ); @@ -59,7 +58,6 @@ public function test_instantiate_fail_type() { * * @since 0.8 * @group ExternalConnection - * @runInSeparateProcess */ public function test_instantiate_fail_not_registered() { Connections::factory()->register( '\TestExternalConnection' ); @@ -107,7 +105,6 @@ public function test_instantiate_fail_not_registered() { * * @since 0.8 * @group ExternalConnection - * @runInSeparateProcess */ public function test_instantiate_success() { Connections::factory()->register( '\TestExternalConnection' ); diff --git a/tests/php/HooksTest.php b/tests/php/HooksTest.php index f7b830c41..19b34dcff 100644 --- a/tests/php/HooksTest.php +++ b/tests/php/HooksTest.php @@ -1,11 +1,10 @@ setup_post_meta_mock( array( @@ -380,7 +378,6 @@ public function test_pull() { * * @since 0.8 * @group NetworkSiteConnection - * @runInSeparateProcess */ public function test_remote_get_empty_id() { @@ -404,7 +401,6 @@ public function test_remote_get_empty_id() { * * @since 0.8 * @group NetworkSiteConnection - * @runInSeparateProcess */ public function test_remote_get() { diff --git a/tests/php/SubscriptionsTest.php b/tests/php/SubscriptionsTest.php index 089599def..560a7e33e 100644 --- a/tests/php/SubscriptionsTest.php +++ b/tests/php/SubscriptionsTest.php @@ -1,8 +1,8 @@ connections = array(); + } +} diff --git a/tests/php/includes/common.php b/tests/php/Utils/common.php similarity index 88% rename from tests/php/includes/common.php rename to tests/php/Utils/common.php index e5100d37d..9a82bdb35 100644 --- a/tests/php/includes/common.php +++ b/tests/php/Utils/common.php @@ -4,6 +4,8 @@ * Simple common WP classes/functions */ +namespace Distributor\Tests\Utils; + /** * Hollowed out WP_Error class for mocking * @@ -316,38 +318,3 @@ 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() { } -} diff --git a/tests/php/UtilsTest.php b/tests/php/UtilsTest.php index da7effd89..9cf6f23bc 100644 --- a/tests/php/UtilsTest.php +++ b/tests/php/UtilsTest.php @@ -1,8 +1,8 @@ setup_post_meta_mock( array() ); @@ -251,7 +249,6 @@ public function test_push() { * * @since 0.8 * @group WordPressExternalConnection - * @runInSeparateProcess */ public function test_pull() { $this->setup_post_meta_mock( array() ); @@ -319,7 +316,6 @@ public function test_pull() { * * @since 0.8 * @group WordPressExternalConnection - * @runInSeparateProcess */ public function test_remote_get() { @@ -379,7 +375,6 @@ public function test_remote_get() { * * @since 0.8 * @group WordPressExternalConnection - * @runInSeparateProcess */ public function test_check_connections_no_errors() { @@ -420,7 +415,6 @@ public function test_check_connections_no_errors() { * * @since 1.0 * @group WordPressExternalConnection - * @runInSeparateProcess */ public function test_check_connections_no_distributor() { \WP_Mock::userFunction( diff --git a/tests/php/bootstrap.php b/tests/php/bootstrap.php index aa1585f2b..0640540c7 100644 --- a/tests/php/bootstrap.php +++ b/tests/php/bootstrap.php @@ -1,23 +1,35 @@ 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, - ) - ); - } -} From e4bf1e8b821e83fb2351699a83cd141afcfb8fa2 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 9 Jun 2023 12:03:36 +0530 Subject: [PATCH 02/14] doc: set correct return type --- includes/classes/Connections.php | 2 +- tests/php/{DistributorPostTest.php => DistributorPostTTest.php} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/php/{DistributorPostTest.php => DistributorPostTTest.php} (100%) 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/tests/php/DistributorPostTest.php b/tests/php/DistributorPostTTest.php similarity index 100% rename from tests/php/DistributorPostTest.php rename to tests/php/DistributorPostTTest.php From 4bac73cb81eb98e874333e5d5ddd513d3d715a32 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 9 Jun 2023 15:43:19 +0530 Subject: [PATCH 03/14] refactor: mark mocked tests incomplete --- tests/php/ConnectionsTest.php | 14 +- tests/php/DebugInfoTest.php | 2 +- tests/php/DistributorPostTTest.php | 2081 ----------------- tests/php/DistributorPostTest.php | 288 +++ tests/php/EnqueueScriptTest.php | 3 +- tests/php/ExternalConnectionTest.php | 147 +- tests/php/HooksTest.php | 808 +------ tests/php/Mocks/TestExternalConnection.php | 19 +- tests/php/Mocks/TestInternalConnection.php | 18 +- tests/php/NetworkSiteConnectionsTest.php | 465 +--- tests/php/SubscriptionsTest.php | 774 +----- .../Utils/ExternalConnectionPostGenerator.php | 58 + tests/php/Utils/PostGenerator.php | 51 + tests/php/Utils/common.php | 51 +- tests/php/UtilsTest.php | 890 +------ tests/php/WordPressExternalConnectionTest.php | 401 +--- tests/php/bootstrap.php | 3 +- 17 files changed, 630 insertions(+), 5443 deletions(-) delete mode 100644 tests/php/DistributorPostTTest.php create mode 100644 tests/php/DistributorPostTest.php create mode 100644 tests/php/Utils/ExternalConnectionPostGenerator.php create mode 100644 tests/php/Utils/PostGenerator.php diff --git a/tests/php/ConnectionsTest.php b/tests/php/ConnectionsTest.php index d68df2c5e..3c28a37ee 100644 --- a/tests/php/ConnectionsTest.php +++ b/tests/php/ConnectionsTest.php @@ -11,16 +11,20 @@ class ConnectionsTest extends TestCase { /** * Test connection registration * - * @since 0.8 - * @group Connections + * @covers \Distributor\Connections::register + * + * @since 0.8 + * @group Connections */ - public function test_register() { + public function test_register(): void { Connections::factory()->register( TestExternalConnection::class ); - $this->assertEquals( TestExternalConnection::class, Connections::factory()->get_registered()['test-external-connection'] ); + $this->assertEquals( TestExternalConnection::class, + Connections::factory()->get_registered()['test-external-connection'] ); Connections::factory()->register( TestInternalConnection::class, 'internal' ); - $this->assertEquals( TestInternalConnection::class, 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 fdc608618..558c16c21 100644 --- a/tests/php/DebugInfoTest.php +++ b/tests/php/DebugInfoTest.php @@ -11,7 +11,7 @@ class DebugInfoTest extends TestCase { /** * @covers \Distributor\DebugInfo\add_debug_info */ - public function test_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'] ); diff --git a/tests/php/DistributorPostTTest.php b/tests/php/DistributorPostTTest.php deleted file mode 100644 index 6c8c9a9a4..000000000 --- a/tests/php/DistributorPostTTest.php +++ /dev/null @@ -1,2081 +0,0 @@ -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, - ) - ); - } - - /** - * 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 - */ - public function test_public_methods() { - $actual_methods = get_class_methods( 'Distributor\DistributorPost' ); - $expected_methods = array( - '__construct', - '__call', - '__get', - '__isset', - ); - - sort( $actual_methods ); - sort( $expected_methods ); - $this->assertSame( $expected_methods, $actual_methods, 'Only magic methods are expected to be public.' ); - } - - /** - * Test the DistributorPost object for internal connections. - * - * @covers ::__construct - */ - 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, - ) - ); - - \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', - ) - ); - - \WP_Mock::userFunction( - 'home_url', - array( - 'return' => 'http://origin.example.org/', - ) - ); - - $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.' ); - } - - /** - * Test the DistributorPost object for external, pushed posts. - * - * @covers ::__construct - */ - 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.' ); - $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.' ); - } - - /** - * Test the DistributorPost object for external, pushed posts. - * - * @covers ::__construct - */ - 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.' ); - $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.' ); - } - - /** - * Test the DistributorPost object a source post. - * - * @covers ::__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() ); - - \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( 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.' ); - } - - /** - * Test the get_the_id() method. - * - * @covers ::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 ); - - $this->assertSame( 1, $dt_post->get_the_id() ); - } - - /** - * Test the get_permalink() method. - * - * @covers ::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 ); - - $this->assertSame( 'http://example.org/?p=1', $dt_post->get_permalink() ); - } - - /** - * Test the get_post_type() method. - * - * @covers ::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 ); - - $this->assertSame( 'post', $dt_post->get_post_type() ); - } - - /** - * Test the get_post_thumbnail_id() method. - * - * @covers ::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 ); - - $this->assertSame( 4, $dt_post->get_post_thumbnail_id() ); - } - - /** - * Test the get_post_thumbnail_url() method. - * - * @covers ::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 ); - - $this->assertSame( 'http://example.org/wp-content/uploads/2018/01/featured-image.jpg', $dt_post->get_post_thumbnail_url() ); - } - - /** - * Test the get_the_post_thumbnail() method. - * - * @covers ::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 ); - - $this->assertSame( $thumbnail, $dt_post->get_the_post_thumbnail() ); - } - - /** - * Test the get_meta() method. - * - * @covers ::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.' ), - ) - ); - - $dt_post = new DistributorPost( 1 ); - $excluded_meta = Utils\excluded_meta(); - $distributable_meta = $dt_post->get_meta(); - - $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." ); - } - } - - /** - * Test the get_terms() method. - * - * @covers ::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 ); - } - - /** - * Test the get_media() method with blocks. - * - * @covers ::get_media - * @covers ::parse_media_blocks - * @covers ::parse_blocks_for_attachment_id - */ - 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 ); - } - - /** - * Test the get_media() method with attachments. - * - * This tests the legacy fork of the method which is still used by posts - * authored in the classic editor. - * - * @covers ::get_media() - */ - 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 ); - } - - /** - * Test methods for formatting the post data without blocks. - * - * @covers ::post_data() - * @covers ::to_insert() - * @covers ::to_json() - */ - 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', - '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 ); - - // 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 ); - - // 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 ); - } - - /** - * Test methods for formatting the post data with blocks. - * - * @covers ::post_data() - * @covers ::to_insert() - * @covers ::to_json() - */ - 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', - '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 ); - - // 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 ); - - // 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 ); - } - - /** - * Test get_canonical_url() method. - * - * @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 ); - } - - /** - * Test get_canonical_url() method. - * - * @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 ); - } - - /** - * Test get_canonical_url() method. - * - * @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 ); - } - - /** - * Test get_author_name() method. - * - * @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 ); - } - - /** - * Test get_author_name() method. - * - * @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.' ); - } - - /** - * Test get_author_name() method. - * - * @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 ); - } - - /** - * Test get_author_name() method. - * - * @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 ); - } - - /** - * Test get_author_link() method. - * - * @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 ); - } - - /** - * Test get_author_link() method. - * - * @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.' ); - } - - /** - * Test get_author_link() method. - * - * @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 ); - } - - /** - * Test get_author_link() method. - * - * @covers ::get_author_link() - */ - public function test_get_author_link_source() { - $this->setup_post_mock(); - $this->setup_post_meta_mock( array() ); - - \WP_Mock::userFunction( - 'get_permalink', - array( - 'return' => 'http://source.example.org/?p=1', - ) - ); - - \WP_Mock::userFunction( - 'get_option', - array( - 'return' => array(), - ) - ); - - \WP_Mock::userFunction( - 'get_author_posts_url', - array( - 'return' => 'http://source.example.org/author/original-author-name/', - ) - ); - - $dt_post = new DistributorPost( 1 ); - $author_link_actual = $dt_post->get_author_link(); - $author_link_expected = 'http://source.example.org/author/original-author-name/'; - - $this->assertSame( $author_link_expected, $author_link_actual ); - } -} diff --git a/tests/php/DistributorPostTest.php b/tests/php/DistributorPostTest.php new file mode 100644 index 000000000..b7cb9aa22 --- /dev/null +++ b/tests/php/DistributorPostTest.php @@ -0,0 +1,288 @@ +assertSame( $expected_methods, $actual_methods, 'Only magic methods are expected to be public.' ); + } + + /** + * Test the DistributorPost object for internal connections. + * + * @covers ::__construct + */ + public function test_internal_connection(): void { + $this->markTestIncomplete(); + } + + /** + * Test the DistributorPost object for external, pushed posts. + * + * @covers ::__construct + */ + public function test_external_connection_with_pushed_post(): void { + $this->markTestIncomplete(); + } + + /** + * Test the DistributorPost object for external, pushed posts. + * + * @covers ::__construct + */ + public function test_external_connection_with_pulled_post(): void { + $this->markTestIncomplete(); + } + + /** + * Test the DistributorPost object a source post. + * + * @covers ::__construct + */ + public function test_source_post(): void { + $this->markTestIncomplete(); + } + + /** + * Test the get_the_id() method. + * + * @covers ::get_the_id + */ + public function test_get_the_id(): void { + $this->markTestIncomplete(); + } + + /** + * Test the get_permalink() method. + * + * @covers ::get_permalink + */ + public function test_get_permalink(): void { + $this->markTestIncomplete(); + } + + /** + * Test the get_post_type() method. + * + * @covers ::get_post_type + */ + public function test_get_post_type(): void { + $this->markTestIncomplete(); + } + + /** + * Test the get_post_thumbnail_id() method. + * + * @covers ::get_post_thumbnail_id + */ + public function test_get_post_thumbnail_id(): void { + $this->markTestIncomplete(); + } + + /** + * Test the get_post_thumbnail_url() method. + * + * @covers ::get_post_thumbnail_url + */ + public function test_get_post_thumbnail_url(): void { + $this->markTestIncomplete(); + } + + /** + * Test the get_the_post_thumbnail() method. + * + * @covers ::get_the_post_thumbnail + */ + public function test_get_the_post_thumbnail(): void { + $this->markTestIncomplete(); + } + + /** + * Test the get_meta() method. + * + * @covers ::get_meta + */ + public function test_get_meta(): void { + $this->markTestIncomplete(); + } + + /** + * Test the get_terms() method. + * + * @covers ::get_terms + */ + public function test_get_terms(): void { + $this->markTestIncomplete(); + } + + /** + * Test the get_media() method with blocks. + * + * @covers ::get_media + * @covers ::parse_media_blocks + * @covers ::parse_blocks_for_attachment_id + */ + public function test_get_media_with_blocks(): void { + $this->markTestIncomplete(); + } + + /** + * Test the get_media() method with attachments. + * + * This tests the legacy fork of the method which is still used by posts + * authored in the classic editor. + * + * @covers ::get_media() + */ + public function test_get_media_with_attachments(): void { + $this->markTestIncomplete(); + } + + /** + * Test methods for formatting the post data without blocks. + * + * @covers ::post_data() + * @covers ::to_insert() + * @covers ::to_json() + */ + public function test_post_data_without_blocks(): void { + $this->markTestIncomplete(); + } + + /** + * Test methods for formatting the post data with blocks. + * + * @covers ::post_data() + * @covers ::to_insert() + * @covers ::to_json() + */ + public function test_post_data_with_blocks(): void { + $this->markTestIncomplete(); + } + + /** + * Test get_canonical_url() method. + * + * @covers ::get_canonical_url() + */ + public function test_get_canonical_url(): void { + $this->markTestIncomplete(); + } + + /** + * Test get_canonical_url() method. + * + * @covers ::get_canonical_url() + */ + public function test_get_canonical_url_unlinked(): void { + $this->markTestIncomplete(); + } + + /** + * Test get_canonical_url() method. + * + * @covers ::get_canonical_url() + */ + public function test_get_canonical_url_source(): void { + $this->markTestIncomplete(); + } + + /** + * Test get_author_name() method. + * + * @covers ::get_author_name() + */ + public function test_get_author_name(): void { + $this->markTestIncomplete(); + } + + /** + * Test get_author_name() method. + * + * @covers ::get_author_name() + */ + public function test_get_author_name_without_override(): void { + $this->markTestIncomplete(); + } + + /** + * Test get_author_name() method. + * + * @covers ::get_author_name() + */ + public function test_get_author_name_unlinked(): void { + $this->markTestIncomplete(); + } + + /** + * Test get_author_name() method. + * + * @covers ::get_author_name() + */ + public function test_get_author_name_source(): void { + $this->markTestIncomplete(); + } + + /** + * Test get_author_link() method. + * + * @covers ::get_author_link() + */ + public function test_get_author_link(): void { + $this->markTestIncomplete(); + } + + /** + * Test get_author_link() method. + * + * @covers ::get_author_link() + */ + public function test_get_author_link_without_override(): void { + $this->markTestIncomplete(); + } + + /** + * Test get_author_link() method. + * + * @covers ::get_author_link() + */ + public function test_get_author_link_unlinked(): void { + $this->markTestIncomplete(); + } + + /** + * Test get_author_link() method. + * + * @covers ::get_author_link() + */ + public function test_get_author_link_source(): void { + $this->markTestIncomplete(); + } +} diff --git a/tests/php/EnqueueScriptTest.php b/tests/php/EnqueueScriptTest.php index 2dab714eb..987933c38 100644 --- a/tests/php/EnqueueScriptTest.php +++ b/tests/php/EnqueueScriptTest.php @@ -3,12 +3,11 @@ namespace Distributor\Tests; use Distributor\EnqueueScript; -use PHPUnit\Framework\TestCase; /** * @since x.x.x */ -class EnqueueScriptTest extends TestCase { +class EnqueueScriptTest extends Utils\TestCase { public function test_script_registration(): void { $this->markTestIncomplete(); } diff --git a/tests/php/ExternalConnectionTest.php b/tests/php/ExternalConnectionTest.php index e76718dfe..629a133f2 100644 --- a/tests/php/ExternalConnectionTest.php +++ b/tests/php/ExternalConnectionTest.php @@ -2,148 +2,79 @@ namespace Distributor\Tests; -use PHPUnit\Framework\TestCase; +use Distributor\Connections; +use Distributor\ExternalConnection; +use Distributor\ExternalConnections\WordPressExternalConnection; +use Distributor\Tests\Mocks\TestExternalConnection; +use Distributor\Tests\Utils\ExternalConnectionPostGenerator; +use WP_Error; -class ExternalConnectionTest extends TestCase { +class ExternalConnectionTest extends Utils\TestCase { /** * Text External Connection instantiation failure on no type * * @since 0.8 - * @group ExternalConnection + * @group ExternalConnection */ - public function test_instantiate_fail_type() { - 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' => 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 + * @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 + * @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 19b34dcff..24290a626 100644 --- a/tests/php/HooksTest.php +++ b/tests/php/HooksTest.php @@ -2,126 +2,16 @@ namespace Distributor\Tests; -use Distributor\Hooks; - -class HooksTest extends \PHPUnit\Framework\TestCase { - - /** - * Set up with WP_Mock - * - * Set up common mocks required for multiple tests. - * - * @since x.x.x - */ - public function setUp(): void { - parent::setUp(); - - \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' ); - } - - /** - * 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, - ) - ); - } +use Distributor\Tests\Utils\TestCase; +class HooksTest extends TestCase { /** * Test get_canonical_url * * @since x.x.x */ - 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(); } /** @@ -129,37 +19,8 @@ public function test_get_canonical_url_source() { * * @since x.x.x */ - 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(); } /** @@ -167,37 +28,8 @@ public function test_get_canonical_url_external_pushed() { * * @since x.x.x */ - 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(); } /** @@ -205,33 +37,8 @@ public function test_get_canonical_url_external_pulled() { * * @since x.x.x */ - 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(); } /** @@ -239,26 +46,8 @@ public function test_get_canonical_url_internal() { * * @since x.x.x */ - 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(); } /** @@ -266,37 +55,8 @@ public function test_wpseo_canonical_source() { * * @since x.x.x */ - 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(); } /** @@ -304,37 +64,8 @@ public function test_wpseo_canonical_external_pushed() { * * @since x.x.x */ - 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(); } /** @@ -343,32 +74,7 @@ public function test_wpseo_canonical_external_pulled() { * @since x.x.x */ 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(); } /** @@ -376,26 +82,8 @@ public function test_wpseo_canonical_internal() { * * @since x.x.x */ - 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(); } /** @@ -403,37 +91,8 @@ public function test_wpseo_opengraph_url_source() { * * @since x.x.x */ - 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(); } /** @@ -441,37 +100,8 @@ public function test_wpseo_opengraph_url_external_pushed() { * * @since x.x.x */ - 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(); } /** @@ -479,33 +109,8 @@ public function test_wpseo_opengraph_url_external_pulled() { * * @since x.x.x */ - 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(); } /** @@ -513,33 +118,8 @@ public function test_wpseo_opengraph_url_internal() { * * @since x.x.x */ - 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(); } /** @@ -547,44 +127,8 @@ public function test_filter_the_author_source() { * * @since x.x.x */ - 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(); } /** @@ -592,44 +136,8 @@ public function test_filter_the_author_external_pushed() { * * @since x.x.x */ - 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(); } /** @@ -637,71 +145,8 @@ public function test_filter_the_author_external_pulled() { * * @since x.x.x */ - 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(); } /** @@ -709,36 +154,8 @@ public function test_filter_the_author_internal() { * * @since x.x.x */ - 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(); } /** @@ -746,12 +163,8 @@ public function test_get_the_author_display_name_source() { * * @since x.x.x */ - 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(); } /** @@ -759,44 +172,8 @@ public function test_get_the_author_display_name_no_post() { * * @since x.x.x */ - 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(); } /** @@ -804,44 +181,8 @@ public function test_get_the_author_display_name_external_pushed() { * * @since x.x.x */ - 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(); } /** @@ -849,70 +190,7 @@ public function test_get_the_author_display_name_external_pulled() { * * @since x.x.x */ - 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 index ee84fa3c6..dd5f014a7 100644 --- a/tests/php/Mocks/TestExternalConnection.php +++ b/tests/php/Mocks/TestExternalConnection.php @@ -6,17 +6,22 @@ * Classes for testing connections */ class TestExternalConnection extends \Distributor\ExternalConnection { - static $slug = 'test-external-connection'; + static $slug = 'test-external-connection'; static $auth_handler_class = '\Distributor\Authentications\WordPressBasicAuth'; - static $namespace = 'wp/v2'; + static $namespace = 'wp/v2'; - public function push( $item_id, $args = array() ) { } + public function push( $item_id, $args = array() ) { + } - public function pull( $items ) { } + public function pull( $items ) { + } - public function check_connections() { } + public function check_connections() { + } - public function remote_get( $args ) { } + public function remote_get( $args ) { + } - public function get_post_types() { } + public function get_post_types() { + } } diff --git a/tests/php/Mocks/TestInternalConnection.php b/tests/php/Mocks/TestInternalConnection.php index 4c68093fc..76bf827e9 100644 --- a/tests/php/Mocks/TestInternalConnection.php +++ b/tests/php/Mocks/TestInternalConnection.php @@ -5,15 +5,21 @@ class TestInternalConnection extends \Distributor\Connection { static $slug = 'test-internal-connection'; - public function push( $item_id, $args = array() ) { } + public function push( $item_id, $args = array() ) { + } - public function pull( $items ) { } + public function pull( $items ) { + } - public function remote_get( $args ) { } + public function remote_get( $args ) { + } - public function log_sync( array $item_id_mappings, $id, $overwrite ) {} + public function log_sync( array $item_id_mappings, $id, $overwrite ) { + } - public function get_sync_log( $id ) {} + public function get_sync_log( $id ) { + } - public function get_post_types() { } + public function get_post_types() { + } } diff --git a/tests/php/NetworkSiteConnectionsTest.php b/tests/php/NetworkSiteConnectionsTest.php index 8f5ba977e..08c2d4218 100644 --- a/tests/php/NetworkSiteConnectionsTest.php +++ b/tests/php/NetworkSiteConnectionsTest.php @@ -2,228 +2,21 @@ namespace Distributor\Tests; -use PHPUnit\Framework\TestCase; +use Distributor\InternalConnections\NetworkSiteConnection; +use Distributor\Tests\Utils\TestCase; class NetworkSiteConnectionsTest extends TestCase { - /** - * Site object. - * - * @var \WP_Site - */ - public $site_obj; - - /** - * Connection object. - * - * @var NetworkSiteConnection - */ - public $connection_obj; - - public function setUp(): void { - $this->site_obj = \Mockery::mock( - '\WP_Site', [ - 'args' => 1, - 'return' => '', - ] - ); - - $this->connection_obj = new NetworkSiteConnection( $this->site_obj ); - } - - /** - * 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, - ) - ); - } + public \WP_Site $site_obj; + public NetworkSiteConnection $connection_obj; /** * Push returns an post ID on success instance of WP Error on failure. * * @since 0.8 - * @group NetworkSiteConnection + * @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', - ], - ] - ); - - \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 { + $this->markTestIncomplete(); } /** @@ -232,145 +25,10 @@ public function test_push() { * three integers. * * @since 0.8 - * @group NetworkSiteConnection + * @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', - '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, - ] - ); - - \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 ); - + $this->markTestIncomplete(); } /** @@ -379,21 +37,8 @@ public function test_pull() { * @since 0.8 * @group NetworkSiteConnection */ - 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' ); - - $this->assertArrayHasKey( 'total_items', $this->connection_obj->remote_get() ); - + public function test_remote_get_empty_id(): void { + $this->markTestIncomplete(); } /** @@ -402,92 +47,8 @@ public function test_remote_get_empty_id() { * @since 0.8 * @group NetworkSiteConnection */ - public function test_remote_get() { - - \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->connection_obj->site->blog_id = 321; - - \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', - ], - ] - ); - - \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_current_blog_id', [ - 'return' => 1, - ] - ); - - \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, - ] - ) - ); - + public function test_remote_get(): void { + $this->markTestIncomplete(); } } diff --git a/tests/php/SubscriptionsTest.php b/tests/php/SubscriptionsTest.php index 560a7e33e..00c3e8483 100644 --- a/tests/php/SubscriptionsTest.php +++ b/tests/php/SubscriptionsTest.php @@ -2,8 +2,7 @@ namespace Distributor\Tests; -use PHPUnit\Framework\TestCase; -use WP_Mock\Functions; +use Distributor\Tests\Utils\TestCase; class SubscriptionsTest extends TestCase { @@ -11,607 +10,50 @@ class SubscriptionsTest extends TestCase { * Test delete subscribed to post * * @since 1.0 - * @group Subscriptions + * @group Subscriptions */ - public function test_delete_subscribed_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' => 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 + * @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 + * @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 + * @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 + * @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(); } /** @@ -619,77 +61,10 @@ public function test_send_notifications_remote_post_exists() { * remote post has subscribed to * * @since 1.0 - * @group Subscriptions + * @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(); } /** @@ -697,122 +72,19 @@ public function test_create_subscription() { * local post has subscribed to * * @since 1.0 - * @group Subscriptions + * @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 + * @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..caeb5fef3 --- /dev/null +++ b/tests/php/Utils/PostGenerator.php @@ -0,0 +1,51 @@ + '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_name' => 'test-post', + 'post_content_filtered' => '', + ); + + return wp_insert_post( $postData ); + } + + /** + * @param int $postId + * @param array $metaData + * + * @return void + */ + public static function saveMeta( int $postId, array $metaData ): void { + foreach ( $metaData as $metaKey => $metaValue ) { + update_post_meta( $postId, $metaKey, $metaValue ); + } + } +} diff --git a/tests/php/Utils/common.php b/tests/php/Utils/common.php index 9a82bdb35..5b6a8a8fc 100644 --- a/tests/php/Utils/common.php +++ b/tests/php/Utils/common.php @@ -6,38 +6,31 @@ namespace Distributor\Tests\Utils; -/** - * Hollowed out WP_Error class for mocking - * - * @since 0.8 - */ -class WP_Error { - public function __construct( $code = '', $message = '' ) { - $this->code = $code; - $this->message = $message; - } -} - /** * 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 ) { @@ -56,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; } @@ -79,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 ); @@ -93,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; } @@ -105,7 +100,6 @@ function is_serialized( $data, $strict = true ) { */ class WP_Query { public function __construct( $args = array() ) { - $items = [ [ 'ID' => 2, @@ -133,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 ) { @@ -156,7 +150,6 @@ function is_wp_error( $thing ) { * @return void */ function remote_get_setup() { - \WP_Mock::userFunction( 'get_option' ); $rest_response = [ @@ -190,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'] ); @@ -276,9 +269,10 @@ function get_allowed_mime_types() { * * @since x.x.x * - * @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 ) { @@ -292,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 ) { @@ -306,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 ) { @@ -317,4 +313,5 @@ function absint( $maybeint ) { * * @return void */ -function remove_filter() { } +function remove_filter() { +} diff --git a/tests/php/UtilsTest.php b/tests/php/UtilsTest.php index 9cf6f23bc..db1063686 100644 --- a/tests/php/UtilsTest.php +++ b/tests/php/UtilsTest.php @@ -2,255 +2,39 @@ namespace Distributor\Tests; -use PHPUnit\Framework\TestCase; +use Distributor\Tests\Utils\TestCase; +use Distributor\Utils; class UtilsTest extends TestCase { - /** - * Set up with WP_Mock - * - * Set up common mocks required for multiple tests. - * - * @since x.x.x - */ - public function setUp(): void { - parent::setUp(); - - - // Return voids. - \WP_Mock::userFunction( '_prime_post_caches' ); - \WP_Mock::userFunction( 'update_object_term_cache' ); - \WP_Mock::userFunction( 'update_postmeta_cache' ); - } - /** * Test set meta with string value and array value * * @since 1.0 - * @group Utils + * @group Utils */ - public function test_set_meta_simple() { - \WP_Mock::userFunction( - 'get_post_meta', [ - 'times' => 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 + * @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 + * @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(); } /** @@ -259,82 +43,8 @@ public function test_set_meta_serialize() { * @since 1.0 * @group Utils */ - 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(); } /** @@ -343,88 +53,8 @@ public function test_set_taxonomy_terms_simple() { * @since 1.0 * @group Utils */ - 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(); } /** @@ -433,141 +63,8 @@ public function test_set_taxonomy_terms_create_term() { * @since 1.0 * @group Utils */ - 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 - */ - 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(); } /** @@ -576,94 +73,8 @@ public function test_format_media_not_featured() { * @since 1.0 * @group Utils */ - 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(); } /** @@ -671,95 +82,8 @@ public function test_format_media_featured() { * * @group Utils */ - 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(); } /** @@ -768,164 +92,8 @@ public function test_format_media_no_attachment_meta() { * @since 1.0 * @group Utils */ - 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(); } /** @@ -936,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 99cfd3b5d..34d21f8db 100644 --- a/tests/php/WordPressExternalConnectionTest.php +++ b/tests/php/WordPressExternalConnectionTest.php @@ -1,65 +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 + * @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 ); } /** @@ -73,301 +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 */ - 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, - ]; - - \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 + * @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 + * @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(); } /** @@ -377,37 +84,7 @@ public function test_remote_get() { * @group WordPressExternalConnection */ 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(); } /** @@ -417,34 +94,6 @@ public function test_check_connections_no_errors() { * @group WordPressExternalConnection */ 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 0640540c7..2c4e6bebe 100644 --- a/tests/php/bootstrap.php +++ b/tests/php/bootstrap.php @@ -1,6 +1,7 @@ Date: Fri, 9 Jun 2023 20:42:55 +0530 Subject: [PATCH 04/14] dev: update test github workflow --- .github/workflows/test.yml | 67 +++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c769f53a6..1651f4347 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Test +name: PHPUnit Tests env: COMPOSER_VERSION: "2" @@ -10,15 +10,12 @@ on: push: branches: - develop - - develop-v1 - trunk pull_request: branches: - develop - - develop-v1 jobs: - phpunit: name: ${{ matrix.php }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} @@ -29,33 +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: Setup WP Tests - run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 - - - 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 bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 + + - name: PHPUnit + run: composer run test From bd353ee25c7f518eff0486ad5c52f7d05665c974 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 15 Sep 2023 10:50:15 +0530 Subject: [PATCH 05/14] format: improve code formatting --- includes/debug-info.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/debug-info.php b/includes/debug-info.php index 4a262e38e..9100b1785 100644 --- a/includes/debug-info.php +++ b/includes/debug-info.php @@ -80,7 +80,7 @@ function enqueue_scripts( $hook ) { function add_debug_info( $info ) { $text_domain = 'distributor'; - $defaults = [ + $defaults = [ 'email' => '', 'valid_license' => false, 'license_key' => '', From 2f7917e90e52a064eac6a7666d71a34aa79f7cf8 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 15 Sep 2023 11:03:00 +0530 Subject: [PATCH 06/14] refactor: change file location --- .github/workflows/test.yml | 2 +- {bin => tests/bin}/install-wp-tests.sh | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename {bin => tests/bin}/install-wp-tests.sh (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1651f4347..9222be955 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,7 +54,7 @@ jobs: run: composer update -W - name: Setup WP Tests - run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 + run: bash tests/bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 - name: PHPUnit run: composer run test diff --git a/bin/install-wp-tests.sh b/tests/bin/install-wp-tests.sh similarity index 100% rename from bin/install-wp-tests.sh rename to tests/bin/install-wp-tests.sh From 9a0491df08d8cdaf60a6599891f1c2a65942e10a Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 15 Sep 2023 11:25:29 +0530 Subject: [PATCH 07/14] format: remove unnecessary php doc tags from class comment --- includes/classes/DistributorPost.php | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/includes/classes/DistributorPost.php b/includes/classes/DistributorPost.php index ce440013e..64021cd20 100644 --- a/includes/classes/DistributorPost.php +++ b/includes/classes/DistributorPost.php @@ -28,24 +28,6 @@ * * @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 { /** From 458e45193efa07aba4d50f8f9d50edf47ae53e4e Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 15 Sep 2023 15:36:18 +0530 Subject: [PATCH 08/14] tests: update DistributorPostTest --- composer.json | 2 +- composer.lock | 2 +- phpunit.xml.dist | 3 + tests/php/DistributorPostTest.php | 273 ++++++++++++++++++++++++++---- tests/php/Utils/PostGenerator.php | 30 ++-- 5 files changed, 269 insertions(+), 41 deletions(-) diff --git a/composer.json b/composer.json index 60b2e5b01..0a79bfcc8 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "require-dev": { "10up/phpcs-composer": "dev-master", "automattic/vipwpcs": "^2.3", - "php-stubs/wordpress-tests-stubs": "^6.2", + "php-stubs/wordpress-tests-stubs": "^6.3", "yoast/phpunit-polyfills": "dev-main" }, "scripts": { diff --git a/composer.lock b/composer.lock index e55322585..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": "19f4d2ff4e8a0bf4bdd5692a4ba3315b", + "content-hash": "0724171bbfdaecc959aaf538d1d455ab", "packages": [ { "name": "yahnis-elsts/plugin-update-checker", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 599fc34fb..53b407062 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,6 +6,9 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" > + + + ./tests/php/ diff --git a/tests/php/DistributorPostTest.php b/tests/php/DistributorPostTest.php index b7cb9aa22..94e9348d2 100644 --- a/tests/php/DistributorPostTest.php +++ b/tests/php/DistributorPostTest.php @@ -3,7 +3,9 @@ namespace Distributor\Tests; use Distributor\DistributorPost; -use Distributor\Tests\Utils\TestCase; +use Distributor\Tests\Utils\PostGenerator; + +use function Distributor\Utils\excluded_meta; /** * Tests for the DistributorPost class. @@ -11,14 +13,14 @@ * @covers \Distributor\DistributorPost * @group Post */ -class DistributorPostTest extends TestCase { +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 + * @covers \Distributor\DistributorPost::__construct */ public function test_public_methods(): void { $actual_methods = get_class_methods( DistributorPost::class ); @@ -37,106 +39,292 @@ public function test_public_methods(): void { /** * Test the DistributorPost object for internal connections. * - * @covers ::__construct + * @covers \Distributor\DistributorPost::__construct + * @dataProvider internal_connection_data_provider */ - public function test_internal_connection(): void { - $this->markTestIncomplete(); + 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.' + ); + $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.' + ); + $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 + * @covers \Distributor\DistributorPost::__construct + * @dataProvider internal_connection_data_provider */ - public function test_external_connection_with_pushed_post(): void { - $this->markTestIncomplete(); + 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( $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 + * @covers \Distributor\DistributorPost::__construct + * @dataProvider internal_connection_data_provider */ - public function test_external_connection_with_pulled_post(): void { - $this->markTestIncomplete(); + 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( $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 + * @covers \Distributor\DistributorPost::__construct */ public function test_source_post(): void { - $this->markTestIncomplete(); + $post = ( new PostGenerator() )->create()->getPost(); + $dt_post = new DistributorPost( $post ); + + $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( + 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 + * @covers \Distributor\DistributorPost::get_the_id */ public function test_get_the_id(): void { - $this->markTestIncomplete(); + $post = ( new PostGenerator() )->create()->getPost(); + $dt_post = new DistributorPost( $post ); + + $this->assertSame( $post->ID, $dt_post->get_the_id() ); } /** * Test the get_permalink() method. * - * @covers ::get_permalink + * @covers \Distributor\DistributorPost::get_permalink */ public function test_get_permalink(): void { - $this->markTestIncomplete(); + $post = ( new PostGenerator() )->create()->getPost(); + $dt_post = new DistributorPost( $post ); + + $this->assertSame( get_permalink( $post ), $dt_post->get_permalink() ); } /** * Test the get_post_type() method. * - * @covers ::get_post_type + * @covers \Distributor\DistributorPost::get_post_type */ public function test_get_post_type(): void { - $this->markTestIncomplete(); + $post = ( new PostGenerator() )->create()->getPost(); + $dt_post = new DistributorPost( $post ); + + $this->assertSame( get_post_type( $post ), $dt_post->get_post_type() ); } /** * Test the get_post_thumbnail_id() method. * - * @covers ::get_post_thumbnail_id + * @covers \Distributor\DistributorPost::get_post_thumbnail_id */ public function test_get_post_thumbnail_id(): void { - $this->markTestIncomplete(); + $post = ( new PostGenerator() )->create()->getPost(); + $dt_post = new DistributorPost( $post ); + + $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 + * @covers \Distributor\DistributorPost::get_post_thumbnail_url */ public function test_get_post_thumbnail_url(): void { - $this->markTestIncomplete(); + $post = ( new PostGenerator() )->create()->getPost(); + $dt_post = new DistributorPost( $post ); + + $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 + * @covers \Distributor\DistributorPost::get_the_post_thumbnail */ public function test_get_the_post_thumbnail(): void { - $this->markTestIncomplete(); + $post = ( new PostGenerator() )->create()->getPost(); + $dt_post = new DistributorPost( $post ); + + $this->assertSame( get_the_post_thumbnail( $post ), $dt_post->get_the_post_thumbnail() ); } /** * Test the get_meta() method. * - * @covers ::get_meta + * @covers \Distributor\DistributorPost::get_meta */ public function test_get_meta(): void { - $this->markTestIncomplete(); + $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 ); + + $excluded_meta = excluded_meta(); + $distributable_meta = $dt_post->get_meta(); + + $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." + ); + } } /** * Test the get_terms() method. * - * @covers ::get_terms + * @covers \Distributor\DistributorPost::get_terms */ public function test_get_terms(): void { $this->markTestIncomplete(); @@ -285,4 +473,31 @@ public function test_get_author_link_unlinked(): void { public function test_get_author_link_source(): void { $this->markTestIncomplete(); } + + /** + * This method provides data for the internal connection tests. + */ + public function internal_connection_data_provider(): array { + $data = new \stdClass(); + + $main_blog_id = get_site()->id; + + // 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 ); + + // Reset to main blog. + switch_to_blog( $main_blog_id ); + + return array( array( $data ) ); + } } diff --git a/tests/php/Utils/PostGenerator.php b/tests/php/Utils/PostGenerator.php index caeb5fef3..9ec7a083e 100644 --- a/tests/php/Utils/PostGenerator.php +++ b/tests/php/Utils/PostGenerator.php @@ -6,10 +6,13 @@ * Class PostGenerator */ class PostGenerator { + /* @var \WP_Post $post */ + private $post; + /** - * @return int|\WP_Error + * This function should create a "post" post type post. */ - public static function create() { + public function create(): self { $postData = array( 'post_title' => 'Test Post', 'post_content' => 'Test Content', @@ -30,22 +33,29 @@ public static function create() { 'pinged' => '', 'to_ping' => '', 'post_password' => '', - 'post_name' => 'test-post', 'post_content_filtered' => '', ); - return wp_insert_post( $postData ); + $this->post = get_post( wp_insert_post( $postData ) ); + + return $this; } /** - * @param int $postId - * @param array $metaData - * - * @return void + * This function should save meta to post. */ - public static function saveMeta( int $postId, array $metaData ): void { + public function withMeta( array $metaData ): self { foreach ( $metaData as $metaKey => $metaValue ) { - update_post_meta( $postId, $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; } } From 35d16342a3d74ba067e78e7bd82c6e289829c1a4 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 15 Sep 2023 15:38:16 +0530 Subject: [PATCH 09/14] format: improve code formatting --- .github/phpcs-report.xml | 7 +++++++ includes/classes/DistributorPost.php | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .github/phpcs-report.xml diff --git a/.github/phpcs-report.xml b/.github/phpcs-report.xml new file mode 100644 index 000000000..601422a2d --- /dev/null +++ b/.github/phpcs-report.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/includes/classes/DistributorPost.php b/includes/classes/DistributorPost.php index 64021cd20..2b84be472 100644 --- a/includes/classes/DistributorPost.php +++ b/includes/classes/DistributorPost.php @@ -27,7 +27,6 @@ * shown in IDEs. * * @since 2.0.0 - * */ class DistributorPost { /** From bb15e92f0078289da7112d23b105d763adcc2d29 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Mon, 25 Sep 2023 19:56:37 +0530 Subject: [PATCH 10/14] chore: remove unnecessary file --- .github/phpcs-report.xml | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .github/phpcs-report.xml diff --git a/.github/phpcs-report.xml b/.github/phpcs-report.xml deleted file mode 100644 index 601422a2d..000000000 --- a/.github/phpcs-report.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - From 17326aa36ad2d42655cdae52053c71af72aa00c8 Mon Sep 17 00:00:00 2001 From: 10upbot on GitHub <10upbot+github@10up.com> Date: Thu, 11 Jan 2024 12:38:40 +0530 Subject: [PATCH 11/14] add: create README.md file for tests directory --- tests/README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/README.md diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 000000000..3d39179de --- /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.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.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 From 917a7ec14d3dc558533ddd27603d087b5fa650b0 Mon Sep 17 00:00:00 2001 From: 10upbot on GitHub <10upbot+github@10up.com> Date: Thu, 11 Jan 2024 12:43:26 +0530 Subject: [PATCH 12/14] add: update file name --- tests/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/README.md b/tests/README.md index 3d39179de..8850bb63d 100644 --- a/tests/README.md +++ b/tests/README.md @@ -15,14 +15,14 @@ This document discusses unit tests. 2. Install WordPress and the WP Unit Test lib using the `install.sh` script: ``` - $ tests/bin/install.sh [db-host] + $ 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.sh distributor_tests root root + $ 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. From 45ebf8ddfe3619bfd2c556242671eb44e0ad41f0 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Thu, 25 Jul 2024 21:25:35 +0530 Subject: [PATCH 13/14] add tests for `NetworkSiteConnection` class --- tests/php/DistributorPostTest.php | 2 - tests/php/NetworkSiteConnectionsTest.php | 90 +++++++++++++++++++++--- 2 files changed, 81 insertions(+), 11 deletions(-) diff --git a/tests/php/DistributorPostTest.php b/tests/php/DistributorPostTest.php index 7b798b23d..a5203e00b 100644 --- a/tests/php/DistributorPostTest.php +++ b/tests/php/DistributorPostTest.php @@ -359,7 +359,6 @@ public function test_get_media_with_attachments(): void { * @covers ::get_media * @covers ::parse_media_blocks * @covers ::parse_blocks_for_attachment_id - * @runInSeparateProcess * @doesNotPerformAssertions */ public function test_get_media_sets_cache() { @@ -372,7 +371,6 @@ 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->markTestIncomplete(); diff --git a/tests/php/NetworkSiteConnectionsTest.php b/tests/php/NetworkSiteConnectionsTest.php index 08c2d4218..7217b5f7f 100644 --- a/tests/php/NetworkSiteConnectionsTest.php +++ b/tests/php/NetworkSiteConnectionsTest.php @@ -2,21 +2,50 @@ namespace Distributor\Tests; +use Distributor\Tests\Utils\PostGenerator; use Distributor\InternalConnections\NetworkSiteConnection; -use Distributor\Tests\Utils\TestCase; -class NetworkSiteConnectionsTest extends TestCase { +class NetworkSiteConnectionsTest extends \WP_UnitTestCase { public \WP_Site $site_obj; public NetworkSiteConnection $connection_obj; /** - * Push returns an post ID on success instance of WP Error on failure. + * This method is called before the first test of this test class is run. + * + * @codeCoverageIgnore + * + * @return void + */ + public function setUp(): void { + parent::setUp(); + + // Create a new blog. + $data = new \stdClass(); + $data->blog = self::factory()->blog->create_and_get( array( + 'blog_id' => 2, + 'domain' => 'origin.example.org', + ) ); + + // $this->site_obj = get_site(); + $this->site_obj = $data->blog; + + $this->connection_obj = new NetworkSiteConnection( $this->site_obj ); // Setting a connection for a second site. + } + + // public function + + /** + * Push returns an post array on success, Instance of WP Error on failure. * * @since 0.8 * @group NetworkSiteConnection */ public function test_push(): void { - $this->markTestIncomplete(); + $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 ) ); } /** @@ -25,30 +54,73 @@ public function test_push(): void { * three integers. * * @since 0.8 + * @covers \Distributor\InternalConnections\NetworkSiteConnection::pull + * @dataProvider network_connection_data_provider * @group NetworkSiteConnection */ - public function test_pull() { - $this->markTestIncomplete(); + public function test_pull( $data ): void { + $items = array( + array( 'remote_post_id' => $data->post->ID ), + ); + + $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 */ public function test_remote_get_empty_id(): void { - $this->markTestIncomplete(); + $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 */ - public function test_remote_get(): void { - $this->markTestIncomplete(); + 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, + ] + ) + ); } + /** + * This method provides data for the internal connection tests. + */ + public function network_connection_data_provider(): array { + $data = new \stdClass(); + + $main_blog_id = get_site()->id; + + // 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 ); + + // Reset to main blog. + switch_to_blog( $main_blog_id ); + + return array( array( $data ) ); + } } From 7b3d75cd266c024fbee347af13f15a58c7a363c9 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Thu, 25 Jul 2024 21:28:49 +0530 Subject: [PATCH 14/14] remove already defined consts, https://github.com/10up/distributor/actions/runs/10097420348/job/27922230463?pr=1073 --- tests/php/bootstrap.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/php/bootstrap.php b/tests/php/bootstrap.php index bb11803ce..2c4e6bebe 100644 --- a/tests/php/bootstrap.php +++ b/tests/php/bootstrap.php @@ -10,8 +10,6 @@ define( 'FS_METHOD', 'direct' ); define( 'TEST_DIR', __DIR__ ); define( 'PHPUNIT_RUNNER', true ); -define( 'DT_PLUGIN_PATH', dirname( __DIR__, 2 ) ); -define( 'DT_VERSION', '2.0.4' ); if ( ! $_tests_dir ) { $_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';