Skip to content

Commit fa2e30a

Browse files
committed
Add more unit tests
1 parent eb4c365 commit fa2e30a

File tree

2 files changed

+118
-6
lines changed

2 files changed

+118
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
/**
4+
* Class Test_WC_Payment_Token_Amazon_Pay tests.
5+
*
6+
*/
7+
class Test_WC_Payment_Token_Amazon_Pay extends WP_UnitTestCase {
8+
9+
/**
10+
* Instance of WC_Payment_Token_Amazon_Pay to test.
11+
*
12+
* @var WC_Payment_Token_Amazon_Pay
13+
*/
14+
private $token;
15+
16+
/**
17+
* Setup test environment.
18+
*/
19+
public function setUp(): void {
20+
parent::setUp();
21+
$this->token = new WC_Payment_Token_Amazon_Pay();
22+
$this->token->set_email( '[email protected]' );
23+
}
24+
25+
/**
26+
* Test that the token type is correctly set as amazon_pay.
27+
*/
28+
public function test_token_type_is_amazon_pay() {
29+
$this->assertEquals(
30+
WC_Stripe_Payment_Methods::AMAZON_PAY,
31+
$this->token->get_type(),
32+
'The token "type" property should match amazon_pay.'
33+
);
34+
}
35+
36+
/**
37+
* Test setting and retrieving the email property.
38+
*/
39+
public function test_set_and_get_email() {
40+
$this->token->set_email( '[email protected]' );
41+
$this->assertEquals(
42+
43+
$this->token->get_email(),
44+
'The email property should match the value that was set.'
45+
);
46+
}
47+
48+
/**
49+
* Test is_equal_payment_method() returns true when type and email match.
50+
*/
51+
public function test_is_equal_payment_method_returns_true_on_valid_object() {
52+
$payment_method_mock = (object) [
53+
'type' => WC_Stripe_Payment_Methods::AMAZON_PAY,
54+
'billing_details' => (object) [
55+
'email' => '[email protected]',
56+
],
57+
];
58+
59+
$this->assertTrue(
60+
$this->token->is_equal_payment_method( $payment_method_mock ),
61+
'is_equal_payment_method() should return true when type and email match.'
62+
);
63+
}
64+
65+
/**
66+
* Test is_equal_payment_method() returns false for a mismatched type.
67+
*/
68+
public function test_is_equal_payment_method_returns_false_mismatched_type() {
69+
$payment_method_mock = (object) [
70+
'type' => 'card',
71+
'billing_details' => (object) [
72+
'email' => '[email protected]',
73+
],
74+
];
75+
76+
$this->assertFalse(
77+
$this->token->is_equal_payment_method( $payment_method_mock ),
78+
'is_equal_payment_method() should return false when the type is not amazon_pay.'
79+
);
80+
}
81+
82+
/**
83+
* Test is_equal_payment_method() returns false for a mismatched email.
84+
*/
85+
public function test_is_equal_payment_method_returns_false_mismatched_email() {
86+
$payment_method_mock = (object) [
87+
'type' => WC_Stripe_Payment_Methods::AMAZON_PAY,
88+
'billing_details' => (object) [
89+
'email' => '[email protected]',
90+
],
91+
];
92+
93+
$this->assertFalse(
94+
$this->token->is_equal_payment_method( $payment_method_mock ),
95+
'is_equal_payment_method() should return false when the email does not match.'
96+
);
97+
}
98+
}

tests/phpunit/payment-tokens/test-interface-wc-stripe-token-comparison.php

+20-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public function test_is_equal_payment_method( $token_type, $payment_method, $exp
2222
$token = new WC_Payment_Token_Link();
2323
$token->set_email( '[email protected]' );
2424
break;
25+
case WC_Stripe_Payment_Methods::AMAZON_PAY:
26+
$token = new WC_Payment_Token_Amazon_Pay();
27+
$token->set_email( '[email protected]' );
28+
break;
2529
case WC_Stripe_Payment_Methods::CASHAPP_PAY:
2630
$token = new WC_Payment_Token_CashApp();
2731
$token->set_cashtag( '$test_cashtag' );
@@ -42,14 +46,14 @@ public function test_is_equal_payment_method( $token_type, $payment_method, $exp
4246
*/
4347
public function provide_test_is_equal_payment_method() {
4448
return [
45-
'Unknown method' => [
49+
'Unknown method' => [
4650
'token type' => 'unknown',
4751
'payment method' => (object) [
4852
'type' => 'unknown',
4953
],
5054
'expected' => false,
5155
],
52-
'CC, not equal' => [
56+
'CC, not equal' => [
5357
'token type' => 'CC',
5458
'payment_method' => (object) [
5559
'type' => WC_Stripe_Payment_Methods::CARD,
@@ -59,7 +63,7 @@ public function provide_test_is_equal_payment_method() {
5963
],
6064
'expected' => false,
6165
],
62-
'CC, equal' => [
66+
'CC, equal' => [
6367
'token type' => 'CC',
6468
'payment method' => (object) [
6569
'type' => WC_Stripe_Payment_Methods::CARD,
@@ -69,7 +73,7 @@ public function provide_test_is_equal_payment_method() {
6973
],
7074
'expected' => true,
7175
],
72-
'SEPA, equal' => [
76+
'SEPA, equal' => [
7377
'token type' => WC_Stripe_Payment_Methods::SEPA,
7478
'payment method' => (object) [
7579
'type' => WC_Stripe_Payment_Methods::SEPA_DEBIT,
@@ -79,7 +83,7 @@ public function provide_test_is_equal_payment_method() {
7983
],
8084
'expected' => true,
8185
],
82-
'Link, equal' => [
86+
'Link, equal' => [
8387
'token type' => WC_Stripe_Payment_Methods::LINK,
8488
'payment method' => (object) [
8589
'type' => WC_Stripe_Payment_Methods::LINK,
@@ -89,7 +93,17 @@ public function provide_test_is_equal_payment_method() {
8993
],
9094
'expected' => true,
9195
],
92-
'CashApp, equal' => [
96+
'Amazon Pay, equal' => [
97+
'token type' => WC_Stripe_Payment_Methods::AMAZON_PAY,
98+
'payment method' => (object) [
99+
'type' => WC_Stripe_Payment_Methods::AMAZON_PAY,
100+
'billing_details' => (object) [
101+
'email' => '[email protected]',
102+
],
103+
],
104+
'expected' => true,
105+
],
106+
'CashApp, equal' => [
93107
'token type' => WC_Stripe_Payment_Methods::CASHAPP_PAY,
94108
'payment method' => (object) [
95109
'type' => WC_Stripe_Payment_Methods::CASHAPP_PAY,

0 commit comments

Comments
 (0)