|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Payment test |
|
4
|
|
|
* |
|
5
|
|
|
* @author Pronamic <[email protected]> |
|
6
|
|
|
* @copyright 2005-2018 Pronamic |
|
7
|
|
|
* @license GPL-3.0-or-later |
|
8
|
|
|
* @package Pronamic\WordPress\Pay\Payments |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Payments; |
|
12
|
|
|
|
|
13
|
|
|
use Pronamic\WordPress\Pay\CreditCard; |
|
14
|
|
|
use stdClass; |
|
15
|
|
|
use WP_UnitTestCase; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Payment test |
|
19
|
|
|
* |
|
20
|
|
|
* @author Remco Tolsma |
|
21
|
|
|
* @version 1.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
class PaymentTest extends WP_UnitTestCase { |
|
24
|
|
|
/** |
|
25
|
|
|
* Test construct payment object. |
|
26
|
|
|
*/ |
|
27
|
|
|
public function test_construct() { |
|
28
|
|
|
$payment = new Payment(); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertInstanceOf( __NAMESPACE__ . '\Payment', $payment ); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Test set and get. |
|
35
|
|
|
* |
|
36
|
|
|
* @dataProvider get_and_set_provider |
|
37
|
|
|
*/ |
|
38
|
|
|
public function test_set_and_get( $set_function, $get_function, $value ) { |
|
39
|
|
|
$payment = new Payment(); |
|
40
|
|
|
|
|
41
|
|
|
$payment->$set_function( $value ); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertEquals( $value, $payment->$get_function() ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function get_and_set_provider() { |
|
47
|
|
|
return array( |
|
48
|
|
|
array( 'set_id', 'get_id', uniqid() ), |
|
49
|
|
|
array( 'set_transaction_id', 'get_transaction_id', uniqid() ), |
|
50
|
|
|
array( 'set_status', 'get_status', 'completed' ), |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Test set. |
|
56
|
|
|
* |
|
57
|
|
|
* @dataProvider set_provider |
|
58
|
|
|
*/ |
|
59
|
|
|
public function test_set( $set_function, $property, $value ) { |
|
60
|
|
|
$payment = new Payment(); |
|
61
|
|
|
|
|
62
|
|
|
$payment->$set_function( $value ); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertEquals( $value, $payment->$property ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function set_provider() { |
|
68
|
|
|
return array( |
|
69
|
|
|
array( 'set_consumer_name', 'consumer_name', 'John Doe' ), |
|
70
|
|
|
array( 'set_consumer_account_number', 'consumer_account_number', '1086.34.779' ), |
|
71
|
|
|
array( 'set_consumer_iban', 'consumer_iban', 'NL56 RABO 0108 6347 79' ), |
|
72
|
|
|
array( 'set_consumer_bic', 'consumer_bic', 'RABONL2U' ), |
|
73
|
|
|
array( 'set_consumer_city', 'consumer_city', 'Drachten' ), |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Test get. |
|
79
|
|
|
* |
|
80
|
|
|
* @dataProvider get_provider |
|
81
|
|
|
*/ |
|
82
|
|
|
public function test_get( $property, $get_function, $value ) { |
|
83
|
|
|
$payment = new Payment(); |
|
84
|
|
|
|
|
85
|
|
|
$payment->$property = $value; |
|
86
|
|
|
|
|
87
|
|
|
$this->assertEquals( $value, $payment->$get_function() ); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function get_provider() { |
|
91
|
|
|
return array( |
|
92
|
|
|
array( 'order_id', 'get_order_id', 1234 ), |
|
93
|
|
|
array( 'amount', 'get_amount', 89.95 ), |
|
94
|
|
|
array( 'currency', 'get_currency', 'EUR' ), |
|
95
|
|
|
array( 'method', 'get_method', 'ideal' ), |
|
96
|
|
|
array( 'issuer', 'get_issuer', 'ideal_KNABNL2H' ), |
|
97
|
|
|
array( 'language', 'get_language', 'nl' ), |
|
98
|
|
|
array( 'locale', 'get_locale', 'nl_NL' ), |
|
99
|
|
|
array( 'description', 'get_description', 'Lorem ipsum dolor sit amet, consectetur.' ), |
|
100
|
|
|
array( 'email', 'get_email', '[email protected]' ), |
|
101
|
|
|
array( 'first_name', 'get_first_name', 'John' ), |
|
102
|
|
|
array( 'last_name', 'get_last_name', 'Doe' ), |
|
103
|
|
|
array( 'customer_name', 'get_customer_name', 'John Doe' ), |
|
104
|
|
|
array( 'address', 'get_address', 'Burgemeester Wuiteweg 39b' ), |
|
105
|
|
|
array( 'city', 'get_city', 'Drachten' ), |
|
106
|
|
|
array( 'zip', 'get_zip', '9203 KA' ), |
|
107
|
|
|
array( 'country', 'get_country', 'NL' ), |
|
108
|
|
|
array( 'telephone_number', 'get_telephone_number', '1234567890' ), |
|
109
|
|
|
array( 'analytics_client_id', 'get_analytics_client_id', 'GA1.2.1234567890.1234567890' ), |
|
110
|
|
|
array( 'entrance_code', 'get_entrance_code', uniqid() ), |
|
111
|
|
|
); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Test getting no payment. |
|
116
|
|
|
* |
|
117
|
|
|
* @see https://github.com/easydigitaldownloads/easy-digital-downloads/blob/2.8.18/tests/tests-payment-class.php#L70-L79 |
|
118
|
|
|
*/ |
|
119
|
|
|
public function test_getting_no_payment() { |
|
120
|
|
|
$payment = new Payment(); |
|
121
|
|
|
|
|
122
|
|
|
$this->assertNull( $payment->get_id() ); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Test setting and getting the payment credit card. |
|
127
|
|
|
*/ |
|
128
|
|
|
public function test_set_and_get_credit_card() { |
|
129
|
|
|
$payment = new Payment(); |
|
130
|
|
|
|
|
131
|
|
|
$credit_card = new CreditCard(); |
|
132
|
|
|
$credit_card->set_number( '5300000000000006' ); |
|
133
|
|
|
$credit_card->set_expiration_month( 12 ); |
|
134
|
|
|
$credit_card->set_expiration_year( date( 'Y' ) + 5 ); |
|
135
|
|
|
$credit_card->set_security_code( '123' ); |
|
136
|
|
|
$credit_card->set_name( 'Pronamic' ); |
|
137
|
|
|
|
|
138
|
|
|
$payment->set_credit_card( $credit_card ); |
|
139
|
|
|
|
|
140
|
|
|
$this->assertEquals( $credit_card, $payment->get_credit_card() ); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|