Completed
Push — master ( 253a74...a80cf4 )
by
unknown
31:33 queued 14s
created
lib/private/Mail/EMailTemplate.php 2 patches
Indentation   +350 added lines, -350 removed lines patch added patch discarded remove patch
@@ -22,19 +22,19 @@  discard block
 block discarded – undo
22 22
  * @package OC\Mail
23 23
  */
24 24
 class EMailTemplate implements IEMailTemplate {
25
-	protected string $subject = '';
26
-	protected string $htmlBody = '';
27
-	protected string $plainBody = '';
28
-	/** indicated if the header is added */
29
-	protected bool $headerAdded = false;
30
-	/** indicated if the body is already opened */
31
-	protected bool $bodyOpened = false;
32
-	/** indicated if there is a list open in the body */
33
-	protected bool $bodyListOpened = false;
34
-	/** indicated if the footer is added */
35
-	protected bool $footerAdded = false;
36
-
37
-	protected string $head = <<<EOF
25
+    protected string $subject = '';
26
+    protected string $htmlBody = '';
27
+    protected string $plainBody = '';
28
+    /** indicated if the header is added */
29
+    protected bool $headerAdded = false;
30
+    /** indicated if the body is already opened */
31
+    protected bool $bodyOpened = false;
32
+    /** indicated if there is a list open in the body */
33
+    protected bool $bodyListOpened = false;
34
+    /** indicated if the footer is added */
35
+    protected bool $footerAdded = false;
36
+
37
+    protected string $head = <<<EOF
38 38
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
39 39
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#fff!important">
40 40
 <head>
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 				<center data-parsed="" style="min-width:580px;width:100%">
53 53
 EOF;
54 54
 
55
-	protected string $tail = <<<EOF
55
+    protected string $tail = <<<EOF
56 56
 					</center>
57 57
 				</td>
58 58
 			</tr>
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 
65 65
 EOF;
66 66
 
67
-	protected string $header = <<<EOF
67
+    protected string $header = <<<EOF
68 68
 <table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#fff;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%">
69 69
 	<tr style="padding:0;text-align:left;vertical-align:top">
70 70
 		<td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 </table>
98 98
 EOF;
99 99
 
100
-	protected string $heading = <<<EOF
100
+    protected string $heading = <<<EOF
101 101
 <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">
102 102
 	<tbody>
103 103
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 </table>
117 117
 EOF;
118 118
 
119
-	protected string $bodyBegin = <<<EOF
119
+    protected string $bodyBegin = <<<EOF
120 120
 <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%">
121 121
 	<tr style="padding:0;text-align:left;vertical-align:top">
122 122
 		<td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 					<td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
127 127
 EOF;
128 128
 
129
-	protected string $bodyText = <<<EOF
129
+    protected string $bodyText = <<<EOF
130 130
 <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%%">
131 131
 	<tbody>
132 132
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -145,8 +145,8 @@  discard block
 block discarded – undo
145 145
 </table>
146 146
 EOF;
147 147
 
148
-	// note: listBegin (like bodyBegin) is not processed through sprintf, so "%" is not escaped as "%%". (bug #12151)
149
-	protected string $listBegin = <<<EOF
148
+    // note: listBegin (like bodyBegin) is not processed through sprintf, so "%" is not escaped as "%%". (bug #12151)
149
+    protected string $listBegin = <<<EOF
150 150
 <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%">
151 151
 	<tbody>
152 152
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 			<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
155 155
 EOF;
156 156
 
157
-	protected string $listItem = <<<EOF
157
+    protected string $listItem = <<<EOF
158 158
 				<tr style="padding:0;text-align:left;vertical-align:top">
159 159
 					<td style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left;width:15px;">
160 160
 						<p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;padding-left:10px;text-align:left">%s</p>
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 				</tr>
167 167
 EOF;
168 168
 
169
-	protected string $listEnd = <<<EOF
169
+    protected string $listEnd = <<<EOF
170 170
 			</table>
171 171
 		</th>
172 172
 	</tr>
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 </table>
175 175
 EOF;
176 176
 
177
-	protected string $buttonGroup = <<<EOF
177
+    protected string $buttonGroup = <<<EOF
178 178
 <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
179 179
 	<tbody>
180 180
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 </table>
228 228
 EOF;
229 229
 
230
-	protected string $button = <<<EOF
230
+    protected string $button = <<<EOF
231 231
 <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
232 232
 	<tbody>
233 233
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 </table>
268 268
 EOF;
269 269
 
270
-	protected string $bodyEnd = <<<EOF
270
+    protected string $bodyEnd = <<<EOF
271 271
 
272 272
 					</td>
273 273
 				</tr>
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 </table>
279 279
 EOF;
280 280
 
281
-	protected string $footer = <<<EOF
281
+    protected string $footer = <<<EOF
282 282
 <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%%">
283 283
 	<tbody>
284 284
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -304,336 +304,336 @@  discard block
 block discarded – undo
304 304
 </table>
305 305
 EOF;
306 306
 
307
-	public function __construct(
308
-		protected Defaults $themingDefaults,
309
-		protected IURLGenerator $urlGenerator,
310
-		protected IFactory $l10nFactory,
311
-		protected ?int $logoWidth,
312
-		protected ?int $logoHeight,
313
-		protected string $emailId,
314
-		protected array $data,
315
-	) {
316
-		$this->htmlBody .= $this->head;
317
-	}
318
-
319
-	/**
320
-	 * Sets the subject of the email
321
-	 */
322
-	public function setSubject(string $subject): void {
323
-		$this->subject = $subject;
324
-	}
325
-
326
-	/**
327
-	 * Adds a header to the email
328
-	 */
329
-	public function addHeader(): void {
330
-		if ($this->headerAdded) {
331
-			return;
332
-		}
333
-		$this->headerAdded = true;
334
-
335
-		$logoSizeDimensions = '';
336
-		if ($this->logoWidth && $this->logoHeight) {
337
-			// Provide a logo size when we have the dimensions so that it displays nicely in Outlook
338
-			$logoSizeDimensions = ' width="' . $this->logoWidth . '" height="' . $this->logoHeight . '"';
339
-		}
340
-
341
-		$logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false));
342
-		$this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getDefaultColorPrimary(), $logoUrl, $this->themingDefaults->getName(), $logoSizeDimensions]);
343
-	}
344
-
345
-	/**
346
-	 * Adds a heading to the email
347
-	 *
348
-	 * @param string|bool $plainTitle Title that is used in the plain text email
349
-	 *                                if empty the $title is used, if false none will be used
350
-	 */
351
-	public function addHeading(string $title, $plainTitle = ''): void {
352
-		if ($this->footerAdded) {
353
-			return;
354
-		}
355
-		if ($plainTitle === '') {
356
-			$plainTitle = $title;
357
-		}
358
-
359
-		$this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]);
360
-		if ($plainTitle !== false) {
361
-			$this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL;
362
-		}
363
-	}
364
-
365
-	/**
366
-	 * Open the HTML body when it is not already
367
-	 */
368
-	protected function ensureBodyIsOpened(): void {
369
-		if ($this->bodyOpened) {
370
-			return;
371
-		}
372
-
373
-		$this->htmlBody .= $this->bodyBegin;
374
-		$this->bodyOpened = true;
375
-	}
376
-
377
-	/**
378
-	 * Adds a paragraph to the body of the email
379
-	 *
380
-	 * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
381
-	 * @param string|bool $plainText Text that is used in the plain text email
382
-	 *                               if empty the $text is used, if false none will be used
383
-	 */
384
-	public function addBodyText(string $text, $plainText = ''): void {
385
-		if ($this->footerAdded) {
386
-			return;
387
-		}
388
-		if ($plainText === '') {
389
-			$plainText = $text;
390
-			$text = htmlspecialchars($text);
391
-		}
392
-
393
-		$this->ensureBodyListClosed();
394
-		$this->ensureBodyIsOpened();
395
-
396
-		$this->htmlBody .= vsprintf($this->bodyText, [$text]);
397
-		if ($plainText !== false) {
398
-			$this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
399
-		}
400
-	}
401
-
402
-	/**
403
-	 * Adds a list item to the body of the email
404
-	 *
405
-	 * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
406
-	 * @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email
407
-	 * @param string $icon Absolute path, must be 16*16 pixels
408
-	 * @param string|bool $plainText Text that is used in the plain text email
409
-	 *                               if empty or true the $text is used, if false none will be used
410
-	 * @param string|bool $plainMetaInfo Meta info that is used in the plain text email
411
-	 *                                   if empty or true the $metaInfo is used, if false none will be used
412
-	 * @param integer $plainIndent plainIndent If > 0, Indent plainText by this amount.
413
-	 * @since 12.0.0
414
-	 */
415
-	public function addBodyListItem(
416
-		string $text,
417
-		string $metaInfo = '',
418
-		string $icon = '',
419
-		$plainText = '',
420
-		$plainMetaInfo = '',
421
-		$plainIndent = 0,
422
-	): void {
423
-		$this->ensureBodyListOpened();
424
-
425
-		if ($plainText === '' || $plainText === true) {
426
-			$plainText = $text;
427
-			$text = htmlspecialchars($text);
428
-			$text = str_replace("\n", '<br/>', $text); // convert newlines to HTML breaks
429
-		}
430
-		if ($plainMetaInfo === '' || $plainMetaInfo === true) {
431
-			$plainMetaInfo = $metaInfo;
432
-			$metaInfo = htmlspecialchars($metaInfo);
433
-		}
434
-
435
-		$htmlText = $text;
436
-		if ($metaInfo) {
437
-			$htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText;
438
-		}
439
-		if ($icon !== '') {
440
-			$icon = '<img src="' . htmlspecialchars($icon) . '" alt="&bull;">';
441
-		} else {
442
-			$icon = '&bull;';
443
-		}
444
-		$this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]);
445
-		if ($plainText !== false) {
446
-			if ($plainIndent === 0) {
447
-				/*
307
+    public function __construct(
308
+        protected Defaults $themingDefaults,
309
+        protected IURLGenerator $urlGenerator,
310
+        protected IFactory $l10nFactory,
311
+        protected ?int $logoWidth,
312
+        protected ?int $logoHeight,
313
+        protected string $emailId,
314
+        protected array $data,
315
+    ) {
316
+        $this->htmlBody .= $this->head;
317
+    }
318
+
319
+    /**
320
+     * Sets the subject of the email
321
+     */
322
+    public function setSubject(string $subject): void {
323
+        $this->subject = $subject;
324
+    }
325
+
326
+    /**
327
+     * Adds a header to the email
328
+     */
329
+    public function addHeader(): void {
330
+        if ($this->headerAdded) {
331
+            return;
332
+        }
333
+        $this->headerAdded = true;
334
+
335
+        $logoSizeDimensions = '';
336
+        if ($this->logoWidth && $this->logoHeight) {
337
+            // Provide a logo size when we have the dimensions so that it displays nicely in Outlook
338
+            $logoSizeDimensions = ' width="' . $this->logoWidth . '" height="' . $this->logoHeight . '"';
339
+        }
340
+
341
+        $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false));
342
+        $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getDefaultColorPrimary(), $logoUrl, $this->themingDefaults->getName(), $logoSizeDimensions]);
343
+    }
344
+
345
+    /**
346
+     * Adds a heading to the email
347
+     *
348
+     * @param string|bool $plainTitle Title that is used in the plain text email
349
+     *                                if empty the $title is used, if false none will be used
350
+     */
351
+    public function addHeading(string $title, $plainTitle = ''): void {
352
+        if ($this->footerAdded) {
353
+            return;
354
+        }
355
+        if ($plainTitle === '') {
356
+            $plainTitle = $title;
357
+        }
358
+
359
+        $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]);
360
+        if ($plainTitle !== false) {
361
+            $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL;
362
+        }
363
+    }
364
+
365
+    /**
366
+     * Open the HTML body when it is not already
367
+     */
368
+    protected function ensureBodyIsOpened(): void {
369
+        if ($this->bodyOpened) {
370
+            return;
371
+        }
372
+
373
+        $this->htmlBody .= $this->bodyBegin;
374
+        $this->bodyOpened = true;
375
+    }
376
+
377
+    /**
378
+     * Adds a paragraph to the body of the email
379
+     *
380
+     * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
381
+     * @param string|bool $plainText Text that is used in the plain text email
382
+     *                               if empty the $text is used, if false none will be used
383
+     */
384
+    public function addBodyText(string $text, $plainText = ''): void {
385
+        if ($this->footerAdded) {
386
+            return;
387
+        }
388
+        if ($plainText === '') {
389
+            $plainText = $text;
390
+            $text = htmlspecialchars($text);
391
+        }
392
+
393
+        $this->ensureBodyListClosed();
394
+        $this->ensureBodyIsOpened();
395
+
396
+        $this->htmlBody .= vsprintf($this->bodyText, [$text]);
397
+        if ($plainText !== false) {
398
+            $this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
399
+        }
400
+    }
401
+
402
+    /**
403
+     * Adds a list item to the body of the email
404
+     *
405
+     * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
406
+     * @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email
407
+     * @param string $icon Absolute path, must be 16*16 pixels
408
+     * @param string|bool $plainText Text that is used in the plain text email
409
+     *                               if empty or true the $text is used, if false none will be used
410
+     * @param string|bool $plainMetaInfo Meta info that is used in the plain text email
411
+     *                                   if empty or true the $metaInfo is used, if false none will be used
412
+     * @param integer $plainIndent plainIndent If > 0, Indent plainText by this amount.
413
+     * @since 12.0.0
414
+     */
415
+    public function addBodyListItem(
416
+        string $text,
417
+        string $metaInfo = '',
418
+        string $icon = '',
419
+        $plainText = '',
420
+        $plainMetaInfo = '',
421
+        $plainIndent = 0,
422
+    ): void {
423
+        $this->ensureBodyListOpened();
424
+
425
+        if ($plainText === '' || $plainText === true) {
426
+            $plainText = $text;
427
+            $text = htmlspecialchars($text);
428
+            $text = str_replace("\n", '<br/>', $text); // convert newlines to HTML breaks
429
+        }
430
+        if ($plainMetaInfo === '' || $plainMetaInfo === true) {
431
+            $plainMetaInfo = $metaInfo;
432
+            $metaInfo = htmlspecialchars($metaInfo);
433
+        }
434
+
435
+        $htmlText = $text;
436
+        if ($metaInfo) {
437
+            $htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText;
438
+        }
439
+        if ($icon !== '') {
440
+            $icon = '<img src="' . htmlspecialchars($icon) . '" alt="&bull;">';
441
+        } else {
442
+            $icon = '&bull;';
443
+        }
444
+        $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]);
445
+        if ($plainText !== false) {
446
+            if ($plainIndent === 0) {
447
+                /*
448 448
 				 * If plainIndent is not set by caller, this is the old NC17 layout code.
449 449
 				 */
450
-				$this->plainBody .= '  * ' . $plainText;
451
-				if ($plainMetaInfo !== false) {
452
-					$this->plainBody .= ' (' . $plainMetaInfo . ')';
453
-				}
454
-				$this->plainBody .= PHP_EOL;
455
-			} else {
456
-				/*
450
+                $this->plainBody .= '  * ' . $plainText;
451
+                if ($plainMetaInfo !== false) {
452
+                    $this->plainBody .= ' (' . $plainMetaInfo . ')';
453
+                }
454
+                $this->plainBody .= PHP_EOL;
455
+            } else {
456
+                /*
457 457
 				 * Caller can set plainIndent > 0 to format plainText in tabular fashion.
458 458
 				 * with plainMetaInfo in column 1, and plainText in column 2.
459 459
 				 * The plainMetaInfo label is right justified in a field of width
460 460
 				 * "plainIndent". Multilines after the first are indented plainIndent+1
461 461
 				 * (to account for space after label).  Fixes: #12391
462 462
 				 */
463
-				/** @var string $label */
464
-				$label = ($plainMetaInfo !== false)? $plainMetaInfo : '';
465
-				$this->plainBody .= sprintf("%{$plainIndent}s %s\n",
466
-					$label,
467
-					str_replace("\n", "\n" . str_repeat(' ', $plainIndent + 1), $plainText));
468
-			}
469
-		}
470
-	}
471
-
472
-	protected function ensureBodyListOpened(): void {
473
-		if ($this->bodyListOpened) {
474
-			return;
475
-		}
476
-
477
-		$this->ensureBodyIsOpened();
478
-		$this->bodyListOpened = true;
479
-		$this->htmlBody .= $this->listBegin;
480
-	}
481
-
482
-	protected function ensureBodyListClosed(): void {
483
-		if (!$this->bodyListOpened) {
484
-			return;
485
-		}
486
-
487
-		$this->bodyListOpened = false;
488
-		$this->htmlBody .= $this->listEnd;
489
-	}
490
-
491
-	/**
492
-	 * Adds a button group of two buttons to the body of the email
493
-	 *
494
-	 * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email
495
-	 * @param string $urlLeft URL of left button
496
-	 * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email
497
-	 * @param string $urlRight URL of right button
498
-	 * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used
499
-	 * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used
500
-	 */
501
-	public function addBodyButtonGroup(
502
-		string $textLeft,
503
-		string $urlLeft,
504
-		string $textRight,
505
-		string $urlRight,
506
-		string $plainTextLeft = '',
507
-		string $plainTextRight = '',
508
-	): void {
509
-		if ($this->footerAdded) {
510
-			return;
511
-		}
512
-		if ($plainTextLeft === '') {
513
-			$plainTextLeft = $textLeft;
514
-			$textLeft = htmlspecialchars($textLeft);
515
-		}
516
-
517
-		if ($plainTextRight === '') {
518
-			$plainTextRight = $textRight;
519
-			$textRight = htmlspecialchars($textRight);
520
-		}
521
-
522
-		$this->ensureBodyIsOpened();
523
-		$this->ensureBodyListClosed();
524
-
525
-		$color = $this->themingDefaults->getDefaultColorPrimary();
526
-		$textColor = $this->themingDefaults->getDefaultTextColorPrimary();
527
-
528
-		$this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]);
529
-		$this->plainBody .= PHP_EOL . $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
530
-		$this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
531
-	}
532
-
533
-	/**
534
-	 * Adds a button to the body of the email
535
-	 *
536
-	 * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
537
-	 * @param string $url URL of button
538
-	 * @param string|false $plainText Text of button in plain text version
539
-	 *                                if empty the $text is used, if false none will be used
540
-	 *
541
-	 * @since 12.0.0
542
-	 */
543
-	public function addBodyButton(string $text, string $url, $plainText = ''): void {
544
-		if ($this->footerAdded) {
545
-			return;
546
-		}
547
-
548
-		$this->ensureBodyIsOpened();
549
-		$this->ensureBodyListClosed();
550
-
551
-		if ($plainText === '') {
552
-			$plainText = $text;
553
-			$text = htmlspecialchars($text);
554
-		}
555
-
556
-		$color = $this->themingDefaults->getDefaultColorPrimary();
557
-		$textColor = $this->themingDefaults->getDefaultTextColorPrimary();
558
-		$this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]);
559
-
560
-		if ($plainText !== false) {
561
-			$this->plainBody .= $plainText . ': ';
562
-		}
563
-
564
-		$this->plainBody .= $url . PHP_EOL;
565
-	}
566
-
567
-	/**
568
-	 * Close the HTML body when it is open
569
-	 */
570
-	protected function ensureBodyIsClosed(): void {
571
-		if (!$this->bodyOpened) {
572
-			return;
573
-		}
574
-
575
-		$this->ensureBodyListClosed();
576
-
577
-		$this->htmlBody .= $this->bodyEnd;
578
-		$this->bodyOpened = false;
579
-	}
580
-
581
-	/**
582
-	 * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
583
-	 *
584
-	 * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
585
-	 */
586
-	public function addFooter(string $text = '', ?string $lang = null): void {
587
-		if ($text === '') {
588
-			$l10n = $this->l10nFactory->get('lib', $lang);
589
-			$slogan = $this->themingDefaults->getSlogan($lang);
590
-			if ($slogan !== '') {
591
-				$slogan = ' - ' . $slogan;
592
-			}
593
-			$text = $this->themingDefaults->getName() . $slogan . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.');
594
-		}
595
-
596
-		if ($this->footerAdded) {
597
-			return;
598
-		}
599
-		$this->footerAdded = true;
600
-
601
-		$this->ensureBodyIsClosed();
602
-
603
-		$this->htmlBody .= vsprintf($this->footer, [$text]);
604
-		$this->htmlBody .= $this->tail;
605
-		$this->plainBody .= PHP_EOL . '-- ' . PHP_EOL;
606
-		$this->plainBody .= str_replace('<br>', PHP_EOL, $text);
607
-	}
608
-
609
-	/**
610
-	 * Returns the rendered email subject as string
611
-	 */
612
-	public function renderSubject(): string {
613
-		return $this->subject;
614
-	}
615
-
616
-	/**
617
-	 * Returns the rendered HTML email as string
618
-	 */
619
-	public function renderHtml(): string {
620
-		if (!$this->footerAdded) {
621
-			$this->footerAdded = true;
622
-			$this->ensureBodyIsClosed();
623
-			$this->htmlBody .= $this->tail;
624
-		}
625
-		return $this->htmlBody;
626
-	}
627
-
628
-	/**
629
-	 * Returns the rendered plain text email as string
630
-	 */
631
-	public function renderText(): string {
632
-		if (!$this->footerAdded) {
633
-			$this->footerAdded = true;
634
-			$this->ensureBodyIsClosed();
635
-			$this->htmlBody .= $this->tail;
636
-		}
637
-		return $this->plainBody;
638
-	}
463
+                /** @var string $label */
464
+                $label = ($plainMetaInfo !== false)? $plainMetaInfo : '';
465
+                $this->plainBody .= sprintf("%{$plainIndent}s %s\n",
466
+                    $label,
467
+                    str_replace("\n", "\n" . str_repeat(' ', $plainIndent + 1), $plainText));
468
+            }
469
+        }
470
+    }
471
+
472
+    protected function ensureBodyListOpened(): void {
473
+        if ($this->bodyListOpened) {
474
+            return;
475
+        }
476
+
477
+        $this->ensureBodyIsOpened();
478
+        $this->bodyListOpened = true;
479
+        $this->htmlBody .= $this->listBegin;
480
+    }
481
+
482
+    protected function ensureBodyListClosed(): void {
483
+        if (!$this->bodyListOpened) {
484
+            return;
485
+        }
486
+
487
+        $this->bodyListOpened = false;
488
+        $this->htmlBody .= $this->listEnd;
489
+    }
490
+
491
+    /**
492
+     * Adds a button group of two buttons to the body of the email
493
+     *
494
+     * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email
495
+     * @param string $urlLeft URL of left button
496
+     * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email
497
+     * @param string $urlRight URL of right button
498
+     * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used
499
+     * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used
500
+     */
501
+    public function addBodyButtonGroup(
502
+        string $textLeft,
503
+        string $urlLeft,
504
+        string $textRight,
505
+        string $urlRight,
506
+        string $plainTextLeft = '',
507
+        string $plainTextRight = '',
508
+    ): void {
509
+        if ($this->footerAdded) {
510
+            return;
511
+        }
512
+        if ($plainTextLeft === '') {
513
+            $plainTextLeft = $textLeft;
514
+            $textLeft = htmlspecialchars($textLeft);
515
+        }
516
+
517
+        if ($plainTextRight === '') {
518
+            $plainTextRight = $textRight;
519
+            $textRight = htmlspecialchars($textRight);
520
+        }
521
+
522
+        $this->ensureBodyIsOpened();
523
+        $this->ensureBodyListClosed();
524
+
525
+        $color = $this->themingDefaults->getDefaultColorPrimary();
526
+        $textColor = $this->themingDefaults->getDefaultTextColorPrimary();
527
+
528
+        $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]);
529
+        $this->plainBody .= PHP_EOL . $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
530
+        $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
531
+    }
532
+
533
+    /**
534
+     * Adds a button to the body of the email
535
+     *
536
+     * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
537
+     * @param string $url URL of button
538
+     * @param string|false $plainText Text of button in plain text version
539
+     *                                if empty the $text is used, if false none will be used
540
+     *
541
+     * @since 12.0.0
542
+     */
543
+    public function addBodyButton(string $text, string $url, $plainText = ''): void {
544
+        if ($this->footerAdded) {
545
+            return;
546
+        }
547
+
548
+        $this->ensureBodyIsOpened();
549
+        $this->ensureBodyListClosed();
550
+
551
+        if ($plainText === '') {
552
+            $plainText = $text;
553
+            $text = htmlspecialchars($text);
554
+        }
555
+
556
+        $color = $this->themingDefaults->getDefaultColorPrimary();
557
+        $textColor = $this->themingDefaults->getDefaultTextColorPrimary();
558
+        $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]);
559
+
560
+        if ($plainText !== false) {
561
+            $this->plainBody .= $plainText . ': ';
562
+        }
563
+
564
+        $this->plainBody .= $url . PHP_EOL;
565
+    }
566
+
567
+    /**
568
+     * Close the HTML body when it is open
569
+     */
570
+    protected function ensureBodyIsClosed(): void {
571
+        if (!$this->bodyOpened) {
572
+            return;
573
+        }
574
+
575
+        $this->ensureBodyListClosed();
576
+
577
+        $this->htmlBody .= $this->bodyEnd;
578
+        $this->bodyOpened = false;
579
+    }
580
+
581
+    /**
582
+     * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
583
+     *
584
+     * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
585
+     */
586
+    public function addFooter(string $text = '', ?string $lang = null): void {
587
+        if ($text === '') {
588
+            $l10n = $this->l10nFactory->get('lib', $lang);
589
+            $slogan = $this->themingDefaults->getSlogan($lang);
590
+            if ($slogan !== '') {
591
+                $slogan = ' - ' . $slogan;
592
+            }
593
+            $text = $this->themingDefaults->getName() . $slogan . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.');
594
+        }
595
+
596
+        if ($this->footerAdded) {
597
+            return;
598
+        }
599
+        $this->footerAdded = true;
600
+
601
+        $this->ensureBodyIsClosed();
602
+
603
+        $this->htmlBody .= vsprintf($this->footer, [$text]);
604
+        $this->htmlBody .= $this->tail;
605
+        $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL;
606
+        $this->plainBody .= str_replace('<br>', PHP_EOL, $text);
607
+    }
608
+
609
+    /**
610
+     * Returns the rendered email subject as string
611
+     */
612
+    public function renderSubject(): string {
613
+        return $this->subject;
614
+    }
615
+
616
+    /**
617
+     * Returns the rendered HTML email as string
618
+     */
619
+    public function renderHtml(): string {
620
+        if (!$this->footerAdded) {
621
+            $this->footerAdded = true;
622
+            $this->ensureBodyIsClosed();
623
+            $this->htmlBody .= $this->tail;
624
+        }
625
+        return $this->htmlBody;
626
+    }
627
+
628
+    /**
629
+     * Returns the rendered plain text email as string
630
+     */
631
+    public function renderText(): string {
632
+        if (!$this->footerAdded) {
633
+            $this->footerAdded = true;
634
+            $this->ensureBodyIsClosed();
635
+            $this->htmlBody .= $this->tail;
636
+        }
637
+        return $this->plainBody;
638
+    }
639 639
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 		$logoSizeDimensions = '';
336 336
 		if ($this->logoWidth && $this->logoHeight) {
337 337
 			// Provide a logo size when we have the dimensions so that it displays nicely in Outlook
338
-			$logoSizeDimensions = ' width="' . $this->logoWidth . '" height="' . $this->logoHeight . '"';
338
+			$logoSizeDimensions = ' width="'.$this->logoWidth.'" height="'.$this->logoHeight.'"';
339 339
 		}
