From f19c850d093fd2d9516abe92a60692b43a003c71 Mon Sep 17 00:00:00 2001 From: Adam Wood Date: Thu, 26 Jan 2023 16:49:35 +1300 Subject: [PATCH 01/10] Parse core/list-items like paragraphs when building patterns --- env/export-content/includes/parser.php | 11 ++++++----- .../parsers/{Paragraph.php => RichText.php} | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) rename env/export-content/includes/parsers/{Paragraph.php => RichText.php} (69%) diff --git a/env/export-content/includes/parser.php b/env/export-content/includes/parser.php index df0a54e0..8ca45dd2 100644 --- a/env/export-content/includes/parser.php +++ b/env/export-content/includes/parser.php @@ -7,7 +7,7 @@ require_once __DIR__ . '/parsers/Button.php'; require_once __DIR__ . '/parsers/Heading.php'; require_once __DIR__ . '/parsers/Noop.php'; -require_once __DIR__ . '/parsers/Paragraph.php'; +require_once __DIR__ . '/parsers/RichText.php'; // Unused. require_once __DIR__ . '/parsers/ShortcodeBlock.php'; @@ -21,10 +21,11 @@ class BlockParser { public function __construct() { $this->parsers = [ // Core blocks that have custom parsers. - 'core/paragraph' => new Parsers\Paragraph(), - 'core/heading' => new Parsers\Heading(), - 'core/button' => new Parsers\Button(), - 'core/spacer' => new Parsers\Noop(), + 'core/paragraph' => new Parsers\RichText(), + 'core/list-item' => new Parsers\RichText(), + 'core/heading' => new Parsers\Heading(), + 'core/button' => new Parsers\Button(), + 'core/spacer' => new Parsers\Noop(), // Common core blocks that use the default parser. 'core/buttons' => new Parsers\BasicText(), diff --git a/env/export-content/includes/parsers/Paragraph.php b/env/export-content/includes/parsers/RichText.php similarity index 69% rename from env/export-content/includes/parsers/Paragraph.php rename to env/export-content/includes/parsers/RichText.php index 9f29a9bc..6521c6f6 100644 --- a/env/export-content/includes/parsers/Paragraph.php +++ b/env/export-content/includes/parsers/RichText.php @@ -2,7 +2,8 @@ namespace WordPress_org\Main_2022\ExportToPatterns\Parsers; -class Paragraph implements BlockParser { +// Default block type is core/paragraph but also handles core/list-item +class RichText implements BlockParser { use GetSetAttribute; public function to_strings( array $block ) : array { @@ -10,7 +11,13 @@ public function to_strings( array $block ) : array { $matches = []; - if ( preg_match( '/]*>(.+)<\/p>/is', $block['innerHTML'], $matches ) ) { + $regex = '/]*>(.+)<\/p>/is'; + + if ( $block['blockName'] === 'core/list-item' ) { + $regex = '/]*>(.+)<\/li>/is'; + } + + if ( preg_match( $regex, $block['innerHTML'], $matches ) ) { if ( ! empty( $matches[1] ) ) { $strings[] = $matches[1]; } @@ -28,6 +35,11 @@ public function replace_strings( array $block, array $replacements ) : array { foreach ( $this->to_strings( $block ) as $original ) { if ( ! empty( $original ) && isset( $replacements[ $original ] ) ) { $regex = '#(]*>)(' . preg_quote( $original, '/' ) . ')(<\/p>)#is'; + + if ( $block['blockName'] === 'core/list-item' ) { + $regex = '#(]*>)(' . preg_quote( $original, '/' ) . ')(<\/li>)#is'; + } + $html = preg_replace( $regex, '${1}' . addcslashes( $replacements[ $original ], '\\$' ) . '${3}', $html ); } } From 50c2687f76e167ab5afbc5d223a091561079d764 Mon Sep 17 00:00:00 2001 From: Adam Wood Date: Thu, 26 Jan 2023 17:19:22 +1300 Subject: [PATCH 02/10] Re export list items correctly --- .../patterns/download-source.php | 8 ++++---- .../wporg-main-2022/patterns/download.php | 8 ++++---- .../wporg-main-2022/patterns/enterprise.php | 18 +++++++++--------- .../themes/wporg-main-2022/patterns/home.php | 8 ++++---- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/source/wp-content/themes/wporg-main-2022/patterns/download-source.php b/source/wp-content/themes/wporg-main-2022/patterns/download-source.php index 9702b905..1a2cb433 100644 --- a/source/wp-content/themes/wporg-main-2022/patterns/download-source.php +++ b/source/wp-content/themes/wporg-main-2022/patterns/download-source.php @@ -35,11 +35,11 @@
    -
  • +
  • https://core.svn.wordpress.org/', 'wporg' ); ?>
  • -
  • +
  • git://core.git.wordpress.org/', 'wporg' ); ?>
