NewUserMailHelperTest.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace Tests\Settings\Mailer;
  22. use OC\Mail\EMailTemplate;
  23. use OCP\Mail\IEMailTemplate;
  24. use OC\Mail\Message;
  25. use OC\Settings\Mailer\NewUserMailHelper;
  26. use OCP\AppFramework\Utility\ITimeFactory;
  27. use OCP\Defaults;
  28. use OCP\IConfig;
  29. use OCP\IL10N;
  30. use OCP\IURLGenerator;
  31. use OCP\IUser;
  32. use OCP\Mail\IMailer;
  33. use OCP\Security\ICrypto;
  34. use OCP\Security\ISecureRandom;
  35. use Test\TestCase;
  36. class NewUserMailHelperTest extends TestCase {
  37. /** @var Defaults|\PHPUnit_Framework_MockObject_MockObject */
  38. private $defaults;
  39. /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
  40. private $urlGenerator;
  41. /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
  42. private $l10n;
  43. /** @var IMailer|\PHPUnit_Framework_MockObject_MockObject */
  44. private $mailer;
  45. /** @var ISecureRandom|\PHPUnit_Framework_MockObject_MockObject */
  46. private $secureRandom;
  47. /** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
  48. private $timeFactory;
  49. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  50. private $config;
  51. /** @var ICrypto|\PHPUnit_Framework_MockObject_MockObject */
  52. private $crypto;
  53. /** @var NewUserMailHelper */
  54. private $newUserMailHelper;
  55. public function setUp() {
  56. parent::setUp();
  57. $this->defaults = $this->createMock(Defaults::class);
  58. $this->defaults->method('getLogo')
  59. ->willReturn('myLogo');
  60. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  61. $this->l10n = $this->createMock(IL10N::class);
  62. $this->mailer = $this->createMock(IMailer::class);
  63. $template = new EMailTemplate(
  64. $this->defaults,
  65. $this->urlGenerator,
  66. $this->l10n,
  67. 'test.TestTemplate',
  68. []
  69. );
  70. $this->mailer->method('createEMailTemplate')
  71. ->will($this->returnValue($template));
  72. $this->secureRandom = $this->createMock(ISecureRandom::class);
  73. $this->timeFactory = $this->createMock(ITimeFactory::class);
  74. $this->config = $this->createMock(IConfig::class);
  75. $this->crypto = $this->createMock(ICrypto::class);
  76. $this->l10n->method('t')
  77. ->will($this->returnCallback(function ($text, $parameters = []) {
  78. return vsprintf($text, $parameters);
  79. }));
  80. $this->newUserMailHelper = new NewUserMailHelper(
  81. $this->defaults,
  82. $this->urlGenerator,
  83. $this->l10n,
  84. $this->mailer,
  85. $this->secureRandom,
  86. $this->timeFactory,
  87. $this->config,
  88. $this->crypto,
  89. 'no-reply@nextcloud.com'
  90. );
  91. }
  92. public function testGenerateTemplateWithPasswordResetToken() {
  93. $this->secureRandom
  94. ->expects($this->once())
  95. ->method('generate')
  96. ->with(21,
  97. ISecureRandom::CHAR_DIGITS .
  98. ISecureRandom::CHAR_LOWER .
  99. ISecureRandom::CHAR_UPPER
  100. )
  101. ->willReturn('MySuperLongSecureRandomToken');
  102. $this->timeFactory
  103. ->expects($this->once())
  104. ->method('getTime')
  105. ->willReturn('12345');
  106. /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
  107. $user = $this->createMock(IUser::class);
  108. $user
  109. ->expects($this->at(0))
  110. ->method('getEmailAddress')
  111. ->willReturn('recipient@example.com');
  112. $user
  113. ->expects($this->at(1))
  114. ->method('getEmailAddress')
  115. ->willReturn('recipient@example.com');
  116. $this->config
  117. ->expects($this->at(0))
  118. ->method('getSystemValue')
  119. ->with('secret')
  120. ->willReturn('MyInstanceWideSecret');
  121. $this->crypto
  122. ->expects($this->once())
  123. ->method('encrypt')
  124. ->with('12345:MySuperLongSecureRandomToken', 'recipient@example.comMyInstanceWideSecret')
  125. ->willReturn('TokenCiphertext');
  126. $user
  127. ->expects($this->at(2))
  128. ->method('getUID')
  129. ->willReturn('john');
  130. $this->config
  131. ->expects($this->at(1))
  132. ->method('setUserValue')
  133. ->with('john', 'core', 'lostpassword', 'TokenCiphertext');
  134. $user
  135. ->expects($this->at(3))
  136. ->method('getUID')
  137. ->willReturn('john');
  138. $this->urlGenerator
  139. ->expects($this->at(0))
  140. ->method('linkToRouteAbsolute')
  141. ->with('core.lost.resetform', ['userId' => 'john', 'token' => 'MySuperLongSecureRandomToken'])
  142. ->willReturn('https://example.com/resetPassword/MySuperLongSecureRandomToken');
  143. $user
  144. ->expects($this->at(4))
  145. ->method('getDisplayName')
  146. ->willReturn('john');
  147. $user
  148. ->expects($this->at(5))
  149. ->method('getUID')
  150. ->willReturn('john');
  151. $this->defaults
  152. ->expects($this->any())
  153. ->method('getName')
  154. ->willReturn('TestCloud');
  155. $this->defaults
  156. ->expects($this->any())
  157. ->method('getTextColorPrimary')
  158. ->willReturn('#ffffff');
  159. $expectedHtmlBody = <<<EOF
  160. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  161. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important">
  162. <head>
  163. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  164. <meta name="viewport" content="width=device-width">
  165. <title></title>
  166. <style type="text/css">@media only screen{html{min-height:100%;background:#F5F5F5}}@media only screen and (max-width:610px){table.body img{width:auto;height:auto}table.body center{min-width:0!important}table.body .container{width:95%!important}table.body .columns{height:auto!important;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;padding-left:30px!important;padding-right:30px!important}th.small-12{display:inline-block!important;width:100%!important}table.menu{width:100%!important}table.menu td,table.menu th{width:auto!important;display:inline-block!important}table.menu.vertical td,table.menu.vertical th{display:block!important}table.menu[align=center]{width:auto!important}}</style>
  167. </head>
  168. <body style="-moz-box-sizing:border-box;-ms-text-size-adjust:100%;-webkit-box-sizing:border-box;-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:100%;Margin:0;background:#f3f3f3!important;box-sizing:border-box;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;min-width:100%;padding:0;text-align:left;width:100%!important">
  169. <span class="preheader" style="color:#F5F5F5;display:none!important;font-size:1px;line-height:1px;max-height:0;max-width:0;mso-hide:all!important;opacity:0;overflow:hidden;visibility:hidden">
  170. </span>
  171. <table class="body" style="-webkit-font-smoothing:antialiased;Margin:0;background:#f3f3f3!important;border-collapse:collapse;border-spacing:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;height:100%;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;width:100%">
  172. <tr style="padding:0;text-align:left;vertical-align:top">
  173. <td class="center" align="center" valign="top" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  174. <center data-parsed="" style="min-width:580px;width:100%"><table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#8a8a8a;background-color:;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
  175. <tr style="padding:0;text-align:left;vertical-align:top">
  176. <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word">
  177. <table align="center" class="container" style="Margin:0 auto;background:0 0;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
  178. <tbody>
  179. <tr style="padding:0;text-align:left;vertical-align:top">
  180. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  181. <table class="row collapse" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
  182. <tbody>
  183. <tr style="padding:0;text-align:left;vertical-align:top">
  184. <center data-parsed="" style="min-width:580px;width:100%">
  185. <img class="logo float-center" src="" alt="TestCloud" align="center" style="-ms-interpolation-mode:bicubic;Margin:0 auto;clear:both;display:block;float:none;margin:0 auto;outline:0;text-align:center;text-decoration:none" height="50">
  186. </center>
  187. </tr>
  188. </tbody>
  189. </table>
  190. </td>
  191. </tr>
  192. </tbody>
  193. </table>
  194. </td>
  195. </tr>
  196. </table>
  197. <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
  198. <tbody>
  199. <tr style="padding:0;text-align:left;vertical-align:top">
  200. <td height="80px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:80px;font-weight:400;hyphens:auto;line-height:80px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
  201. </tr>
  202. </tbody>
  203. </table><table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px">
  204. <tbody>
  205. <tr style="padding:0;text-align:left;vertical-align:top">
  206. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  207. <h1 class="text-center" style="Margin:0;Margin-bottom:10px;color:inherit;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:24px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:center;word-wrap:normal">Welcome aboard</h1>
  208. </td>
  209. </tr>
  210. </tbody>
  211. </table>
  212. <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
  213. <tbody>
  214. <tr style="padding:0;text-align:left;vertical-align:top">
  215. <td height="40px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:40px;font-weight:400;hyphens:auto;line-height:40px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
  216. </tr>
  217. </tbody>
  218. </table><table align="center" class="wrapper content float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
  219. <tr style="padding:0;text-align:left;vertical-align:top">
  220. <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  221. <table align="center" class="container has-shadow" style="Margin:0 auto;background:#fefefe;border-collapse:collapse;border-spacing:0;box-shadow:0 1px 2px 0 rgba(0,0,0,.2),0 1px 3px 0 rgba(0,0,0,.1);margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
  222. <tbody>
  223. <tr style="padding:0;text-align:left;vertical-align:top">
  224. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  225. <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  226. <tbody>
  227. <tr style="padding:0;text-align:left;vertical-align:top">
  228. <td height="60px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
  229. </tr>
  230. </tbody>
  231. </table><table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
  232. <tbody>
  233. <tr style="padding:0;text-align:left;vertical-align:top">
  234. <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
  235. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  236. <tr style="padding:0;text-align:left;vertical-align:top">
  237. <th style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
  238. <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:left">Welcome to your TestCloud account, you can add, protect, and share your data.</p>
  239. </th>
  240. <th class="expander" style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
  241. </tr>
  242. </table>
  243. </th>
  244. </tr>
  245. </tbody>
  246. </table><table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
  247. <tbody>
  248. <tr style="padding:0;text-align:left;vertical-align:top">
  249. <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
  250. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  251. <tr style="padding:0;text-align:left;vertical-align:top">
  252. <th style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
  253. <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:left">Your username is: john</p>
  254. </th>
  255. <th class="expander" style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
  256. </tr>
  257. </table>
  258. </th>
  259. </tr>
  260. </tbody>
  261. </table><table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  262. <tbody>
  263. <tr style="padding:0;text-align:left;vertical-align:top">
  264. <td height="50px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:50px;font-weight:400;hyphens:auto;line-height:50px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
  265. </tr>
  266. </tbody>
  267. </table>
  268. <table align="center" class="row btn-group" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
  269. <tbody>
  270. <tr style="padding:0;text-align:left;vertical-align:top">
  271. <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
  272. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  273. <tr style="padding:0;text-align:left;vertical-align:top">
  274. <th style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
  275. <center data-parsed="" style="min-width:490px;width:100%">
  276. <table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;max-height:40px;max-width:200px;padding:0;text-align:center;vertical-align:top;width:auto">
  277. <tr style="padding:0;text-align:left;vertical-align:top">
  278. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  279. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  280. <tr style="padding:0;text-align:left;vertical-align:top">
  281. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:;border:0 solid ;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  282. <a href="https://example.com/resetPassword/MySuperLongSecureRandomToken" style="Margin:0;border:0 solid ;border-radius:2px;color:#ffffff;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Set your password</a>
  283. </td>
  284. </tr>
  285. </table>
  286. </td>
  287. </tr>
  288. </table>
  289. <table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;max-height:40px;max-width:200px;padding:0;text-align:center;vertical-align:top;width:auto">
  290. <tr style="padding:0;text-align:left;vertical-align:top">
  291. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  292. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  293. <tr style="padding:0;text-align:left;vertical-align:top">
  294. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#777;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  295. <a href="https://nextcloud.com/install/#install-clients" style="Margin:0;background-color:#fff;border:0 solid #777;border-radius:2px;color:#6C6C6C!important;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;outline:1px solid #CBCBCB;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">Install Client</a>
  296. </td>
  297. </tr>
  298. </table>
  299. </td>
  300. </tr>
  301. </table>
  302. </center>
  303. </th>
  304. <th class="expander" style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
  305. </tr>
  306. </table>
  307. </th>
  308. </tr>
  309. </tbody>
  310. </table>
  311. </td>
  312. </tr>
  313. </tbody>
  314. </table>
  315. </td>
  316. </tr>
  317. </table><table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
  318. <tbody>
  319. <tr style="padding:0;text-align:left;vertical-align:top">
  320. <td height="60px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
  321. </tr>
  322. </tbody>
  323. </table>
  324. <table align="center" class="wrapper footer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
  325. <tr style="padding:0;text-align:left;vertical-align:top">
  326. <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  327. <center data-parsed="" style="min-width:580px;width:100%">
  328. <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
  329. <tbody>
  330. <tr style="padding:0;text-align:left;vertical-align:top">
  331. <td height="15px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:15px;font-weight:400;hyphens:auto;line-height:15px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
  332. </tr>
  333. </tbody>
  334. </table>
  335. <p class="text-center float-center" align="center" style="Margin:0;Margin-bottom:10px;color:#C8C8C8;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:12px;font-weight:400;line-height:16px;margin:0;margin-bottom:10px;padding:0;text-align:center">TestCloud - <br>This is an automatically sent email, please do not reply.</p>
  336. </center>
  337. </td>
  338. </tr>
  339. </table> </center>
  340. </td>
  341. </tr>
  342. </table>
  343. <!-- prevent Gmail on iOS font size manipulation -->
  344. <div style="display:none;white-space:nowrap;font:15px courier;line-height:0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
  345. </body>
  346. </html>
  347. EOF;
  348. $expectedTextBody = <<<EOF
  349. Welcome aboard
  350. Welcome to your TestCloud account, you can add, protect, and share your data.
  351. Your username is: john
  352. Set your password: https://example.com/resetPassword/MySuperLongSecureRandomToken
  353. Install Client: https://nextcloud.com/install/#install-clients
  354. --
  355. TestCloud -
  356. This is an automatically sent email, please do not reply.
  357. EOF;
  358. $result = $this->newUserMailHelper->generateTemplate($user, true);
  359. $this->assertEquals($expectedHtmlBody, $result->renderHtml());
  360. $this->assertEquals($expectedTextBody, $result->renderText());
  361. $this->assertSame('OC\Mail\EMailTemplate', get_class($result));
  362. }
  363. public function testGenerateTemplateWithoutPasswordResetToken() {
  364. $this->urlGenerator
  365. ->expects($this->at(0))
  366. ->method('getAbsoluteURL')
  367. ->with('/')
  368. ->willReturn('https://example.com/');
  369. /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
  370. $user = $this->createMock(IUser::class);
  371. $user
  372. ->expects($this->at(0))
  373. ->method('getDisplayName')
  374. ->willReturn('John Doe');
  375. $user
  376. ->expects($this->at(1))
  377. ->method('getUID')
  378. ->willReturn('john');
  379. $this->defaults
  380. ->expects($this->any())
  381. ->method('getName')
  382. ->willReturn('TestCloud');
  383. $this->defaults
  384. ->expects($this->any())
  385. ->method('getTextColorPrimary')
  386. ->willReturn('#ffffff');
  387. $expectedHtmlBody = <<<EOF
  388. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  389. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important">
  390. <head>
  391. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  392. <meta name="viewport" content="width=device-width">
  393. <title></title>
  394. <style type="text/css">@media only screen{html{min-height:100%;background:#F5F5F5}}@media only screen and (max-width:610px){table.body img{width:auto;height:auto}table.body center{min-width:0!important}table.body .container{width:95%!important}table.body .columns{height:auto!important;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;padding-left:30px!important;padding-right:30px!important}th.small-12{display:inline-block!important;width:100%!important}table.menu{width:100%!important}table.menu td,table.menu th{width:auto!important;display:inline-block!important}table.menu.vertical td,table.menu.vertical th{display:block!important}table.menu[align=center]{width:auto!important}}</style>
  395. </head>
  396. <body style="-moz-box-sizing:border-box;-ms-text-size-adjust:100%;-webkit-box-sizing:border-box;-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:100%;Margin:0;background:#f3f3f3!important;box-sizing:border-box;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;min-width:100%;padding:0;text-align:left;width:100%!important">
  397. <span class="preheader" style="color:#F5F5F5;display:none!important;font-size:1px;line-height:1px;max-height:0;max-width:0;mso-hide:all!important;opacity:0;overflow:hidden;visibility:hidden">
  398. </span>
  399. <table class="body" style="-webkit-font-smoothing:antialiased;Margin:0;background:#f3f3f3!important;border-collapse:collapse;border-spacing:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;height:100%;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;width:100%">
  400. <tr style="padding:0;text-align:left;vertical-align:top">
  401. <td class="center" align="center" valign="top" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  402. <center data-parsed="" style="min-width:580px;width:100%"><table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#8a8a8a;background-color:;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
  403. <tr style="padding:0;text-align:left;vertical-align:top">
  404. <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word">
  405. <table align="center" class="container" style="Margin:0 auto;background:0 0;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
  406. <tbody>
  407. <tr style="padding:0;text-align:left;vertical-align:top">
  408. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  409. <table class="row collapse" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
  410. <tbody>
  411. <tr style="padding:0;text-align:left;vertical-align:top">
  412. <center data-parsed="" style="min-width:580px;width:100%">
  413. <img class="logo float-center" src="" alt="TestCloud" align="center" style="-ms-interpolation-mode:bicubic;Margin:0 auto;clear:both;display:block;float:none;margin:0 auto;outline:0;text-align:center;text-decoration:none" height="50">
  414. </center>
  415. </tr>
  416. </tbody>
  417. </table>
  418. </td>
  419. </tr>
  420. </tbody>
  421. </table>
  422. </td>
  423. </tr>
  424. </table>
  425. <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
  426. <tbody>
  427. <tr style="padding:0;text-align:left;vertical-align:top">
  428. <td height="80px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:80px;font-weight:400;hyphens:auto;line-height:80px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
  429. </tr>
  430. </tbody>
  431. </table><table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px">
  432. <tbody>
  433. <tr style="padding:0;text-align:left;vertical-align:top">
  434. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  435. <h1 class="text-center" style="Margin:0;Margin-bottom:10px;color:inherit;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:24px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:center;word-wrap:normal">Welcome aboard John Doe</h1>
  436. </td>
  437. </tr>
  438. </tbody>
  439. </table>
  440. <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
  441. <tbody>
  442. <tr style="padding:0;text-align:left;vertical-align:top">
  443. <td height="40px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:40px;font-weight:400;hyphens:auto;line-height:40px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
  444. </tr>
  445. </tbody>
  446. </table><table align="center" class="wrapper content float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
  447. <tr style="padding:0;text-align:left;vertical-align:top">
  448. <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  449. <table align="center" class="container has-shadow" style="Margin:0 auto;background:#fefefe;border-collapse:collapse;border-spacing:0;box-shadow:0 1px 2px 0 rgba(0,0,0,.2),0 1px 3px 0 rgba(0,0,0,.1);margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
  450. <tbody>
  451. <tr style="padding:0;text-align:left;vertical-align:top">
  452. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  453. <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  454. <tbody>
  455. <tr style="padding:0;text-align:left;vertical-align:top">
  456. <td height="60px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
  457. </tr>
  458. </tbody>
  459. </table><table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
  460. <tbody>
  461. <tr style="padding:0;text-align:left;vertical-align:top">
  462. <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
  463. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  464. <tr style="padding:0;text-align:left;vertical-align:top">
  465. <th style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
  466. <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:left">Welcome to your TestCloud account, you can add, protect, and share your data.</p>
  467. </th>
  468. <th class="expander" style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
  469. </tr>
  470. </table>
  471. </th>
  472. </tr>
  473. </tbody>
  474. </table><table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
  475. <tbody>
  476. <tr style="padding:0;text-align:left;vertical-align:top">
  477. <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
  478. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  479. <tr style="padding:0;text-align:left;vertical-align:top">
  480. <th style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
  481. <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:left">Your username is: john</p>
  482. </th>
  483. <th class="expander" style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
  484. </tr>
  485. </table>
  486. </th>
  487. </tr>
  488. </tbody>
  489. </table><table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  490. <tbody>
  491. <tr style="padding:0;text-align:left;vertical-align:top">
  492. <td height="50px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:50px;font-weight:400;hyphens:auto;line-height:50px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
  493. </tr>
  494. </tbody>
  495. </table>
  496. <table align="center" class="row btn-group" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
  497. <tbody>
  498. <tr style="padding:0;text-align:left;vertical-align:top">
  499. <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
  500. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  501. <tr style="padding:0;text-align:left;vertical-align:top">
  502. <th style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
  503. <center data-parsed="" style="min-width:490px;width:100%">
  504. <table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;max-height:40px;max-width:200px;padding:0;text-align:center;vertical-align:top;width:auto">
  505. <tr style="padding:0;text-align:left;vertical-align:top">
  506. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  507. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  508. <tr style="padding:0;text-align:left;vertical-align:top">
  509. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:;border:0 solid ;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  510. <a href="https://example.com/" style="Margin:0;border:0 solid ;border-radius:2px;color:#ffffff;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Go to TestCloud</a>
  511. </td>
  512. </tr>
  513. </table>
  514. </td>
  515. </tr>
  516. </table>
  517. <table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;max-height:40px;max-width:200px;padding:0;text-align:center;vertical-align:top;width:auto">
  518. <tr style="padding:0;text-align:left;vertical-align:top">
  519. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  520. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  521. <tr style="padding:0;text-align:left;vertical-align:top">
  522. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#777;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  523. <a href="https://nextcloud.com/install/#install-clients" style="Margin:0;background-color:#fff;border:0 solid #777;border-radius:2px;color:#6C6C6C!important;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;outline:1px solid #CBCBCB;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">Install Client</a>
  524. </td>
  525. </tr>
  526. </table>
  527. </td>
  528. </tr>
  529. </table>
  530. </center>
  531. </th>
  532. <th class="expander" style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
  533. </tr>
  534. </table>
  535. </th>
  536. </tr>
  537. </tbody>
  538. </table>
  539. </td>
  540. </tr>
  541. </tbody>
  542. </table>
  543. </td>
  544. </tr>
  545. </table><table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
  546. <tbody>
  547. <tr style="padding:0;text-align:left;vertical-align:top">
  548. <td height="60px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
  549. </tr>
  550. </tbody>
  551. </table>
  552. <table align="center" class="wrapper footer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
  553. <tr style="padding:0;text-align:left;vertical-align:top">
  554. <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
  555. <center data-parsed="" style="min-width:580px;width:100%">
  556. <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
  557. <tbody>
  558. <tr style="padding:0;text-align:left;vertical-align:top">
  559. <td height="15px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:15px;font-weight:400;hyphens:auto;line-height:15px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
  560. </tr>
  561. </tbody>
  562. </table>
  563. <p class="text-center float-center" align="center" style="Margin:0;Margin-bottom:10px;color:#C8C8C8;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:12px;font-weight:400;line-height:16px;margin:0;margin-bottom:10px;padding:0;text-align:center">TestCloud - <br>This is an automatically sent email, please do not reply.</p>
  564. </center>
  565. </td>
  566. </tr>
  567. </table> </center>
  568. </td>
  569. </tr>
  570. </table>
  571. <!-- prevent Gmail on iOS font size manipulation -->
  572. <div style="display:none;white-space:nowrap;font:15px courier;line-height:0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
  573. </body>
  574. </html>
  575. EOF;
  576. $expectedTextBody = <<<EOF
  577. Welcome aboard John Doe
  578. Welcome to your TestCloud account, you can add, protect, and share your data.
  579. Your username is: john
  580. Go to TestCloud: https://example.com/
  581. Install Client: https://nextcloud.com/install/#install-clients
  582. --
  583. TestCloud -
  584. This is an automatically sent email, please do not reply.
  585. EOF;
  586. $result = $this->newUserMailHelper->generateTemplate($user, false);
  587. $this->assertEquals($expectedHtmlBody, $result->renderHtml());
  588. $this->assertEquals($expectedTextBody, $result->renderText());
  589. $this->assertSame('OC\Mail\EMailTemplate', get_class($result));
  590. }
  591. public function testSendMail() {
  592. /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
  593. $user = $this->createMock(IUser::class);
  594. $user
  595. ->expects($this->at(0))
  596. ->method('getEMailAddress')
  597. ->willReturn('recipient@example.com');
  598. $user
  599. ->expects($this->at(1))
  600. ->method('getDisplayName')
  601. ->willReturn('John Doe');
  602. /** @var IEMailTemplate|\PHPUnit_Framework_MockObject_MockObject $emailTemplate */
  603. $emailTemplate = $this->createMock(IEMailTemplate::class);
  604. $message = $this->createMock(Message::class);
  605. $message
  606. ->expects($this->at(0))
  607. ->method('setTo')
  608. ->with(['recipient@example.com' => 'John Doe']);
  609. $message
  610. ->expects($this->at(1))
  611. ->method('setFrom')
  612. ->with(['no-reply@nextcloud.com' => 'TestCloud']);
  613. $message
  614. ->expects($this->at(2))
  615. ->method('useTemplate')
  616. ->with($emailTemplate);
  617. $this->defaults
  618. ->expects($this->exactly(1))
  619. ->method('getName')
  620. ->willReturn('TestCloud');
  621. $this->mailer
  622. ->expects($this->once())
  623. ->method('createMessage')
  624. ->willReturn($message);
  625. $this->newUserMailHelper->sendMail($user, $emailTemplate);
  626. }
  627. }