fix tests

This commit is contained in:
Dennis Eichhorn 2021-01-01 18:47:54 +01:00
parent 69ff0e0035
commit b6cba39abf
12 changed files with 177 additions and 24 deletions

View File

@ -283,7 +283,7 @@ class Email implements MessageInterface
* @var string
* @since 1.0.0
*/
protected string $charset = CharsetType::ISO_8859_1;
public string $charset = CharsetType::ISO_8859_1;
/**
* Mail message type.

View File

@ -23,6 +23,7 @@ use phpOMS\Config\SettingsInterface;
use phpOMS\Dispatcher\Dispatcher;
use phpOMS\Module\ModuleManager;
use phpOMS\Router\WebRouter;
use phpOMS\System\File\Local\Directory;
/**
* @testdox phpOMS\tests\Application\ApplicationManagerTest: Application manager
@ -74,7 +75,10 @@ class ApplicationManagerTest extends \PHPUnit\Framework\TestCase
*/
public function testInstall() : void
{
self::markTestIncomplete();
self::assertTrue($this->appManager->install(__DIR__ . '/Testapp', __DIR__ . '/Apps/Testapp'));
self::assertTrue(\is_dir(__DIR__ . '/Apps/Testapp'));
self::assertTrue(\is_file(__DIR__ . '/Apps/Testapp/css/styles.css'));
Directory::delete(__DIR__ . '/Apps/Testapp');
}
/**

View File

@ -0,0 +1,3 @@
#test {
color: #000;
}

View File

@ -0,0 +1,20 @@
{
"name": {
"id": 1000100000,
"internal": "ABC",
"external": "ABC"
},
"version": "1.0.0",
"category": "Test",
"requirements": {
"phpOMS": "1.0.0",
"phpOMS-db": "1.0.0"
},
"creator": {
"name": "Orange Management",
"website": "www.spl1nes.com"
},
"description": "The administration module.",
"directory": "Admin",
"dependencies": []
}

View File

@ -165,9 +165,8 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase
$this->cache->set('key2', 'testVal2', 1);
self::assertEquals('testVal2', $this->cache->get('key2', 1));
\sleep(2);
self::assertNull($this->cache->get('key2', 1));
self::assertTrue($this->cache->updateExpire(10000));
self::assertEquals('testVal2', $this->cache->get('key2', 1));
self::assertTrue($this->cache->updateExpire('key2', \time() + 10000));
self::assertEquals('testVal2', $this->cache->get('key2'));
}
/**

View File

@ -166,9 +166,8 @@ class MemCachedTest extends \PHPUnit\Framework\TestCase
$this->cache->set('key2', 'testVal2', 1);
self::assertEquals('testVal2', $this->cache->get('key2', 1));
\sleep(2);
self::assertNull($this->cache->get('key2', 1));
self::assertTrue($this->cache->updateExpire(10000));
self::assertEquals('testVal2', $this->cache->get('key2', 1));
self::assertTrue($this->cache->updateExpire('key2', \time() + 10000));
self::assertEquals('testVal2', $this->cache->get('key2'));
}
/**

View File

@ -162,9 +162,8 @@ class RedisCacheTest extends \PHPUnit\Framework\TestCase
$this->cache->set('key2', 'testVal2', 1);
self::assertEquals('testVal2', $this->cache->get('key2', 1));
\sleep(2);
self::assertNull($this->cache->get('key2', 1));
self::assertTrue($this->cache->updateExpire(10000));
self::assertEquals('testVal2', $this->cache->get('key2', 1));
self::assertTrue($this->cache->updateExpire('key2', \time() + 10000));
self::assertEquals('testVal2', $this->cache->get('key2'));
}
/**

View File

@ -105,15 +105,21 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
);*/
}
public function testMysqlCreateFromSchema() : void
{
Builder::createFromSchema(
\json_decode(
\file_get_contents(__DIR__ . '/Grammar/testSchema.json'), true
)['test_foreign'],
$this->con
)->execute();
Builder::createFromSchema(
\json_decode(
\file_get_contents(__DIR__ . '/Grammar/testSchema.json'), true
)['test'],
$this->con
);
)->execute();
$table = new Builder($this->con);
$tables = $table->selectTables()->execute()->fetchAll(\PDO::FETCH_COLUMN);

View File

@ -17,6 +17,7 @@ namespace phpOMS\tests\Message;
require_once __DIR__ . '/../../Autoloader.php';
use phpOMS\Message\Mail\Email;
use phpOMS\System\CharsetType;
/**
* @testdox phpOMS\tests\Message\MailHandlerTest: Abstract mail handler
@ -25,6 +26,23 @@ use phpOMS\Message\Mail\Email;
*/
class EmailTestTest extends \PHPUnit\Framework\TestCase
{
protected Email $mail;
public function setUp() : void
{
$this->mail = new Email();
}
public function testDefault() : void
{
self::assertEquals(CharsetType::ISO_8859_1, $this->mail->charset);
self::assertEquals('', $this->mail->subject);
self::assertEquals('', $this->mail->body);
self::assertEquals('', $this->mail->bodyAlt);
self::assertFalse($this->mail->hasAttachment());
self::assertFalse($this->mail->hasInlineImage());
}
public function testEmailParsing() : void
{
self::assertEquals(
@ -37,4 +55,26 @@ class EmailTestTest extends \PHPUnit\Framework\TestCase
Email::parseAddresses('Test Name <test@orange-management.org>', false)
);
}
public function testHtml() : void
{
$message = \file_get_contents(__DIR__ . '/files/utf8.html');
$this->mail->charset = CharsetType::UTF_8;
$this->mail->body = '';
$this->mail->bodyAlt = '';
$this->mail->msgHTML($message, __DIR__ . '/files');
//$this->mail->subject = 'msgHTML';
self::assertNotEmpty($this->mail->body);
self::assertNotEmpty($this->mail->bodyAlt);
self::assertTrue(\stripos($this->mail->body, 'cid:') !== false);
}
public function testAttachment() : void
{
self::assertTrue($this->mail->addAttachment(__DIR__ . '/files/logo.png', 'logo'));
self::assertTrue($this->mail->hasAttachment());
self::assertCount(1, $this->mail->getAttachments());
}
}

