You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.4 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  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 PHPUnit\Framework\MockObject\MockObject;
  13. use Test\TestCase;
  14. class MailTest extends TestCase {
  15. private Mail $admin;
  16. private IConfig&MockObject $config;
  17. private IL10N&MockObject $l10n;
  18. protected function setUp(): void {
  19. parent::setUp();
  20. $this->config = $this->createMock(IConfig::class);
  21. $this->l10n = $this->createMock(IL10N::class);
  22. $this->admin = new Mail(
  23. $this->config,
  24. $this->l10n
  25. );
  26. }
  27. public static function dataGetForm(): array {
  28. return [
  29. [true],
  30. [false],
  31. ];
  32. }
  33. /** @dataProvider dataGetForm */
  34. public function testGetForm(bool $sendmail) {
  35. $finder = $this->createMock(IBinaryFinder::class);
  36. $finder->expects(self::once())
  37. ->method('findBinaryPath')
  38. ->with('sendmail')
  39. ->willReturn($sendmail ? '/usr/bin/sendmail': false);
  40. $this->overwriteService(IBinaryFinder::class, $finder);
  41. $this->config
  42. ->expects($this->any())
  43. ->method('getSystemValue')
  44. ->willReturnMap([
  45. ['mail_domain', '', 'mx.nextcloud.com'],
  46. ['mail_from_address', '', 'no-reply@nextcloud.com'],
  47. ['mail_smtpmode', '', 'smtp'],
  48. ['mail_smtpsecure', '', true],
  49. ['mail_smtphost', '', 'smtp.nextcloud.com'],
  50. ['mail_smtpport', '', 25],
  51. ['mail_smtpauth', false, true],
  52. ['mail_smtpname', '', 'smtp.sender.com'],
  53. ['mail_smtppassword', '', 'mypassword'],
  54. ['mail_sendmailmode', 'smtp', 'smtp'],
  55. ]);
  56. $expected = new TemplateResponse(
  57. 'settings',
  58. 'settings/admin/additional-mail',
  59. [
  60. 'sendmail_is_available' => $sendmail,
  61. 'mail_domain' => 'mx.nextcloud.com',
  62. 'mail_from_address' => 'no-reply@nextcloud.com',
  63. 'mail_smtpmode' => 'smtp',
  64. 'mail_smtpsecure' => true,
  65. 'mail_smtphost' => 'smtp.nextcloud.com',
  66. 'mail_smtpport' => 25,
  67. 'mail_smtpauth' => true,
  68. 'mail_smtpname' => 'smtp.sender.com',
  69. 'mail_smtppassword' => '********',
  70. 'mail_sendmailmode' => 'smtp',
  71. ],
  72. ''
  73. );
  74. $this->assertEquals($expected, $this->admin->getForm());
  75. }
  76. public function testGetSection(): void {
  77. $this->assertSame('server', $this->admin->getSection());
  78. }
  79. public function testGetPriority(): void {
  80. $this->assertSame(10, $this->admin->getPriority());
  81. }
  82. }