Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Events Virtual Support. #53

Merged
merged 12 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions .env.dist

This file was deleted.

34 changes: 34 additions & 0 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# WordPress admin configurations
[email protected]
ADMIN_USERNAME=admin
ADMIN_PASSWORD=password
ADMIN_PATH=/wp-admin

# WordPress location configurations
WP_CORE_DIR=local/public
PLUGINS_DIR=
MUPLUGINS_DIR=
THEMES_DIR=

# WordPress database configurations
WP_TEST_DB_NAME=wordpress
WP_TEST_DB_HOST=mysql
WP_TEST_DB_PORT=3306
WP_TEST_DB_USER=wordpress
WP_TEST_DB_PASSWORD=password
ROOT_PASSWORD=password
WP_TABLE_PREFIX=wp_
SKIP_DB_CREATE=true
SKIP_WP_SETUP=true

# Extra environmental variables/constants.
GRAPHQL_JWT_AUTH_SECRET_KEY=testingtesting123

WP_ROOT_FOLDER=local/public

# Codeception params.
TESTS_DIR=tests
TESTS_OUTPUT=tests/_output
TESTS_DATA=tests/_data
TESTS_SUPPORT=tests/_support
TESTS_ENVS=tests/_envs
70 changes: 70 additions & 0 deletions .github/workflows/tests-php-alt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Automated-Testing

on:
schedule:
- cron: '0 4 * * 5'
push:
branches:
- master
pull_request:
branches:
- master
paths:
- '**.php'
- '!docs/**'

jobs:
Automated-Testing:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.1', '8.0', '7.4']
wordpress: ['6.1', '5.9', '5.6']
composer_version: ['v2']
include:
- php: '7.4'
wordpress: '5.9'
coverage: '--coverage --coverage-xml'
xdebug: 1
- php: '8.1'
wordpress: '5.6'
debug: '--debug'

