44
55class CssInlinerPluginTest extends PHPUnit_Framework_TestCase
66{
7-
87 protected $ stubs ;
98
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+
1016 public function setUp ()
1117 {
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 ' );
1523 }
1624
1725 /** @test **/
1826 public function itShouldConvertHtmlBody ()
1927 {
2028 $ mailer = Swift_Mailer::newInstance (Swift_NullTransport::newInstance ());
2129
22- $ mailer ->registerPlugin (new CssInlinerPlugin ());
30+ $ mailer ->registerPlugin (new CssInlinerPlugin ($ this -> options ));
2331
2432 $ message = Swift_Message::newInstance ();
2533
@@ -33,12 +41,54 @@ public function itShouldConvertHtmlBody()
3341 $ this ->assertEquals ($ this ->stubs ['converted-html ' ], $ message ->getBody ());
3442 }
3543
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+
3686 /** @test **/
3787 public function itShouldConvertHtmlBodyAndTextParts ()
3888 {
3989 $ mailer = Swift_Mailer::newInstance (Swift_NullTransport::newInstance ());
4090
41- $ mailer ->registerPlugin (new CssInlinerPlugin ());
91+ $ mailer ->registerPlugin (new CssInlinerPlugin ($ this -> options ));
4292
4393 $ message = Swift_Message::newInstance ();
4494
@@ -61,7 +111,7 @@ public function itShouldLeavePlainTextUnmodified()
61111 {
62112 $ mailer = Swift_Mailer::newInstance (Swift_NullTransport::newInstance ());
63113
64- $ mailer ->registerPlugin (new CssInlinerPlugin ());
114+ $ mailer ->registerPlugin (new CssInlinerPlugin ($ this -> options ));
65115
66116 $ message = Swift_Message::newInstance ();
67117
@@ -82,7 +132,7 @@ public function itShouldConvertHtmlBodyAsAPart()
82132 {
83133 $ mailer = Swift_Mailer::newInstance (Swift_NullTransport::newInstance ());
84134
85- $ mailer ->registerPlugin (new CssInlinerPlugin ());
135+ $ mailer ->registerPlugin (new CssInlinerPlugin ($ this -> options ));
86136
87137 $ message = Swift_Message::newInstance ();
88138
0 commit comments