Skip to content

Add WP core tests

Add WP core tests #30

Workflow file for this run

name: CI
on:
push:
branches:
- automated-testing
pull_request:
jobs:
integration-tests:
runs-on: ubuntu-latest
services:
docker:
image: docker:19.03.12
options: --privileged
# Docker-in-Docker is available on GitHub Actions by default on ubuntu-latest runners.
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install docker-compose
run: |
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
- name: Set up Docker Compose
run: |
docker-compose -f .github/docker/docker-compose.yml up -d
#Debug, remove when working
- name: List Docker Containers
run: docker ps
- name: Print WordPress container logs
run: |
CONTAINER_ID=$(docker-compose -f .github/docker/docker-compose.yml ps -q wordpress)
docker logs "$CONTAINER_ID"
- name: Install SVN
run: |
sudo apt-get update && sudo apt-get install -y subversion && sudo rm -rf /var/lib/apt/lists/*
# Wait for WordPress to be fully up before running commands
- name: Wait for WordPress to be available
run: |
# Give the container extra time to initialize
echo "Initial wait for container initialization…"
sleep 5
echo "Executing verbose curl"
RESPONSE=$(curl -v --max-time 30 http://localhost:8000 || true)
echo "Response from curl:"
echo "$RESPONSE"
- name: Install WordPress via WP-CLI
run: |
CONTAINER_ID=$(docker-compose -f .github/docker/docker-compose.yml ps -q wordpress)
# Ensure WP-CLI is available inside the container.
docker exec $CONTAINER_ID bash -c "if ! command -v wp &> /dev/null; then \
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \
chmod +x wp-cli.phar && mv wp-cli.phar /usr/local/bin/wp; \
fi"
# Run WordPress install
docker-compose -f .github/docker/docker-compose.yml exec -T wordpress \
wp core install \
--url="http://localhost:8000" \
--title="GitHub Actions Test Site" \
--admin_user="admin" \
--admin_password="admin_password" \
--admin_email="admin@example.com" \
--skip-email \
--allow-root
# Copy plugin into container
- name: Copy Plugin into Container
run: |
CONTAINER_ID=$(docker-compose -f .github/docker/docker-compose.yml ps -q wordpress)
echo "Creating build folder..."
docker exec $CONTAINER_ID mkdir -p /var/www/html/wp-content/plugins/shortpixel-image-optimiser/build/
echo "Copying plugin files..."
docker cp build/shortpixel/ "$CONTAINER_ID":/var/www/html/wp-content/plugins/shortpixel-image-optimiser/build/
docker cp res "$CONTAINER_ID":/var/www/html/wp-content/plugins/shortpixel-image-optimiser/
docker cp class "$CONTAINER_ID":/var/www/html/wp-content/plugins/shortpixel-image-optimiser/
docker cp wp-shortpixel.php "$CONTAINER_ID":/var/www/html/wp-content/plugins/shortpixel-image-optimiser/
docker cp shortpixel-plugin.php "$CONTAINER_ID":/var/www/html/wp-content/plugins/shortpixel-image-optimiser/
docker cp readme.txt "$CONTAINER_ID":/var/www/html/wp-content/plugins/shortpixel-image-optimiser/
echo "Listing main plugin files:"
docker exec $CONTAINER_ID ls -alh /var/www/html/wp-content/plugins/shortpixel-image-optimiser/
# Activate the plugin using WP-CLI
- name: Activate Plugin via WP-CLI
run: |
CONTAINER_ID=$(docker-compose -f .github/docker/docker-compose.yml ps -q wordpress)
# Activate the plugin via WP-CLI (already installed above)
docker exec $CONTAINER_ID wp plugin activate shortpixel-image-optimiser --allow-root
# Setup WordPress tests
- name: Setup WordPress core tests
run: |
echo "Copying WordPress tests..."
mkdir -p /var/www/html/tests/
wp_version=$(wp core version); svn export --quiet --ignore-externals https://develop.svn.wordpress.org/$wp_version/tests/phpunit/includes/ /var/www/html/tests/includes/
ls -alh /var/www/html/tests/includes/
#Configure GH token to access the plugin-modules repo, which is private
- name: Configure GitHub OAuth for Composer
run: composer --version
# Run plugin tests
- name: Run Plugin Tests
run: |
# Example: running PHPUnit test suite located in /tests directory.
# Customize the following command based on your actual testing framework.
composer update --no-interaction --prefer-dist
#vendor/bin/phpunit --configuration phpunit.xml.dist
# Tear down Docker Compose
- name: Shut down Docker Compose
if: always()
run: docker-compose -f .github/docker/docker-compose.yml down