X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Fsrc%2FUtil%2FEMailerTest.php;h=b43482b304fd51a5f8b0ccbc82179eef29a9171c;hb=360614d2cf3aceeb763ef1281ad5236878f5d735;hp=636965ec4e3e7febb290d9437b71bcae8c478f60;hpb=e2b736d0a9b351965cc2310696dbbaeb4f19ebb2;p=friendica.git
diff --git a/tests/src/Util/EMailerTest.php b/tests/src/Util/EMailerTest.php
index 636965ec4e..b43482b304 100644
--- a/tests/src/Util/EMailerTest.php
+++ b/tests/src/Util/EMailerTest.php
@@ -1,11 +1,30 @@
.
+ *
+ */
namespace Friendica\Test\src\Util;
use Friendica\App\BaseURL;
-use Friendica\Core\Config\IConfig;
+use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
-use Friendica\Core\PConfig\IPConfig;
+use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Object\EMail\IEmail;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\EmailerSpy;
@@ -19,46 +38,41 @@ use Psr\Log\NullLogger;
* Annotation necessary because of Hook calls
*
* @runTestsInSeparateProcesses
- * @preserveGlobalState false
+ * @preserveGlobalState disabled
*/
class EMailerTest extends MockedTest
{
use VFSTrait;
use HookMockTrait;
- /** @var IConfig|MockInterface */
+ /** @var IManageConfigValues|MockInterface */
private $config;
- /** @var IPConfig|MockInterface */
+ /** @var IManagePersonalConfigValues|MockInterface */
private $pConfig;
/** @var L10n|MockInterface */
private $l10n;
/** @var BaseURL|MockInterface */
private $baseUrl;
- /** @var string */
- private $defaultHeaders;
-
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
$this->setUpVfsDir();
- $this->config = \Mockery::mock(IConfig::class);
+ $this->config = \Mockery::mock(IManageConfigValues::class);
$this->config->shouldReceive('get')->withArgs(['config', 'sender_email'])->andReturn('test@friendica.local')->once();
$this->config->shouldReceive('get')->withArgs(['config', 'sitename', 'Friendica Social Network'])->andReturn('Friendica Social Network')->once();
$this->config->shouldReceive('get')->withArgs(['system', 'sendmail_params', true])->andReturn(true);
- $this->pConfig = \Mockery::mock(IPConfig::class);
+ $this->pConfig = \Mockery::mock(IManagePersonalConfigValues::class);
$this->l10n = \Mockery::mock(L10n::class);
$this->baseUrl = \Mockery::mock(BaseURL::class);
$this->baseUrl->shouldReceive('getHostname')->andReturn('friendica.local');
$this->baseUrl->shouldReceive('get')->andReturn('http://friendica.local');
-
- $this->defaultHeaders = [];
}
- protected function tearDown()
+ protected function tearDown(): void
{
EmailerSpy::$MAIL_DATA = [];
@@ -74,36 +88,41 @@ class EMailerTest extends MockedTest
$testEmail = $builder
->withRecipient('recipient@friendica.local')
->withMessage('Test Subject', "Test MessageBold", 'Test Text')
- ->withSender('Sender', 'sender@friendica.loca')
+ ->withSender('Sender', 'sender@friendica.local')
->forUser(['uid' => 1])
->addHeader('Message-ID', 'first Id')
->build(true);
$emailer = new EmailerSpy($this->config, $this->pConfig, $this->baseUrl, new NullLogger(), $this->l10n);
- $this->assertTrue($emailer->send($testEmail));
+ self::assertTrue($emailer->send($testEmail));
- $this->assertContains("X-Friendica-Host : friendica.local", EmailerSpy::$MAIL_DATA['headers']);
- $this->assertContains("X-Friendica-Platform : Friendica", EmailerSpy::$MAIL_DATA['headers']);
- $this->assertContains("List-ID : ", EmailerSpy::$MAIL_DATA['headers']);
- $this->assertContains("List-Archive : ", EmailerSpy::$MAIL_DATA['headers']);
- $this->assertContains("Reply-To: Sender ", EmailerSpy::$MAIL_DATA['headers']);
- $this->assertContains("MIME-Version: 1.0", EmailerSpy::$MAIL_DATA['headers']);
+ self::assertStringContainsString("X-Friendica-Host: friendica.local", EmailerSpy::$MAIL_DATA['headers']);
+ self::assertStringContainsString("X-Friendica-Platform: Friendica", EmailerSpy::$MAIL_DATA['headers']);
+ self::assertStringContainsString("List-ID: ", EmailerSpy::$MAIL_DATA['headers']);
+ self::assertStringContainsString("List-Archive: ", EmailerSpy::$MAIL_DATA['headers']);
+ self::assertStringContainsString("Reply-To: Sender ", EmailerSpy::$MAIL_DATA['headers']);
+ self::assertStringContainsString("MIME-Version: 1.0", EmailerSpy::$MAIL_DATA['headers']);
// Base64 "Test Text"
- $this->assertContains(chunk_split(base64_encode('Test Text')), EmailerSpy::$MAIL_DATA['body']);
+ self::assertStringContainsString(chunk_split(base64_encode('Test Text')), EmailerSpy::$MAIL_DATA['body']);
// Base64 "Test MessageBold"
- $this->assertContains(chunk_split(base64_encode("Test MessageBold")), EmailerSpy::$MAIL_DATA['body']);
- $this->assertEquals("Test Subject", EmailerSpy::$MAIL_DATA['subject']);
- $this->assertEquals("recipient@friendica.local", EmailerSpy::$MAIL_DATA['to']);
- $this->assertEquals("-f sender@friendica.local", EmailerSpy::$MAIL_DATA['parameters']);
+ self::assertStringContainsString(chunk_split(base64_encode("Test MessageBold")), EmailerSpy::$MAIL_DATA['body']);
+ self::assertEquals("Test Subject", EmailerSpy::$MAIL_DATA['subject']);
+ self::assertEquals("recipient@friendica.local", EmailerSpy::$MAIL_DATA['to']);
+ self::assertEquals("-f sender@friendica.local", EmailerSpy::$MAIL_DATA['parameters']);
}
- public function testWrongReturnTwoMessageIds()
+ public function testTwoMessageIds()
{
- /** @var IEmail $returnMail */
- $returnMail = null;
+ $this->pConfig->shouldReceive('get')->withArgs(['1', 'system', 'email_textonly'])->andReturn(false)->once();
+
+ /** @var IEmail $preparedEmail */
+ $preparedEmail = null;
+ /** @var IEmail $sentEMail */
+ $sentEMail = null;
- $this->mockHookCallAll('emailer_send_prepare', $returnMail);
+ $this->mockHookCallAll('emailer_send_prepare', $preparedEmail);
+ $this->mockHookCallAll('emailer_send', $sentEMail);
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config, new NullLogger());
@@ -118,10 +137,11 @@ class EMailerTest extends MockedTest
$emailer = new EmailerSpy($this->config, $this->pConfig, $this->baseUrl, new NullLogger(), $this->l10n);
- $this->assertFalse($emailer->send($testEmail));
+ // even in case there are two message ids, send the mail anyway
+ self::assertTrue($emailer->send($testEmail));
// check case sensitive key problem
- $this->assertArrayHasKey('Message-ID', $testEmail->getAdditionalMailHeader());
- $this->assertArrayHasKey('Message-Id', $testEmail->getAdditionalMailHeader());
+ self::assertArrayHasKey('Message-ID', $testEmail->getAdditionalMailHeader());
+ self::assertArrayHasKey('Message-Id', $testEmail->getAdditionalMailHeader());
}
}