From f8bfb1a0868d01c046bd4b1ce4b6f8a98be52a74 Mon Sep 17 00:00:00 2001 From: Christopher Allford <6451942+ObliviousHarmony@users.noreply.github.com> Date: Mon, 17 Apr 2023 15:25:29 -0700 Subject: [PATCH 1/7] Added Port Addition/Replacement Function This new function will allow us to add/replace ports in certain `wp-config.php` values. --- .../env/lib/config/add-or-replace-port.js | 32 +++++++++++ .../lib/config/test/add-or-replace-port.js | 53 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 packages/env/lib/config/add-or-replace-port.js create mode 100644 packages/env/lib/config/test/add-or-replace-port.js diff --git a/packages/env/lib/config/add-or-replace-port.js b/packages/env/lib/config/add-or-replace-port.js new file mode 100644 index 00000000000000..730290b9c4081c --- /dev/null +++ b/packages/env/lib/config/add-or-replace-port.js @@ -0,0 +1,32 @@ +/** + * Internal dependencies + */ +const { ValidationError } = require( './validate-config' ); + +/** + * Adds or replaces the port to the given domain or URI. + * + * @param {string} input The domain or URI to operate on. + * @param {string} port The port to append. + * @param {boolean} [replace] Indicates whether or not the port should be replaced if one is already present. Defaults to true. + * @return {string} The string with the port added or replaced. + */ +module.exports = function addOrReplacePort( input, port, replace = true ) { + // This matches both domains and URIs with an optional port and anything + // that remains after. We can use this to build an output string that + // adds or replaces the port without making any other changes to the input. + const matches = input.match( + /^((?:.+:\/\/)?[a-z0-9.\-]+)(?::([0-9]+))?(.*)$/i + ); + if ( ! matches ) { + throw new ValidationError( `Invalid domain or uri: ${ input }.` ); + } + + // When a port is already present we will do nothing if the caller doesn't want it to be replaced. + if ( matches[ 2 ] !== undefined && ! replace ) { + return input; + } + + // Place the port in the correct location in the input. + return matches[ 1 ] + ':' + port + matches[ 3 ]; +}; diff --git a/packages/env/lib/config/test/add-or-replace-port.js b/packages/env/lib/config/test/add-or-replace-port.js new file mode 100644 index 00000000000000..f5186e1db93739 --- /dev/null +++ b/packages/env/lib/config/test/add-or-replace-port.js @@ -0,0 +1,53 @@ +/** + * Internal dependencies + */ +const addOrReplacePort = require( '../add-or-replace-port.js' ); + +describe( 'addOrReplacePort', () => { + beforeEach( () => { + jest.clearAllMocks(); + } ); + + it( 'should add or replace port with various inputs', () => { + const testMap = [ + // Addition + { in: 'test', expect: 'test:101' }, + { in: 'test/test?test#test', expect: 'test:101/test?test#test' }, + { in: 'http://test.com', expect: 'http://test.com:101' }, + { + in: 'http://test.com/test?test#test', + expect: 'http://test.com:101/test?test#test', + }, + { in: 'ssh://test.com', expect: 'ssh://test.com:101' }, + { in: 'test.com', expect: 'test.com:101' }, + + // Replacement + { in: 'test:99', expect: 'test:101' }, + { in: 'test:99/test?test#test', expect: 'test:101/test?test#test' }, + { in: 'http://test.com:99', expect: 'http://test.com:101' }, + { + in: 'http://test.com:99/test?test#test', + expect: 'http://test.com:101/test?test#test', + }, + { in: 'ssh://test.com:99', expect: 'ssh://test.com:101' }, + { in: 'test.com:99', expect: 'test.com:101' }, + ]; + + for ( const test of testMap ) { + const result = addOrReplacePort( test.in, '101' ); + expect( result ).toEqual( test.expect ); + } + } ); + + it( 'should do nothing if port is present but replacement is not requested', () => { + const testMap = [ + { in: 'test', expect: 'test:103' }, + { in: 'test:99', expect: 'test:99' }, + ]; + + for ( const test of testMap ) { + const result = addOrReplacePort( test.in, '103', false ); + expect( result ).toEqual( test.expect ); + } + } ); +} ); From a4dc90fa13faf5ab4881ec2a5fab658f935171b6 Mon Sep 17 00:00:00 2001 From: Christopher Allford <6451942+ObliviousHarmony@users.noreply.github.com> Date: Mon, 17 Apr 2023 23:22:18 -0700 Subject: [PATCH 2/7] Refactored WP_SITEURL and WP_HOME Validation --- packages/env/lib/config/test/config.js | 38 ++++++++++++++++++++++ packages/env/lib/config/validate-config.js | 24 ++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/packages/env/lib/config/test/config.js b/packages/env/lib/config/test/config.js index 5552ecce9d70f4..ce749c1b71c095 100644 --- a/packages/env/lib/config/test/config.js +++ b/packages/env/lib/config/test/config.js @@ -70,6 +70,44 @@ describe( 'readConfig', () => { } } ); + it( 'should throw a validation error if WP_SITEURL is not a valid URL', async () => { + readFile.mockImplementation( () => + Promise.resolve( + JSON.stringify( { + config: { + WP_SITEURL: 'test', + }, + } ) + ) + ); + expect.assertions( 2 ); + try { + await readConfig( '.wp-env.json' ); + } catch ( error ) { + expect( error ).toBeInstanceOf( ValidationError ); + expect( error.message ).toContain( 'must be a valid URL' ); + } + } ); + + it( 'should throw a validation error if WP_HOME is not a valid URL', async () => { + readFile.mockImplementation( () => + Promise.resolve( + JSON.stringify( { + config: { + WP_SITEURL: 'test', + }, + } ) + ) + ); + expect.assertions( 2 ); + try { + await readConfig( '.wp-env.json' ); + } catch ( error ) { + expect( error ).toBeInstanceOf( ValidationError ); + expect( error.message ).toContain( 'must be a valid URL' ); + } + } ); + it( 'should infer a core config when ran from a core directory', async () => { readFile.mockImplementation( () => Promise.reject( { code: 'ENOENT' } ) diff --git a/packages/env/lib/config/validate-config.js b/packages/env/lib/config/validate-config.js index 1ecee11010f118..74a5fb79b5deb3 100644 --- a/packages/env/lib/config/validate-config.js +++ b/packages/env/lib/config/validate-config.js @@ -83,9 +83,33 @@ function validateConfig( config, envLocation ) { ); } + checkValidURL( envPrefix, config.config, 'WP_SITEURL' ); + checkValidURL( envPrefix, config.config, 'WP_HOME' ); + return config; } +/** + * Validates the input and throws if it isn't a valid URL. + * + * @param {string} envPrefix The environment we're validating. + * @param {Object} config The configuration object we're looking at. + * @param {string} configKey The configuration key we're validating. + */ +function checkValidURL( envPrefix, config, configKey ) { + if ( config[ configKey ] === undefined ) { + return; + } + + try { + new URL( config[ configKey ] ); + } catch { + throw new ValidationError( + `Invalid .wp-env.json: "${ envPrefix }config.${ configKey }" must be a valid URL.` + ); + } +} + module.exports = { validateConfig, ValidationError, From 0f6388dbbacbb018516c1703ffb884f82f77fb5a Mon Sep 17 00:00:00 2001 From: Christopher Allford <6451942+ObliviousHarmony@users.noreply.github.com> Date: Mon, 17 Apr 2023 23:41:09 -0700 Subject: [PATCH 3/7] Always Use `WP_SITEURL` When Configuring WordPress Since `WP_SITEURL` already contains the port in both the development and test environments, there is no reason to try and construct the URL with the port. Additionally, it is more accurate to use the test environment's `WP_SITEURL` since that's what WordPress will expect due to the constant. --- packages/env/CHANGELOG.md | 4 ++++ packages/env/lib/commands/start.js | 4 ++-- packages/env/lib/wordpress.js | 15 +-------------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/packages/env/CHANGELOG.md b/packages/env/CHANGELOG.md index dd77223ea720e3..a026f741ba23d5 100644 --- a/packages/env/CHANGELOG.md +++ b/packages/env/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Breaking Change + +- Use test environment's `WP_SITEURL` instead of `WP_TESTS_DOMAIN` as the WordPress URL. + ## 5.11.0 (2023-02-01) ### Bug fix diff --git a/packages/env/lib/commands/start.js b/packages/env/lib/commands/start.js index 7ffc333d23bdac..a217d5492d2b48 100644 --- a/packages/env/lib/commands/start.js +++ b/packages/env/lib/commands/start.js @@ -193,7 +193,7 @@ module.exports = async function start( { spinner, debug, update, xdebug } ) { } const siteUrl = config.env.development.config.WP_SITEURL; - const e2eSiteUrl = `http://${ config.env.tests.config.WP_TESTS_DOMAIN }:${ config.env.tests.port }/`; + const testsSiteUrl = config.env.tests.config.WP_SITEURL; const { out: mySQLAddress } = await dockerCompose.port( 'mysql', @@ -213,7 +213,7 @@ module.exports = async function start( { spinner, debug, update, xdebug } ) { .concat( siteUrl ? ` at ${ siteUrl }` : '.' ) .concat( '\n' ) .concat( 'WordPress test site started' ) - .concat( e2eSiteUrl ? ` at ${ e2eSiteUrl }` : '.' ) + .concat( testsSiteUrl ? ` at ${ testsSiteUrl }` : '.' ) .concat( '\n' ) .concat( `MySQL is listening on port ${ mySQLPort }` ) .concat( diff --git a/packages/env/lib/wordpress.js b/packages/env/lib/wordpress.js index 0d8f571cce71c1..fc8f6db5670777 100644 --- a/packages/env/lib/wordpress.js +++ b/packages/env/lib/wordpress.js @@ -44,20 +44,7 @@ async function checkDatabaseConnection( { dockerComposeConfigPath, debug } ) { * @param {Object} spinner A CLI spinner which indicates progress. */ async function configureWordPress( environment, config, spinner ) { - const url = ( () => { - const port = config.env[ environment ].port; - const domain = - environment === 'tests' - ? config.env.tests.config.WP_TESTS_DOMAIN - : config.env.development.config.WP_SITEURL; - if ( port === 80 ) { - return domain; - } - - return `${ domain }:${ port }`; - } )(); - - const installCommand = `wp core install --url="${ url }" --title="${ config.name }" --admin_user=admin --admin_password=password --admin_email=wordpress@example.com --skip-email`; + const installCommand = `wp core install --url="${ config.env[ environment ].config.WP_SITEURL }" --title="${ config.name }" --admin_user=admin --admin_password=password --admin_email=wordpress@example.com --skip-email`; // -eo pipefail exits the command as soon as anything fails in bash. const setupCommands = [ 'set -eo pipefail', installCommand ]; From b8936652d1b0f9a3023247789c0695ea251665e4 Mon Sep 17 00:00:00 2001 From: Christopher Allford <6451942+ObliviousHarmony@users.noreply.github.com> Date: Mon, 17 Apr 2023 23:46:09 -0700 Subject: [PATCH 4/7] Automatically Add Port To `WP_TESTS_DOMAIN` Tests should use the `WP_TESTS_DOMAIN` constant to construct URLs in tests. This poses a problem, however, because the port will be part of the URL in test environments. In my review of WordPress Core and WooCommerce, adding the port to `WP_TESTS_DOMAIN` should not break anything and will make the container more resilient to port customizations. --- packages/env/CHANGELOG.md | 1 + packages/env/lib/config/config.js | 40 +++++++++---------- .../config/test/__snapshots__/config.js.snap | 24 +++++------ packages/env/lib/config/test/config.js | 38 +++++++++--------- 4 files changed, 50 insertions(+), 53 deletions(-) diff --git a/packages/env/CHANGELOG.md b/packages/env/CHANGELOG.md index a026f741ba23d5..f93cf574e7b569 100644 --- a/packages/env/CHANGELOG.md +++ b/packages/env/CHANGELOG.md @@ -5,6 +5,7 @@ ### Breaking Change - Use test environment's `WP_SITEURL` instead of `WP_TESTS_DOMAIN` as the WordPress URL. +- Automatically add the environment's port to `WP_TESTS_DOMAIN`. ## 5.11.0 (2023-02-01) diff --git a/packages/env/lib/config/config.js b/packages/env/lib/config/config.js index ca00aebacf4ba9..0baef67ac7ce46 100644 --- a/packages/env/lib/config/config.js +++ b/packages/env/lib/config/config.js @@ -14,6 +14,7 @@ const { validateConfig, ValidationError } = require( './validate-config' ); const readRawConfigFile = require( './read-raw-config-file' ); const parseConfig = require( './parse-config' ); const { includeTestsPath, parseSourceString } = parseConfig; +const addOrReplacePort = require( './add-or-replace-port' ); const md5 = require( '../md5' ); /** @@ -272,30 +273,25 @@ function withOverrides( config ) { config.env.tests.phpVersion = process.env.WP_ENV_PHP_VERSION || config.env.tests.phpVersion; - const updateEnvUrl = ( configKey ) => { - [ 'development', 'tests' ].forEach( ( envKey ) => { - try { - const baseUrl = new URL( - config.env[ envKey ].config[ configKey ] - ); - - // Don't overwrite the port of WP_HOME when set. - if ( ! ( configKey === 'WP_HOME' && !! baseUrl.port ) ) { - baseUrl.port = config.env[ envKey ].port; - } + // Some of our configuration options need to have the port added to them. + const addConfigPort = ( configKey ) => { + // Don't replace the port if one is set in WP_HOME. + const replace = configKey !== 'WP_HOME'; - config.env[ envKey ].config[ configKey ] = baseUrl.toString(); - } catch ( error ) { - throw new ValidationError( - `Invalid .wp-env.json: config.${ configKey } must be a valid URL.` - ); - } - } ); + config.env.development.config[ configKey ] = addOrReplacePort( + config.env.development.config[ configKey ], + config.env.development.port, + replace + ); + config.env.tests.config[ configKey ] = addOrReplacePort( + config.env.tests.config[ configKey ], + config.env.tests.port, + replace + ); }; - - // Update wp config options to include the correct port number in the URL. - updateEnvUrl( 'WP_SITEURL' ); - updateEnvUrl( 'WP_HOME' ); + addConfigPort( 'WP_TESTS_DOMAIN' ); + addConfigPort( 'WP_SITEURL' ); + addConfigPort( 'WP_HOME' ); return config; } diff --git a/packages/env/lib/config/test/__snapshots__/config.js.snap b/packages/env/lib/config/test/__snapshots__/config.js.snap index ad0c18e4279de7..709baedbb8edf6 100644 --- a/packages/env/lib/config/test/__snapshots__/config.js.snap +++ b/packages/env/lib/config/test/__snapshots__/config.js.snap @@ -14,10 +14,10 @@ Object { "TEST_VAL3": false, "WP_DEBUG": true, "WP_ENVIRONMENT_TYPE": "local", - "WP_HOME": "http://localhost:2000/", + "WP_HOME": "http://localhost:2000", "WP_PHP_BINARY": "php", - "WP_SITEURL": "http://localhost:2000/", - "WP_TESTS_DOMAIN": "localhost", + "WP_SITEURL": "http://localhost:2000", + "WP_TESTS_DOMAIN": "localhost:2000", "WP_TESTS_EMAIL": "admin@example.org", "WP_TESTS_TITLE": "Test Blog", }, @@ -36,10 +36,10 @@ Object { "TEST_VAL3": false, "WP_DEBUG": false, "WP_ENVIRONMENT_TYPE": "local", - "WP_HOME": "http://localhost:1000/", + "WP_HOME": "http://localhost:1000", "WP_PHP_BINARY": "php", - "WP_SITEURL": "http://localhost:1000/", - "WP_TESTS_DOMAIN": "localhost", + "WP_SITEURL": "http://localhost:1000", + "WP_TESTS_DOMAIN": "localhost:1000", "WP_TESTS_EMAIL": "admin@example.org", "WP_TESTS_TITLE": "Test Blog", }, @@ -59,10 +59,10 @@ Object { "SCRIPT_DEBUG": false, "WP_DEBUG": false, "WP_ENVIRONMENT_TYPE": "local", - "WP_HOME": "http://localhost:8889/", + "WP_HOME": "http://localhost:8889", "WP_PHP_BINARY": "php", - "WP_SITEURL": "http://localhost:8889/", - "WP_TESTS_DOMAIN": "localhost", + "WP_SITEURL": "http://localhost:8889", + "WP_TESTS_DOMAIN": "localhost:8889", "WP_TESTS_EMAIL": "admin@example.org", "WP_TESTS_TITLE": "Test Blog", } @@ -73,10 +73,10 @@ Object { "SCRIPT_DEBUG": true, "WP_DEBUG": true, "WP_ENVIRONMENT_TYPE": "local", - "WP_HOME": "http://localhost:8888/", + "WP_HOME": "http://localhost:8888", "WP_PHP_BINARY": "php", - "WP_SITEURL": "http://localhost:8888/", - "WP_TESTS_DOMAIN": "localhost", + "WP_SITEURL": "http://localhost:8888", + "WP_TESTS_DOMAIN": "localhost:8888", "WP_TESTS_EMAIL": "admin@example.org", "WP_TESTS_TITLE": "Test Blog", } diff --git a/packages/env/lib/config/test/config.js b/packages/env/lib/config/test/config.js index ce749c1b71c095..a3ac0b966dbe49 100644 --- a/packages/env/lib/config/test/config.js +++ b/packages/env/lib/config/test/config.js @@ -892,17 +892,17 @@ describe( 'readConfig', () => { development: { port: 1000, config: { - WP_TESTS_DOMAIN: 'localhost', - WP_SITEURL: 'http://localhost:1000/', - WP_HOME: 'http://localhost:1000/', + WP_TESTS_DOMAIN: 'localhost:1000', + WP_SITEURL: 'http://localhost:1000', + WP_HOME: 'http://localhost:1000', }, }, tests: { port: 2000, config: { - WP_TESTS_DOMAIN: 'localhost', - WP_SITEURL: 'http://localhost:2000/', - WP_HOME: 'http://localhost:2000/', + WP_TESTS_DOMAIN: 'localhost:2000', + WP_SITEURL: 'http://localhost:2000', + WP_HOME: 'http://localhost:2000', }, }, }, @@ -916,7 +916,7 @@ describe( 'readConfig', () => { port: 1000, testsPort: 2000, config: { - WP_HOME: 'http://localhost:3000/', + WP_HOME: 'http://localhost:3000', }, } ) ) @@ -928,17 +928,17 @@ describe( 'readConfig', () => { development: { port: 1000, config: { - WP_TESTS_DOMAIN: 'localhost', - WP_SITEURL: 'http://localhost:1000/', - WP_HOME: 'http://localhost:3000/', + WP_TESTS_DOMAIN: 'localhost:1000', + WP_SITEURL: 'http://localhost:1000', + WP_HOME: 'http://localhost:3000', }, }, tests: { port: 2000, config: { - WP_TESTS_DOMAIN: 'localhost', - WP_SITEURL: 'http://localhost:2000/', - WP_HOME: 'http://localhost:3000/', + WP_TESTS_DOMAIN: 'localhost:2000', + WP_SITEURL: 'http://localhost:2000', + WP_HOME: 'http://localhost:3000', }, }, }, @@ -1191,9 +1191,9 @@ describe( 'readConfig', () => { WP_PHP_BINARY: 'php', WP_TESTS_EMAIL: 'admin@example.org', WP_TESTS_TITLE: 'Test Blog', - WP_TESTS_DOMAIN: 'localhost', - WP_SITEURL: 'http://localhost:8889/', - WP_HOME: 'http://localhost:8889/', + WP_TESTS_DOMAIN: 'localhost:8889', + WP_SITEURL: 'http://localhost:8889', + WP_HOME: 'http://localhost:8889', } ); expect( config.env.development.config ).toEqual( { @@ -1205,9 +1205,9 @@ describe( 'readConfig', () => { WP_PHP_BINARY: 'php', WP_TESTS_EMAIL: 'admin@example.org', WP_TESTS_TITLE: 'Test Blog', - WP_TESTS_DOMAIN: 'localhost', - WP_SITEURL: 'http://localhost:8888/', - WP_HOME: 'http://localhost:8888/', + WP_TESTS_DOMAIN: 'localhost:8888', + WP_SITEURL: 'http://localhost:8888', + WP_HOME: 'http://localhost:8888', } ); } ); } ); From 0ddc704980ce1748e779f16ff9810598a8539d50 Mon Sep 17 00:00:00 2001 From: Christopher Allford <6451942+ObliviousHarmony@users.noreply.github.com> Date: Tue, 18 Apr 2023 00:01:55 -0700 Subject: [PATCH 5/7] Removed Hardcoded `localhost` From PHPUnit Tests To add resiliency to the test suite, we should use `WP_TESTS_DOMAIN` instead of hardcoding the domain and port in the URLs. --- phpunit/blocks/render-block-file-test.php | 18 +++++++++--------- .../blocks/render-block-navigation-test.php | 18 +++++++++--------- ...lass-block-library-navigation-link-test.php | 18 ++++++++++++------ 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/phpunit/blocks/render-block-file-test.php b/phpunit/blocks/render-block-file-test.php index 7ffbb411038750..7fdeb60a707a9e 100644 --- a/phpunit/blocks/render-block-file-test.php +++ b/phpunit/blocks/render-block-file-test.php @@ -18,14 +18,14 @@ class Tests_Blocks_Render_File extends WP_UnitTestCase { */ public function test_render_block_core_file() { $attributes = array( - 'href' => 'http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf', + 'href' => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2021/04/yolo.pdf', 'fileId' => 'wp-block-file--media-_clientId_0', - 'textLinkHref' => 'http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf', + 'textLinkHref' => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2021/04/yolo.pdf', 'showDownloadButton' => true, 'displayPreview' => true, 'previewHeight' => 370, ); - $content = '
'; + $content = ''; $new_content = gutenberg_render_block_core_file( $attributes, $content ); $this->assertStringContainsString( 'aria-label="Embed of yolo."', $new_content ); @@ -36,14 +36,14 @@ public function test_render_block_core_file() { */ public function test_render_block_core_file_custom_filename() { $attributes = array( - 'href' => 'http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf', + 'href' => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2021/04/yolo.pdf', 'fileId' => 'wp-block-file--media-_clientId_0', - 'textLinkHref' => 'http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf', + 'textLinkHref' => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2021/04/yolo.pdf', 'showDownloadButton' => true, 'displayPreview' => true, 'previewHeight' => 370, ); - $content = ''; + $content = ''; $new_content = gutenberg_render_block_core_file( $attributes, $content ); $this->assertStringContainsString( 'aria-label="Embed of custom filename."', $new_content ); @@ -54,14 +54,14 @@ public function test_render_block_core_file_custom_filename() { */ public function test_render_block_core_file_empty_filename() { $attributes = array( - 'href' => 'http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf', + 'href' => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2021/04/yolo.pdf', 'fileId' => 'wp-block-file--media-_clientId_0', - 'textLinkHref' => 'http://localhost:8889/wp-content/uploads/2021/04/yolo.pdf', + 'textLinkHref' => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2021/04/yolo.pdf', 'showDownloadButton' => true, 'displayPreview' => true, 'previewHeight' => 370, ); - $content = ''; + $content = ''; $new_content = gutenberg_render_block_core_file( $attributes, $content ); $this->assertStringContainsString( 'aria-label="PDF embed"', $new_content ); diff --git a/phpunit/blocks/render-block-navigation-test.php b/phpunit/blocks/render-block-navigation-test.php index 211a20be3b9942..ca4bbb6c342789 100644 --- a/phpunit/blocks/render-block-navigation-test.php +++ b/phpunit/blocks/render-block-navigation-test.php @@ -17,7 +17,7 @@ class Render_Block_Navigation_Test extends WP_UnitTestCase { */ public function test_block_core_navigation_get_post_ids_from_block() { $parsed_blocks = parse_blocks( - '' + '' ); $parsed_block = $parsed_blocks[0]; $context = array(); @@ -33,13 +33,13 @@ public function test_block_core_navigation_get_post_ids_from_block() { public function test_block_core_navigation_get_post_ids_from_block_nested() { $parsed_blocks = parse_blocks( ' - - - - - - - + + + + + + + ' @@ -56,7 +56,7 @@ public function test_block_core_navigation_get_post_ids_from_block_nested() { * @covers ::gutenberg_block_core_navigation_from_block_get_post_ids */ public function test_block_core_navigation_get_post_ids_from_block_with_submenu() { - $parsed_blocks = parse_blocks( '\n\n' ); + $parsed_blocks = parse_blocks( '\n\n' ); $parsed_block = $parsed_blocks[0]; $context = array(); $block = new WP_Block( $parsed_block, $context ); diff --git a/phpunit/class-block-library-navigation-link-test.php b/phpunit/class-block-library-navigation-link-test.php index 0ff603bca3ef6c..b0a5b989a9ae83 100644 --- a/phpunit/class-block-library-navigation-link-test.php +++ b/phpunit/class-block-library-navigation-link-test.php @@ -111,9 +111,10 @@ public function tear_down() { public function test_returns_link_when_post_is_published() { $page_id = self::$page->ID; + $url = 'http://' . WP_TESTS_DOMAIN; $parsed_blocks = parse_blocks( - "" + "" ); $this->assertEquals( 1, count( $parsed_blocks ) ); @@ -133,9 +134,10 @@ public function test_returns_link_when_post_is_published() { public function test_returns_empty_when_label_is_missing() { $page_id = self::$page->ID; + $url = 'http://' . WP_TESTS_DOMAIN; $parsed_blocks = parse_blocks( - "" + "" ); $this->assertEquals( 1, count( $parsed_blocks ) ); @@ -152,9 +154,10 @@ public function test_returns_empty_when_label_is_missing() { public function test_returns_empty_when_draft() { $page_id = self::$draft->ID; + $url = 'http://' . WP_TESTS_DOMAIN; $parsed_blocks = parse_blocks( - "" + "" ); $this->assertEquals( 1, count( $parsed_blocks ) ); @@ -172,9 +175,10 @@ public function test_returns_empty_when_draft() { public function test_returns_link_for_category() { $category_id = self::$category->term_id; + $url = 'http://' . WP_TESTS_DOMAIN; $parsed_blocks = parse_blocks( - "" + "" ); $this->assertEquals( 1, count( $parsed_blocks ) ); @@ -247,9 +251,10 @@ public function test_returns_link_for_decoded_link() { public function test_returns_empty_when_custom_post_type_draft() { $page_id = self::$custom_draft->ID; + $url = 'http://' . WP_TESTS_DOMAIN; $parsed_blocks = parse_blocks( - "" + "" ); $this->assertEquals( 1, count( $parsed_blocks ) ); @@ -267,9 +272,10 @@ public function test_returns_empty_when_custom_post_type_draft() { public function test_returns_link_when_custom_post_is_published() { $page_id = self::$custom_post->ID; + $url = 'http://' . WP_TESTS_DOMAIN; $parsed_blocks = parse_blocks( - "" + "" ); $this->assertEquals( 1, count( $parsed_blocks ) ); From 6ce58ff7cd73d7b4de5299e2545c81eae9662e78 Mon Sep 17 00:00:00 2001 From: Christopher Allford <6451942+ObliviousHarmony@users.noreply.github.com> Date: Tue, 18 Apr 2023 00:23:59 -0700 Subject: [PATCH 6/7] Style Fixes --- packages/env/lib/config/add-or-replace-port.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/env/lib/config/add-or-replace-port.js b/packages/env/lib/config/add-or-replace-port.js index 730290b9c4081c..8d891869238a31 100644 --- a/packages/env/lib/config/add-or-replace-port.js +++ b/packages/env/lib/config/add-or-replace-port.js @@ -6,8 +6,8 @@ const { ValidationError } = require( './validate-config' ); /** * Adds or replaces the port to the given domain or URI. * - * @param {string} input The domain or URI to operate on. - * @param {string} port The port to append. + * @param {string} input The domain or URI to operate on. + * @param {string} port The port to append. * @param {boolean} [replace] Indicates whether or not the port should be replaced if one is already present. Defaults to true. * @return {string} The string with the port added or replaced. */ From 3aa9e1735055fa5ca0f7f48c5803eb126ce790a2 Mon Sep 17 00:00:00 2001 From: Christopher Allford <6451942+ObliviousHarmony@users.noreply.github.com> Date: Tue, 18 Apr 2023 16:08:04 -0700 Subject: [PATCH 7/7] Update CHANGELOG.md --- packages/env/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/env/CHANGELOG.md b/packages/env/CHANGELOG.md index 7a445e879eb22f..714b692694dc28 100644 --- a/packages/env/CHANGELOG.md +++ b/packages/env/CHANGELOG.md @@ -4,8 +4,8 @@ ### Breaking Change -- Use test environment's `WP_SITEURL` instead of `WP_TESTS_DOMAIN` as the WordPress URL. -- Automatically add the environment's port to `WP_TESTS_DOMAIN`. +- Use test environment's `WP_SITEURL` instead of `WP_TESTS_DOMAIN` as the WordPress URL. +- Automatically add the environment's port to `WP_TESTS_DOMAIN`. ## 5.16.0 (2023-04-12)