Skip to content

Commit bf0fcbe

Browse files
authored
Add tests (afragen#11)
1 parent d33fbbc commit bf0fcbe

29 files changed

+5176
-1
lines changed

.editorconfig

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
# WordPress Coding Standards
5+
# https://make.wordpress.org/core/handbook/coding-standards/
6+
7+
root = true
8+
9+
[*]
10+
charset = utf-8
11+
end_of_line = lf
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
indent_style = tab
15+
16+
[*.yml]
17+
indent_style = space
18+
indent_size = 2
19+
20+
[*.md]
21+
trim_trailing_whitespace = false
22+
23+
[*.txt]
24+
end_of_line = crlf

.gitattributes

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
* text=auto
2+
3+
.gitattributes export-ignore
4+
.gitignore export-ignore
5+
.editorconfig export-ignore
6+
composer.lock export-ignore
7+
phpunit.xml export-ignore
8+
/.github export-ignore
9+
/bin export-ignore
10+
/tests export-ignore

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
.idea
3+
.vscode
4+
5+
vendor
6+
phpcs.xml
7+
phpunit.xml
8+
tests/phpunit/cache
9+
tests/phpunit/coverage
10+
.phpunit.result.cache

Lite.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function run() {
8181
return;
8282
}
8383

84-
if ( null === $this->update_server ) {
84+
if ( empty( $this->update_server ) ) {
8585
return new \WP_Error( 'no_domain', 'No update server domain' );
8686
}
8787
$url = "$this->update_server/wp-json/git-updater/v1/update-api/?slug=$this->slug";
@@ -310,6 +310,7 @@ public function customize_theme_update_html( $prepared_themes ) {
310310
* @author Seth Carstens
311311
*
312312
* @access protected
313+
* @codeCoverageIgnore
313314
*
314315
* @param \stdClass $theme Theme object.
315316
*

bin/install-wp-tests.sh

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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]"
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+
14+
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
15+
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
16+
17+
download() {
18+
if [ `which curl` ]; then
19+
curl -s "$1" > "$2";
20+
elif [ `which wget` ]; then
21+
wget -nv -O "$2" "$1"
22+
fi
23+
}
24+
25+
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
26+
WP_TESTS_TAG="tags/$WP_VERSION"
27+
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
28+
WP_TESTS_TAG="trunk"
29+
else
30+
# http serves a single offer, whereas https serves multiple. we only want one
31+
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
32+
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
33+
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
34+
if [[ -z "$LATEST_VERSION" ]]; then
35+
echo "Latest WordPress version could not be found"
36+
exit 1
37+
fi
38+
WP_TESTS_TAG="tags/$LATEST_VERSION"
39+
fi
40+
41+
set -ex
42+
43+
install_wp() {
44+
45+
if [ -d $WP_CORE_DIR ]; then
46+
return;
47+
fi
48+
49+
mkdir -p $WP_CORE_DIR
50+
51+
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
56+
else
57+
if [ $WP_VERSION == 'latest' ]; then
58+
local ARCHIVE_NAME='latest'
59+
else
60+
local ARCHIVE_NAME="wordpress-$WP_VERSION"
61+
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
64+
fi
65+
66+
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
67+
}
68+
69+
install_test_suite() {
70+
# portable in-place argument for both GNU sed and Mac OSX sed
71+
if [[ $(uname -s) == 'Darwin' ]]; then
72+
local ioption='-i .bak'
73+
else
74+
local ioption='-i'
75+
fi
76+
77+
# set up testing suite if it doesn't yet exist
78+
if [ ! -d $WP_TESTS_DIR ]; then
79+
# set up testing suite
80+
mkdir -p $WP_TESTS_DIR
81+
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
82+
fi
83+
84+
cd $WP_TESTS_DIR
85+
86+
if [ ! -f wp-tests-config.php ]; then
87+
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
89+
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
90+
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
91+
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
92+
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
93+
fi
94+
95+
}
96+
97+
install_db() {
98+
# parse DB_HOST for port or socket references
99+
local PARTS=(${DB_HOST//\:/ })
100+
local DB_HOSTNAME=${PARTS[0]};
101+
local DB_SOCK_OR_PORT=${PARTS[1]};
102+
local EXTRA=""
103+
104+
if ! [ -z $DB_HOSTNAME ] ; then
105+
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
106+
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
107+
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
108+
EXTRA=" --socket=$DB_SOCK_OR_PORT"
109+
elif ! [ -z $DB_HOSTNAME ] ; then
110+
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
111+
fi
112+
fi
113+
114+
# create database
115+
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
116+
}
117+
118+
install_gu() {
119+
if [ -d "${WP_CORE_DIR}wp-content/plugins/git-updater" ]; then
120+
return;
121+
fi
122+
123+
local LATEST_GU_ZIP=$(curl -s https://api.github.com/repos/afragen/git-updater/releases/latest | grep browser_download_url | cut -d '"' -f 4)
124+
curl -L $LATEST_GU_ZIP > ${WP_CORE_DIR}wp-content/plugins/git-updater.zip
125+
unzip -q ${WP_CORE_DIR}wp-content/plugins/git-updater.zip -d ${WP_CORE_DIR}wp-content/plugins
126+
}
127+
128+
install_wp
129+
install_test_suite
130+
install_db
131+
install_gu

composer.json

+10
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,15 @@
3232
"classmap": [
3333
"Lite.php"
3434
]
35+
},
36+
"require-dev": {
37+
"squizlabs/php_codesniffer": "3.10.3",
38+
"wp-coding-standards/wpcs": "~3.1.0",
39+
"yoast/phpunit-polyfills": "^1.1.0"
40+
},
41+
"config": {
42+
"allow-plugins": {
43+
"dealerdirect/phpcodesniffer-composer-installer": true
44+
}
3545
}
3646
}

0 commit comments

Comments
 (0)