Skip to content
This repository was archived by the owner on Dec 5, 2023. It is now read-only.

Commit a409c8b

Browse files
committed
test files
1 parent e34629b commit a409c8b

File tree

6 files changed

+235
-0
lines changed

6 files changed

+235
-0
lines changed

.travis.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
language: php
2+
3+
notifications:
4+
email:
5+
on_success: never
6+
on_failure: change
7+
8+
branches:
9+
only:
10+
- master
11+
12+
php:
13+
- 5.3
14+
- 5.6
15+
16+
env:
17+
- WP_VERSION=latest WP_MULTISITE=0
18+
19+
matrix:
20+
include:
21+
- php: 5.3
22+
env: WP_VERSION=latest WP_MULTISITE=1
23+
24+
before_script:
25+
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
26+
- export PATH="$HOME/.composer/vendor/bin:$PATH"
27+
- |
28+
if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.0" ]]; then
29+
composer global require "phpunit/phpunit=5.6.*"
30+
else
31+
composer global require "phpunit/phpunit=4.8.*"
32+
fi
33+
- |
34+
composer global require wp-coding-standards/wpcs
35+
phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs
36+
37+
script:
38+
- phpcs --standard=phpcs.ruleset.xml $(find . -name '*.php')
39+
- phpunit

bin/install-wp-tests.sh

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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] [skip-database-creation]"
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+
SKIP_DB_CREATE=${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+
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
29+
WP_TESTS_TAG="trunk"
30+
else
31+
# http serves a single offer, whereas https serves multiple. we only want one
32+
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
33+
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
34+
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
35+
if [[ -z "$LATEST_VERSION" ]]; then
36+
echo "Latest WordPress version could not be found"
37+
exit 1
38+
fi
39+
WP_TESTS_TAG="tags/$LATEST_VERSION"
40+
fi
41+
42+
set -ex
43+
44+
install_wp() {
45+
46+
if [ -d $WP_CORE_DIR ]; then
47+
return;
48+
fi
49+
50+
mkdir -p $WP_CORE_DIR
51+
52+
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
53+
mkdir -p /tmp/wordpress-nightly
54+
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
55+
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
56+
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
57+
else
58+
if [ $WP_VERSION == 'latest' ]; then
59+
local ARCHIVE_NAME='latest'
60+
else
61+
local ARCHIVE_NAME="wordpress-$WP_VERSION"
62+
fi
63+
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
64+
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
65+
fi
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+
# portable in-place argument for both GNU sed and Mac OSX sed
72+
if [[ $(uname -s) == 'Darwin' ]]; then
73+
local ioption='-i .bak'
74+
else
75+
local ioption='-i'
76+
fi
77+
78+
# set up testing suite if it doesn't yet exist
79+
if [ ! -d $WP_TESTS_DIR ]; then
80+
# set up testing suite
81+
mkdir -p $WP_TESTS_DIR
82+
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
83+
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
84+
fi
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+
# remove all forward slashes in the end
89+
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
90+
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
91+
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
92+
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
93+
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
94+
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
95+
fi
96+
97+
}
98+
99+
install_db() {
100+
101+
if [ ${SKIP_DB_CREATE} = "true" ]; then
102+
return 0
103+
fi
104+
105+
# parse DB_HOST for port or socket references
106+
local PARTS=(${DB_HOST//\:/ })
107+
local DB_HOSTNAME=${PARTS[0]};
108+
local DB_SOCK_OR_PORT=${PARTS[1]};
109+
local EXTRA=""
110+
111+
if ! [ -z $DB_HOSTNAME ] ; then
112+
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
113+
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
114+
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
115+
EXTRA=" --socket=$DB_SOCK_OR_PORT"
116+
elif ! [ -z $DB_HOSTNAME ] ; then
117+
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
118+
fi
119+
fi
120+
121+
# create database
122+
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
123+
}
124+
125+
install_wp
126+
install_test_suite
127+
install_db

phpcs.ruleset.xml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="WordPress Coding Standards for Plugins">
3+
<description>Generally-applicable sniffs for WordPress plugins</description>
4+
5+
<rule ref="WordPress-Core" />
6+
<rule ref="WordPress-Docs" />
7+
8+
<exclude-pattern>*/node_modules/*</exclude-pattern>
9+
<exclude-pattern>*/vendor/*</exclude-pattern>
10+
</ruleset>

phpunit.xml.dist

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<phpunit
2+
bootstrap="tests/bootstrap.php"
3+
backupGlobals="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
>
9+
<testsuites>
10+
<testsuite>
11+
<directory prefix="test-" suffix=".php">./tests/</directory>
12+
</testsuite>
13+
</testsuites>
14+
</phpunit>

tests/bootstrap.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* PHPUnit bootstrap file
4+
*
5+
* @package Wp_Deploybot_Api
6+
*/
7+
8+
$_tests_dir = getenv( 'WP_TESTS_DIR' );
9+
if ( ! $_tests_dir ) {
10+
$_tests_dir = '/tmp/wordpress-tests-lib';
11+
}
12+
13+
// Give access to tests_add_filter() function.
14+
require_once $_tests_dir . '/includes/functions.php';
15+
16+
/**
17+
* Manually load the plugin being tested.
18+
*/
19+
function _manually_load_plugin() {
20+
require dirname( dirname( __FILE__ ) ) . '/wp-deploybot-api.php';
21+
}
22+
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
23+
24+
// Start up the WP testing environment.
25+
require $_tests_dir . '/includes/bootstrap.php';

tests/test-sample.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Class SampleTest
4+
*
5+
* @package Wp_Deploybot_Api
6+
*/
7+
8+
/**
9+
* Sample test case.
10+
*/
11+
class SampleTest extends WP_UnitTestCase {
12+
13+
/**
14+
* A single example test.
15+
*/
16+
function test_sample() {
17+
// Replace this with some actual testing code.
18+
$this->assertTrue( true );
19+
}
20+
}

0 commit comments

Comments
 (0)