@@ -25,13 +25,13 @@ class RendererTest extends TestCase
25
25
{
26
26
public function testRenderTextOnly (): void
27
27
{
28
- $ email = $ this ->prepareEmail (null , 'Text ' , null );
28
+ $ email = $ this ->prepareEmail ('Text ' , null );
29
29
$ this ->assertEquals ('Text ' , $ email ->getBody ()->bodyToString ());
30
30
}
31
31
32
32
public function testRenderHtmlOnly (): void
33
33
{
34
- $ email = $ this ->prepareEmail (null , null , '<b>HTML</b> ' );
34
+ $ email = $ this ->prepareEmail (null , '<b>HTML</b> ' );
35
35
$ body = $ email ->getBody ();
36
36
$ this ->assertInstanceOf (AlternativePart::class, $ body );
37
37
$ this ->assertEquals ('HTML ' , $ body ->getParts ()[0 ]->bodyToString ());
@@ -40,7 +40,7 @@ public function testRenderHtmlOnly(): void
40
40
41
41
public function testRenderHtmlOnlyWithTextSet (): void
42
42
{
43
- $ email = $ this ->prepareEmail (null , null , '<b>HTML</b> ' );
43
+ $ email = $ this ->prepareEmail (null , '<b>HTML</b> ' );
44
44
$ email ->text ('Text ' );
45
45
$ body = $ email ->getBody ();
46
46
$ this ->assertInstanceOf (AlternativePart::class, $ body );
@@ -50,118 +50,23 @@ public function testRenderHtmlOnlyWithTextSet(): void
50
50
51
51
public function testRenderTextAndHtml (): void
52
52
{
53
- $ email = $ this ->prepareEmail (null , 'Text ' , '<b>HTML</b> ' );
53
+ $ email = $ this ->prepareEmail ('Text ' , '<b>HTML</b> ' );
54
54
$ body = $ email ->getBody ();
55
55
$ this ->assertInstanceOf (AlternativePart::class, $ body );
56
56
$ this ->assertEquals ('Text ' , $ body ->getParts ()[0 ]->bodyToString ());
57
57
$ this ->assertEquals ('<b>HTML</b> ' , $ body ->getParts ()[1 ]->bodyToString ());
58
58
}
59
59
60
- public function testRenderFullOnly (): void
61
- {
62
- $ email = $ this ->prepareEmail (<<<EOF
63
- {% block subject %}Subject{% endblock %}
64
- {% block text %}Text{% endblock %}
65
- {% block html %}<b>HTML</b>{% endblock %}
66
- EOF
67
- , null , null );
68
- $ body = $ email ->getBody ();
69
- $ this ->assertInstanceOf (AlternativePart::class, $ body );
70
- $ this ->assertEquals ('Subject ' , $ email ->getSubject ());
71
- $ this ->assertEquals ('Text ' , $ body ->getParts ()[0 ]->bodyToString ());
72
- $ this ->assertEquals ('<b>HTML</b> ' , $ body ->getParts ()[1 ]->bodyToString ());
73
- }
74
-
75
- public function testRenderFullOnlyWithTextOnly (): void
76
- {
77
- $ email = $ this ->prepareEmail (<<<EOF
78
- {% block text %}Text{% endblock %}
79
- EOF
80
- , null , null );
81
- $ body = $ email ->getBody ();
82
- $ this ->assertInstanceOf (TextPart::class, $ body );
83
- $ this ->assertEquals ('' , $ email ->getSubject ());
84
- $ this ->assertEquals ('Text ' , $ body ->bodyToString ());
85
- }
86
-
87
- public function testRenderFullOnlyWithHtmlOnly (): void
88
- {
89
- $ email = $ this ->prepareEmail (<<<EOF
90
- {% block html %}<b>HTML</b>{% endblock %}
91
- EOF
92
- , null , null );
93
- $ body = $ email ->getBody ();
94
- $ this ->assertInstanceOf (AlternativePart::class, $ body );
95
- $ this ->assertEquals ('' , $ email ->getSubject ());
96
- $ this ->assertEquals ('HTML ' , $ body ->getParts ()[0 ]->bodyToString ());
97
- $ this ->assertEquals ('<b>HTML</b> ' , $ body ->getParts ()[1 ]->bodyToString ());
98
- }
99
-
100
- public function testRenderFullAndText (): void
101
- {
102
- $ email = $ this ->prepareEmail (<<<EOF
103
- {% block text %}Text full{% endblock %}
104
- {% block html %}<b>HTML</b>{% endblock %}
105
- EOF
106
- , 'Text ' , null );
107
- $ body = $ email ->getBody ();
108
- $ this ->assertInstanceOf (AlternativePart::class, $ body );
109
- $ this ->assertEquals ('Text ' , $ body ->getParts ()[0 ]->bodyToString ());
110
- $ this ->assertEquals ('<b>HTML</b> ' , $ body ->getParts ()[1 ]->bodyToString ());
111
- }
112
-
113
- public function testRenderFullAndHtml (): void
114
- {
115
- $ email = $ this ->prepareEmail (<<<EOF
116
- {% block text %}Text full{% endblock %}
117
- {% block html %}<b>HTML</b>{% endblock %}
118
- EOF
119
- , null , '<i>HTML</i> ' );
120
- $ body = $ email ->getBody ();
121
- $ this ->assertInstanceOf (AlternativePart::class, $ body );
122
- $ this ->assertEquals ('Text full ' , $ body ->getParts ()[0 ]->bodyToString ());
123
- $ this ->assertEquals ('<i>HTML</i> ' , $ body ->getParts ()[1 ]->bodyToString ());
124
- }
125
-
126
- public function testRenderHtmlWithEmbeddedImages (): void
127
- {
128
- $ email = $ this ->prepareEmail (null , null , '<img src="{{ email.image("image.jpg") }}" /> ' );
129
- $ body = $ email ->getBody ();
130
- $ this ->assertInstanceOf (RelatedPart::class, $ body );
131
- $ this ->assertInstanceOf (AlternativePart::class, $ body ->getParts ()[0 ]);
132
- $ this ->assertStringMatchesFormat ('<img src=3D"cid:%s@symfony" /> ' , $ body ->getParts ()[0 ]->getParts ()[1 ]->bodyToString ());
133
- $ this ->assertEquals ('Some image data ' , base64_decode ($ body ->getParts ()[1 ]->bodyToString ()));
134
- }
135
-
136
- public function testRenderFullWithAttachments (): void
137
- {
138
- $ email = $ this ->prepareEmail (<<<EOF
139
- {% block text %}Text{% endblock %}
140
- {% block config %}
141
- {% do email.attach('document.txt') %}
142
- {% endblock %}
143
- EOF
144
- , null , null );
145
- $ body = $ email ->getBody ();
146
- $ this ->assertInstanceOf (MixedPart::class, $ body );
147
- $ this ->assertEquals ('Text ' , $ body ->getParts ()[0 ]->bodyToString ());
148
- $ this ->assertEquals ('Some text document... ' , base64_decode ($ body ->getParts ()[1 ]->bodyToString ()));
149
- }
150
-
151
- private function prepareEmail (?string $ full , ?string $ text , ?string $ html ): TemplatedEmail
60
+ private function prepareEmail (?string $ text , ?string $ html ): TemplatedEmail
152
61
{
153
62
$ twig = new Environment (new ArrayLoader ([
154
- 'full ' => $ full ,
155
63
'text ' => $ text ,
156
64
'html ' => $ html ,
157
65
'document.txt ' => 'Some text document... ' ,
158
66
'image.jpg ' => 'Some image data ' ,
159
67
]));
160
68
$ renderer = new BodyRenderer ($ twig );
161
69
$ email = (new TemplatedEmail ())->to ('fabien@symfony.com ' )->from ('helene@symfony.com ' );
162
- if (null !== $ full ) {
163
- $ email ->template ('full ' );
164
- }
165
70
if (null !== $ text ) {
166
71
$ email ->textTemplate ('text ' );
167
72
}
0 commit comments