@@ -17,7 +17,6 @@ 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
2120download () {
2221 if [ ` which curl` ]; then
2322 curl -s " $1 " > " $2 " ;
@@ -30,15 +29,17 @@ download() {
3029}
3130
3231# 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
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+ }
3738
38- # Set WP_TESTS_TAG based on WP_VERSION
3939if [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+\- (beta| RC)[0-9]+$ ]]; then
4040 WP_BRANCH=${WP_VERSION% \- * }
4141 WP_TESTS_TAG=" branches/$WP_BRANCH "
42+
4243elif [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+$ ]]; then
4344 WP_TESTS_TAG=" branches/$WP_VERSION "
4445elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0-9]+ ]]; then
@@ -51,19 +52,18 @@ elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
5152elif [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
5253 WP_TESTS_TAG=" trunk"
5354else
54- # Download latest version if no specific version is provided
55+ # http serves a single offer, whereas https serves multiple. we only want one
5556 download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
57+ grep ' [0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
5658 LATEST_VERSION=$( grep -o ' "version":"[^"]*' /tmp/wp-latest.json | sed ' s/"version":"//' )
5759 if [[ -z " $LATEST_VERSION " ]]; then
5860 echo " Latest WordPress version could not be found"
5961 exit 1
6062 fi
6163 WP_TESTS_TAG=" tags/$LATEST_VERSION "
6264fi
63-
6465set -ex
6566
66- # Install WordPress core
6767install_wp () {
6868
6969 if [ -d $WP_CORE_DIR ]; then
@@ -75,16 +75,20 @@ install_wp() {
7575 if [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
7676 mkdir -p $TMPDIR /wordpress-trunk
7777 rm -rf $TMPDIR /wordpress-trunk/*
78+ check_svn_installed
7879 svn export --quiet https://core.svn.wordpress.org/trunk $TMPDIR /wordpress-trunk/wordpress
7980 mv $TMPDIR /wordpress-trunk/wordpress/* $WP_CORE_DIR
8081 else
8182 if [ $WP_VERSION == ' latest' ]; then
8283 local ARCHIVE_NAME=' latest'
8384 elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+ ]]; then
85+ # https serves multiple offers, whereas http serves single.
8486 download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR /wp-latest.json
8587 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
8689 LATEST_VERSION=${WP_VERSION% ??}
8790 else
91+ # otherwise, scan the releases and get the most up to date minor version of the major release
8892 local VERSION_ESCAPED=` echo $WP_VERSION | sed ' s/\./\\\\./g' `
8993 LATEST_VERSION=$( grep -o ' "version":"' $VERSION_ESCAPED ' [^"]*' $TMPDIR /wp-latest.json | sed ' s/"version":"//' | head -1)
9094 fi
@@ -103,7 +107,6 @@ install_wp() {
103107 download https://raw.githubusercontent.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR /wp-content/db.php
104108}
105109
106- # Install the WordPress test suite
107110install_test_suite () {
108111 # portable in-place argument for both GNU sed and Mac OSX sed
109112 if [[ $( uname -s) == ' Darwin' ]]; then
@@ -117,13 +120,14 @@ install_test_suite() {
117120 # set up testing suite
118121 mkdir -p $WP_TESTS_DIR
119122 rm -rf $WP_TESTS_DIR /{includes,data}
123+ check_svn_installed
120124 svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/includes/ $WP_TESTS_DIR /includes
121125 svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/data/ $WP_TESTS_DIR /data
122126 fi
123127
124- # Configure wp-tests-config.php
125128 if [ ! -f wp-tests-config.php ]; then
126129 download https://develop.svn.wordpress.org/${WP_TESTS_TAG} /wp-tests-config-sample.php " $WP_TESTS_DIR " /wp-tests-config.php
130+ # remove all forward slashes in the end
127131 WP_CORE_DIR=$( echo $WP_CORE_DIR | sed " s:/\+$::" )
128132 sed $ioption " s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR /':" " $WP_TESTS_DIR " /wp-tests-config.php
129133 sed $ioption " s:__DIR__ . '/src/':'$WP_CORE_DIR /':" " $WP_TESTS_DIR " /wp-tests-config.php
@@ -132,9 +136,9 @@ install_test_suite() {
132136 sed $ioption " s/yourpasswordhere/$DB_PASS /" " $WP_TESTS_DIR " /wp-tests-config.php
133137 sed $ioption " s|localhost|${DB_HOST} |" " $WP_TESTS_DIR " /wp-tests-config.php
134138 fi
139+
135140}
136141
137- # Recreate the database if needed
138142recreate_db () {
139143 shopt -s nocasematch
140144 if [[ $1 =~ ^(y| yes)$ ]]
@@ -148,12 +152,10 @@ recreate_db() {
148152 shopt -u nocasematch
149153}
150154
151- # Create the database
152155create_db () {
153156 mysqladmin create $DB_NAME --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
154157}
155158
156- # Install the test database
157159install_db () {
158160
159161 if [ ${SKIP_DB_CREATE} = " true" ]; then
@@ -187,7 +189,6 @@ install_db() {
187189 fi
188190}
189191
190- # Run the installation functions
191192install_wp
192193install_test_suite
193194install_db
0 commit comments