Merge pull request #28535 from woocommerce/add/disable_wc_admin_tracking

Tracker: Add tracking of woocommerce_admin_disabled usage.
This commit is contained in:
Néstor Soriano 2021-03-02 09:35:38 +01:00 committed by GitHub
commit 1181c4be4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 0 deletions

View File

@ -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 );
} }

View File

@ -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'] );
}
}