diff --git a/Message/Mail/Email.php b/Message/Mail/Email.php index c89221394..5380d46a7 100644 --- a/Message/Mail/Email.php +++ b/Message/Mail/Email.php @@ -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. diff --git a/tests/Application/ApplicationManagerTest.php b/tests/Application/ApplicationManagerTest.php index bd5bc287c..12df4cc92 100644 --- a/tests/Application/ApplicationManagerTest.php +++ b/tests/Application/ApplicationManagerTest.php @@ -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'); } /** diff --git a/tests/Application/Testapp/Themes/Default/css/styles.css b/tests/Application/Testapp/Themes/Default/css/styles.css new file mode 100644 index 000000000..31aa65cd5 --- /dev/null +++ b/tests/Application/Testapp/Themes/Default/css/styles.css @@ -0,0 +1,3 @@ +#test { + color: #000; +} \ No newline at end of file diff --git a/tests/Application/Testapp/info.json b/tests/Application/Testapp/info.json new file mode 100644 index 000000000..77d3f1aab --- /dev/null +++ b/tests/Application/Testapp/info.json @@ -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": [] +} \ No newline at end of file diff --git a/tests/DataStorage/Cache/Connection/FileCacheTest.php b/tests/DataStorage/Cache/Connection/FileCacheTest.php index 14bac8ccc..851f0fd75 100644 --- a/tests/DataStorage/Cache/Connection/FileCacheTest.php +++ b/tests/DataStorage/Cache/Connection/FileCacheTest.php @@ -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')); } /** diff --git a/tests/DataStorage/Cache/Connection/MemCachedTest.php b/tests/DataStorage/Cache/Connection/MemCachedTest.php index eeee79572..f2b33cfc2 100644 --- a/tests/DataStorage/Cache/Connection/MemCachedTest.php +++ b/tests/DataStorage/Cache/Connection/MemCachedTest.php @@ -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')); } /** diff --git a/tests/DataStorage/Cache/Connection/RedisCacheTest.php b/tests/DataStorage/Cache/Connection/RedisCacheTest.php index 38d45f5ee..7e68cdb06 100644 --- a/tests/DataStorage/Cache/Connection/RedisCacheTest.php +++ b/tests/DataStorage/Cache/Connection/RedisCacheTest.php @@ -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')); } /** diff --git a/tests/DataStorage/Database/Schema/BuilderTest.php b/tests/DataStorage/Database/Schema/BuilderTest.php index c1fbcf5f7..3bcaa79ab 100644 --- a/tests/DataStorage/Database/Schema/BuilderTest.php +++ b/tests/DataStorage/Database/Schema/BuilderTest.php @@ -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); diff --git a/tests/Message/Mail/EmailTest.php b/tests/Message/Mail/EmailTest.php index a2b3410b9..78f0caac9 100644 --- a/tests/Message/Mail/EmailTest.php +++ b/tests/Message/Mail/EmailTest.php @@ -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 ', 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()); + } } diff --git a/tests/Message/Mail/MailHandlerTest.php b/tests/Message/Mail/MailHandlerTest.php index 983215e9c..866ed5c91 100644 --- a/tests/Message/Mail/MailHandlerTest.php +++ b/tests/Message/Mail/MailHandlerTest.php @@ -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());*/ } } diff --git a/tests/Message/Mail/files/logo.png b/tests/Message/Mail/files/logo.png new file mode 100644 index 000000000..27d7f3c71 Binary files /dev/null and b/tests/Message/Mail/files/logo.png differ diff --git a/tests/Message/Mail/files/utf8.html b/tests/Message/Mail/files/utf8.html new file mode 100644 index 000000000..d7ea6fda5 --- /dev/null +++ b/tests/Message/Mail/files/utf8.html @@ -0,0 +1,23 @@ + + + + + Mailer Test + + +
+

This is a mailer test.

+
+ Logo +
+

This example uses HTML with the UTF-8 unicode charset.

+

Chinese text: 郵件內容為空

+

Russian text: Пустое тело сообщения

+

Armenian text: Հաղորդագրությունը դատարկ է

+

Czech text: Prázdné tělo zprávy

+

Emoji: 😂 🦄 💥 📤 📧

+

Image data URL (base64)#

+

Image data URL (URL-encoded)#

+
+ + \ No newline at end of file