3 require_once('lanceur_spip.php');
5 class Test_nettoyer_raccourcis_typo
extends SpipTest
{
7 public function __construct() {
8 parent
::__construct("Tests de nettoyer_raccourcis_typo()");
9 include_spip('inc/lien');
10 include_spip('inc/texte_mini');
14 * @param array[] $data Collection of array with keys : [texte, couper, nettoyer]
16 protected function _testData(array $data) {
17 foreach ($data as $d) {
18 $nettoyer = nettoyer_raccourcis_typo($d['texte']);
19 $couper = couper($d['texte']);
20 $this->_printTest($d, $nettoyer, $couper);
25 protected function _printTest(array $data, $nettoyer, $couper) {
26 $titre = isset($data['titre']) ?
$data['titre'] : '';
27 if (!$this->assertEqual($nettoyer, $data['nettoyer'])) {
28 $this->reporter
->paintFormattedMessage("Nettoyer_raccourcis_typo | $titre. Texte -> Attendu -> Reçu");
29 $this->reporter
->paintFormattedMessage($data['texte']);
30 $this->reporter
->paintFormattedMessage($data['nettoyer']);
31 $this->reporter
->paintFormattedMessage($nettoyer);
33 if (!$this->assertEqual($couper, $data['couper'])) {
34 $this->reporter
->paintFormattedMessage("Couper | $titre. Texte -> Attendu -> Reçu");
35 $this->reporter
->paintFormattedMessage($data['texte']);
36 $this->reporter
->paintFormattedMessage($data['couper']);
37 $this->reporter
->paintFormattedMessage($couper);
41 function testNettoyerItalique(){
43 'texte' => 'Un mot {italique}',
44 'couper' => 'Un mot italique',
45 'nettoyer' => 'Un mot italique',
47 'texte' => '{Un texte italique}',
48 'couper' => 'Un texte italique',
49 'nettoyer' => 'Un texte italique',
53 function testNettoyerGras(){
55 'texte' => 'Un mot {{gras}}',
56 'couper' => 'Un mot gras',
57 'nettoyer' => 'Un mot gras',
59 'texte' => '{{Un texte gras}}',
60 'couper' => 'Un texte gras',
61 'nettoyer' => 'Un texte gras',
66 function testNettoyerIntertitre(){
68 'texte' => '{{{Un intertitre}}}',
69 'couper' => 'Un intertitre',
70 'nettoyer' => 'Un intertitre',
72 'texte' => "Ligne\n\n{{{Un intertitre}}}\n\nLigne",
73 'couper' => "Ligne\n\nUn intertitre\n\nLigne",
74 'nettoyer' => "Ligne\n\nUn intertitre\n\nLigne",
78 function testNettoyerLiens(){
80 'texte' => 'Un lien [interne->article1]',
81 'couper' => 'Un lien interne',
82 'nettoyer' => 'Un lien interne',
84 'texte' => 'Un lien [externe->http://example.org]',
85 'couper' => 'Un lien externe',
86 'nettoyer' => 'Un lien externe',
91 * Les listes sont mises à plat
92 * 1 saut de ligne \n entre chaque, couper les réassemble en espace.
95 * Avant SPIP 3.2, 1 saut de paragraphe \n\n entre chaque (couper le laissait).
97 function testNettoyerListes(){
105 'couper' => "Une liste un deux trois",
106 'nettoyer' => "Une liste\nun\ndeux\ntrois",
109 "Une liste avec ligne
116 'couper' => "Une liste avec ligne un deux trois",
117 'nettoyer' => "Une liste avec ligne\nun\ndeux\ntrois",
122 * Les tableaux sont totalement supprimés.
123 * Enfin presque : remplacés par \n\n
124 * Le texte étant trimmé, \n en fins sont enlevés.
127 * Avant SPIP 3.2, les tableaux n’étaient pas toujours correctement supprimés
129 function testNettoyerTableaux(){
131 // tableau sans sauts de ligne avant / après.
132 'titre' => 'tableau sans sauts de ligne avant / après',
134 "| {{colonneA}} | {{colonneB}} |
135 | ligneA1 | ligneB1 |
136 | ligneA2 | ligneB2 |",
141 "Un tableau sans ligne vide avant
142 | {{colonneA}} | {{colonneB}} |
143 | ligneA1 | ligneB1 |
144 | ligneA2 | ligneB2 |
146 'couper' => "Un tableau sans ligne vide avant",
147 'nettoyer' => "Un tableau sans ligne vide avant",
150 "Un tableau avec ligne vide avant
152 | {{colonneA}} | {{colonneB}} |
153 | ligneA1 | ligneB1 |
154 | ligneA2 | ligneB2 |
156 'couper' => "Un tableau avec ligne vide avant",
157 'nettoyer' => "Un tableau avec ligne vide avant",
160 "Un tableau avec ligne avant / après
161 | {{colonneA}} | {{colonneB}} |
162 | ligneA1 | ligneB1 |
163 | ligneA2 | ligneB2 |
166 'couper' => "Un tableau avec ligne avant / après\n\nAprès",
167 'nettoyer' => "Un tableau avec ligne avant / après\n\nAprès",
172 * Les notes sont supprimées.
175 * Avant 3.2 la regexp pouvait tuer pcre sur des textes longs
176 * ayant des notes mal fermées.
178 function testNettoyerNotes(){
180 'texte' => 'Une note bien fermée [[note 1]]',
181 'couper' => 'Une note bien fermée',
182 'nettoyer' => 'Une note bien fermée',
184 'texte' => 'Une note mal fermée [[note 1]',
185 'couper' => 'Une note mal fermée [[note 1]',
186 'nettoyer' => 'Une note mal fermée [[note 1]',
188 'texte' => 'Un lien dans une note [[note [lien->article1]]]',
189 'couper' => 'Un lien dans une note',
190 'nettoyer' => 'Un lien dans une note',
192 'texte' => 'Lien et note ratée [[note [lien->article1]] ]',
193 'couper' => 'Lien et note ratée [[note lien] ]',
194 'nettoyer' => 'Lien et note ratée [[note lien] ]',