@@ -12,21 +12,43 @@ DB_HOST=${4-localhost}
12
12
WP_VERSION=${5-latest}
13
13
SKIP_DB_CREATE=${6-false}
14
14
15
- WP_TESTS_DIR=${WP_TESTS_DIR-/ tmp/ wordpress-tests-lib}
16
- WP_CORE_DIR=${WP_CORE_DIR-/ tmp/ wordpress/ }
15
+ TMPDIR=${TMPDIR-/ tmp}
16
+ TMPDIR=$( echo $TMPDIR | sed -e " s/\/$//" )
17
+ WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR / wordpress-tests-lib}
18
+ WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR / wordpress}
17
19
18
- command_exists () {
19
- type -t " $1 " > /dev/null 2>&1
20
- }
21
20
download () {
22
- if command_exists " curl" ; then
23
- curl -s -o " ${2:- -} " " $1 "
24
- elif command_exists " wget" ; then
25
- wget -nv -O " ${2:- -} " " $1 "
21
+ if [ ` which curl` ]; then
22
+ curl -s " $1 " > " $2 " ;
23
+ elif [ ` which wget` ]; then
24
+ wget -nv -O " $2 " " $1 "
25
+ else
26
+ echo " Error: Neither curl nor wget is installed."
27
+ exit 1
26
28
fi
27
29
}
28
- if [[ $WP_VERSION =~ [0-9]+\. [0-9]+ (\. [0-9]+)? ]]; then
29
- WP_TESTS_TAG=" tags/$WP_VERSION "
30
+
31
+ # Check if svn is installed
32
+ check_svn_installed () {
33
+ if ! command -v svn > /dev/null; then
34
+ echo " Error: svn is not installed. Please install svn and try again."
35
+ exit 1
36
+ fi
37
+ }
38
+
39
+ if [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+\- (beta| RC)[0-9]+$ ]]; then
40
+ WP_BRANCH=${WP_VERSION% \- * }
41
+ WP_TESTS_TAG=" branches/$WP_BRANCH "
42
+
43
+ elif [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+$ ]]; then
44
+ WP_TESTS_TAG=" branches/$WP_VERSION "
45
+ elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0-9]+ ]]; then
46
+ if [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0] ]]; then
47
+ # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
48
+ WP_TESTS_TAG=" tags/${WP_VERSION% ??} "
49
+ else
50
+ WP_TESTS_TAG=" tags/$WP_VERSION "
51
+ fi
30
52
elif [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
31
53
WP_TESTS_TAG=" trunk"
32
54
else
40
62
fi
41
63
WP_TESTS_TAG=" tags/$LATEST_VERSION "
42
64
fi
43
-
44
65
set -ex
45
66
46
-
47
67
install_wp () {
48
68
49
69
if [ -d $WP_CORE_DIR ]; then
@@ -53,27 +73,44 @@ install_wp() {
53
73
mkdir -p $WP_CORE_DIR
54
74
55
75
if [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
56
- mkdir -p /tmp/wordpress-nightly
57
- download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
58
- unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
59
- mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
76
+ mkdir -p $TMPDIR /wordpress-trunk
77
+ rm -rf $TMPDIR /wordpress-trunk/*
78
+ check_svn_installed
79
+ svn export --quiet https://core.svn.wordpress.org/trunk $TMPDIR /wordpress-trunk/wordpress
80
+ mv $TMPDIR /wordpress-trunk/wordpress/* $WP_CORE_DIR
60
81
else
61
82
if [ $WP_VERSION == ' latest' ]; then
62
83
local ARCHIVE_NAME=' latest'
84
+ elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+ ]]; then
85
+ # https serves multiple offers, whereas http serves single.
86
+ download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR /wp-latest.json
87
+ if [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0] ]]; then
88
+ # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
89
+ LATEST_VERSION=${WP_VERSION% ??}
90
+ else
91
+ # otherwise, scan the releases and get the most up to date minor version of the major release
92
+ local VERSION_ESCAPED=` echo $WP_VERSION | sed ' s/\./\\\\./g' `
93
+ LATEST_VERSION=$( grep -o ' "version":"' $VERSION_ESCAPED ' [^"]*' $TMPDIR /wp-latest.json | sed ' s/"version":"//' | head -1)
94
+ fi
95
+ if [[ -z " $LATEST_VERSION " ]]; then
96
+ local ARCHIVE_NAME=" wordpress-$WP_VERSION "
97
+ else
98
+ local ARCHIVE_NAME=" wordpress-$LATEST_VERSION "
99
+ fi
63
100
else
64
101
local ARCHIVE_NAME=" wordpress-$WP_VERSION "
65
102
fi
66
- download https://wordpress.org/${ARCHIVE_NAME} .tar.gz /tmp /wordpress.tar.gz
67
- tar --strip-components=1 -zxmf /tmp /wordpress.tar.gz -C $WP_CORE_DIR
103
+ download https://wordpress.org/${ARCHIVE_NAME} .tar.gz $TMPDIR /wordpress.tar.gz
104
+ tar --strip-components=1 -zxmf $TMPDIR /wordpress.tar.gz -C $WP_CORE_DIR
68
105
fi
69
106
70
- download https://raw.github .com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR /wp-content/db.php
107
+ download https://raw.githubusercontent .com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR /wp-content/db.php
71
108
}
72
109
73
110
install_test_suite () {
74
111
# portable in-place argument for both GNU sed and Mac OSX sed
75
112
if [[ $( uname -s) == ' Darwin' ]]; then
76
- local ioption=' -i .bak'
113
+ local ioption=' -i.bak'
77
114
else
78
115
local ioption=' -i'
79
116
fi
@@ -82,15 +119,18 @@ install_test_suite() {
82
119
if [ ! -d $WP_TESTS_DIR ]; then
83
120
# set up testing suite
84
121
mkdir -p $WP_TESTS_DIR
85
- svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/includes/ $WP_TESTS_DIR /includes
86
- svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/data/ $WP_TESTS_DIR /data
122
+ rm -rf $WP_TESTS_DIR /{includes,data}
123
+ check_svn_installed
124
+ svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/includes/ $WP_TESTS_DIR /includes
125
+ svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/data/ $WP_TESTS_DIR /data
87
126
fi
88
127
89
128
if [ ! -f wp-tests-config.php ]; then
90
129
download https://develop.svn.wordpress.org/${WP_TESTS_TAG} /wp-tests-config-sample.php " $WP_TESTS_DIR " /wp-tests-config.php
91
130
# remove all forward slashes in the end
92
131
WP_CORE_DIR=$( echo $WP_CORE_DIR | sed " s:/\+$::" )
93
132
sed $ioption " s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR /':" " $WP_TESTS_DIR " /wp-tests-config.php
133
+ sed $ioption " s:__DIR__ . '/src/':'$WP_CORE_DIR /':" " $WP_TESTS_DIR " /wp-tests-config.php
94
134
sed $ioption " s/youremptytestdbnamehere/$DB_NAME /" " $WP_TESTS_DIR " /wp-tests-config.php
95
135
sed $ioption " s/yourusernamehere/$DB_USER /" " $WP_TESTS_DIR " /wp-tests-config.php
96
136
sed $ioption " s/yourpasswordhere/$DB_PASS /" " $WP_TESTS_DIR " /wp-tests-config.php
@@ -99,6 +139,23 @@ install_test_suite() {
99
139
100
140
}
101
141
142
+ recreate_db () {
143
+ shopt -s nocasematch
144
+ if [[ $1 =~ ^(y| yes)$ ]]
145
+ then
146
+ mysqladmin drop $DB_NAME -f --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
147
+ create_db
148
+ echo " Recreated the database ($DB_NAME )."
149
+ else
150
+ echo " Leaving the existing database ($DB_NAME ) in place."
151
+ fi
152
+ shopt -u nocasematch
153
+ }
154
+
155
+ create_db () {
156
+ mysqladmin create $DB_NAME --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
157
+ }
158
+
102
159
install_db () {
103
160
104
161
if [ ${SKIP_DB_CREATE} = " true" ]; then
@@ -122,7 +179,14 @@ install_db() {
122
179
fi
123
180
124
181
# create database
125
- mysql --user=" $DB_USER " --password=" $DB_PASS " $EXTRA --execute " CREATE DATABASE IF NOT EXISTS $DB_NAME ;"
182
+ if [ $( mysql --user=" $DB_USER " --password=" $DB_PASS " $EXTRA --execute=' show databases;' | grep ^$DB_NAME $) ]
183
+ then
184
+ echo " Reinstalling will delete the existing test database ($DB_NAME )"
185
+ read -p ' Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB
186
+ recreate_db $DELETE_EXISTING_DB
187
+ else
188
+ create_db
189
+ fi
126
190
}
127
191
128
192
install_wp
0 commit comments