-
Notifications
You must be signed in to change notification settings - Fork 626
/
Copy pathSingleEmailToMultipleRecipientsTest.php
110 lines (102 loc) · 3.14 KB
/
SingleEmailToMultipleRecipientsTest.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
<?php
/**
* This file tests the request object generation for a /mail/send API call.
*/
namespace SendGrid\Tests\Unit;
use SendGrid\Tests\BaseTestClass;
/**
* This class tests the request object generation for a /mail/send API call.
*
* @package SendGrid\Tests\Unit
*/
class SingleEmailToMultipleRecipientsTest extends BaseTestClass
{
private $REQUEST_OBJECT = <<<'JSON'
{
"personalizations": [
{
"to": [
{
"email": "test+test1@example.com",
"name": "Example User1"
},
{
"email": "test+test2@example.com",
"name": "Example User2"
},
{
"email": "test+test3@example.com",
"name": "Example User3"
}
]
}
],
"subject": "Sending with Twilio SendGrid is Fun",
"content": [
{
"type": "text/plain",
"value": "and easy to do anywhere, even with PHP"
},
{
"type": "text/html",
"value": "<strong>and easy to do anywhere, even with PHP</strong>"
}
],
"from": {
"email": "test@example.com",
"name": "Example User"
}
}
JSON;
/**
* Test when we are using objects
*/
public function testWithObjects()
{
$from = new \SendGrid\Mail\From("test@example.com", "Example User");
$tos = [
new \SendGrid\Mail\To("test+test1@example.com", "Example User1"),
new \SendGrid\Mail\To("test+test2@example.com", "Example User2"),
new \SendGrid\Mail\To("test+test3@example.com", "Example User3")
];
$subject = new \SendGrid\Mail\Subject("Sending with Twilio SendGrid is Fun");
$plainTextContent = new \SendGrid\Mail\PlainTextContent(
"and easy to do anywhere, even with PHP"
);
$htmlContent = new \SendGrid\Mail\HtmlContent(
"<strong>and easy to do anywhere, even with PHP</strong>"
);
$email = new \SendGrid\Mail\Mail(
$from,
$tos,
$subject,
$plainTextContent,
$htmlContent
);
$json = json_encode($email->jsonSerialize());
$isEqual = BaseTestClass::compareJSONObjects($json, $this->REQUEST_OBJECT);
$this->assertTrue($isEqual);
}
/**
* Test when we are not using objects
*/
public function testWithoutObjects()
{
$email = new \SendGrid\Mail\Mail();
$email->setFrom("test@example.com", "Example User");
$tos = [
"test+test1@example.com" => "Example User1",
"test+test2@example.com" => "Example User2",
"test+test3@example.com" => "Example User3"
];
$email->addTos($tos);
$email->setSubject("Sending with Twilio SendGrid is Fun");
$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
$email->addContent(
"text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
);
$json = json_encode($email->jsonSerialize());
$isEqual = BaseTestClass::compareJSONObjects($json, $this->REQUEST_OBJECT);
$this->assertTrue($isEqual);
}
}