340 340
 
341 341
 		$logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false));
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 
359 359
 		$this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]);
360 360
 		if ($plainTitle !== false) {
361
-			$this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL;
361
+			$this->plainBody .= $plainTitle.PHP_EOL.PHP_EOL;
362 362
 		}
363 363
 	}
364 364
 
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
 
396 396
 		$this->htmlBody .= vsprintf($this->bodyText, [$text]);
397 397
 		if ($plainText !== false) {
398
-			$this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
398
+			$this->plainBody .= $plainText.PHP_EOL.PHP_EOL;
399 399
 		}
400 400
 	}
401 401
 
@@ -434,10 +434,10 @@  discard block
 block discarded – undo
434 434
 
435 435
 		$htmlText = $text;
436 436
 		if ($metaInfo) {
437
-			$htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText;
437
+			$htmlText = '<em style="color:#777;">'.$metaInfo.'</em><br>'.$htmlText;
438 438
 		}
439 439
 		if ($icon !== '') {
440
-			$icon = '<img src="' . htmlspecialchars($icon) . '" alt="&bull;">';
440
+			$icon = '<img src="'.htmlspecialchars($icon).'" alt="&bull;">';
441 441
 		} else {
442 442
 			$icon = '&bull;';
443 443
 		}
@@ -447,9 +447,9 @@  discard block
 block discarded – undo
