Skip to content

Commit

Permalink
feat: mail provider backend
Browse files Browse the repository at this point in the history
Signed-off-by: SebastianKrupinski <[email protected]>
  • Loading branch information
SebastianKrupinski committed Aug 30, 2024
1 parent f5d0792 commit 3dddc78
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 4 additions & 2 deletions lib/Provider/MailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use OCA\Mail\Account;
use OCA\Mail\Service\AccountService;
use OCP\IL10N;
use OCP\Mail\Provider\Address as MailAddress;
use OCP\Mail\Provider\IProvider;
use OCP\Mail\Provider\IService;
Expand All @@ -21,7 +22,8 @@ class MailProvider implements IProvider {
public function __construct(
protected ContainerInterface $container,
protected AccountService $accountService,
protected LoggerInterface $logger
protected LoggerInterface $logger,
protected IL10N $l10n
) {
}

Expand All @@ -44,7 +46,7 @@ public function id(): string {
* @return string label/name of this provider (e.g. Plain Old IMAP/SMTP)
*/
public function label(): string {
return 'Mail Application';
return $this->l10n->t('Mail Application');
}

/**
Expand Down
22 changes: 14 additions & 8 deletions tests/Unit/Provider/MailProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,48 @@
use OCA\Mail\Provider\MailProvider;
use OCA\Mail\Provider\MailService;
use OCA\Mail\Service\AccountService;
use OCP\IL10N;
use OCP\Mail\Provider\Address as MailAddress;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

class MailProviderTest extends TestCase {

/** @var ContainerInterfaceMockObject */
/** @var ContainerInterface&MockObject */
private $containerInterface;
/** @var AccountServiceMockObject */
/** @var AccountService&MockObject */
private $accountService;
/** @var LoggerInterface */
private $logger;
/** @var IL10N&MockObject */
private $l10n;

protected function setUp(): void {
parent::setUp();

$this->containerInterface = $this->createMock(ContainerInterface::class);
$this->accountService = $this->createMock(AccountService::class);
$this->logger = new NullLogger();
$this->l10n = $this->createMock(IL10N::class);

}

public function testId(): void {

// construct mail provider
$mailProvider = new MailProvider($this->containerInterface, $this->accountService, $this->logger);
$mailProvider = new MailProvider($this->containerInterface, $this->accountService, $this->logger, $this->l10n);
// test set by constructor
$this->assertEquals('mail-application', $mailProvider->id());

}

public function testLabel(): void {

// define l10n return
$this->l10n->expects(self::once())->method('t')->willReturn('Mail Application');
// construct mail provider
$mailProvider = new MailProvider($this->containerInterface, $this->accountService, $this->logger);
$mailProvider = new MailProvider($this->containerInterface, $this->accountService, $this->logger, $this->l10n);
// test set by constructor
$this->assertEquals('Mail Application', $mailProvider->label());

Expand Down Expand Up @@ -85,7 +91,7 @@ public function testHasServices(): void {
)
);
// construct mail provider
$mailProvider = new MailProvider($this->containerInterface, $this->accountService, $this->logger);
$mailProvider = new MailProvider($this->containerInterface, $this->accountService, $this->logger, $this->l10n);
// test result with no services found
$this->assertFalse($mailProvider->hasServices('user0'));
// test result with services found
Expand Down Expand Up @@ -130,7 +136,7 @@ public function testListServices(): void {
)
);
// construct mail provider
$mailProvider = new MailProvider($this->containerInterface, $this->accountService, $this->logger);
$mailProvider = new MailProvider($this->containerInterface, $this->accountService, $this->logger, $this->l10n);
// test result with no services found
$this->assertEquals([], $mailProvider->listServices('user0'));
// test result with services found
Expand Down Expand Up @@ -175,7 +181,7 @@ public function testFindServiceById(): void {
)
);
// construct mail provider
$mailProvider = new MailProvider($this->containerInterface, $this->accountService, $this->logger);
$mailProvider = new MailProvider($this->containerInterface, $this->accountService, $this->logger, $this->l10n);
// test result with no services found
$this->assertEquals(null, $mailProvider->findServiceById('user0', '100'));
// test result with services found
Expand Down Expand Up @@ -220,7 +226,7 @@ public function testFindServiceByAddress(): void {
)
);
// construct mail provider
$mailProvider = new MailProvider($this->containerInterface, $this->accountService, $this->logger);
$mailProvider = new MailProvider($this->containerInterface, $this->accountService, $this->logger, $this->l10n);
// test result with no services found
$this->assertEquals(null, $mailProvider->findServiceByAddress('user0', '[email protected]'));
// test result with services found
Expand Down

0 comments on commit 3dddc78

Please sign in to comment.