Files
nextcloud-server-mirror/tests/lib/Mail/EMailDetailsTest.php
John Molakvoæ 9e39985130 feat(mail): add sender, note, details and buttons blocks to email template
Adds addBodySender, addBodyNote, addBodyDetails and addBodyButtons to
IEMailTemplate, with the EMailDetails and EMailDetailsRow value classes
for the details card. All values are escaped by the template, each block
also renders a plain text version.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: John Molakvoæ <14975046+skjnldsv@users.noreply.github.com>
2026-10-06 20:17:29 +02:00

60 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Mail;
use OCP\Mail\EMailDetails;
use OCP\Mail\EMailDetailsRow;
use Test\TestCase;
class EMailDetailsTest extends TestCase {
public function testDefaults(): void {
$details = new EMailDetails('Title');
$this->assertSame('Title', $details->getTitle());
$this->assertSame('', $details->getSubtitle());
$this->assertNull($details->getInitialsName());
$this->assertNull($details->getDateBadge());
$this->assertSame([], $details->getRows());
}
public function testLeadingVisualReplacesTheOther(): void {
$details = (new EMailDetails('Title'))
->setInitials('Board prep')
->setDateBadge('Oct', '15');
$this->assertNull($details->getInitialsName());
$this->assertSame(['month' => 'Oct', 'day' => '15'], $details->getDateBadge());
$details->setInitials('Board prep');
$this->assertSame('Board prep', $details->getInitialsName());
$this->assertNull($details->getDateBadge());
}
public function testRowsKeepOrder(): void {
$details = new EMailDetails('Title');
$details->addRow('Where')
->text('Room 2')
->link('Join', 'https://example.org')
->muted('Optional');
$details->addRow('When')->text('Today');
$rows = $details->getRows();
$this->assertCount(2, $rows);
$this->assertSame('Where', $rows[0]->getLabel());
$this->assertSame([
['type' => EMailDetailsRow::PART_TEXT, 'text' => 'Room 2', 'url' => ''],
['type' => EMailDetailsRow::PART_LINK, 'text' => 'Join', 'url' => 'https://example.org'],
['type' => EMailDetailsRow::PART_MUTED, 'text' => 'Optional', 'url' => ''],
], $rows[0]->getParts());
$this->assertSame('When', $rows[1]->getLabel());
}
}