@@ -49,11 +49,11 @@
    -
  • +
  • https://develop.svn.wordpress.org/', 'wporg' ); ?>
  • -
  • +
  • git://develop.git.wordpress.org/', 'wporg' ); ?>
diff --git a/source/wp-content/themes/wporg-main-2022/patterns/download.php b/source/wp-content/themes/wporg-main-2022/patterns/download.php index c1ead174..0815031e 100644 --- a/source/wp-content/themes/wporg-main-2022/patterns/download.php +++ b/source/wp-content/themes/wporg-main-2022/patterns/download.php @@ -131,19 +131,19 @@
diff --git a/source/wp-content/themes/wporg-main-2022/patterns/enterprise.php b/source/wp-content/themes/wporg-main-2022/patterns/enterprise.php index bd01a386..78446849 100644 --- a/source/wp-content/themes/wporg-main-2022/patterns/enterprise.php +++ b/source/wp-content/themes/wporg-main-2022/patterns/enterprise.php @@ -196,15 +196,15 @@
    -
  • +
  • Abril (PDF)', 'wporg' ); ?>
  • -
  • +
  • KFF (PDF)', 'wporg' ); ?>
  • -
  • +
  • NewsCorp Australia (PDF)', 'wporg' ); ?>
@@ -216,15 +216,15 @@
    -
  • +
  • IDC Report (PDF)', 'wporg' ); ?>
  • -
  • +
  • WP as a Content Hub (PDF)', 'wporg' ); ?>
  • -
  • +
  • Personalization (PDF)', 'wporg' ); ?>
@@ -236,15 +236,15 @@
    - + - + - +
