@@ -17,33 +17,39 @@ TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
1717WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR / wordpress-tests-lib}
1818WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR / wordpress}
1919
20+ # Function to download files using curl or wget
2021download () {
2122 if [ ` which curl` ]; then
2223 curl -s " $1 " > " $2 " ;
2324 elif [ ` which wget` ]; then
2425 wget -nv -O " $2 " " $1 "
26+ else
27+ echo " Error: Neither curl nor wget is installed."
28+ exit 1
2529 fi
2630}
2731
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+
2838if [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+\- (beta| RC)[0-9]+$ ]]; then
2939 WP_BRANCH=${WP_VERSION% \- * }
3040 WP_TESTS_TAG=" branches/$WP_BRANCH "
31-
3241elif [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+$ ]]; then
3342 WP_TESTS_TAG=" branches/$WP_VERSION "
3443elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0-9]+ ]]; then
3544 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
3745 WP_TESTS_TAG=" tags/${WP_VERSION% ??} "
3846 else
3947 WP_TESTS_TAG=" tags/$WP_VERSION "
4048 fi
4149elif [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
4250 WP_TESTS_TAG=" trunk"
4351else
44- # http serves a single offer, whereas https serves multiple. we only want one
4552 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
4753 LATEST_VERSION=$( grep -o ' "version":"[^"]*' /tmp/wp-latest.json | sed ' s/"version":"//' )
4854 if [[ -z " $LATEST_VERSION " ]]; then
4955 echo " Latest WordPress version could not be found"
@@ -70,13 +76,10 @@ install_wp() {
7076 if [ $WP_VERSION == ' latest' ]; then
7177 local ARCHIVE_NAME=' latest'
7278 elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+ ]]; then
73- # https serves multiple offers, whereas http serves single.
7479 download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR /wp-latest.json
7580 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
7781 LATEST_VERSION=${WP_VERSION% ??}
7882 else
79- # otherwise, scan the releases and get the most up to date minor version of the major release
8083 local VERSION_ESCAPED=` echo $WP_VERSION | sed ' s/\./\\\\./g' `
8184 LATEST_VERSION=$( grep -o ' "version":"' $VERSION_ESCAPED ' [^"]*' $TMPDIR /wp-latest.json | sed ' s/"version":"//' | head -1)
8285 fi
@@ -96,16 +99,13 @@ install_wp() {
9699}
97100
98101install_test_suite () {
99- # portable in-place argument for both GNU sed and Mac OSX sed
100102 if [[ $( uname -s) == ' Darwin' ]]; then
101103 local ioption=' -i.bak'
102104 else
103105 local ioption=' -i'
104106 fi
105107
106- # set up testing suite if it doesn't yet exist
107108 if [ ! -d $WP_TESTS_DIR ]; then
108- # set up testing suite
109109 mkdir -p $WP_TESTS_DIR
110110 rm -rf $WP_TESTS_DIR /{includes,data}
111111 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() {
114114
115115 if [ ! -f wp-tests-config.php ]; then
116116 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
118117 WP_CORE_DIR=$( echo $WP_CORE_DIR | sed " s:/\+$::" )
119118 sed $ioption " s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR /':" " $WP_TESTS_DIR " /wp-tests-config.php
120119 sed $ioption " s:__DIR__ . '/src/':'$WP_CORE_DIR /':" " $WP_TESTS_DIR " /wp-tests-config.php
@@ -123,13 +122,11 @@ install_test_suite() {
123122 sed $ioption " s/yourpasswordhere/$DB_PASS /" " $WP_TESTS_DIR " /wp-tests-config.php
124123 sed $ioption " s|localhost|${DB_HOST} |" " $WP_TESTS_DIR " /wp-tests-config.php
125124 fi
126-
127125}
128126
129127recreate_db () {
130128 shopt -s nocasematch
131- if [[ $1 =~ ^(y| yes)$ ]]
132- then
129+ if [[ $1 =~ ^(y| yes)$ ]]; then
133130 mysqladmin drop $DB_NAME -f --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
134131 create_db
135132 echo " Recreated the database ($DB_NAME )."
@@ -144,30 +141,26 @@ create_db() {
144141}
145142
146143install_db () {
147-
148144 if [ ${SKIP_DB_CREATE} = " true" ]; then
149145 return 0
150146 fi
151147
152- # parse DB_HOST for port or socket references
153148 local PARTS=(${DB_HOST// \: / } )
154149 local DB_HOSTNAME=${PARTS[0]} ;
155150 local DB_SOCK_OR_PORT=${PARTS[1]} ;
156151 local EXTRA=" "
157152
158- if ! [ -z $DB_HOSTNAME ] ; then
153+ if ! [ -z $DB_HOSTNAME ]; then
159154 if [ $( echo $DB_SOCK_OR_PORT | grep -e ' ^[0-9]\{1,\}$' ) ]; then
160155 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
162157 EXTRA=" --socket=$DB_SOCK_OR_PORT "
163- elif ! [ -z $DB_HOSTNAME ] ; then
158+ elif ! [ -z $DB_HOSTNAME ]; then
164159 EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
165160 fi
166161 fi
167162
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
171164 echo " Reinstalling will delete the existing test database ($DB_NAME )"
172165 read -p ' Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB
173166 recreate_db $DELETE_EXISTING_DB
0 commit comments