From 2241ea1238ffe675f4861404caafb17c9515124f Mon Sep 17 00:00:00 2001
From: Matthieu Marcillaud <marcimat@rezo.net>
Date: Sat, 1 Jul 2023 10:22:39 +0200
Subject: [PATCH] tests: Test balise `#FILTRE' en PHPUnit

---
 ecrire/tests/Squelettes/Balise/FiltreTest.php | 54 +++++++++++++++++++
 ecrire/tests/legacy/unit/balises/filtre.html  | 10 ----
 .../legacy/unit/balises/filtre_fonctions.php  | 18 -------
 3 files changed, 54 insertions(+), 28 deletions(-)
 create mode 100644 ecrire/tests/Squelettes/Balise/FiltreTest.php
 delete mode 100644 ecrire/tests/legacy/unit/balises/filtre.html
 delete mode 100644 ecrire/tests/legacy/unit/balises/filtre_fonctions.php

diff --git a/ecrire/tests/Squelettes/Balise/FiltreTest.php b/ecrire/tests/Squelettes/Balise/FiltreTest.php
new file mode 100644
index 0000000000..4dceafb5e6
--- /dev/null
+++ b/ecrire/tests/Squelettes/Balise/FiltreTest.php
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Spip\Test\Squelettes\Balise;
+
+use PHPUnit\Framework\Attributes\Depends;
+use Spip\Test\SquelettesTestCase;
+use Spip\Test\Template\Loader\StringLoader;
+use Spip\Test\Templating;
+
+class FiltreTest extends SquelettesTestCase
+{
+
+	public function testFiltre(): void {
+		$loader = new StringLoader([
+			'fonctions' => <<<PHP
+				function strip_non(string \$texte): string {
+					return str_replace('NON', '', \$texte);
+				}
+
+				function strip_on(string \$texte): string {
+					return str_replace('ON', '', \$texte);
+				}
+			PHP,
+			'apres_code' => <<<SPIP
+				[(#FILTRE{strip_non})]
+				[(#FILTRE{strip_on})]
+			SPIP,
+		]);
+		$templating = new Templating($loader);
+		$this->assertOk($templating->render('NONONOK'));
+	}
+
+	public function testFiltreNommageExplicite(): void {
+		$loader = new StringLoader([
+			'fonctions' => <<<PHP
+				function filtre_remove_non_dist(string \$texte): string {
+					return str_replace('NON', '', \$texte);
+				}
+
+				function filtre_remove_on_dist(string \$texte): string {
+					return str_replace('ON', '', \$texte);
+				}
+			PHP,
+			'apres_code' => <<<SPIP
+				[(#FILTRE{remove_non})]
+				[(#FILTRE{remove_on})]
+			SPIP,
+		]);
+		$templating = new Templating($loader);
+		$this->assertOk($templating->render('NONONOK'));
+	}
+}
diff --git a/ecrire/tests/legacy/unit/balises/filtre.html b/ecrire/tests/legacy/unit/balises/filtre.html
deleted file mode 100644
index 3cc020f1e2..0000000000
--- a/ecrire/tests/legacy/unit/balises/filtre.html
+++ /dev/null
@@ -1,10 +0,0 @@
-[(#REM)
-
-  Squelette
-  (c) 2009 xxx
-  Distribue sous licence GPL
-
-]
-NONONOK
-#FILTRE{strip_non}
-#FILTRE{strip_on}
\ No newline at end of file
diff --git a/ecrire/tests/legacy/unit/balises/filtre_fonctions.php b/ecrire/tests/legacy/unit/balises/filtre_fonctions.php
deleted file mode 100644
index 6daf899504..0000000000
--- a/ecrire/tests/legacy/unit/balises/filtre_fonctions.php
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/*
- * Plugin xxx
- * (c) 2009 xxx
- * Distribue sous licence GPL
- *
- */
-
-function strip_non($texte) {
-	return str_replace('NON', '', $texte);
-}
-
-function strip_on($texte) {
-	return str_replace('ON', '', $texte);
-}
-- 
GitLab