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/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8280d03a7..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 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: diff --git a/codeception.dist.yml b/codeception.dist.yml index 0cfedfc1d..5660ac453 100644 --- a/codeception.dist.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