-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCoinpaymentsValidatorTest.php
171 lines (153 loc) · 5.85 KB
/
CoinpaymentsValidatorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
require('../src/CoinpaymentsValidator.php');
use PHPUnit\Framework\TestCase;
class CoinpaymentsValidatorTest extends TestCase
{
private $validator;
private $fields;
protected function setUp()
{
$this->fields = [];
}
/**
* @expectedExceptionMessage
*/
public function testInvalidCommand()
{
$this->validator = new CoinpaymentsValidator('fake_command', $this->fields);
$is_valid = $this->validator->validate();
$this->assertEquals('Error: Invalid command name!', $is_valid);
}
public function testMissingRequiredField()
{
$this->fields = [
'full' => 1
];
$this->validator = new CoinpaymentsValidator('get_tx_info_multi', $this->fields);
$is_valid = $this->validator->validate();
$this->assertEquals('Error: The field "full" was passed but is not a valid field for the "get_tx_info_multi" command!', $is_valid);
}
public function testPassingInvalidField()
{
$this->fields = [
'fake_field' => 1
];
$this->validator = new CoinpaymentsValidator('rates', $this->fields);
$is_valid = $this->validator->validate();
$this->assertEquals('Error: The field "fake_field" was passed but is not a valid field for the "rates" command!', $is_valid);
}
public function testInvalidFieldStringType()
{
$fake_array = ['test1', 'test2'];
$this->fields = [
'txid' => $fake_array,
'full' => 1
];
$this->validator = new CoinpaymentsValidator('get_tx_info', $this->fields);
$is_valid = $this->validator->validate();
$this->assertEquals('Error: Field "txid" passed with value of "[ArrayData]" and data type of "array", but expected type is "string".', $is_valid);
}
public function testInvalidFieldIntegerType()
{
$this->fields = [
'txid' => 'test1',
'full' => 'test2'
];
$this->validator = new CoinpaymentsValidator('get_tx_info', $this->fields);
$is_valid = $this->validator->validate();
$this->assertEquals('Error: Field "full" passed with value of "test2" and data type of "string", but expected type is "integer".', $is_valid);
}
public function testInvalidFieldArrayType()
{
$this->fields = [
'wd' => 'test1'
];
$this->validator = new CoinpaymentsValidator('create_mass_withdrawal', $this->fields);
$is_valid = $this->validator->validate();
$this->assertEquals('Error: Field "wd" passed with value of "test1" and data type of "string", but expected type is "array".', $is_valid);
}
public function testInvalidFieldUrlType()
{
$this->fields = [
'currency' => 'BTC',
'ipn_url' => 'test.com'
];
$this->validator = new CoinpaymentsValidator('get_callback_address', $this->fields);
$is_valid = $this->validator->validate();
$this->assertEquals('Error: Field "ipn_url" passed with value of "test.com" and data type of "string", but expected type is "url".', $is_valid);
}
public function testInvalidFieldEmailType()
{
$this->fields = [
'amount' => 1,
'currency1' => 'BTC',
'buyer_email' => 'notanemail.com'
];
$this->validator = new CoinpaymentsValidator('create_transaction', $this->fields);
$is_valid = $this->validator->validate();
$this->assertEquals('Error: Field "buyer_email" passed with value of "notanemail.com" and data type of "string", but expected type is "email".', $is_valid);
}
public function testInvalidPermittedFieldValue()
{
$this->fields = [
'all' => 3
];
$this->validator = new CoinpaymentsValidator('balances', $this->fields);
$is_valid = $this->validator->validate();
$this->assertEquals('Error: Permitted values for the field "all" are [ 0 | 1 ] but the value passed was: 3', $is_valid);
}
public function testValidPermittedFieldValue()
{
$this->fields = [
'all' => 1
];
$this->validator = new CoinpaymentsValidator('balances', $this->fields);
$is_valid = $this->validator->validate();
$this->assertTrue($is_valid);
}
public function testMissingOneOfField()
{
$this->fields = [
'amount' => 1,
'currency' => 'BTC'
];
$this->validator = new CoinpaymentsValidator('create_transfer', $this->fields);
$is_valid = $this->validator->validate();
$this->assertEquals('Error: At least one of the following fields must be passed: [ merchant | pbntag ]', $is_valid);
}
public function testTooManyOneOfFields()
{
$this->fields = [
'amount' => 1,
'currency' => 'BTC',
'merchant' => 'test1',
'pbntag' => 'test2'
];
$this->validator = new CoinpaymentsValidator('create_transfer', $this->fields);
$is_valid = $this->validator->validate();
$this->assertEquals('Error: No more than one of the following fields can be passed: [ merchant | pbntag ]', $is_valid);
}
public function testNoFields()
{
$this->validator = new CoinpaymentsValidator('get_basic_info', $this->fields);
$is_valid = $this->validator->validate();
$this->assertTrue($is_valid);
}
public function testAllFieldGroups()
{
$this->fields = [
'amount' => 1,
'currency' => 'BTC',
'merchant' => 'test1',
'auto_confirm' => 1
];
$this->validator = new CoinpaymentsValidator('create_transfer', $this->fields);
$is_valid = $this->validator->validate();
$this->assertTrue($is_valid);
}
protected function tearDown()
{
$this->validator = null;
$this->fields = null;
}
}