From 13b3d8c1edbe42fbf42c77274556e33c26075dfd Mon Sep 17 00:00:00 2001
From: Matthieu Marcillaud <marcimat@rezo.net>
Date: Sun, 9 Jul 2023 16:17:27 +0200
Subject: [PATCH] tests: Boucle Documents, modeles img/doc/emb en PHPUnit

---
 .../Critere/OperatorRegexpLikeTest.php        |  3 +-
 .../Squelettes/Modeles/DocumentsTest.php      | 55 +++++++++++++++++++
 .../unit/documents/affichage_documents.html   | 44 ---------------
 3 files changed, 56 insertions(+), 46 deletions(-)
 create mode 100644 ecrire/tests/Squelettes/Modeles/DocumentsTest.php
 delete mode 100644 ecrire/tests/legacy/unit/documents/affichage_documents.html

diff --git a/ecrire/tests/Squelettes/Critere/OperatorRegexpLikeTest.php b/ecrire/tests/Squelettes/Critere/OperatorRegexpLikeTest.php
index b56f12cdae..7dd9137ea0 100644
--- a/ecrire/tests/Squelettes/Critere/OperatorRegexpLikeTest.php
+++ b/ecrire/tests/Squelettes/Critere/OperatorRegexpLikeTest.php
@@ -23,9 +23,8 @@ class OperatorRegexpLikeTest extends SquelettesTestCase
 	private function getArticleIdTitle(): array {
 		$result = $this->getArticle();
 		[$id_article, $starts_with] = explode(':', trim($result));
-		$id_article = (int) $id_article;
 		return [
-			'id_article' => $id_article,
+			'id_article' => (int) $id_article,
 			'starts_with' => $starts_with
 		];
 	}
diff --git a/ecrire/tests/Squelettes/Modeles/DocumentsTest.php b/ecrire/tests/Squelettes/Modeles/DocumentsTest.php
new file mode 100644
index 0000000000..9489d675cf
--- /dev/null
+++ b/ecrire/tests/Squelettes/Modeles/DocumentsTest.php
@@ -0,0 +1,55 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Spip\Test\Squelettes\Modeles;
+
+use PHPUnit\Framework\Attributes\Depends;
+use PHPUnit\Framework\Attributes\DataProvider;
+use Spip\Test\SquelettesTestCase;
+use Spip\Test\Templating;
+
+class DocumentsTest extends SquelettesTestCase
+{
+	/**
+	 * D'abord une image uploadee en vignette, et sans titre
+	 * On teste le rendu de son src, width, height
+	 */
+	#[DataProvider('providerDocumentSansTitreModeles')]
+	public function testDocumentSansTitreModeles(string $modele): void {
+		$id_document = $this->getIdDocumentImageSansTitreNiDescriptif();
+		$modele = sprintf($modele, $id_document);
+		$this->assertOkCode(<<<SPIP
+			[(#SET{modele,[(#ENV*{modele}|propre)]})]
+			[(#SET{src,#GET{modele}|extraire_balise{img}|extraire_attribut{src}})]
+			[(#GET{src}|quote_amp|=={#URL_DOCUMENT}|oui)OK ]
+			\<img#ID_DOCUMENT\> src pas bon: "#URL_DOCUMENT" != "[(#GET{src})]"
+			SPIP,
+			[
+				'id_document' => $id_document,
+				'modele' => $modele,
+			]
+		);
+	}
+
+	public static function providerDocumentSansTitreModeles() {
+		return [
+			'img' => ['<img%s>'],
+			'doc' => ['<doc%s>'],
+			'emb' => ['<emb%s>'],
+		];
+	}
+
+	private function getIdDocumentImageSansTitreNiDescriptif(): int {
+		$templating = Templating::fromString();
+		$result = $templating->render(<<<SPIP
+		<BOUCLE_d(DOCUMENTS){mode=image}{titre=''}{descriptif=''}{0,1}>#ID_DOCUMENT</BOUCLE_d>
+		NA Ce test exige une image chargee en mode "image" et n'ayant ni titre ni descriptif
+		<//B_d>
+		SPIP);
+		if ($this->isNa($result)) {
+			$this->markTestSkipped($result);
+		}
+		return (int) $result;
+	}
+}
diff --git a/ecrire/tests/legacy/unit/documents/affichage_documents.html b/ecrire/tests/legacy/unit/documents/affichage_documents.html
deleted file mode 100644
index 3d621810f1..0000000000
--- a/ecrire/tests/legacy/unit/documents/affichage_documents.html
+++ /dev/null
@@ -1,44 +0,0 @@
-[(#REM)
-
-	On va tester le rendu des documents joints
-
-]
-#SET{ok1,''}#SET{ok2,''}#SET{ok3,''}
-
-
-[(#REM)
-	D'abord une image uploadee en vignette, et sans titre
-	On teste le rendu de son src, width, height
-]
-<BOUCLE_d(DOCUMENTS){mode=image}{titre=''}{descriptif=''}{0,1}>
-[(#SET{img,[(#REM|sinon{<img#ID_DOCUMENT>}|propre)]})]
-[(#SET{doc,[(#REM|sinon{<doc#ID_DOCUMENT>}|propre)]})]
-[(#SET{emb,[(#REM|sinon{<emb#ID_DOCUMENT>}|propre)]})]
-
-[(#GET{img}|extraire_balise{img}|extraire_attribut{src}|quote_amp|=={#URL_DOCUMENT}|?{
-	#SET{ok1,1}
-	,' '})
-	&lt;img#ID_DOCUMENT&gt; src pas bon: &quot;#URL_DOCUMENT&quot; != &quot;[(#GET{img}|extraire_balise{img}|extraire_attribut{src})]&quot;
-]
-[(#GET{doc}|extraire_balise{img}|extraire_attribut{src}|quote_amp|=={#URL_DOCUMENT}|?{
-	#SET{ok2,1}
-	,' '})
-	&lt;doc#ID_DOCUMENT&gt; src pas bon: &quot;#URL_DOCUMENT&quot; != &quot;[(#GET{doc}|extraire_balise{img}|extraire_attribut{src})]&quot;
-]
-[(#GET{emb}|extraire_balise{img}|extraire_attribut{src}|quote_amp|=={#URL_DOCUMENT}|?{
-	#SET{ok3,1}
-	,' '})
-	&lt;emb#ID_DOCUMENT&gt; src pas bon: &quot;#URL_DOCUMENT&quot; != &quot;[(#GET{emb}|extraire_balise{img}|extraire_attribut{src})]&quot;
-]
-
-
-</BOUCLE_d>
-
-NA Ce test exige une image chargee en mode "image" et n'ayant ni titre ni descriptif
-
-<//B_d>
-
-
-
-
-[(#GET{ok1}|?{#GET{ok2}}|?{#GET{ok3}}|?{OK})]
-- 
GitLab