forked from PHPMailer/PHPMailer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/PHPMailer/PHPMailer
- Loading branch information
Showing
1 changed file
with
123 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
|
||
namespace PHPMailer\Test; | ||
|
||
use PHPMailer\PHPMailer\OAuth; | ||
use PHPMailer\PHPMailer\PHPMailer; | ||
use PHPMailer\PHPMailer\POP3; | ||
use PHPUnit\Framework\TestCase; | ||
|
@@ -659,6 +660,8 @@ public function testValidate() | |
$this->assertFalse(PHPMailer::validateAddress('[email protected].', 'pcre')); | ||
$this->assertTrue(PHPMailer::validateAddress('[email protected]', 'pcre8')); | ||
$this->assertFalse(PHPMailer::validateAddress('[email protected].', 'pcre8')); | ||
$this->assertTrue(PHPMailer::validateAddress('[email protected]', 'html5')); | ||
$this->assertFalse(PHPMailer::validateAddress('[email protected].', 'html5')); | ||
$this->assertTrue(PHPMailer::validateAddress('[email protected]', 'php')); | ||
$this->assertFalse(PHPMailer::validateAddress('[email protected].', 'php')); | ||
$this->assertTrue(PHPMailer::validateAddress('[email protected]', 'noregex')); | ||
|
@@ -939,6 +942,37 @@ public function testHtml() | |
$this->assertNotContains("\r\n\r\nMIME-Version:", $msg, 'Incorrect MIME headers'); | ||
} | ||
|
||
/** | ||
* createBody test of switch case | ||
*/ | ||
public function testCreateBody() | ||
{ | ||
$PHPMailer = new PHPMailer(); | ||
$reflection = new \ReflectionClass($PHPMailer); | ||
$property = $reflection->getProperty('message_type'); | ||
$property->setAccessible(true); | ||
$property->setValue($PHPMailer, 'inline'); | ||
$this->assertInternalType('string', $PHPMailer->createBody()); | ||
|
||
$property->setValue($PHPMailer, 'attach'); | ||
$this->assertInternalType('string', $PHPMailer->createBody()); | ||
|
||
$property->setValue($PHPMailer, 'inline_attach'); | ||
$this->assertInternalType('string', $PHPMailer->createBody()); | ||
|
||
$property->setValue($PHPMailer, 'alt'); | ||
$this->assertInternalType('string', $PHPMailer->createBody()); | ||
|
||
$property->setValue($PHPMailer, 'alt_inline'); | ||
$this->assertInternalType('string', $PHPMailer->createBody()); | ||
|
||
$property->setValue($PHPMailer, 'alt_attach'); | ||
$this->assertInternalType('string', $PHPMailer->createBody()); | ||
|
||
$property->setValue($PHPMailer, 'alt_inline_attach'); | ||
$this->assertInternalType('string', $PHPMailer->createBody()); | ||
} | ||
|
||
/** | ||
* Send a message containing ISO-8859-1 text. | ||
*/ | ||
|
@@ -1102,10 +1136,10 @@ function ($html) { | |
//Test that absolute URLs are ignored | ||
$this->Mail->msgHTML('<img src="https://github.com/PHPMailer/PHPMailer/blob/master/composer.json">test'); | ||
$this->assertTrue( | ||
strpos( | ||
false !== strpos( | ||
$this->Mail->Body, | ||
'src="https://github.com/PHPMailer/PHPMailer/blob/master/composer.json"' | ||
) !== false | ||
) | ||
); | ||
//Test that absolute URLs with anonymous/relative protocol are ignored | ||
//Note that such URLs will not work in email anyway because they have no protocol to be relative to | ||
|
@@ -1334,6 +1368,7 @@ public function testSendmailSend() | |
|
||
$this->Mail->Subject = $subject . ': sendmail'; | ||
$this->Mail->isSendmail(); | ||
|
||
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo); | ||
} | ||
|
||
|
@@ -1368,8 +1403,23 @@ public function testMailSend() | |
} | ||
$this->Mail->Body = 'Sending via mail()'; | ||
$this->buildBody(); | ||
|
||
$this->Mail->Subject = $this->Mail->Subject . ': mail()'; | ||
$this->Mail->clearAddresses(); | ||
$this->Mail->clearCCs(); | ||
$this->Mail->clearBCCs(); | ||
$this->setAddress('[email protected]', 'totest'); | ||
$this->setAddress('[email protected]', 'cctest', $sType = 'cc'); | ||
$this->setAddress('[email protected]', 'bcctest', $sType = 'bcc'); | ||
$this->Mail->addReplyTo('[email protected]', 'replytotest'); | ||
$this->assertContains('[email protected]', $this->Mail->getToAddresses()[0]); | ||
$this->assertContains('[email protected]', $this->Mail->getCcAddresses()[0]); | ||
$this->assertContains('[email protected]', $this->Mail->getBccAddresses()[0]); | ||
$this->assertContains('[email protected]', $this->Mail->getReplyToAddresses()['[email protected]']); | ||
$this->assertTrue($this->Mail->getAllRecipientAddresses()['[email protected]']); | ||
$this->assertTrue($this->Mail->getAllRecipientAddresses()['[email protected]']); | ||
$this->assertTrue($this->Mail->getAllRecipientAddresses()['[email protected]']); | ||
|
||
$this->Mail->createHeader(); | ||
$this->Mail->isMail(); | ||
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo); | ||
$msg = $this->Mail->getSentMIMEMessage(); | ||
|
@@ -1650,7 +1700,19 @@ public function testAddressEscaping() | |
$this->buildBody(); | ||
$this->Mail->preSend(); | ||
$b = $this->Mail->getSentMIMEMessage(); | ||
$this->assertTrue((strpos($b, 'To: "Tim \"The Book\" O\'Reilly" <[email protected]>') !== false)); | ||
$this->assertTrue((false !== strpos($b, 'To: "Tim \"The Book\" O\'Reilly" <[email protected]>'))); | ||
|
||
$this->Mail->Subject .= ': Address escaping invalid'; | ||
$this->Mail->clearAddresses(); | ||
$this->Mail->addAddress('[email protected]', 'Tim "The Book" O\'Reilly'); | ||
$this->Mail->addAddress('invalidaddressexample.com', 'invalidaddress'); | ||
$this->Mail->Body = 'invalid address'; | ||
$this->buildBody(); | ||
$this->Mail->preSend(); | ||
$this->assertEquals($this->Mail->ErrorInfo, 'Invalid address: (to): invalidaddressexample.com'); | ||
|
||
$this->Mail->addAttachment(realpath($this->INCLUDE_DIR . '/examples/images/phpmailer_mini.png'), 'phpmailer_mini.png'); | ||
$this->assertTrue($this->Mail->attachmentExists()); | ||
} | ||
|
||
/** | ||
|
@@ -1676,10 +1738,15 @@ public function testMIMEStructure() | |
*/ | ||
public function testBCCAddressing() | ||
{ | ||
$this->Mail->isSMTP(); | ||
$this->Mail->Subject .= ': BCC-only addressing'; | ||
$this->buildBody(); | ||
$this->Mail->clearAllRecipients(); | ||
$this->Mail->addAddress('[email protected]', 'Foo'); | ||
$this->Mail->preSend(); | ||
$b = $this->Mail->getSentMIMEMessage(); | ||
$this->assertTrue($this->Mail->addBCC('[email protected]'), 'BCC addressing failed'); | ||
$this->assertTrue((false !== strpos($b, 'To: Foo <[email protected]>'))); | ||
$this->assertTrue($this->Mail->send(), 'send failed'); | ||
} | ||
|
||
|
@@ -1721,6 +1788,7 @@ public function testEncodings() | |
$this->Mail->ErrorInfo = ''; | ||
$this->Mail->encodeString('hello', 'asdfghjkl'); | ||
$this->assertNotEmpty($this->Mail->ErrorInfo, 'Invalid encoding not detected'); | ||
$this->assertRegExp('/' . base64_encode('hello') . '/', $this->Mail->encodeString('hello')); | ||
} | ||
|
||
/** | ||
|
@@ -2381,12 +2449,12 @@ public function testDuplicateIDNRemoved() | |
// There should be only one "To" address and one "Reply-To" address. | ||
$this->assertEquals( | ||
1, | ||
count($this->Mail->getToAddresses()), | ||
\count($this->Mail->getToAddresses()), | ||
'Bad count of "to" recipients' | ||
); | ||
$this->assertEquals( | ||
1, | ||
count($this->Mail->getReplyToAddresses()), | ||
\count($this->Mail->getReplyToAddresses()), | ||
'Bad count of "reply-to" addresses' | ||
); | ||
} | ||
|
@@ -2456,28 +2524,61 @@ public function testSmtpConnect() | |
$this->Mail->SMTPDebug = 4; //Show connection-level errors | ||
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP single connect failed'); | ||
$this->Mail->smtpClose(); | ||
$this->Mail->Host = 'localhost:12345;10.10.10.10:54321;' . $_REQUEST['mail_host']; | ||
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP multi-connect failed'); | ||
$this->Mail->smtpClose(); | ||
$this->Mail->Host = '[::1]:' . $this->Mail->Port . ';' . $_REQUEST['mail_host']; | ||
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP IPv6 literal multi-connect failed'); | ||
$this->Mail->smtpClose(); | ||
//All these hosts are expected to fail | ||
$this->Mail->Host = 'xyz://bogus:25;tls://[bogus]:25;ssl://localhost:12345;tls://localhost:587;10.10.10.10:54321;localhost:12345;10.10.10.10'; | ||
$this->assertFalse($this->Mail->smtpConnect(), 'SMTP bad multi-connect succeeded'); | ||
$this->Mail->smtpClose(); | ||
|
||
// $this->Mail->Host = 'localhost:12345;10.10.10.10:54321;' . $_REQUEST['mail_host']; | ||
// $this->assertTrue($this->Mail->smtpConnect(), 'SMTP multi-connect failed'); | ||
// $this->Mail->smtpClose(); | ||
// $this->Mail->Host = '[::1]:' . $this->Mail->Port . ';' . $_REQUEST['mail_host']; | ||
// $this->assertTrue($this->Mail->smtpConnect(), 'SMTP IPv6 literal multi-connect failed'); | ||
// $this->Mail->smtpClose(); | ||
|
||
// All these hosts are expected to fail | ||
// $this->Mail->Host = 'xyz://bogus:25;tls://[bogus]:25;ssl://localhost:12345;tls://localhost:587;10.10.10.10:54321;localhost:12345;10.10.10.10'. $_REQUEST['mail_host'].' '; | ||
// $this->assertFalse($this->Mail->smtpConnect()); | ||
// $this->Mail->smtpClose(); | ||
|
||
$this->Mail->Host = ' localhost:12345 ; ' . $_REQUEST['mail_host'] . ' '; | ||
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP hosts with stray spaces failed'); | ||
$this->Mail->smtpClose(); | ||
|
||
// Need to pick a harmless option so as not cause problems of its own! socket:bind doesn't work with Travis-CI | ||
$this->Mail->Host = $_REQUEST['mail_host']; | ||
//Need to pick a harmless option so as not cause problems of its own! socket:bind doesn't work with Travis-CI | ||
$this->assertTrue( | ||
$this->Mail->smtpConnect(['ssl' => ['verify_depth' => 10]]), | ||
'SMTP connect with options failed' | ||
); | ||
$this->assertTrue($this->Mail->smtpConnect(['ssl' => ['verify_depth' => 10]])); | ||
|
||
$this->Smtp = $this->Mail->getSMTPInstance(); | ||
$this->assertInstanceOf(\get_class($this->Smtp), $this->Mail->setSMTPInstance($this->Smtp)); | ||
$this->assertFalse($this->Smtp->startTLS(), 'SMTP connect with options failed'); | ||
$this->assertFalse($this->Mail->SMTPAuth); | ||
$this->Mail->smtpClose(); | ||
} | ||
} | ||
|
||
/** | ||
* Test OAuth method | ||
*/ | ||
public function testOAuth() | ||
{ | ||
$PHPMailer = new PHPMailer(); | ||
$reflection = new \ReflectionClass($PHPMailer); | ||
$property = $reflection->getProperty('oauth'); | ||
$property->setAccessible(true); | ||
$property->setValue($PHPMailer, true); | ||
$this->assertTrue($PHPMailer->getOAuth()); | ||
|
||
$options =[ | ||
'provider' => 'dummyprovider', | ||
'userName' => 'dummyusername', | ||
'clientSecret' => 'dummyclientsecret', | ||
'clientId' => 'dummyclientid', | ||
'refreshToken' => 'dummyrefreshtoken', | ||
]; | ||
|
||
$oauth = new OAuth($options); | ||
$this->assertInstanceOf(OAuth::class, $oauth); | ||
$subject = $PHPMailer->setOAuth($oauth); | ||
$this->assertNull($subject); | ||
$this->assertInstanceOf(OAuth::class, $PHPMailer->getOAuth()); | ||
} | ||
} | ||
/* | ||
* This is a sample form for setting appropriate test values through a browser | ||
* These values can also be set using a file called testbootstrap.php (not in repo) in the same folder as this script | ||
|