Removed unused method call and added unit tests.

This commit is contained in:
Vedanshu Jain 2023-07-13 18:16:06 +05:30
parent 88b7e992bc
commit 74522b2b24
3 changed files with 23 additions and 22 deletions

View File

@ -49,6 +49,8 @@ class WC_Order_Refund extends WC_Abstract_Order {
* @var array
*/
protected $legacy_datastore_props = array(
'_refund_amount',
'_refund_reason',
'_refunded_by',
'_refunded_payment',
);

View File

@ -49,16 +49,6 @@ class OrdersTableRefundDataStore extends OrdersTableDataStore {
),
);
/**
* We do not have and use all the getters and setters from OrderTableDataStore, so we only select the props we actually need.
*/
protected $internal_meta_keys = array(
'_refund_amount',
'_refund_reason',
'_refunded_payment',
'_refunded_by',
);
/**
* Delete a refund order from database.
*
@ -90,22 +80,11 @@ class OrdersTableRefundDataStore extends OrdersTableDataStore {
}
}
/**
* Read a refund object from custom tables.
*
* @param \WC_Abstract_Order $refund Refund object.
*
* @return void
*/
public function read( &$refund ) {
parent::read( $refund );
$this->set_refund_props( $refund );
}
/**
* Helper method to set refund props.
*
* @param \WC_Order_Refund $refund Refund object.
* @param object $data DB data object.
*/
protected function set_order_props_from_data( &$refund, $data ) {
parent::set_order_props_from_data( $refund, $data );

View File

@ -101,4 +101,24 @@ class OrdersTableRefundDataStoreTests extends WC_Unit_Test_Case {
$this->assertEquals( 'Test', $refreshed_refund->get_reason() );
}
/**
* @testDox Test that refund props are set as expected.
*/
public function test_refund_data_is_set() {
$order = OrderHelper::create_order();
$refund = wc_create_refund(
array(
'order_id' => $order->get_id(),
'amount' => 10,
'reason' => 'Test',
)
);
$refund->save();
$refreshed_refund = wc_get_order( $order->get_id() )->get_refunds()[0];
$this->assertEquals( $refund->get_id(), $refreshed_refund->get_id() );
$this->assertEquals( 10, $refreshed_refund->get_data()['amount'] );
$this->assertEquals( 'Test', $refreshed_refund->get_data()['reason'] );
}
}