447 447
 				/*
448 448
 				 * If plainIndent is not set by caller, this is the old NC17 layout code.
449 449
 				 */
450
-				$this->plainBody .= '  * ' . $plainText;
450
+				$this->plainBody .= '  * '.$plainText;
451 451
 				if ($plainMetaInfo !== false) {
452
-					$this->plainBody .= ' (' . $plainMetaInfo . ')';
452
+					$this->plainBody .= ' ('.$plainMetaInfo.')';
453 453
 				}
454 454
 				$this->plainBody .= PHP_EOL;
455 455
 			} else {
@@ -461,10 +461,10 @@  discard block
 block discarded – undo
461 461
 				 * (to account for space after label).  Fixes: #12391
462 462
 				 */
463 463
 				/** @var string $label */
464
-				$label = ($plainMetaInfo !== false)? $plainMetaInfo : '';
464
+				$label = ($plainMetaInfo !== false) ? $plainMetaInfo : '';
465 465
 				$this->plainBody .= sprintf("%{$plainIndent}s %s\n",
466 466
 					$label,
467
-					str_replace("\n", "\n" . str_repeat(' ', $plainIndent + 1), $plainText));
467
+					str_replace("\n", "\n".str_repeat(' ', $plainIndent + 1), $plainText));
468 468
 			}
