-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,81 @@ | ||
<?php | ||
/** | ||
* Bootstraps unit-tests. | ||
* | ||
* @package GlotPress | ||
* @subpackage Tests | ||
*/ | ||
|
||
$_tests_dir = getenv( 'WP_TESTS_DIR' ); | ||
if ( ! $_tests_dir ) { | ||
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib'; | ||
if ( ! defined( 'GP_TESTS_DIR' ) ) { | ||
define( 'GP_TESTS_DIR', __DIR__ ); | ||
} | ||
|
||
function _glotpress_path( string $path ): string { | ||
$glotpress_path = dirname( __DIR__, 2 ) . '/glotpress/'; | ||
if ( getenv( 'GITHUB_ACTIONS' ) ) { | ||
$glotpress_path = '/tmp/wordpress/wp-content/plugins/glotpress/'; | ||
} | ||
return $glotpress_path . $path; | ||
if ( ! defined( 'GP_DIR_TESTDATA' ) ) { | ||
define( 'GP_DIR_TESTDATA', GP_TESTS_DIR . '/data' ); | ||
} | ||
|
||
// Forward custom PHPUnit Polyfills configuration to PHPUnit bootstrap file. | ||
$_phpunit_polyfills_path = getenv( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ); | ||
if ( false !== $_phpunit_polyfills_path ) { | ||
define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', $_phpunit_polyfills_path ); | ||
if ( ! defined( 'GP_TESTS_PERMALINK_STRUCTURE' ) ) { | ||
define( 'GP_TESTS_PERMALINK_STRUCTURE', '/%postname%' ); | ||
} | ||
|
||
if ( ! file_exists( "$_tests_dir/includes/functions.php" ) ) { | ||
echo "Could not find $_tests_dir/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | ||
if ( ! defined( 'GP_TESTS_PERMALINK_STRUCTURE_WITH_TRAILING_SLASH' ) ) { | ||
define( 'GP_TESTS_PERMALINK_STRUCTURE_WITH_TRAILING_SLASH', '/%postname%/' ); | ||
} | ||
|
||
$_tests_dir = getenv( 'WP_TESTS_DIR' ); | ||
|
||
if ( ! $_tests_dir ) { | ||
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib'; | ||
} | ||
|
||
if ( ! file_exists( "{$_tests_dir}/includes/functions.php" ) ) { | ||
echo "Could not find {$_tests_dir}/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | ||
exit( 1 ); | ||
} | ||
|
||
// Give access to tests_add_filter() function. | ||
require_once "$_tests_dir/includes/functions.php"; | ||
require_once "{$_tests_dir}/includes/functions.php"; | ||
|
||
$_core_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress'; | ||
|
||
$_gp_dir = getenv( 'GLOTPRESS_DIR' ); | ||
if ( $_gp_dir ) { | ||
define( 'EXTERNAL_GP_DIR', $_gp_dir ); | ||
} else { | ||
define( 'EXTERNAL_GP_DIR', $_core_dir . '/build/wp-content/plugins/glotpress' ); | ||
} | ||
|
||
if ( ! file_exists( EXTERNAL_GP_DIR . '/glotpress.php' ) ) { | ||
echo 'Could not find ' . EXTERNAL_GP_DIR . '/glotpress.php Please specify the path to your GlotPress install with the GLOTPRESS_DIR environment variable.' . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | ||
exit( 1 ); | ||
} | ||
/** | ||
* Manually load the plugin being tested. | ||
*/ | ||
function _manually_load_plugin() { | ||
require_once _glotpress_path( '/tests/phpunit/includes/loader.php' ); | ||
require EXTERNAL_GP_DIR . '/glotpress.php'; | ||
require_once dirname( __DIR__ ) . '/wporg-gp-translation-events.php'; | ||
} | ||
|
||
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); | ||
|
||
global $wp_tests_options; | ||
$wp_tests_options['permalink_structure'] = '/%postname%'; | ||
$wp_tests_options['permalink_structure'] = GP_TESTS_PERMALINK_STRUCTURE; | ||
|
||
// Start up the WP testing environment. | ||
require "$_tests_dir/includes/bootstrap.php"; | ||
require "{$_tests_dir}/includes/bootstrap.php"; | ||
|
||
// Require GlotPress test code. | ||
require_once _glotpress_path( '/tests/phpunit/lib/testcase.php' ); | ||
require_once _glotpress_path( '/tests/phpunit/lib/testcase-route.php' ); | ||
require_once _glotpress_path( '/tests/phpunit/lib/testcase-request.php' ); | ||
require_once GP_TESTS_DIR . '/lib/testcase.php'; | ||
require_once GP_TESTS_DIR . '/lib/testcase-route.php'; | ||
require_once GP_TESTS_DIR . '/lib/testcase-request.php'; | ||
|
||
/** | ||
* Installs GlotPress tables. | ||
*/ | ||
function _install_glotpress() { | ||
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; | ||
require_once _glotpress_path( '/gp-includes/schema.php' ); | ||
require_once _glotpress_path( '/gp-includes/install-upgrade.php' ); | ||
require_once EXTERNAL_GP_DIR . '/gp-includes/schema.php'; | ||
require_once EXTERNAL_GP_DIR . '/gp-includes/install-upgrade.php'; | ||
gp_upgrade_db(); | ||
} | ||
_install_glotpress(); |