From ba22a9fe01cbcf8760ce9dc575bfacc69a04492e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ma=C3=AFeul=20Rouquette?= <maieul@maieul.net>
Date: Sat, 4 May 2024 20:54:18 +0200
Subject: [PATCH] test: `svg_nettoyer()`

---
 ecrire/tests/Svg/NettoyerTest.php | 54 +++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 ecrire/tests/Svg/NettoyerTest.php

diff --git a/ecrire/tests/Svg/NettoyerTest.php b/ecrire/tests/Svg/NettoyerTest.php
new file mode 100644
index 0000000000..a8f95163e9
--- /dev/null
+++ b/ecrire/tests/Svg/NettoyerTest.php
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * Test unitaire de la fonction svg_nettoyer du fichier ./inc/svg.php
+ */
+
+namespace Spip\Test\Svg;
+
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\TestCase;
+
+class NettoyerTest extends TestCase
+{
+	public static function setUpBeforeClass(): void {
+		find_in_path('./inc/svg.php', '', true);
+	}
+
+	#[DataProvider('providerNettoyer')]
+	public function testNettoyer($expected, ...$args): void {
+		$actual = svg_nettoyer(...$args);
+		$this->assertSame($expected, $actual);
+	}
+
+	public static function providerNettoyer(): array {
+		return [
+			'bom' => [
+				// Expected
+				'toto',
+				// Provided
+				"\xEF\xBB\xBFtoto",
+			],
+			'entete' => [
+				// Expected
+				'<svg xmlns="http://www.w3.org/2000/svg"></svg>',
+				// Provided
+				'<?xml version="1.0" encoding="utf-8"?><svg xmlns="http://www.w3.org/2000/svg"></svg>',
+			],
+			'ajout_xmlns' => [
+				// Expected
+				'<svg xmlns="http://www.w3.org/2000/svg"></svg>',
+				// Provided
+				'<svg></svg>',
+			],
+			'supprimer_commentaire' => [
+				// Expected
+				'<hop></hop>',
+				// Provided
+				'<hop><!--- ceci est un commentaire--></hop>',
+			],
+		];
+	}
+}
-- 
GitLab