Skip to content

Commit 6978d2c

Browse files
committed
Add tests for get_headers
1 parent 479012f commit 6978d2c

File tree

3 files changed

+156
-3
lines changed

3 files changed

+156
-3
lines changed

tests/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"require-dev": {
55
"satooshi/php-coveralls": "^1.0",
66
"phpunit/phpunit": "^5.6",
7-
"nyholm/nsa": "^1.0"
7+
"nyholm/nsa": "^1.0",
8+
"mockery/mockery": "^0.9.5"
89
},
910
"scripts": {
1011
"test": "./vendor/bin/phpunit"

tests/composer.lock

Lines changed: 112 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/specs/test-mailer.http.class.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
namespace WPSparkPost;
66
use \Nyholm\NSA;
7+
use \Mockery;
78

89
class TestHttpMailer extends \WP_UnitTestCase {
910
var $mailer;
@@ -89,4 +90,45 @@ function test_get_request_headers_obfuscate_key() {
8990
);
9091
$this->assertTrue(NSA::invokeMethod($this->mailer, 'get_request_headers', true) == $expected);
9192
}
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+
}
92134
}

0 commit comments

Comments
 (0)