diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..c32440d --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,59 @@ +version: 2 +workflows: + version: 2 + main: + jobs: + - build + nightly: + triggers: + - schedule: + cron: "0 0 * * *" + filters: + branches: + only: + - master + jobs: + - build +jobs: + build: + working_directory: ~/pantheon-systems/pantheon-hud + parallelism: 1 + docker: + - image: circleci/php:7.1 + steps: + - checkout + - run: echo $(openssl rand -hex 8) > /tmp/WORDPRESS_ADMIN_PASSWORD + - run: | + echo 'export PATH=/tmp/terminus/bin:$PATH' >> $BASH_ENV + echo 'export TERMINUS_ENV=ci-$CIRCLE_BUILD_NUM' >> $BASH_ENV + echo 'export TERMINUS_SITE=pantheon-hud' >> $BASH_ENV + echo 'export SITE_ENV=pantheon-hud.ci-$CIRCLE_BUILD_NUM' >> $BASH_ENV + echo 'export WORDPRESS_ADMIN_USERNAME=pantheon' >> $BASH_ENV + echo 'export WORDPRESS_ADMIN_EMAIL=no-reply@getpantheon.com' >> $BASH_ENV + echo 'export WORDPRESS_ADMIN_PASSWORD=$(cat /tmp/WORDPRESS_ADMIN_PASSWORD)' >> $BASH_ENV + source $BASH_ENV + - run: echo "StrictHostKeyChecking no" >> "$HOME/.ssh/config" + - run: | + sudo apt-get update + sudo apt-get install -y rsync + - run: | + if [ -z "$GITHUB_TOKEN" ]; then + echo "GITHUB_TOKEN environment variables missing; assuming unauthenticated build" + exit 0 + fi + echo "Setting GitHub OAuth token with suppressed ouput" + { + composer config -g github-oauth.github.com $GITHUB_TOKEN + } &> /dev/null + - run: | + if [ -z "$TERMINUS_TOKEN" ]; then + echo "TERMINUS_TOKEN environment variables missing; assuming unauthenticated build" + exit 0 + fi + composer install + git clone --branch master https://github.com/pantheon-systems/terminus.git /tmp/terminus + cd /tmp/terminus && composer install + terminus auth:login --machine-token=$TERMINUS_TOKEN + - run: ./bin/behat-prepare.sh + - run: ./bin/behat-test.sh --strict + - run: ./bin/behat-cleanup.sh diff --git a/behat.yml b/behat.yml new file mode 100644 index 0000000..6f66839 --- /dev/null +++ b/behat.yml @@ -0,0 +1,22 @@ +# behat.yml +default: + suites: + default: + paths: + - tests/behat + contexts: + - Behat\MinkExtension\Context\MinkContext + - PantheonSystems\PantheonWordPressUpstreamTests\Behat\AdminLogIn + core: + filters: + tags: "~@upstreamonly" + paths: + - vendor/pantheon-systems/pantheon-wordpress-upstream-tests/features + contexts: + - Behat\MinkExtension\Context\MinkContext + - PantheonSystems\PantheonWordPressUpstreamTests\Behat\AdminLogIn + - PantheonSystems\PantheonWordPressUpstreamTests\Behat\ResponseHeader + extensions: + Behat\MinkExtension: + # base_url set by ENV + goutte: ~ diff --git a/bin/behat-cleanup.sh b/bin/behat-cleanup.sh new file mode 100755 index 0000000..99f6d8e --- /dev/null +++ b/bin/behat-cleanup.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +### +# Delete the Pantheon site environment after the Behat test suite has run. +### + +terminus whoami > /dev/null +if [ $? -ne 0 ]; then + echo "Terminus unauthenticated; assuming unauthenticated build" + exit 0 +fi + +set -ex + +if [ -z "$TERMINUS_SITE" ] || [ -z "$TERMINUS_ENV" ]; then + echo "TERMINUS_SITE and TERMINUS_ENV environment variables must be set" + exit 1 +fi + +### +# Delete the environment used for this test run. +### +terminus multidev:delete $SITE_ENV --delete-branch --yes diff --git a/bin/behat-prepare.sh b/bin/behat-prepare.sh new file mode 100755 index 0000000..e3363e2 --- /dev/null +++ b/bin/behat-prepare.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +### +# Prepare a Pantheon site environment for the Behat test suite, by installing +# and configuring the plugin for the environment. This script is architected +# such that it can be run a second time if a step fails. +### + +terminus whoami > /dev/null +if [ $? -ne 0 ]; then + echo "Terminus unauthenticated; assuming unauthenticated build" + exit 0 +fi + +if [ -z "$TERMINUS_SITE" ] || [ -z "$TERMINUS_ENV" ]; then + echo "TERMINUS_SITE and TERMINUS_ENV environment variables must be set" + exit 1 +fi + +if [ -z "$WORDPRESS_ADMIN_USERNAME" ] || [ -z "$WORDPRESS_ADMIN_PASSWORD" ]; then + echo "WORDPRESS_ADMIN_USERNAME and WORDPRESS_ADMIN_PASSWORD environment variables must be set" + exit 1 +fi + +set -ex + +### +# Create a new environment for this particular test run. +### +terminus env:create $TERMINUS_SITE.dev $TERMINUS_ENV +terminus env:wipe $SITE_ENV --yes + +### +# Get all necessary environment details. +### +PANTHEON_GIT_URL=$(terminus connection:info $SITE_ENV --field=git_url) +PANTHEON_SITE_URL="$TERMINUS_ENV-$TERMINUS_SITE.pantheonsite.io" +PREPARE_DIR="/tmp/$TERMINUS_ENV-$TERMINUS_SITE" +BASH_DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +### +# Switch to git mode for pushing the files up +### +terminus connection:set $SITE_ENV git +rm -rf $PREPARE_DIR +git clone -b $TERMINUS_ENV $PANTHEON_GIT_URL $PREPARE_DIR + +### +# Add the copy of this plugin itself to the environment +### +rm -rf $PREPARE_DIR/wp-content/plugins/pantheon-hud +cd $BASH_DIR/.. +rsync -av --exclude='vendor/' --exclude='node_modules/' --exclude='tests/' ./* $PREPARE_DIR/wp-content/plugins/pantheon-hud +rm -rf $PREPARE_DIR/wp-content/plugins/pantheon-hud/.git + +# Download the latest Classic Editor release from WordPress.org +wget -O $PREPARE_DIR/classic-editor.zip https://downloads.wordpress.org/plugin/classic-editor.zip +unzip $PREPARE_DIR/classic-editor.zip -d $PREPARE_DIR +mv $PREPARE_DIR/classic-editor $PREPARE_DIR/wp-content/plugins/ +rm $PREPARE_DIR/classic-editor.zip + +### +# Push files to the environment +### +cd $PREPARE_DIR +git add wp-content +git config user.email "pantheon-hud@getpantheon.com" +git config user.name "Pantheon" +git commit -m "Include Pantheon HUD and its configuration files" +git push + +### +# Set up WordPress, theme, and plugins for the test run +### +# Silence output so as not to show the password. +{ + terminus wp $SITE_ENV -- core install --title=$TERMINUS_ENV-$TERMINUS_SITE --url=$PANTHEON_SITE_URL --admin_user=$WORDPRESS_ADMIN_USERNAME --admin_email=pantheon-hud@getpantheon.com --admin_password=$WORDPRESS_ADMIN_PASSWORD +} &> /dev/null +terminus wp $SITE_ENV -- cache flush +terminus wp $SITE_ENV -- plugin activate pantheon-hud classic-editor +terminus wp $SITE_ENV -- theme activate twentyseventeen +terminus wp $SITE_ENV -- rewrite structure '/%year%/%monthnum%/%day%/%postname%/' diff --git a/bin/behat-test.sh b/bin/behat-test.sh new file mode 100755 index 0000000..eaf7dad --- /dev/null +++ b/bin/behat-test.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +### +# Execute the Behat test suite against a prepared Pantheon site environment. +### + +terminus whoami > /dev/null +if [ $? -ne 0 ]; then + echo "Terminus unauthenticated; assuming unauthenticated build" + exit 0 +fi + +if [ -z "$TERMINUS_SITE" ] || [ -z "$TERMINUS_ENV" ]; then + echo "TERMINUS_SITE and TERMINUS_ENV environment variables must be set" + exit 1 +fi + +if [ -z "$WORDPRESS_ADMIN_USERNAME" ] || [ -z "$WORDPRESS_ADMIN_PASSWORD" ]; then + echo "WORDPRESS_ADMIN_USERNAME and WORDPRESS_ADMIN_PASSWORD environment variables must be set" + exit 1 +fi + +set -ex + +export BEHAT_PARAMS='{"extensions" : {"Behat\\MinkExtension" : {"base_url" : "http://'$TERMINUS_ENV'-'$TERMINUS_SITE'.pantheonsite.io"} }}' + +./vendor/bin/behat "$@" diff --git a/tests/behat/pantheon-hud.feature b/tests/behat/pantheon-hud.feature new file mode 100644 index 0000000..0bcf972 --- /dev/null +++ b/tests/behat/pantheon-hud.feature @@ -0,0 +1,11 @@ +Feature: Solr Power plugin + + Background: + Given I log in as an admin + + Scenario: Plugin is loaded + When I go to "/wp-admin/" + Then the "#wp-admin-bar-pantheon-hud" element should contain "pantheon-hud.pantheonsite.io" + And the "#wp-admin-bar-pantheon-hud" element should contain "1 app container running PHP" + And the "#wp-admin-bar-pantheon-hud" element should contain "1 db container with replication disabled" + And the "#wp-admin-bar-pantheon-hud" element should contain "Visit Pantheon Dashboard"