diff --git a/tests/phpunit/tests/shortcode.php b/tests/phpunit/tests/shortcode.php index ea8bb136fc..01b022ec67 100644 --- a/tests/phpunit/tests/shortcode.php +++ b/tests/phpunit/tests/shortcode.php @@ -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();