Permalink
Browse files

Use test framework from same branch as WP install

  • Loading branch information...
1 parent 9623181 commit 9cad3f36c1e0c49ca0ab179c632072ba02c0f12d @keesiemeijer committed Oct 7, 2015
Showing with 118 additions and 29 deletions.
  1. +102 −27 bin/install-wp-tests.sh
  2. +1 −2 tests/bootstrap.php
  3. +5 −0 tests/test-cache.php
  4. +10 −0 tests/test-functions-thumbnail.php
@@ -9,47 +9,126 @@ DB_NAME=$1
DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}
-WP_VERSION=${5-master}
+WP_VERSION=${5-latest}
-WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
-WP_CORE_DIR=/tmp/wordpress/
+WP_TESTS_DIR=/tmp/wordpress-tests-lib
+WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
+
+#remove trailing slash
+WP_CORE_DIR=${WP_CORE_DIR%/}
set -ex
+download() {
+ if [ `which curl` ]; then
+ curl -s "$1" > "$2";
+ elif [ `which wget` ]; then
+ wget -nv -O "$2" "$1"
+ fi
+}
+
+wp_core_version(){
+ local version='trunk'
+
+ if [ -f $WP_CORE_DIR/wp-includes/version.php ]; then
+ if grep -q "wp_version = " $WP_CORE_DIR/wp-includes/version.php; then
+ version=$(grep "wp_version = " $WP_CORE_DIR/wp-includes/version.php|awk -F\' '{print $2}')
+ fi
+ fi
+
+ echo $version
+}
+
+wp_api_version(){
+ local latest=''
+ local api_url="http://api.wordpress.org/core/version-check/1.5/"
+
+ if [ `which curl` ]; then
+ latest=$(curl -s "$api_url" | head -n 4 | tail -n 1)
+ elif [ `which wget` ]; then
+ latest=$(wget -S -q -O - "$api_url" | head -n 4 | tail -n 1);
+ fi
+
+ echo $latest
+}
+
+wp_download_exists(){
+ if [ `which curl` ]; then
+ $(curl --output /dev/null --silent --head --fail "$1");
+ elif [ `which wget` ]; then
+ $(wget --spider $1 >/dev/null 2>&1);
+ fi
+}
+
install_wp() {
- mkdir -p $WP_CORE_DIR
- if [ $WP_VERSION == 'latest' ]; then
- local ARCHIVE_NAME='latest'
+ if [ $WP_VERSION == 'latest' ]; then
+
+ local archive_name='latest'
+ local latest=$(wp_api_version)
+ local url=https://wordpress.org/"wordpress-$latest".tar.gz
+
+ # check if latest version exists
+ if wp_download_exists $url; then
+ WP_VERSION=$latest
+ archive_name="wordpress-$latest"
+ fi
else
- local ARCHIVE_NAME="wordpress-$WP_VERSION"
+ local archive_name="wordpress-$WP_VERSION"
+ fi
+
+ local core_version=$(wp_core_version)
+
+ if [ $core_version != 'trunk' ]; then
+ if [ $core_version == $WP_VERSION ]; then
+ return
+ fi
fi
- wget -nv -O /tmp/wordpress.tar.gz http://wordpress.org/${ARCHIVE_NAME}.tar.gz
- tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
+ mkdir -p $WP_CORE_DIR
+
+ if wp_download_exists "https://wordpress.org/${archive_name}.tar.gz"; then
- wget -nv -O $WP_CORE_DIR/wp-content/db.php https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
+ download https://wordpress.org/${archive_name}.tar.gz /tmp/wordpress.tar.gz
+ tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C "$WP_CORE_DIR"
+
+ download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php "$WP_CORE_DIR/wp-content/db.php"
+ else
+ echo "Error: WordPress version not found."
+ exit
+ fi
}
install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
- local ioption='-i ""'
+ local ioption='-i .bak'
else
local ioption='-i'
fi
- # set up testing suite
+ # get the version from the installed WordPress version
+ local core_version=$(wp_core_version)
+
+ if [ $core_version != 'trunk' ]; then
+ core_version="tags/"$core_version
+ fi
+
+ # Set up the testing suite from the core version
mkdir -p $WP_TESTS_DIR
- cd $WP_TESTS_DIR
- svn co --quiet http://develop.svn.wordpress.org/trunk/tests/phpunit/includes/
-
- wget -nv -O wp-tests-config.php http://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php
- sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" wp-tests-config.php
- sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" wp-tests-config.php
- sed $ioption "s/yourusernamehere/$DB_USER/" wp-tests-config.php
- sed $ioption "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php
- sed $ioption "s|localhost|${DB_HOST}|" wp-tests-config.php
+
+ if wp_download_exists "https://develop.svn.wordpress.org/$core_version/wp-tests-config-sample.php"; then
+
+ svn export --quiet --force https://develop.svn.wordpress.org/$core_version/tests/phpunit/includes/ $WP_TESTS_DIR/includes
+ cd $WP_TESTS_DIR
+
+ download https://develop.svn.wordpress.org/$core_version/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
+ sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
+ sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
+ sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
+ sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
+ sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
+ fi
}
install_db() {
@@ -60,7 +139,7 @@ install_db() {
local EXTRA=""
if ! [ -z $DB_HOSTNAME ] ; then
- if [[ "$DB_SOCK_OR_PORT" =~ ^[0-9]+$ ]] ; then
+ if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
@@ -71,12 +150,8 @@ install_db() {
# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
-
- # alternative way to create the database
- # mysql -u root --password=root -e "CREATE DATABASE IF NOT EXISTS \`$DB_NAME\`"
- # mysql -u root --password=root -e "GRANT ALL PRIVILEGES ON \`$DB_NAME\`.* TO $DB_USER@$DB_HOSTNAME IDENTIFIED BY '$DB_PASS';"
}
install_wp
install_test_suite
-install_db
+install_db
View
@@ -1,8 +1,7 @@
<?php
define( 'KM_RPBT_TEST_OUTPUT', true );
-$_tests_dir = getenv( 'WP_TESTS_DIR' );
-if ( !$_tests_dir ) $_tests_dir = '/tmp/wordpress-tests-lib';
+$_tests_dir = '/tmp/wordpress-tests-lib';
require_once $_tests_dir . '/includes/functions.php';
@@ -26,6 +26,11 @@ function setUp() {
$this->utils = new RPBT_Test_Utils( $this->factory );
}
+ function tearDown(){
+ // use tearDown for WP < 4.0
+ remove_filter( 'related_posts_by_taxonomy_cache', '__return_true' );
+ }
+
function setup_cache() {
// Activate cache
@@ -24,6 +24,14 @@ function setUp() {
}
+ function tearDown(){
+ // use tearDown for WP < 4.0
+ remove_filter( 'use_default_gallery_style', '__return_false', 99 );
+ remove_filter( 'use_default_gallery_style', '__return_true', 99 );
+ remove_filter( 'related_posts_by_taxonomy_post_thumbnail_link', array( $this, 'add_image' ), 99, 4 );
+ }
+
+
/**
* Test output from gallery.
*
@@ -117,6 +125,8 @@ function test_shortcode_gallery_no_caption() {
$gallery_args = $this->setup_gallery();
extract( $gallery_args );
$args['caption'] = '';
+
+ //
add_filter( 'use_default_gallery_style', '__return_false', 99 );
ob_start();
echo km_rpbt_related_posts_by_taxonomy_gallery( $args, array( $related_post ) );

1 comment on commit 9cad3f3

@keesiemeijer
Owner

See this pull request why a change was necessary.

Please sign in to comment.