Skip to content

Commit 9d834f2

Browse files
authored
FE-1168: SparkPost logo is broken on Wordpress plugin admin page (#157)
1 parent cbb67d4 commit 9d834f2

7 files changed

+73
-58
lines changed

.travis.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
language: php
22

3+
services:
4+
- mysql
5+
36
notifications:
47
email:
58
on_success: never
@@ -10,16 +13,10 @@ branches:
1013
- master
1114

1215
php:
13-
- 5.6
1416
- 7.0
1517

1618
env:
17-
- WP_VERSION=latest WP_MULTISITE=0
18-
- WP_VERSION=4.3 WP_MULTISITE=0
19-
- WP_VERSION=4.4 WP_MULTISITE=0
20-
- WP_VERSION=4.5 WP_MULTISITE=0
21-
- WP_VERSION=4.6 WP_MULTISITE=0
22-
- WP_VERSION=4.7 WP_MULTISITE=0
19+
- WP_VERSION=5.5 WP_MULTISITE=0
2320

2421
before_script:
2522
- cd tests

deploy.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ rm -rf $SVNPATH/assets/*
7676

7777
echo "Exporting the HEAD of master from git to the trunk of SVN"
7878
git checkout-index -a -f --prefix=$SVNPATH/trunk/
79-
git checkout-index -a -f --prefix=$SVNPATH/ assets/*
79+
git checkout-index -f --prefix=$SVNPATH/ assets/*
8080
rm -rf $SVNPATH/trunk/assets
8181

8282
echo "Ignoring github specific files and deployment script"

mailer.http.class.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected function get_request_body()
123123
if (!empty($template_id)) {
124124
// stored template
125125
$substitution_data = $this->get_template_substitutes($sender, $replyTo);
126-
if (sizeof($attachments) > 0) { //get template preview data and then send it as inline
126+
if (sizeof($attachments) > 0) { // get template preview data and then send it as inline
127127
$preview_contents = $this->template->preview($template_id, $substitution_data);
128128
if ($preview_contents === false) {
129129
return false;
@@ -133,6 +133,10 @@ protected function get_request_body()
133133
'subject' => (string)$preview_contents->subject
134134
);
135135

136+
if(!empty($content_headers)) {
137+
$body['content']['headers'] = $content_headers;
138+
}
139+
136140
if (property_exists($preview_contents, 'text')) {
137141
$body['content']['text'] = $preview_contents->text;
138142
}
@@ -145,7 +149,7 @@ protected function get_request_body()
145149
$body['content']['reply_to'] = $preview_contents->reply_to;
146150
}
147151

148-
} else { // simply subsititute template tags
152+
} else { // simply substitute template tags
149153
$body['content']['template_id'] = $template_id;
150154
$body['substitution_data'] = $substitution_data;
151155
}
@@ -156,6 +160,10 @@ protected function get_request_body()
156160
'subject' => $this->Subject
157161
);
158162

163+
if(!empty($content_headers)) {
164+
$body['content']['headers'] = $content_headers;
165+
}
166+
159167
if ($replyTo) {
160168
$body['content']['reply_to'] = $replyTo;
161169
}
@@ -174,10 +182,6 @@ protected function get_request_body()
174182
}
175183
}
176184

177-
if(!empty($content_headers)) {
178-
$body['content']['headers'] = $content_headers;
179-
}
180-
181185
if (sizeof($attachments)) {
182186
$body['content']['attachments'] = $attachments;
183187
}

readme.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: sparkpost, rajuru
33
Tags: sparkpost, smtp, wp_mail, mail, email
44
Requires at least: 5.5
55
Tested up to: 5.5
6-
Stable tag: 3.2.2
6+
Stable tag: 3.2.3
77
License: GPLv2 or later
88

99
Send all your email from WordPress through SparkPost, the most advanced email delivery service.
@@ -14,7 +14,7 @@ The [SparkPost](https://www.sparkpost.com/) email delivery service offers best i
1414
When the SparkPost plugin is enabled, all outgoing email from your WordPress installation is sent through your SparkPost service. From within [the SparkPost UI](https://app.sparkpost.com/) or [SparkPost EU UI](https://app.eu.sparkpost.com/), you can then watch your campaigns unfold live by tracking your engagement metrics, learn what your audience responds to and even integrate more deeply with your app using the SparkPost API.
1515

1616
**Requirements**
17-
- PHP 5.4 or later
17+
- PHP 7.0 or later
1818
- WordPress 5.5 or later
1919

2020

@@ -52,6 +52,9 @@ Visit plugin's [official issue tracker](https://github.com/SparkPost/wordpress-s
5252

5353
== Changelog ==
5454

55+
= 3.2.3 =
56+
- Fixed broken SparkPost logo on settings page ([157](https://github.com/SparkPost/wordpress-sparkpost/pull/157))
57+
5558
= 3.2.2 =
5659
- Fixed parsing of headers and addressed class-phpmailer.php deprecation notice (for HTTP) ([156](https://github.com/SparkPost/wordpress-sparkpost/pull/156))
5760

tests/bin/install-wp-tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ install_db() {
118118
fi
119119

120120
# create database
121-
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
121+
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS" $EXTRA
122122
}
123123

124124
install_wp

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

+51-40
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ function test_mailSend_calls_sparkpost_send() {
2525
$stub = Mockery::mock($this->mailer);
2626
$stub->shouldReceive('sparkpost_send')->andReturn('woowoo');
2727

28-
$this->assertTrue(NSA::invokeMethod($stub, 'mailSend', null, null) == 'woowoo');
28+
$this->assertEquals(NSA::invokeMethod($stub, 'mailSend', null, null), 'woowoo');
2929
}
3030

3131
function test_mailer_is_a_mailer_instance() {
32-
$this->assertTrue( $this->mailer instanceof \PHPMailer );
32+
$this->assertTrue( $this->mailer instanceof \PHPMailer\PHPMailer\PHPMailer );
3333
}
3434

3535
function test_get_sender_with_name() {
@@ -39,7 +39,7 @@ function test_get_sender_with_name() {
3939
'email' => 'me@hello.com'
4040
);
4141

42-
$this->assertTrue(NSA::invokeMethod($this->mailer, 'get_sender') == $sender);
42+
$this->assertEquals(NSA::invokeMethod($this->mailer, 'get_sender'), $sender);
4343
}
4444

4545
function test_get_sender_without_name() {
@@ -48,7 +48,7 @@ function test_get_sender_without_name() {
4848
'email' => 'me@hello.com'
4949
);
5050

51-
$this->assertTrue(NSA::invokeMethod($this->mailer, 'get_sender') == $sender);
51+
$this->assertEquals(NSA::invokeMethod($this->mailer, 'get_sender'), $sender);
5252
}
5353

5454
function test_get_request_headers() {
@@ -57,15 +57,15 @@ function test_get_request_headers() {
5757
'Content-Type' => 'application/json',
5858
'Authorization' => ''
5959
);
60-
$this->assertTrue(NSA::invokeMethod($this->mailer, 'get_request_headers') == $expected);
60+
$this->assertEquals(NSA::invokeMethod($this->mailer, 'get_request_headers'), $expected);
6161

6262
NSA::setProperty($this->mailer, 'settings', array('password' => 'abcd1234'));
6363
$expected = array(
6464
'User-Agent' => 'wordpress-sparkpost/' . WPSP_PLUGIN_VERSION,
6565
'Content-Type' => 'application/json',
6666
'Authorization' => 'abcd1234'
6767
);
68-
$this->assertTrue(NSA::invokeMethod($this->mailer, 'get_request_headers') == $expected);
68+
$this->assertEquals(NSA::invokeMethod($this->mailer, 'get_request_headers'), $expected);
6969
}
7070

7171
function test_get_request_headers_obfuscate_key() {
@@ -75,48 +75,59 @@ function test_get_request_headers_obfuscate_key() {
7575
'Content-Type' => 'application/json',
7676
'Authorization' => 'abcd'.str_repeat('*', 36)
7777
);
78-
$this->assertTrue(NSA::invokeMethod($this->mailer, 'get_request_headers', true) == $expected);
78+
79+
$this->assertEquals(NSA::invokeMethod($this->mailer, 'get_request_headers', true), $expected);
7980
}
8081

8182
function test_get_headers() {
82-
$raw_headers = "Date: Wed, 26 Oct 2016 23:45:32 +0000
83-
To: undisclosed-recipients:;
84-
From: Root User <root@localhost>
85-
Subject: Hello
86-
Reply-To: replyto@mydomain.com
87-
Message-ID: <abcd@example.org>
88-
MIME-Version: 1.0
89-
Content-Type: text/plain; charset=iso-8859-1
90-
Content-Transfer-Encoding: 8bit";
83+
$stub = Mockery::mock($this->mailer);
84+
$raw_headers = join(
85+
NSA::getProperty($stub, 'LE'),
86+
array(
87+
'Date: Wed, 26 Oct 2016 23:45:32 +0000',
88+
'To: undisclosed-recipients:;',
89+
'From: Root User <root@localhost>',
90+
'Subject: Hello',
91+
'Reply-To: replyto@mydomain.com',
92+
'Message-ID: <abcd@example.org>',
93+
'MIME-Version: 1.0',
94+
'Content-Type: text/plain; charset=iso-8859-1',
95+
'Content-Transfer-Encoding: 8bit'
96+
)
97+
);
98+
$stub->shouldReceive('createHeader')->andReturn($raw_headers);
99+
$formatted_headers = NSA::invokeMethod($stub, 'get_headers');
91100

92101
$expected = array(
93102
'Message-ID' => '<abcd@example.org>',
94103
'Date' => 'Wed, 26 Oct 2016 23:45:32 +0000'
95104
);
96-
$stub = Mockery::mock($this->mailer);
97-
$stub->shouldReceive('createHeader')->andReturn($raw_headers);
98-
$formatted_headers = NSA::invokeMethod($stub, 'get_headers');
99105

100-
$this->assertTrue($formatted_headers == $expected);
106+
$this->assertEquals($formatted_headers, $expected);
101107
}
102108

103109

104110
function test_get_headers_should_include_cc_if_exists() {
105-
$raw_headers = "Date: Wed, 26 Oct 2016 23:45:32 +0000
106-
Reply-To: replyto@mydomain.com";
107-
108-
$expected = array(
109-
'Date' => 'Wed, 26 Oct 2016 23:45:32 +0000',
110-
'CC' => 'hello@abc.com,Name <name@domain.com>'
111-
);
112111
$stub = Mockery::mock($this->mailer);
112+
$raw_headers = join(
113+
NSA::getProperty($stub, 'LE'),
114+
array(
115+
'Date: Wed, 26 Oct 2016 23:45:32 +0000',
116+
'Reply-To: replyto@mydomain.com'
117+
)
118+
);
113119
$stub->shouldReceive('createHeader')->andReturn($raw_headers);
114120
$stub->addCc('hello@abc.com');
115121
$stub->addCc('name@domain.com', 'Name');
116122

117123
$formatted_headers = NSA::invokeMethod($stub, 'get_headers');
118124

119-
$this->assertTrue($formatted_headers == $expected);
125+
$expected = array(
126+
'Date' => 'Wed, 26 Oct 2016 23:45:32 +0000',
127+
'CC' => 'hello@abc.com,Name <name@domain.com>'
128+
);
129+
130+
$this->assertEquals($formatted_headers, $expected);
120131
}
121132

122133
function test_get_recipients() {
@@ -172,7 +183,7 @@ function test_get_recipients() {
172183
];
173184

174185
$recipients = NSA::invokeMethod($this->mailer, 'get_recipients');
175-
$this->assertTrue($recipients == $expected);
186+
$this->assertEquals($recipients, $expected);
176187
}
177188

178189
function test_get_attachments() {
@@ -190,9 +201,9 @@ function test_get_attachments() {
190201
function test_isMail() {
191202
// test if isMail sets correct mailer
192203
$this->mailer->Mailer = 'abc';
193-
$this->assertTrue($this->mailer->Mailer === 'abc');
204+
$this->assertEquals($this->mailer->Mailer, 'abc');
194205
$this->mailer->isMail();
195-
$this->assertTrue($this->mailer->Mailer === 'sparkpost');
206+
$this->assertEquals($this->mailer->Mailer, 'sparkpost');
196207
}
197208

198209
function test_get_request_body_without_template() {
@@ -250,15 +261,15 @@ function test_get_request_body_without_template() {
250261
// for simpler expectation reset content.headers to empty array.
251262
// alternative is to stub get_headers which isn't working expectedly
252263
$actual['content']['headers'] = [];
253-
$this->assertTrue($expected_request_body == $actual);
264+
$this->assertEquals($expected_request_body, $actual);
254265

255266
//INCLUDE REPLYTO
256267
$this->mailer->addReplyTo('reply@abc.com', 'reply-to');
257268
$this->mailer->addCustomHeader('Reply-To', 'reply-to <reply@abc.com>'); //for below version v4.6
258269
$actual = NSA::invokeMethod($this->mailer, 'get_request_body');
259270
$actual['content']['headers'] = []; //see note above
260271
$expected_request_body['content']['reply_to'] = 'reply-to <reply@abc.com>';
261-
$this->assertTrue($expected_request_body == $actual);
272+
$this->assertEquals($expected_request_body, $actual);
262273
}
263274

264275
function test_get_request_body_template_in_hook_but_not_in_settings() {
@@ -279,7 +290,7 @@ function test_get_request_body_template_in_hook_but_not_in_settings() {
279290

280291
$body = NSA::invokeMethod($this->mailer, 'get_request_body');
281292
remove_filter('wpsp_template_id', $callback);
282-
$this->assertTrue($body['content']['template_id'] == 'test-template');
293+
$this->assertEquals($body['content']['template_id'], 'test-template');
283294
}
284295

285296
function test_get_request_body_with_template() {
@@ -333,14 +344,14 @@ function test_get_request_body_with_template() {
333344
];
334345

335346
$actual = NSA::invokeMethod($this->mailer, 'get_request_body');
336-
$this->assertTrue($expected_request_body == $actual);
347+
$this->assertEquals($expected_request_body, $actual);
337348

338349
//INCLUDE REPLYTO
339350
$this->mailer->addReplyTo('reply@abc.com', 'reply-to');
340351
$this->mailer->addCustomHeader('Reply-To', 'reply-to <reply@abc.com>'); //for below version v4.6
341352
$actual = NSA::invokeMethod($this->mailer, 'get_request_body');
342353
$expected_request_body['substitution_data']['reply_to'] = 'reply-to <reply@abc.com>';
343-
$this->assertTrue($expected_request_body == $actual);
354+
$this->assertEquals($expected_request_body, $actual);
344355
}
345356

346357
function test_get_request_body_with_template_and_attachments() {
@@ -420,7 +431,7 @@ function test_get_request_body_with_template_and_attachments() {
420431

421432
$actual = NSA::invokeMethod($mailer, 'get_request_body');
422433
unset($actual['content']['headers']); //to simplify assertion
423-
$this->assertTrue($expected_request_body == $actual);
434+
$this->assertEquals($expected_request_body, $actual);
424435
}
425436

426437
function test_sparkpost_send_false_on_error() {
@@ -519,7 +530,7 @@ function test_get_request_body_with_sandbox() {
519530
]);
520531

521532
$body = NSA::invokeMethod($mailer, 'get_request_body');
522-
$this->assertTrue($body['options']['sandbox'] == true);
533+
$this->assertTrue($body['options']['sandbox']);
523534
}
524535

525536
function sparkpost_send_prepare_mocks($num_rejected) {
@@ -658,10 +669,10 @@ function test_check_permission_error(){
658669
->setMethods(array('debug', 'error'))
659670
->getMock();
660671

661-
$this->assertTrue($mailer->check_permission_error($response, 'test_perm') === true);
672+
$this->assertTrue($mailer->check_permission_error($response, 'test_perm'));
662673

663674
$response['response']['code'] = 200;
664-
$this->assertTrue($mailer->check_permission_error($response, 'test_perm') === false);
675+
$this->assertFalse($mailer->check_permission_error($response, 'test_perm'));
665676
}
666677

667678

wordpress-sparkpost.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
define('WPSP_PLUGIN_DIR', plugin_dir_path(__FILE__));
2020
define('WPSP_PLUGIN_PATH', WPSP_PLUGIN_DIR . basename(__FILE__));
21-
define('WPSP_PLUGIN_VERSION', '3.2.2');
21+
define('WPSP_PLUGIN_VERSION', '3.2.3');
2222

2323
require_once(WPSP_PLUGIN_DIR . 'sparkpost.class.php');
2424

0 commit comments

Comments
 (0)