@@ -17,33 +17,39 @@ TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
17
17
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR / wordpress-tests-lib}
18
18
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR / wordpress}
19
19
20
+ # Function to download files using curl or wget
20
21
download () {
21
22
if [ ` which curl` ]; then
22
23
curl -s " $1 " > " $2 " ;
23
24
elif [ ` which wget` ]; then
24
25
wget -nv -O " $2 " " $1 "
26
+ else
27
+ echo " Error: Neither curl nor wget is installed."
28
+ exit 1
25
29
fi
26
30
}
27
31
32
+ # Check if svn is installed
33
+ if ! command -v svn & > /dev/null; then
34
+ echo " Error: svn is not installed. Please install svn to proceed."
35
+ exit 1
36
+ fi
37
+
28
38
if [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+\- (beta| RC)[0-9]+$ ]]; then
29
39
WP_BRANCH=${WP_VERSION% \- * }
30
40
WP_TESTS_TAG=" branches/$WP_BRANCH "
31
-
32
41
elif [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+$ ]]; then
33
42
WP_TESTS_TAG=" branches/$WP_VERSION "
34
43
elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0-9]+ ]]; then
35
44
if [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0] ]]; then
36
- # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
37
45
WP_TESTS_TAG=" tags/${WP_VERSION% ??} "
38
46
else
39
47
WP_TESTS_TAG=" tags/$WP_VERSION "
40
48
fi
41
49
elif [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
42
50
WP_TESTS_TAG=" trunk"
43
51
else
44
- # http serves a single offer, whereas https serves multiple. we only want one
45
52
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
46
- grep ' [0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
47
53
LATEST_VERSION=$( grep -o ' "version":"[^"]*' /tmp/wp-latest.json | sed ' s/"version":"//' )
48
54
if [[ -z " $LATEST_VERSION " ]]; then
49
55
echo " Latest WordPress version could not be found"
@@ -70,13 +76,10 @@ install_wp() {
70
76
if [ $WP_VERSION == ' latest' ]; then
71
77
local ARCHIVE_NAME=' latest'
72
78
elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+ ]]; then
73
- # https serves multiple offers, whereas http serves single.
74
79
download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR /wp-latest.json
75
80
if [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0] ]]; then
76
- # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
77
81
LATEST_VERSION=${WP_VERSION% ??}
78
82
else
79
- # otherwise, scan the releases and get the most up to date minor version of the major release
80
83
local VERSION_ESCAPED=` echo $WP_VERSION | sed ' s/\./\\\\./g' `
81
84
LATEST_VERSION=$( grep -o ' "version":"' $VERSION_ESCAPED ' [^"]*' $TMPDIR /wp-latest.json | sed ' s/"version":"//' | head -1)
82
85
fi
@@ -96,16 +99,13 @@ install_wp() {
96
99
}
97
100
98
101
install_test_suite () {
99
- # portable in-place argument for both GNU sed and Mac OSX sed
100
102
if [[ $( uname -s) == ' Darwin' ]]; then
101
103
local ioption=' -i.bak'
102
104
else
103
105
local ioption=' -i'
104
106
fi
105
107
106
- # set up testing suite if it doesn't yet exist
107
108
if [ ! -d $WP_TESTS_DIR ]; then
108
- # set up testing suite
109
109
mkdir -p $WP_TESTS_DIR
110
110
rm -rf $WP_TESTS_DIR /{includes,data}
111
111
svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/includes/ $WP_TESTS_DIR /includes
@@ -114,7 +114,6 @@ install_test_suite() {
114
114
115
115
if [ ! -f wp-tests-config.php ]; then
116
116
download https://develop.svn.wordpress.org/${WP_TESTS_TAG} /wp-tests-config-sample.php " $WP_TESTS_DIR " /wp-tests-config.php
117
- # remove all forward slashes in the end
118
117
WP_CORE_DIR=$( echo $WP_CORE_DIR | sed " s:/\+$::" )
119
118
sed $ioption " s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR /':" " $WP_TESTS_DIR " /wp-tests-config.php
120
119
sed $ioption " s:__DIR__ . '/src/':'$WP_CORE_DIR /':" " $WP_TESTS_DIR " /wp-tests-config.php
@@ -123,13 +122,11 @@ install_test_suite() {
123
122
sed $ioption " s/yourpasswordhere/$DB_PASS /" " $WP_TESTS_DIR " /wp-tests-config.php
124
123
sed $ioption " s|localhost|${DB_HOST} |" " $WP_TESTS_DIR " /wp-tests-config.php
125
124
fi
126
-
127
125
}
128
126
129
127
recreate_db () {
130
128
shopt -s nocasematch
131
- if [[ $1 =~ ^(y| yes)$ ]]
132
- then
129
+ if [[ $1 =~ ^(y| yes)$ ]]; then
133
130
mysqladmin drop $DB_NAME -f --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
134
131
create_db
135
132
echo " Recreated the database ($DB_NAME )."
@@ -144,30 +141,26 @@ create_db() {
144
141
}
145
142
146
143
install_db () {
147
-
148
144
if [ ${SKIP_DB_CREATE} = " true" ]; then
149
145
return 0
150
146
fi
151
147
152
- # parse DB_HOST for port or socket references
153
148
local PARTS=(${DB_HOST// \: / } )
154
149
local DB_HOSTNAME=${PARTS[0]} ;
155
150
local DB_SOCK_OR_PORT=${PARTS[1]} ;
156
151
local EXTRA=" "
157
152
158
- if ! [ -z $DB_HOSTNAME ] ; then
153
+ if ! [ -z $DB_HOSTNAME ]; then
159
154
if [ $( echo $DB_SOCK_OR_PORT | grep -e ' ^[0-9]\{1,\}$' ) ]; then
160
155
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
161
- elif ! [ -z $DB_SOCK_OR_PORT ] ; then
156
+ elif ! [ -z $DB_SOCK_OR_PORT ]; then
162
157
EXTRA=" --socket=$DB_SOCK_OR_PORT "
163
- elif ! [ -z $DB_HOSTNAME ] ; then
158
+ elif ! [ -z $DB_HOSTNAME ]; then
164
159
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
165
160
fi
166
161
fi
167
162
168
- # create database
169
- if [ $( mysql --user=" $DB_USER " --password=" $DB_PASS " $EXTRA --execute=' show databases;' | grep ^$DB_NAME $) ]
170
- then
163
+ if [ $( mysql --user=" $DB_USER " --password=" $DB_PASS " $EXTRA --execute=' show databases;' | grep ^$DB_NAME $) ]; then
171
164
echo " Reinstalling will delete the existing test database ($DB_NAME )"
172
165
read -p ' Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB
173
166
recreate_db $DELETE_EXISTING_DB
0 commit comments