Skip to content

Commit

Permalink
test(Mailer): Align tests for mailer with stable30
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
joshtrichards authored and susnux committed Feb 12, 2025
1 parent f2b25a4 commit 8429344
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
5 changes: 3 additions & 2 deletions apps/settings/lib/Settings/Admin/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use OCP\IBinaryFinder;
use OCP\IConfig;
use OCP\IL10N;
use OCP\Server;
use OCP\Settings\IDelegatedSettings;

class Mail implements IDelegatedSettings {
Expand All @@ -27,9 +26,11 @@ public function __construct(
* @return TemplateResponse
*/
public function getForm() {
$finder = \OCP\Server::get(IBinaryFinder::class);

$parameters = [
// Mail
'sendmail_is_available' => (bool)Server::get(IBinaryFinder::class)->findBinaryPath('sendmail'),
'sendmail_is_available' => $finder->findBinaryPath('sendmail') !== false,
'mail_domain' => $this->config->getSystemValue('mail_domain', ''),
'mail_from_address' => $this->config->getSystemValue('mail_from_address', ''),
'mail_smtpmode' => $this->config->getSystemValue('mail_smtpmode', ''),
Expand Down
31 changes: 22 additions & 9 deletions apps/settings/tests/Settings/Admin/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@
use OCP\IBinaryFinder;
use OCP\IConfig;
use OCP\IL10N;
use OCP\Server;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class MailTest extends TestCase {
/** @var Mail */
private $admin;
/** @var IConfig */
private $config;
/** @var IL10N */
private $l10n;

private Mail $admin;
private IConfig&MockObject $config;
private IL10N&MockObject $l10n;

protected function setUp(): void {
parent::setUp();
Expand All @@ -32,7 +30,22 @@ protected function setUp(): void {
);
}

public function testGetForm(): void {
public static function dataGetForm(): array {
return [
[true],
[false],
];
}

/** @dataProvider dataGetForm */
public function testGetForm(bool $sendmail) {
$finder = $this->createMock(IBinaryFinder::class);
$finder->expects(self::once())
->method('findBinaryPath')
->with('sendmail')
->willReturn($sendmail ? '/usr/bin/sendmail': false);
$this->overwriteService(IBinaryFinder::class, $finder);

$this->config
->expects($this->any())
->method('getSystemValue')
Expand All @@ -53,7 +66,7 @@ public function testGetForm(): void {
'settings',
'settings/admin/additional-mail',
[
'sendmail_is_available' => (bool)Server::get(IBinaryFinder::class)->findBinaryPath('sendmail'),
'sendmail_is_available' => $sendmail,
'mail_domain' => 'mx.nextcloud.com',
'mail_from_address' => 'no-reply@nextcloud.com',
'mail_smtpmode' => 'smtp',
Expand Down

0 comments on commit 8429344

Please sign in to comment.