woocommerce/tests/php/includes/class-wc-tracker-test.php

68 lines
1.8 KiB
PHP
Raw Normal View History

<?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() {
2021-01-23 01:22:38 +00:00
$posted_data = null;
2021-02-25 20:48:56 +00:00
// Test the case for woocommerce_admin_disabled filter returning true.
add_filter(
'woocommerce_admin_disabled',
function( $default ) {
return true;
}
);
2021-01-23 01:22:38 +00:00
add_filter(
'pre_http_request',
function( $pre, $args, $url ) use ( &$posted_data ) {
$posted_data = $args;
return true;
2021-02-25 20:48:56 +00:00
},
3,
10
2021-01-23 01:22:38 +00:00
);
WC_Tracker::send_tracking_data( true );
$tracking_data = json_decode( $posted_data['body'], true );
2021-02-25 20:48:56 +00:00
// 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' ) );
2021-01-23 01:22:38 +00:00
add_filter(
2021-02-25 20:48:56 +00:00
'pre_http_request',
function( $pre, $args, $url ) use ( &$posted_data ) {
$posted_data = $args;
return true;
},
3,
10
2021-01-23 01:22:38 +00:00
);
WC_Tracker::send_tracking_data( true );
2021-02-25 20:48:56 +00:00
$tracking_data = json_decode( $posted_data['body'], true );
2021-02-25 20:48:56 +00:00
// 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'] );
}
}