2020-11-10 20:34:24 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Customer Effort Score Survey Tests.
|
|
|
|
*
|
|
|
|
* @package Automattic\WooCommerce\Admin\Features
|
|
|
|
*/
|
|
|
|
|
2022-02-21 09:47:28 +00:00
|
|
|
use Automattic\WooCommerce\Internal\Admin\CustomerEffortScoreTracks;
|
2020-11-10 20:34:24 +00:00
|
|
|
|
2020-11-18 19:44:57 +00:00
|
|
|
// CustomerEffortScoreTracks only works in wp-admin, so let's fake it.
|
|
|
|
define( 'WP_ADMIN', true );
|
|
|
|
|
2020-11-10 20:34:24 +00:00
|
|
|
/**
|
|
|
|
* Class WC_Tests_CES_Tracks
|
|
|
|
*/
|
|
|
|
class WC_Tests_CES_Tracks extends WC_Unit_Test_Case {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var CustomerEffortScoreTracks
|
|
|
|
*/
|
|
|
|
private $ces;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overridden setUp method from PHPUnit
|
|
|
|
*/
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
update_option( 'woocommerce_allow_tracking', 'yes' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify that it adds correct action to the queue on woocommerce_update_options action.
|
|
|
|
*/
|
|
|
|
public function test_updating_options_triggers_ces() {
|
2020-11-22 22:26:24 +00:00
|
|
|
$ces = new CustomerEffortScoreTracks();
|
2020-11-10 20:34:24 +00:00
|
|
|
|
2020-11-22 22:26:24 +00:00
|
|
|
do_action( 'woocommerce_update_options' );
|
2020-11-10 20:34:24 +00:00
|
|
|
|
2020-11-18 19:44:57 +00:00
|
|
|
$queue_items = get_option( $ces::CES_TRACKS_QUEUE_OPTION_NAME, array() );
|
2020-11-10 20:34:24 +00:00
|
|
|
$this->assertNotEmpty( $queue_items );
|
|
|
|
|
|
|
|
$expected_queue_item = array_filter(
|
|
|
|
$queue_items,
|
|
|
|
function ( $item ) use ( $ces ) {
|
|
|
|
return $ces::SETTINGS_CHANGE_ACTION_NAME === $item['action'];
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertCount( 1, $expected_queue_item );
|
|
|
|
}
|
2020-11-19 00:30:22 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-22 02:09:45 +00:00
|
|
|
* Verify that the queue does not add duplicate item by checking
|
2020-11-19 00:30:22 +00:00
|
|
|
* action and label values.
|
|
|
|
*/
|
|
|
|
public function test_the_queue_does_not_allow_duplicate() {
|
2020-11-22 22:26:24 +00:00
|
|
|
$ces = new CustomerEffortScoreTracks();
|
|
|
|
|
2020-11-19 00:30:22 +00:00
|
|
|
// Fire the action twice to trigger the queueing process twice.
|
|
|
|
do_action( 'woocommerce_update_options' );
|
|
|
|
do_action( 'woocommerce_update_options' );
|
|
|
|
|
|
|
|
$queue_items = get_option( $ces::CES_TRACKS_QUEUE_OPTION_NAME, array() );
|
|
|
|
$this->assertNotEmpty( $queue_items );
|
|
|
|
|
|
|
|
$expected_queue_item = array_filter(
|
|
|
|
$queue_items,
|
|
|
|
function ( $item ) use ( $ces ) {
|
|
|
|
return $ces::SETTINGS_CHANGE_ACTION_NAME === $item['action'];
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertCount( 1, $expected_queue_item );
|
|
|
|
}
|
2020-11-22 22:26:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify that tasks performed using a mobile device are ignored.
|
|
|
|
*/
|
|
|
|
public function test_disabled_for_mobile() {
|
|
|
|
add_filter( 'wp_is_mobile', '__return_true' );
|
|
|
|
|
|
|
|
$ces = new CustomerEffortScoreTracks();
|
|
|
|
|
|
|
|
do_action( 'woocommerce_update_options' );
|
|
|
|
|
|
|
|
$queue_items = get_option( $ces::CES_TRACKS_QUEUE_OPTION_NAME, array() );
|
|
|
|
|
|
|
|
$this->assertEmpty( $queue_items );
|
|
|
|
}
|
2021-02-22 02:09:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify that it adds `settings_area` prop.
|
|
|
|
*/
|
|
|
|
public function test_settings_area_included_in_event_props() {
|
|
|
|
// Global assignment to mimic what's done in WC_Admin_Settings::save_settings.
|
|
|
|
global $current_tab;
|
|
|
|
$current_tab = 'test_tab';
|
|
|
|
$ces = new CustomerEffortScoreTracks();
|
|
|
|
|
|
|
|
do_action( 'woocommerce_update_options' );
|
|
|
|
|
|
|
|
$queue_items = get_option( $ces::CES_TRACKS_QUEUE_OPTION_NAME, array() );
|
|
|
|
$this->assertNotEmpty( $queue_items );
|
|
|
|
|
|
|
|
$expected_queue_item = array_filter(
|
|
|
|
$queue_items,
|
|
|
|
function ( $item ) use ( $ces ) {
|
|
|
|
return $ces::SETTINGS_CHANGE_ACTION_NAME === $item['action'];
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// Remove global assignment.
|
|
|
|
unset( $GLOBALS['current_tab'] );
|
|
|
|
|
|
|
|
$this->assertCount( 1, $expected_queue_item );
|
|
|
|
$this->assertEquals( 'test_tab', $expected_queue_item[0]['props']->settings_area );
|
|
|
|
}
|
2020-11-10 20:34:24 +00:00
|
|
|
}
|