MailTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Settings\Tests\Settings\Admin;
  7. use OCA\Settings\Settings\Admin\Mail;
  8. use OCP\AppFramework\Http\TemplateResponse;
  9. use OCP\IBinaryFinder;
  10. use OCP\IConfig;
  11. use OCP\IL10N;
  12. use OCP\Server;
  13. use Test\TestCase;
  14. class MailTest extends TestCase {
  15. /** @var Mail */
  16. private $admin;
  17. /** @var IConfig */
  18. private $config;
  19. /** @var IL10N */
  20. private $l10n;
  21. protected function setUp(): void {
  22. parent::setUp();
  23. $this->config = $this->getMockBuilder(IConfig::class)->getMock();
  24. $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
  25. $this->admin = new Mail(
  26. $this->config,
  27. $this->l10n
  28. );
  29. }
  30. public function testGetForm(): void {
  31. $this->config
  32. ->expects($this->any())
  33. ->method('getSystemValue')
  34. ->willReturnMap([
  35. ['mail_domain', '', 'mx.nextcloud.com'],
  36. ['mail_from_address', '', 'no-reply@nextcloud.com'],
  37. ['mail_smtpmode', '', 'smtp'],
  38. ['mail_smtpsecure', '', true],
  39. ['mail_smtphost', '', 'smtp.nextcloud.com'],
  40. ['mail_smtpport', '', 25],
  41. ['mail_smtpauth', false, true],
  42. ['mail_smtpname', '', 'smtp.sender.com'],
  43. ['mail_smtppassword', '', 'mypassword'],
  44. ['mail_sendmailmode', 'smtp', 'smtp'],
  45. ]);
  46. $expected = new TemplateResponse(
  47. 'settings',
  48. 'settings/admin/additional-mail',
  49. [
  50. 'sendmail_is_available' => (bool)Server::get(IBinaryFinder::class)->findBinaryPath('sendmail'),
  51. 'mail_domain' => 'mx.nextcloud.com',
  52. 'mail_from_address' => 'no-reply@nextcloud.com',
  53. 'mail_smtpmode' => 'smtp',
  54. 'mail_smtpsecure' => true,
  55. 'mail_smtphost' => 'smtp.nextcloud.com',
  56. 'mail_smtpport' => 25,
  57. 'mail_smtpauth' => true,
  58. 'mail_smtpname' => 'smtp.sender.com',
  59. 'mail_smtppassword' => '********',
  60. 'mail_sendmailmode' => 'smtp',
  61. ],
  62. ''
  63. );
  64. $this->assertEquals($expected, $this->admin->getForm());
  65. }
  66. public function testGetSection(): void {
  67. $this->assertSame('server', $this->admin->getSection());
  68. }
  69. public function testGetPriority(): void {
  70. $this->assertSame(10, $this->admin->getPriority());
  71. }
  72. }