469 469
 		}
470 470
 	}
@@ -526,8 +526,8 @@  discard block
 block discarded – undo
526 526
 		$textColor = $this->themingDefaults->getDefaultTextColorPrimary();
527 527
 
528 528
 		$this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]);
529
-		$this->plainBody .= PHP_EOL . $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
530
-		$this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
529
+		$this->plainBody .= PHP_EOL.$plainTextLeft.': '.$urlLeft.PHP_EOL;
530
+		$this->plainBody .= $plainTextRight.': '.$urlRight.PHP_EOL.PHP_EOL;
531 531
 	}
532 532
 
533 533
 	/**
@@ -558,10 +558,10 @@  discard block
 block discarded – undo
558 558
 		$this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]);
559 559
 
560 560
 		if ($plainText !== false) {
561
-			$this->plainBody .= $plainText . ': ';
561
+			$this->plainBody .= $plainText.': ';
562 562
 		}
563 563
 
564
-		$this->plainBody .= $url . PHP_EOL;
564
+		$this->plainBody .= $url.PHP_EOL;
565 565
 	}
566 566
 
567 567
 	/**
@@ -588,9 +588,9 @@  discard block
 block discarded – undo
588 588
 			$l10n = $this->l10nFactory->get('lib', $lang);
589 589
 			$slogan = $this->themingDefaults->getSlogan($lang);
590 590
 			if ($slogan !== '') {
591
-				$slogan = ' - ' . $slogan;
591
+				$slogan = ' - '.$slogan;
592 592
 			}
593
-			$text = $this->themingDefaults->getName() . $slogan . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.');
593
+			$text = $this->themingDefaults->getName().$slogan.'<br>'.$l10n->t('This is an automatically sent email, please do not reply.');
594 594
 		}
595 595
 
596 596
 		if ($this->footerAdded) {
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 
603 603
 		$this->htmlBody .= vsprintf($this->footer, [$text]);
604 604
 		$this->htmlBody .= $this->tail;
605
-		$this->plainBody .= PHP_EOL . '-- ' . PHP_EOL;
605
+		$this->plainBody .= PHP_EOL.'-- '.PHP_EOL;
606 606
 		$this->plainBody .= str_replace('<br>', PHP_EOL, $text);
607 607
 	}
608 608
 
Please login to merge, or discard this patch.
apps/settings/tests/Mailer/NewUserMailHelperTest.php 1 patch
Indentation   +270 added lines, -270 removed lines patch added patch discarded remove patch
@@ -23,138 +23,138 @@  discard block
 block discarded – undo
23 23
 use Test\TestCase;
24 24
 
25 25
 class NewUserMailHelperTest extends TestCase {
26
-	/** @var Defaults|\PHPUnit\Framework\MockObject\MockObject */
27
-	private $defaults;
28
-	/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
29
-	private $urlGenerator;
30
-	/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
31
-	private $l10n;
32
-	/** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
33
-	private $l10nFactory;
34
-	/** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */
35
-	private $mailer;
36
-	/** @var ISecureRandom|\PHPUnit\Framework\MockObject\MockObject */
37
-	private $secureRandom;
38
-	/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
39
-	private $timeFactory;
40
-	/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
41
-	private $config;
42
-	/** @var ICrypto|\PHPUnit\Framework\MockObject\MockObject */
43
-	private $crypto;
44
-	/** @var NewUserMailHelper */
45
-	private $newUserMailHelper;
46
-
47
-	protected function setUp(): void {
48
-		parent::setUp();
49
-
50
-		$this->defaults = $this->createMock(Defaults::class);
51
-		$this->defaults->method('getLogo')
52
-			->willReturn('myLogo');
53
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
54
-		$this->l10n = $this->createMock(IL10N::class);
55
-		$this->l10nFactory = $this->createMock(IFactory::class);
56
-		$this->mailer = $this->createMock(IMailer::class);
57
-		$template = new EMailTemplate(
58
-			$this->defaults,
59
-			$this->urlGenerator,
60
-			$this->l10nFactory,
61
-			null,
62
-			null,
63
-			'test.TestTemplate',
64
-			[]
65
-		);
66
-		$this->mailer->method('createEMailTemplate')
67
-			->willReturn($template);
68
-		$this->secureRandom = $this->createMock(ISecureRandom::class);
69
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
70
-		$this->config = $this->createMock(IConfig::class);
71
-		$this->config
72
-			->expects($this->any())
73
-			->method('getSystemValue')
74
-			->willReturnCallback(function ($arg) {
75
-				switch ($arg) {
76
-					case 'secret':
77
-						return 'MyInstanceWideSecret';
78
-					case 'customclient_desktop':
79
-						return 'https://nextcloud.com/install/#install-clients';
80
-				}
81
-				return '';
82
-			});
83
-		$this->crypto = $this->createMock(ICrypto::class);
84
-		$this->l10n->method('t')
85
-			->willReturnCallback(function ($text, $parameters = []) {
86
-				return vsprintf($text, $parameters);
87
-			});
88
-		$this->l10nFactory->method('get')
89
-			->willReturnCallback(function ($text, $lang) {
90
-				return $this->l10n;
91
-			});
92
-
93
-		$this->newUserMailHelper = new NewUserMailHelper(
94
-			$this->defaults,
95
-			$this->urlGenerator,
96
-			$this->l10nFactory,
97
-			$this->mailer,
98
-			$this->secureRandom,
99
-			$this->timeFactory,
100
-			$this->config,
101
-			$this->crypto,
102
-			'[email protected]'
103
-		);
104
-	}
105
-
106
-	public function testGenerateTemplateWithPasswordResetToken(): void {
107
-		$this->secureRandom
108
-			->expects($this->once())
109
-			->method('generate')
110
-			->with(21, ISecureRandom::CHAR_ALPHANUMERIC)
111
-			->willReturn('MySuperLongSecureRandomToken');
112
-		$this->timeFactory
113
-			->expects($this->once())
114
-			->method('getTime')
115
-			->willReturn(12345);
116
-		/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
117
-		$user = $this->createMock(IUser::class);
118
-		$user
119
-			->expects($this->any())
120
-			->method('getEmailAddress')
121
-			->willReturn('[email protected]');
122
-		$this->crypto
123
-			->expects($this->once())
124
-			->method('encrypt')
125
-			->with('12345:MySuperLongSecureRandomToken', '[email protected]')
126
-			->willReturn('TokenCiphertext');
127
-		$user
128
-			->expects($this->any())
129
-			->method('getUID')
130
-			->willReturn('john');
131
-		$this->config
132
-			->expects($this->once())
133
-			->method('setUserValue')
134
-			->with('john', 'core', 'lostpassword', 'TokenCiphertext');
135
-		$this->urlGenerator
136
-			->expects($this->once())
137
-			->method('linkToRouteAbsolute')
138
-			->with('core.lost.resetform', ['userId' => 'john', 'token' => 'MySuperLongSecureRandomToken'])
139
-			->willReturn('https://example.com/resetPassword/MySuperLongSecureRandomToken');
140
-		$user
141
-			->expects($this->any())
142
-			->method('getDisplayName')
143
-			->willReturn('john');
144
-		$this->defaults
145
-			->expects($this->any())
146
-			->method('getName')
147
-			->willReturn('TestCloud');
148
-		$this->defaults
149
-			->expects($this->atLeastOnce())
150
-			->method('getDefaultColorPrimary')
151
-			->willReturn('#00679e');
152
-		$this->defaults
153
-			->expects($this->atLeastOnce())
154
-			->method('getDefaultTextColorPrimary')
155
-			->willReturn('#ffffff');
156
-
157
-		$expectedHtmlBody = <<<EOF
26
+    /** @var Defaults|\PHPUnit\Framework\MockObject\MockObject */
27
+    private $defaults;
28
+    /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
29
+    private $urlGenerator;
30
+    /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
31
+    private $l10n;
32
+    /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
33
+    private $l10nFactory;
34
+    /** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */
35
+    private $mailer;
36
+    /** @var ISecureRandom|\PHPUnit\Framework\MockObject\MockObject */
37
+    private $secureRandom;
38
+    /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
39
+    private $timeFactory;
40
+    /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
41
+    private $config;
42
+    /** @var ICrypto|\PHPUnit\Framework\MockObject\MockObject */
43
+    private $crypto;
44
+    /** @var NewUserMailHelper */
45
+    private $newUserMailHelper;
46
+
47
+    protected function setUp(): void {
48
+        parent::setUp();
49
+
50
+        $this->defaults = $this->createMock(Defaults::class);
51
+        $this->defaults->method('getLogo')
52
+            ->willReturn('myLogo');
53
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
54
+        $this->l10n = $this->createMock(IL10N::class);
55
+        $this->l10nFactory = $this->createMock(IFactory::class);
56
+        $this->mailer = $this->createMock(IMailer::class);
57
+        $template = new EMailTemplate(
58
+            $this->defaults,
59
+            $this->urlGenerator,
60
+            $this->l10nFactory,
61
+            null,
62
+            null,
63
+            'test.TestTemplate',
64
+            []
65
+        );
66
+        $this->mailer->method('createEMailTemplate')
67
+            ->willReturn($template);
68
+        $this->secureRandom = $this->createMock(ISecureRandom::class);
69
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
70
+        $this->config = $this->createMock(IConfig::class);
71
+        $this->config
72
+            ->expects($this->any())
73
+            ->method('getSystemValue')
74
+            ->willReturnCallback(function ($arg) {
75
+                switch ($arg) {
76
+                    case 'secret':
77
+                        return 'MyInstanceWideSecret';
78
+                    case 'customclient_desktop':
79
+                        return 'https://nextcloud.com/install/#install-clients';
80
+                }
81
+                return '';
82
+            });
83
+        $this->crypto = $this->createMock(ICrypto::class);
84
+        $this->l10n->method('t')
85
+            ->willReturnCallback(function ($text, $parameters = []) {
86
+                return vsprintf($text, $parameters);
87
+            });
88
+        $this->l10nFactory->method('get')
89
+            ->willReturnCallback(function ($text, $lang) {
90
+                return $this->l10n;
91
+            });
92
+
93
+        $this->newUserMailHelper = new NewUserMailHelper(
94
+            $this->defaults,
95
+            $this->urlGenerator,
96
+            $this->l10nFactory,
97
+            $this->mailer,
98
+            $this->secureRandom,
99
+            $this->timeFactory,
100
+            $this->config,
101
+            $this->crypto,
102
+            '[email protected]'
103
+        );
104
+    }
105
+
106
+    public function testGenerateTemplateWithPasswordResetToken(): void {
107
+        $this->secureRandom
108
+            ->expects($this->once())
109
+            ->method('generate')
110
+            ->with(21, ISecureRandom::CHAR_ALPHANUMERIC)
111
+            ->willReturn('MySuperLongSecureRandomToken');
112
+        $this->timeFactory
113
+            ->expects($this->once())
114
+            ->method('getTime')
115
+            ->willReturn(12345);
116
+        /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
117
+        $user = $this->createMock(IUser::class);
118
+        $user
119
+            ->expects($this->any())
120
+            ->method('getEmailAddress')
121
+            ->willReturn('[email protected]');
122
+        $this->crypto
123
+            ->expects($this->once())
124
+            ->method('encrypt')
125
+            ->with('12345:MySuperLongSecureRandomToken', '[email protected]')
126
+            ->willReturn('TokenCiphertext');
127
+        $user
128
+            ->expects($this->any())
129
+            ->method('getUID')
130
+            ->willReturn('john');
131
+        $this->config
132
+            ->expects($this->once())
133
+            ->method('setUserValue')
134
+            ->with('john', 'core', 'lostpassword', 'TokenCiphertext');
135
+        $this->urlGenerator
136
+            ->expects($this->once())
137
+            ->method('linkToRouteAbsolute')
138
+            ->with('core.lost.resetform', ['userId' => 'john', 'token' => 'MySuperLongSecureRandomToken'])
139
+            ->willReturn('https://example.com/resetPassword/MySuperLongSecureRandomToken');
140
+        $user
141
+            ->expects($this->any())
142
+            ->method('getDisplayName')
143
+            ->willReturn('john');
144
+        $this->defaults
145
+            ->expects($this->any())
146
+            ->method('getName')
147
+            ->willReturn('TestCloud');
148
+        $this->defaults
149
+            ->expects($this->atLeastOnce())
150
+            ->method('getDefaultColorPrimary')
151
+            ->willReturn('#00679e');
152
+        $this->defaults
153
+            ->expects($this->atLeastOnce())
154
+            ->method('getDefaultTextColorPrimary')
155
+            ->willReturn('#ffffff');
156
+
157
+        $expectedHtmlBody = <<<EOF
158 158
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
159 159
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#fff!important">
160 160
 <head>
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 </html>
338 338
 
339 339
 EOF;
340
-		$expectedTextBody = <<<EOF
340
+        $expectedTextBody = <<<EOF
341 341
 Welcome aboard
342 342
 
343 343
 Welcome to your TestCloud account, you can add, protect, and share your data.
@@ -350,51 +350,51 @@  discard block
 block discarded – undo
350 350
 
351 351
 
352 352
 EOF;
353
-		$expectedTextBody .= "\n-- \n";
354
-		$expectedTextBody .= <<<EOF
353
+        $expectedTextBody .= "\n-- \n";
354
+        $expectedTextBody .= <<<EOF
355 355
 TestCloud
356 356
 This is an automatically sent email, please do not reply.
357 357
 EOF;
358 358
 
359
-		$result = $this->newUserMailHelper->generateTemplate($user, true);
360
-		$this->assertEquals($expectedHtmlBody, $result->renderHtml());
361
-		$this->assertEquals($expectedTextBody, $result->renderText());
362
-		$this->assertSame('OC\Mail\EMailTemplate', get_class($result));
363
-	}
364
-
365
-	public function testGenerateTemplateWithoutPasswordResetToken(): void {
366
-		$this->urlGenerator
367
-			->expects($this->any())
368
-			->method('getAbsoluteURL')
369
-			->willReturnMap([
370
-				['/','https://example.com/'],
371
-				['myLogo',''],
372
-			]);
373
-
374
-		/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
375
-		$user = $this->createMock(IUser::class);
376
-		$user
377
-			->expects($this->any())
378
-			->method('getDisplayName')
379
-			->willReturn('John Doe');
380
-		$user
381
-			->expects($this->any())
382
-			->method('getUID')
383
-			->willReturn('john');
384
-		$this->defaults
385
-			->expects($this->any())
386
-			->method('getName')
387
-			->willReturn('TestCloud');
388
-		$this->defaults
389
-			->expects($this->atLeastOnce())
390
-			->method('getDefaultColorPrimary')
391
-			->willReturn('#00679e');
392
-		$this->defaults
393
-			->expects($this->atLeastOnce())
394
-			->method('getDefaultTextColorPrimary')
395
-			->willReturn('#ffffff');
396
-
397
-		$expectedHtmlBody = <<<EOF
359
+        $result = $this->newUserMailHelper->generateTemplate($user, true);
360
+        $this->assertEquals($expectedHtmlBody, $result->renderHtml());
361
+        $this->assertEquals($expectedTextBody, $result->renderText());
362
+        $this->assertSame('OC\Mail\EMailTemplate', get_class($result));
363
+    }
364
+
365
+    public function testGenerateTemplateWithoutPasswordResetToken(): void {
366
+        $this->urlGenerator
367
+            ->expects($this->any())
368
+            ->method('getAbsoluteURL')
369
+            ->willReturnMap([
370
+                ['/','https://example.com/'],
371
+                ['myLogo',''],
372
+            ]);
373
+
374
+        /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
375
+        $user = $this->createMock(IUser::class);
376
+        $user
377
+            ->expects($this->any())
378
+            ->method('getDisplayName')
379
+            ->willReturn('John Doe');
380
+        $user
381
+            ->expects($this->any())
382
+            ->method('getUID')
383
+            ->willReturn('john');
384
+        $this->defaults
385
+            ->expects($this->any())
386
+            ->method('getName')
387
+            ->willReturn('TestCloud');
388
+        $this->defaults
389
+            ->expects($this->atLeastOnce())
390
+            ->method('getDefaultColorPrimary')
391
+            ->willReturn('#00679e');
392
+        $this->defaults
393
+            ->expects($this->atLeastOnce())
394
+            ->method('getDefaultTextColorPrimary')
395
+            ->willReturn('#ffffff');
396
+
397
+        $expectedHtmlBody = <<<EOF
398 398
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
399 399
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#fff!important">
400 400
 <head>
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 </html>
578 578
 
579 579
 EOF;
580
-		$expectedTextBody = <<<EOF
580
+        $expectedTextBody = <<<EOF
581 581
 Welcome aboard John Doe
582 582
 
583 583
 Welcome to your TestCloud account, you can add, protect, and share your data.
@@ -590,55 +590,55 @@  discard block
 block discarded – undo
590 590
 
591 591
 
592 592
 EOF;
593
-		$expectedTextBody .= "\n-- \n";
594
-		$expectedTextBody .= <<<EOF
593
+        $expectedTextBody .= "\n-- \n";
594
+        $expectedTextBody .= <<<EOF
595 595
 TestCloud
596 596
 This is an automatically sent email, please do not reply.
597 597
 EOF;
598 598
 
599
-		$result = $this->newUserMailHelper->generateTemplate($user, false);
600
-		$this->assertEquals($expectedHtmlBody, $result->renderHtml());
601
-		$this->assertEquals($expectedTextBody, $result->renderText());
602
-		$this->assertSame('OC\Mail\EMailTemplate', get_class($result));
603
-	}
604
-
605
-	public function testGenerateTemplateWithoutUserId(): void {
606
-		$this->urlGenerator
607
-			->expects($this->any())
608
-			->method('getAbsoluteURL')
609
-			->willReturnMap([
610
-				['/', 'https://example.com/'],
611
-				['myLogo', ''],
612
-			]);
613
-
614
-		/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
615
-		$user = $this->createMock(IUser::class);
616
-		$user
617
-			->expects($this->any())
618
-			->method('getDisplayName')
619
-			->willReturn('John Doe');
620
-		$user
621
-			->expects($this->any())
622
-			->method('getUID')
623
-			->willReturn('john');
624
-		$user
625
-			->expects($this->atLeastOnce())
626
-			->method('getBackendClassName')
627
-			->willReturn('LDAP');
628
-		$this->defaults
629
-			->expects($this->any())
630
-			->method('getName')
631
-			->willReturn('TestCloud');
632
-		$this->defaults
633
-			->expects($this->atLeastOnce())
634
-			->method('getDefaultColorPrimary')
635
-			->willReturn('#00679e');
636
-		$this->defaults
637
-			->expects($this->atLeastOnce())
638
-			->method('getDefaultTextColorPrimary')
639
-			->willReturn('#ffffff');
640
-
641
-		$expectedHtmlBody = <<<EOF
599
+        $result = $this->newUserMailHelper->generateTemplate($user, false);
600
+        $this->assertEquals($expectedHtmlBody, $result->renderHtml());
601
+        $this->assertEquals($expectedTextBody, $result->renderText());
602
+        $this->assertSame('OC\Mail\EMailTemplate', get_class($result));
603
+    }
604
+
605
+    public function testGenerateTemplateWithoutUserId(): void {
606
+        $this->urlGenerator
607
+            ->expects($this->any())
608
+            ->method('getAbsoluteURL')
609
+            ->willReturnMap([
610
+                ['/', 'https://example.com/'],
611
+                ['myLogo', ''],
612
+            ]);
613
+
614
+        /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
615
+        $user = $this->createMock(IUser::class);
616
+        $user
617
+            ->expects($this->any())
618
+            ->method('getDisplayName')
619
+            ->willReturn('John Doe');
620
+        $user
621
+            ->expects($this->any())
622
+            ->method('getUID')
623
+            ->willReturn('john');
624
+        $user
625
+            ->expects($this->atLeastOnce())
626
+            ->method('getBackendClassName')
627
+            ->willReturn('LDAP');
628
+        $this->defaults
629
+            ->expects($this->any())
630
+            ->method('getName')
631
+            ->willReturn('TestCloud');
632
+        $this->defaults
633
+            ->expects($this->atLeastOnce())
634
+            ->method('getDefaultColorPrimary')
635
+            ->willReturn('#00679e');
636
+        $this->defaults
637
+            ->expects($this->atLeastOnce())
638
+            ->method('getDefaultTextColorPrimary')
639
+            ->willReturn('#ffffff');
640
+
641
+        $expectedHtmlBody = <<<EOF
642 642
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
643 643
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#fff!important">
644 644
 <head>
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
 </html>
807 807
 
808 808
 EOF;
809
-		$expectedTextBody = <<<EOF
809
+        $expectedTextBody = <<<EOF
810 810
 Welcome aboard John Doe
811 811
 
812 812
 Welcome to your TestCloud account, you can add, protect, and share your data.
@@ -817,57 +817,57 @@  discard block
 block discarded – undo
817 817
 
818 818
 
819 819
 EOF;
820
-		$expectedTextBody .= "\n-- \n";
821
-		$expectedTextBody .= <<<EOF
820
+        $expectedTextBody .= "\n-- \n";
821
+        $expectedTextBody .= <<<EOF
822 822
 TestCloud
823 823
 This is an automatically sent email, please do not reply.
824 824
 EOF;
825 825
 
826
-		$result = $this->newUserMailHelper->generateTemplate($user, false);
827
-		$this->assertEquals($expectedHtmlBody, $result->renderHtml());
828
-		$this->assertEquals($expectedTextBody, $result->renderText());
829
-		$this->assertSame('OC\Mail\EMailTemplate', get_class($result));
830
-	}
831
-
832
-	public function testSendMail(): void {
833
-		/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
834
-		$user = $this->createMock(IUser::class);
835
-		$user
836
-			->expects($this->once())
837
-			->method('getEMailAddress')
838
-			->willReturn('[email protected]');
839
-		$user
840
-			->expects($this->once())
841
-			->method('getDisplayName')
842
-			->willReturn('John Doe');
843
-		/** @var IEMailTemplate|\PHPUnit\Framework\MockObject\MockObject $emailTemplate */
844
-		$emailTemplate = $this->createMock(IEMailTemplate::class);
845
-		$message = $this->createMock(Message::class);
846
-		$message
847
-			->expects($this->once())
848
-			->method('setTo')
849
-			->with(['[email protected]' => 'John Doe']);
850
-		$message
851
-			->expects($this->once())
852
-			->method('setFrom')
853
-			->with(['[email protected]' => 'TestCloud']);
854
-		$message
855
-			->expects($this->once())
856
-			->method('useTemplate')
857
-			->with($emailTemplate);
858
-		$message
859
-			->expects($this->once())
860
-			->method('setAutoSubmitted')
861
-			->with(AutoSubmitted::VALUE_AUTO_GENERATED);
862
-		$this->defaults
863
-			->expects($this->once())
864
-			->method('getName')
865
-			->willReturn('TestCloud');
866
-		$this->mailer
867
-			->expects($this->once())
868
-			->method('createMessage')
869
-			->willReturn($message);
870
-
871
-		$this->newUserMailHelper->sendMail($user, $emailTemplate);
872
-	}
826
+        $result = $this->newUserMailHelper->generateTemplate($user, false);
827
+        $this->assertEquals($expectedHtmlBody, $result->renderHtml());
828
+        $this->assertEquals($expectedTextBody, $result->renderText());
829
+        $this->assertSame('OC\Mail\EMailTemplate', get_class($result));
830
+    }
831
+
832
+    public function testSendMail(): void {
833
+        /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
834
+        $user = $this->createMock(IUser::class);
835
+        $user
836
+            ->expects($this->once())
837
+            ->method('getEMailAddress')
838
+            ->willReturn('[email protected]');
839
+        $user
840
+            ->expects($this->once())
841
+            ->method('getDisplayName')
842
+            ->willReturn('John Doe');
843
+        /** @var IEMailTemplate|\PHPUnit\Framework\MockObject\MockObject $emailTemplate */
844
+        $emailTemplate = $this->createMock(IEMailTemplate::class);
845
+        $message = $this->createMock(Message::class);
846
+        $message
847
+            ->expects($this->once())
848
+            ->method('setTo')
849
+            ->with(['[email protected]' => 'John Doe']);
850
+        $message
851
+            ->expects($this->once())
852
+            ->method('setFrom')
853
+            ->with(['[email protected]' => 'TestCloud']);
854
+        $message
855
+            ->expects($this->once())
856
+            ->method('useTemplate')
857
+            ->with($emailTemplate);
858
+        $message
859
+            ->expects($this->once())
860
+            ->method('setAutoSubmitted')
861
+            ->with(AutoSubmitted::VALUE_AUTO_GENERATED);
862
+        $this->defaults
863
+            ->expects($this->once())
864
+            ->method('getName')
865
+            ->willReturn('TestCloud');
866
+        $this->mailer
867
+            ->expects($this->once())
868
+            ->method('createMessage')
869
+            ->willReturn($message);
870
+
871
+        $this->newUserMailHelper->sendMail($user, $emailTemplate);
872
+    }
873 873
 }
