Merge pull request #50779 from nextcloud/chore/mailer-tests

test(Mailer): Align tests for mailer with stable30
pull/50820/head
Ferdinand Thiessen 2025-02-18 17:52:12 +07:00 committed by GitHub
commit 082e85f6da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 11 deletions

@ -9,7 +9,6 @@ use OCP\AppFramework\Http\TemplateResponse;
use OCP\IBinaryFinder;
use OCP\IConfig;
use OCP\IL10N;
use OCP\Server;
use OCP\Settings\IDelegatedSettings;
class Mail implements IDelegatedSettings {
@ -27,9 +26,11 @@ class Mail implements IDelegatedSettings {
* @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', ''),

@ -10,16 +10,14 @@ use OCP\AppFramework\Http\TemplateResponse;
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();
@ -32,7 +30,22 @@ class MailTest extends TestCase {
);
}
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')
@ -53,7 +66,7 @@ class MailTest extends TestCase {
'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',