Skip to content

Commit

Permalink
Specific unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrosa committed Dec 30, 2024
1 parent 7a3fc08 commit eccc35f
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/phpunit/payment-tokens/test-trait-wc-stripe-fingerprint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Trait WC_Stripe_Fingerprint_Trait tests.
*/
class WC_Stripe_Fingerprint_Test extends WP_UnitTestCase {
/**
* Test for `get_fingerprint` and `set_fingerprint`.
*
* @return void
*/
public function test_fingerprint() {
$token = new WC_Stripe_Payment_Token_CC();
$token->set_fingerprint( '123abc' );
$this->assertEquals( '123abc', $token->get_fingerprint() );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* Trait WC_Stripe_Token_Comparison_Trait tests.
*/
class WC_Stripe_Token_Comparison_Test extends WP_UnitTestCase {
/**
* Test for `is_equal`.
*
* @param string $token_type Token type.
* @param object $payment_method Payment method object.
* @param boolean $expected Whether the payment method is equal.
* @return void
* @dataProvider provide_test_is_equal
*/
public function test_is_equal( $token_type, $payment_method, $expected ) {
switch ( $token_type ) {
case 'sepa':
$token = new WC_Payment_Token_SEPA();
$token->set_fingerprint( '123abc' );
break;
case 'link':
$token = new WC_Payment_Token_Link();
$token->set_email( '[email protected]' );
break;
case 'cashapp':
$token = new WC_Payment_Token_CashApp();
$token->set_cashtag( '$test_cashtag' );
break;
case 'CC':
default:
$token = new WC_Stripe_Payment_Token_CC();
$token->set_fingerprint( '123abc' );
}

$this->assertEquals( $expected, $token->is_equal( $payment_method ) );
}

/**
* Data provider for `test_is_equal`.
*
* @return array
*/
public function provide_test_is_equal() {
return [
'Unknown method' => [
'token type' => 'unknown',
'payment method' => (object) [],
'expected' => false,
],
'CC, not equal' => [
'token type' => 'CC',
'payment_method' => (object) [
'card' => (object) [
'fingerprint' => '456def',
],
],
'expected' => false,
],
'CC, equal' => [
'token type' => 'CC',
'payment method' => (object) [
'card' => (object) [
'fingerprint' => '123abc',
],
],
'expected' => true,
],
'SEPA, equal' => [
'token type' => 'sepa',
'payment method' => (object) [
'sepa_debit' => (object) [
'fingerprint' => '123abc',
],
],
'expected' => true,
],
'Link, equal' => [
'token type' => 'link',
'payment method' => (object) [
'link' => (object) [
'email' => '[email protected]',
],
],
'expected' => true,
],
'CashApp, equal' => [
'token type' => 'cashapp',
'payment method' => (object) [
'cashapp' => (object) [
'cashtag' => '$test_cashtag',
],
],
'expected' => true,
],
];
}
}

0 comments on commit eccc35f

Please sign in to comment.