|
13 | 13 | */
|
14 | 14 | class CssInlinerPluginTest extends PHPUnit_Framework_TestCase
|
15 | 15 | {
|
16 |
| - /** |
17 |
| - * @var Swift_Mailer |
18 |
| - */ |
19 |
| - private $mailer; |
20 |
| - |
21 |
| - /** |
22 |
| - * @var string |
23 |
| - */ |
24 |
| - private $emailRaw; |
25 |
| - |
26 |
| - /** |
27 |
| - * @var string |
28 |
| - */ |
29 |
| - private $emailConverted; |
30 |
| - |
31 |
| - public function setUp() |
32 |
| - { |
33 |
| - $dir = __DIR__.'/../fixtures/'; |
34 |
| - |
35 |
| - $this->emailRaw = file_get_contents($dir.'emailRaw.html'); |
36 |
| - $this->emailConverted = file_get_contents($dir.'emailConverted.html'); |
37 |
| - |
38 |
| - $this->mailer = Swift_Mailer::newInstance(Swift_NullTransport::newInstance()); |
39 |
| - $this->mailer->registerPLugin(new CssInlinerPlugin()); |
40 |
| - } |
41 |
| - |
42 |
| - /** |
43 |
| - * @return Swift_Message |
44 |
| - */ |
45 |
| - private function createMessage() |
46 |
| - { |
47 |
| - $message = Swift_Message::newInstance(); |
48 |
| - |
49 |
| - $message->setFrom('test@example.com'); |
50 |
| - $message->setTo('test2@example.com'); |
51 |
| - $message->setSubject('Test'); |
52 |
| - |
53 |
| - return $message; |
54 |
| - } |
55 |
| - |
56 |
| - /** |
57 |
| - * @covers ::beforeSendPerformed |
58 |
| - * @covers ::sendPerformed |
59 |
| - */ |
60 |
| - public function testHtmlBody() |
61 |
| - { |
62 |
| - $message = $this->createMessage(); |
63 |
| - |
64 |
| - $message->setContentType('text/html'); |
65 |
| - $message->setBody($this->emailRaw); |
66 |
| - |
67 |
| - $this->mailer->send($message); |
68 |
| - |
69 |
| - $this->assertStringEqualsStringWithoutIndentation($this->emailConverted, $message->getBody()); |
70 |
| - } |
71 |
| - |
72 |
| - /** |
73 |
| - * @covers ::beforeSendPerformed |
74 |
| - */ |
75 |
| - public function testHtmlPart() |
76 |
| - { |
77 |
| - $message = $this->createMessage(); |
78 |
| - |
79 |
| - $message->addPart($this->emailRaw, 'text/html'); |
80 |
| - $message->addPart('plain part', 'text/plain'); |
81 |
| - |
82 |
| - $this->mailer->send($message); |
83 |
| - |
84 |
| - $children = $message->getChildren(); |
85 |
| - |
86 |
| - $this->assertStringEqualsStringWithoutIndentation($this->emailConverted, $children[0]->getBody()); |
87 |
| - } |
88 |
| - |
89 |
| - /** |
90 |
| - * @covers ::__construct |
91 |
| - * @covers ::beforeSendPerformed |
92 |
| - */ |
93 |
| - public function testInjectedConverterIsUsedInsteadOfDefault() |
94 |
| - { |
95 |
| - $converterStub = $this |
96 |
| - ->getMockBuilder('TijsVerkoyen\CssToInlineStyles\CssToInlineStyles') |
97 |
| - ->setMethods(array('convert', 'setUseInlineStylesBlock')) |
98 |
| - ->getMock(); |
99 |
| - |
100 |
| - // "our" converter should be used |
101 |
| - $converterStub |
102 |
| - ->expects($this->atLeastOnce()) |
103 |
| - ->method('convert'); |
104 |
| - |
105 |
| - $converterStub |
106 |
| - ->expects($this->never()) |
107 |
| - ->method('setUseInlineStylesBlock'); |
108 |
| - |
109 |
| - $message = $this->createMessage(); |
110 |
| - $message->setContentType('text/html'); |
111 |
| - |
112 |
| - $mailer = Swift_Mailer::newInstance(Swift_NullTransport::newInstance()); |
113 |
| - $mailer->registerPlugin(new CssInlinerPlugin($converterStub)); |
114 |
| - $mailer->send($message); |
115 |
| - } |
116 |
| - |
117 |
| - /** |
118 |
| - * This assert is an ugly hack aiming to fix an indent issue when using libxml < 2.9.5. |
119 |
| - * |
120 |
| - * @param string $expected |
121 |
| - * @param string $actual |
122 |
| - * @param string $message |
123 |
| - */ |
124 |
| - private function assertStringEqualsStringWithoutIndentation($expected, $actual, $message = '') |
125 |
| - { |
126 |
| - $expected = preg_replace('/^[[:space:]]+|\n/m', '', $expected); |
127 |
| - $actual = preg_replace('/^[[:space:]]+|\n/m', '', $actual); |
128 |
| - |
129 |
| - $this->assertEquals($expected, $actual, $message); |
130 |
| - } |
| 16 | + /** |
| 17 | + * @var Swift_Mailer |
| 18 | + */ |
| 19 | + private $mailer; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var string |
| 23 | + */ |
| 24 | + private $emailRaw; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var string |
| 28 | + */ |
| 29 | + private $emailConverted; |
| 30 | + |
| 31 | + public function setUp() |
| 32 | + { |
| 33 | + $dir = __DIR__.'/../fixtures/'; |
| 34 | + |
| 35 | + $this->emailRaw = file_get_contents($dir.'emailRaw.html'); |
| 36 | + $this->emailConverted = file_get_contents($dir.'emailConverted.html'); |
| 37 | + |
| 38 | + $this->mailer = Swift_Mailer::newInstance(Swift_NullTransport::newInstance()); |
| 39 | + $this->mailer->registerPLugin(new CssInlinerPlugin()); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @return Swift_Message |
| 44 | + */ |
| 45 | + private function createMessage() |
| 46 | + { |
| 47 | + $message = Swift_Message::newInstance(); |
| 48 | + |
| 49 | + $message->setFrom('test@example.com'); |
| 50 | + $message->setTo('test2@example.com'); |
| 51 | + $message->setSubject('Test'); |
| 52 | + |
| 53 | + return $message; |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @covers ::beforeSendPerformed |
| 58 | + * @covers ::sendPerformed |
| 59 | + */ |
| 60 | + public function testHtmlBody() |
| 61 | + { |
| 62 | + $message = $this->createMessage(); |
| 63 | + |
| 64 | + $message->setContentType('text/html'); |
| 65 | + $message->setBody($this->emailRaw); |
| 66 | + |
| 67 | + $this->mailer->send($message); |
| 68 | + |
| 69 | + $this->assertStringEqualsStringWithoutIndentation($this->emailConverted, $message->getBody()); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @covers ::beforeSendPerformed |
| 74 | + */ |
| 75 | + public function testHtmlPart() |
| 76 | + { |
| 77 | + $message = $this->createMessage(); |
| 78 | + |
| 79 | + $message->addPart($this->emailRaw, 'text/html'); |
| 80 | + $message->addPart('plain part', 'text/plain'); |
| 81 | + |
| 82 | + $this->mailer->send($message); |
| 83 | + |
| 84 | + $children = $message->getChildren(); |
| 85 | + |
| 86 | + $this->assertStringEqualsStringWithoutIndentation($this->emailConverted, $children[0]->getBody()); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * @covers ::__construct |
| 91 | + * @covers ::beforeSendPerformed |
| 92 | + */ |
| 93 | + public function testInjectedConverterIsUsedInsteadOfDefault() |
| 94 | + { |
| 95 | + $converterStub = $this |
| 96 | + ->getMockBuilder('TijsVerkoyen\CssToInlineStyles\CssToInlineStyles') |
| 97 | + ->setMethods(array('convert', 'setUseInlineStylesBlock')) |
| 98 | + ->getMock(); |
| 99 | + |
| 100 | + // "our" converter should be used |
| 101 | + $converterStub |
| 102 | + ->expects($this->atLeastOnce()) |
| 103 | + ->method('convert'); |
| 104 | + |
| 105 | + $converterStub |
| 106 | + ->expects($this->never()) |
| 107 | + ->method('setUseInlineStylesBlock'); |
| 108 | + |
| 109 | + $message = $this->createMessage(); |
| 110 | + $message->setContentType('text/html'); |
| 111 | + |
| 112 | + $mailer = Swift_Mailer::newInstance(Swift_NullTransport::newInstance()); |
| 113 | + $mailer->registerPlugin(new CssInlinerPlugin($converterStub)); |
| 114 | + $mailer->send($message); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * This assert is an ugly hack aiming to fix an indent issue when using libxml < 2.9.5. |
| 119 | + * |
| 120 | + * @param string $expected |
| 121 | + * @param string $actual |
| 122 | + * @param string $message |
| 123 | + */ |
| 124 | + private function assertStringEqualsStringWithoutIndentation($expected, $actual, $message = '') |
| 125 | + { |
| 126 | + $expected = preg_replace('/^[[:space:]]+|\n/m', '', $expected); |
| 127 | + $actual = preg_replace('/^[[:space:]]+|\n/m', '', $actual); |
| 128 | + |
| 129 | + $this->assertEquals($expected, $actual, $message); |
| 130 | + } |
131 | 131 | }
|
0 commit comments