Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mailing Sub-System Improvments #85

Merged
merged 17 commits into from
Nov 2, 2021
18 changes: 18 additions & 0 deletions app/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,24 @@ private function initSiteInfo() {
*/
private function initSmtpConnections() {
$this->emailAccounts = [
'no-reply' => new SMTPAccount([
'port' => 587,
'server-address' => 'outlook.office365.com',
'user' => '[email protected]',
'pass' => '???',
'sender-name' => 'Ibrahim',
'sender-address' => '[email protected]',
'account-name' => 'no-reply'
]),
'no-reply2' => new SMTPAccount([
'port' => 465,
'server-address' => 'smtp.gmail.com',
'user' => '[email protected]',
'pass' => '???',
'sender-name' => 'Ibrahim',
'sender-address' => '[email protected]',
'account-name' => 'no-reply2'
])
];
}
/**
Expand Down
147 changes: 105 additions & 42 deletions tests/entity/mail/EmailMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,68 +14,131 @@ class EmailMessageTest extends TestCase {
/**
* @test
*/
public function test00() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No SMTP account was found which has the name "not exist".');
$message = new EmailMessage('not exist');
public function testAddReciver00() {
$sm = new EmailMessage('no-reply');
$this->assertFalse($sm->addTo('', ''));
$this->assertFalse($sm->addTo('', 'Hello'));
$this->assertFalse($sm->addTo('', '[email protected]'));
}
/**
* @test
*/
public function test01() {
$smtp = new SMTPAccount();
$smtp->setAccountName('smtp-acc-00');
//$smtp->setServerAddress('mail.invalid.com');
WebFioriApp::getAppConfig()->addAccount($smtp);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The account "smtp-acc-00" has invalid host or port number. Port: 465, Host: .');
$message = new EmailMessage('smtp-acc-00');
public function testAddReciver01() {
$sm = new EmailMessage('no-reply');
$this->assertTrue($sm->addTo(' hello@>hello.com ', ' <Hello'));
$this->assertEquals('=?UTF-8?B?SGVsbG8=?= <[email protected]>',$sm->getToStr());
$this->assertEquals('Hello',$sm->getTo()['[email protected]']);
$this->assertTrue($sm->addTo(' hello@>hello.com ', ' <Hello2 '));
$this->assertEquals('=?UTF-8?B?SGVsbG8y?= <[email protected]>',$sm->getToStr());
$this->assertTrue($sm->addTo(' hello-9@>hello.com ', ' Hel>lo-9'));
$this->assertEquals('=?UTF-8?B?SGVsbG8y?= <[email protected]>,=?UTF-8?B?SGVsbG8tOQ==?= <[email protected]>',$sm->getToStr());
}
/**
* @test
*/
public function test02() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The account "smtp-acc-00" has invalid host or port number. Port: 255, Host: mail.programmingacademia.com.');
$smtp = new SMTPAccount();
$smtp->setPassword('iz1Iimu#z');
$smtp->setAddress('[email protected]');
$smtp->setUsername('[email protected]');
$smtp->setServerAddress('mail.programmingacademia.com ');
$smtp->setPort(255);
$smtp->setAccountName('smtp-acc-00');
WebFioriApp::getAppConfig()->addAccount($smtp);
$message = new EmailMessage('smtp-acc-00');
public function testAddReciver02() {
$sm = new EmailMessage('no-reply');
$this->assertTrue($sm->addCC(' hello@>hello.com ', ' <Hello '));
$this->assertEquals('=?UTF-8?B?SGVsbG8=?= <[email protected]>',$sm->getCCStr());
$this->assertEquals('Hello',$sm->getCC()['[email protected]']);
$this->assertTrue($sm->addCC(' hello@>hello.com ', ' <Hello2 '));
$this->assertEquals('=?UTF-8?B?SGVsbG8y?= <[email protected]>',$sm->getCCStr());
$this->assertTrue($sm->addCC(' hello-9@>hello.com ', ' Hel>lo-9 '));
$this->assertEquals('=?UTF-8?B?SGVsbG8y?= <[email protected]>,=?UTF-8?B?SGVsbG8tOQ==?= <[email protected]>',$sm->getCCStr());
}
/**
* @test
*/
public function test03() {
public function testAddReciver03() {
$sm = new EmailMessage('no-reply');
$this->assertTrue($sm->addBCC(' hello@>hello.com ', ' <Hello',true,true));
$this->assertEquals('=?UTF-8?B?SGVsbG8=?= <[email protected]>',$sm->getBCCStr());
$this->assertEquals('Hello',$sm->getBCC()['[email protected]']);
$this->assertTrue($sm->addBCC('hello@>hello.com ', ' <Hello2 ',true,true));
$this->assertEquals('=?UTF-8?B?SGVsbG8y?= <[email protected]>',$sm->getBCCStr());
$this->assertTrue($sm->addBCC('hello-9@>hello.com ', ' Hel>lo-9',true,true));
$this->assertEquals('=?UTF-8?B?SGVsbG8y?= <[email protected]>,=?UTF-8?B?SGVsbG8tOQ==?= <[email protected]>',$sm->getBCCStr());
}
/**
* @test
*/
public function testConstructor00() {
$sm = new EmailMessage('no-reply');
$this->assertEquals('',$sm->getSMTPServer()->getLastResponse());
$this->assertSame(0,$sm->getSMTPServer()->getLastResponseCode());
$this->assertSame(0,$sm->getPriority());
$this->assertSame(5,$sm->getSMTPServer()->getTimeout());
}
/**
* @test
*/
public function testSetPriority00() {
$sm = new EmailMessage('no-reply');
$sm->setPriority(-2);
$this->assertSame(-1,$sm->getPriority());
$sm->setPriority(100);
$this->assertSame(1,$sm->getPriority());
$sm->setPriority("hello");
$this->assertSame(0,$sm->getPriority());
$sm->setPriority("-26544");
$this->assertSame(-1,$sm->getPriority());
$sm->setPriority("26544");
$this->assertSame(1,$sm->getPriority());
$sm->setPriority(0);
$this->assertSame(0,$sm->getPriority());
}
/**
* @test
*/
public function test00() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The account "smtp-acc-00" has invalid host or port number. Port: 765765, Host: mail.programmingacademia.com.');
$smtp = new SMTPAccount();
$smtp->setPassword('izimu#z');
$smtp->setAddress('[email protected]');
$smtp->setUsername('[email protected]');
$smtp->setServerAddress('mail.programmingacademia.com ');
$smtp->setPort(765765);
$smtp->setAccountName('smtp-acc-00');
WebFioriApp::getAppConfig()->addAccount($smtp);
$message = new EmailMessage('smtp-acc-00');
$this->assertTrue($message instanceof EmailMessage);
$this->expectExceptionMessage('No SMTP account was found which has the name "not exist".');
$message = new EmailMessage('not exist');
}
/**
* @test
*/
// public function test04() {
// public function test01() {
// $smtp = new SMTPAccount();
// $smtp->setAccountName('smtp-acc-00');
// //$smtp->setServerAddress('mail.invalid.com');
// WebFioriApp::getAppConfig()->addAccount($smtp);
// $this->expectException(\Exception::class);
// $this->expectExceptionMessage('The account "smtp-acc-00" has invalid host or port number. Port: 465, Host: .');
// $message = new EmailMessage('smtp-acc-00');
// }
/**
* @test
*/
// public function test02() {
// $this->expectException(\Exception::class);
// $this->expectExceptionMessage('The account "smtp-acc-00" has invalid host or port number. Port: 255, Host: mail.programmingacademia.com.');
// $smtp = new SMTPAccount();
// $smtp->setPassword('iz1Iimu#z');
// $smtp->setAddress('[email protected]');
// $smtp->setUsername('[email protected]');
// $smtp->setServerAddress('mail.programmingacademia.com ');
// $smtp->setPort(255);
// $smtp->setAccountName('smtp-acc-00');
// WebFioriApp::getAppConfig()->addAccount($smtp);
// $message = new EmailMessage('smtp-acc-00');
// }
/**
* @test
*/
// public function test03() {
// $this->expectException(\Exception::class);
// $this->expectExceptionMessage('The account "smtp-acc-00" has invalid host or port number. Port: 765765, Host: mail.programmingacademia.com.');
// $smtp = new SMTPAccount();
// $smtp->setPassword('iz2)X1Iimu#z');
// $smtp->setPassword('izimu#z');
// $smtp->setAddress('[email protected]');
// $smtp->setUsername('[email protected]');
// $smtp->setServerAddress('mail.programmingacademia.com ');
// $smtp->setPort(25);
// MailConfig::get()->addSMTPAccount('smtp-acc-00', $smtp);
// $message = EmailMessage::createInstance('smtp-acc-00');
// $smtp->setServerAddress('mail.programmingacademia.com ');
// $smtp->setPort(765765);
// $smtp->setAccountName('smtp-acc-00');
// WebFioriApp::getAppConfig()->addAccount($smtp);
// $message = new EmailMessage('smtp-acc-00');
// $this->assertTrue($message instanceof EmailMessage);
// }

}
88 changes: 0 additions & 88 deletions tests/entity/mail/SocketMailerTest.php

This file was deleted.

38 changes: 38 additions & 0 deletions tests/entity/mail/TestSMTPServer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

namespace webfiori\tests\entity\mail;
use PHPUnit\Framework\TestCase;
use PHPMailer\PHPMailer;
/**
* Description of TestSMTPServer
*
* @author Ibrahim
*/
class TestSMTPServer extends TestCase {
/**
* @test
*/
public function test00() {
$server = new SMTPServer('smtp.gmail.com', 465);
$this->assertEquals('smtp.gmail.com', $server->getHost());
$this->assertEquals(465, $server->getPort());

$this->assertTrue($server->connect());
}
/**
* @test
*/
public function test01() {
$server = new SMTPServer('smtp.outlook.com', 587);
$this->assertEquals('smtp.outlook.com', $server->getHost());
$this->assertEquals(587, $server->getPort());

$this->assertTrue($server->connect());
}
}
Loading