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 () {
$this -> assertEquals ( array (
2016-10-12 10:16:30 +00:00
'dashboard' => 'Dashboard' ,
'orders' => 'Orders' ,
'downloads' => 'Downloads' ,
'edit-address' => 'Addresses' ,
'edit-account' => 'Account details' ,
'customer-logout' => 'Logout' ,
2016-01-19 23:37:39 +00:00
), wc_get_account_menu_items () );
}
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 () {
$this -> assertEquals ( array (
2016-10-12 10:16:30 +00:00
'order-number' => 'Order' ,
'order-date' => 'Date' ,
'order-status' => 'Status' ,
'order-total' => 'Total' ,
2017-04-25 13:46:17 +00:00
'order-actions' => 'Actions' ,
2016-01-19 23:37:39 +00:00
), wc_get_account_orders_columns () );
}
/**
* Test wc_get_account_downloads_columns () .
*
* @ since 2.6 . 0
*/
public function test_wc_get_account_downloads_columns () {
$this -> assertEquals ( array (
2017-07-12 15:18:43 +00:00
'download-file' => 'Download' ,
2016-10-12 10:16:30 +00:00
'download-remaining' => 'Downloads remaining' ,
'download-expires' => 'Expires' ,
'download-product' => 'Product' ,
2016-01-19 23:37:39 +00:00
), wc_get_account_downloads_columns () );
}
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 () {
$this -> assertEquals ( array (
'method' => 'Method' ,
'expires' => 'Expires' ,
'actions' => ' ' ,
), wc_get_account_payment_methods_columns () );
}
/**
* Test wc_get_account_payment_methods_types () .
*
* @ since 3.3 . 0
*/
public function test_wc_get_account_payment_methods_types () {
$this -> assertEquals ( array (
'cc' => 'Credit card' ,
'echeck' => 'eCheck' ,
), wc_get_account_payment_methods_types () );
}
/**
* Test wc_get_account_orders_actions () .
*
* @ since 3.3 . 0
*/
public function test_wc_get_account_orders_actions () {
$order = WC_Helper_Order :: create_order ();
$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' ,
),
), wc_get_account_orders_actions ( $order -> get_id () ) );
$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 () );
$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' ,
),
),
),
),
), wc_get_account_saved_payment_methods_list ( array (), $customer -> get_id () ) );
$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 ();
$this -> assertEquals ( array (
'method' => array (
'last4' => '1234' ,
'brand' => 'Mastercard' ,
),
'expires' => '12/20' ,
), wc_get_account_saved_payment_methods_list_item_cc ( array (), $token ) );
$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 ();
$this -> assertEquals ( array (
'method' => array (
'last4' => '1234' ,
'brand' => 'eCheck' ,
),
), wc_get_account_saved_payment_methods_list_item_echeck ( array (), $token ) );
$token -> delete ( true );
}
2016-01-19 23:37:39 +00:00
}