Permalink
Browse files

some very rough tests-related code to get something going

  • Loading branch information...
zytzagoo committed Dec 3, 2015
1 parent ee4b613 commit 6f54ba92192a764b758d9581e5e28b4fdac3c2cb
Showing with 74,150 additions and 28 deletions.
  1. +23 −0 .travis.yml
  2. +18 −7 autoptimize.php
  3. +119 −0 bin/install-wp-tests.sh
  4. +31 −21 classes/autoptimizeConfig.php
  5. +21 −0 classes/autoptimizeStyles.php
  6. +73,595 −0 phpunit.phar
  7. +14 −0 phpunit.xml
  8. +35 −0 tests/bootstrap.php
  9. +294 −0 tests/test-ao.php
View
@@ -0,0 +1,23 @@
language: php
notifications:
email:
on_success: never
on_failure: change
php:
- 5.3
- 5.6
env:
- WP_VERSION=latest WP_MULTISITE=0
matrix:
include:
- php: 5.3
env: WP_VERSION=latest WP_MULTISITE=1
before_script:
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
script: phpunit
View
@@ -43,6 +43,8 @@
define( 'AUTOPTIMIZE_CACHE_DELAY', true );
define( 'WP_ROOT_DIR', str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', WP_CONTENT_DIR ) );
// define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() );
// Initialize the cache at least once
$conf = autoptimizeConfig::instance();
@@ -149,7 +151,8 @@ function autoptimize_do_buffering() {
}
}
// If not a feed or in admin and not explicitly turned off
// We only buffer the frontend requests (and then only if not a feed and not turned off explicitly)
// TODO/FIXME: Tests throw a notice here since we're calling is_feed() without the main query being ran
$do_buffering = ( ! is_admin() && ! is_feed() && ! $ao_noptimize );
}
@@ -221,12 +224,20 @@ function autoptimize_end_buffering($content) {
}
// load URL constants as late as possible to allow domain mapper to kick in
if ( function_exists( 'domain_mapping_siteurl' ) ) {
define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) );
define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) );
} else {
define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() );
define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() );
// (but do so only if they haven't been defined already)
if ( ! defined( 'AUTOPTIMIZE_WP_SITE_URL' ) ) {
if ( function_exists( 'domain_mapping_siteurl' ) ) {
define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) );
} else {
define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() );
}
}
if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_URL' ) ) {
if ( function_exists( 'domain_mapping_siteurl' ) ) {
define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) );
} else {
define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() );
}
}
if ( is_multisite() ) {
View
@@ -0,0 +1,119 @@
#!/usr/bin/env bash
if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
exit 1
fi
DB_NAME=$1
DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}
WP_VERSION=${5-latest}
WP_TESTS_DIR=${WP_TESTS_DIR-C:/tmp/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-C:/tmp/wordpress/}
download() {
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
fi
}
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
WP_TESTS_TAG="tags/$WP_VERSION"
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
WP_TESTS_TAG="trunk"
else
# http serves a single offer, whereas https serves multiple. we only want one
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
if [[ -z "$LATEST_VERSION" ]]; then
echo "Latest WordPress version could not be found"
exit 1
fi
WP_TESTS_TAG="tags/$LATEST_VERSION"
fi
set -ex
install_wp() {
if [ -d $WP_CORE_DIR ]; then
return;
fi
mkdir -p $WP_CORE_DIR
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
mkdir -p /tmp/wordpress-nightly
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
else
if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi
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
fi
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
}
install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i .bak'
else
local ioption='-i'
fi
# set up testing suite if it doesn't yet exist
if [ ! -d $WP_TESTS_DIR ]; then
# set up testing suite
mkdir -p $WP_TESTS_DIR
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
fi
cd $WP_TESTS_DIR
if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/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() {
# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
local EXTRA=""
if ! [ -z $DB_HOSTNAME ] ; 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"
elif ! [ -z $DB_HOSTNAME ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
fi
fi
# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
}
install_wp
install_test_suite
install_db
@@ -439,31 +439,41 @@ public function setmeta($links, $file = null)
return $links;
}
/**
* @return array
*/
public static function get_defaults()
{
static $config = array(
'autoptimize_html' => 0,
'autoptimize_html_keepcomments' => 0,
'autoptimize_js' => 0,
'autoptimize_js_exclude' => 's_sid, smowtion_size, sc_project, WAU_, wau_add, comment-form-quicktags, edToolbar, ch_client, seal.js',
'autoptimize_js_trycatch' => 0,
'autoptimize_js_justhead' => 0,
'autoptimize_js_include_inline' => 0,
'autoptimize_js_forcehead' => 1,
'autoptimize_css' => 0,
'autoptimize_css_exclude' => 'admin-bar.min.css, dashicons.min.css',
'autoptimize_css_justhead' => 0,
'autoptimize_css_include_inline' => 0,
'autoptimize_css_defer' => 0,
'autoptimize_css_defer_inline' => '',
'autoptimize_css_inline' => 0,
'autoptimize_css_datauris' => 0,
'autoptimize_cdn_url' => '',
'autoptimize_cache_nogzip' => 1,
'autoptimize_show_adv' => 0
);
return $config;
}
public function get($key)
{
if ( ! is_array( $this->config ) ) {
// Default config
$config = array(
'autoptimize_html' => 0,
'autoptimize_html_keepcomments' => 0,
'autoptimize_js' => 0,
'autoptimize_js_exclude' => 's_sid, smowtion_size, sc_project, WAU_, wau_add, comment-form-quicktags, edToolbar, ch_client, seal.js',
'autoptimize_js_trycatch' => 0,
'autoptimize_js_justhead' => 0,
'autoptimize_js_include_inline' => 0,
'autoptimize_js_forcehead' => 1,
'autoptimize_css' => 0,
'autoptimize_css_exclude' => 'admin-bar.min.css, dashicons.min.css',
'autoptimize_css_justhead' => 0,
'autoptimize_css_include_inline' => 0,
'autoptimize_css_defer' => 0,
'autoptimize_css_defer_inline' => '',
'autoptimize_css_inline' => 0,
'autoptimize_css_datauris' => 0,
'autoptimize_cdn_url' => '',
'autoptimize_cache_nogzip' => 1,
'autoptimize_show_adv' => 0
);
$config = self::get_defaults();
// Override with user settings
foreach ( array_keys( $config ) as $name ) {
@@ -775,4 +775,25 @@ private function ismovable($tag)
return true;
}
}
public function getOptions()
{
return $this->options;
}
public function replaceOptions($options)
{
$this->options = $options;
}
public function setOption($name, $value)
{
$this->options[$name] = $value;
$this->$name = $value;
}
public function getOption($name)
{
return $this->options[$name];
}
}
Oops, something went wrong.

0 comments on commit 6f54ba9

Please sign in to comment.