Please login to merge, or discard this patch.
tests/lib/Mail/EMailTemplateTest.php 1 patch
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -14,207 +14,207 @@
 block discarded – undo
14 14
 use Test\TestCase;
15 15
 
16 16
 class EMailTemplateTest extends TestCase {
17
-	/** @var Defaults|\PHPUnit\Framework\MockObject\MockObject */
18
-	private $defaults;
19
-	/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
20
-	private $urlGenerator;
21
-	/** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
22
-	private $l10n;
23
-	/** @var EMailTemplate */
24
-	private $emailTemplate;
25
-
26
-	protected function setUp(): void {
27
-		parent::setUp();
28
-
29
-		$this->defaults = $this->createMock(Defaults::class);
30
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
31
-		$this->l10n = $this->createMock(IFactory::class);
32
-
33
-		$this->l10n->method('get')
34
-			->with('lib', '')
35
-			->willReturn($this->createMock(IL10N::class));
36
-
37
-		$this->emailTemplate = new EMailTemplate(
38
-			$this->defaults,
39
-			$this->urlGenerator,
40
-			$this->l10n,
41
-			252,
42
-			120,
43
-			'test.TestTemplate',
44
-			[]
45
-		);
46
-	}
47
-
48
-	public function testEMailTemplateCustomFooter(): void {
49
-		$this->defaults
50
-			->expects($this->atLeastOnce())
51
-			->method('getDefaultColorPrimary')
52
-			->willReturn('#0082c9');
53
-		$this->defaults
54
-			->expects($this->any())
55
-			->method('getLogo')
56
-			->willReturn('/img/logo-mail-header.png');
57
-		$this->defaults
58
-			->expects($this->any())
59
-			->method('getName')
60
-			->willReturn('TestCloud');
61
-		$this->defaults
62
-			->expects($this->atLeastOnce())
63
-			->method('getDefaultTextColorPrimary')
64
-			->willReturn('#ffffff');
65
-		$this->urlGenerator
66
-			->expects($this->once())
67
-			->method('getAbsoluteURL')
68
-			->with('/img/logo-mail-header.png')
69
-			->willReturn('https://example.org/img/logo-mail-header.png');
70
-
71
-		$this->emailTemplate->addHeader();
72
-		$this->emailTemplate->addHeading('Welcome aboard');
73
-		$this->emailTemplate->addBodyText('Welcome to your Nextcloud account, you can add, protect, and share your data.');
74
-		$this->emailTemplate->addBodyText('Your username is: abc');
75
-		$this->emailTemplate->addBodyButtonGroup(
76
-			'Set your password', 'https://example.org/resetPassword/123',
77
-			'Install Client', 'https://nextcloud.com/install/#install-clients'
78
-		);
79
-		$this->emailTemplate->addFooter(
80
-			'TestCloud - A safe home for your data<br>This is an automatically sent email, please do not reply.'
81
-		);
82
-
83
-		$expectedHTML = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email.html');
84
-		$this->assertSame($expectedHTML, $this->emailTemplate->renderHtml());
85
-		$expectedTXT = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email.txt');
86
-		$this->assertSame($expectedTXT, $this->emailTemplate->renderText());
87
-	}
88
-
89
-	public function testEMailTemplateDefaultFooter(): void {
90
-		$this->defaults
91
-			->expects($this->atLeastOnce())
92
-			->method('getDefaultColorPrimary')
93
-			->willReturn('#0082c9');
94
-		$this->defaults
95
-			->expects($this->any())
96
-			->method('getName')
97
-			->willReturn('TestCloud');
98
-		$this->defaults
99
-			->expects($this->any())
100
-			->method('getSlogan')
101
-			->willReturn('A safe home for your data');
102
-		$this->defaults
103
-			->expects($this->any())
104
-			->method('getLogo')
105
-			->willReturn('/img/logo-mail-header.png');
106
-		$this->defaults
107
-			->expects($this->atLeastOnce())
108
-			->method('getDefaultTextColorPrimary')
109
-			->willReturn('#ffffff');
110
-		$this->urlGenerator
111
-			->expects($this->once())
112
-			->method('getAbsoluteURL')
113
-			->with('/img/logo-mail-header.png')
114
-			->willReturn('https://example.org/img/logo-mail-header.png');
115
-
116
-		$this->emailTemplate->addHeader();
117
-		$this->emailTemplate->addHeading('Welcome aboard');
118
-		$this->emailTemplate->addBodyText('Welcome to your Nextcloud account, you can add, protect, and share your data.');
119
-		$this->emailTemplate->addBodyText('Your username is: abc');
120
-		$this->emailTemplate->addBodyButtonGroup(
121
-			'Set your password', 'https://example.org/resetPassword/123',
122
-			'Install Client', 'https://nextcloud.com/install/#install-clients'
123
-		);
124
-		$this->emailTemplate->addFooter();
125
-
126
-		$expectedHTML = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-custom.html');
127
-		$this->assertSame($expectedHTML, $this->emailTemplate->renderHtml());
128
-		$expectedTXT = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-custom.txt');
129
-		$this->assertSame($expectedTXT, $this->emailTemplate->renderText());
130
-	}
131
-
132
-	public function testEMailTemplateSingleButton(): void {
133
-		$this->defaults
134
-			->expects($this->atLeastOnce())
135
-			->method('getDefaultColorPrimary')
136
-			->willReturn('#0082c9');
137
-		$this->defaults
138
-			->expects($this->any())
139
-			->method('getName')
140
-			->willReturn('TestCloud');
141
-		$this->defaults
142
-			->expects($this->any())
143
-			->method('getSlogan')
144
-			->willReturn('A safe home for your data');
145
-		$this->defaults
146
-			->expects($this->any())
147
-			->method('getLogo')
148
-			->willReturn('/img/logo-mail-header.png');
149
-		$this->defaults
150
-			->expects($this->atLeastOnce())
151
-			->method('getDefaultTextColorPrimary')
152
-			->willReturn('#ffffff');
153
-		$this->urlGenerator
154
-			->expects($this->once())
155
-			->method('getAbsoluteURL')
156
-			->with('/img/logo-mail-header.png')
157
-			->willReturn('https://example.org/img/logo-mail-header.png');
158
-
159
-		$this->emailTemplate->addHeader();
160
-		$this->emailTemplate->addHeading('Welcome aboard');
161
-		$this->emailTemplate->addBodyText('Welcome to your Nextcloud account, you can add, protect, and share your data.');
162
-		$this->emailTemplate->addBodyText('Your username is: abc');
163
-		$this->emailTemplate->addBodyButton(
164
-			'Set your password', 'https://example.org/resetPassword/123',
165
-			false
166
-		);
167
-		$this->emailTemplate->addFooter();
168
-
169
-		$expectedHTML = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-single-button.html');
170
-		$this->assertSame($expectedHTML, $this->emailTemplate->renderHtml());
171
-		$expectedTXT = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-single-button.txt');
172
-		$this->assertSame($expectedTXT, $this->emailTemplate->renderText());
173
-	}
174
-
175
-
176
-
177
-	public function testEMailTemplateAlternativePlainTexts(): void {
178
-		$this->defaults
179
-			->expects($this->atLeastOnce())
180
-			->method('getDefaultColorPrimary')
181
-			->willReturn('#0082c9');
182
-		$this->defaults
183
-			->expects($this->any())
184
-			->method('getName')
185
-			->willReturn('TestCloud');
186
-		$this->defaults
187
-			->expects($this->any())
188
-			->method('getSlogan')
189
-			->willReturn('A safe home for your data');
190
-		$this->defaults
191
-			->expects($this->any())
192
-			->method('getLogo')
193
-			->willReturn('/img/logo-mail-header.png');
194
-		$this->defaults
195
-			->expects($this->atLeastOnce())
196
-			->method('getDefaultTextColorPrimary')
197
-			->willReturn('#ffffff');
198
-		$this->urlGenerator
199
-			->expects($this->once())
200
-			->method('getAbsoluteURL')
201
-			->with('/img/logo-mail-header.png')
202
-			->willReturn('https://example.org/img/logo-mail-header.png');
203
-
204
-		$this->emailTemplate->addHeader();
205
-		$this->emailTemplate->addHeading('Welcome aboard', 'Welcome aboard - text');
206
-		$this->emailTemplate->addBodyText('Welcome to your Nextcloud account, you can add, protect, and share your data.', 'Welcome to your Nextcloud account, you can add, protect, and share your data. - text');
207
-		$this->emailTemplate->addBodyText('Your username is: abc');
208
-		$this->emailTemplate->addBodyButtonGroup(
209
-			'Set your password', 'https://example.org/resetPassword/123',
210
-			'Install Client', 'https://nextcloud.com/install/#install-clients',
211
-			'Set your password - text', 'Install Client - text'
212
-		);
213
-		$this->emailTemplate->addFooter();
214
-
215
-		$expectedHTML = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-custom.html');
216
-		$this->assertSame($expectedHTML, $this->emailTemplate->renderHtml());
217
-		$expectedTXT = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-custom-text-alternative.txt');
218
-		$this->assertSame($expectedTXT, $this->emailTemplate->renderText());
219
-	}
17
+    /** @var Defaults|\PHPUnit\Framework\MockObject\MockObject */
18
+    private $defaults;
19
+    /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
20
+    private $urlGenerator;
21
+    /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
22
+    private $l10n;
23
+    /** @var EMailTemplate */
24
+    private $emailTemplate;
25
+
26
+    protected function setUp(): void {
27
+        parent::setUp();
28
+
29
+        $this->defaults = $this->createMock(Defaults::class);
30
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
31
+        $this->l10n = $this->createMock(IFactory::class);
32
+
33
+        $this->l10n->method('get')
34
+            ->with('lib', '')
35
+            ->willReturn($this->createMock(IL10N::class));
36
+
37
+        $this->emailTemplate = new EMailTemplate(
38
+            $this->defaults,
39
+            $this->urlGenerator,
40
+            $this->l10n,
41
+            252,
42
+            120,
43
+            'test.TestTemplate',
44
+            []
45
+        );
46
+    }
47
+
48
+    public function testEMailTemplateCustomFooter(): void {
49
+        $this->defaults
50
+            ->expects($this->atLeastOnce())
51
+            ->method('getDefaultColorPrimary')
52
+            ->willReturn('#0082c9');
53
+        $this->defaults
54
+            ->expects($this->any())
55
+            ->method('getLogo')
56
+            ->willReturn('/img/logo-mail-header.png');
57
+        $this->defaults
58
+            ->expects($this->any())
59
+            ->method('getName')
60
+            ->willReturn('TestCloud');
61
+        $this->defaults
62
+            ->expects($this->atLeastOnce())
63
+            ->method('getDefaultTextColorPrimary')
64
+            ->willReturn('#ffffff');
65
+        $this->urlGenerator
66
+            ->expects($this->once())
67
+            ->method('getAbsoluteURL')
68
+            ->with('/img/logo-mail-header.png')
69
+            ->willReturn('https://example.org/img/logo-mail-header.png');
70
+
71
+        $this->emailTemplate->addHeader();
72
+        $this->emailTemplate->addHeading('Welcome aboard');
73
+        $this->emailTemplate->addBodyText('Welcome to your Nextcloud account, you can add, protect, and share your data.');
74
+        $this->emailTemplate->addBodyText('Your username is: abc');
75
+        $this->emailTemplate->addBodyButtonGroup(
76
+            'Set your password', 'https://example.org/resetPassword/123',
77
+            'Install Client', 'https://nextcloud.com/install/#install-clients'
78
+        );
79
+        $this->emailTemplate->addFooter(
80
+            'TestCloud - A safe home for your data<br>This is an automatically sent email, please do not reply.'
81
+        );
82
+
83
+        $expectedHTML = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email.html');
84
+        $this->assertSame($expectedHTML, $this->emailTemplate->renderHtml());
85
+        $expectedTXT = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email.txt');
86
+        $this->assertSame($expectedTXT, $this->emailTemplate->renderText());
87
+    }
88
+
89
+    public function testEMailTemplateDefaultFooter(): void {
90
+        $this->defaults
91
+            ->expects($this->atLeastOnce())
92
+            ->method('getDefaultColorPrimary')
93
+            ->willReturn('#0082c9');
94
+        $this->defaults
95
+            ->expects($this->any())
96
+            ->method('getName')
97
+            ->willReturn('TestCloud');
98
+        $this->defaults
99
+            ->expects($this->any())
100
+            ->method('getSlogan')
101
+            ->willReturn('A safe home for your data');
102
+        $this->defaults
103
+            ->expects($this->any())
104
+            ->method('getLogo')
105
+            ->willReturn('/img/logo-mail-header.png');
106
+        $this->defaults
107
+            ->expects($this->atLeastOnce())
108
+            ->method('getDefaultTextColorPrimary')
109
+            ->willReturn('#ffffff');
110
+        $this->urlGenerator
111
+            ->expects($this->once())
112
+            ->method('getAbsoluteURL')
113
+            ->with('/img/logo-mail-header.png')
114
+            ->willReturn('https://example.org/img/logo-mail-header.png');
115
+
116
+        $this->emailTemplate->addHeader();
117
+        $this->emailTemplate->addHeading('Welcome aboard');
118
+        $this->emailTemplate->addBodyText('Welcome to your Nextcloud account, you can add, protect, and share your data.');
119
+        $this->emailTemplate->addBodyText('Your username is: abc');
120
+        $this->emailTemplate->addBodyButtonGroup(
121
+            'Set your password', 'https://example.org/resetPassword/123',
122
+            'Install Client', 'https://nextcloud.com/install/#install-clients'
123
+        );
124
+        $this->emailTemplate->addFooter();
125
+
126
+        $expectedHTML = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-custom.html');
127
+        $this->assertSame($expectedHTML, $this->emailTemplate->renderHtml());
128
+        $expectedTXT = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-custom.txt');
129
+        $this->assertSame($expectedTXT, $this->emailTemplate->renderText());
130
+    }
131
+
132
+    public function testEMailTemplateSingleButton(): void {
133
+        $this->defaults
134
+            ->expects($this->atLeastOnce())
135
+            ->method('getDefaultColorPrimary')
136
+            ->willReturn('#0082c9');
137
+        $this->defaults
138
+            ->expects($this->any())
139
+            ->method('getName')
140
+            ->willReturn('TestCloud');
141
+        $this->defaults
142
+            ->expects($this->any())
143
+            ->method('getSlogan')
144
+            ->willReturn('A safe home for your data');
145
+        $this->defaults
146
+            ->expects($this->any())
147
+            ->method('getLogo')
148
+            ->willReturn('/img/logo-mail-header.png');
149
+        $this->defaults
150
+            ->expects($this->atLeastOnce())
151
+            ->method('getDefaultTextColorPrimary')
152
+            ->willReturn('#ffffff');
153
+        $this->urlGenerator
154
+            ->expects($this->once())
155
+            ->method('getAbsoluteURL')
156
+            ->with('/img/logo-mail-header.png')
157
+            ->willReturn('https://example.org/img/logo-mail-header.png');
158
+
159
+        $this->emailTemplate->addHeader();
160
+        $this->emailTemplate->addHeading('Welcome aboard');
161
+        $this->emailTemplate->addBodyText('Welcome to your Nextcloud account, you can add, protect, and share your data.');
162
+        $this->emailTemplate->addBodyText('Your username is: abc');
163
+        $this->emailTemplate->addBodyButton(
164
+            'Set your password', 'https://example.org/resetPassword/123',
165
+            false
166
+        );
167
+        $this->emailTemplate->addFooter();
168
+
169
+        $expectedHTML = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-single-button.html');
170
+        $this->assertSame($expectedHTML, $this->emailTemplate->renderHtml());
171
+        $expectedTXT = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-single-button.txt');
172
+        $this->assertSame($expectedTXT, $this->emailTemplate->renderText());
173
+    }
174
+
175
+
176
+
177
+    public function testEMailTemplateAlternativePlainTexts(): void {
178
+        $this->defaults
179
+            ->expects($this->atLeastOnce())
180
+            ->method('getDefaultColorPrimary')
181
+            ->willReturn('#0082c9');
182
+        $this->defaults
183
+            ->expects($this->any())
184
+            ->method('getName')
185
+            ->willReturn('TestCloud');
186
+        $this->defaults
187
+            ->expects($this->any())
188
+            ->method('getSlogan')
189
+            ->willReturn('A safe home for your data');
190
+        $this->defaults
191
+            ->expects($this->any())
192
+            ->method('getLogo')
193
+            ->willReturn('/img/logo-mail-header.png');
194
+        $this->defaults
195
+            ->expects($this->atLeastOnce())
196
+            ->method('getDefaultTextColorPrimary')
197
+            ->willReturn('#ffffff');
198
+        $this->urlGenerator
199
+            ->expects($this->once())
200
+            ->method('getAbsoluteURL')
201
+            ->with('/img/logo-mail-header.png')
202
+            ->willReturn('https://example.org/img/logo-mail-header.png');
203
+
204
+        $this->emailTemplate->addHeader();
205
+        $this->emailTemplate->addHeading('Welcome aboard', 'Welcome aboard - text');
206
+        $this->emailTemplate->addBodyText('Welcome to your Nextcloud account, you can add, protect, and share your data.', 'Welcome to your Nextcloud account, you can add, protect, and share your data. - text');
207
+        $this->emailTemplate->addBodyText('Your username is: abc');
208
+        $this->emailTemplate->addBodyButtonGroup(
209
+            'Set your password', 'https://example.org/resetPassword/123',
210
+            'Install Client', 'https://nextcloud.com/install/#install-clients',
211
+            'Set your password - text', 'Install Client - text'
212
+        );
213
+        $this->emailTemplate->addFooter();
214
+
215
+        $expectedHTML = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-custom.html');
216
+        $this->assertSame($expectedHTML, $this->emailTemplate->renderHtml());
217
+        $expectedTXT = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-custom-text-alternative.txt');
218
+        $this->assertSame($expectedTXT, $this->emailTemplate->renderText());
219
+    }
220 220
 }
Please login to merge, or discard this patch.