-
-
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 pull request #21 from WebFiori/dev
feat: Improved Testing Mode
- Loading branch information
Showing
4 changed files
with
262 additions
and
34 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
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 |
---|---|---|
|
@@ -4,8 +4,10 @@ | |
use PHPUnit\Framework\TestCase; | ||
use webfiori\email\Email; | ||
use webfiori\email\exceptions\SMTPException; | ||
use webfiori\email\SendMode; | ||
use webfiori\email\SMTPAccount; | ||
use webfiori\email\SMTPServer; | ||
use webfiori\file\exceptions\FileException; | ||
use webfiori\file\File; | ||
/** | ||
* A test class for testing the class 'webfiori\framework\mail\EmailMessage'. | ||
|
@@ -433,4 +435,110 @@ public function testTemplate03() { | |
. '</html>'.SMTPServer::NL, $message.''); | ||
|
||
} | ||
/** | ||
* @test | ||
*/ | ||
public function testStoreMode00() { | ||
$message = new Email(); | ||
$this->assertEquals(SendMode::PROD, $message->getMode()); | ||
$this->assertTrue($message->setMode(SendMode::TEST_STORE, [ | ||
'store-path' => __DIR__ | ||
])); | ||
$this->assertEquals(SendMode::TEST_STORE, $message->getMode()); | ||
$message->send(); | ||
$this->assertTrue(File::isFileExist(__DIR__.DIRECTORY_SEPARATOR.$message->getSubject().DIRECTORY_SEPARATOR.date('Y-m-d H-i-s').'.html')); | ||
} | ||
/** | ||
* @test | ||
*/ | ||
public function testStoreMode01() { | ||
$this->expectException(FileException::class); | ||
$this->expectExceptionMessage('Store path is not set for mode SendMode::TEST_STORE.'); | ||
$message = new Email(); | ||
$this->assertEquals(SendMode::PROD, $message->getMode()); | ||
$this->assertTrue($message->setMode(SendMode::TEST_STORE, [ | ||
|
||
])); | ||
$this->assertEquals(SendMode::TEST_STORE, $message->getMode()); | ||
$message->send(); | ||
$this->assertTrue(File::isFileExist(__DIR__.DIRECTORY_SEPARATOR.$message->getSubject().DIRECTORY_SEPARATOR.date('Y-m-d H-i-s').'.html')); | ||
} | ||
/** | ||
* @test | ||
*/ | ||
public function testStoreMode02() { | ||
$this->expectException(FileException::class); | ||
$this->expectExceptionMessage('Store path does not exist: \''.__DIR__.DIRECTORY_SEPARATOR.'inv_p\''); | ||
$message = new Email(); | ||
$this->assertEquals(SendMode::PROD, $message->getMode()); | ||
$this->assertTrue($message->setMode(SendMode::TEST_STORE, [ | ||
'store-path' => __DIR__.DIRECTORY_SEPARATOR.'inv_p' | ||
])); | ||
$this->assertEquals(SendMode::TEST_STORE, $message->getMode()); | ||
$message->send(); | ||
} | ||
/** | ||
* @test | ||
*/ | ||
public function testSendMode00() { | ||
$message = new Email(new SMTPAccount($this->acc01)); | ||
$this->assertTrue($message->setMode(SendMode::TEST_SEND, [ | ||
'send-addresses' => [ | ||
'[email protected]' | ||
] | ||
])); | ||
$this->assertEquals(SendMode::TEST_SEND, $message->getMode()); | ||
$message->send(); | ||
$this->assertEquals([ | ||
'command' => 'QUIT', | ||
'code' => 221, | ||
'message' => '221 gator4189.hostgator.com closing connection', | ||
'time' => date('Y-m-d H:i:s'), | ||
], $message->getSMTPServer()->getLastLogEntry()); | ||
$this->assertTrue(true); | ||
} | ||
/** | ||
* @test | ||
*/ | ||
public function testSendMode01() { | ||
$message = new Email(new SMTPAccount($this->acc01)); | ||
$this->assertTrue($message->setMode(SendMode::TEST_SEND, [ | ||
'send-addresses' => '[email protected]' | ||
])); | ||
$this->assertEquals(SendMode::TEST_SEND, $message->getMode()); | ||
$message->send(); | ||
$this->assertEquals([ | ||
'command' => 'QUIT', | ||
'code' => 221, | ||
'message' => '221 gator4189.hostgator.com closing connection', | ||
'time' => date('Y-m-d H:i:s'), | ||
], $message->getSMTPServer()->getLastLogEntry()); | ||
$this->assertTrue(true); | ||
} | ||
/** | ||
* @test | ||
*/ | ||
public function testSendMode02() { | ||
$this->expectException(SMTPException::class); | ||
$this->expectExceptionMessage('Recipients are not set for mode SendMode::TEST_SEND.'); | ||
$message = new Email(new SMTPAccount($this->acc01)); | ||
$this->assertTrue($message->setMode(SendMode::TEST_SEND, [ | ||
|
||
])); | ||
$this->assertEquals(SendMode::TEST_SEND, $message->getMode()); | ||
$message->send(); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
namespace webfiori\email; | ||
|
||
/** | ||
* Class that holds the constants used to set sending mode of an email message | ||
* instance. | ||
* | ||
* @author Ibrahim | ||
*/ | ||
class SendMode { | ||
/** | ||
* The default mode. Used to send the message to its recipients. | ||
*/ | ||
const PROD = 'send'; | ||
/** | ||
* This mode indicates that the message will be sent to a set of specified | ||
* addresses as test including meta-data of the message. Used to mimic actual | ||
* process of sending the message (similar to staging or QA env). | ||
*/ | ||
const TEST_SEND = 'test_send'; | ||
/** | ||
* This mode indicates that the message will be stored as HTML in specific | ||
* path. | ||
*/ | ||
const TEST_STORE = 'store'; | ||
} |