|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class WC_Stripe_Test extends WP_UnitTestCase { |
|
4
|
|
|
public function test_constants_defined() { |
|
5
|
|
|
$this->assertTrue( defined( 'WC_STRIPE_VERSION' ) ); |
|
6
|
|
|
$this->assertTrue( defined( 'WC_STRIPE_MIN_PHP_VER' ) ); |
|
7
|
|
|
$this->assertTrue( defined( 'WC_STRIPE_MIN_WC_VER' ) ); |
|
8
|
|
|
$this->assertTrue( defined( 'WC_STRIPE_MAIN_FILE' ) ); |
|
9
|
|
|
$this->assertTrue( defined( 'WC_STRIPE_PLUGIN_URL' ) ); |
|
10
|
|
|
$this->assertTrue( defined( 'WC_STRIPE_PLUGIN_PATH' ) ); |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Stripe requires price in the smallest dominations aka cents. |
|
15
|
|
|
* This test will see if we're indeed converting the price correctly. |
|
16
|
|
|
*/ |
|
17
|
|
|
public function test_price_conversion_before_send_to_stripe() { |
|
18
|
|
|
$this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
19
|
|
|
$this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 10050, 'JPY' ) ); |
|
20
|
|
|
$this->assertEquals( 100, WC_Stripe_Helper::get_stripe_amount( 100.50, 'JPY' ) ); |
|
21
|
|
|
$this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50 ) ); |
|
22
|
|
|
$this->assertInternalType( 'int', WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* We store balance fee/net amounts coming from Stripe. |
|
27
|
|
|
* We need to make sure we format it correctly to be stored in WC. |
|
28
|
|
|
* These amounts are posted in lowest dominations. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function test_format_balance_fee() { |
|
31
|
|
|
$balance_fee1 = new stdClass(); |
|
32
|
|
|
$balance_fee1->fee = 10500; |
|
33
|
|
|
$balance_fee1->net = 10000; |
|
34
|
|
|
$balance_fee1->currency = 'USD'; |
|
35
|
|
|
|
|
36
|
|
|
$this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee1, 'fee' ) ); |
|
37
|
|
|
|
|
38
|
|
|
$balance_fee2 = new stdClass(); |
|
39
|
|
|
$balance_fee2->fee = 10500; |
|
40
|
|
|
$balance_fee2->net = 10000; |
|
41
|
|
|
$balance_fee2->currency = 'JPY'; |
|
42
|
|
|
|
|
43
|
|
|
$this->assertEquals( 10500, WC_Stripe_Helper::format_balance_fee( $balance_fee2, 'fee' ) ); |
|
44
|
|
|
|
|
45
|
|
|
$balance_fee3 = new stdClass(); |
|
46
|
|
|
$balance_fee3->fee = 10500; |
|
47
|
|
|
$balance_fee3->net = 10000; |
|
48
|
|
|
$balance_fee3->currency = 'USD'; |
|
49
|
|
|
|
|
50
|
|
|
$this->assertEquals( 100.00, WC_Stripe_Helper::format_balance_fee( $balance_fee3, 'net' ) ); |
|
51
|
|
|
|
|
52
|
|
|
$balance_fee4 = new stdClass(); |
|
53
|
|
|
$balance_fee4->fee = 10500; |
|
54
|
|
|
$balance_fee4->net = 10000; |
|
55
|
|
|
$balance_fee4->currency = 'JPY'; |
|
56
|
|
|
|
|
57
|
|
|
$this->assertEquals( 10000, WC_Stripe_Helper::format_balance_fee( $balance_fee4, 'net' ) ); |
|
58
|
|
|
|
|
59
|
|
|
$balance_fee5 = new stdClass(); |
|
60
|
|
|
$balance_fee5->fee = 10500; |
|
61
|
|
|
$balance_fee5->net = 10000; |
|
62
|
|
|
$balance_fee5->currency = 'USD'; |
|
63
|
|
|
|
|
64
|
|
|
$this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertInternalType( 'string', WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Stripe requires statement_descriptor to be no longer than 22 characters. |
|
71
|
|
|
* In addition, it cannot contain <>"' special characters. |
|
72
|
|
|
* |
|
73
|
|
|
* @dataProvider statement_descriptor_sanitation_provider |
|
74
|
|
|
*/ |
|
75
|
|
|
public function test_statement_descriptor_sanitation( $original, $expected ) { |
|
76
|
|
|
$this->assertEquals( $expected, WC_Stripe_Helper::clean_statement_descriptor( $original ) ); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function statement_descriptor_sanitation_provider() { |
|
80
|
|
|
return [ |
|
81
|
|
|
'removes \'' => [ 'Test\'s Store', 'Tests Store' ], |
|
82
|
|
|
'removes "' => [ 'Test " Store', 'Test Store' ], |
|
83
|
|
|
'removes <' => [ 'Test < Store', 'Test Store' ], |
|
84
|
|
|
'removes >' => [ 'Test > Store', 'Test Store' ], |
|
85
|
|
|
'removes /' => [ 'Test / Store', 'Test Store' ], |
|
86
|
|
|
'removes (' => [ 'Test ( Store', 'Test Store' ], |
|
87
|
|
|
'removes )' => [ 'Test ) Store', 'Test Store' ], |
|
88
|
|
|
'removes {' => [ 'Test { Store', 'Test Store' ], |
|
89
|
|
|
'removes }' => [ 'Test } Store', 'Test Store' ], |
|
90
|
|
|
'removes \\' => [ 'Test \\ Store', 'Test Store' ], |
|
91
|
|
|
'removes *' => [ 'Test * Store', 'Test Store' ], |
|
92
|
|
|
'keeps at most 22 chars' => [ 'Test\'s Store > Driving Course Range', 'Tests Store Driving C' ], |
|
93
|
|
|
'mixed length, \' and >' => [ 'Test\'s Store > Driving Course Range', 'Tests Store Driving C' ], |
|
94
|
|
|
'mixed length, \' and <' => [ 'Test\'s Store < Driving Course Range', 'Tests Store Driving C' ], |
|
95
|
|
|
'mixed length, \' and "' => [ 'Test\'s Store " Driving Course Range', 'Tests Store Driving C' ] |
|
96
|
|
|
]; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|