@@ -17,7 +17,6 @@ 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
21
20
download () {
22
21
if [ ` which curl` ]; then
23
22
curl -s " $1 " > " $2 " ;
@@ -30,15 +29,17 @@ download() {
30
29
}
31
30
32
31
# 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
+ }
37
38
38
- # Set WP_TESTS_TAG based on WP_VERSION
39
39
if [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+\- (beta| RC)[0-9]+$ ]]; then
40
40
WP_BRANCH=${WP_VERSION% \- * }
41
41
WP_TESTS_TAG=" branches/$WP_BRANCH "
42
+
42
43
elif [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+$ ]]; then
43
44
WP_TESTS_TAG=" branches/$WP_VERSION "
44
45
elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0-9]+ ]]; then
@@ -51,19 +52,18 @@ elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
51
52
elif [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
52
53
WP_TESTS_TAG=" trunk"
53
54
else
54
- # Download latest version if no specific version is provided
55
+ # http serves a single offer, whereas https serves multiple. we only want one
55
56
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
56
58
LATEST_VERSION=$( grep -o ' "version":"[^"]*' /tmp/wp-latest.json | sed ' s/"version":"//' )
57
59
if [[ -z " $LATEST_VERSION " ]]; then
58
60
echo " Latest WordPress version could not be found"
59
61
exit 1
60
62
fi
61
63
WP_TESTS_TAG=" tags/$LATEST_VERSION "
62
64
fi
63
-
64
65
set -ex
65
66
66
- # Install WordPress core
67
67
install_wp () {
68
68
69
69
if [ -d $WP_CORE_DIR ]; then
@@ -75,16 +75,20 @@ install_wp() {
75
75
if [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
76
76
mkdir -p $TMPDIR /wordpress-trunk
77
77
rm -rf $TMPDIR /wordpress-trunk/*
78
+ check_svn_installed
78
79
svn export --quiet https://core.svn.wordpress.org/trunk $TMPDIR /wordpress-trunk/wordpress
79
80
mv $TMPDIR /wordpress-trunk/wordpress/* $WP_CORE_DIR
80
81
else
81
82
if [ $WP_VERSION == ' latest' ]; then
82
83
local ARCHIVE_NAME=' latest'
83
84
elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+ ]]; then
85
+ # https serves multiple offers, whereas http serves single.
84
86
download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR /wp-latest.json
85
87
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
86
89
LATEST_VERSION=${WP_VERSION% ??}
87
90
else
91
+ # otherwise, scan the releases and get the most up to date minor version of the major release
88
92
local VERSION_ESCAPED=` echo $WP_VERSION | sed ' s/\./\\\\./g' `
89
93
LATEST_VERSION=$( grep -o ' "version":"' $VERSION_ESCAPED ' [^"]*' $TMPDIR /wp-latest.json | sed ' s/"version":"//' | head -1)
90
94
fi
@@ -103,7 +107,6 @@ install_wp() {
103
107
download https://raw.githubusercontent.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR /wp-content/db.php
104
108
}
105
109
106
- # Install the WordPress test suite
107
110
install_test_suite () {
108
111
# portable in-place argument for both GNU sed and Mac OSX sed
109
112
if [[ $( uname -s) == ' Darwin' ]]; then
@@ -117,13 +120,14 @@ install_test_suite() {
117
120
# set up testing suite
118
121
mkdir -p $WP_TESTS_DIR
119
122
rm -rf $WP_TESTS_DIR /{includes,data}
123
+ check_svn_installed
120
124
svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/includes/ $WP_TESTS_DIR /includes
121
125
svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/data/ $WP_TESTS_DIR /data
122
126
fi
123
127
124
- # Configure wp-tests-config.php
125
128
if [ ! -f wp-tests-config.php ]; then
126
129
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
127
131
WP_CORE_DIR=$( echo $WP_CORE_DIR | sed " s:/\+$::" )
128
132
sed $ioption " s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR /':" " $WP_TESTS_DIR " /wp-tests-config.php
129
133
sed $ioption " s:__DIR__ . '/src/':'$WP_CORE_DIR /':" " $WP_TESTS_DIR " /wp-tests-config.php
@@ -132,9 +136,9 @@ install_test_suite() {
132
136
sed $ioption " s/yourpasswordhere/$DB_PASS /" " $WP_TESTS_DIR " /wp-tests-config.php
133
137
sed $ioption " s|localhost|${DB_HOST} |" " $WP_TESTS_DIR " /wp-tests-config.php
134
138
fi
139
+
135
140
}
136
141
137
- # Recreate the database if needed
138
142
recreate_db () {
139
143
shopt -s nocasematch
140
144
if [[ $1 =~ ^(y| yes)$ ]]
@@ -148,12 +152,10 @@ recreate_db() {
148
152
shopt -u nocasematch
149
153
}
150
154
151
- # Create the database
152
155
create_db () {
153
156
mysqladmin create $DB_NAME --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
154
157
}
155
158
156
- # Install the test database
157
159
install_db () {
158
160
159
161
if [ ${SKIP_DB_CREATE} = " true" ]; then
@@ -187,7 +189,6 @@ install_db() {
187
189
fi
188
190
}
189
191
190
- # Run the installation functions
191
192
install_wp
192
193
install_test_suite
193
194
install_db
0 commit comments