33use  Openbuildings \Swiftmailer \CssInlinerPlugin ;
44
55/** 
6-  * @group    css-inliner-plugin 
6+  * @group css-inliner-plugin 
77 */ 
8- class  CssInlinerPluginTest extends  PHPUnit_Framework_TestCase {
9- 
10- 	public  $ html<<<HTML 
11- <html> 
12- 	<head> 
13- 		<style> 
14- 			.block { 
15- 				width: 100px; 
16- 				height: 20px; 
17- 			} 
18- 			div.block ul li.small { 
19- 				margin: 10px; 
20- 			} 
21- 		</style> 
22- 	</head> 
23- 	<body> 
24- 		<div class="block"> 
25- 			text 
26- 
27- 			<ul> 
28- 				<li> 
29- 					Big list 
30- 				</li> 
31- 				<li class="small"> 
32- 					Small list 
33- 				</li> 
34- 			</ul> 
35- 		</div> 
36- 	</body> 
37- </html> 
38- HTML ;
39- 
40- 	public  $ converted_html<<<CONVERTED 
41- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> 
42- <html><head><style> 
43- 			.block { 
44- 				width: 100px; 
45- 				height: 20px; 
46- 			} 
47- 			div.block ul li.small { 
48- 				margin: 10px; 
49- 			} 
50- 		</style></head><body> 
51- 		<div class="block" style="height: 20px; width: 100px;"> 
52- 			text 
53- 
54- 			<ul><li> 
55- 					Big list 
56- 				</li> 
57- 				<li class="small" style="margin: 10px;"> 
58- 					Small list 
59- 				</li> 
60- 			</ul></div> 
61- 	</body></html> 
62- 
63- CONVERTED ;
8+ class  CssInlinerPluginTest extends  PHPUnit_Framework_TestCase
9+ {
10+ 	/** 
11+ 	 * @var Swift_Mailer 
12+ 	 */ 
13+ 	private  $ mailer
14+ 
15+ 	/** 
16+ 	 * @var string 
17+ 	 */ 
18+ 	private  $ email_raw
19+ 
20+ 	/** 
21+ 	 * @var string 
22+ 	 */ 
23+ 	private  $ email_converted
6424
6525	public  function  test_html_body ()
6626	{
67- 		$ mailer Swift_Mailer:: newInstance (Swift_NullTransport:: newInstance () );
27+ 		$ message $ this -> create_message ( );
6828
69- 		$ mailerregisterPLugin (new  CssInlinerPlugin ());
29+ 		$ messagesetContentType ('text/html ' );
30+ 		$ messagesetBody ($ this email_raw );
7031
71- 		$ message  = Swift_Message:: newInstance ( );
32+ 		$ this -> mailer -> send ( $ message 
7233
73- 		$ messagesetFrom ('test@example.com ' );
74- 		$ messagesetTo ('test2@example.com ' );
75- 		$ messagesetSubject ('Test ' );
76- 		$ messagesetContentType ('text/html ' );
77- 		$ messagesetBody ($ this html );
34+ 		$ this assertEquals ($ this email_converted , $ messagegetBody ());
35+ 	}
7836
79- 		$ mailersend ($ message
80- 		
81- 		$ this assertEquals ($ this converted_html , $ messagegetBody ());
37+ 	public  function  test_html_part ()
38+ 	{
39+ 		$ message$ this create_message ();
40+ 
41+ 		$ messageaddPart ($ this email_raw , 'text/html ' );
42+ 		$ messageaddPart ('plain part ' , 'text/plain ' );
43+ 
44+ 		$ this mailer ->send ($ message
45+ 
46+ 		$ children$ messagegetChildren ();
47+ 
48+ 		$ this assertEquals ($ this email_converted , $ children0 ]->getBody ());
8249	}
8350
51+ 	public  function  test_default_converter_uses_inline_styles_block ()
52+ 	{
53+ 		$ pluginnew  CssInlinerPlugin ();
8454
85- 	public  function  test_html_part ()
55+ 		$ converterreadAttribute ($ plugin'converter ' );
56+ 
57+ 		$ this assertTrue (
58+ 			\PHPUnit_Framework_Assert::readAttribute ($ converter'useInlineStylesBlock ' ),
59+ 			'setUseInlineStylesBlock() should be called on default $converter ' 
60+ 		);
61+ 	}
62+ 
63+ 	public  function  test_injected_conveter_is_used_istead_of_default ()
8664	{
65+ 		$ converterStub$ this 
66+ 			->getMockBuilder ('TijsVerkoyen\CssToInlineStyles\CssToInlineStyles ' )
67+ 			->setMethods (array ('convert ' , 'setUseInlineStylesBlock ' ))
68+ 			->getMock ();
69+ 
70+ 		// "our" converter should be used 
71+ 		$ converterStub
72+ 			->expects ($ this atLeastOnce ())
73+ 			->method ('convert ' );
74+ 
75+ 		$ converterStub
76+ 			->expects ($ this never ())
77+ 			->method ('setUseInlineStylesBlock ' );
78+ 
79+ 		$ message$ this create_message ();
80+ 		$ messagesetContentType ('text/html ' );
81+ 
8782		$ mailernewInstance (Swift_NullTransport::newInstance ());
83+ 		$ mailerregisterPlugin (new  CssInlinerPlugin ($ converterStub
84+ 		$ mailersend ($ message
85+ 	}
8886
89- 		$ mailerregisterPLugin (new  CssInlinerPlugin ());
87+ 	protected  function  setUp ()
88+ 	{
89+ 		$ dir__DIR__ .'/../fixtures/ ' ;
90+ 
91+ 		$ this email_raw  = file_get_contents ($ dir'email_raw.html ' );
92+ 		$ this email_converted  = file_get_contents ($ dir'email_converted.html ' );
9093
94+ 		$ this mailer  = Swift_Mailer::newInstance (Swift_NullTransport::newInstance ());
95+ 		$ this mailer ->registerPLugin (new  CssInlinerPlugin ());
96+ 	}
97+ 
98+ 	/** 
99+ 	 * @return Swift_Message 
100+ 	 */ 
101+ 	private  function  create_message ()
102+ 	{
91103		$ messagenewInstance ();
92104
93105		$ messagesetFrom ('test@example.com ' );
94106		$ messagesetTo ('test2@example.com ' );
95107		$ messagesetSubject ('Test ' );
96- 		$ messageaddPart ($ this html , 'text/html ' );
97- 		$ messageaddPart ('plain part ' , 'text/plain ' );
98- 
99- 		$ mailersend ($ message
100108
101- 		$ children$ messagegetChildren ();
102- 		
103- 		$ this assertEquals ($ this converted_html , $ children0 ]->getBody ());
109+ 		return  $ message
104110	}
105- }
111+ }
0 commit comments