View File

@ -20,6 +20,7 @@ use phpOMS\Message\Mail\MailHandler;
use phpOMS\Message\Mail\SubmitType;
use phpOMS\Message\Mail\Email;
use phpOMS\Message\Mail\Imap;
use phpOMS\System\CharsetType;
/**
* @testdox phpOMS\tests\Message\MailHandlerTest: Abstract mail handler
@ -28,25 +29,32 @@ use phpOMS\Message\Mail\Imap;
*/
class MailHandlerTest extends \PHPUnit\Framework\TestCase
{
protected MailHandler $handler;
public function setUp() : void
{
$this->handler = new MailHandler();
}
public function testSendTextWithMail() : void
{
if (!\file_exists('/usr/sbin/sendmail') && empty(\ini_get('sendmail_path'))) {
self::markTestSkipped();
}
$mailer = new MailHandler();
$mailer->setMailer(SubmitType::MAIL);
$this->handler->setMailer(SubmitType::MAIL);
$mail = new Email();
$mail->setFrom('info@orange-management.org', 'Dennis Eichhorn');
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
$mail->addCC('test2@orange-management.email', 'Dennis Eichhorn');
$mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn');
$mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn');
$mail->subject = 'testSendTextWithMail';
$mail->body = 'This is some content';
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
self::assertTrue($mailer->send($mail));
self::assertTrue($this->handler->send($mail));
}
public function testSendTextWithSendmail() : void
@ -55,26 +63,78 @@ class MailHandlerTest extends \PHPUnit\Framework\TestCase
self::markTestSkipped();
}
$mailer = new MailHandler();
$mailer->setMailer(SubmitType::SENDMAIL);
$this->handler->setMailer(SubmitType::SENDMAIL);
$mail = new Email();
$mail->setFrom('info@orange-management.org', 'Dennis Eichhorn');
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
$mail->addCC('test2@orange-management.email', 'Dennis Eichhorn');
$mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn');
$mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn');
$mail->subject = 'testSendTextWithSendmail';
$mail->body = 'This is some content';
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
self::assertTrue($mailer->send($mail));
self::assertTrue($this->handler->send($mail));
}
public function testSendHtmlWithMail() : void
{
if (!\file_exists('/usr/sbin/sendmail') && empty(\ini_get('sendmail_path'))) {
self::markTestSkipped();
}
$this->handler->setMailer(SubmitType::MAIL);
$mail = new Email();
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
$mail->addCC('test2@orange-management.email', 'Dennis Eichhorn');
$mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn');
$mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn');
$mail->subject = 'testSendHtmlWithMail';
$message = \file_get_contents(__DIR__ . '/files/utf8.html');
$mail->charset = CharsetType::UTF_8;
$mail->body = '';
$mail->bodyAlt = '';
$mail->msgHTML($message, __DIR__ . '/files');
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
self::assertTrue($this->handler->send($mail));
}
public function testSendHtmlWithSendmail() : void
{
if (!\file_exists('/usr/sbin/sendmail') && empty(\ini_get('sendmail_path'))) {
self::markTestSkipped();
}
$this->handler->setMailer(SubmitType::SENDMAIL);
$mail = new Email();
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
$mail->addCC('test2@orange-management.email', 'Dennis Eichhorn');
$mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn');
$mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn');
$mail->subject = 'testSendHtmlWithSendmail';
$message = \file_get_contents(__DIR__ . '/files/utf8.html');
$mail->charset = CharsetType::UTF_8;
$mail->body = '';
$mail->bodyAlt = '';
$mail->msgHTML($message, __DIR__ . '/files');
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
self::assertTrue($this->handler->send($mail));
}
public function testReceiveMailWithImap() : void
{/*
$mailer = new Imap();
$mailer->connectInbox();
$this->handler = new Imap();
$this->handler->connectInbox();
var_dump($mailer->getBoxes());*/
var_dump($this->handler->getBoxes());*/
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Mailer Test</title>
</head>
<body>
<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
<h1>This is a mailer test.</h1>
<div align="center">
<a href="https://orange-management.org"><img src="logo.png" height="90" width="340" alt="Logo"></a>
</div>
<p>This example uses <strong>HTML</strong> with the UTF-8 unicode charset.</p>
<p>Chinese text: 郵件內容為空</p>
<p>Russian text: Пустое тело сообщения</p>
<p>Armenian text: Հաղորդագրությունը դատարկ է</p>
<p>Czech text: Prázdné tělo zprávy</p>
<p>Emoji: <span style="font-size: 48px">😂 🦄 💥 📤 📧</span></p>
<p>Image data URL (base64)<img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="#"></p>
<p>Image data URL (URL-encoded)<img src="data:image/gif,GIF89a%01%00%01%00%00%00%00%21%F9%04%01%0A%00%01%00%2C%00%00%00%00%01%00%01%00%00%02%02L%01%00%3B" alt="#"></p>
</div>
</body>
</html>