Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wp_print_inline_script_tag within the WP Proxy class to facilitate testing the inline scripts #2185

Open
jorgemd24 opened this issue Dec 15, 2023 · 0 comments
Assignees

Comments

@jorgemd24
Copy link
Contributor

jorgemd24 commented Dec 15, 2023

Describe the bug:

This a follow-up of #2184

Currently, it is not possible to mock wp_print_inline_script_tag making it challenging to test various scenarios, like the scripts inserted for the gtag events. See this case:

$conversion_gtag_info =
sprintf(
'gtag("event", "conversion", {
send_to: "%s",
value: %f,
currency: "%s",
transaction_id: "%s"});',
esc_js( "{$ads_conversion_id}/{$ads_conversion_label}" ),
$order->get_total(),
esc_js( $order->get_currency() ),
esc_js( $order->get_id() ),
);
wp_print_inline_script_tag( $conversion_gtag_info );

If we add wp_print_inline_script_tag within the WP Proxy class we will be able to mock the method and therefore to test different scenarios easily, similar what is done here:

$this->wp->expects( $this->exactly( 1 ) )
->method( 'wp_remote_get' )
->with( $data['content'] )
->willReturn(
[
'body' => $data['content'],
'headers' => new ArrayObject( [ 'content-length' => 12345 ] ),
]
);
$this->generate_asset_mutate_mock( 'create', $data );
$this->assertEquals( $this->generate_asset_resource_name( $data['id'] ), $this->asset->create_assets( [ $data ] )[0] );

Expected behavior:

To be able to mock wp_print_inline_script_tag easily

Actual behavior:

Difficult to mock wp_print_inline_script_tag

Additional details:

@jorgemd24 jorgemd24 self-assigned this Dec 15, 2023
@jorgemd24 jorgemd24 changed the title Add wp_print_inline_script_tag within the WP Proxy class to facilitate testing the printing scripts Add wp_print_inline_script_tag within the WP Proxy class to facilitate testing the inline scripts Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant