/**
  * Create a new 'stub' payment token
  *
  * @since 2.6
  * @param  string $extra A string to insert and get to test the metadata functionality of a token
  * @return WC_Payment_Token_Stub object
  */
 public static function create_stub_token($extra)
 {
     $token = new WC_Payment_Token_Stub();
     $token->set_extra($extra);
     $token->set_token(time());
     $token->save();
     return $token;
 }
예제 #2
0
 /**
  * Test: get_payment_tokens
  */
 function test_get_payment_tokens()
 {
     $object = new WC_Order();
     $object->save();
     $token = new WC_Payment_Token_Stub();
     $token->set_extra(__FUNCTION__);
     $token->set_token(time());
     $token->save();
     $object->add_payment_token($token);
     $this->assertCount(1, $object->get_payment_tokens());
 }
예제 #3
0
 /**
  * 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());
 }
예제 #4
0
 /**
  * Test creating a new token.
  * @since 2.6.0
  */
 public function test_wc_payment_token_create()
 {
     $token = new \WC_Payment_Token_Stub();
     $token->set_extra(__FUNCTION__);
     $token->set_token(time());
     $token->create();
     $this->assertNotEmpty($token->get_id());
     $this->assertEquals(__FUNCTION__, $token->get_extra());
 }