1
+ #! /usr/bin/env bash
2
+
3
+ if [ $# -lt 3 ]; then
4
+ echo " usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [force download]"
5
+ exit 1
6
+ fi
7
+
8
+ DB_NAME=$1
9
+ DB_USER=$2
10
+ DB_PASS=$3
11
+ DB_HOST=${4-localhost}
12
+ WP_VERSION=${5-latest}
13
+ FORCE=${6-false}
14
+
15
+ WP_TESTS_DIR=${WP_TESTS_DIR-/ tmp/ wordpress-tests-lib}
16
+ WP_CORE_DIR=${WP_CORE_DIR-/ tmp/ wordpress/ }
17
+
18
+ download () {
19
+ if [ ` which curl` ]; then
20
+ curl -s " $1 " > " $2 " ;
21
+ elif [ ` which wget` ]; then
22
+ wget -nv -O " $2 " " $1 "
23
+ fi
24
+ }
25
+
26
+ if [[ $WP_VERSION =~ [0-9]+\. [0-9]+ (\. [0-9]+)? ]]; then
27
+ WP_TESTS_TAG=" tags/$WP_VERSION "
28
+ else
29
+ # http serves a single offer, whereas https serves multiple. we only want one
30
+ download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
31
+ grep ' [0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
32
+ LATEST_VERSION=$( grep -o ' "version":"[^"]*' /tmp/wp-latest.json | sed ' s/"version":"//' )
33
+ if [[ -z " $LATEST_VERSION " ]]; then
34
+ echo " Latest WordPress version could not be found"
35
+ exit 1
36
+ fi
37
+ WP_TESTS_TAG=" tags/$LATEST_VERSION "
38
+ fi
39
+
40
+ if [[ $WP_TESTS_TAG == * " beta" * ]]
41
+ then
42
+ WP_TESTS_TAG=" trunk"
43
+ fi
44
+
45
+ set -ex
46
+
47
+ install_wp () {
48
+ if [ $FORCE == ' true' ]; then
49
+ rm -Rf $WP_CORE_DIR
50
+ fi
51
+
52
+ if [ -d $WP_CORE_DIR ]; then
53
+ return ;
54
+ fi
55
+
56
+ mkdir -p $WP_CORE_DIR
57
+
58
+ if [ $WP_VERSION == ' latest' ]; then
59
+ local ARCHIVE_NAME=' latest'
60
+ else
61
+ local ARCHIVE_NAME=" wordpress-$WP_VERSION "
62
+ fi
63
+
64
+ download https://wordpress.org/${ARCHIVE_NAME} .tar.gz /tmp/wordpress.tar.gz
65
+ tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
66
+
67
+ download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR /wp-content/db.php
68
+ }
69
+
70
+ install_test_suite () {
71
+ if [ $FORCE == ' true' ]; then
72
+ rm -Rf $WP_TESTS_DIR
73
+ fi
74
+
75
+ # portable in-place argument for both GNU sed and Mac OSX sed
76
+ if [[ $( uname -s) == ' Darwin' ]]; then
77
+ local ioption=' -i .bak'
78
+ else
79
+ local ioption=' -i'
80
+ fi
81
+
82
+ # set up testing suite if it doesn't yet exist
83
+ if [ ! -d $WP_TESTS_DIR ]; then
84
+ # set up testing suite
85
+ mkdir -p $WP_TESTS_DIR
86
+ svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/includes/ $WP_TESTS_DIR /includes
87
+ svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/data/ $WP_TESTS_DIR /data
88
+ fi
89
+
90
+ cd $WP_TESTS_DIR
91
+
92
+ if [ ! -f wp-tests-config.php ]; then
93
+ download https://develop.svn.wordpress.org/${WP_TESTS_TAG} /wp-tests-config-sample.php " $WP_TESTS_DIR " /wp-tests-config.php
94
+ sed $ioption " s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR ':" " $WP_TESTS_DIR " /wp-tests-config.php
95
+ sed $ioption " s/youremptytestdbnamehere/$DB_NAME /" " $WP_TESTS_DIR " /wp-tests-config.php
96
+ sed $ioption " s/yourusernamehere/$DB_USER /" " $WP_TESTS_DIR " /wp-tests-config.php
97
+ sed $ioption " s/yourpasswordhere/$DB_PASS /" " $WP_TESTS_DIR " /wp-tests-config.php
98
+ sed $ioption " s|localhost|${DB_HOST} |" " $WP_TESTS_DIR " /wp-tests-config.php
99
+ fi
100
+
101
+ }
102
+
103
+ install_db () {
104
+ # parse DB_HOST for port or socket references
105
+ local PARTS=(${DB_HOST// \: / } )
106
+ local DB_HOSTNAME=${PARTS[0]} ;
107
+ local DB_SOCK_OR_PORT=${PARTS[1]} ;
108
+ local EXTRA=" "
109
+
110
+ if ! [ -z $DB_HOSTNAME ] ; then
111
+ if [ $( echo $DB_SOCK_OR_PORT | grep -e ' ^[0-9]\{1,\}$' ) ]; then
112
+ EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
113
+ elif ! [ -z $DB_SOCK_OR_PORT ] ; then
114
+ EXTRA=" --socket=$DB_SOCK_OR_PORT "
115
+ elif ! [ -z $DB_HOSTNAME ] ; then
116
+ EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
117
+ fi
118
+ fi
119
+
120
+ # create database
121
+ mysqladmin create $DB_NAME --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
122
+ }
123
+
124
+ install_wp
125
+ install_test_suite
126
+ install_db
0 commit comments