diff options
author | Andrew Nacin <nacin@git.wordpress.org> | 2013-08-29 18:39:34 +0000 |
---|---|---|
committer | Andrew Nacin <nacin@git.wordpress.org> | 2013-08-29 18:39:34 +0000 |
commit | 8045afd81b7c80f6ef5b327c115a5bbb43e4b65c (patch) | |
tree | 15d457007610c451577debda89bd9e9cd3d74551 /tests/phpunit/includes/bootstrap.php | |
parent | d34baebc1d8111c9c1014e11001957face778e52 (diff) | |
download | wordpress-8045afd81b7c80f6ef5b327c115a5bbb43e4b65c.tar.gz wordpress-8045afd81b7c80f6ef5b327c115a5bbb43e4b65c.zip |
Move PHPUnit tests into a tests/phpunit directory.
wp-tests-config.php can/should reside in the root of a develop checkout. `phpunit` should be run from the root.
see #25088.
git-svn-id: https://develop.svn.wordpress.org/trunk@25165 602fd350-edb4-49c9-b593-d223f7449a82
Diffstat (limited to 'tests/phpunit/includes/bootstrap.php')
-rw-r--r-- | tests/phpunit/includes/bootstrap.php | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php new file mode 100644 index 0000000000..b73dd4e09c --- /dev/null +++ b/tests/phpunit/includes/bootstrap.php @@ -0,0 +1,135 @@ +<?php +/** + * Installs WordPress for running the tests and loads WordPress and the test libraries + */ + + +$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 ) ); +} +$config_file_path .= '/wp-tests-config.php'; + +/* + * Globalize some WordPress variables, because PHPUnit loads this file inside a function + * See: https://github.com/sebastianbergmann/phpunit/issues/325 + */ +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; + +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; +$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' ); +$phpmailer = new MockPHPMailer(); + +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 ); + define( 'DOMAIN_CURRENT_SITE', WP_TESTS_DOMAIN ); + define( 'PATH_CURRENT_SITE', '/' ); + define( 'SITE_ID_CURRENT_SITE', 1 ); + define( 'BLOG_ID_CURRENT_SITE', 1 ); + $GLOBALS['base'] = '/'; +} else { + echo "Running as single site... To run multisite, use -c multisite.xml" . PHP_EOL; +} +unset( $multisite ); + +require_once dirname( __FILE__ ) . '/functions.php'; + +// 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'; +require dirname( __FILE__ ) . '/exceptions.php'; +require dirname( __FILE__ ) . '/utils.php'; + +/** + * A child class of the PHP test runner. + * + * Not actually used as a runner. Rather, used to access the protected + * longOptions property, to parse the arguments passed to the script. + * + * 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. + */ +class WP_PHPUnit_TextUI_Command extends PHPUnit_TextUI_Command { + function __construct( $argv ) { + $options = PHPUnit_Util_Getopt::getopt( + $argv, + 'd:c:hv', + array_keys( $this->longOptions ) + ); + $ajax_message = true; + foreach ( $options[0] as $option ) { + switch ( $option[0] ) { + case '--exclude-group' : + $ajax_message = false; + continue 2; + case '--group' : + $groups = explode( ',', $option[1] ); + foreach ( $groups as $group ) { + if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) ) + WP_UnitTestCase::forceTicket( $group ); + } + $ajax_message = ! in_array( 'ajax', $groups ); + continue 2; + } + } + if ( $ajax_message ) + echo "Not running ajax tests... To execute these, use --group ajax." . PHP_EOL; + } +} +new WP_PHPUnit_TextUI_Command( $_SERVER['argv'] ); |