test(php): add native unit tests for security, cache, format, markdown
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests unitaires pour markdown_to_html (includes/lib/markdown.php)
|
||||
*
|
||||
* Les sorties attendues reflètent le comportement actuel de la fonction,
|
||||
* y compris ses particularités (voir la note sur les listes à puces).
|
||||
*/
|
||||
|
||||
// --- Échappement XSS ---------------------------------------------------------
|
||||
|
||||
assertEquals(
|
||||
'<script>alert("x")</script>',
|
||||
markdown_to_html('<script>alert("x")</script>'),
|
||||
'markdown_to_html échappe le HTML brut'
|
||||
);
|
||||
assertNotContains(
|
||||
'<script>',
|
||||
markdown_to_html('<script>alert("x")</script>'),
|
||||
'markdown_to_html ne laisse passer aucune balise script'
|
||||
);
|
||||
|
||||
// --- Gras et italique --------------------------------------------------------
|
||||
|
||||
assertEquals(
|
||||
'<strong>gras</strong>',
|
||||
markdown_to_html('**gras**'),
|
||||
'markdown_to_html convertit **texte** en <strong>'
|
||||
);
|
||||
assertEquals(
|
||||
'<em>ital</em>',
|
||||
markdown_to_html('*ital*'),
|
||||
'markdown_to_html convertit *texte* en <em>'
|
||||
);
|
||||
|
||||
// --- Liens Markdown ----------------------------------------------------------
|
||||
|
||||
assertEquals(
|
||||
'<a href="https://exemple.com" target="_blank" rel="noopener noreferrer">exemple</a>',
|
||||
markdown_to_html('[exemple](https://exemple.com)'),
|
||||
'markdown_to_html convertit un lien Markdown avec attributs de sécurité'
|
||||
);
|
||||
assertEquals(
|
||||
'<a href="http://exemple.com" target="_blank" rel="noopener noreferrer">site</a>',
|
||||
markdown_to_html('[site](exemple.com)'),
|
||||
'markdown_to_html ajoute http:// aux liens sans protocole'
|
||||
);
|
||||
|
||||
// --- URLs brutes -------------------------------------------------------------
|
||||
|
||||
assertEquals(
|
||||
'Visite <a href="https://exemple.com/page" target="_blank" rel="noopener noreferrer">https://exemple.com/page</a> pour info',
|
||||
markdown_to_html('Visite https://exemple.com/page pour info'),
|
||||
'markdown_to_html rend les URLs http(s) brutes cliquables'
|
||||
);
|
||||
assertEquals(
|
||||
'va sur <a href="http://o-k-i.net" target="_blank" rel="noopener noreferrer">o-k-i.net</a> maintenant',
|
||||
markdown_to_html('va sur o-k-i.net maintenant'),
|
||||
'markdown_to_html rend les domaines nus cliquables (avec http://)'
|
||||
);
|
||||
assertEquals(
|
||||
'version v1.2 dispo',
|
||||
markdown_to_html('version v1.2 dispo'),
|
||||
'markdown_to_html ne transforme pas un numéro de version en lien'
|
||||
);
|
||||
|
||||
// --- Listes ------------------------------------------------------------------
|
||||
|
||||
// Note : la passe des listes numérotées s'applique aussi aux <li> déjà
|
||||
// produits par la passe des puces, d'où un double enveloppement <ul><ol>.
|
||||
// C'est le comportement actuel, verrouillé ici contre toute régression.
|
||||
assertEquals(
|
||||
"<ul><ol><li>a</li>\n<li>b</li></ol></ul>",
|
||||
markdown_to_html("- a\n- b"),
|
||||
'markdown_to_html convertit les listes à puces (double enveloppement actuel)'
|
||||
);
|
||||
assertEquals(
|
||||
"<ol><li>a</li>\n<li>b</li></ol>",
|
||||
markdown_to_html("1. a\n2. b"),
|
||||
'markdown_to_html convertit les listes numérotées en <ol>'
|
||||
);
|
||||
|
||||
// --- Retours à la ligne ------------------------------------------------------
|
||||
|
||||
assertEquals(
|
||||
"ligne1<br />\nligne2",
|
||||
markdown_to_html("ligne1\nligne2"),
|
||||
'markdown_to_html convertit les sauts de ligne en <br />'
|
||||
);
|
||||
Reference in New Issue
Block a user