Unit Tests: add a DIR_TESTROOT constant to avoid relative paths.

Fix an issue that prevents tests from running correctly when run outside their normal context.

Props PressLabs, johnbillion.
Fixes #40071.



git-svn-id: https://develop.svn.wordpress.org/trunk@42741 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Adam Silverstein 2018-02-25 18:06:49 +00:00
parent d67a7c9b0b
commit d8a4215abb
2 changed files with 2 additions and 1 deletions

View File

@ -36,6 +36,7 @@ tests_reset__SERVER();
define( 'WP_TESTS_TABLE_PREFIX', $table_prefix ); define( 'WP_TESTS_TABLE_PREFIX', $table_prefix );
define( 'DIR_TESTDATA', dirname( __FILE__ ) . '/../data' ); define( 'DIR_TESTDATA', dirname( __FILE__ ) . '/../data' );
define( 'DIR_TESTROOT', realpath( dirname( dirname( __FILE__ ) ) ) );
define( 'WP_LANG_DIR', DIR_TESTDATA . '/languages' ); define( 'WP_LANG_DIR', DIR_TESTDATA . '/languages' );

View File

@ -395,7 +395,7 @@ class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase {
// Only generate API client fixtures in single site and when required JSON_* constants are supported. // Only generate API client fixtures in single site and when required JSON_* constants are supported.
if ( ! is_multisite() && version_compare( PHP_VERSION, '5.4', '>=' ) ) { if ( ! is_multisite() && version_compare( PHP_VERSION, '5.4', '>=' ) ) {
// Save the route object for QUnit tests. // Save the route object for QUnit tests.
$file = './tests/qunit/fixtures/wp-api-generated.js'; $file = dirname( DIR_TESTROOT ) . '/qunit/fixtures/wp-api-generated.js';
file_put_contents( $file, $mocked_responses ); file_put_contents( $file, $mocked_responses );
} }