From 26772874cecf1a0e4bc24b326cac6798de8681a6 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Fri, 5 Mar 2021 15:26:22 +0000 Subject: [PATCH] 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. Props alexstine, desrosj See #51734 git-svn-id: https://develop.svn.wordpress.org/trunk@50501 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/shortcode.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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();