2016-01-19 23:37:39 +00:00
< ? php
2017-10-04 19:43:41 +00:00
/**
* Account function tests
*
* @ package WooCommerce\Tests\Account
*/
2016-01-19 23:37:39 +00:00
/**
* Class Functions .
*/
2016-03-23 12:14:13 +00:00
class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
2016-01-19 23:37:39 +00:00
2017-10-04 19:43:41 +00:00
/**
* Test wc_lostpassword_url () .
*
* @ since 3.3 . 0
*/
public function test_wc_lostpassword_url () {
$this -> assertEquals ( '' , wc_lostpassword_url () );
}
/**
* Test wc_customer_edit_account_url () .
*
* @ since 3.3 . 0
*/
public function test_wc_customer_edit_account_url () {
$this -> assertEquals ( 'http://example.org?edit-account' , wc_customer_edit_account_url () );
}
/**
* Test wc_edit_address_i18n () .
*
* @ since 3.3 . 0
*/
public function test_wc_edit_address_i18n () {
// Should return the same result, since it's using en_US in Unit Tests.
$this -> assertEquals ( 'billing' , wc_edit_address_i18n ( 'billing' ) );
$this -> assertEquals ( 'billing' , wc_edit_address_i18n ( 'billing' , true ) );
}
2016-01-19 23:37:39 +00:00
/**
* Test wc_get_account_menu_items () .
*
* @ since 2.6 . 0
*/
public function test_wc_get_account_menu_items () {
2019-05-01 22:05:00 +00:00
$this -> assertEquals (
array (
'dashboard' => 'Dashboard' ,
'orders' => 'Orders' ,
'downloads' => 'Downloads' ,
'edit-address' => 'Addresses' ,
'edit-account' => 'Account details' ,
'customer-logout' => 'Logout' ,
),
wc_get_account_menu_items ()
);
2016-01-19 23:37:39 +00:00
}
2017-10-04 19:43:41 +00:00
/**
* Test wc_get_account_menu_item_classes () .
*
* @ since 3.3 . 0
*/
public function test_wc_get_account_menu_item_classes () {
$this -> assertEquals ( 'woocommerce-MyAccount-navigation-link woocommerce-MyAccount-navigation-link--test' , wc_get_account_menu_item_classes ( 'test' ) );
}
/**
* Test wc_get_account_endpoint_url () .
*
* @ since 3.3 . 0
*/
public function test_wc_get_account_endpoint_url () {
$this -> assertEquals ( 'http://example.org?test' , wc_get_account_endpoint_url ( 'test' ) );
}
2016-01-19 23:37:39 +00:00
/**
* Test wc_get_account_orders_columns () .
*
* @ since 2.6 . 0
*/
public function test_wc_get_account_orders_columns () {
2019-05-01 22:05:00 +00:00
$this -> assertEquals (
array (
'order-number' => 'Order' ,
'order-date' => 'Date' ,
'order-status' => 'Status' ,
'order-total' => 'Total' ,
'order-actions' => 'Actions' ,
),
wc_get_account_orders_columns ()
);
2016-01-19 23:37:39 +00:00
}
/**
* Test wc_get_account_downloads_columns () .
*
* @ since 2.6 . 0
*/
public function test_wc_get_account_downloads_columns () {
2019-05-01 22:05:00 +00:00
$this -> assertEquals (
array (
'download-file' => 'Download' ,
'download-remaining' => 'Downloads remaining' ,
'download-expires' => 'Expires' ,
'download-product' => 'Product' ,
),
wc_get_account_downloads_columns ()
);
2016-01-19 23:37:39 +00:00
}
2017-10-04 19:43:41 +00:00
/**
* Test wc_get_account_payment_methods_columns () .
*
* @ since 3.3 . 0
*/
public function test_wc_get_account_payment_methods_columns () {
2019-05-01 22:05:00 +00:00
$this -> assertEquals (
array (
'method' => 'Method' ,
'expires' => 'Expires' ,
'actions' => ' ' ,
),
wc_get_account_payment_methods_columns ()
);
2017-10-04 19:43:41 +00:00
}
/**
* Test wc_get_account_payment_methods_types () .
*
* @ since 3.3 . 0
*/
public function test_wc_get_account_payment_methods_types () {
2019-05-01 22:05:00 +00:00
$this -> assertEquals (
array (
'cc' => 'Credit card' ,
'echeck' => 'eCheck' ,
),
wc_get_account_payment_methods_types ()
);
2017-10-04 19:43:41 +00:00
}
/**
* Test wc_get_account_orders_actions () .
*
* @ since 3.3 . 0
*/
public function test_wc_get_account_orders_actions () {
$order = WC_Helper_Order :: create_order ();
2019-05-01 22:05:00 +00:00
$this -> assertEquals (
array (
'view' => array (
'url' => $order -> get_view_order_url (),
'name' => 'View' ,
),
'pay' => array (
'url' => $order -> get_checkout_payment_url (),
'name' => 'Pay' ,
),
'cancel' => array (
'url' => $order -> get_cancel_order_url ( wc_get_page_permalink ( 'myaccount' ) ),
'name' => 'Cancel' ,
),
2017-10-04 19:43:41 +00:00
),
2019-05-01 22:05:00 +00:00
wc_get_account_orders_actions ( $order -> get_id () )
);
2017-10-04 19:43:41 +00:00
$order -> delete ( true );
}
/**
* Test wc_get_account_formatted_address () .
*
* @ since 3.3 . 0
*/
public function test_wc_get_account_formatted_address () {
$customer = WC_Helper_Customer :: create_customer ();
$this -> assertEquals ( '123 South Street<br/>Apt 1<br/>Philadelphia, PA 19123<br/>United States (US)' , wc_get_account_formatted_address ( 'billing' , $customer -> get_id () ) );
$customer -> delete ( true );
}
/**
* Test wc_get_account_saved_payment_methods_list () .
*
* @ since 3.3 . 0
*/
public function test_wc_get_account_saved_payment_methods_list () {
$customer = WC_Helper_Customer :: create_customer ();
$token = new WC_Payment_Token_CC ();
$token -> set_token ( '1234' );
$token -> set_gateway_id ( 'bacs' );
$token -> set_card_type ( 'mastercard' );
$token -> set_last4 ( '1234' );
$token -> set_expiry_month ( '12' );
$token -> set_expiry_year ( '2020' );
$token -> set_user_id ( $customer -> get_id () );
$token -> save ();
$delete_url = wc_get_endpoint_url ( 'delete-payment-method' , $token -> get_id () );
$delete_url = wp_nonce_url ( $delete_url , 'delete-payment-method-' . $token -> get_id () );
2019-05-01 22:05:00 +00:00
$this -> assertEquals (
array (
'cc' => array (
array (
'method' => array (
'gateway' => 'bacs' ,
'last4' => '1234' ,
'brand' => 'Mastercard' ,
),
'expires' => '12/20' ,
'is_default' => true ,
'actions' => array (
'delete' => array (
'url' => $delete_url ,
'name' => 'Delete' ,
),
2017-10-04 19:43:41 +00:00
),
),
),
),
2019-05-01 22:05:00 +00:00
wc_get_account_saved_payment_methods_list ( array (), $customer -> get_id () )
);
2017-10-04 19:43:41 +00:00
$customer -> delete ( true );
$token -> delete ( true );
}
/**
* Test wc_get_account_saved_payment_methods_list_item_cc () .
*
* @ since 3.3 . 0
*/
public function test_wc_get_account_saved_payment_methods_list_item_cc () {
$token = new WC_Payment_Token_CC ();
$token -> set_token ( '1234' );
$token -> set_gateway_id ( 'bacs' );
$token -> set_card_type ( 'mastercard' );
$token -> set_last4 ( '1234' );
$token -> set_expiry_month ( '12' );
$token -> set_expiry_year ( '2020' );
$token -> save ();
2019-05-01 22:05:00 +00:00
$this -> assertEquals (
array (
'method' => array (
'last4' => '1234' ,
'brand' => 'Mastercard' ,
),
'expires' => '12/20' ,
2017-10-04 19:43:41 +00:00
),
2019-05-01 22:05:00 +00:00
wc_get_account_saved_payment_methods_list_item_cc ( array (), $token )
);
2017-10-04 19:43:41 +00:00
$token -> delete ( true );
}
/**
* Test wc_get_account_saved_payment_methods_list_item_echeck () .
*
* @ since 3.3 . 0
*/
public function test_wc_get_account_saved_payment_methods_list_item_echeck () {
2018-03-07 17:50:21 +00:00
$token = new WC_Payment_Token_ECheck ();
2017-10-04 19:43:41 +00:00
$token -> set_token ( '1234' );
$token -> set_gateway_id ( 'bacs' );
$token -> set_last4 ( '1234' );
$token -> save ();
2019-05-01 22:05:00 +00:00
$this -> assertEquals (
array (
'method' => array (
'last4' => '1234' ,
'brand' => 'eCheck' ,
),
2017-10-04 19:43:41 +00:00
),
2019-05-01 22:05:00 +00:00
wc_get_account_saved_payment_methods_list_item_echeck ( array (), $token )
);
2017-10-04 19:43:41 +00:00
$token -> delete ( true );
}
2016-01-19 23:37:39 +00:00
}