From 40f589c67d539712269170f4e0fd653c0127931b Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 8 Jul 2024 14:55:41 -0600 Subject: [PATCH 01/39] add new helper function that parses and normalizes a url from parts --- web/app/mu-plugins/filters.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/web/app/mu-plugins/filters.php b/web/app/mu-plugins/filters.php index bcaedb38..9c29b695 100644 --- a/web/app/mu-plugins/filters.php +++ b/web/app/mu-plugins/filters.php @@ -172,15 +172,19 @@ function __is_login_url( string $url ) : bool { * @return string The normalized URL. */ function __normalize_wp_url( string $url ): string { - $scheme = parse_url( $url, PHP_URL_SCHEME ); - $scheme_with_separator = $scheme ? $scheme . '://' : ''; - // Remove the scheme from the URL if it exists. - $remaining_url = $scheme ? substr( $url, strlen($scheme_with_separator ) ) : $url; - - // Normalize the remaining URL to remove any double slashes. - $normalized_url = str_replace( '//', '/', $remaining_url ); - - // Reconstruct and return the full normalized URL. - return $scheme_with_separator . $normalized_url; +/** + * Rebuild parsed URL from parts. + * + * @since 1.1.0 + * @param array $parts URL parts from parse_url. + * @return string Re-parsed URL. + */ +function __rebuild_url_from_parts( array $parts ) : string { + return trailingslashit( + isset( $parts['scheme'] ) ? "{$parts['scheme']}:" : '' . + isset( $parts['path'] ) ? untrailingslashit( "{$parts['path']}" ) : '' . + isset( $parts['query'] ) ? str_replace( '/', '', "?{$parts['query']}" ) : '' . + isset( $parts['fragment'] ) ? str_replace( '/', '', "#{$parts['fragment']}" ) : '' + ); } From bd90d48290f31d601ee3ec006e8740d384f4890e Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 8 Jul 2024 14:56:16 -0600 Subject: [PATCH 02/39] Update URL normalization function to refactor using __rebuild_url_from_parts --- web/app/mu-plugins/filters.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/web/app/mu-plugins/filters.php b/web/app/mu-plugins/filters.php index 9c29b695..07397273 100644 --- a/web/app/mu-plugins/filters.php +++ b/web/app/mu-plugins/filters.php @@ -172,6 +172,16 @@ function __is_login_url( string $url ) : bool { * @return string The normalized URL. */ function __normalize_wp_url( string $url ): string { + $scheme = parse_url( $url ); + + // Normalize the URL to remove any double slashes. + if ( isset( $parts['path'] ) ) { + $parts['path'] = preg_replace( '#/+#', '/', $parts['path'] ); + } + + // Rebuild and return the full normalized URL. + return __rebuild_url_from_parts( $parts ); +} /** * Rebuild parsed URL from parts. From efc07484856b0cfb27e751ab2f121f8c3a72c9fd Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 8 Jul 2024 15:45:48 -0600 Subject: [PATCH 03/39] check if endpoint is defined already --- web/app/mu-plugins/filters.php | 35 +++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/web/app/mu-plugins/filters.php b/web/app/mu-plugins/filters.php index 07397273..4c937469 100644 --- a/web/app/mu-plugins/filters.php +++ b/web/app/mu-plugins/filters.php @@ -136,6 +136,27 @@ function add_wp_prefix_to_login_and_admin_urls( string $url ) : string { add_filter( 'login_url', __NAMESPACE__ . '\\add_wp_prefix_to_login_and_admin_urls', 9 ); add_filter( 'admin_url', __NAMESPACE__ . '\\add_wp_prefix_to_login_and_admin_urls', 9 ); +/** + * Ensure the /wp prefix is retained in the WPGraphQL endpoint. + * + * @since 1.1.0 + * @param null|string $endpoint The GraphQL endpoint. + * @return null|string The filtered GraphQL endpoint. + */ +add_filter( 'graphql_endpoint', function( $endpoint ) { + $desired_endpoint = '/wp/graphql'; + + if ( ! $endpoint ) { + return $desired_endpoint; + } + + if ( $endpoint && strpos( $endpoint, '/wp' ) === false ) { + $endpoint = "/wp/$endpoint"; + } + + return $endpoint; +}, 9 ); + /** * Check the URL to see if it's either an admin or wp-login URL. * @@ -157,11 +178,11 @@ function __is_login_url( string $url ) : bool { } // Check if the URL is a login or admin page - if (strpos($url, 'wp-login') !== false || strpos($url, 'wp-admin') !== false) { + if ( strpos( $url, 'wp-login' ) !== false || strpos($url, 'wp-admin' ) !== false) { return true; } - return false + return false; } /** @@ -172,7 +193,7 @@ function __is_login_url( string $url ) : bool { * @return string The normalized URL. */ function __normalize_wp_url( string $url ): string { - $scheme = parse_url( $url ); + $parts = parse_url( $url ); // Normalize the URL to remove any double slashes. if ( isset( $parts['path'] ) ) { @@ -192,9 +213,9 @@ function __normalize_wp_url( string $url ): string { */ function __rebuild_url_from_parts( array $parts ) : string { return trailingslashit( - isset( $parts['scheme'] ) ? "{$parts['scheme']}:" : '' . - isset( $parts['path'] ) ? untrailingslashit( "{$parts['path']}" ) : '' . - isset( $parts['query'] ) ? str_replace( '/', '', "?{$parts['query']}" ) : '' . - isset( $parts['fragment'] ) ? str_replace( '/', '', "#{$parts['fragment']}" ) : '' + ( isset( $parts['scheme'] ) ? "{$parts['scheme']}:" : '' ) . + ( isset( $parts['path'] ) ? untrailingslashit( "{$parts['path']}" ) : '' ) . + ( isset( $parts['query'] ) ? str_replace( '/', '', "?{$parts['query']}" ) : '' ) . + ( isset( $parts['fragment'] ) ? str_replace( '/', '', "#{$parts['fragment']}" ) : '' ) ); } From d59ba4bee8972fa2ff04b18fe5ce85fc8deb54af Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 8 Jul 2024 15:55:14 -0600 Subject: [PATCH 04/39] dont' use anonymous function --- web/app/mu-plugins/filters.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/web/app/mu-plugins/filters.php b/web/app/mu-plugins/filters.php index 4c937469..7aba0ce1 100644 --- a/web/app/mu-plugins/filters.php +++ b/web/app/mu-plugins/filters.php @@ -143,7 +143,7 @@ function add_wp_prefix_to_login_and_admin_urls( string $url ) : string { * @param null|string $endpoint The GraphQL endpoint. * @return null|string The filtered GraphQL endpoint. */ -add_filter( 'graphql_endpoint', function( $endpoint ) { +function ensure_graphql_url_prefix( $endpoint ) : null|string { $desired_endpoint = '/wp/graphql'; if ( ! $endpoint ) { @@ -155,7 +155,8 @@ function add_wp_prefix_to_login_and_admin_urls( string $url ) : string { } return $endpoint; -}, 9 ); +} +add_filter( 'graphql_endpoint', __NAMESPACE__ . '\\ensure_graphql_url_prefix', 9 ); /** * Check the URL to see if it's either an admin or wp-login URL. From 1489d344f1cf05066696274e5c08488c4ef9b9c1 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 8 Jul 2024 16:14:40 -0600 Subject: [PATCH 05/39] add host if exists --- web/app/mu-plugins/filters.php | 1 + 1 file changed, 1 insertion(+) diff --git a/web/app/mu-plugins/filters.php b/web/app/mu-plugins/filters.php index 7aba0ce1..1763f68a 100644 --- a/web/app/mu-plugins/filters.php +++ b/web/app/mu-plugins/filters.php @@ -215,6 +215,7 @@ function __normalize_wp_url( string $url ): string { function __rebuild_url_from_parts( array $parts ) : string { return trailingslashit( ( isset( $parts['scheme'] ) ? "{$parts['scheme']}:" : '' ) . + ( isset( $parts['host'] ) ? "{$parts['host']}" : '' ) . ( isset( $parts['path'] ) ? untrailingslashit( "{$parts['path']}" ) : '' ) . ( isset( $parts['query'] ) ? str_replace( '/', '', "?{$parts['query']}" ) : '' ) . ( isset( $parts['fragment'] ) ? str_replace( '/', '', "#{$parts['fragment']}" ) : '' ) From 58366060d2e648e057ef70a71d43180cd1eef7cd Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 8 Jul 2024 16:15:36 -0600 Subject: [PATCH 06/39] replace graphql endpoint filter with an action hook to prepopulate this is a setting that can be changed, so this way we're setting it to what we think it should be without forcing users to use our path --- web/app/mu-plugins/filters.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/web/app/mu-plugins/filters.php b/web/app/mu-plugins/filters.php index 1763f68a..98da9d79 100644 --- a/web/app/mu-plugins/filters.php +++ b/web/app/mu-plugins/filters.php @@ -137,26 +137,20 @@ function add_wp_prefix_to_login_and_admin_urls( string $url ) : string { add_filter( 'admin_url', __NAMESPACE__ . '\\add_wp_prefix_to_login_and_admin_urls', 9 ); /** - * Ensure the /wp prefix is retained in the WPGraphQL endpoint. + * Prepopulate GraphQL endpoint URL with default value if unset. + * This will ensure that the URL is not changed from /wp/graphql to /graphql by our other filtering unless that's what the user wants. * * @since 1.1.0 - * @param null|string $endpoint The GraphQL endpoint. - * @return null|string The filtered GraphQL endpoint. */ -function ensure_graphql_url_prefix( $endpoint ) : null|string { - $desired_endpoint = '/wp/graphql'; - - if ( ! $endpoint ) { - return $desired_endpoint; - } - - if ( $endpoint && strpos( $endpoint, '/wp' ) === false ) { - $endpoint = "/wp/$endpoint"; +function prepopulate_graphql_endpoint_url() { + $options = get_option( 'graphql_general_settings' ); + if ( ! $options ) { + $options = []; + $options['graphql_endpoint'] = '/wp/graphql'; + update_option( 'graphql_general_settings', $options ); } - - return $endpoint; } -add_filter( 'graphql_endpoint', __NAMESPACE__ . '\\ensure_graphql_url_prefix', 9 ); +add_action( 'graphql_init', __NAMESPACE__ . '\\prepopulate_graphql_endpoint_url' ); /** * Check the URL to see if it's either an admin or wp-login URL. From e477b51bdcde7609f0e53008d3ec70d035a91737 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 11:00:57 -0600 Subject: [PATCH 07/39] move the prepopulate action and make it more robust use dynamic site_url and make the setting conditional based on whether there's already a /wp/ i the siteurl --- web/app/mu-plugins/filters.php | 35 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/web/app/mu-plugins/filters.php b/web/app/mu-plugins/filters.php index 98da9d79..30f146a8 100644 --- a/web/app/mu-plugins/filters.php +++ b/web/app/mu-plugins/filters.php @@ -96,6 +96,25 @@ function fix_core_resource_urls( string $url ) : string { } } +/** + * Prepopulate GraphQL endpoint URL with default value if unset. + * This will ensure that the URL is not changed from /wp/graphql to /graphql by our other filtering unless that's what the user wants. + * + * @since 1.1.0 + */ +function prepopulate_graphql_endpoint_url() { + $options = get_option( 'graphql_general_settings' ); + $site_path = site_url(); + + if ( ! $options ) { + $endpoint = ( ! empty( $site_path ) || strpos( $site_path, 'wp' ) !== false ) ? 'graphql' : 'wp/graphql'; + $options = []; + $options['graphql_endpoint'] = $endpoint; + update_option( 'graphql_general_settings', $options ); + } +} +add_action( 'graphql_init', __NAMESPACE__ . '\\prepopulate_graphql_endpoint_url' ); + /** * Drop the /wp, if it exists, from URLs on the main site (single site or multisite). * @@ -136,22 +155,6 @@ function add_wp_prefix_to_login_and_admin_urls( string $url ) : string { add_filter( 'login_url', __NAMESPACE__ . '\\add_wp_prefix_to_login_and_admin_urls', 9 ); add_filter( 'admin_url', __NAMESPACE__ . '\\add_wp_prefix_to_login_and_admin_urls', 9 ); -/** - * Prepopulate GraphQL endpoint URL with default value if unset. - * This will ensure that the URL is not changed from /wp/graphql to /graphql by our other filtering unless that's what the user wants. - * - * @since 1.1.0 - */ -function prepopulate_graphql_endpoint_url() { - $options = get_option( 'graphql_general_settings' ); - if ( ! $options ) { - $options = []; - $options['graphql_endpoint'] = '/wp/graphql'; - update_option( 'graphql_general_settings', $options ); - } -} -add_action( 'graphql_init', __NAMESPACE__ . '\\prepopulate_graphql_endpoint_url' ); - /** * Check the URL to see if it's either an admin or wp-login URL. * From 2607a16b9fb5a2dcdf0493fef8e1e7a675443850 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 11:01:14 -0600 Subject: [PATCH 08/39] add exclusions to site_url filter for graphql --- web/app/mu-plugins/filters.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/web/app/mu-plugins/filters.php b/web/app/mu-plugins/filters.php index 30f146a8..34b0144b 100644 --- a/web/app/mu-plugins/filters.php +++ b/web/app/mu-plugins/filters.php @@ -125,6 +125,15 @@ function prepopulate_graphql_endpoint_url() { * @return string The filtered URL. */ function adjust_main_site_urls( string $url ) : string { + if ( doing_action( 'graphql_init' ) ) { + return $url; + } + + // Explicit handling for /wp/graphql + if ( strpos( $url, '/graphql' ) !== false ) { + return $url; + } + // If this is the main site, drop the /wp. if ( is_main_site() && ! __is_login_url( $url ) ) { $url = str_replace( '/wp/', '/', $url ); @@ -191,6 +200,7 @@ function __is_login_url( string $url ) : bool { * @return string The normalized URL. */ function __normalize_wp_url( string $url ): string { + // Parse the URL into components. $parts = parse_url( $url ); // Normalize the URL to remove any double slashes. From 0b5cda22ecebd847d13b3869b013d1a45a6afb22 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 11:51:41 -0600 Subject: [PATCH 09/39] add playwright tests --- .github/tests/wpcm.spec.ts | 49 ++++++++++++++++++++ .github/workflows/playwright.yml | 76 ++++++++++++++++++++++++++++++++ package.json | 12 +++++ 3 files changed, 137 insertions(+) create mode 100644 .github/tests/wpcm.spec.ts create mode 100644 .github/workflows/playwright.yml create mode 100644 package.json diff --git a/.github/tests/wpcm.spec.ts b/.github/tests/wpcm.spec.ts new file mode 100644 index 00000000..998e39c3 --- /dev/null +++ b/.github/tests/wpcm.spec.ts @@ -0,0 +1,49 @@ +import { test, expect } from "@playwright/test"; + +const exampleArticle = "Hello world!"; +const siteTitle = "WPCM Playwright Tests"; +const siteUrl = process.env.SITE_URL || "https://dev-wpcm-playwright-tests.pantheonsite.io"; + +test("homepage loads and contains example content", async ({ page }) => { + await page.goto(siteUrl); + await expect(page).toHaveTitle(siteTitle); + await expect(page.getByText(exampleArticle)).toHaveText(exampleArticle); +}); + +test("WP REST API is accessible", async ({ request }) => { + const apiRoot = await request.get(`${siteUrl}/wp-json`); + expect(apiRoot.ok()).toBeTruthy(); +}); + +test("Hello World post is accessible", async ({ page }) => { + await page.goto(`${siteUrl}/hello-world`); + await expect(page).toHaveTitle(`${exampleArticle} – ${siteTitle}`); +}); + +test("graphql is able to access hello world post", async ({ request }) => { + const query = ` + query { + posts(where: { search: "${exampleArticle}" }) { + edges { + node { + title + } + } + } + } + `; + + const response = await request.post(`${siteUrl}/wp/graphql`, { + data: { + query: query + }, + headers: { + 'Content-Type': 'application/json' + } + }); + + const responseBody = await response.json(); + + expect(responseBody.data.posts.edges.length).toBeGreaterThan(0); + expect(responseBody.data.posts.edges[0].node.title).toBe(exampleArticle); +}); diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml new file mode 100644 index 00000000..b2f7b370 --- /dev/null +++ b/.github/workflows/playwright.yml @@ -0,0 +1,76 @@ +name: WordPress (Composer Managed) Playwright Tests +on: + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + +permissions: + contents: write + +jobs: + playwright: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install Composer dependencies + run: composer update --no-progress --prefer-dist --optimize-autoloader + + - name: Install NPM dependencies + run: npm ci + + - name: Install Playwright Browsers + run: npx playwright install --with-deps + + - name: Install SSH keys + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Get latest Terminus release + uses: pantheon-systems/terminus-github-actions@v1 + with: + pantheon-machine-token: ${{ secrets.TERMINUS_TOKEN }} + - name: Validate Pantheon Host Key + run: | + echo "Host *.drush.in HostKeyAlgorithms +ssh-rsa" >> ~/.ssh/config + echo "Host *.drush.in PubkeyAcceptedKeyTypes +ssh-rsa" >> ~/.ssh/config + echo "StrictHostKeyChecking no" >> ~/.ssh/config + - name: Log into Terminus + run: | + terminus auth:login --machine-token=${{ secrets.TERMINUS_TOKEN }} + + - name: Create Site + run: | + terminus site:create wpcm-playwright-tests 'WordPress (Composer Managed) Playwright Test Site' 'WordPress (Composer Managed)' --org=5ae1fa30-8cc4-4894-8ca9-d50628dcba17 + + - name: Clone the site and pull down updates + run: | + terminus local:clone wpcm-playwright-tests + cd ~/pantheon-local-copies/wpcm-playwright-tests + rsync -a --exclude='.git' ${{ github.workspace }} . + git add -A + git commit -m "Update to latest" + git push origin master + + - name: Status Check + run: terminus wp wpcm-playwright-tests.dev -- cli info + + - name: Install WordPress + run: terminus wp wpcm-playwright-tests.dev -- core install --title='WPCM Playwright Tests' --admin_user=wpcm --admin_email=test@dev.null + + - name: Install WP GraphQL + run: | + terminus connection:set wpcm-playwright-tests.dev sftp + terminus wp wpcm-playwright-tests.dev -- plugin install --activate wp-graphql + + - name: Run Playwright Tests + run: npm run test .github/tests/wpcm.spec.ts + + - name: Delete Site + if: success() + run: terminus site:delete wpcm-playwright-tests -y diff --git a/package.json b/package.json new file mode 100644 index 00000000..3842ab81 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "@pantheon-systems/wordpress-composer-managed", + "version": "1.31.0", + "description": "Automated testing for WordPress (Composer Managed).", + "scripts": { + "test": "playwright test --trace on", + "report": "playwright show-report" + }, + "devDependencies": { + "@playwright/test": "^1.28.0" + } +} From 0169f4b04e6295710913d51456395a2866764c60 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 11:53:27 -0600 Subject: [PATCH 10/39] change ci to install --- .github/workflows/playwright.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index b2f7b370..3012d1a8 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -21,7 +21,7 @@ jobs: run: composer update --no-progress --prefer-dist --optimize-autoloader - name: Install NPM dependencies - run: npm ci + run: npm install - name: Install Playwright Browsers run: npx playwright install --with-deps From 9ea9a605c321411d458df908c73b7c8a554743d0 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 12:06:40 -0600 Subject: [PATCH 11/39] don't create the site if it already exists --- .github/workflows/playwright.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 3012d1a8..f2d30cf9 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -46,7 +46,11 @@ jobs: - name: Create Site run: | - terminus site:create wpcm-playwright-tests 'WordPress (Composer Managed) Playwright Test Site' 'WordPress (Composer Managed)' --org=5ae1fa30-8cc4-4894-8ca9-d50628dcba17 + if terminus site:info wpcm-playwright-tests; then + echo "Test site already exists, skipping site creation." + else + terminus site:create wpcm-playwright-tests 'WordPress (Composer Managed) Playwright Test Site' 'WordPress (Composer Managed)' --org=5ae1fa30-8cc4-4894-8ca9-d50628dcba17 + fi - name: Clone the site and pull down updates run: | From 468f5c1ddf41cbcaf39973fb19ac8bbda209f36d Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 12:06:57 -0600 Subject: [PATCH 12/39] add git config for the user --- .github/workflows/playwright.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index f2d30cf9..e49f9ca3 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -52,11 +52,13 @@ jobs: terminus site:create wpcm-playwright-tests 'WordPress (Composer Managed) Playwright Test Site' 'WordPress (Composer Managed)' --org=5ae1fa30-8cc4-4894-8ca9-d50628dcba17 fi - - name: Clone the site and pull down updates + - name: Clone the site and copy PR updates run: | + git config --global user.email "cms-platform+sage-testing@pantheon.io" + git config --global user.name "Pantheon WPCM Bot 🤖" terminus local:clone wpcm-playwright-tests cd ~/pantheon-local-copies/wpcm-playwright-tests - rsync -a --exclude='.git' ${{ github.workspace }} . + rsync -a --exclude='.git' ${{ github.workspace }}/ . git add -A git commit -m "Update to latest" git push origin master From 218da9869648f91f402ab7d4de655a5ab766f145 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 12:10:09 -0600 Subject: [PATCH 13/39] wait for the last action to finish before switching to sftp mode --- .github/workflows/playwright.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index e49f9ca3..e7040206 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -71,6 +71,7 @@ jobs: - name: Install WP GraphQL run: | + terminus workflow:wait wpcm-playwright-tests.dev terminus connection:set wpcm-playwright-tests.dev sftp terminus wp wpcm-playwright-tests.dev -- plugin install --activate wp-graphql From c0bc9ea872cf83d8230a876912cb8eaae719f5c6 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 12:18:18 -0600 Subject: [PATCH 14/39] set pretty permalinks for playwright test site --- .github/workflows/playwright.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index e7040206..c18c080d 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -67,7 +67,11 @@ jobs: run: terminus wp wpcm-playwright-tests.dev -- cli info - name: Install WordPress - run: terminus wp wpcm-playwright-tests.dev -- core install --title='WPCM Playwright Tests' --admin_user=wpcm --admin_email=test@dev.null + run: | + terminus wp wpcm-playwright-tests.dev -- core install --title='WPCM Playwright Tests' --admin_user=wpcm --admin_email=test@dev.null + terminus wp wpcm-playwright-tests.dev -- option update permalink_structure '/%postname%/' + terminus wp wpcm-playwright-tests.dev -- rewrite flush + terminus wp wpcm-playwright-tests.dev -- cache flush - name: Install WP GraphQL run: | From d1c040631ae296baf62ace398b36497937359527 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 12:23:24 -0600 Subject: [PATCH 15/39] switch the existing site to git mode --- .github/workflows/playwright.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index c18c080d..f89a35f6 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -48,6 +48,8 @@ jobs: run: | if terminus site:info wpcm-playwright-tests; then echo "Test site already exists, skipping site creation." + # If the site exists already, we should switch it to git mode. + terminus connection:set wpcm-playwright-tests.dev git else terminus site:create wpcm-playwright-tests 'WordPress (Composer Managed) Playwright Test Site' 'WordPress (Composer Managed)' --org=5ae1fa30-8cc4-4894-8ca9-d50628dcba17 fi From f9a1180dbde9ff01ff7b9df1bfa617a8e053b339 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 12:25:18 -0600 Subject: [PATCH 16/39] force yes --- .github/workflows/playwright.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index f89a35f6..6e764968 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -49,7 +49,7 @@ jobs: if terminus site:info wpcm-playwright-tests; then echo "Test site already exists, skipping site creation." # If the site exists already, we should switch it to git mode. - terminus connection:set wpcm-playwright-tests.dev git + terminus connection:set wpcm-playwright-tests.dev git -y else terminus site:create wpcm-playwright-tests 'WordPress (Composer Managed) Playwright Test Site' 'WordPress (Composer Managed)' --org=5ae1fa30-8cc4-4894-8ca9-d50628dcba17 fi From 25d1e44dfc9c82aa23684a39ad14851c94cc29c2 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 12:38:58 -0600 Subject: [PATCH 17/39] check the h2 instead of the site title that's a theme thing. the canary sites are running a different theme --- .github/tests/wpcm.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/tests/wpcm.spec.ts b/.github/tests/wpcm.spec.ts index 998e39c3..67e0138c 100644 --- a/.github/tests/wpcm.spec.ts +++ b/.github/tests/wpcm.spec.ts @@ -17,7 +17,9 @@ test("WP REST API is accessible", async ({ request }) => { test("Hello World post is accessible", async ({ page }) => { await page.goto(`${siteUrl}/hello-world`); - await expect(page).toHaveTitle(`${exampleArticle} – ${siteTitle}`); + const h2Element = await page.locator('h2'); + await expect(h2Element).toHaveText(exampleArticle); +}); }); test("graphql is able to access hello world post", async ({ request }) => { From d12ab4b11b84fa7c3f062e1d9996e44dad55c189 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 12:39:12 -0600 Subject: [PATCH 18/39] test that the resource urls have /wp/ in the path --- .github/tests/wpcm.spec.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/tests/wpcm.spec.ts b/.github/tests/wpcm.spec.ts index 67e0138c..bb762898 100644 --- a/.github/tests/wpcm.spec.ts +++ b/.github/tests/wpcm.spec.ts @@ -20,6 +20,20 @@ test("Hello World post is accessible", async ({ page }) => { const h2Element = await page.locator('h2'); await expect(h2Element).toHaveText(exampleArticle); }); + +test("validate core resource URLs", async ({ page }) => { + await page.goto(siteUrl); + + const coreResources = [ + 'wp-includes/js/dist/interactivity.min.js', + 'wp-includes/css/dist/editor.min.css', + ]; + + for ( const resource of coreResources ) { + const resourceUrl = `${siteUrl}/wp/${resource}`; + const element = await page.locator(`link[href="${resourceUrl}], script[src="${resourceUrl}"]`); + await expect(element).toBeVisible(); + } }); test("graphql is able to access hello world post", async ({ request }) => { From 707e2c9076f0b15916e368056bdb229c8e2e08a6 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 12:44:27 -0600 Subject: [PATCH 19/39] missing " --- .github/tests/wpcm.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/tests/wpcm.spec.ts b/.github/tests/wpcm.spec.ts index bb762898..d5efb423 100644 --- a/.github/tests/wpcm.spec.ts +++ b/.github/tests/wpcm.spec.ts @@ -31,7 +31,7 @@ test("validate core resource URLs", async ({ page }) => { for ( const resource of coreResources ) { const resourceUrl = `${siteUrl}/wp/${resource}`; - const element = await page.locator(`link[href="${resourceUrl}], script[src="${resourceUrl}"]`); + const element = await page.locator(`link[href="${resourceUrl}"], script[src="${resourceUrl}"]`); await expect(element).toBeVisible(); } }); From 9093ef706b0741c85bdc03aadf9e27675fd88123 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 12:57:09 -0600 Subject: [PATCH 20/39] expect the resource url to be truthy on a request --- .github/tests/wpcm.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/tests/wpcm.spec.ts b/.github/tests/wpcm.spec.ts index d5efb423..105649b5 100644 --- a/.github/tests/wpcm.spec.ts +++ b/.github/tests/wpcm.spec.ts @@ -21,7 +21,7 @@ test("Hello World post is accessible", async ({ page }) => { await expect(h2Element).toHaveText(exampleArticle); }); -test("validate core resource URLs", async ({ page }) => { +test("validate core resource URLs", async ({ request }) => { await page.goto(siteUrl); const coreResources = [ @@ -31,8 +31,8 @@ test("validate core resource URLs", async ({ page }) => { for ( const resource of coreResources ) { const resourceUrl = `${siteUrl}/wp/${resource}`; - const element = await page.locator(`link[href="${resourceUrl}"], script[src="${resourceUrl}"]`); - await expect(element).toBeVisible(); + const response = await request.get(resourceUrl); + await expect(response).toBeTruthy(); } }); From 1f611f9a92873122c98dc3ae32da19d506acad0c Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 12:58:40 -0600 Subject: [PATCH 21/39] append the commit message from the PR to the commit to the test site --- .github/workflows/playwright.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 6e764968..1f145eb2 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -61,8 +61,9 @@ jobs: terminus local:clone wpcm-playwright-tests cd ~/pantheon-local-copies/wpcm-playwright-tests rsync -a --exclude='.git' ${{ github.workspace }}/ . + COMMIT_MSG=$(gh pr view ${{ github.event.pull_request.number }} --json commits --jq '.commits[-1].commit.message') git add -A - git commit -m "Update to latest" + git commit -m "Update to latest commit: ${COMMIT_MSG}" git push origin master - name: Status Check From b702020b3e9faa39b0cd16454e47c8ad158c7988 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 13:01:31 -0600 Subject: [PATCH 22/39] use github token so we can use gh --- .github/workflows/playwright.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 1f145eb2..111d73ea 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -55,6 +55,8 @@ jobs: fi - name: Clone the site and copy PR updates + env: + GH_TOKEN: ${{ github.token }} run: | git config --global user.email "cms-platform+sage-testing@pantheon.io" git config --global user.name "Pantheon WPCM Bot 🤖" From 6aeb8c9c570e41523a57590a21fbd6aec035ca14 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 13:01:40 -0600 Subject: [PATCH 23/39] add package.json to export-ignore --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index db8a36b2..4560403d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,4 @@ /.editorconfig export-ignore /.gitattributes export-ignore /.github export-ignore +/package.json export-ignore From dfef2ceeb5295deb8966e425cf4c0fe3e4f5ab1d Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 13:05:15 -0600 Subject: [PATCH 24/39] move the commit msg var up so we haven't cd'd into the local copy when we're looking for the commit message --- .github/workflows/playwright.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 111d73ea..c7ed910f 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -60,10 +60,10 @@ jobs: run: | git config --global user.email "cms-platform+sage-testing@pantheon.io" git config --global user.name "Pantheon WPCM Bot 🤖" + COMMIT_MSG=$(gh pr view ${{ github.event.pull_request.number }} --json commits --jq '.commits[-1].commit.message') terminus local:clone wpcm-playwright-tests cd ~/pantheon-local-copies/wpcm-playwright-tests rsync -a --exclude='.git' ${{ github.workspace }}/ . - COMMIT_MSG=$(gh pr view ${{ github.event.pull_request.number }} --json commits --jq '.commits[-1].commit.message') git add -A git commit -m "Update to latest commit: ${COMMIT_MSG}" git push origin master From 312ba79f33ab972b02e36095ddd4249914618e7f Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 13:09:47 -0600 Subject: [PATCH 25/39] we don't need `page` at all --- .github/tests/wpcm.spec.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/tests/wpcm.spec.ts b/.github/tests/wpcm.spec.ts index 105649b5..88c2792a 100644 --- a/.github/tests/wpcm.spec.ts +++ b/.github/tests/wpcm.spec.ts @@ -22,8 +22,6 @@ test("Hello World post is accessible", async ({ page }) => { }); test("validate core resource URLs", async ({ request }) => { - await page.goto(siteUrl); - const coreResources = [ 'wp-includes/js/dist/interactivity.min.js', 'wp-includes/css/dist/editor.min.css', From 69e379c620641b9db6b5aa3f30a4fec399b1c1ea Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 13:14:26 -0600 Subject: [PATCH 26/39] this doesn't change anything other than seeing if we're getting the PR number --- .github/workflows/playwright.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index c7ed910f..586da115 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -60,7 +60,10 @@ jobs: run: | git config --global user.email "cms-platform+sage-testing@pantheon.io" git config --global user.name "Pantheon WPCM Bot 🤖" - COMMIT_MSG=$(gh pr view ${{ github.event.pull_request.number }} --json commits --jq '.commits[-1].commit.message') + PR_NUMBER=$(echo ${{ github.event.pull_request.number }}) + echo "Pull Request Number: ${PR_NUMBER}" + COMMIT_MSG=$(gh pr view ${PR_NUMBER} --json commits --jq '.commits[-1].commit.message') + echo "Commit Message: ${COMMIT_MSG}" terminus local:clone wpcm-playwright-tests cd ~/pantheon-local-copies/wpcm-playwright-tests rsync -a --exclude='.git' ${{ github.workspace }}/ . From d138206346b98843fd099ea698416cb5c8235576 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 13:25:55 -0600 Subject: [PATCH 27/39] fix the commit message --- .github/workflows/playwright.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 586da115..0e57d634 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -62,7 +62,7 @@ jobs: git config --global user.name "Pantheon WPCM Bot 🤖" PR_NUMBER=$(echo ${{ github.event.pull_request.number }}) echo "Pull Request Number: ${PR_NUMBER}" - COMMIT_MSG=$(gh pr view ${PR_NUMBER} --json commits --jq '.commits[-1].commit.message') + COMMIT_MSG=$(gh pr view ${PR_NUMBER} --json commits --jq '.commits[-1].messageHeadline') echo "Commit Message: ${COMMIT_MSG}" terminus local:clone wpcm-playwright-tests cd ~/pantheon-local-copies/wpcm-playwright-tests From a9a1d10f11da2fc792f4b33b4c28ebdebfb8eae5 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 13:35:15 -0600 Subject: [PATCH 28/39] Include the git commit message body so it's not just truncated if it's long --- .github/workflows/playwright.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 0e57d634..1fd1bc80 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -62,7 +62,7 @@ jobs: git config --global user.name "Pantheon WPCM Bot 🤖" PR_NUMBER=$(echo ${{ github.event.pull_request.number }}) echo "Pull Request Number: ${PR_NUMBER}" - COMMIT_MSG=$(gh pr view ${PR_NUMBER} --json commits --jq '.commits[-1].messageHeadline') + COMMIT_MSG=$(gh pr view ${PR_NUMBER} --json commits --jq '.commits[-1] | "\(.messageHeadline) \(.messageBody)"') echo "Commit Message: ${COMMIT_MSG}" terminus local:clone wpcm-playwright-tests cd ~/pantheon-local-copies/wpcm-playwright-tests From 2aab87ba2e478b5acfe825a3d65126a7d2909fe9 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 13:44:17 -0600 Subject: [PATCH 29/39] don't fail if there's nothing to commit --- .github/workflows/playwright.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 1fd1bc80..20abe073 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -54,7 +54,7 @@ jobs: terminus site:create wpcm-playwright-tests 'WordPress (Composer Managed) Playwright Test Site' 'WordPress (Composer Managed)' --org=5ae1fa30-8cc4-4894-8ca9-d50628dcba17 fi - - name: Clone the site and copy PR updates + - name: Clone the site locally and copy PR updates env: GH_TOKEN: ${{ github.token }} run: | @@ -68,8 +68,8 @@ jobs: cd ~/pantheon-local-copies/wpcm-playwright-tests rsync -a --exclude='.git' ${{ github.workspace }}/ . git add -A - git commit -m "Update to latest commit: ${COMMIT_MSG}" - git push origin master + git commit -m "Update to latest commit: ${COMMIT_MSG}" || true + git push origin master || true - name: Status Check run: terminus wp wpcm-playwright-tests.dev -- cli info From 54dbbf9dc371c6ef6156dd48e94f8e42f543512e Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 13:48:36 -0600 Subject: [PATCH 30/39] add caching for dependencies --- .github/workflows/playwright.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 20abe073..4cd44382 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -17,6 +17,18 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Set up cache for dependencies + uses: actions/cache@v4 + with: + path: | + ~/.composer/cache + ./vendor + ~/.npm + ./node_modules + key: ${{ runner.os }}-deps-${{ hashFiles( '**/composer.lock', '**/package-lock.json' ) }} + restore-keys: ${{ runner.os }}-deps- + + - name: Install Composer dependencies run: composer update --no-progress --prefer-dist --optimize-autoloader From 75292b871c7f2d5e67cec5e4337614752c83b966 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 13:58:36 -0600 Subject: [PATCH 31/39] fix hello world test --- .github/tests/wpcm.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/tests/wpcm.spec.ts b/.github/tests/wpcm.spec.ts index 88c2792a..8240c5a1 100644 --- a/.github/tests/wpcm.spec.ts +++ b/.github/tests/wpcm.spec.ts @@ -16,9 +16,9 @@ test("WP REST API is accessible", async ({ request }) => { }); test("Hello World post is accessible", async ({ page }) => { - await page.goto(`${siteUrl}/hello-world`); - const h2Element = await page.locator('h2'); - await expect(h2Element).toHaveText(exampleArticle); + await page.goto(`${siteUrl}/hello-world/'`); + await expect(page).toHaveTitle(`${exampleArticle} - ${siteTitle}`); + await expect(page).toHaveText('Welcome to WordPress'); }); test("validate core resource URLs", async ({ request }) => { From dec93c0176a596c5f860afd562a137614d6c1282 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 14:39:36 -0600 Subject: [PATCH 32/39] emdash problems --- .github/tests/wpcm.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/tests/wpcm.spec.ts b/.github/tests/wpcm.spec.ts index 8240c5a1..ff8e9343 100644 --- a/.github/tests/wpcm.spec.ts +++ b/.github/tests/wpcm.spec.ts @@ -17,7 +17,7 @@ test("WP REST API is accessible", async ({ request }) => { test("Hello World post is accessible", async ({ page }) => { await page.goto(`${siteUrl}/hello-world/'`); - await expect(page).toHaveTitle(`${exampleArticle} - ${siteTitle}`); + await expect(page).toHaveTitle(`${exampleArticle} – ${siteTitle}`); await expect(page).toHaveText('Welcome to WordPress'); }); From 3c94b14e5848b67e9020af8a731adb847a677aaa Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 14:58:11 -0600 Subject: [PATCH 33/39] fix the locator on the welcome message test --- .github/tests/wpcm.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/tests/wpcm.spec.ts b/.github/tests/wpcm.spec.ts index ff8e9343..a7e6c4c2 100644 --- a/.github/tests/wpcm.spec.ts +++ b/.github/tests/wpcm.spec.ts @@ -18,7 +18,9 @@ test("WP REST API is accessible", async ({ request }) => { test("Hello World post is accessible", async ({ page }) => { await page.goto(`${siteUrl}/hello-world/'`); await expect(page).toHaveTitle(`${exampleArticle} – ${siteTitle}`); - await expect(page).toHaveText('Welcome to WordPress'); + // Locate the element containing the desired text + const welcomeText = page.locator('text=Welcome to WordPress'); + await expect(welcomeText).toHaveText('Welcome to WordPress'); }); test("validate core resource URLs", async ({ request }) => { From 1cc61ff5627754fa8e5410c18daf9f220a693400 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 14:59:47 -0600 Subject: [PATCH 34/39] generate lock files so we can use the cache --- .github/workflows/playwright.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 4cd44382..a4564c99 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -17,6 +17,11 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Generate lock files + run: | + composer update --lock + npm install --package-lock-only + - name: Set up cache for dependencies uses: actions/cache@v4 with: @@ -33,7 +38,7 @@ jobs: run: composer update --no-progress --prefer-dist --optimize-autoloader - name: Install NPM dependencies - run: npm install + run: npm ci - name: Install Playwright Browsers run: npx playwright install --with-deps From 4e9a2ff0622230239f48766b97d8de70a71e63d0 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 15:03:37 -0600 Subject: [PATCH 35/39] pass default values so the substr check isn't null --- upstream-configuration/scripts/ComposerScripts.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/upstream-configuration/scripts/ComposerScripts.php b/upstream-configuration/scripts/ComposerScripts.php index 07cb923e..7d6828de 100644 --- a/upstream-configuration/scripts/ComposerScripts.php +++ b/upstream-configuration/scripts/ComposerScripts.php @@ -55,9 +55,9 @@ public static function applyComposerJsonUpdates(Event $event) // is the same as the Pantheon PHP version (which is only major.minor). // If they do not match, force an update to the platform PHP version. If they // have the same major.minor version, then - $platformPhpVersion = static::getCurrentPlatformPhp($event); - $pantheonPhpVersion = static::getPantheonPhpVersion($event); - $updatedPlatformPhpVersion = static::bestPhpPatchVersion($pantheonPhpVersion); + $platformPhpVersion = static::getCurrentPlatformPhp($event) ?? ''; + $pantheonPhpVersion = static::getPantheonPhpVersion($event) ?? ''; + $updatedPlatformPhpVersion = static::bestPhpPatchVersion($pantheonPhpVersion) ?? ''; if ((substr($platformPhpVersion, 0, strlen($pantheonPhpVersion)) != $pantheonPhpVersion) && !empty($updatedPlatformPhpVersion)) { $io->write("Setting platform.php from '$platformPhpVersion' to '$updatedPlatformPhpVersion' to conform to pantheon php version."); $composerJson['config']['platform']['php'] = $updatedPlatformPhpVersion; From 1db29d480e0bceb08431f8230a115e6ea19c89fb Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 15:05:20 -0600 Subject: [PATCH 36/39] change test to toContainText --- .github/tests/wpcm.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/tests/wpcm.spec.ts b/.github/tests/wpcm.spec.ts index a7e6c4c2..de8861e3 100644 --- a/.github/tests/wpcm.spec.ts +++ b/.github/tests/wpcm.spec.ts @@ -20,7 +20,7 @@ test("Hello World post is accessible", async ({ page }) => { await expect(page).toHaveTitle(`${exampleArticle} – ${siteTitle}`); // Locate the element containing the desired text const welcomeText = page.locator('text=Welcome to WordPress'); - await expect(welcomeText).toHaveText('Welcome to WordPress'); + await expect(welcomeText).toContainText('Welcome to WordPress'); }); test("validate core resource URLs", async ({ request }) => { From 1d11125456e86c87c960d782b8566e47046e3bdb Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 9 Jul 2024 15:10:42 -0600 Subject: [PATCH 37/39] only generate the npm lock use the composer.json instead of composer.lock use the conditional to check for cache --- .github/workflows/playwright.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index a4564c99..616a10b3 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -19,25 +19,26 @@ jobs: - name: Generate lock files run: | - composer update --lock npm install --package-lock-only - name: Set up cache for dependencies uses: actions/cache@v4 + id: cache with: path: | ~/.composer/cache ./vendor ~/.npm ./node_modules - key: ${{ runner.os }}-deps-${{ hashFiles( '**/composer.lock', '**/package-lock.json' ) }} + key: ${{ runner.os }}-deps-${{ hashFiles( '**/composer.json', '**/package-lock.json' ) }} restore-keys: ${{ runner.os }}-deps- - - name: Install Composer dependencies + if: steps.cache.outputs.cache-hit != true run: composer update --no-progress --prefer-dist --optimize-autoloader - name: Install NPM dependencies + if: steps.cache.outputs.cache-hit != true run: npm ci - name: Install Playwright Browsers From 76ad38c2bd68d3a5259aac3d0ddcf06e2b18545c Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 10 Jul 2024 08:37:20 -0600 Subject: [PATCH 38/39] =?UTF-8?q?party=20pooper=20=F0=9F=92=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Phil Tyler --- .github/workflows/playwright.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 616a10b3..f3d7442c 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -77,7 +77,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | git config --global user.email "cms-platform+sage-testing@pantheon.io" - git config --global user.name "Pantheon WPCM Bot 🤖" + git config --global user.name "Pantheon WPCM Bot" PR_NUMBER=$(echo ${{ github.event.pull_request.number }}) echo "Pull Request Number: ${PR_NUMBER}" COMMIT_MSG=$(gh pr view ${PR_NUMBER} --json commits --jq '.commits[-1] | "\(.messageHeadline) \(.messageBody)"') From 364083a87ec4d0211b67639d3893ee41b241c02a Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 10 Jul 2024 09:23:24 -0600 Subject: [PATCH 39/39] bail early --- web/app/mu-plugins/filters.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/web/app/mu-plugins/filters.php b/web/app/mu-plugins/filters.php index 34b0144b..b9b3fa7d 100644 --- a/web/app/mu-plugins/filters.php +++ b/web/app/mu-plugins/filters.php @@ -104,14 +104,17 @@ function fix_core_resource_urls( string $url ) : string { */ function prepopulate_graphql_endpoint_url() { $options = get_option( 'graphql_general_settings' ); - $site_path = site_url(); - if ( ! $options ) { - $endpoint = ( ! empty( $site_path ) || strpos( $site_path, 'wp' ) !== false ) ? 'graphql' : 'wp/graphql'; - $options = []; - $options['graphql_endpoint'] = $endpoint; - update_option( 'graphql_general_settings', $options ); - } + // Bail early if options have already been set. + if ( $options ) { + return; + } + + $options = []; + $site_path = site_url(); + $endpoint = ( ! empty( $site_path ) || strpos( $site_path, 'wp' ) !== false ) ? 'graphql' : 'wp/graphql'; + $options['graphql_endpoint'] = $endpoint; + update_option( 'graphql_general_settings', $options ); } add_action( 'graphql_init', __NAMESPACE__ . '\\prepopulate_graphql_endpoint_url' );