1 | <?php |
---|
2 | /** |
---|
3 | * Installs WordPress for running the tests and loads WordPress and the test libraries |
---|
4 | */ |
---|
5 | |
---|
6 | |
---|
7 | $config_file_path = dirname( dirname( __FILE__ ) ); |
---|
8 | if ( ! file_exists( $config_file_path . '/wp-tests-config.php' ) ) { |
---|
9 | // Support the config file from the root of the develop repository. |
---|
10 | if ( basename( $config_file_path ) === 'phpunit' && basename( dirname( $config_file_path ) ) === 'tests' ) |
---|
11 | $config_file_path = dirname( dirname( $config_file_path ) ); |
---|
12 | } |
---|
13 | $config_file_path .= '/wp-tests-config.php'; |
---|
14 | |
---|
15 | /* |
---|
16 | * Globalize some WordPress variables, because PHPUnit loads this file inside a function |
---|
17 | * See: https://github.com/sebastianbergmann/phpunit/issues/325 |
---|
18 | */ |
---|
19 | global $wpdb, $current_site, $current_blog, $wp_rewrite, $shortcode_tags, $wp, $phpmailer; |
---|
20 | |
---|
21 | if ( !is_readable( $config_file_path ) ) { |
---|
22 | die( "ERROR: wp-tests-config.php is missing! Please use wp-tests-config-sample.php to create a config file.\n" ); |
---|
23 | } |
---|
24 | require_once $config_file_path; |
---|
25 | |
---|
26 | define( 'DIR_TESTDATA', dirname( __FILE__ ) . '/../data' ); |
---|
27 | |
---|
28 | if ( ! defined( 'WP_TESTS_FORCE_KNOWN_BUGS' ) ) |
---|
29 | define( 'WP_TESTS_FORCE_KNOWN_BUGS', false ); |
---|
30 | |
---|
31 | // Cron tries to make an HTTP request to the blog, which always fails, because tests are run in CLI mode only |
---|
32 | define( 'DISABLE_WP_CRON', true ); |
---|
33 | |
---|
34 | define( 'WP_MEMORY_LIMIT', -1 ); |
---|
35 | define( 'WP_MAX_MEMORY_LIMIT', -1 ); |
---|
36 | |
---|
37 | $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; |
---|
38 | $_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN; |
---|
39 | $PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php'; |
---|
40 | |
---|
41 | if ( "1" == getenv( 'WP_MULTISITE' ) || |
---|
42 | ( defined( 'WP_TESTS_MULTISITE') && WP_TESTS_MULTISITE ) ) { |
---|
43 | $multisite = true; |
---|
44 | } else { |
---|
45 | $multisite = false; |
---|
46 | } |
---|
47 | |
---|
48 | // Override the PHPMailer |
---|
49 | require_once( dirname( __FILE__ ) . '/mock-mailer.php' ); |
---|
50 | $phpmailer = new MockPHPMailer(); |
---|
51 | |
---|
52 | system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite ); |
---|
53 | |
---|
54 | if ( $multisite ) { |
---|
55 | echo "Running as multisite..." . PHP_EOL; |
---|
56 | define( 'MULTISITE', true ); |
---|
57 | define( 'SUBDOMAIN_INSTALL', false ); |
---|
58 | define( 'DOMAIN_CURRENT_SITE', WP_TESTS_DOMAIN ); |
---|
59 | define( 'PATH_CURRENT_SITE', '/' ); |
---|
60 | define( 'SITE_ID_CURRENT_SITE', 1 ); |
---|
61 | define( 'BLOG_ID_CURRENT_SITE', 1 ); |
---|
62 | $GLOBALS['base'] = '/'; |
---|
63 | } else { |
---|
64 | echo "Running as single site... To run multisite, use -c multisite.xml" . PHP_EOL; |
---|
65 | } |
---|
66 | unset( $multisite ); |
---|
67 | |
---|
68 | require_once dirname( __FILE__ ) . '/functions.php'; |
---|
69 | |
---|
70 | // Preset WordPress options defined in bootstrap file. |
---|
71 | // Used to activate themes, plugins, as well as other settings. |
---|
72 | if(isset($GLOBALS['wp_tests_options'])) { |
---|
73 | function wp_tests_options( $value ) { |
---|
74 | $key = substr( current_filter(), strlen( 'pre_option_' ) ); |
---|
75 | return $GLOBALS['wp_tests_options'][$key]; |
---|
76 | } |
---|
77 | |
---|
78 | foreach ( array_keys( $GLOBALS['wp_tests_options'] ) as $key ) { |
---|
79 | tests_add_filter( 'pre_option_'.$key, 'wp_tests_options' ); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | // Load WordPress |
---|
84 | require_once ABSPATH . '/wp-settings.php'; |
---|
85 | |
---|
86 | // Delete any default posts & related data |
---|
87 | _delete_all_posts(); |
---|
88 | |
---|
89 | require dirname( __FILE__ ) . '/testcase.php'; |
---|
90 | require dirname( __FILE__ ) . '/testcase-xmlrpc.php'; |
---|
91 | require dirname( __FILE__ ) . '/testcase-ajax.php'; |
---|
92 | require dirname( __FILE__ ) . '/exceptions.php'; |
---|
93 | require dirname( __FILE__ ) . '/utils.php'; |
---|
94 | |
---|
95 | /** |
---|
96 | * A child class of the PHP test runner. |
---|
97 | * |
---|
98 | * Not actually used as a runner. Rather, used to access the protected |
---|
99 | * longOptions property, to parse the arguments passed to the script. |
---|
100 | * |
---|
101 | * If it is determined that phpunit was called with a --group that corresponds |
---|
102 | * to an @ticket annotation (such as `phpunit --group 12345` for bugs marked |
---|
103 | * as #WP12345), then it is assumed that known bugs should not be skipped. |
---|
104 | * |
---|
105 | * If WP_TESTS_FORCE_KNOWN_BUGS is already set in wp-tests-config.php, then |
---|
106 | * how you call phpunit has no effect. |
---|
107 | */ |
---|
108 | class WP_PHPUnit_TextUI_Command extends PHPUnit_TextUI_Command { |
---|
109 | function __construct( $argv ) { |
---|
110 | $options = PHPUnit_Util_Getopt::getopt( |
---|
111 | $argv, |
---|
112 | 'd:c:hv', |
---|
113 | array_keys( $this->longOptions ) |
---|
114 | ); |
---|
115 | $ajax_message = true; |
---|
116 | foreach ( $options[0] as $option ) { |
---|
117 | switch ( $option[0] ) { |
---|
118 | case '--exclude-group' : |
---|
119 | $ajax_message = false; |
---|
120 | continue 2; |
---|
121 | case '--group' : |
---|
122 | $groups = explode( ',', $option[1] ); |
---|
123 | foreach ( $groups as $group ) { |
---|
124 | if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) ) |
---|
125 | WP_UnitTestCase::forceTicket( $group ); |
---|
126 | } |
---|
127 | $ajax_message = ! in_array( 'ajax', $groups ); |
---|
128 | continue 2; |
---|
129 | } |
---|
130 | } |
---|
131 | if ( $ajax_message ) |
---|
132 | echo "Not running ajax tests... To execute these, use --group ajax." . PHP_EOL; |
---|
133 | } |
---|
134 | } |
---|
135 | new WP_PHPUnit_TextUI_Command( $_SERVER['argv'] ); |
---|