Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' => '[email protected]',
'mail_smtpmode' => 'smtp',
Expand Down
Loading