1
1
#! /usr/bin/env bash
2
2
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
+
3
9
source .env
4
10
5
11
print_usage_instruction () {
6
12
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"
8
14
exit 1
9
15
}
10
16
@@ -20,23 +26,17 @@ if [[ -z "$TEST_DB_USER" ]]; then
20
26
else
21
27
DB_USER=$TEST_DB_USER
22
28
fi
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
36
29
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/ }
37
37
PLUGIN_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 }
40
40
41
41
download () {
42
42
if [ ` which curl` ]; then
@@ -46,8 +46,19 @@ download() {
46
46
fi
47
47
}
48
48
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
51
62
elif [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
52
63
WP_TESTS_TAG=" trunk"
53
64
else
61
72
fi
62
73
WP_TESTS_TAG=" tags/$LATEST_VERSION "
63
74
fi
64
-
65
75
set -ex
66
76
67
77
install_wp () {
@@ -73,52 +83,39 @@ install_wp() {
73
83
mkdir -p $WP_CORE_DIR
74
84
75
85
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
80
90
else
81
91
if [ $WP_VERSION == ' latest' ]; then
82
92
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
83
109
else
84
110
local ARCHIVE_NAME=" wordpress-$WP_VERSION "
85
111
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
88
114
fi
89
115
90
116
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR /wp-content/db.php
91
117
}
92
118
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
-
122
119
install_db () {
123
120
124
121
if [ ${SKIP_DB_CREATE} = " true" ]; then
@@ -149,41 +146,45 @@ install_db() {
149
146
}
150
147
151
148
configure_wordpress () {
152
-
153
149
cd $WP_CORE_DIR
154
150
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
156
152
wp rewrite structure ' /%year%/%monthnum%/%postname%/'
157
153
}
158
154
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
163
163
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
165
172
wp plugin activate wp-graphql
166
- }
167
173
168
- activate_plugins () {
174
+ wp plugin list
169
175
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
174
178
175
- cd $WP_CORE_DIR
179
+ # Flush the permalinks
180
+ wp rewrite flush
176
181
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
179
184
180
- # Export the db for codeception to use
181
- wp db export $PLUGIN_DIR /tests/_data/dump.sql
182
185
}
183
186
184
187
install_wp
185
- install_test_suite
186
188
install_db
187
189
configure_wordpress
188
- install_wpgraphql
189
- activate_plugins
190
+ setup_plugin
0 commit comments