@@ -35,20 +35,23 @@ if ! command -v svn &> /dev/null; then
35
35
exit 1
36
36
fi
37
37
38
+ # Set WP_TESTS_TAG based on WP_VERSION
38
39
if [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+\- (beta| RC)[0-9]+$ ]]; then
39
40
WP_BRANCH=${WP_VERSION% \- * }
40
41
WP_TESTS_TAG=" branches/$WP_BRANCH "
41
42
elif [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+$ ]]; then
42
43
WP_TESTS_TAG=" branches/$WP_VERSION "
43
44
elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0-9]+ ]]; then
44
45
if [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0] ]]; then
46
+ # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
45
47
WP_TESTS_TAG=" tags/${WP_VERSION% ??} "
46
48
else
47
49
WP_TESTS_TAG=" tags/$WP_VERSION "
48
50
fi
49
51
elif [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
50
52
WP_TESTS_TAG=" trunk"
51
53
else
54
+ # Download latest version if no specific version is provided
52
55
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
53
56
LATEST_VERSION=$( grep -o ' "version":"[^"]*' /tmp/wp-latest.json | sed ' s/"version":"//' )
54
57
if [[ -z " $LATEST_VERSION " ]]; then
57
60
fi
58
61
WP_TESTS_TAG=" tags/$LATEST_VERSION "
59
62
fi
63
+
60
64
set -ex
61
65
66
+ # Install WordPress core
62
67
install_wp () {
63
68
64
69
if [ -d $WP_CORE_DIR ]; then
@@ -98,20 +103,25 @@ install_wp() {
98
103
download https://raw.githubusercontent.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR /wp-content/db.php
99
104
}
100
105
106
+ # Install the WordPress test suite
101
107
install_test_suite () {
108
+ # portable in-place argument for both GNU sed and Mac OSX sed
102
109
if [[ $( uname -s) == ' Darwin' ]]; then
103
110
local ioption=' -i.bak'
104
111
else
105
112
local ioption=' -i'
106
113
fi
107
114
115
+ # set up testing suite if it doesn't yet exist
108
116
if [ ! -d $WP_TESTS_DIR ]; then
117
+ # set up testing suite
109
118
mkdir -p $WP_TESTS_DIR
110
119
rm -rf $WP_TESTS_DIR /{includes,data}
111
120
svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/includes/ $WP_TESTS_DIR /includes
112
121
svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/data/ $WP_TESTS_DIR /data
113
122
fi
114
123
124
+ # Configure wp-tests-config.php
115
125
if [ ! -f wp-tests-config.php ]; then
116
126
download https://develop.svn.wordpress.org/${WP_TESTS_TAG} /wp-tests-config-sample.php " $WP_TESTS_DIR " /wp-tests-config.php
117
127
WP_CORE_DIR=$( echo $WP_CORE_DIR | sed " s:/\+$::" )
@@ -124,9 +134,11 @@ install_test_suite() {
124
134
fi
125
135
}
126
136
137
+ # Recreate the database if needed
127
138
recreate_db () {
128
139
shopt -s nocasematch
129
- if [[ $1 =~ ^(y| yes)$ ]]; then
140
+ if [[ $1 =~ ^(y| yes)$ ]]
141
+ then
130
142
mysqladmin drop $DB_NAME -f --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
131
143
create_db
132
144
echo " Recreated the database ($DB_NAME )."
@@ -136,31 +148,37 @@ recreate_db() {
136
148
shopt -u nocasematch
137
149
}
138
150
151
+ # Create the database
139
152
create_db () {
140
153
mysqladmin create $DB_NAME --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
141
154
}
142
155
156
+ # Install the test database
143
157
install_db () {
158
+
144
159
if [ ${SKIP_DB_CREATE} = " true" ]; then
145
160
return 0
146
161
fi
147
162
163
+ # parse DB_HOST for port or socket references
148
164
local PARTS=(${DB_HOST// \: / } )
149
165
local DB_HOSTNAME=${PARTS[0]} ;
150
166
local DB_SOCK_OR_PORT=${PARTS[1]} ;
151
167
local EXTRA=" "
152
168
153
- if ! [ -z $DB_HOSTNAME ]; then
169
+ if ! [ -z $DB_HOSTNAME ] ; then
154
170
if [ $( echo $DB_SOCK_OR_PORT | grep -e ' ^[0-9]\{1,\}$' ) ]; then
155
171
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
156
- elif ! [ -z $DB_SOCK_OR_PORT ]; then
172
+ elif ! [ -z $DB_SOCK_OR_PORT ] ; then
157
173
EXTRA=" --socket=$DB_SOCK_OR_PORT "
158
- elif ! [ -z $DB_HOSTNAME ]; then
174
+ elif ! [ -z $DB_HOSTNAME ] ; then
159
175
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
160
176
fi
161
177
fi
162
178
163
- if [ $( mysql --user=" $DB_USER " --password=" $DB_PASS " $EXTRA --execute=' show databases;' | grep ^$DB_NAME $) ]; then
179
+ # create database
180
+ if [ $( mysql --user=" $DB_USER " --password=" $DB_PASS " $EXTRA --execute=' show databases;' | grep ^$DB_NAME $) ]
181
+ then
164
182
echo " Reinstalling will delete the existing test database ($DB_NAME )"
165
183
read -p ' Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB
166
184
recreate_db $DELETE_EXISTING_DB
@@ -169,6 +187,7 @@ install_db() {
169
187
fi
170
188
}
171
189
190
+ # Run the installation functions
172
191
install_wp
173
192
install_test_suite
174
193
install_db
0 commit comments