Slide descriptions support *bold*, _italic_, ~strikethrough~ and lists with "- " or "* " at the start of a line. FormatHelper renders them for the participant page and the PDF (escaping everything else), Format in plenario.js builds the same DOM for presenter and embed. Participant input stays plain text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
2.1 KiB
PHP
60 lines
2.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Test\TestCase\View\Helper;
|
|
|
|
use App\View\Helper\FormatHelper;
|
|
use Cake\TestSuite\TestCase;
|
|
use Cake\View\View;
|
|
|
|
/**
|
|
* WhatsApp style formatting of slide texts.
|
|
*/
|
|
class FormatHelperTest extends TestCase
|
|
{
|
|
protected FormatHelper $Format;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->Format = new FormatHelper(new View());
|
|
}
|
|
|
|
public function testInlineMarkers(): void
|
|
{
|
|
$this->assertSame('<strong>fett</strong>', $this->Format->text('*fett*'));
|
|
$this->assertSame('ganz <em>kursiv</em> hier', $this->Format->text('ganz _kursiv_ hier'));
|
|
$this->assertSame('<s>alt</s> neu', $this->Format->text('~alt~ neu'));
|
|
$this->assertSame('<strong>zwei Wörter</strong>, gut', $this->Format->text('*zwei Wörter*, gut'));
|
|
$this->assertSame('<strong><em>beides</em></strong>', $this->Format->text('*_beides_*'));
|
|
$this->assertSame('<strong>a</strong> und <strong>b</strong>', $this->Format->text('*a* und *b*'));
|
|
}
|
|
|
|
public function testMarkersNeedWordBoundariesAndNoInnerSpaces(): void
|
|
{
|
|
$this->assertSame('2*3*4', $this->Format->text('2*3*4'));
|
|
$this->assertSame('snake_case_name', $this->Format->text('snake_case_name'));
|
|
$this->assertSame('so * nicht fett *', $this->Format->text('so * nicht fett *'));
|
|
$this->assertSame('5 * 3 = 15', $this->Format->text('5 * 3 = 15'));
|
|
$this->assertSame('*offen', $this->Format->text('*offen'));
|
|
}
|
|
|
|
public function testLinesAndLists(): void
|
|
{
|
|
$this->assertSame('eins<br>zwei', $this->Format->text("eins\r\nzwei"));
|
|
$this->assertSame(
|
|
'Agenda:<ul><li>Bericht</li><li><strong>Wahl</strong></li></ul>Danke!',
|
|
$this->Format->text("Agenda:\n- Bericht\n* *Wahl*\nDanke!"),
|
|
);
|
|
}
|
|
|
|
public function testEverythingElseIsEscaped(): void
|
|
{
|
|
$this->assertSame(
|
|
'<script>x</script> <strong><b></strong> &',
|
|
$this->Format->text('<script>x</script> *<b>* &'),
|
|
);
|
|
$this->assertSame('', $this->Format->text(null));
|
|
}
|
|
}
|