fail-fast: false
name: WordPress ${{ matrix.wordpress }} on PHP ${{ matrix.php }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: json, mbstring
tools: composer:v2
env:
GITHUB_TOKEN: ${{ secrets.COMPOSER_TOKEN }}


- name: Install dependencies
run: |
cp .env.testing .env
rm -rf composer.lock
composer install
SKIP_DB_CREATE=true SKIP_WP_SETUP=true composer install-test-env

- name: Run Tests w/ Docker.
env:
USING_XDEBUG: ${{ matrix.xdebug }}
WP_VERSION: ${{ matrix.wordpress }}
PHP_VERSION: ${{ matrix.php }}

run: composer run-codeception -- ${{ matrix.coverage }} ${{ matrix.debug }}

- name: Push Codecoverage to Coveralls.io
if: ${{ matrix.coverage == '--coverage --coverage-xml' }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer global require php-coveralls/php-coveralls
php-coveralls -v
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ node_modules/
*.zip
.env
.env.*
!.env.dist
!.env.testing
.idea
.vscode
.github_changelog_generator
Expand Down
60 changes: 18 additions & 42 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,49 +1,25 @@
############################################################################
# Container for running Codeception tests on a WooGraphQL Docker instance. #
############################################################################
ARG PHP_VERSION=7.4

# Using the 'DESIRED_' prefix to avoid confusion with environment variables of the same name.
ARG DESIRED_WP_VERSION
ARG DESIRED_PHP_VERSION
FROM wordpress:php${PHP_VERSION}-apache

FROM kidunot89/ql-events-app:wp${DESIRED_WP_VERSION}-php${DESIRED_PHP_VERSION}
ARG XDEBUG_VERSION=2.9.6

RUN apt-get update; \
apt-get install -y --no-install-recommends \
# WP-CLI dependencies.
bash less default-mysql-client git \
# MailHog dependencies.
msmtp;

LABEL author=kidunot89
LABEL author_uri=https://github.com/kidunot89
COPY local/php.ini /usr/local/etc/php/php.ini

SHELL [ "/bin/bash", "-c" ]
# Setup xdebug. The latest version supported by PHP 5.6 is 2.5.5.
RUN pecl install "xdebug-${XDEBUG_VERSION}"; \
docker-php-ext-enable xdebug

ARG DESIRED_WP_VERSION
ARG DESIRED_PHP_VERSION
# Install PDO MySQL driver.
RUN docker-php-ext-install \
pdo_mysql

# Install php extensions
RUN docker-php-ext-install pdo_mysql

# Install Xdebug
RUN if [ "$DESIRED_PHP_VERSION" == "5.6" ]; then yes | pecl install xdebug-2.5.5; else yes | pecl install xdebug; fi \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini

# Install composer
ENV COMPOSER_ALLOW_SUPERUSER=1

RUN curl -sS https://getcomposer.org/installer | php -- \
--filename=composer \
--install-dir=/usr/local/bin

# Add composer global binaries to PATH
ENV PATH "$PATH:~/.composer/vendor/bin"

# Configure php
RUN echo "date.timezone = UTC" >> /usr/local/etc/php/php.ini

# Remove exec statement from base entrypoint script.
RUN sed -i '$d' /usr/local/bin/app-entrypoint.sh

# Set up entrypoint
WORKDIR /var/www/html/wp-content/plugins/ql-events
COPY bin/testing-entrypoint.sh /usr/local/bin/testing-entrypoint.sh
RUN chmod 755 /usr/local/bin/testing-entrypoint.sh
ENTRYPOINT ["testing-entrypoint.sh"]
ADD https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh /usr/local/bin/wait_for_it
RUN chmod 755 /usr/local/bin/wait_for_it
99 changes: 48 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,72 @@
# QL Events
[![Codeception Tests](https://github.com/the-events-calendar/ql-events/actions/workflows/tests-php.yml/badge.svg)](https://github.com/the-events-calendar/ql-events/actions/workflows/tests-php.yml)
[![Coding-Standards](https://github.com/the-events-calendar/ql-events/actions/workflows/lint.yml/badge.svg)](https://github.com/the-events-calendar/ql-events/actions/workflows/lint.yml)

[![Automated-Testing](https://github.com/the-events-calendar/ql-events/actions/workflows/tests-php-alt.yml/badge.svg)](https://github.com/the-events-calendar/ql-events/actions/workflows/tests-php-alt.yml) [![Coding-Standards](https://github.com/the-events-calendar/ql-events/actions/workflows/lint.yml/badge.svg)](https://github.com/the-events-calendar/ql-events/actions/workflows/lint.yml)

## Quick Install

1. Install & activate [The Events Calendar/The Events Calendar Pro](https://theeventscalendar.com/)
- (Optional) Install & activate [Ticket Events/Ticket Events Plus](https://theeventscalendar.com/products/wordpress-event-tickets/)
2. Install & activate [WPGraphQL](https://www.wpgraphql.com/)
- (Optional) Install & activate [WPGraphQL-JWT-Authentication](https://github.com/wp-graphql/wp-graphql-jwt-authentication) to add a `login` mutation that returns a JSON Web Token.
3. Clone or download the zip of this repository into your WordPress plugin directory & activate the **QL Events** plugin

## What does this plugin do?

It adds *The Events Calendar*'s and some of it's extension's functionality to the WPGraphQL schema.

## Unit Tests

Until the documentation is in full effect, it's recommended that a [GraphiQL](https://github.com/graphql/graphiql)-based tool like [WPGraphiQL](https://github.com/wp-graphql/wp-graphiql) be used to view the GraphQL schema, an alternative to this is viewing the unit tests located in `tests/wpunit` directory. Which are constantly updated along with the project. If you're interested in contributing when I begin accepting contribution or simply want to run the tests. Follow the instruction below.

### Prerequisties

- Shell/CMD access
- [Composer](https://getcomposer.org/)
- [WP-CLI](https://wp-cli.org/)

### Setup

1. Make sure all dependencies are install by running `composer install` from the CMD/Terminal in the project directory.
2. Next the copy 5 distributed files with the `.dist` in there filenames. For instance `.env.dist` becomes `.env` and `wpunit.suite.dist.yml` becomes `wpunit.suite.yml`. The distributed files and what their copied names should are as follows.
- `tests/acceptance.suite.dist.yml` => `tests/acceptance.suite.yml`
- `tests/functional.suite.dist.yml` => `tests/functional.suite.yml`
- `tests/wpunit.suite.dist.yml` => `tests/wpunit.suite.yml`
2. Next the copy 5 distributed files with the `.dist` in there filenames. For instance `.env.testing` becomes `.env` and `wpunit.suite.dist.yml` becomes `wpunit.suite.yml`. The distributed files and what their copied names should are as follows.
- `codeception.dist.yml` => `codeception.yml`
- `.env.dist` => `.env`
- `.env.testing` => `.env`
3. Next open `.env` and alter to make you usage.
```
DB_NAME=wordpress
DB_HOST=app_db
DB_USER=wordpress
DB_PASSWORD=wordpress
WP_TABLE_PREFIX=wp_
WP_URL=http://localhost
WP_DOMAIN=localhost
[email protected]
ADMIN_USERNAME=admin
ADMIN_PASSWORD=password
ADMIN_PATH=/wp-admin

TEST_DB_NAME=ql_events_tests
TEST_DB_HOST=127.0.0.1
TEST_DB_USER=wordpress
TEST_DB_PASSWORD=wordpress
TEST_WP_TABLE_PREFIX=wp_

SKIP_DB_CREATE=false
TEST_WP_ROOT_FOLDER=/tmp/wordpress
[email protected]

TESTS_DIR=tests
TESTS_OUTPUT=tests/_output
TESTS_DATA=tests/_data
TESTS_SUPPORT=tests/_support
TESTS_ENVS=tests/_envs
```
- `Shared` variables are as the comment implies, variables shared in both the `install-wp-tests` script and the **Codeception** configuration. The variable names should tell you what they mean.
- `Install script` variables are specified to the `install-wp-tests` script, and most likely won't changed. I've listed their meaning below.
- `WP_VERSION` WordPress version used for testing
- `SKIP_DB_CREATE` Should database creation be skipped?
- `Codeception` variables are specified to the **Codeception** configuration. View the config files and Codeception's [Docs](https://codeception.com/docs/reference/Configuration#Suite-Configuration) for more info on them.

4. Once you have finish modifying the `.env` file. Run `composer install-wp-tests` from the project directory.
```bash
DB_NAME=wordpress
DB_HOST=app_db
DB_USER=wordpress
DB_PASSWORD=wordpress
WP_TABLE_PREFIX=wp_
WP_URL=http://localhost
WP_DOMAIN=localhost
[email protected]
ADMIN_USERNAME=admin
ADMIN_PASSWORD=password
ADMIN_PATH=/wp-admin

TEST_DB_NAME=ql_events_tests
TEST_DB_HOST=127.0.0.1
TEST_DB_USER=wordpress
TEST_DB_PASSWORD=wordpress
TEST_WP_TABLE_PREFIX=wp_

SKIP_DB_CREATE=false
TEST_WP_ROOT_FOLDER=/tmp/wordpress
[email protected]

TESTS_DIR=tests
TESTS_OUTPUT=tests/_output
TESTS_DATA=tests/_data
TESTS_SUPPORT=tests/_support
TESTS_ENVS=tests/_envs
```
- `Shared` variables are as the comment implies, variables shared in both the `install-wp-tests` script and the **Codeception** configuration. The variable names should tell you what they mean.
- `Install script` variables are specified to the `install-wp-tests` script, and most likely won't changed. I've listed their meaning below.
- `WP_VERSION` WordPress version used for testing
- `SKIP_DB_CREATE` Should database creation be skipped?
- `Codeception` variables are specified to the **Codeception** configuration. View the config files and Codeception's [Docs](https://codeception.com/docs/reference/Configuration#Suite-Configuration) for more info on them.

4. Once you have finish modifying the `.env` file. Run `composer install-test-env` from the project directory.
5. Upon success you can begin running the tests.

### Running tests
Expand All @@ -73,13 +75,8 @@ If you use the command with at least a `suite` specified, **Codeception** will r

To learn more about the usage of Codeception with WordPress view the [Documentation](https://codeception.com/for/wordpress)

## Functional and Acceptance Tests (Docker/Docker-Compose required)
It's possible to run functional and acceptance tests, but is very limited at the moment. The script docker entrypoint script runs all three suites (acceptance, functional, and wpunit) at once. This will change eventually, however as of right now, this is the limitation.

### Running tests
Even though the two suite use a Docker environment to run, the docker environment relies on a few environmental variables defined in `.env` and a volume source provided by the test install script.
0. Ensure that you can copy `.env.dist` to `.env`.
1. First you must run `composer install-wp-tests` to ensure the required dependencies are available.
2. Next run `docker-compose build` from the terminal in the project root directory, to build the docker image for test environment.
3. And now you're ready to run the tests. Running `docker-compose run --rm wpbrowser` does just that.
You can rerun the tests by simply repeating step 3.
0. Ensure that you can copy `.env.testing` to `.env`.
1. First you must run `composer install-test-env` to ensure the required dependencies are available.
2. Next run `composer run-codeception` to run the tests within a docker container.
26 changes: 26 additions & 0 deletions bin/_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set +u

if [[ -z "$WP_TEST_DB_NAME" ]]; then
echo "WP_TEST_DB_NAME not found"
print_usage_instruction
fi
DB_NAME="$WP_TEST_DB_NAME"
if [[ -z "$WP_TEST_DB_USER" ]]; then
echo "WP_TEST_DB_USER not found"
print_usage_instruction
fi
DB_USER="$WP_TEST_DB_USER"

DB_HOST=${WP_TEST_DB_HOST-localhost}
DB_PASS=${WP_TEST_DB_PASSWORD-""}
WP_VERSION=${WP_VERSION-6}
PROJECT_ROOT_DIR=$(pwd)
WP_CORE_DIR=${WP_CORE_DIR:-local/public}
PLUGINS_DIR=${PLUGINS_DIR:-"$WP_CORE_DIR/wp-content/plugins"}
MUPLUGINS_DIR=${MUPLUGINS_DIR:-"$WP_CORE_DIR/wp-content/mu-plugins"}
THEMES_DIR=${THEMES_DIR:-"$WP_CORE_DIR/wp-content/themes"}
SKIP_DB_CREATE=${SKIP_DB_CREATE-false}
COMPOSER_TOKEN=${COMPOSER_TOKEN}
COMPOSER_AUTH=${COMPOSER_AUTH:-"{\"github-oauth\": {\"github.com\": \"$COMPOSER_TOKEN\"} }"}
Loading