11#! /usr/bin/env bash
22
33if [ $# -lt 3 ]; then
4- echo " usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
4+ echo " usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation] "
55 exit 1
66fi
77
@@ -10,9 +10,12 @@ DB_USER=$2
1010DB_PASS=$3
1111DB_HOST=${4-localhost}
1212WP_VERSION=${5-latest}
13+ SKIP_DB_CREATE=${6-false}
1314
14- WP_TESTS_DIR=${WP_TESTS_DIR-/ tmp/ wordpress-tests-lib}
15- 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/ }
1619
1720download () {
1821 if [ ` which curl` ]; then
@@ -22,8 +25,19 @@ download() {
2225 fi
2326}
2427
25- if [[ $WP_VERSION =~ [0-9]+\. [0-9]+ (\. [0-9]+)? ]]; then
26- WP_TESTS_TAG=" tags/$WP_VERSION "
28+ if [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+\- (beta| RC)[0-9]+$ ]]; then
29+ WP_BRANCH=${WP_VERSION% \- * }
30+ WP_TESTS_TAG=" branches/$WP_BRANCH "
31+
32+ elif [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+$ ]]; then
33+ WP_TESTS_TAG=" branches/$WP_VERSION "
34+ elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0-9]+ ]]; then
35+ 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+ WP_TESTS_TAG=" tags/${WP_VERSION% ??} "
38+ else
39+ WP_TESTS_TAG=" tags/$WP_VERSION "
40+ fi
2741elif [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
2842 WP_TESTS_TAG=" trunk"
2943else
3751 fi
3852 WP_TESTS_TAG=" tags/$LATEST_VERSION "
3953fi
40-
4154set -ex
4255
4356install_wp () {
@@ -49,18 +62,34 @@ install_wp() {
4962 mkdir -p $WP_CORE_DIR
5063
5164 if [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
52- mkdir -p /tmp /wordpress-nightly
53- download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp /wordpress-nightly/wordpress-nightly.zip
54- unzip -q /tmp/ wordpress-nightly/wordpress-nightly.zip -d /tmp /wordpress-nightly/
55- mv /tmp /wordpress-nightly/wordpress/* $WP_CORE_DIR
65+ mkdir -p $TMPDIR /wordpress-nightly
66+ download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR /wordpress-nightly/wordpress-nightly.zip
67+ unzip -q $TMPDIR / wordpress-nightly/wordpress-nightly.zip -d $TMPDIR /wordpress-nightly/
68+ mv $TMPDIR /wordpress-nightly/wordpress/* $WP_CORE_DIR
5669 else
5770 if [ $WP_VERSION == ' latest' ]; then
5871 local ARCHIVE_NAME=' latest'
72+ elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+ ]]; then
73+ # https serves multiple offers, whereas http serves single.
74+ download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR /wp-latest.json
75+ 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+ LATEST_VERSION=${WP_VERSION% ??}
78+ else
79+ # otherwise, scan the releases and get the most up to date minor version of the major release
80+ local VERSION_ESCAPED=` echo $WP_VERSION | sed ' s/\./\\\\./g' `
81+ LATEST_VERSION=$( grep -o ' "version":"' $VERSION_ESCAPED ' [^"]*' $TMPDIR /wp-latest.json | sed ' s/"version":"//' | head -1)
82+ fi
83+ if [[ -z " $LATEST_VERSION " ]]; then
84+ local ARCHIVE_NAME=" wordpress-$WP_VERSION "
85+ else
86+ local ARCHIVE_NAME=" wordpress-$LATEST_VERSION "
87+ fi
5988 else
6089 local ARCHIVE_NAME=" wordpress-$WP_VERSION "
6190 fi
62- download https://wordpress.org/${ARCHIVE_NAME} .tar.gz /tmp /wordpress.tar.gz
63- tar --strip-components=1 -zxmf /tmp /wordpress.tar.gz -C $WP_CORE_DIR
91+ download https://wordpress.org/${ARCHIVE_NAME} .tar.gz $TMPDIR /wordpress.tar.gz
92+ tar --strip-components=1 -zxmf $TMPDIR /wordpress.tar.gz -C $WP_CORE_DIR
6493 fi
6594
6695 download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR /wp-content/db.php
@@ -69,7 +98,7 @@ install_wp() {
6998install_test_suite () {
7099 # portable in-place argument for both GNU sed and Mac OSX sed
71100 if [[ $( uname -s) == ' Darwin' ]]; then
72- local ioption=' -i .bak'
101+ local ioption=' -i.bak'
73102 else
74103 local ioption=' -i'
75104 fi
@@ -79,13 +108,14 @@ install_test_suite() {
79108 # set up testing suite
80109 mkdir -p $WP_TESTS_DIR
81110 svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/includes/ $WP_TESTS_DIR /includes
111+ svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/data/ $WP_TESTS_DIR /data
82112 fi
83113
84- cd $WP_TESTS_DIR
85-
86114 if [ ! -f wp-tests-config.php ]; then
87115 download https://develop.svn.wordpress.org/${WP_TESTS_TAG} /wp-tests-config-sample.php " $WP_TESTS_DIR " /wp-tests-config.php
88- sed $ioption " s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR ':" " $WP_TESTS_DIR " /wp-tests-config.php
116+ # remove all forward slashes in the end
117+ WP_CORE_DIR=$( echo $WP_CORE_DIR | sed " s:/\+$::" )
118+ sed $ioption " s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR /':" " $WP_TESTS_DIR " /wp-tests-config.php
89119 sed $ioption " s/youremptytestdbnamehere/$DB_NAME /" " $WP_TESTS_DIR " /wp-tests-config.php
90120 sed $ioption " s/yourusernamehere/$DB_USER /" " $WP_TESTS_DIR " /wp-tests-config.php
91121 sed $ioption " s/yourpasswordhere/$DB_PASS /" " $WP_TESTS_DIR " /wp-tests-config.php
@@ -95,6 +125,11 @@ install_test_suite() {
95125}
96126
97127install_db () {
128+
129+ if [ ${SKIP_DB_CREATE} = " true" ]; then
130+ return 0
131+ fi
132+
98133 # parse DB_HOST for port or socket references
99134 local PARTS=(${DB_HOST// \: / } )
100135 local DB_HOSTNAME=${PARTS[0]} ;
0 commit comments