Skip to content

Commit 082e85f

Browse files
authored
Merge pull request #50779 from nextcloud/chore/mailer-tests
test(Mailer): Align tests for mailer with stable30
2 parents 9f108d8 + 8429344 commit 082e85f

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

apps/settings/lib/Settings/Admin/Mail.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use OCP\IBinaryFinder;
1010
use OCP\IConfig;
1111
use OCP\IL10N;
12-
use OCP\Server;
1312
use OCP\Settings\IDelegatedSettings;
1413

1514
class Mail implements IDelegatedSettings {
@@ -27,9 +26,11 @@ public function __construct(
2726
* @return TemplateResponse
2827
*/
2928
public function getForm() {
29+
$finder = \OCP\Server::get(IBinaryFinder::class);
30+
3031
$parameters = [
3132
// Mail
32-
'sendmail_is_available' => (bool)Server::get(IBinaryFinder::class)->findBinaryPath('sendmail'),
33+
'sendmail_is_available' => $finder->findBinaryPath('sendmail') !== false,
3334
'mail_domain' => $this->config->getSystemValue('mail_domain', ''),
3435
'mail_from_address' => $this->config->getSystemValue('mail_from_address', ''),
3536
'mail_smtpmode' => $this->config->getSystemValue('mail_smtpmode', ''),

apps/settings/tests/Settings/Admin/MailTest.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@
1010
use OCP\IBinaryFinder;
1111
use OCP\IConfig;
1212
use OCP\IL10N;
13-
use OCP\Server;
13+
use PHPUnit\Framework\MockObject\MockObject;
1414
use Test\TestCase;
1515

1616
class MailTest extends TestCase {
17-
/** @var Mail */
18-
private $admin;
19-
/** @var IConfig */
20-
private $config;
21-
/** @var IL10N */
22-
private $l10n;
17+
18+
private Mail $admin;
19+
private IConfig&MockObject $config;
20+
private IL10N&MockObject $l10n;
2321

2422
protected function setUp(): void {
2523
parent::setUp();
@@ -32,7 +30,22 @@ protected function setUp(): void {
3230
);
3331
}
3432

35-
public function testGetForm(): void {
33+
public static function dataGetForm(): array {
34+
return [
35+
[true],
36+
[false],
37+
];
38+
}
39+
40+
/** @dataProvider dataGetForm */
41+
public function testGetForm(bool $sendmail) {
42+
$finder = $this->createMock(IBinaryFinder::class);
43+
$finder->expects(self::once())
44+
->method('findBinaryPath')
45+
->with('sendmail')
46+
->willReturn($sendmail ? '/usr/bin/sendmail': false);
47+
$this->overwriteService(IBinaryFinder::class, $finder);
48+
3649
$this->config
3750
->expects($this->any())
3851
->method('getSystemValue')
@@ -53,7 +66,7 @@ public function testGetForm(): void {
5366
'settings',
5467
'settings/admin/additional-mail',
5568
[
56-
'sendmail_is_available' => (bool)Server::get(IBinaryFinder::class)->findBinaryPath('sendmail'),
69+
'sendmail_is_available' => $sendmail,
5770
'mail_domain' => 'mx.nextcloud.com',
5871
'mail_from_address' => '[email protected]',
5972
'mail_smtpmode' => 'smtp',

0 commit comments

Comments
 (0)