Skip to content

Commit eab442d

Browse files
authored
Merge pull request #1682 from equalizedigital/william/no-issue/add-cache-busting-param-to-bundle-output-on-frontend-scanner
Add versioning to scanner bundle URL for frontend scans
2 parents 835dd57 + 144bd77 commit eab442d

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

includes/classes/class-enqueue-frontend.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public static function maybe_enqueue_frontend_highlighter() {
161161
'appCssUrl' => EDAC_PLUGIN_URL . 'build/css/frontendHighlighterApp.css?ver=' . EDAC_VERSION,
162162
'widgetPosition' => get_option( 'edac_frontend_highlighter_position', 'right' ),
163163
'editorLink' => get_edit_post_link( $post_id ),
164-
'scannerBundleUrl' => plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/pageScanner.bundle.js',
164+
'scannerBundleUrl' => esc_url_raw( add_query_arg( 'ver', EDAC_VERSION, plugin_dir_url( __FILE__ ) . 'build/pageScanner.bundle.js' ) ),
165165
'adminThemeColor' => self::get_admin_theme_color(),
166166
]
167167
);

tests/phpunit/includes/classes/EnqueueFrontendTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ protected function tearDown(): void {
5151
parent::tearDown();
5252
}
5353

54+
/**
55+
* Ensure the localized scannerBundleUrl includes the plugin version as a query string parameter.
56+
*/
57+
public function testScannerBundleUrlIncludesVersionQueryString(): void {
58+
$admin_id = $this->factory()->user->create( [ 'role' => 'administrator' ] );
59+
wp_set_current_user( $admin_id );
60+
61+
$created_post = $this->factory()->post->create_and_get( [ 'post_type' => 'post' ] );
62+
63+
global $post;
64+
$post = $created_post;
65+
66+
Enqueue_Frontend::maybe_enqueue_frontend_highlighter();
67+
68+
global $wp_scripts;
69+
$localized_data = $wp_scripts->get_data( 'edac-frontend-highlighter-app', 'data' );
70+
71+
$this->assertNotEmpty( $localized_data );
72+
$this->assertStringContainsString( 'scannerBundleUrl', $localized_data );
73+
$this->assertStringContainsString( 'ver=' . EDAC_VERSION, $localized_data );
74+
}
75+
5476
/**
5577
* Ensure the highlighter uses the filtered post ID when determining scannable post types.
5678
*/

0 commit comments

Comments
 (0)