|
4 | 4 | */ |
5 | 5 | namespace WPSparkPost; |
6 | 6 | use \Nyholm\NSA; |
| 7 | +use \Mockery; |
7 | 8 |
|
8 | 9 | class TestHttpMailer extends \WP_UnitTestCase { |
9 | 10 | var $mailer; |
@@ -89,4 +90,45 @@ function test_get_request_headers_obfuscate_key() { |
89 | 90 | ); |
90 | 91 | $this->assertTrue(NSA::invokeMethod($this->mailer, 'get_request_headers', true) == $expected); |
91 | 92 | } |
| 93 | + |
| 94 | + function test_get_headers() { |
| 95 | + $raw_headers = "Date: Wed, 26 Oct 2016 23:45:32 +0000 |
| 96 | + To: undisclosed-recipients:; |
| 97 | + From: Root User <root@localhost> |
| 98 | + Subject: Hello |
| 99 | + Reply-To: replyto@mydomain.com |
| 100 | + Message-ID: <abcd@example.org> |
| 101 | + MIME-Version: 1.0 |
| 102 | + Content-Type: text/plain; charset=iso-8859-1 |
| 103 | + Content-Transfer-Encoding: 8bit"; |
| 104 | + |
| 105 | + $expected = array( |
| 106 | + 'Message-ID' => '<abcd@example.org>', |
| 107 | + 'Date' => 'Wed, 26 Oct 2016 23:45:32 +0000' |
| 108 | + ); |
| 109 | + $stub = Mockery::mock($this->mailer); |
| 110 | + $stub->shouldReceive('createHeader')->andReturn($raw_headers); |
| 111 | + $formatted_headers = NSA::invokeMethod($stub, 'get_headers'); |
| 112 | + |
| 113 | + $this->assertTrue($formatted_headers == $expected); |
| 114 | + } |
| 115 | + |
| 116 | + |
| 117 | + function test_get_headers_should_include_cc_if_exists() { |
| 118 | + $raw_headers = "Date: Wed, 26 Oct 2016 23:45:32 +0000 |
| 119 | + Reply-To: replyto@mydomain.com"; |
| 120 | + |
| 121 | + $expected = array( |
| 122 | + 'Date' => 'Wed, 26 Oct 2016 23:45:32 +0000', |
| 123 | + 'CC' => 'hello@abc.com,Name <name@domain.com>' |
| 124 | + ); |
| 125 | + $stub = Mockery::mock($this->mailer); |
| 126 | + $stub->shouldReceive('createHeader')->andReturn($raw_headers); |
| 127 | + $stub->addCc('hello@abc.com'); |
| 128 | + $stub->addCc('name@domain.com', 'Name'); |
| 129 | + |
| 130 | + $formatted_headers = NSA::invokeMethod($stub, 'get_headers'); |
| 131 | + |
| 132 | + $this->assertTrue($formatted_headers == $expected); |
| 133 | + } |
92 | 134 | } |
0 commit comments