From 425f3e88fce272bd2bd346b68a49f1bbc3dcb38a Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 19 Jun 2025 21:18:56 +0100 Subject: [PATCH 1/6] Tests: GitHub Actions: Use specific `codeception.github.yml` --- .github/workflows/tests.yml | 4 ++-- codeception.dist.yml => codeception.github.yml | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename codeception.dist.yml => codeception.github.yml (100%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8280d03a7..d2ae3f744 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -321,12 +321,12 @@ jobs: - name: Run tests/wpunit if: ${{ matrix.php-versions == '8.3' && matrix.test-groups == 'EndToEnd/tags' }} working-directory: ${{ env.PLUGIN_DIR }} - run: php vendor/bin/codecept run tests/Integration --fail-fast + run: php vendor/bin/codecept run tests/Integration -c codeception.github.yml --fail-fast # Run Codeception End to End Tests - name: Run tests/${{ matrix.test-groups }} working-directory: ${{ env.PLUGIN_DIR }} - run: php vendor/bin/codecept run tests/${{ matrix.test-groups }} --fail-fast + run: php vendor/bin/codecept run tests/${{ matrix.test-groups }} -c codeception.github.yml --fail-fast # Artifacts are data generated by this workflow that we want to access, such as log files, screenshots, HTML output. # The if: failure() directive means that this will run when the workflow fails e.g. if a test fails, which is needed diff --git a/codeception.dist.yml b/codeception.github.yml similarity index 100% rename from codeception.dist.yml rename to codeception.github.yml From 22b9661a2cde604193fcc1d8fc1bd86549a649db Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Fri, 20 Jun 2025 02:00:38 +0400 Subject: [PATCH 2/6] Tests: Bulid: Use specified yml file --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d2ae3f744..1c65ac8e4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -314,7 +314,7 @@ jobs: # Build Codeception Tests. - name: Build Tests working-directory: ${{ env.PLUGIN_DIR }} - run: php vendor/bin/codecept build + run: php vendor/bin/codecept build -c codeception.github.yml # Run Codeception Integration Tests on the PHP 8.3 instance before the EndToEnd/tags End to End tests. # We run these once to avoid hitting API rate limits. From 8d678b3ffdc1e924e8b59f2d88e9b8dd94dcf43e Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 23 Jun 2025 12:08:39 +0800 Subject: [PATCH 3/6] Move configuration flag --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1c65ac8e4..e1b93facf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -321,12 +321,12 @@ jobs: - name: Run tests/wpunit if: ${{ matrix.php-versions == '8.3' && matrix.test-groups == 'EndToEnd/tags' }} working-directory: ${{ env.PLUGIN_DIR }} - run: php vendor/bin/codecept run tests/Integration -c codeception.github.yml --fail-fast + run: php vendor/bin/codecept run -c codeception.github.yml tests/Integration --fail-fast # Run Codeception End to End Tests - name: Run tests/${{ matrix.test-groups }} working-directory: ${{ env.PLUGIN_DIR }} - run: php vendor/bin/codecept run tests/${{ matrix.test-groups }} -c codeception.github.yml --fail-fast + run: php vendor/bin/codecept run -c codeception.github.yml tests/${{ matrix.test-groups }} --fail-fast # Artifacts are data generated by this workflow that we want to access, such as log files, screenshots, HTML output. # The if: failure() directive means that this will run when the workflow fails e.g. if a test fails, which is needed From 26571b347e11ba9313230e698436f91a79a20967 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 23 Jun 2025 12:11:51 +0800 Subject: [PATCH 4/6] Tests: Provide full path to configuration file --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e1b93facf..c129ec4b5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -314,19 +314,19 @@ jobs: # Build Codeception Tests. - name: Build Tests working-directory: ${{ env.PLUGIN_DIR }} - run: php vendor/bin/codecept build -c codeception.github.yml + run: php vendor/bin/codecept build -c ${{ env.PLUGIN_DIR }}/codeception.github.yml # Run Codeception Integration Tests on the PHP 8.3 instance before the EndToEnd/tags End to End tests. # We run these once to avoid hitting API rate limits. - name: Run tests/wpunit if: ${{ matrix.php-versions == '8.3' && matrix.test-groups == 'EndToEnd/tags' }} working-directory: ${{ env.PLUGIN_DIR }} - run: php vendor/bin/codecept run -c codeception.github.yml tests/Integration --fail-fast + run: php vendor/bin/codecept run -c ${{ env.PLUGIN_DIR }}/codeception.github.yml tests/Integration --fail-fast # Run Codeception End to End Tests - name: Run tests/${{ matrix.test-groups }} working-directory: ${{ env.PLUGIN_DIR }} - run: php vendor/bin/codecept run -c codeception.github.yml tests/${{ matrix.test-groups }} --fail-fast + run: php vendor/bin/codecept run -c ${{ env.PLUGIN_DIR }}/codeception.github.yml tests/${{ matrix.test-groups }} --fail-fast # Artifacts are data generated by this workflow that we want to access, such as log files, screenshots, HTML output. # The if: failure() directive means that this will run when the workflow fails e.g. if a test fails, which is needed From 55d476e13c23c56b4c4da823747fa51112b9c8e7 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 23 Jun 2025 12:44:38 +0800 Subject: [PATCH 5/6] Write secrets to .env.testing; include .env.testing in codeception.dist.yml params --- .github/workflows/tests.yml | 15 ++++++--------- codeception.github.yml => codeception.dist.yml | 3 ++- 2 files changed, 8 insertions(+), 10 deletions(-) rename codeception.github.yml => codeception.dist.yml (95%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c129ec4b5..da1d50587 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -253,15 +253,12 @@ jobs: echo "CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA=$access_token" >> $GITHUB_ENV echo "CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA=$refresh_token" >> $GITHUB_ENV - # Write any secrets, such as API keys, to the .env.dist.testing file now. - # Make sure your committed .env.dist.testing file ends with a newline. - # The formatting of the contents to include a blank newline is deliberate. + # Write any secrets, such as API keys, to the .env.testing file now. - name: Define GitHub Secrets in .env.dist.testing uses: DamianReeves/write-file-action@v1.3 with: - path: ${{ env.PLUGIN_DIR }}/.env.dist.testing + path: ${{ env.PLUGIN_DIR }}/.env.testing contents: | - CONVERTKIT_API_KEY=${{ env.CONVERTKIT_API_KEY }} CONVERTKIT_API_SECRET=${{ env.CONVERTKIT_API_SECRET }} CONVERTKIT_API_KEY_NO_DATA=${{ env.CONVERTKIT_API_KEY_NO_DATA }} @@ -278,7 +275,7 @@ jobs: CONVERTKIT_API_RECAPTCHA_SITE_KEY=${{ env.CONVERTKIT_API_RECAPTCHA_SITE_KEY }} CONVERTKIT_API_RECAPTCHA_SECRET_KEY=${{ env.CONVERTKIT_API_RECAPTCHA_SECRET_KEY }} - write-mode: append + write-mode: overwrite # Installs wp-browser, Codeception, PHP CodeSniffer and anything else needed to run tests. - name: Run Composer @@ -314,19 +311,19 @@ jobs: # Build Codeception Tests. - name: Build Tests working-directory: ${{ env.PLUGIN_DIR }} - run: php vendor/bin/codecept build -c ${{ env.PLUGIN_DIR }}/codeception.github.yml + run: php vendor/bin/codecept build # Run Codeception Integration Tests on the PHP 8.3 instance before the EndToEnd/tags End to End tests. # We run these once to avoid hitting API rate limits. - name: Run tests/wpunit if: ${{ matrix.php-versions == '8.3' && matrix.test-groups == 'EndToEnd/tags' }} working-directory: ${{ env.PLUGIN_DIR }} - run: php vendor/bin/codecept run -c ${{ env.PLUGIN_DIR }}/codeception.github.yml tests/Integration --fail-fast + run: php vendor/bin/codecept run tests/Integration --fail-fast # Run Codeception End to End Tests - name: Run tests/${{ matrix.test-groups }} working-directory: ${{ env.PLUGIN_DIR }} - run: php vendor/bin/codecept run -c ${{ env.PLUGIN_DIR }}/codeception.github.yml tests/${{ matrix.test-groups }} --fail-fast + run: php vendor/bin/codecept run tests/${{ matrix.test-groups }} --fail-fast # Artifacts are data generated by this workflow that we want to access, such as log files, screenshots, HTML output. # The if: failure() directive means that this will run when the workflow fails e.g. if a test fails, which is needed diff --git a/codeception.github.yml b/codeception.dist.yml similarity index 95% rename from codeception.github.yml rename to codeception.dist.yml index 0cfedfc1d..5660ac453 100644 --- a/codeception.github.yml +++ b/codeception.dist.yml @@ -24,4 +24,5 @@ extensions: - lucatume\WPBrowser\Command\DevRestart - lucatume\WPBrowser\Command\ChromedriverUpdate params: - - .env.dist.testing \ No newline at end of file + - .env.dist.testing + - .env.testing \ No newline at end of file From 054238aaa411c039668d21fd39f8a37a335e41e9 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 23 Jun 2025 13:01:00 +0800 Subject: [PATCH 6/6] Update .env.example and setup guide --- .env.example | 82 ++++------------------------------------------------ SETUP.md | 22 +++++--------- 2 files changed, 12 insertions(+), 92 deletions(-) diff --git a/.env.example b/.env.example index c01e94b07..e63441941 100644 --- a/.env.example +++ b/.env.example @@ -1,37 +1,10 @@ -# The path to the WordPress root directory, the one containing the wp-load.php file. -# This can be a relative path from the directory that contains the codeception.yml file, -# or an absolute path. -WORDPRESS_ROOT_DIR=/var/www/html +# Local site path +WORDPRESS_ROOT_DIR="/Users/tim/Local Sites/convertkit-github/app/public" -# Tests will require a MySQL database to run. -# The database will be created if it does not exist. -# Do not use a database that contains important data! -WORDPRESS_DB_URL=mysql://root:root@localhost:3306/test +# Local site URL +WORDPRESS_URL=http://kit.local -# The Integration suite will use this table prefix for the WordPress tables. -TEST_TABLE_PREFIX=wp_ - -# This table prefix used by the WordPress site in end-to-end tests. -WORDPRESS_TABLE_PREFIX=wp_ - -# The URL and domain of the WordPress site used in end-to-end tests. -WORDPRESS_URL=http://127.0.0.1 -WORDPRESS_DOMAIN=127.0.0.1 -WORDPRESS_ADMIN_PATH=/wp-admin - -# The username and password of the administrator user of the WordPress site used in end-to-end tests. -WORDPRESS_ADMIN_USER=admin -WORDPRESS_ADMIN_PASSWORD=password - -# The host and port of the ChromeDriver server that will be used in end-to-end tests. -CHROMEDRIVER_HOST=localhost -CHROMEDRIVER_PORT=9515 - -# The user agents used in end-to-end tests. -TEST_SITE_HTTP_USER_AGENT=HeadlessChrome -TEST_SITE_HTTP_USER_AGENT_MOBILE=HeadlessChromeMobile - -# Kit specific variables +# Kit credentials CONVERTKIT_OAUTH_ACCESS_TOKEN= CONVERTKIT_OAUTH_REFRESH_TOKEN= CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA= @@ -45,50 +18,5 @@ CONVERTKIT_API_KEY= CONVERTKIT_API_SECRET= CONVERTKIT_API_SIGNED_SUBSCRIBER_ID= CONVERTKIT_API_SIGNED_SUBSCRIBER_ID_NO_ACCESS= -CONVERTKIT_API_SUBSCRIBER_EMAIL="optin@n7studios.com" -CONVERTKIT_API_SUBSCRIBER_ID="1579118532" -CONVERTKIT_API_SUBSCRIBER_ID_NO_ACCESS="1632998602" CONVERTKIT_API_RECAPTCHA_SITE_KEY= CONVERTKIT_API_RECAPTCHA_SECRET_KEY= -CONVERTKIT_API_FORM_NAME="Page Form [inline]" -CONVERTKIT_API_FORM_ID="2765139" -CONVERTKIT_API_FORM_FORMAT_MODAL_NAME="Modal Form [modal]" -CONVERTKIT_API_FORM_FORMAT_MODAL_NAME_ONLY="Modal Form" -CONVERTKIT_API_FORM_FORMAT_MODAL_ID="2780977" -CONVERTKIT_API_FORM_FORMAT_MODAL_URL="https://cheerful-architect-3237.kit.com/397e876257" -CONVERTKIT_API_FORM_FORMAT_SLIDE_IN_NAME="Slide In Form [slide in]" -CONVERTKIT_API_FORM_FORMAT_SLIDE_IN_NAME_ONLY="Slide In Form" -CONVERTKIT_API_FORM_FORMAT_SLIDE_IN_ID="2780979" -CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_NAME="Sticky Bar Form [sticky bar]" -CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_NAME_ONLY="Sticky Bar Form" -CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID="2780980" -CONVERTKIT_API_LANDING_PAGE_NAME="Landing Page" -CONVERTKIT_API_LANDING_PAGE_ID="2765196" -CONVERTKIT_API_LANDING_PAGE_CHARACTER_ENCODING_NAME="Character Encoding" -CONVERTKIT_API_LEGACY_FORM_NAME="Legacy Form" -CONVERTKIT_API_LEGACY_FORM_ID="470099" -CONVERTKIT_API_LEGACY_FORM_SHORTCODE="[convertkit form=5281783]" -CONVERTKIT_API_LEGACY_LANDING_PAGE_NAME="Legacy Landing Page" -CONVERTKIT_API_LEGACY_LANDING_PAGE_ID="470103" -CONVERTKIT_API_LEGACY_LANDING_PAGE_URL="https://app.kit.com/landing_pages/470103" -CONVERTKIT_API_PRODUCT_NAME="Newsletter Subscription" -CONVERTKIT_API_PRODUCT_ID="36377" -CONVERTKIT_API_PRODUCT_URL="https://cheerful-architect-3237.kit.com/products/newsletter-subscription" -CONVERTKIT_API_PRODUCT_DISCOUNT_CODE=B7G96H637H -CONVERTKIT_API_SEQUENCE_NAME="WordPress Sequence" -CONVERTKIT_API_SEQUENCE_ID="1030824" -CONVERTKIT_API_TAG_NAME="wordpress" -CONVERTKIT_API_TAG_ID="2744672" -CONVERTKIT_API_THIRD_PARTY_INTEGRATIONS_FORM_NAME="Third Party Integrations Form [inline]" -CONVERTKIT_API_THIRD_PARTY_INTEGRATIONS_FORM_ID="3003590" -CONVERTKIT_API_COMMERCE_JS_URL="https://cheerful-architect-3237.kit.com/commerce.js" -CONVERTKIT_API_BROADCAST_ID=3175837 -CONVERTKIT_API_BROADCAST_FIRST_URL="https://cheerful-architect-3237.kit.com/posts/html-template-test" -CONVERTKIT_API_BROADCAST_FIRST_TITLE="HTML Template Test" -CONVERTKIT_API_BROADCAST_FIRST_DATE="2023-08-02T16:34:51.000Z" -CONVERTKIT_API_BROADCAST_FIRST_DESCRIPTION="This is a sample meta description." -CONVERTKIT_API_BROADCAST_SECOND_URL="https://cheerful-architect-3237.kit.com/posts/paid-subscriber-broadcast" -CONVERTKIT_API_BROADCAST_SECOND_TITLE="Paid Subscriber Broadcast" -CONVERTKIT_API_BROADCAST_THIRD_URL="https://cheerful-architect-3237.kit.com/posts/test-subject" -CONVERTKIT_API_BROADCAST_THIRD_TITLE="Test Subject" -CONVERTKIT_API_BROADCAST_COUNT=5 diff --git a/SETUP.md b/SETUP.md index 8d35ab361..fe69030f2 100644 --- a/SETUP.md +++ b/SETUP.md @@ -58,17 +58,9 @@ Create a blank `test` database in MySQL, with a MySQL user who can read and writ ### Configure Testing Environment -Copy the `.env.example` file to `.env.testing` in the root of this repository, changing folder and database credentials as necessary. +Copy the `.env.example` file to `.env.testing` in the root of this repository, changing parameters to match your local development environment as necessary. -### Codeception - -Create a `codeception.yml` file in the root of the repository, with the following contents: -```yaml -params: - - .env.testing -``` - -This tells Codeception to read the above `.env.testing` file when testing on the local development enviornment. +You'll also want to include Kit credentials, such as API Keys and OAuth tokens here. `.env.testing` is excluded from Git, to ensure these sensitive credentials are not stored in version control. ### Install Packages @@ -135,21 +127,21 @@ chromedriver --url-base=/wd/hub ![ChromeDriver Screenshot](/.github/docs/chromedriver.png?raw=true) -In a second Terminal window, in the Plugin's directory, build and run the tests to make sure there are no errors and that you have +In a second Terminal window, in the Plugin's directory, build and run the a test to make sure there are no errors and that you have correctly setup your environment: ```bash vendor/bin/codecept build -vendor/bin/codecept run EndToEnd -vendor/bin/codecept run Integration +vendor/bin/codecept run EndToEnd general/other/ActivateDeactivatePluginCest --fail-fast +vendor/bin/codecept run Integration APITest:testAccessTokenRefreshedAndSavedWhenExpired --fail-fast ``` ![Codeception Test Results](/.github/docs/codeception.png?raw=true) Don't worry if you don't understand these commands; if your output looks similar to the above screenshot, and no test is prefixed with `E`, -your environment is setup successfully. +your environment is setup successfully. Our [Testing Guide](TESTING.md) covers this in more detail. -### Running CodeSniffer +### Running PHP CodeSniffer In the Plugin's directory, run the following command to run PHP_CodeSniffer, which will check the code meets WordPress' Coding Standards: