Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Martyn Jones committed Oct 27, 2023
1 parent 2ee2fad commit 2ce30f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion tests/unit-tests/CheckoutProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ public function test_begin_checkout_event() {
$cart = WC()->cart;

$add_to = $cart->add_to_cart( $product->get_id() );
( new WC_Google_Gtag_JS() )->checkout_process( $cart->get_cart() );

$mock = $this->getMockBuilder( WC_Google_Gtag_JS::class )
->setMethods( array( '__construct' ) )
->setConstructorArgs( array( array( 'ga_enhanced_checkout_process_enabled' => 'yes' ) ) )
->getMock();

$mock->checkout_process( $cart->get_cart() );

// Confirm woocommerce_gtag_event_data is called by checkout_process().
$this->assertEquals( 1, $this->get_event_data_filter_call_count(), 'woocommerce_gtag_event_data filter was not called for begin_checkout (checkout_process()) event' );
Expand Down
8 changes: 7 additions & 1 deletion tests/unit-tests/ProductDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ class ProductDetail extends EventsDataTest {
* @return void
*/
public function test_view_item_event() {
global $product;
$product = $this->get_product();

( new WC_Google_Gtag_JS() )->product_detail( $product );
$mock = $this->getMockBuilder( WC_Google_Gtag_JS::class )
->setMethods( array( '__construct' ) )
->setConstructorArgs( array( array( 'ga_enhanced_product_detail_view_enabled' => 'yes' ) ) )
->getMock();

$mock->product_detail();

// Confirm woocommerce_gtag_event_data is called by product_detail().
$this->assertEquals( 1, $this->get_event_data_filter_call_count(), 'woocommerce_gtag_event_data filter was not called for view_item (product_detail()) event' );
Expand Down

0 comments on commit 2ce30f6

Please sign in to comment.