diff --git a/source/wp-content/themes/wporg-main-2022/patterns/home.php b/source/wp-content/themes/wporg-main-2022/patterns/home.php index b68cee2a..67d8aff7 100644 --- a/source/wp-content/themes/wporg-main-2022/patterns/home.php +++ b/source/wp-content/themes/wporg-main-2022/patterns/home.php @@ -219,19 +219,19 @@
From d540451eec44a3fa43302c1c4d291daa670ae02d Mon Sep 17 00:00:00 2001 From: Adam Wood Date: Thu, 26 Jan 2023 17:23:30 +1300 Subject: [PATCH 03/10] composer update wporg/wporg-mu-plugins --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 3a704c1b..682a4f97 100644 --- a/composer.lock +++ b/composer.lock @@ -2274,12 +2274,12 @@ "source": { "type": "git", "url": "https://github.com/WordPress/wporg-mu-plugins.git", - "reference": "8ca7ab0b5e281115373846e2c1cc8366b4d12675" + "reference": "7d2ffaabca7d6c90c74190b09c23b76aa70ece58" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/wporg-mu-plugins/zipball/8ca7ab0b5e281115373846e2c1cc8366b4d12675", - "reference": "8ca7ab0b5e281115373846e2c1cc8366b4d12675", + "url": "https://api.github.com/repos/WordPress/wporg-mu-plugins/zipball/7d2ffaabca7d6c90c74190b09c23b76aa70ece58", + "reference": "7d2ffaabca7d6c90c74190b09c23b76aa70ece58", "shasum": "" }, "require-dev": { @@ -2317,7 +2317,7 @@ "source": "https://github.com/WordPress/wporg-mu-plugins/tree/build", "issues": "https://github.com/WordPress/wporg-mu-plugins/issues" }, - "time": "2023-01-25T04:03:56+00:00" + "time": "2023-01-25T23:19:09+00:00" }, { "name": "wporg/wporg-parent-2021", From 22e6f72da9f21ec0bd97a8232a16a7e91ba661fd Mon Sep 17 00:00:00 2001 From: Adam Wood Date: Fri, 27 Jan 2023 09:56:31 +1300 Subject: [PATCH 04/10] Add ListItem parser rather than branching in RichText --- env/export-content/includes/parser.php | 7 ++-- .../includes/parsers/ListItem.php | 40 +++++++++++++++++++ .../parsers/{RichText.php => Paragraph.php} | 16 +------- 3 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 env/export-content/includes/parsers/ListItem.php rename env/export-content/includes/parsers/{RichText.php => Paragraph.php} (69%) diff --git a/env/export-content/includes/parser.php b/env/export-content/includes/parser.php index 8ca45dd2..5b56ea61 100644 --- a/env/export-content/includes/parser.php +++ b/env/export-content/includes/parser.php @@ -6,8 +6,9 @@ require_once __DIR__ . '/parsers/BasicText.php'; require_once __DIR__ . '/parsers/Button.php'; require_once __DIR__ . '/parsers/Heading.php'; +require_once __DIR__ . '/parsers/ListItem.php'; require_once __DIR__ . '/parsers/Noop.php'; -require_once __DIR__ . '/parsers/RichText.php'; +require_once __DIR__ . '/parsers/Paragraph.php'; // Unused. require_once __DIR__ . '/parsers/ShortcodeBlock.php'; @@ -21,8 +22,8 @@ class BlockParser { public function __construct() { $this->parsers = [ // Core blocks that have custom parsers. - 'core/paragraph' => new Parsers\RichText(), - 'core/list-item' => new Parsers\RichText(), + 'core/paragraph' => new Parsers\Paragraph(), + 'core/list-item' => new Parsers\ListItem(), 'core/heading' => new Parsers\Heading(), 'core/button' => new Parsers\Button(), 'core/spacer' => new Parsers\Noop(), diff --git a/env/export-content/includes/parsers/ListItem.php b/env/export-content/includes/parsers/ListItem.php new file mode 100644 index 00000000..15a55c04 --- /dev/null +++ b/env/export-content/includes/parsers/ListItem.php @@ -0,0 +1,40 @@ +get_attribute( 'placeholder', $block ); + + $matches = []; + + if ( preg_match( '/]*>(.+)<\/li>/is', $block['innerHTML'], $matches ) ) { + if ( ! empty( $matches[1] ) ) { + $strings[] = $matches[1]; + } + } + + return $strings; + } + + // todo: this needs a fix to properly rebuild innerContent - similar to ParagraphParserTest + public function replace_strings( array $block, array $replacements ) : array { + $this->set_attribute( 'placeholder', $block, $replacements ); + + $html = $block['innerHTML']; + + foreach ( $this->to_strings( $block ) as $original ) { + if ( ! empty( $original ) && isset( $replacements[ $original ] ) ) { + $regex = '#(]*>)(' . preg_quote( $original, '/' ) . ')(<\/li>)#is'; + $html = preg_replace( $regex, '${1}' . addcslashes( $replacements[ $original ], '\\$' ) . '${3}', $html ); + } + } + + $block['innerHTML'] = $html; + $block['innerContent'] = [ $html ]; + + return $block; + } +} diff --git a/env/export-content/includes/parsers/RichText.php b/env/export-content/includes/parsers/Paragraph.php similarity index 69% rename from env/export-content/includes/parsers/RichText.php rename to env/export-content/includes/parsers/Paragraph.php index 6521c6f6..9f29a9bc 100644 --- a/env/export-content/includes/parsers/RichText.php +++ b/env/export-content/includes/parsers/Paragraph.php @@ -2,8 +2,7 @@ namespace WordPress_org\Main_2022\ExportToPatterns\Parsers; -// Default block type is core/paragraph but also handles core/list-item -class RichText implements BlockParser { +class Paragraph implements BlockParser { use GetSetAttribute; public function to_strings( array $block ) : array { @@ -11,13 +10,7 @@ public function to_strings( array $block ) : array { $matches = []; - $regex = '/]*>(.+)<\/p>/is'; - - if ( $block['blockName'] === 'core/list-item' ) { - $regex = '/]*>(.+)<\/li>/is'; - } - - if ( preg_match( $regex, $block['innerHTML'], $matches ) ) { + if ( preg_match( '/]*>(.+)<\/p>/is', $block['innerHTML'], $matches ) ) { if ( ! empty( $matches[1] ) ) { $strings[] = $matches[1]; } @@ -35,11 +28,6 @@ public function replace_strings( array $block, array $replacements ) : array { foreach ( $this->to_strings( $block ) as $original ) { if ( ! empty( $original ) && isset( $replacements[ $original ] ) ) { $regex = '#(]*>)(' . preg_quote( $original, '/' ) . ')(<\/p>)#is'; - - if ( $block['blockName'] === 'core/list-item' ) { - $regex = '#(]*>)(' . preg_quote( $original, '/' ) . ')(<\/li>)#is'; - } - $html = preg_replace( $regex, '${1}' . addcslashes( $replacements[ $original ], '\\$' ) . '${3}', $html ); } } From b0cbc70b309bc1e4daa9028290a102a88c9259ba Mon Sep 17 00:00:00 2001 From: Adam Wood Date: Fri, 27 Jan 2023 16:08:49 +1300 Subject: [PATCH 05/10] Add tests for the export content List Item parser --- .gitignore | 1 + .../tests/phpunit/parser-list-item-test.php | 34 ++++++++++ package.json | 3 +- source/wp-content/tests/phpunit/bootstrap.php | 63 +++++++++++++++++++ source/wp-content/tests/phpunit/phpunit.xml | 14 +++++ 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 env/export-content/tests/phpunit/parser-list-item-test.php create mode 100644 source/wp-content/tests/phpunit/bootstrap.php create mode 100644 source/wp-content/tests/phpunit/phpunit.xml diff --git a/.gitignore b/.gitignore index 97da45fa..f2dbdb60 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ phpcs.xml.dist /source/wp-content/mu-plugins/* # ...except the actual source of this project. +!/source/wp-content/tests !/source/wp-content/themes !/source/wp-content/themes/wporg-main-2022 !/source/wp-content/mu-plugins diff --git a/env/export-content/tests/phpunit/parser-list-item-test.php b/env/export-content/tests/phpunit/parser-list-item-test.php new file mode 100644 index 00000000..4ac5db71 --- /dev/null +++ b/env/export-content/tests/phpunit/parser-list-item-test.php @@ -0,0 +1,34 @@ + 'core/list-item', + 'innerHTML' => '
  • Learn with WordPress ↗
  • ', + 'innerContent' => array( '
  • Learn with WordPress ↗
  • ' ), + ); + $replacements = array( + 'Learn with WordPress ↗' => 'Learn with WordPress ↗", "wporg" ); ?>', + ); + + $parsed_block = $parser->replace_strings( $block, $replacements ); + + $this->assertSame( + $parsed_block, + array( + 'blockName' => 'core/list-item', + 'innerHTML' => '
  • Learn with WordPress ↗", "wporg" ); ?>
  • ', + 'innerContent' => array( '
  • Learn with WordPress ↗", "wporg" ); ?>
  • ' ), + ), + ); + } +} diff --git a/package.json b/package.json index f6f22c0e..a0b7cd62 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "lighthouse": "lighthouse-ci http://localhost:8888/ --accessibility=100 --best-practices=100 --seo=100", "lighthouse:desktop": "lighthouse http://localhost:8888/ --view --preset=desktop --output-path=lighthouse.html", "lighthouse:mobile": "lighthouse http://localhost:8888/ --view --screenEmulation.mobile --output-path=lighthouse.html", - "build:patterns": "./env/build-patterns.sh" + "build:patterns": "./env/build-patterns.sh", + "test:php": "wp-env run phpunit 'WP_MULTISITE=1 phpunit -c /var/www/html/wp-content/tests/phpunit/phpunit.xml --verbose'" }, "workspaces": [ "source/wp-content/themes/wporg-main-2022" diff --git a/source/wp-content/tests/phpunit/bootstrap.php b/source/wp-content/tests/phpunit/bootstrap.php new file mode 100644 index 00000000..174c032e --- /dev/null +++ b/source/wp-content/tests/phpunit/bootstrap.php @@ -0,0 +1,63 @@ +get_error_message(); + } + + throw new Exception( 'WordPress died: ' . $message ); +} +tests_add_filter( 'wp_die_handler', 'fail_if_died' ); + +// Start up the WP testing environment. +require $_tests_dir . '/includes/bootstrap.php'; + +// Use existing behavior for wp_die during actual test execution. +remove_filter( 'wp_die_handler', 'fail_if_died' ); diff --git a/source/wp-content/tests/phpunit/phpunit.xml b/source/wp-content/tests/phpunit/phpunit.xml new file mode 100644 index 00000000..5e2eb0e2 --- /dev/null +++ b/source/wp-content/tests/phpunit/phpunit.xml @@ -0,0 +1,14 @@ + + + + ../../../../env/export-content/tests/phpunit/ + + + From 04eb22f0f8599021a7f02ff3a55951ab3f803cab Mon Sep 17 00:00:00 2001 From: Adam Wood Date: Mon, 30 Jan 2023 11:28:33 +1300 Subject: [PATCH 06/10] Add tests mappings to wp-env --- .wp-env.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.wp-env.json b/.wp-env.json index a90954ef..6571038d 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -25,8 +25,20 @@ ], "mappings": { "env": "./env", + "wp-content": "./source/wp-content", "wp-content/mu-plugins": "./source/wp-content/mu-plugins", "wp-content/mu-plugins/0-sandbox.php": "./env/0-sandbox.php", + "wp-content/tests/phpunit": "./source/wp-content/tests/phpunit", "wp-cli.yml": "./wp-cli.yml" + }, + "env": { + "tests": { + "mappings": { + "wp-content": "./source/wp-content", + "wp-content/mu-plugins/0-sandbox.php": "./env/0-sandbox.php", + "wp-content/tests/phpunit": "./source/wp-content/tests/phpunit", + "vendor": "./vendor" + } + } } } From 836a7620922dc5ea6628d0e787606e936f898a3f Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Wed, 1 Feb 2023 17:02:11 -0500 Subject: [PATCH 07/10] Add `yoast/phpunit-polyfills` required for running tests --- composer.json | 3 ++- composer.lock | 71 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index eb07ef49..23936b5b 100644 --- a/composer.json +++ b/composer.json @@ -100,7 +100,8 @@ "wpackagist-plugin/wordpress-importer": "*", "wporg/wporg-repo-tools": "dev-trunk", "wporg/wporg-mu-plugins": "dev-build", - "wporg/wporg-parent-2021": "dev-build" + "wporg/wporg-parent-2021": "dev-build", + "yoast/phpunit-polyfills": "^1.0" }, "scripts": { "format": "phpcbf -p", diff --git a/composer.lock b/composer.lock index 682a4f97..f9297b55 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": "dbc668c35d44dec32c81c5dce68077a4", + "content-hash": "652c9baa4366ca13314c13344b96f9cc", "packages": [], "packages-dev": [ { @@ -2274,12 +2274,12 @@ "source": { "type": "git", "url": "https://github.com/WordPress/wporg-mu-plugins.git", - "reference": "7d2ffaabca7d6c90c74190b09c23b76aa70ece58" + "reference": "2097028ce55d25b166ca8a234b0058359456ed7b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/wporg-mu-plugins/zipball/7d2ffaabca7d6c90c74190b09c23b76aa70ece58", - "reference": "7d2ffaabca7d6c90c74190b09c23b76aa70ece58", + "url": "https://api.github.com/repos/WordPress/wporg-mu-plugins/zipball/2097028ce55d25b166ca8a234b0058359456ed7b", + "reference": "2097028ce55d25b166ca8a234b0058359456ed7b", "shasum": "" }, "require-dev": { @@ -2317,7 +2317,7 @@ "source": "https://github.com/WordPress/wporg-mu-plugins/tree/build", "issues": "https://github.com/WordPress/wporg-mu-plugins/issues" }, - "time": "2023-01-25T23:19:09+00:00" + "time": "2023-02-01T02:41:04+00:00" }, { "name": "wporg/wporg-parent-2021", @@ -2369,6 +2369,67 @@ "source": "https://github.com/WordPress/wporg-repo-tools/tree/trunk" }, "time": "2022-11-16T17:56:26+00:00" + }, + { + "name": "yoast/phpunit-polyfills", + "version": "1.0.4", + "source": { + "type": "git", + "url": "https://github.com/Yoast/PHPUnit-Polyfills.git", + "reference": "3c621ff5429d2b1ff96dc5808ad6cde99d31ea4c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/3c621ff5429d2b1ff96dc5808ad6cde99d31ea4c", + "reference": "3c621ff5429d2b1ff96dc5808ad6cde99d31ea4c", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "require-dev": { + "yoast/yoastcs": "^2.2.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "files": [ + "phpunitpolyfills-autoload.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Team Yoast", + "email": "support@yoast.com", + "homepage": "https://yoast.com" + }, + { + "name": "Contributors", + "homepage": "https://github.com/Yoast/PHPUnit-Polyfills/graphs/contributors" + } + ], + "description": "Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests", + "homepage": "https://github.com/Yoast/PHPUnit-Polyfills", + "keywords": [ + "phpunit", + "polyfill", + "testing" + ], + "support": { + "issues": "https://github.com/Yoast/PHPUnit-Polyfills/issues", + "source": "https://github.com/Yoast/PHPUnit-Polyfills" + }, + "time": "2022-11-16T09:07:52+00:00" } ], "aliases": [], From 1560e4ebc6a849f15636e3cdc4ff6d78d652a236 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Wed, 1 Feb 2023 17:02:22 -0500 Subject: [PATCH 08/10] Update mapping to load test files in docker --- .wp-env.json | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.wp-env.json b/.wp-env.json index 6571038d..d3a76826 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -25,18 +25,17 @@ ], "mappings": { "env": "./env", - "wp-content": "./source/wp-content", "wp-content/mu-plugins": "./source/wp-content/mu-plugins", "wp-content/mu-plugins/0-sandbox.php": "./env/0-sandbox.php", - "wp-content/tests/phpunit": "./source/wp-content/tests/phpunit", "wp-cli.yml": "./wp-cli.yml" }, "env": { "tests": { + "config": { + "WP_ENVIRONMENT_TYPE": false + }, "mappings": { - "wp-content": "./source/wp-content", - "wp-content/mu-plugins/0-sandbox.php": "./env/0-sandbox.php", - "wp-content/tests/phpunit": "./source/wp-content/tests/phpunit", + "wp-content/tests": "./source/wp-content/tests", "vendor": "./vendor" } } From 6d048bc4bcb1701e7bf0ecf642727aabd2c95ebf Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Wed, 1 Feb 2023 17:02:31 -0500 Subject: [PATCH 09/10] Fix paths to loader, tests --- source/wp-content/tests/phpunit/bootstrap.php | 35 +++++-------------- source/wp-content/tests/phpunit/phpunit.xml | 2 +- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/source/wp-content/tests/phpunit/bootstrap.php b/source/wp-content/tests/phpunit/bootstrap.php index 174c032e..2d4525f3 100644 --- a/source/wp-content/tests/phpunit/bootstrap.php +++ b/source/wp-content/tests/phpunit/bootstrap.php @@ -4,36 +4,17 @@ */ // Require composer dependencies. -require_once '/var/www/html/vendor/autoload.php'; +require_once __DIR__ . '/../../../vendor/autoload.php'; -// If we're running in WP's build directory, ensure that WP knows that, too. -if ( 'build' === getenv( 'LOCAL_DIR' ) ) { - define( 'WP_RUN_CORE_TESTS', true ); -} - -// Determine the tests directory (from a WP dev checkout). -// Try the WP_TESTS_DIR environment variable first. -$_tests_dir = getenv( 'WP_TESTS_DIR' ); - -// Next, try the WP_PHPUNIT composer package. -if ( ! $_tests_dir ) { - $_tests_dir = getenv( 'WP_PHPUNIT__DIR' ); -} - -// See if we're installed inside an existing WP dev instance. -if ( ! $_tests_dir ) { - $_try_tests_dir = __DIR__ . '/../../../../../tests/phpunit'; - if ( file_exists( $_try_tests_dir . '/includes/functions.php' ) ) { - $_tests_dir = $_try_tests_dir; - } -} -// Fallback. -if ( ! $_tests_dir ) { - $_tests_dir = '/tmp/wordpress-tests-lib'; +// Detect where to load the WordPress tests environment from. +if ( false !== getenv( 'WP_TESTS_DIR' ) ) { + $_test_root = getenv( 'WP_TESTS_DIR' ); +} else { + $_test_root = __DIR__ . '/../../../vendor/wp-phpunit/wp-phpunit'; } // Give access to tests_add_filter() function. -require_once $_tests_dir . '/includes/functions.php'; +require_once $_test_root . '/includes/functions.php'; /** * Adds a wp_die handler for use during tests. @@ -57,7 +38,7 @@ function fail_if_died( $message ) { tests_add_filter( 'wp_die_handler', 'fail_if_died' ); // Start up the WP testing environment. -require $_tests_dir . '/includes/bootstrap.php'; +require_once $_test_root . '/includes/bootstrap.php'; // Use existing behavior for wp_die during actual test execution. remove_filter( 'wp_die_handler', 'fail_if_died' ); diff --git a/source/wp-content/tests/phpunit/phpunit.xml b/source/wp-content/tests/phpunit/phpunit.xml index 5e2eb0e2..91bfab1b 100644 --- a/source/wp-content/tests/phpunit/phpunit.xml +++ b/source/wp-content/tests/phpunit/phpunit.xml @@ -8,7 +8,7 @@ > - ../../../../env/export-content/tests/phpunit/ + ../../../env/export-content/tests/phpunit From 485df02df64df15996fff115cf39efa77cd4ac2e Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Wed, 1 Feb 2023 17:02:42 -0500 Subject: [PATCH 10/10] Load parser files in test --- env/export-content/tests/phpunit/parser-list-item-test.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/env/export-content/tests/phpunit/parser-list-item-test.php b/env/export-content/tests/phpunit/parser-list-item-test.php index 4ac5db71..6523653b 100644 --- a/env/export-content/tests/phpunit/parser-list-item-test.php +++ b/env/export-content/tests/phpunit/parser-list-item-test.php @@ -2,7 +2,10 @@ defined( 'WPINC' ) || die(); -require_once __DIR__ . '../../parsers/ListItem.php'; +require_once dirname( dirname( __DIR__ ) ) . '/includes/parsers/BlockParser.php'; +require_once dirname( dirname( __DIR__ ) ) . '/includes/parsers/ListItem.php'; + +use WordPress_org\Main_2022\ExportToPatterns\Parsers; class Test_Parser_List_Item extends WP_UnitTestCase { @@ -10,7 +13,7 @@ class Test_Parser_List_Item extends WP_UnitTestCase { * @covers WordPress_org\Main_2022\ExportToPatterns\Parsers\ListItem\replace_strings */ public function test_totp_setup_returns_expected_data() : void { - $parser = new ListItem(); + $parser = new Parsers\ListItem(); $block = array( 'blockName' => 'core/list-item', 'innerHTML' => '
  • Learn with WordPress ↗
  • ',