1
0

MailTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Settings\Admin;
  24. use OC\Settings\Admin\Additional;
  25. use OC\Settings\Admin\Mail;
  26. use OCP\AppFramework\Http\TemplateResponse;
  27. use OCP\IConfig;
  28. use Test\TestCase;
  29. class MailTest extends TestCase {
  30. /** @var Additional */
  31. private $admin;
  32. /** @var IConfig */
  33. private $config;
  34. public function setUp() {
  35. parent::setUp();
  36. $this->config = $this->getMockBuilder(IConfig::class)->getMock();
  37. $this->admin = new Mail(
  38. $this->config
  39. );
  40. }
  41. public function testGetForm() {
  42. $this->config
  43. ->expects($this->at(0))
  44. ->method('getSystemValue')
  45. ->with('mail_domain', '')
  46. ->willReturn('mx.nextcloud.com');
  47. $this->config
  48. ->expects($this->at(1))
  49. ->method('getSystemValue')
  50. ->with('mail_from_address', '')
  51. ->willReturn('no-reply@nextcloud.com');
  52. $this->config
  53. ->expects($this->at(2))
  54. ->method('getSystemValue')
  55. ->with('mail_smtpmode', '')
  56. ->willReturn('smtp');
  57. $this->config
  58. ->expects($this->at(3))
  59. ->method('getSystemValue')
  60. ->with('mail_smtpsecure', '')
  61. ->willReturn(true);
  62. $this->config
  63. ->expects($this->at(4))
  64. ->method('getSystemValue')
  65. ->with('mail_smtphost', '')
  66. ->willReturn('smtp.nextcloud.com');
  67. $this->config
  68. ->expects($this->at(5))
  69. ->method('getSystemValue')
  70. ->with('mail_smtpport', '')
  71. ->willReturn(25);
  72. $this->config
  73. ->expects($this->at(6))
  74. ->method('getSystemValue')
  75. ->with('mail_smtpauthtype', '')
  76. ->willReturn('login');
  77. $this->config
  78. ->expects($this->at(7))
  79. ->method('getSystemValue')
  80. ->with('mail_smtpauth', false)
  81. ->willReturn(true);
  82. $this->config
  83. ->expects($this->at(8))
  84. ->method('getSystemValue')
  85. ->with('mail_smtpname', '')
  86. ->willReturn('smtp.sender.com');
  87. $this->config
  88. ->expects($this->at(9))
  89. ->method('getSystemValue')
  90. ->with('mail_smtppassword', '')
  91. ->willReturn('mypassword');
  92. $this->config
  93. ->expects($this->at(10))
  94. ->method('getSystemValue')
  95. ->with('mail_sendmailmode', 'smtp')
  96. ->willReturn('smtp');
  97. $expected = new TemplateResponse(
  98. 'settings',
  99. 'settings/admin/additional-mail',
  100. [
  101. 'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'),
  102. 'mail_domain' => 'mx.nextcloud.com',
  103. 'mail_from_address' => 'no-reply@nextcloud.com',
  104. 'mail_smtpmode' => 'smtp',
  105. 'mail_smtpsecure' => true,
  106. 'mail_smtphost' => 'smtp.nextcloud.com',
  107. 'mail_smtpport' => 25,
  108. 'mail_smtpauthtype' => 'login',
  109. 'mail_smtpauth' => true,
  110. 'mail_smtpname' => 'smtp.sender.com',
  111. 'mail_smtppassword' => '********',
  112. 'mail_sendmailmode' => 'smtp',
  113. ],
  114. ''
  115. );
  116. $this->assertEquals($expected, $this->admin->getForm());
  117. }
  118. public function testGetSection() {
  119. $this->assertSame('server', $this->admin->getSection());
  120. }
  121. public function testGetPriority() {
  122. $this->assertSame(10, $this->admin->getPriority());
  123. }
  124. }