-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathHeaderTest.php
More file actions
254 lines (199 loc) · 7.39 KB
/
HeaderTest.php
File metadata and controls
254 lines (199 loc) · 7.39 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?php
use PHPUnit\Framework\TestCase;
class HeaderTest extends TestCase
{
protected $t;
protected function setUp(): void
{
$file = __DIR__ . '/../smtpapi_test_strings.json';
$json = json_decode(file_get_contents($file), true);
$this->t = $json;
}
public function testConstructionHeader()
{
$header = new Smtpapi\Header();
$this->assertEquals(get_class($header), 'Smtpapi\Header');
}
public function testHasAToJsonStringMethod()
{
$header = new Smtpapi\Header();
$this->assertEquals($this->t['json_string'], $header->jsonString());
}
public function testAddTo()
{
$header = new Smtpapi\Header();
$header->addTo('foo@example.com');
$header->addTo('bar@example.com');
$this->assertEquals($this->t['add_to'], $header->jsonString());
}
public function testAddToWithName()
{
$header = new Smtpapi\Header();
$header->addTo('foo@example.com', 'Mike Bar');
$this->assertEquals($this->t['add_to_name'], $header->jsonString());
}
public function testAddToNameWithComma()
{
$header = new Smtpapi\Header();
$header->addTo('foo@example.com', 'Mike, John and Jane Bar');
$this->assertEquals(
$this->t['add_to_name_with_comma'],
$header->jsonString()
);
}
public function testSetTos()
{
$header = new Smtpapi\Header();
$header->setTos(array('setTos@mailinator.com'));
$this->assertEquals($this->t['set_tos'], $header->jsonString());
}
public function testAddSubstitution()
{
$header = new Smtpapi\Header();
$header->addSubstitution('sub', array('val'));
$this->assertEquals($this->t['add_substitution'], $header->jsonString());
}
public function testSetSubstitutions()
{
$header = new Smtpapi\Header();
$header->setSubstitutions(array('sub' => array('val')));
$this->assertEquals($this->t['set_substitutions'], $header->jsonString());
}
public function testAddUniqueArg()
{
$header = new Smtpapi\Header();
$header->addUniqueArg('add_unique_argument_key', 'add_unique_argument_value');
$header->addUniqueArg('add_unique_argument_key_2', 'add_unique_argument_value_2');
$this->assertEquals($this->t['add_unique_arg'], $header->jsonString());
}
public function testSetUniqueArgs()
{
$header = new Smtpapi\Header();
$header->setUniqueArgs(array('set_unique_argument_key' => 'set_unique_argument_value'));
$this->assertEquals($this->t['set_unique_args'], $header->jsonString());
}
public function testAddCategory()
{
$header = new Smtpapi\Header();
$header->addCategory('addCategory');
$header->addCategory('addCategory2');
$this->assertEquals($this->t['add_category'], $header->jsonString());
}
public function testAddCategoryUnicode()
{
$header = new Smtpapi\Header();
$header->addCategory('天破活殺');
$header->addCategory('天翔十字鳳');
$this->assertEquals($this->t['add_category_unicode'], $header->jsonString());
}
public function testAddCategoryUnicodeUnescape()
{
$header = new Smtpapi\Header();
$header->addCategory('天破活殺');
$header->addCategory('天翔十字鳳');
$options = JSON_UNESCAPED_UNICODE;
$this->assertEquals($this->t['add_category_unicode_unescape'], $header->jsonString($options));
}
public function testSetCategories()
{
$header = new Smtpapi\Header();
$header->setCategories(array('setCategories'));
$this->assertEquals($this->t['set_categories'], $header->jsonString());
}
public function testSetCategory()
{
$header = new Smtpapi\Header();
$header->setCategory('setCategory');
$this->assertEquals($this->t['set_category'], $header->jsonString());
}
public function testAddSection()
{
$header = new Smtpapi\Header();
$header->addSection('set_section_key', 'set_section_value');
$header->addSection('set_section_key_2', 'set_section_value_2');
$this->assertEquals($this->t['add_section'], $header->jsonString());
}
public function testAddSendAt()
{
$header = new Smtpapi\Header();
$header->setSendEachAt(array(1409348513, 1409348514));
$header->setSendAt(1409348513);
$this->assertEquals($this->t['set_send_at'], $header->jsonString());
}
public function testSendEachAt()
{
$header = new Smtpapi\Header();
$header->setSendAt(1409348513);
$header->setSendEachAt(array(1409348513, 1409348514, 1409348515));
$this->assertEquals($this->t['set_send_each_at'], $header->jsonString());
}
public function testAddSendEachAt()
{
$header = new Smtpapi\Header();
$header->setSendAt(1409348513);
$header->addSendEachAt(1409348513);
$header->addSendEachAt(1409348514);
$header->addSendEachAt(1409348515);
$this->assertEquals($this->t['add_send_each_at'], $header->jsonString());
}
public function testSetSendEachAtAndAddSendEachAt()
{
$header = new Smtpapi\Header();
$header->setSendAt(1409348513);
$header->setSendEachAt(array(1409348513));
$header->addSendEachAt(1409348514);
$header->addSendEachAt(1409348515);
$this->assertEquals($this->t['set_send_each_at'], $header->jsonString());
}
public function testSetASMGroupID()
{
$header = new Smtpapi\Header();
$header->setASMGroupID(2);
$this->assertEquals($this->t['set_asm_group_id'], $header->jsonString());
}
public function testSetSections()
{
$header = new Smtpapi\Header();
$header->setSections(array('set_section_key' => 'set_section_value'));
$this->assertEquals($this->t['set_sections'], $header->jsonString());
}
public function testAddFilter()
{
$header = new Smtpapi\Header();
$header->addFilter('footer', 'text/html', '<strong>boo</strong>');
$this->assertEquals($this->t['add_filter'], $header->jsonString());
}
public function testSetFilters()
{
$header = new Smtpapi\Header();
$filter = array(
'footer' => array(
'setting' => array(
'enable' => 1,
'text/plain' => 'You can haz footers!'
)
)
);
$header->setFilters($filter);
$this->assertEquals($this->t['set_filters'], $header->jsonString());
}
public function testGetFilters()
{
$header = new Smtpapi\Header();
$header->addFilter('footer', 'text/html', '<strong>boo</strong>');
$filter = array('footer' => array('settings' => array('text/html' => '<strong>boo</strong>')));
$this->assertEquals($filter, $header->getFilters());
}
public function testSetIpPool()
{
$header = new Smtpapi\Header();
$header->setIpPool('foo');
$this->assertEquals($this->t['set_ip_pool'], $header->jsonString());
}
public function testLicenseDateRange()
{
$license_file = file_get_contents("LICENSE");
$current_year = date("Y");
$this->assertIsInt(strpos($license_file, "Copyright (C) " . $current_year . ", Twilio SendGrid, Inc."));
}
}