Build/Test Tools: Ensure the test_php_and_js_shortcode_attribute_regexes_match() test can run when testing using either the src or build directory.

Reviewed by desrosj, johnbillion.
Props alexstine, desrosj.
Merges [50501] to the 5.7 branch.
Fixes #51734.

git-svn-id: https://develop.svn.wordpress.org/branches/5.7@50509 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2021-03-08 15:14:30 +00:00
parent 739323f34b
commit 64444cd67e

View File

@ -744,9 +744,27 @@ EOF;
return data_whole_posts();
}
/**
* Ensure the shortcode attribute regex is the same in both the PHP and JS implementations.
*
* @ticket 34191
* @ticket 51734
*/
function test_php_and_js_shortcode_attribute_regexes_match() {
// This test uses the source file by default but will use the built file if it exists.
// This allows the test to run using either the src or build directory.
$file_src = ABSPATH . 'js/_enqueues/wp/shortcode.js';
$file_build = ABSPATH . 'wp-includes/js/shortcode.js';
$file = file_get_contents( ABSPATH . 'js/_enqueues/wp/shortcode.js' );
$this->assertTrue( file_exists( $file_src ) || file_exists( $file_build ) );
$path = $file_src;
if ( file_exists( $file_build ) ) {
$path = $file_build;
}
$file = file_get_contents( $path );
$matched = preg_match( '|\s+pattern = (\/.+\/)g;|', $file, $matches );
$php = get_shortcode_atts_regex();