Skip to content

Commit

Permalink
WIP feat: allow custom mailer - adding tests
Browse files Browse the repository at this point in the history
Signed-off-by: Misha M.-Kupriyanov <[email protected]>
  • Loading branch information
printminion-co committed Jun 19, 2024
1 parent 251bbfa commit 4e910db
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/lib/Mail/FakeMailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Test\Mail;

use OCP\Defaults;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use OCP\Mail\IAttachment;
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMessage;
use Psr\Log\LoggerInterface;

/**
* Class FakeMailer
*/
class FakeMailer implements \OCP\Mail\IMailer {

public function __construct(
private IConfig $config,
private LoggerInterface $logger,
private Defaults $defaults,
private IURLGenerator $urlGenerator,
private IL10N $l10n,
private IEventDispatcher $dispatcher,
private IFactory $l10nFactory,
) {
}
public function createMessage(): IMessage {
}

public function createAttachment($data = null, $filename = null, $contentType = null): IAttachment {
}

public function createAttachmentFromPath(string $path, $contentType = null): IAttachment {
}

public function createEMailTemplate(string $emailId, array $data = []): IEMailTemplate {
}

public function send(IMessage $message): array {
}

public function validateMailAddress(string $email): bool {
}
}
20 changes: 20 additions & 0 deletions tests/lib/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,24 @@ public function testOverwriteDefaultCommentsManager() {

$config->setSystemValue('comments.managerFactory', $defaultManagerFactory);
}

public function testOverwriteDefaultMailer() {
$config = $this->server->getConfig();
$config->deleteSystemValue('custom_mailer_class');

$this->assertEquals('not_set', $config->getSystemValue('custom_mailer_class', 'not_set'), "custom_mailer_class is not set");

$serviceName = 'Mailer';
$instanceOf = '\OC\Mail\Mailer';

$this->assertInstanceOf($instanceOf, $this->server->query($serviceName), 'Service "' . $serviceName . '"" did not return the right class');
// $this->assertInstanceOf($instanceOf, $this->server->query($serviceName), 'Service "' . $serviceName . '"" did not return the right class. serviceName=' . $serviceName);

$instanceOf = 'Test\\Mail\\FakeMailer';
$config->setSystemValue('custom_mailer_class', 'Test\\Mail\\FakeMailer');

$this->assertInstanceOf($instanceOf, $this->server->query($serviceName), 'Service "' . $serviceName . '"" did not return the right class');

$config->deleteSystemValue('custom_mailer_class');
}
}

0 comments on commit 4e910db

Please sign in to comment.