r = new TemplateRenderer; } public function test_substitue_et_echappe_les_variables(): void { $this->assertSame('Bonjour Jean <b>', $this->r->render('Bonjour {{prenom}}', ['prenom' => 'Jean '])); } public function test_valeur_brute_avec_triple_accolade(): void { $this->assertSame('', $this->r->render('{{{banniere}}}', ['banniere' => ''])); } 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); } }