45
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Signature\TemplateRenderer;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TemplateRendererTest extends TestCase
|
||||
{
|
||||
private TemplateRenderer $r;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->r = new TemplateRenderer;
|
||||
}
|
||||
|
||||
public function test_substitue_et_echappe_les_variables(): void
|
||||
{
|
||||
$this->assertSame('Bonjour Jean <b>', $this->r->render('Bonjour {{prenom}}', ['prenom' => 'Jean <b>']));
|
||||
}
|
||||
|
||||
public function test_valeur_brute_avec_triple_accolade(): void
|
||||
{
|
||||
$this->assertSame('<img src="x">', $this->r->render('{{{banniere}}}', ['banniere' => '<img src="x">']));
|
||||
}
|
||||
|
||||
public function test_bloc_if_masque_si_vide(): void
|
||||
{
|
||||
$tpl = 'A{{#if mobile}} Mob. {{mobile}}{{/if}}B';
|
||||
$this->assertSame('AB', $this->r->render($tpl, ['mobile' => ' ']));
|
||||
$this->assertSame('A Mob. 06B', $this->r->render($tpl, ['mobile' => '06']));
|
||||
}
|
||||
|
||||
public function test_blocs_imbriques_et_unless(): void
|
||||
{
|
||||
$tpl = '{{#if adresse}}{{adresse}}{{#if ville}}, {{ville}}{{/if}}{{/if}}{{#unless adresse}}-{{/unless}}';
|
||||
$this->assertSame('1 rue X, Béziers', $this->r->render($tpl, ['adresse' => '1 rue X', 'ville' => 'Béziers']));
|
||||
$this->assertSame('1 rue X', $this->r->render($tpl, ['adresse' => '1 rue X']));
|
||||
$this->assertSame('-', $this->r->render($tpl, []));
|
||||
}
|
||||
|
||||
public function test_variable_inconnue_vide_et_casse_ignoree(): void
|
||||
{
|
||||
$this->assertSame('[]', $this->r->render('[{{Inconnue}}]', []));
|
||||
$this->assertSame('x', $this->r->render('{{PRENOM}}', ['prenom' => 'x']));
|
||||
}
|
||||
|
||||
public function test_liste_des_variables(): void
|
||||
{
|
||||
$vars = $this->r->variables('{{prenom}} {{#if mobile}}{{mobile}}{{/if}} {{{banniere}}}');
|
||||
sort($vars);
|
||||
$this->assertSame(['banniere', 'mobile', 'prenom'], $vars);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user