11#! /usr/bin/env bash
22
3+ if [[ ! -f " .env" ]]; then
4+ echo " No .env file was detected. .env.dist has been copied to .env"
5+ echo " Open the .env file and enter values to match your local environment"
6+ cp .env.dist .env
7+ fi
8+
39source .env
410
511print_usage_instruction () {
612 echo " Ensure that .env file exist in project root directory exists."
7- echo " And run the following 'composer install-wp-tests ' in the project root directory"
13+ echo " And run the following 'composer build-test ' in the project root directory"
814 exit 1
915}
1016
@@ -20,23 +26,17 @@ if [[ -z "$TEST_DB_USER" ]]; then
2026else
2127 DB_USER=$TEST_DB_USER
2228fi
23- if [[ -z " $TEST_DB_PASSWORD " ]]; then
24- DB_PASS=" "
25- else
26- DB_PASS=$TEST_DB_PASSWORD
27- fi
28- if [[ -z " $TEST_DB_HOST " ]]; then
29- DB_HOST=localhost
30- else
31- DB_HOST=$TEST_DB_HOST
32- fi
33- if [ -z " $SKIP_DB_CREATE " ]; then
34- SKIP_DB_CREATE=false
35- fi
3629
30+ DB_HOST=${TEST_DB_HOST-localhost}
31+ DB_PASS=${TEST_DB_PASSWORD-" " }
32+ WP_VERSION=${WP_VERSION-latest}
33+ TMPDIR=${TMPDIR-/ tmp}
34+ TMPDIR=$( echo $TMPDIR | sed -e " s/\/$//" )
35+ WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR / wordpress-tests-lib}
36+ WP_CORE_DIR=${TEST_WP_ROOT_FOLDER-$TMPDIR / wordpress/ }
3737PLUGIN_DIR=$( pwd)
38- WP_TESTS_DIR =${WP_TESTS_DIR- / tmp / wp-graphql-jwt-authentication / wordpress-tests-lib }
39- WP_CORE_DIR =${WP_CORE_DIR- / tmp / wp-graphql-jwt-authentication / wordpress / }
38+ DB_SERVE_NAME =${DB_SERVE_NAME-wpgatsby_serve }
39+ SKIP_DB_CREATE =${SKIP_DB_CREATE-false }
4040
4141download () {
4242 if [ ` which curl` ]; then
@@ -46,8 +46,19 @@ download() {
4646 fi
4747}
4848
49- if [[ $WP_VERSION =~ [0-9]+\. [0-9]+ (\. [0-9]+)? ]]; then
50- WP_TESTS_TAG=" tags/$WP_VERSION "
49+ if [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+\- (beta| RC)[0-9]+$ ]]; then
50+ WP_BRANCH=${WP_VERSION% \- * }
51+ WP_TESTS_TAG=" branches/$WP_BRANCH "
52+
53+ elif [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+$ ]]; then
54+ WP_TESTS_TAG=" branches/$WP_VERSION "
55+ elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0-9]+ ]]; then
56+ if [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0] ]]; then
57+ # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
58+ WP_TESTS_TAG=" tags/${WP_VERSION% ??} "
59+ else
60+ WP_TESTS_TAG=" tags/$WP_VERSION "
61+ fi
5162elif [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
5263 WP_TESTS_TAG=" trunk"
5364else
6172 fi
6273 WP_TESTS_TAG=" tags/$LATEST_VERSION "
6374fi
64-
6575set -ex
6676
6777install_wp () {
@@ -73,52 +83,39 @@ install_wp() {
7383 mkdir -p $WP_CORE_DIR
7484
7585 if [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
76- mkdir -p /tmp /wordpress-nightly
77- download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp /wordpress-nightly/wordpress-nightly.zip
78- unzip -q /tmp/ wordpress-nightly/wordpress-nightly.zip -d /tmp /wordpress-nightly/
79- mv /tmp /wordpress-nightly/wordpress/* $WP_CORE_DIR
86+ mkdir -p $TMPDIR /wordpress-nightly
87+ download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR /wordpress-nightly/wordpress-nightly.zip
88+ unzip -q $TMPDIR / wordpress-nightly/wordpress-nightly.zip -d $TMPDIR /wordpress-nightly/
89+ mv $TMPDIR /wordpress-nightly/wordpress/* $WP_CORE_DIR
8090 else
8191 if [ $WP_VERSION == ' latest' ]; then
8292 local ARCHIVE_NAME=' latest'
93+ elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+ ]]; then
94+ # https serves multiple offers, whereas http serves single.
95+ download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR /wp-latest.json
96+ if [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0] ]]; then
97+ # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
98+ LATEST_VERSION=${WP_VERSION% ??}
99+ else
100+ # otherwise, scan the releases and get the most up to date minor version of the major release
101+ local VERSION_ESCAPED=` echo $WP_VERSION | sed ' s/\./\\\\./g' `
102+ LATEST_VERSION=$( grep -o ' "version":"' $VERSION_ESCAPED ' [^"]*' $TMPDIR /wp-latest.json | sed ' s/"version":"//' | head -1)
103+ fi
104+ if [[ -z " $LATEST_VERSION " ]]; then
105+ local ARCHIVE_NAME=" wordpress-$WP_VERSION "
106+ else
107+ local ARCHIVE_NAME=" wordpress-$LATEST_VERSION "
108+ fi
83109 else
84110 local ARCHIVE_NAME=" wordpress-$WP_VERSION "
85111 fi
86- download https://wordpress.org/${ARCHIVE_NAME} .tar.gz /tmp /wordpress.tar.gz
87- tar --strip-components=1 -zxmf /tmp /wordpress.tar.gz -C $WP_CORE_DIR
112+ download https://wordpress.org/${ARCHIVE_NAME} .tar.gz $TMPDIR /wordpress.tar.gz
113+ tar --strip-components=1 -zxmf $TMPDIR /wordpress.tar.gz -C $WP_CORE_DIR
88114 fi
89115
90116 download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR /wp-content/db.php
91117}
92118
93- install_test_suite () {
94- # portable in-place argument for both GNU sed and Mac OSX sed
95- if [[ $( uname -s) == ' Darwin' ]]; then
96- local ioption=' -i .bak'
97- else
98- local ioption=' -i'
99- fi
100-
101- # set up testing suite if it doesn't yet exist
102- if [ ! -d $WP_TESTS_DIR ]; then
103- # set up testing suite
104- mkdir -p $WP_TESTS_DIR
105- svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/includes/ $WP_TESTS_DIR /includes
106- svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/data/ $WP_TESTS_DIR /data
107- fi
108-
109- if [ ! -f wp-tests-config.php ]; then
110- download https://develop.svn.wordpress.org/${WP_TESTS_TAG} /wp-tests-config-sample.php " $WP_TESTS_DIR " /wp-tests-config.php
111- # remove all forward slashes in the end
112- WP_CORE_DIR=$( echo $WP_CORE_DIR | sed " s:/\+$::" )
113- sed $ioption " s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR /':" " $WP_TESTS_DIR " /wp-tests-config.php
114- sed $ioption " s/youremptytestdbnamehere/$DB_NAME /" " $WP_TESTS_DIR " /wp-tests-config.php
115- sed $ioption " s/yourusernamehere/$DB_USER /" " $WP_TESTS_DIR " /wp-tests-config.php
116- sed $ioption " s/yourpasswordhere/$DB_PASS /" " $WP_TESTS_DIR " /wp-tests-config.php
117- sed $ioption " s|localhost|$DB_HOST |" " $WP_TESTS_DIR " /wp-tests-config.php
118- fi
119-
120- }
121-
122119install_db () {
123120
124121 if [ ${SKIP_DB_CREATE} = " true" ]; then
@@ -149,41 +146,45 @@ install_db() {
149146}
150147
151148configure_wordpress () {
152-
153149 cd $WP_CORE_DIR
154150 wp config create --dbname=" $DB_NAME " --dbuser=" $DB_USER " --dbpass=" $DB_PASS " --dbhost=" $DB_HOST " --skip-check --force=true
155- wp core install --url=wpgraphql .test --title=" WPGraphQL jwt-authentication Tests" --admin_user=admin --admin_password=password --admin_email=admin@wpgraphql .test
151+ wp core install --url=wp .test --title=" WPGraphQL Tests" --admin_user=admin --admin_password=password --admin_email=admin@wp .test
156152 wp rewrite structure ' /%year%/%monthnum%/%postname%/'
157153}
158154
159- install_wpgraphql () {
160- if [ ! -d $WP_CORE_DIR /wp-content/plugins/wp-graphql ]; then
161- echo " Cloning WPGraphQL"
162- git clone https://github.com/wp-graphql/wp-graphql.git $WP_CORE_DIR /wp-content/plugins/wp-graphql
155+ setup_plugin () {
156+
157+ # Add this repo as a plugin to the repo
158+ if [ ! -d $WP_CORE_DIR /wp-content/plugins/wp-graphql-jwt-authentication ]; then
159+ ln -s $PLUGIN_DIR $WP_CORE_DIR /wp-content/plugins/wp-graphql-jwt-authentication
160+ cd $WP_CORE_DIR /wp-content/plugins
161+ pwd
162+ ls
163163 fi
164- echo " Activating WPGraphQL"
164+
165+ cd $PLUGIN_DIR
166+
167+ composer install
168+
169+ cd $WP_CORE_DIR
170+
171+ wp plugin install wp-graphql
165172 wp plugin activate wp-graphql
166- }
167173
168- activate_plugins () {
174+ wp plugin list
169175
170- # Add this repo as a plugin to the repo
171- if [ ! -d $WP_CORE_DIR /wp-content/plugins/wp-graphql-jwt-authentication ]; then
172- ln -s $PLUGIN_DIR $WP_CORE_DIR /wp-content/plugins/wp-graphql-jwt-authentication
173- fi
176+ # activate the plugin
177+ wp plugin activate wp-graphql-jwt-authentication
174178
175- cd $WP_CORE_DIR
179+ # Flush the permalinks
180+ wp rewrite flush
176181
177- # Flush the permalinks
178- wp rewrite flush
182+ # Export the db for codeception to use
183+ wp db export $PLUGIN_DIR /tests/_data/dump.sql
179184
180- # Export the db for codeception to use
181- wp db export $PLUGIN_DIR /tests/_data/dump.sql
182185}
183186
184187install_wp
185- install_test_suite
186188install_db
187189configure_wordpress
188- install_wpgraphql
189- activate_plugins
190+ setup_plugin
0 commit comments