2013-08-07 08:38:38 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Installs WordPress for running the tests and loads WordPress and the test libraries
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-08-29 20:39:34 +02:00
|
|
|
$config_file_path = dirname( dirname( __FILE__ ) );
|
|
|
|
if ( ! file_exists( $config_file_path . '/wp-tests-config.php' ) ) {
|
|
|
|
// Support the config file from the root of the develop repository.
|
|
|
|
if ( basename( $config_file_path ) === 'phpunit' && basename( dirname( $config_file_path ) ) === 'tests' )
|
|
|
|
$config_file_path = dirname( dirname( $config_file_path ) );
|
2013-08-07 12:09:35 +02:00
|
|
|
}
|
2013-08-29 20:39:34 +02:00
|
|
|
$config_file_path .= '/wp-tests-config.php';
|
2013-08-07 08:38:38 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Globalize some WordPress variables, because PHPUnit loads this file inside a function
|
|
|
|
* See: https://github.com/sebastianbergmann/phpunit/issues/325
|
2013-08-29 20:39:34 +02:00
|
|
|
*/
|
2013-08-07 08:38:38 +02:00
|
|
|
global $wpdb, $current_site, $current_blog, $wp_rewrite, $shortcode_tags, $wp, $phpmailer;
|
|
|
|
|
|
|
|
if ( !is_readable( $config_file_path ) ) {
|
|
|
|
die( "ERROR: wp-tests-config.php is missing! Please use wp-tests-config-sample.php to create a config file.\n" );
|
|
|
|
}
|
|
|
|
require_once $config_file_path;
|
|
|
|
|
2014-07-01 20:51:46 +02:00
|
|
|
define( 'WP_TESTS_TABLE_PREFIX', $table_prefix );
|
2013-08-07 08:38:38 +02:00
|
|
|
define( 'DIR_TESTDATA', dirname( __FILE__ ) . '/../data' );
|
|
|
|
|
|
|
|
if ( ! defined( 'WP_TESTS_FORCE_KNOWN_BUGS' ) )
|
|
|
|
define( 'WP_TESTS_FORCE_KNOWN_BUGS', false );
|
|
|
|
|
|
|
|
// Cron tries to make an HTTP request to the blog, which always fails, because tests are run in CLI mode only
|
|
|
|
define( 'DISABLE_WP_CRON', true );
|
|
|
|
|
|
|
|
define( 'WP_MEMORY_LIMIT', -1 );
|
|
|
|
define( 'WP_MAX_MEMORY_LIMIT', -1 );
|
|
|
|
|
|
|
|
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
|
|
|
|
$_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN;
|
2015-06-16 02:03:25 +02:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
2015-09-15 10:04:33 +02:00
|
|
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
2013-08-07 08:38:38 +02:00
|
|
|
$PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php';
|
|
|
|
|
|
|
|
if ( "1" == getenv( 'WP_MULTISITE' ) ||
|
|
|
|
( defined( 'WP_TESTS_MULTISITE') && WP_TESTS_MULTISITE ) ) {
|
|
|
|
$multisite = true;
|
|
|
|
} else {
|
|
|
|
$multisite = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Override the PHPMailer
|
|
|
|
require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
|
2014-06-21 21:59:28 +02:00
|
|
|
$phpmailer = new MockPHPMailer();
|
2013-08-07 08:38:38 +02:00
|
|
|
|
|
|
|
system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite );
|
|
|
|
|
|
|
|
if ( $multisite ) {
|
|
|
|
echo "Running as multisite..." . PHP_EOL;
|
|
|
|
define( 'MULTISITE', true );
|
|
|
|
define( 'SUBDOMAIN_INSTALL', false );
|
|
|
|
$GLOBALS['base'] = '/';
|
|
|
|
} else {
|
2013-09-12 23:04:16 +02:00
|
|
|
echo "Running as single site... To run multisite, use -c tests/phpunit/multisite.xml" . PHP_EOL;
|
2013-08-07 08:38:38 +02:00
|
|
|
}
|
|
|
|
unset( $multisite );
|
|
|
|
|
|
|
|
require_once dirname( __FILE__ ) . '/functions.php';
|
|
|
|
|
2014-06-21 21:59:28 +02:00
|
|
|
$GLOBALS['_wp_die_disabled'] = false;
|
|
|
|
// Allow tests to override wp_die
|
|
|
|
tests_add_filter( 'wp_die_handler', '_wp_die_handler_filter' );
|
|
|
|
|
2013-08-07 08:38:38 +02:00
|
|
|
// Preset WordPress options defined in bootstrap file.
|
|
|
|
// Used to activate themes, plugins, as well as other settings.
|
|
|
|
if(isset($GLOBALS['wp_tests_options'])) {
|
|
|
|
function wp_tests_options( $value ) {
|
|
|
|
$key = substr( current_filter(), strlen( 'pre_option_' ) );
|
|
|
|
return $GLOBALS['wp_tests_options'][$key];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( array_keys( $GLOBALS['wp_tests_options'] ) as $key ) {
|
|
|
|
tests_add_filter( 'pre_option_'.$key, 'wp_tests_options' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load WordPress
|
|
|
|
require_once ABSPATH . '/wp-settings.php';
|
|
|
|
|
|
|
|
// Delete any default posts & related data
|
|
|
|
_delete_all_posts();
|
|
|
|
|
|
|
|
require dirname( __FILE__ ) . '/testcase.php';
|
|
|
|
require dirname( __FILE__ ) . '/testcase-xmlrpc.php';
|
|
|
|
require dirname( __FILE__ ) . '/testcase-ajax.php';
|
2014-11-08 20:28:12 +01:00
|
|
|
require dirname( __FILE__ ) . '/testcase-canonical.php';
|
2013-08-07 08:38:38 +02:00
|
|
|
require dirname( __FILE__ ) . '/exceptions.php';
|
|
|
|
require dirname( __FILE__ ) . '/utils.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A child class of the PHP test runner.
|
|
|
|
*
|
2013-12-27 16:07:07 +01:00
|
|
|
* Used to access the protected longOptions property, to parse the arguments
|
|
|
|
* passed to the script.
|
2013-08-07 08:38:38 +02:00
|
|
|
*
|
|
|
|
* If it is determined that phpunit was called with a --group that corresponds
|
|
|
|
* to an @ticket annotation (such as `phpunit --group 12345` for bugs marked
|
|
|
|
* as #WP12345), then it is assumed that known bugs should not be skipped.
|
|
|
|
*
|
|
|
|
* If WP_TESTS_FORCE_KNOWN_BUGS is already set in wp-tests-config.php, then
|
|
|
|
* how you call phpunit has no effect.
|
|
|
|
*/
|
2013-12-27 16:07:07 +01:00
|
|
|
class WP_PHPUnit_Util_Getopt extends PHPUnit_Util_Getopt {
|
|
|
|
protected $longOptions = array(
|
|
|
|
'exclude-group=',
|
|
|
|
'group=',
|
|
|
|
);
|
2013-08-07 08:38:38 +02:00
|
|
|
function __construct( $argv ) {
|
2013-12-27 16:07:07 +01:00
|
|
|
array_shift( $argv );
|
|
|
|
$options = array();
|
|
|
|
while ( list( $i, $arg ) = each( $argv ) ) {
|
|
|
|
try {
|
|
|
|
if ( strlen( $arg ) > 1 && $arg[0] === '-' && $arg[1] === '-' ) {
|
|
|
|
PHPUnit_Util_Getopt::parseLongOption( substr( $arg, 2 ), $this->longOptions, $options, $argv );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch ( PHPUnit_Framework_Exception $e ) {
|
|
|
|
// Enforcing recognized arguments or correctly formed arguments is
|
|
|
|
// not really the concern here.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-10 15:48:28 +01:00
|
|
|
$skipped_groups = array(
|
|
|
|
'ajax' => true,
|
|
|
|
'ms-files' => true,
|
|
|
|
'external-http' => true,
|
|
|
|
);
|
|
|
|
|
2013-12-27 16:07:07 +01:00
|
|
|
foreach ( $options as $option ) {
|
2013-08-07 08:38:38 +02:00
|
|
|
switch ( $option[0] ) {
|
|
|
|
case '--exclude-group' :
|
2014-11-10 15:48:28 +01:00
|
|
|
foreach ( $skipped_groups as $group_name => $skipped ) {
|
|
|
|
$skipped_groups[ $group_name ] = false;
|
|
|
|
}
|
2013-08-07 08:38:38 +02:00
|
|
|
continue 2;
|
|
|
|
case '--group' :
|
|
|
|
$groups = explode( ',', $option[1] );
|
|
|
|
foreach ( $groups as $group ) {
|
2013-12-27 16:07:07 +01:00
|
|
|
if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) ) {
|
2013-08-07 08:38:38 +02:00
|
|
|
WP_UnitTestCase::forceTicket( $group );
|
2013-12-27 16:07:07 +01:00
|
|
|
}
|
2013-08-07 08:38:38 +02:00
|
|
|
}
|
2014-11-10 15:48:28 +01:00
|
|
|
|
|
|
|
foreach ( $skipped_groups as $group_name => $skipped ) {
|
|
|
|
if ( in_array( $group_name, $groups ) ) {
|
|
|
|
$skipped_groups[ $group_name ] = false;
|
|
|
|
}
|
|
|
|
}
|
2013-08-07 08:38:38 +02:00
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
}
|
2014-11-10 15:48:28 +01:00
|
|
|
|
|
|
|
$skipped_groups = array_filter( $skipped_groups );
|
|
|
|
foreach ( $skipped_groups as $group_name => $skipped ) {
|
|
|
|
echo sprintf( 'Not running %1$s tests. To execute these, use --group %1$s.', $group_name ) . PHP_EOL;
|
2014-11-08 22:07:05 +01:00
|
|
|
}
|
2015-10-06 05:36:18 +02:00
|
|
|
|
|
|
|
if ( ! isset( $skipped_groups['external-http'] ) ){
|
|
|
|
echo PHP_EOL;
|
|
|
|
echo 'External HTTP skipped tests can be caused by timeouts.' . PHP_EOL;
|
|
|
|
echo 'If this changeset inclues changes to HTTP, make sure there are no timeouts.' . PHP_EOL;
|
|
|
|
echo PHP_EOL;
|
|
|
|
}
|
2013-08-07 08:38:38 +02:00
|
|
|
}
|
|
|
|
}
|
2013-12-27 16:07:07 +01:00
|
|
|
new WP_PHPUnit_Util_Getopt( $_SERVER['argv'] );
|