} // make sure we're installed assert(true == is_blog_installed()); // include plugins for testing, if any if (is_dir(DIR_TESTPLUGINS)) { $plugins = glob(realpath(DIR_TESTPLUGINS) . '/*.php'); foreach ($plugins as $plugin) { include_once $plugin; } } // needed for jacob's tests ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . ABSPATH . '/wp-includes'); define('PHPUnit_MAIN_METHOD', false); $original_wpdb = $GLOBALS['wpdb']; // include all files in DIR_TESTCASE, and fetch all the WPTestCase descendents $files = wptest_get_all_test_files(DIR_TESTCASE); foreach ($files as $file) { require_once $file; } $classes = wptest_get_all_test_cases(); // some of jacob's tests clobber the wpdb object, so restore it $GLOBALS['wpdb'] = $original_wpdb; if (isset($opts['l'])) { wptest_listall_testcases($classes); } else { do_action('test_start'); // hide warnings during testing, since that's the normal WP behaviour if (!WP_DEBUG) { error_reporting(E_ALL ^ E_NOTICE); } // run the tests and print the results
function hmdev_phpunit_load_all_test_files() { if (!empty($_POST['tests'])) { foreach ((array) $_POST['tests'] as $test_file) { if (strpos($test_file, '.php')) { include_once WP_PLUGIN_DIR . '/' . $test_file; } else { $files = wptest_get_all_test_files(WP_PLUGIN_DIR . '/' . $test_file); foreach ($files as $file) { require_once $file; } } } } else { $plugins = get_plugins(); foreach ($plugins as $plugin_path => $plugin) { if (is_plugin_active($plugin_path)) { foreach (get_plugin_files($plugin_path) as $file) { if (strpos($file, '/tests/') && end(explode('.', $file)) == 'php') { include_once WP_PLUGIN_DIR . '/' . $file; } } } } if (is_dir(get_template_directory() . '/tests/')) { foreach (glob(get_template_directory() . '/tests/*.php') as $file) { include_once $file; } } if (is_dir(WPMU_PLUGIN_DIR)) { foreach (glob(WPMU_PLUGIN_DIR . '/*/tests/*.php') as $file) { include_once $file; } } } }
function wptest_get_all_test_files($dir) { $tests = array(); $dh = opendir($dir); while (($file = readdir($dh)) !== false) { if ($file[0] == '.') { continue; } // skip test loaders from jacob's tests if (strtolower($file) == 'alltests.php') { continue; } // these tests clash with other things if (in_array(strtolower($file), array('testplugin.php', 'testlocale.php'))) { continue; } $path = realpath($dir . DIRECTORY_SEPARATOR . $file); $fileparts = pathinfo($file); if (is_file($path) and $fileparts['extension'] == 'php') { $tests[] = $path; } elseif (is_dir($path)) { $tests = array_merge($tests, wptest_get_all_test_files($path)); } } closedir($dh); return $tests; }