Example #1
0
 /**
  * Test reading/getting a token from DB correctly sets meta.
  * @since 2.6.0
  */
 public function test_wc_payment_token_echeck_read_pulls_meta()
 {
     $token = WC_Helper_Payment_Token::create_eCheck_token();
     $token_id = $token->get_id();
     $token_read = new WC_Payment_Token_eCheck($token_id);
     $this->assertEquals('1234', $token_read->get_last4());
 }
 /**
  * Test setting a users default token.
  * @since 2.6.0
  */
 function test_wc_payment_tokens_set_users_default()
 {
     $token = WC_Helper_Payment_Token::create_cc_token($this->user_id);
     $token_id = $token->get_id();
     $token->save();
     $token2 = WC_Helper_Payment_Token::create_cc_token($this->user_id);
     $token_id_2 = $token2->get_id();
     $token2->save();
     $this->assertTrue($token->is_default());
     // first created is default
     $this->assertFalse($token2->is_default());
     WC_Payment_Tokens::set_users_default($this->user_id, $token_id_2);
     $token->read($token_id);
     $token2->read($token_id_2);
     $this->assertFalse($token->is_default());
     $this->assertTrue($token2->is_default());
     WC_Payment_Tokens::set_users_default($this->user_id, $token_id);
     $token->read($token_id);
     $token2->read($token_id_2);
     $this->assertTrue($token->is_default());
     $this->assertFalse($token2->is_default());
 }
 /**
  * Test legacy token functions.
  *
  * @since 2.7.0
  *
  * @expectedDeprecated WC_Payment_Token::read
  * @expectedDeprecated WC_Payment_Token::create
  * @expectedDeprecated WC_Payment_Token::update
  */
 public function test_wc_payment_token_legacy()
 {
     $token = WC_Helper_Payment_Token::create_stub_token(__FUNCTION__);
     $token_id = $token->get_id();
     $token_read = new WC_Payment_Token_Stub();
     $token_read->read($token_id);
     $this->assertEquals($token_id, $token_read->get_id());
     $token = new WC_Payment_Token_Stub();
     $token->set_token('blah');
     $token->create();
     $this->assertEquals('blah', $token->get_token());
     $this->assertNotEmpty($token->get_id());
     $token->set_token('blah2');
     $token->update();
     $this->assertEquals('blah2', $token->get_token());
 }
Example #4
0
 /**
  * Test adding a payment token to an order
  *
  * @since 2.6
  */
 public function test_wc_order_add_payment_token()
 {
     $order = WC_Helper_Order::create_order();
     $this->assertEmpty($order->get_payment_tokens());
     $token = WC_Helper_Payment_Token::create_cc_token();
     $order->add_payment_token($token);
     $this->assertCount(1, $order->get_payment_tokens());
 }
Example #5
0
 /**
  * Test reading/getting a token from DB correctly sets meta.
  * @since 2.6.0
  */
 public function test_wc_payment_token_cc_read_pulls_meta()
 {
     $token = \WC_Helper_Payment_Token::create_cc_token();
     $token_id = $token->get_id();
     $token_read = new \WC_Payment_Token_CC();
     $token_read->read($token_id);
     $this->assertEquals('1234', $token_read->get_last4());
 }
Example #6
0
 /**
  * Test deleting a token.
  * @since 2.6.0
  */
 public function test_wc_payment_token_delete()
 {
     $token = \WC_Helper_Payment_Token::create_stub_token(__FUNCTION__);
     $token_id = $token->get_id();
     $token->delete();
     $get_token = \WC_Payment_Tokens::get($token_id);
     $this->assertNull($get_token);
 }
Example #7
0
 /**
  * Test setting a users default token.
  * @since 2.6.0
  */
 function test_wc_payment_tokens_set_users_default()
 {
     $token = \WC_Helper_Payment_Token::create_cc_token();
     $token_id = $token->get_id();
     $token->set_user_id(1);
     $token->save();
     $token2 = \WC_Helper_Payment_Token::create_cc_token();
     $token_id_2 = $token2->get_id();
     $token2->set_user_id(1);
     $token2->save();
     $this->assertFalse($token->is_default());
     $this->assertFalse($token2->is_default());
     \WC_Payment_Tokens::set_users_default(1, $token_id_2);
     $token->read($token_id);
     $token2->read($token_id_2);
     $this->assertFalse($token->is_default());
     $this->assertTrue($token2->is_default());
     \WC_Payment_Tokens::set_users_default(1, $token_id);
     $token->read($token_id);
     $token2->read($token_id_2);
     $this->assertTrue($token->is_default());
     $this->assertFalse($token2->is_default());
 }