Add expected deprecated call so that we can call setUp for this testcase.

This commit is contained in:
vedanshujain 2021-03-09 18:20:24 +05:30
parent 162588c42d
commit f5056d37e4
1 changed files with 33 additions and 18 deletions

View File

@ -1,44 +1,58 @@
<?php
/**
* Classes WC_Deprecated_Filter_Hooks & WC_Deprecated_Action_Hooks.
* @package WooCommerce\Tests\Util
* @since 3.0
*/
/**
* Class WC_Tests_Deprecated_Hooks.
*/
class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
/**
* @var array Deprecated hook handlers.
*/
protected $handlers = array();
/**
* Generic toggle value function that can be hooked to a filter for testing.
* @param bool/int $value
* @return bool/int
*
* @param bool/int $value Value to change.
*
* @return bool/int Changed value.
*/
function toggle_value( $value ) {
public function toggle_value( $value ) {
return ! $value;
}
/**
* Generic toggle value function that can be hooked to an action for testing.
* @param bool/int $value
*
* @param bool/int $value Value to change.
*/
function toggle_value_by_ref( &$value ) {
public function toggle_value_by_ref( &$value ) {
$value = ! $value;
}
/**
* Generic meta setting function that can be hooked to an action for testing.
* @param int $item1_id
* @param int $item2_id (default: false)
*
* @param int $item1_id Post ID.
* @param int $item2_id Post ID.
*/
function set_meta( $item1_id, $item2_id = false ) {
public function set_meta( $item1_id, $item2_id = false ) {
update_post_meta( $item1_id, 'wc_deprecated_hook_test_item1_meta', 1 );
if ( $item2_id ) {
update_post_meta( $item2_id, 'wc_deprecated_hook_test_item2_meta', 2 );
}
}
function setUp() {
/**
* Disable deprecation error trigger for this class.
*/
public function setUp() {
parent::setUp();
add_filter( 'deprecated_function_trigger_error', '__return_false' );
add_filter( 'deprecated_hook_trigger_error', '__return_false' );
$this->handlers = WC()->deprecated_hook_handlers;
@ -49,7 +63,7 @@ class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
*
* @since 3.0
*/
function test_deprecated_hook_handlers_exist() {
public function test_deprecated_hook_handlers_exist() {
$this->assertArrayHasKey( 'filters', $this->handlers );
$this->assertInstanceOf( 'WC_Deprecated_Filter_Hooks', $this->handlers['filters'] );
@ -62,7 +76,7 @@ class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
*
* @since 3.0
*/
function test_get_old_hooks() {
public function test_get_old_hooks() {
$old_filters = $this->handlers['filters']->get_old_hooks( 'woocommerce_structured_data_order' );
$old_actions = $this->handlers['actions']->get_old_hooks( 'woocommerce_new_order_item' );
@ -75,7 +89,7 @@ class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
*
* @since 3.0
*/
function test_hook_in() {
public function test_hook_in() {
$this->assertTrue( (bool) has_filter( 'woocommerce_structured_data_order', array( $this->handlers['filters'], 'maybe_handle_deprecated_hook' ) ) );
$this->assertTrue( (bool) has_action( 'woocommerce_new_order_item', array( $this->handlers['actions'], 'maybe_handle_deprecated_hook' ) ) );
}
@ -85,7 +99,7 @@ class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
*
* @since 3.0
*/
function test_handle_deprecated_hook_filter() {
public function test_handle_deprecated_hook_filter() {
$new_hook = 'wc_new_hook';
$old_hook = 'wc_old_hook';
$args = array( false );
@ -102,7 +116,7 @@ class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
*
* @since 3.0
*/
function test_handle_deprecated_hook_action() {
public function test_handle_deprecated_hook_action() {
$new_hook = 'wc_new_hook';
$old_hook = 'wc_old_hook';
$test_value = false;
@ -120,7 +134,7 @@ class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
*
* @since 3.0
*/
function test_filter_handler() {
public function test_filter_handler() {
$test_width = 1;
add_filter( 'woocommerce_product_width', array( $this, 'toggle_value' ) );
@ -134,7 +148,7 @@ class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
*
* @since 3.0
*/
function test_action_handler() {
public function test_action_handler() {
$test_product = WC_Helper_Product::create_simple_product();
$test_order = WC_Helper_Order::create_order( 1, $test_product );
$test_order_id = $test_order->get_id();
@ -142,6 +156,7 @@ class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
$test_item = reset( $test_items );
$test_item_id = $test_item->get_id();
$this->setExpectedDeprecated( 'woocommerce_order_edit_product' );
add_action( 'woocommerce_order_edit_product', array( $this, 'set_meta' ), 10, 2 );
do_action( 'woocommerce_update_order_item', $test_item_id, $test_item, $test_order_id );
@ -157,7 +172,7 @@ class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
*
* @since 3.0
*/
function test_created_actions_deprecation() {
public function test_created_actions_deprecation() {
add_filter( 'woocommerce_payment_token_created', '__return_true' );
add_filter( 'woocommerce_create_product_variation', '__return_true' );