@@ -3,5 +3,5 @@ |
||
| 3 | 3 | namespace Jacobemerick\Archangel; |
| 4 | 4 | |
| 5 | 5 | function uniqid() { |
| 6 | - return '1234567890123'; |
|
| 6 | + return '1234567890123'; |
|
| 7 | 7 | } |
@@ -8,311 +8,311 @@ |
||
| 8 | 8 | class ArchangelTest extends PHPUnit_Framework_TestCase |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - public function testIsInstanceOfArchangel() |
|
| 12 | - { |
|
| 13 | - $archangel = new Archangel(); |
|
| 14 | - |
|
| 15 | - $this->assertInstanceOf('Jacobemerick\Archangel\Archangel', $archangel); |
|
| 16 | - } |
|
| 11 | + public function testIsInstanceOfArchangel() |
|
| 12 | + { |
|
| 13 | + $archangel = new Archangel(); |
|
| 14 | + |
|
| 15 | + $this->assertInstanceOf('Jacobemerick\Archangel\Archangel', $archangel); |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - public function testIsLoggerAwareInterface() |
|
| 19 | - { |
|
| 20 | - $archangel = new Archangel(); |
|
| 21 | - |
|
| 22 | - $this->assertInstanceOf('Psr\Log\LoggerAwareInterface', $archangel); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public function testConstructSetsDefaultMailer() |
|
| 26 | - { |
|
| 27 | - $archangel = new Archangel(); |
|
| 28 | - $mailer = sprintf('PHP/%s', phpversion()); |
|
| 29 | - $headers = array('X-Mailer' => $mailer); |
|
| 30 | - |
|
| 31 | - $this->assertAttributeEquals($headers, 'headers', $archangel); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function testConstructOverridesMailer() |
|
| 35 | - { |
|
| 36 | - $archangel = new Archangel('AwesomeMailer'); |
|
| 37 | - $headers = array('X-Mailer' => 'AwesomeMailer'); |
|
| 38 | - |
|
| 39 | - $this->assertAttributeEquals($headers, 'headers', $archangel); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - public function testConstructSetsNullLogger() |
|
| 43 | - { |
|
| 44 | - $archangel = new Archangel(); |
|
| 45 | - |
|
| 46 | - $this->assertAttributeInstanceOf('Psr\Log\NullLogger', 'logger', $archangel); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public function testSetLogger() |
|
| 50 | - { |
|
| 51 | - $logger = $this->getMock('Psr\Log\LoggerInterface'); |
|
| 52 | - $archangel = new Archangel(); |
|
| 53 | - $archangel->setLogger($logger); |
|
| 54 | - |
|
| 55 | - $this->assertAttributeSame($logger, 'logger', $archangel); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - public function testAddTo() |
|
| 59 | - { |
|
| 60 | - $archangel = new Archangel(); |
|
| 61 | - $archangel->addTo('[email protected]'); |
|
| 62 | - |
|
| 63 | - $this->assertAttributeContains('[email protected]', 'toAddresses', $archangel); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - public function testAddToMultiple() |
|
| 67 | - { |
|
| 68 | - $archangel = new Archangel(); |
|
| 69 | - $archangel->addTo('[email protected]'); |
|
| 70 | - $archangel->addTo('[email protected]'); |
|
| 71 | - |
|
| 72 | - $this->assertAttributeContains('[email protected]', 'toAddresses', $archangel); |
|
| 73 | - $this->assertAttributeContains('[email protected]', 'toAddresses', $archangel); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public function testAddToWithTitle() |
|
| 77 | - { |
|
| 78 | - $archangel = new Archangel(); |
|
| 79 | - $archangel->addTo('[email protected]', 'Mr. Test Alot'); |
|
| 80 | - |
|
| 81 | - $this->assertAttributeContains('"Mr. Test Alot" <[email protected]>', 'toAddresses', $archangel); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public function testAddCc() |
|
| 85 | - { |
|
| 86 | - $archangel = new Archangel(); |
|
| 87 | - $archangel->addCc('[email protected]'); |
|
| 88 | - |
|
| 89 | - $this->assertAttributeContains('[email protected]', 'ccAddresses', $archangel); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - public function testAddCcMultiple() |
|
| 93 | - { |
|
| 94 | - $archangel = new Archangel(); |
|
| 95 | - $archangel->addCc('[email protected]'); |
|
| 96 | - $archangel->addCc('[email protected]'); |
|
| 97 | - |
|
| 98 | - $this->assertAttributeContains('[email protected]', 'ccAddresses', $archangel); |
|
| 99 | - $this->assertAttributeContains('[email protected]', 'ccAddresses', $archangel); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - public function testAddCcWithTitle() |
|
| 103 | - { |
|
| 104 | - $archangel = new Archangel(); |
|
| 105 | - $archangel->addCc('[email protected]', 'Mr. Test Alot'); |
|
| 106 | - |
|
| 107 | - $this->assertAttributeContains('"Mr. Test Alot" <[email protected]>', 'ccAddresses', $archangel); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - public function testAddBcc() |
|
| 111 | - { |
|
| 112 | - $archangel = new Archangel(); |
|
| 113 | - $archangel->addBcc('[email protected]'); |
|
| 114 | - |
|
| 115 | - $this->assertAttributeContains('[email protected]', 'bccAddresses', $archangel); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - public function testAddBccMultiple() |
|
| 119 | - { |
|
| 120 | - $archangel = new Archangel(); |
|
| 121 | - $archangel->addBcc('[email protected]'); |
|
| 122 | - $archangel->addBcc('[email protected]'); |
|
| 123 | - |
|
| 124 | - $this->assertAttributeContains('[email protected]', 'bccAddresses', $archangel); |
|
| 125 | - $this->assertAttributeContains('[email protected]', 'bccAddresses', $archangel); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function testAddBccWithTitle() |
|
| 129 | - { |
|
| 130 | - $archangel = new Archangel(); |
|
| 131 | - $archangel->addBcc('[email protected]', 'Mr. Test Alot'); |
|
| 132 | - |
|
| 133 | - $this->assertAttributeContains('"Mr. Test Alot" <[email protected]>', 'bccAddresses', $archangel); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function testSetFrom() |
|
| 137 | - { |
|
| 138 | - $archangel = new Archangel(); |
|
| 139 | - $archangel->setFrom('[email protected]'); |
|
| 140 | - $setHeaders = $this->getProtectedValue($archangel, 'headers'); |
|
| 141 | - |
|
| 142 | - $this->assertArraySubset(array('From' => '[email protected]'), $setHeaders); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - public function testSetFromMultiple() |
|
| 146 | - { |
|
| 147 | - $archangel = new Archangel(); |
|
| 148 | - $archangel->setFrom('[email protected]'); |
|
| 149 | - $archangel->setFrom('[email protected]'); |
|
| 150 | - $setHeaders = $this->getProtectedValue($archangel, 'headers'); |
|
| 151 | - |
|
| 152 | - $this->assertArraySubset(array('From' => '[email protected]'), $setHeaders); |
|
| 153 | - $this->assertNotContains('[email protected]', $setHeaders); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - public function testSetFromWithTitle() |
|
| 157 | - { |
|
| 158 | - $archangel = new Archangel(); |
|
| 159 | - $archangel->setFrom('[email protected]', 'Mr. Test Alot'); |
|
| 160 | - $setHeaders = $this->getProtectedValue($archangel, 'headers'); |
|
| 161 | - |
|
| 162 | - $this->assertArraySubset(array('From' => '"Mr. Test Alot" <[email protected]>'), $setHeaders); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - public function testSetReplyTo() |
|
| 166 | - { |
|
| 167 | - $archangel = new Archangel(); |
|
| 168 | - $archangel->setReplyTo('[email protected]'); |
|
| 169 | - $setHeaders = $this->getProtectedValue($archangel, 'headers'); |
|
| 170 | - |
|
| 171 | - $this->assertArraySubset(array('Reply-To' => '[email protected]'), $setHeaders); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - public function testSetReplyToMultiple() |
|
| 175 | - { |
|
| 176 | - $archangel = new Archangel(); |
|
| 177 | - $archangel->setReplyTo('[email protected]'); |
|
| 178 | - $archangel->setReplyTo('[email protected]'); |
|
| 179 | - $setHeaders = $this->getProtectedValue($archangel, 'headers'); |
|
| 180 | - |
|
| 181 | - $this->assertArraySubset(array('Reply-To' => '[email protected]'), $setHeaders); |
|
| 182 | - $this->assertNotContains('[email protected]', $setHeaders); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - public function testSetReplyToWithTitle() |
|
| 186 | - { |
|
| 187 | - $archangel = new Archangel(); |
|
| 188 | - $archangel->setReplyTo('[email protected]', 'Mr. Test Alot'); |
|
| 189 | - $setHeaders = $this->getProtectedValue($archangel, 'headers'); |
|
| 190 | - |
|
| 191 | - $this->assertArraySubset(array('Reply-To' => '"Mr. Test Alot" <[email protected]>'), $setHeaders); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - public function testSetSubject() |
|
| 195 | - { |
|
| 196 | - $archangel = new Archangel(); |
|
| 197 | - $archangel->setSubject('Test Subject'); |
|
| 198 | - $setSubject = $this->getProtectedValue($archangel, 'subject'); |
|
| 199 | - |
|
| 200 | - $this->assertEquals('Test Subject', $setSubject); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - public function testSetPlainMessage() |
|
| 204 | - { |
|
| 205 | - $archangel = new Archangel(); |
|
| 206 | - $archangel->setPlainMessage('Plain text message'); |
|
| 207 | - $setPlainMessage = $this->getProtectedValue($archangel, 'plainMessage'); |
|
| 208 | - |
|
| 209 | - $this->assertEquals('Plain text message', $setPlainMessage); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - public function testSetHTMLMessage() |
|
| 213 | - { |
|
| 214 | - $archangel = new Archangel(); |
|
| 215 | - $archangel->setHTMLMessage('<p>An HTML message.</p>'); |
|
| 216 | - $setHTMLMessage = $this->getProtectedValue($archangel, 'htmlMessage'); |
|
| 217 | - |
|
| 218 | - $this->assertEquals('<p>An HTML message.</p>', $setHTMLMessage); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - public function testFormatEmailAddress() |
|
| 222 | - { |
|
| 223 | - $archangel = new Archangel(); |
|
| 224 | - $formatMethod = $this->getProtectedMethod('formatEmailAddress'); |
|
| 225 | - $formattedEmail = $formatMethod->invokeArgs($archangel, array('[email protected]', '')); |
|
| 226 | - |
|
| 227 | - $this->assertEquals('[email protected]', $formattedEmail); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - public function testFormatEmailAddressWithTitle() |
|
| 231 | - { |
|
| 232 | - $archangel = new Archangel(); |
|
| 233 | - $formatMethod = $this->getProtectedMethod('formatEmailAddress'); |
|
| 234 | - $formattedEmail = $formatMethod->invokeArgs($archangel, array('[email protected]', 'Mr. Test Alot')); |
|
| 235 | - |
|
| 236 | - $this->assertEquals('"Mr. Test Alot" <[email protected]>', $formattedEmail); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - public function testAddAttachment() |
|
| 240 | - { |
|
| 241 | - $archangel = new Archangel(); |
|
| 242 | - $archangel->addAttachment('path', 'type'); |
|
| 243 | - |
|
| 244 | - $this->assertAttributeContains( |
|
| 245 | - array('path' => 'path', 'type' => 'type', 'title' => ''), |
|
| 246 | - 'attachments', |
|
| 247 | - $archangel |
|
| 248 | - ); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - public function testAddAttachmentMultiple() |
|
| 252 | - { |
|
| 253 | - $archangel = new Archangel(); |
|
| 254 | - $archangel->addAttachment('pathOne', 'typeOne'); |
|
| 255 | - $archangel->addAttachment('pathTwo', 'typeTwo'); |
|
| 256 | - |
|
| 257 | - $this->assertAttributeContains( |
|
| 258 | - array('path' => 'pathOne', 'type' => 'typeOne', 'title' => ''), |
|
| 259 | - 'attachments', |
|
| 260 | - $archangel |
|
| 261 | - ); |
|
| 262 | - $this->assertAttributeContains( |
|
| 263 | - array('path' => 'pathTwo', 'type' => 'typeTwo', 'title' => ''), |
|
| 264 | - 'attachments', |
|
| 265 | - $archangel |
|
| 266 | - ); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - public function testAddAttachmentWithTitle() |
|
| 270 | - { |
|
| 271 | - $archangel = new Archangel(); |
|
| 272 | - $archangel->addAttachment('path', 'type', 'title'); |
|
| 273 | - |
|
| 274 | - $this->assertAttributeContains( |
|
| 275 | - array('path' => 'path', 'type' => 'type', 'title' => 'title'), |
|
| 276 | - 'attachments', |
|
| 277 | - $archangel |
|
| 278 | - ); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - public function testGetBoundary() |
|
| 282 | - { |
|
| 283 | - $archangel = new Archangel(); |
|
| 284 | - $boundaryMethod = $this->getProtectedMethod('getBoundary'); |
|
| 285 | - $boundary = $boundaryMethod->invoke($archangel); |
|
| 286 | - $expectedBoundary = sprintf('PHP-mixed-%s', uniqid()); |
|
| 287 | - |
|
| 288 | - $this->assertEquals($expectedBoundary, $boundary); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - public function testGetAlternativeBoundary() |
|
| 292 | - { |
|
| 293 | - $archangel = new Archangel(); |
|
| 294 | - $boundaryMethod = $this->getProtectedMethod('getAlternativeBoundary'); |
|
| 295 | - $boundary = $boundaryMethod->invoke($archangel); |
|
| 296 | - $expectedBoundary = sprintf('PHP-alternative-%s', uniqid()); |
|
| 297 | - |
|
| 298 | - $this->assertEquals($expectedBoundary, $boundary); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - protected function getProtectedValue($archangel, $property) |
|
| 302 | - { |
|
| 303 | - $reflectedArchangel = new ReflectionClass($archangel); |
|
| 304 | - $reflectedProperty = $reflectedArchangel->getProperty($property); |
|
| 305 | - $reflectedProperty->setAccessible(true); |
|
| 306 | - |
|
| 307 | - return $reflectedProperty->getValue($archangel); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - protected function getProtectedMethod($method) |
|
| 311 | - { |
|
| 312 | - $reflectedArchangel = new ReflectionClass('Jacobemerick\Archangel\Archangel'); |
|
| 313 | - $reflectedMethod = $reflectedArchangel->getMethod($method); |
|
| 314 | - $reflectedMethod->setAccessible(true); |
|
| 315 | - |
|
| 316 | - return $reflectedMethod; |
|
| 317 | - } |
|
| 18 | + public function testIsLoggerAwareInterface() |
|
| 19 | + { |
|
| 20 | + $archangel = new Archangel(); |
|
| 21 | + |
|
| 22 | + $this->assertInstanceOf('Psr\Log\LoggerAwareInterface', $archangel); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + public function testConstructSetsDefaultMailer() |
|
| 26 | + { |
|
| 27 | + $archangel = new Archangel(); |
|
| 28 | + $mailer = sprintf('PHP/%s', phpversion()); |
|
| 29 | + $headers = array('X-Mailer' => $mailer); |
|
| 30 | + |
|
| 31 | + $this->assertAttributeEquals($headers, 'headers', $archangel); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public function testConstructOverridesMailer() |
|
| 35 | + { |
|
| 36 | + $archangel = new Archangel('AwesomeMailer'); |
|
| 37 | + $headers = array('X-Mailer' => 'AwesomeMailer'); |
|
| 38 | + |
|
| 39 | + $this->assertAttributeEquals($headers, 'headers', $archangel); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + public function testConstructSetsNullLogger() |
|
| 43 | + { |
|
| 44 | + $archangel = new Archangel(); |
|
| 45 | + |
|
| 46 | + $this->assertAttributeInstanceOf('Psr\Log\NullLogger', 'logger', $archangel); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public function testSetLogger() |
|
| 50 | + { |
|
| 51 | + $logger = $this->getMock('Psr\Log\LoggerInterface'); |
|
| 52 | + $archangel = new Archangel(); |
|
| 53 | + $archangel->setLogger($logger); |
|
| 54 | + |
|
| 55 | + $this->assertAttributeSame($logger, 'logger', $archangel); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + public function testAddTo() |
|
| 59 | + { |
|
| 60 | + $archangel = new Archangel(); |
|
| 61 | + $archangel->addTo('[email protected]'); |
|
| 62 | + |
|
| 63 | + $this->assertAttributeContains('[email protected]', 'toAddresses', $archangel); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + public function testAddToMultiple() |
|
| 67 | + { |
|
| 68 | + $archangel = new Archangel(); |
|
| 69 | + $archangel->addTo('[email protected]'); |
|
| 70 | + $archangel->addTo('[email protected]'); |
|
| 71 | + |
|
| 72 | + $this->assertAttributeContains('[email protected]', 'toAddresses', $archangel); |
|
| 73 | + $this->assertAttributeContains('[email protected]', 'toAddresses', $archangel); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public function testAddToWithTitle() |
|
| 77 | + { |
|
| 78 | + $archangel = new Archangel(); |
|
| 79 | + $archangel->addTo('[email protected]', 'Mr. Test Alot'); |
|
| 80 | + |
|
| 81 | + $this->assertAttributeContains('"Mr. Test Alot" <[email protected]>', 'toAddresses', $archangel); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public function testAddCc() |
|
| 85 | + { |
|
| 86 | + $archangel = new Archangel(); |
|
| 87 | + $archangel->addCc('[email protected]'); |
|
| 88 | + |
|
| 89 | + $this->assertAttributeContains('[email protected]', 'ccAddresses', $archangel); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + public function testAddCcMultiple() |
|
| 93 | + { |
|
| 94 | + $archangel = new Archangel(); |
|
| 95 | + $archangel->addCc('[email protected]'); |
|
| 96 | + $archangel->addCc('[email protected]'); |
|
| 97 | + |
|
| 98 | + $this->assertAttributeContains('[email protected]', 'ccAddresses', $archangel); |
|
| 99 | + $this->assertAttributeContains('[email protected]', 'ccAddresses', $archangel); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + public function testAddCcWithTitle() |
|
| 103 | + { |
|
| 104 | + $archangel = new Archangel(); |
|
| 105 | + $archangel->addCc('[email protected]', 'Mr. Test Alot'); |
|
| 106 | + |
|
| 107 | + $this->assertAttributeContains('"Mr. Test Alot" <[email protected]>', 'ccAddresses', $archangel); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + public function testAddBcc() |
|
| 111 | + { |
|
| 112 | + $archangel = new Archangel(); |
|
| 113 | + $archangel->addBcc('[email protected]'); |
|
| 114 | + |
|
| 115 | + $this->assertAttributeContains('[email protected]', 'bccAddresses', $archangel); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + public function testAddBccMultiple() |
|
| 119 | + { |
|
| 120 | + $archangel = new Archangel(); |
|
| 121 | + $archangel->addBcc('[email protected]'); |
|
| 122 | + $archangel->addBcc('[email protected]'); |
|
| 123 | + |
|
| 124 | + $this->assertAttributeContains('[email protected]', 'bccAddresses', $archangel); |
|
| 125 | + $this->assertAttributeContains('[email protected]', 'bccAddresses', $archangel); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function testAddBccWithTitle() |
|
| 129 | + { |
|
| 130 | + $archangel = new Archangel(); |
|
| 131 | + $archangel->addBcc('[email protected]', 'Mr. Test Alot'); |
|
| 132 | + |
|
| 133 | + $this->assertAttributeContains('"Mr. Test Alot" <[email protected]>', 'bccAddresses', $archangel); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function testSetFrom() |
|
| 137 | + { |
|
| 138 | + $archangel = new Archangel(); |
|
| 139 | + $archangel->setFrom('[email protected]'); |
|
| 140 | + $setHeaders = $this->getProtectedValue($archangel, 'headers'); |
|
| 141 | + |
|
| 142 | + $this->assertArraySubset(array('From' => '[email protected]'), $setHeaders); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + public function testSetFromMultiple() |
|
| 146 | + { |
|
| 147 | + $archangel = new Archangel(); |
|
| 148 | + $archangel->setFrom('[email protected]'); |
|
| 149 | + $archangel->setFrom('[email protected]'); |
|
| 150 | + $setHeaders = $this->getProtectedValue($archangel, 'headers'); |
|
| 151 | + |
|
| 152 | + $this->assertArraySubset(array('From' => '[email protected]'), $setHeaders); |
|
| 153 | + $this->assertNotContains('[email protected]', $setHeaders); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + public function testSetFromWithTitle() |
|
| 157 | + { |
|
| 158 | + $archangel = new Archangel(); |
|
| 159 | + $archangel->setFrom('[email protected]', 'Mr. Test Alot'); |
|
| 160 | + $setHeaders = $this->getProtectedValue($archangel, 'headers'); |
|
| 161 | + |
|
| 162 | + $this->assertArraySubset(array('From' => '"Mr. Test Alot" <[email protected]>'), $setHeaders); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + public function testSetReplyTo() |
|
| 166 | + { |
|
| 167 | + $archangel = new Archangel(); |
|
| 168 | + $archangel->setReplyTo('[email protected]'); |
|
| 169 | + $setHeaders = $this->getProtectedValue($archangel, 'headers'); |
|
| 170 | + |
|
| 171 | + $this->assertArraySubset(array('Reply-To' => '[email protected]'), $setHeaders); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + public function testSetReplyToMultiple() |
|
| 175 | + { |
|
| 176 | + $archangel = new Archangel(); |
|
| 177 | + $archangel->setReplyTo('[email protected]'); |
|
| 178 | + $archangel->setReplyTo('[email protected]'); |
|
| 179 | + $setHeaders = $this->getProtectedValue($archangel, 'headers'); |
|
| 180 | + |
|
| 181 | + $this->assertArraySubset(array('Reply-To' => '[email protected]'), $setHeaders); |
|
| 182 | + $this->assertNotContains('[email protected]', $setHeaders); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + public function testSetReplyToWithTitle() |
|
| 186 | + { |
|
| 187 | + $archangel = new Archangel(); |
|
| 188 | + $archangel->setReplyTo('[email protected]', 'Mr. Test Alot'); |
|
| 189 | + $setHeaders = $this->getProtectedValue($archangel, 'headers'); |
|
| 190 | + |
|
| 191 | + $this->assertArraySubset(array('Reply-To' => '"Mr. Test Alot" <[email protected]>'), $setHeaders); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + public function testSetSubject() |
|
| 195 | + { |
|
| 196 | + $archangel = new Archangel(); |
|
| 197 | + $archangel->setSubject('Test Subject'); |
|
| 198 | + $setSubject = $this->getProtectedValue($archangel, 'subject'); |
|
| 199 | + |
|
| 200 | + $this->assertEquals('Test Subject', $setSubject); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + public function testSetPlainMessage() |
|
| 204 | + { |
|
| 205 | + $archangel = new Archangel(); |
|
| 206 | + $archangel->setPlainMessage('Plain text message'); |
|
| 207 | + $setPlainMessage = $this->getProtectedValue($archangel, 'plainMessage'); |
|
| 208 | + |
|
| 209 | + $this->assertEquals('Plain text message', $setPlainMessage); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + public function testSetHTMLMessage() |
|
| 213 | + { |
|
| 214 | + $archangel = new Archangel(); |
|
| 215 | + $archangel->setHTMLMessage('<p>An HTML message.</p>'); |
|
| 216 | + $setHTMLMessage = $this->getProtectedValue($archangel, 'htmlMessage'); |
|
| 217 | + |
|
| 218 | + $this->assertEquals('<p>An HTML message.</p>', $setHTMLMessage); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + public function testFormatEmailAddress() |
|
| 222 | + { |
|
| 223 | + $archangel = new Archangel(); |
|
| 224 | + $formatMethod = $this->getProtectedMethod('formatEmailAddress'); |
|
| 225 | + $formattedEmail = $formatMethod->invokeArgs($archangel, array('[email protected]', '')); |
|
| 226 | + |
|
| 227 | + $this->assertEquals('[email protected]', $formattedEmail); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + public function testFormatEmailAddressWithTitle() |
|
| 231 | + { |
|
| 232 | + $archangel = new Archangel(); |
|
| 233 | + $formatMethod = $this->getProtectedMethod('formatEmailAddress'); |
|
| 234 | + $formattedEmail = $formatMethod->invokeArgs($archangel, array('[email protected]', 'Mr. Test Alot')); |
|
| 235 | + |
|
| 236 | + $this->assertEquals('"Mr. Test Alot" <[email protected]>', $formattedEmail); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + public function testAddAttachment() |
|
| 240 | + { |
|
| 241 | + $archangel = new Archangel(); |
|
| 242 | + $archangel->addAttachment('path', 'type'); |
|
| 243 | + |
|
| 244 | + $this->assertAttributeContains( |
|
| 245 | + array('path' => 'path', 'type' => 'type', 'title' => ''), |
|
| 246 | + 'attachments', |
|
| 247 | + $archangel |
|
| 248 | + ); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + public function testAddAttachmentMultiple() |
|
| 252 | + { |
|
| 253 | + $archangel = new Archangel(); |
|
| 254 | + $archangel->addAttachment('pathOne', 'typeOne'); |
|
| 255 | + $archangel->addAttachment('pathTwo', 'typeTwo'); |
|
| 256 | + |
|
| 257 | + $this->assertAttributeContains( |
|
| 258 | + array('path' => 'pathOne', 'type' => 'typeOne', 'title' => ''), |
|
| 259 | + 'attachments', |
|
| 260 | + $archangel |
|
| 261 | + ); |
|
| 262 | + $this->assertAttributeContains( |
|
| 263 | + array('path' => 'pathTwo', 'type' => 'typeTwo', 'title' => ''), |
|
| 264 | + 'attachments', |
|
| 265 | + $archangel |
|
| 266 | + ); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + public function testAddAttachmentWithTitle() |
|
| 270 | + { |
|
| 271 | + $archangel = new Archangel(); |
|
| 272 | + $archangel->addAttachment('path', 'type', 'title'); |
|
| 273 | + |
|
| 274 | + $this->assertAttributeContains( |
|
| 275 | + array('path' => 'path', 'type' => 'type', 'title' => 'title'), |
|
| 276 | + 'attachments', |
|
| 277 | + $archangel |
|
| 278 | + ); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + public function testGetBoundary() |
|
| 282 | + { |
|
| 283 | + $archangel = new Archangel(); |
|
| 284 | + $boundaryMethod = $this->getProtectedMethod('getBoundary'); |
|
| 285 | + $boundary = $boundaryMethod->invoke($archangel); |
|
| 286 | + $expectedBoundary = sprintf('PHP-mixed-%s', uniqid()); |
|
| 287 | + |
|
| 288 | + $this->assertEquals($expectedBoundary, $boundary); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + public function testGetAlternativeBoundary() |
|
| 292 | + { |
|
| 293 | + $archangel = new Archangel(); |
|
| 294 | + $boundaryMethod = $this->getProtectedMethod('getAlternativeBoundary'); |
|
| 295 | + $boundary = $boundaryMethod->invoke($archangel); |
|
| 296 | + $expectedBoundary = sprintf('PHP-alternative-%s', uniqid()); |
|
| 297 | + |
|
| 298 | + $this->assertEquals($expectedBoundary, $boundary); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + protected function getProtectedValue($archangel, $property) |
|
| 302 | + { |
|
| 303 | + $reflectedArchangel = new ReflectionClass($archangel); |
|
| 304 | + $reflectedProperty = $reflectedArchangel->getProperty($property); |
|
| 305 | + $reflectedProperty->setAccessible(true); |
|
| 306 | + |
|
| 307 | + return $reflectedProperty->getValue($archangel); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + protected function getProtectedMethod($method) |
|
| 311 | + { |
|
| 312 | + $reflectedArchangel = new ReflectionClass('Jacobemerick\Archangel\Archangel'); |
|
| 313 | + $reflectedMethod = $reflectedArchangel->getMethod($method); |
|
| 314 | + $reflectedMethod->setAccessible(true); |
|
| 315 | + |
|
| 316 | + return $reflectedMethod; |
|
| 317 | + } |
|
| 318 | 318 | } |