Merge pull request #28535 from woocommerce/add/disable_wc_admin_tracking
Tracker: Add tracking of woocommerce_admin_disabled usage.
This commit is contained in:
commit
1181c4be4a
|
@ -166,6 +166,9 @@ class WC_Tracker {
|
||||||
// Cart & checkout tech (blocks or shortcodes).
|
// Cart & checkout tech (blocks or shortcodes).
|
||||||
$data['cart_checkout'] = self::get_cart_checkout_info();
|
$data['cart_checkout'] = self::get_cart_checkout_info();
|
||||||
|
|
||||||
|
// WooCommerce Admin info.
|
||||||
|
$data['wc_admin_disabled'] = apply_filters( 'woocommerce_admin_disabled', false ) ? 'yes' : 'no';
|
||||||
|
|
||||||
return apply_filters( 'woocommerce_tracker_data', $data );
|
return apply_filters( 'woocommerce_tracker_data', $data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Unit tests for the WC_Tracker class.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\Tests\WC_Tracker.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class WC_Tracker_Test
|
||||||
|
*/
|
||||||
|
class WC_Tracker_Test extends \WC_Unit_Test_Case {
|
||||||
|
/**
|
||||||
|
* Test the tracking of wc_admin being disabled via filter.
|
||||||
|
*/
|
||||||
|
public function test_wc_admin_disabled_get_tracking_data() {
|
||||||
|
$posted_data = null;
|
||||||
|
|
||||||
|
// Test the case for woocommerce_admin_disabled filter returning true.
|
||||||
|
add_filter(
|
||||||
|
'woocommerce_admin_disabled',
|
||||||
|
function( $default ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
add_filter(
|
||||||
|
'pre_http_request',
|
||||||
|
function( $pre, $args, $url ) use ( &$posted_data ) {
|
||||||
|
$posted_data = $args;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
3,
|
||||||
|
10
|
||||||
|
);
|
||||||
|
WC_Tracker::send_tracking_data( true );
|
||||||
|
$tracking_data = json_decode( $posted_data['body'], true );
|
||||||
|
|
||||||
|
// Test the default case of no filter for set for woocommerce_admin_disabled.
|
||||||
|
$this->assertArrayHasKey( 'wc_admin_disabled', $tracking_data );
|
||||||
|
$this->assertEquals( 'yes', $tracking_data['wc_admin_disabled'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the tracking of wc_admin being not disabled via filter.
|
||||||
|
*/
|
||||||
|
public function test_wc_admin_not_disabled_get_tracking_data() {
|
||||||
|
$posted_data = null;
|
||||||
|
// Bypass time delay so we can invoke send_tracking_data again.
|
||||||
|
update_option( 'woocommerce_tracker_last_send', strtotime( '-2 weeks' ) );
|
||||||
|
|
||||||
|
add_filter(
|
||||||
|
'pre_http_request',
|
||||||
|
function( $pre, $args, $url ) use ( &$posted_data ) {
|
||||||
|
$posted_data = $args;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
3,
|
||||||
|
10
|
||||||
|
);
|
||||||
|
WC_Tracker::send_tracking_data( true );
|
||||||
|
$tracking_data = json_decode( $posted_data['body'], true );
|
||||||
|
|
||||||
|
// Test the default case of no filter for set for woocommerce_admin_disabled.
|
||||||
|
$this->assertArrayHasKey( 'wc_admin_disabled', $tracking_data );
|
||||||
|
$this->assertEquals( 'no', $tracking_data['wc_admin_disabled'] );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue