4
4
5
5
class CssInlinerPluginTest extends PHPUnit_Framework_TestCase
6
6
{
7
-
8
7
protected $ stubs ;
9
8
9
+ protected $ options ;
10
+
11
+ protected static $ stubDefinitions = array (
12
+ 'plain-text ' , 'original-html ' , 'converted-html ' , 'converted-html-with-classes ' ,
13
+ 'converted-html-with-styles '
14
+ );
15
+
10
16
public function setUp ()
11
17
{
12
- $ this ->stubs ['plain-text ' ] = file_get_contents (__DIR__ .'/stubs/plain-text.stub ' );
13
- $ this ->stubs ['original-html ' ] = file_get_contents (__DIR__ .'/stubs/original-html.stub ' );
14
- $ this ->stubs ['converted-html ' ] = file_get_contents (__DIR__ .'/stubs/converted-html.stub ' );
18
+ foreach (self ::$ stubDefinitions as $ stub ) {
19
+ $ this ->stubs [$ stub ] = file_get_contents (__DIR__ .'/stubs/ ' .$ stub .'.stub ' );
20
+ }
21
+
22
+ $ this ->options = require (__DIR__ .'/../config/css-inliner.php ' );
15
23
}
16
24
17
25
/** @test **/
18
26
public function itShouldConvertHtmlBody ()
19
27
{
20
28
$ mailer = Swift_Mailer::newInstance (Swift_NullTransport::newInstance ());
21
29
22
- $ mailer ->registerPlugin (new CssInlinerPlugin ());
30
+ $ mailer ->registerPlugin (new CssInlinerPlugin ($ this -> options ));
23
31
24
32
$ message = Swift_Message::newInstance ();
25
33
@@ -33,12 +41,54 @@ public function itShouldConvertHtmlBody()
33
41
$ this ->assertEquals ($ this ->stubs ['converted-html ' ], $ message ->getBody ());
34
42
}
35
43
44
+ /** @test **/
45
+ public function itShouldConvertHtmlBodyKeepingClasses ()
46
+ {
47
+ $ this ->options ['strip-classes ' ] = false ;
48
+
49
+ $ mailer = Swift_Mailer::newInstance (Swift_NullTransport::newInstance ());
50
+
51
+ $ mailer ->registerPlugin (new CssInlinerPlugin ($ this ->options ));
52
+
53
+ $ message = Swift_Message::newInstance ();
54
+
55
+ $ message->
setFrom (
'[email protected] ' );
56
+ $ message->
setTo (
'[email protected] ' );
57
+ $ message ->setSubject ('Test ' );
58
+ $ message ->setBody ($ this ->stubs ['original-html ' ], 'text/html ' );
59
+
60
+ $ mailer ->send ($ message );
61
+
62
+ $ this ->assertEquals ($ this ->stubs ['converted-html-with-classes ' ], $ message ->getBody ());
63
+ }
64
+
65
+ /** @test **/
66
+ public function itShouldConvertHtmlBodyKeepingStyles ()
67
+ {
68
+ $ this ->options ['strip-styles ' ] = false ;
69
+
70
+ $ mailer = Swift_Mailer::newInstance (Swift_NullTransport::newInstance ());
71
+
72
+ $ mailer ->registerPlugin (new CssInlinerPlugin ($ this ->options ));
73
+
74
+ $ message = Swift_Message::newInstance ();
75
+
76
+ $ message->
setFrom (
'[email protected] ' );
77
+ $ message->
setTo (
'[email protected] ' );
78
+ $ message ->setSubject ('Test ' );
79
+ $ message ->setBody ($ this ->stubs ['original-html ' ], 'text/html ' );
80
+
81
+ $ mailer ->send ($ message );
82
+
83
+ $ this ->assertEquals ($ this ->stubs ['converted-html-with-styles ' ], $ message ->getBody ());
84
+ }
85
+
36
86
/** @test **/
37
87
public function itShouldConvertHtmlBodyAndTextParts ()
38
88
{
39
89
$ mailer = Swift_Mailer::newInstance (Swift_NullTransport::newInstance ());
40
90
41
- $ mailer ->registerPlugin (new CssInlinerPlugin ());
91
+ $ mailer ->registerPlugin (new CssInlinerPlugin ($ this -> options ));
42
92
43
93
$ message = Swift_Message::newInstance ();
44
94
@@ -61,7 +111,7 @@ public function itShouldLeavePlainTextUnmodified()
61
111
{
62
112
$ mailer = Swift_Mailer::newInstance (Swift_NullTransport::newInstance ());
63
113
64
- $ mailer ->registerPlugin (new CssInlinerPlugin ());
114
+ $ mailer ->registerPlugin (new CssInlinerPlugin ($ this -> options ));
65
115
66
116
$ message = Swift_Message::newInstance ();
67
117
@@ -82,7 +132,7 @@ public function itShouldConvertHtmlBodyAsAPart()
82
132
{
83
133
$ mailer = Swift_Mailer::newInstance (Swift_NullTransport::newInstance ());
84
134
85
- $ mailer ->registerPlugin (new CssInlinerPlugin ());
135
+ $ mailer ->registerPlugin (new CssInlinerPlugin ($ this -> options ));
86
136
87
137
$ message = Swift_Message::newInstance ();
88
138
0 commit comments