2016-02-08 19:57:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Payment_Token_CC.
|
|
|
|
* @package WooCommerce\Tests\Payment_Tokens
|
|
|
|
*/
|
2016-03-23 12:14:13 +00:00
|
|
|
class WC_Tests_Payment_Token_CC extends WC_Unit_Test_Case {
|
2016-02-08 19:57:48 +00:00
|
|
|
|
|
|
|
/**
|
2016-03-01 17:09:29 +00:00
|
|
|
* Test validation for empty/unset values.
|
|
|
|
* @since 2.6.0
|
2016-02-08 19:57:48 +00:00
|
|
|
*/
|
|
|
|
function test_wc_payment_token_cc_validate_empty() {
|
2016-03-23 12:14:13 +00:00
|
|
|
$token = new WC_Payment_Token_CC();
|
2016-02-08 19:57:48 +00:00
|
|
|
$token->set_token( time() . ' ' . __FUNCTION__ );
|
|
|
|
$this->assertFalse( $token->validate() );
|
|
|
|
$token->set_last4( '1111' );
|
|
|
|
$token->set_expiry_year( '2016' );
|
|
|
|
$token->set_expiry_month( '08' );
|
|
|
|
$token->set_card_type( 'visa' );
|
|
|
|
$this->assertTrue( $token->validate() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-01 17:09:29 +00:00
|
|
|
* Test validation for expiry length.
|
|
|
|
* @since 2.6.0
|
2016-02-08 19:57:48 +00:00
|
|
|
*/
|
|
|
|
function test_wc_payment_token_cc_validate_expiry_length() {
|
2016-03-23 12:14:13 +00:00
|
|
|
$token = new WC_Payment_Token_CC();
|
2016-02-08 19:57:48 +00:00
|
|
|
$token->set_token( time() . ' ' . __FUNCTION__ );
|
|
|
|
$this->assertFalse( $token->validate() );
|
|
|
|
|
|
|
|
$token->set_last4( '1111' );
|
|
|
|
$token->set_expiry_year( '16' );
|
|
|
|
$token->set_expiry_month( '08' );
|
|
|
|
$token->set_card_type( 'visa' );
|
|
|
|
|
|
|
|
$this->assertFalse( $token->validate() );
|
|
|
|
|
|
|
|
$token->set_expiry_year( '2016' );
|
2016-03-18 18:24:06 +00:00
|
|
|
|
2016-02-08 19:57:48 +00:00
|
|
|
$this->assertTrue( $token->validate() );
|
|
|
|
|
|
|
|
$token->set_expiry_month( '8' );
|
|
|
|
$this->assertFalse( $token->validate() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-18 18:24:06 +00:00
|
|
|
* Tes get/set card type.
|
2016-03-01 17:09:29 +00:00
|
|
|
* @since 2.6.0
|
2016-02-08 19:57:48 +00:00
|
|
|
*/
|
2016-03-18 18:24:06 +00:00
|
|
|
public function test_wc_payment_token_cc_card_type() {
|
2016-03-23 12:14:13 +00:00
|
|
|
$token = new WC_Payment_Token_CC();
|
2016-02-08 19:57:48 +00:00
|
|
|
$token->set_card_type( 'visa' );
|
|
|
|
$this->assertEquals( 'visa', $token->get_card_type() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-18 18:24:06 +00:00
|
|
|
* Test get/set expiry year.
|
2016-03-01 17:09:29 +00:00
|
|
|
* @since 2.6.0
|
2016-02-08 19:57:48 +00:00
|
|
|
*/
|
2016-03-18 18:24:06 +00:00
|
|
|
public function test_wc_payment_token_cc_expiry_year() {
|
2016-03-23 12:14:13 +00:00
|
|
|
$token = new WC_Payment_Token_CC();
|
2016-02-08 19:57:48 +00:00
|
|
|
$token->set_expiry_year( '2016' );
|
|
|
|
$this->assertEquals( '2016', $token->get_expiry_year() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-18 18:24:06 +00:00
|
|
|
* Test get/set expiry month.
|
2016-03-01 17:09:29 +00:00
|
|
|
* @since 2.6.0
|
2016-02-08 19:57:48 +00:00
|
|
|
*/
|
2016-03-18 18:24:06 +00:00
|
|
|
public function test_wc_payment_token_cc_expiry_month() {
|
2016-03-23 12:14:13 +00:00
|
|
|
$token = new WC_Payment_Token_CC();
|
2016-02-08 19:57:48 +00:00
|
|
|
$token->set_expiry_month( '08' );
|
|
|
|
$this->assertEquals( '08', $token->get_expiry_month() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-18 18:24:06 +00:00
|
|
|
* Test get/set last4.
|
2016-03-01 17:09:29 +00:00
|
|
|
* @since 2.6.0
|
2016-02-08 19:57:48 +00:00
|
|
|
*/
|
2016-03-18 18:24:06 +00:00
|
|
|
public function test_wc_payment_token_cc_last4() {
|
2016-03-23 12:14:13 +00:00
|
|
|
$token = new WC_Payment_Token_CC();
|
2016-03-18 18:24:06 +00:00
|
|
|
$token->set_last4( '1111' );
|
2016-02-08 19:57:48 +00:00
|
|
|
$this->assertEquals( '1111', $token->get_last4() );
|
|
|
|
}
|
|
|
|
|
2016-03-18 18:24:06 +00:00
|
|
|
/*
|
2016-03-01 17:09:29 +00:00
|
|
|
* Test reading/getting a token from DB correctly sets meta.
|
|
|
|
* @since 2.6.0
|
2016-02-08 19:57:48 +00:00
|
|
|
*/
|
|
|
|
public function test_wc_payment_token_cc_read_pulls_meta() {
|
2016-03-23 12:14:13 +00:00
|
|
|
$token = WC_Helper_Payment_Token::create_cc_token();
|
2016-02-08 19:57:48 +00:00
|
|
|
$token_id = $token->get_id();
|
2016-03-23 12:14:13 +00:00
|
|
|
$token_read = new WC_Payment_Token_CC();
|
2016-02-08 19:57:48 +00:00
|
|
|
$token_read->read( $token_id );
|
|
|
|
$this->assertEquals( '1234', $token_read->get_last4() );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|