[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / plugins-dist / textwheel / tests / simpletest / nettoyer_raccourcis_typo.php
1 <?php
2
3 require_once('lanceur_spip.php');
4
5 class Test_nettoyer_raccourcis_typo extends SpipTest {
6
7 public function __construct() {
8 parent::__construct("Tests de nettoyer_raccourcis_typo()");
9 include_spip('inc/lien');
10 include_spip('inc/texte_mini');
11 }
12
13 /**
14 * @param array[] $data Collection of array with keys : [texte, couper, nettoyer]
15 */
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);
21 }
22 }
23
24
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);
32 }
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);
38 }
39 }
40
41 function testNettoyerItalique(){
42 $this->_testData([[
43 'texte' => 'Un mot {italique}',
44 'couper' => 'Un mot italique',
45 'nettoyer' => 'Un mot italique',
46 ],[
47 'texte' => '{Un texte italique}',
48 'couper' => 'Un texte italique',
49 'nettoyer' => 'Un texte italique',
50 ]]);
51 }
52
53 function testNettoyerGras(){
54 $this->_testData([[
55 'texte' => 'Un mot {{gras}}',
56 'couper' => 'Un mot gras',
57 'nettoyer' => 'Un mot gras',
58 ],[
59 'texte' => '{{Un texte gras}}',
60 'couper' => 'Un texte gras',
61 'nettoyer' => 'Un texte gras',
62 ]]);
63 }
64
65
66 function testNettoyerIntertitre(){
67 $this->_testData([[
68 'texte' => '{{{Un intertitre}}}',
69 'couper' => 'Un intertitre',
70 'nettoyer' => 'Un intertitre',
71 ],[
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",
75 ]]);
76 }
77
78 function testNettoyerLiens(){
79 $this->_testData([[
80 'texte' => 'Un lien [interne->article1]',
81 'couper' => 'Un lien interne',
82 'nettoyer' => 'Un lien interne',
83 ],[
84 'texte' => 'Un lien [externe->http://example.org]',
85 'couper' => 'Un lien externe',
86 'nettoyer' => 'Un lien externe',
87 ]]);
88 }
89
90 /**
91 * Les listes sont mises à plat
92 * 1 saut de ligne \n entre chaque, couper les réassemble en espace.
93 *
94 * @note
95 * Avant SPIP 3.2, 1 saut de paragraphe \n\n entre chaque (couper le laissait).
96 */
97 function testNettoyerListes(){
98 $this->_testData([[
99 'texte' =>
100 "Une liste
101 -* un
102 -* deux
103 -* trois
104 ",
105 'couper' => "Une liste un deux trois",
106 'nettoyer' => "Une liste\nun\ndeux\ntrois",
107 ],[
108 'texte' =>
109 "Une liste avec ligne
110
111 -* un
112 -* deux
113 -* trois
114
115 ",
116 'couper' => "Une liste avec ligne un deux trois",
117 'nettoyer' => "Une liste avec ligne\nun\ndeux\ntrois",
118 ]]);
119 }
120
121 /**
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.
125 *
126 * @note
127 * Avant SPIP 3.2, les tableaux n’étaient pas toujours correctement supprimés
128 */
129 function testNettoyerTableaux(){
130 $this->_testData([[
131 // tableau sans sauts de ligne avant / après.
132 'titre' => 'tableau sans sauts de ligne avant / après',
133 'texte' =>
134 "| {{colonneA}} | {{colonneB}} |
135 | ligneA1 | ligneB1 |
136 | ligneA2 | ligneB2 |",
137 'couper' => "",
138 'nettoyer' => "",
139 ],[
140 'texte' =>
141 "Un tableau sans ligne vide avant
142 | {{colonneA}} | {{colonneB}} |
143 | ligneA1 | ligneB1 |
144 | ligneA2 | ligneB2 |
145 ",
146 'couper' => "Un tableau sans ligne vide avant",
147 'nettoyer' => "Un tableau sans ligne vide avant",
148 ],[
149 'texte' =>
150 "Un tableau avec ligne vide avant
151
152 | {{colonneA}} | {{colonneB}} |
153 | ligneA1 | ligneB1 |
154 | ligneA2 | ligneB2 |
155 ",
156 'couper' => "Un tableau avec ligne vide avant",
157 'nettoyer' => "Un tableau avec ligne vide avant",
158 ],[
159 'texte' =>
160 "Un tableau avec ligne avant / après
161 | {{colonneA}} | {{colonneB}} |
162 | ligneA1 | ligneB1 |
163 | ligneA2 | ligneB2 |
164 Après
165 ",
166 'couper' => "Un tableau avec ligne avant / après\n\nAprès",
167 'nettoyer' => "Un tableau avec ligne avant / après\n\nAprès",
168 ]]);
169 }
170
171 /**
172 * Les notes sont supprimées.
173 *
174 * @note
175 * Avant 3.2 la regexp pouvait tuer pcre sur des textes longs
176 * ayant des notes mal fermées.
177 */
178 function testNettoyerNotes(){
179 $this->_testData([[
180 'texte' => 'Une note bien fermée [[note 1]]',
181 'couper' => 'Une note bien fermée',
182 'nettoyer' => 'Une note bien fermée',
183 ],[
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]',
187 ],[
188 'texte' => 'Un lien dans une note [[note [lien->article1]]]',
189 'couper' => 'Un lien dans une note',
190 'nettoyer' => 'Un lien dans une note',
191 ],[
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] ]',
195 ]]);
196 }
197 }