Skip to content

Commit

Permalink
Merge 9e0bf39 into 8db60e7
Browse files Browse the repository at this point in the history
  • Loading branch information
rajumsys committed Nov 3, 2016
2 parents 8db60e7 + 9e0bf39 commit 02a8558
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ env:
- WP_VERSION=4.6 WP_MULTISITE=0

before_script:
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
- cd tests
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
- composer install --no-interaction

script: composer test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ git clone git@github.com:SparkPost/wordpress-sparkpost.git ~/src/wordpress/wp-co

## Running Tests
* Make sure you're using PHP 5.6 or above.
* Go to `./tests` directory.
* Install test files by running `bash bin/install-wp-tests.sh wordpress_test root '' localhost latest`. Details on [wp-cli.org](http://wp-cli.org/docs/plugin-unit-tests/).
* [Install composer](https://getcomposer.org/doc/00-intro.md)
* Go to `./tests` directory.
* Run `composer install` to install required packages.
* To run tests, run `composer test`.
* Add your tests in `tests/specs` directory. Upon pushing the branch, Travis will automatically run it and generate reports (tests and coverage).
Expand Down
17 changes: 9 additions & 8 deletions mailer.http.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,21 @@ protected function get_recipients()
$recipients = array();
$recipients_header_to = array();

//prepare header_to
foreach ($this->to as $to) {
$recipients[] = $this->build_recipient($to[0], $to[1]);

// prepare for header_to
if(!empty($to[1])) {
$recipients_header_to[] = sprintf('%s <%s>', $to[1], $to[0]);
} else {
if(empty($to[1])) { // if name is empty use only address
$recipients_header_to[] = $to[0];
} else { // otherwise, use name and email
$recipients_header_to[] = sprintf('%s <%s>', $to[1], $to[0]);
}
}
$recipients_header_to = implode(',', $recipients_header_to);
$recipients_header_to = implode(', ', $recipients_header_to);

foreach ($this->to as $to) {
$recipients[] = $this->build_recipient($to[0], $to[1], $recipients_header_to);
}

// include bcc to recipients
// sparkposts recipients list acts as bcc by default
$recipients = array_merge($recipients, $this->get_bcc($recipients_header_to));

// include cc to recipients, they need to included in recipients and in headers (refer to get_headers method)
Expand Down
File renamed without changes.
84 changes: 56 additions & 28 deletions tests/specs/test-mailer.http.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,6 @@ function test_mailer_is_a_mailer_instance() {
$this->assertTrue( $this->mailer instanceof \PHPMailer );
}

function test_recipients_list() {

$this->mailer->addAddress('abc@xyz.com', 'abc');
$this->mailer->addAddress('def@xyz.com', 'def');
$this->mailer->addAddress('noname@xyz.com');
$prepared_list = array(
array(
'address' => array(
'email' => 'abc@xyz.com',
'name' => 'abc',
)
),
array(
'address' => array(
'name' => 'def',
'email' => 'def@xyz.com'
)
),
array(
'address' => array(
'email' => 'noname@xyz.com',
'name' => ''
)
)
);
$this->assertTrue(NSA::invokeMethod($this->mailer, 'get_recipients') == $prepared_list);
}

function test_sender_with_name() {
$this->mailer->setFrom( 'me@hello.com', 'me' );
$sender = array(
Expand Down Expand Up @@ -131,4 +103,60 @@ function test_get_headers_should_include_cc_if_exists() {

$this->assertTrue($formatted_headers == $expected);
}

function test_get_recipients() {
$this->mailer->addAddress('to@abc.com');
$this->mailer->addAddress('to1@abc.com', 'to1');
$this->mailer->addCc('cc@abc.com');
$this->mailer->addCc('cc1@abc.com', 'cc1');
$this->mailer->addBcc('bcc@abc.com');
$this->mailer->addBcc('bcc1@abc.com', 'bcc1');

$header_to = implode(', ', [
'to@abc.com',
'to1 <to1@abc.com>',
]);

$expected = [
[
'address' => [
'email' => 'to@abc.com',
'header_to' => $header_to
]
],
[
'address' => [
'email' => 'to1@abc.com',
'header_to' => $header_to
]
],
[
'address' => [
'email' => 'bcc@abc.com',
'header_to' => $header_to
]
],
[
'address' => [
'email' => 'bcc1@abc.com',
'header_to' => $header_to
]
],
[
'address' => [
'email' => 'cc@abc.com',
'header_to' => $header_to
]
],
[
'address' => [
'email' => 'cc1@abc.com',
'header_to' => $header_to
]
]
];

$recipients = NSA::invokeMethod($this->mailer, 'get_recipients');
$this->assertTrue($recipients == $expected);
}
}

0 comments on commit 02a8558

Please sign in to comment.