1 | <?php |
---|
2 | /* |
---|
3 | * Plugin Porte Plume pour SPIP 2 |
---|
4 | * Licence GPL |
---|
5 | * Auteur Matthieu Marcillaud |
---|
6 | */ |
---|
7 | require_once('lanceur_spip.php'); |
---|
8 | |
---|
9 | class Test_barre_outil_markitup extends SpipTest { |
---|
10 | |
---|
11 | var $baseParamsBarre = array(); |
---|
12 | var $baseParamsBarreEtendue = array(); |
---|
13 | |
---|
14 | function __construct() { |
---|
15 | |
---|
16 | parent::__construct("Test de la classe Barre_outils"); |
---|
17 | |
---|
18 | // instancier une barre d'outil |
---|
19 | include_spip('porte_plume_fonctions'); |
---|
20 | |
---|
21 | $this->baseParamsBarre = array( |
---|
22 | 'nameSpace' => 'spip', |
---|
23 | 'markupSet' => array( |
---|
24 | // H1 - {{{ |
---|
25 | array( |
---|
26 | "id" => 'header1', |
---|
27 | "name" => _T('barreoutils:barre_intertitre'), |
---|
28 | "key" => "H", |
---|
29 | "className" => "outil_header1", |
---|
30 | "openWith" => "{{{", |
---|
31 | "closeWith" => "}}}", |
---|
32 | "display" => true, |
---|
33 | ) |
---|
34 | ) |
---|
35 | ); |
---|
36 | $p = $this->baseParamsBarre; |
---|
37 | $p['markupSet'][1] = array( |
---|
38 | "id" => 'couleurs', |
---|
39 | "name" => _T('barreoutils:barre_couleur'), |
---|
40 | "key" => "C", |
---|
41 | "className" => "outil_couleur", |
---|
42 | "openWith" => '[color=[![Color]!]]', |
---|
43 | "closeWith" => '[/color]', |
---|
44 | "display" => true, |
---|
45 | "dropMenu" => array( |
---|
46 | array( |
---|
47 | "id" => "couleur_jaune", |
---|
48 | "name" => 'Yellow', |
---|
49 | "openWith" => '[color=yellow]', |
---|
50 | "closeWith" => '[/color]', |
---|
51 | "className" => "outil_couleur", |
---|
52 | "display" => true, |
---|
53 | ), |
---|
54 | array( |
---|
55 | "id" => "couleur_orange", |
---|
56 | "name" => 'Orange', |
---|
57 | "openWith" => '[color=orange]', |
---|
58 | "closeWith" => '[/color]', |
---|
59 | "className" => "outil_couleur", |
---|
60 | "display" => true, |
---|
61 | ), |
---|
62 | array( |
---|
63 | "id" => "couleur_rouge", |
---|
64 | "name" => 'Red', |
---|
65 | "openWith" => '[color=red]', |
---|
66 | "closeWith" => '[/color]', |
---|
67 | "className" => "outil_couleur", |
---|
68 | "display" => true, |
---|
69 | ), |
---|
70 | ), |
---|
71 | ); |
---|
72 | $this->baseParamsBarreEtendue = $p; |
---|
73 | } |
---|
74 | |
---|
75 | // avant chaque appel de fonction test |
---|
76 | function setUp() { |
---|
77 | |
---|
78 | } |
---|
79 | |
---|
80 | // apres chaque appel de fonction test |
---|
81 | function tearDown() { |
---|
82 | |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | function testInitialisationBarre() { |
---|
87 | // parametres inseres a leur bonne place |
---|
88 | $b = new Barre_outils($this->baseParamsBarre); |
---|
89 | $this->assertEqual('spip', $b->nameSpace); |
---|
90 | $this->assertEqual('header1', $b->markupSet[0]['id']); |
---|
91 | $this->assertEqual(7, count($b->markupSet[0])); |
---|
92 | } |
---|
93 | |
---|
94 | function testInitialisationBarreEtendue() { |
---|
95 | // parametres inseres a leur bonne place, |
---|
96 | // meme quand il y a des sous-menu d'icones |
---|
97 | $b = new Barre_outils($this->baseParamsBarreEtendue); |
---|
98 | $this->assertEqual('spip', $b->nameSpace); |
---|
99 | $this->assertEqual('header1', $b->markupSet[0]['id']); |
---|
100 | $this->assertEqual(7, count($b->markupSet[0])); |
---|
101 | $this->assertEqual('couleurs', $b->markupSet[1]['id']); |
---|
102 | $this->assertEqual(3, count($b->markupSet[1]['dropMenu'])); |
---|
103 | } |
---|
104 | |
---|
105 | function testOptionsIncorrectesNonIncluses() { |
---|
106 | $p = $this->baseParamsBarre; |
---|
107 | $p['fausseVariable'] = "je ne dois pas m'installer"; |
---|
108 | $p['markupSet'][0]['fauxParam'] = "je ne dois pas m'installer"; |
---|
109 | $b = new Barre_outils($p); |
---|
110 | $this->assertEqual('spip', $b->nameSpace); |
---|
111 | |
---|
112 | $this->expectError(new PatternExpectation("/Undefined property: Barre_outils::\\\$fausseVariable/i")); |
---|
113 | $b->fausseVariable; |
---|
114 | |
---|
115 | $this->expectError(new PatternExpectation("/Undefined index: fauxParam/i")); |
---|
116 | $b->markupSet[0]['fauxParam']; |
---|
117 | |
---|
118 | $this->assertEqual(7, count($b->markupSet[0])); |
---|
119 | } |
---|
120 | |
---|
121 | function testRecuperationDeParametreAvecGet() { |
---|
122 | // trouver des id de premier niveau |
---|
123 | $p = $this->baseParamsBarre; |
---|
124 | $b = new Barre_outils($p); |
---|
125 | $this->assertEqual($b->get('header1'), $p['markupSet'][0]); |
---|
126 | |
---|
127 | // trouver des id de second niveau |
---|
128 | $p = $this->baseParamsBarreEtendue; |
---|
129 | $b = new Barre_outils($p); |
---|
130 | $this->assertEqual($b->get('header1'), $p['markupSet'][0]); |
---|
131 | $this->assertEqual($b->get('couleurs'), $p['markupSet'][1]); |
---|
132 | $this->assertEqual($b->get('couleur_jaune'), $p['markupSet'][1]['dropMenu'][0]); |
---|
133 | $this->assertEqual($b->get('couleur_orange'), $p['markupSet'][1]['dropMenu'][1]); |
---|
134 | $this->assertEqual($b->get('couleur_rouge'), $p['markupSet'][1]['dropMenu'][2]); |
---|
135 | |
---|
136 | // ne pas trouver d'id inconnu |
---|
137 | $this->assertFalse($b->get('je_nexiste_pas')); |
---|
138 | } |
---|
139 | |
---|
140 | function testModificationDeParametresAvecSet() { |
---|
141 | $p = $this->baseParamsBarre; |
---|
142 | $b = new Barre_outils($p); |
---|
143 | $p['markupSet'][0]['name'] = 'New'; |
---|
144 | $r = $p['markupSet'][0]; |
---|
145 | $x = $b->set('header1', array("name" => "New")); |
---|
146 | |
---|
147 | $this->assertEqual($r, $x); // set retourne la chaine modifiee complete |
---|
148 | $this->assertEqual($r, $b->get('header1')); |
---|
149 | |
---|
150 | // on ne peut ajouter de mauvais parametres |
---|
151 | $x = $b->set('header1', array("Je Suis Pas Bon" => "No no no")); |
---|
152 | $this->assertEqual($r, $x); // set retourne la chaine modifiee complete |
---|
153 | $this->assertEqual($r, $b->get('header1')); |
---|
154 | } |
---|
155 | |
---|
156 | function testAjoutDeParametresApres() { |
---|
157 | $b = new Barre_outils($this->baseParamsBarre); |
---|
158 | $p = $this->baseParamsBarreEtendue; |
---|
159 | |
---|
160 | // ajoutons la couleur apres |
---|
161 | $b->ajouterApres('header1', $p['markupSet'][1]); |
---|
162 | $this->assertEqual(2, count($b->markupSet)); // 2 boutons de premier niveau maintenant |
---|
163 | $this->assertEqual($b->get('couleurs'), $p['markupSet'][1]); // get renvoie bien le bon ajout |
---|
164 | $this->assertEqual($b->markupSet[1], $p['markupSet'][1]); // et l'ajout est au bon endroit |
---|
165 | |
---|
166 | // ajoutons une couleur dans l'ajout |
---|
167 | $coul = $p['markupSet'][1]['dropMenu'][0]; |
---|
168 | $coul['id'] = 'couleur_violette'; |
---|
169 | $b->ajouterApres('couleur_orange', $coul); |
---|
170 | $this->assertEqual(4, count($b->markupSet[1]['dropMenu'])); // sous boutons |
---|
171 | $this->assertEqual($b->get('couleur_violette'), $coul); |
---|
172 | $this->assertEqual($b->markupSet[1]['dropMenu'][2], $coul); // insertion au bon endroit |
---|
173 | |
---|
174 | // ajoutons un header2 encore apres |
---|
175 | $p['markupSet'][0]['id'] = 'header2'; |
---|
176 | $b->ajouterApres('couleurs', $p['markupSet'][0]); |
---|
177 | $this->assertEqual(3, count($b->markupSet)); |
---|
178 | $this->assertEqual($b->get('header2'), $p['markupSet'][0]); |
---|
179 | $this->assertEqual($b->markupSet[2], $p['markupSet'][0]); |
---|
180 | } |
---|
181 | |
---|
182 | function testAjoutDeParametresAvant() { |
---|
183 | $b = new Barre_outils($this->baseParamsBarre); |
---|
184 | $p = $this->baseParamsBarreEtendue; |
---|
185 | |
---|
186 | // ajoutons la couleur apres |
---|
187 | $b->ajouterAvant('header1', $p['markupSet'][1]); |
---|
188 | $this->assertEqual(2, count($b->markupSet)); // 2 boutons de premier niveau maintenant |
---|
189 | $this->assertEqual($b->get('couleurs'), $p['markupSet'][1]); // get renvoie bien le bon ajout |
---|
190 | $this->assertEqual($b->markupSet[0], $p['markupSet'][1]); // et l'ajout est au bon endroit |
---|
191 | |
---|
192 | // ajoutons une couleur dans l'ajout |
---|
193 | $coul = $p['markupSet'][1]['dropMenu'][0]; |
---|
194 | $coul['id'] = 'couleur_violette'; |
---|
195 | $b->ajouterAvant('couleur_orange', $coul); |
---|
196 | $this->assertEqual(4, count($b->markupSet[0]['dropMenu'])); // sous boutons |
---|
197 | $this->assertEqual($b->get('couleur_violette'), $coul); |
---|
198 | $this->assertEqual($b->markupSet[0]['dropMenu'][1], $coul); // insertion au bon endroit |
---|
199 | |
---|
200 | // ajoutons un header2 avant le 1 |
---|
201 | $p['markupSet'][0]['id'] = 'header2'; |
---|
202 | $b->ajouterAvant('header1', $p['markupSet'][0]); |
---|
203 | $this->assertEqual(3, count($b->markupSet)); |
---|
204 | $this->assertEqual($b->get('header2'), $p['markupSet'][0]); |
---|
205 | $this->assertEqual($b->markupSet[1], $p['markupSet'][0]); |
---|
206 | } |
---|
207 | |
---|
208 | function testAfficherEtCacher() { |
---|
209 | $b = new Barre_outils($this->baseParamsBarre); |
---|
210 | $b->cacher('header1'); |
---|
211 | $this->assertFalse($b->markupSet[0]['display']); |
---|
212 | $b->afficher('header1'); |
---|
213 | $this->assertTrue($b->markupSet[0]['display']); |
---|
214 | } |
---|
215 | |
---|
216 | function testAfficherEtCacherTout() { |
---|
217 | $b = new Barre_outils($this->baseParamsBarreEtendue); |
---|
218 | $b->cacherTout(); |
---|
219 | $this->assertFalse($b->markupSet[0]['display']); |
---|
220 | $this->assertFalse($b->markupSet[1]['dropMenu'][0]['display']); |
---|
221 | |
---|
222 | $b->afficherTout(); |
---|
223 | $this->assertTrue($b->markupSet[0]['display']); |
---|
224 | $this->assertTrue($b->markupSet[1]['dropMenu'][0]['display']); |
---|
225 | } |
---|
226 | |
---|
227 | function testAfficherEtCacherPlusieursBoutons() { |
---|
228 | $b = new Barre_outils($this->baseParamsBarreEtendue); |
---|
229 | $b->cacher(array('header1', 'couleur_jaune')); |
---|
230 | $this->assertFalse($b->markupSet[0]['display']); |
---|
231 | $this->assertFalse($b->markupSet[1]['dropMenu'][0]['display']); |
---|
232 | $this->assertTrue($b->markupSet[1]['dropMenu'][1]['display']); |
---|
233 | |
---|
234 | $b->cacherTout(); |
---|
235 | $b->afficher(array('header1', 'couleur_jaune')); |
---|
236 | $this->assertTrue($b->markupSet[0]['display']); |
---|
237 | $this->assertTrue($b->markupSet[1]['dropMenu'][0]['display']); |
---|
238 | $this->assertFalse($b->markupSet[1]['dropMenu'][1]['display']); |
---|
239 | } |
---|
240 | |
---|
241 | function testSetAvecIdVideNeDoitRienModifier() { |
---|
242 | $b = new Barre_outils($this->baseParamsBarreEtendue); |
---|
243 | $b->set(array(), array('display' => false)); |
---|
244 | $this->assertTrue($b->markupSet[0]['display']); |
---|
245 | $this->assertTrue($b->markupSet[1]['dropMenu'][0]['display']); |
---|
246 | } |
---|
247 | |
---|
248 | function testSetAvecIdArrayDoitModifTousLesIds() { |
---|
249 | $b = new Barre_outils($this->baseParamsBarreEtendue); |
---|
250 | $b->set(array('header1', 'couleur_jaune'), array('display' => false)); |
---|
251 | $this->assertFalse($b->markupSet[0]['display']); |
---|
252 | $this->assertFalse($b->markupSet[1]['dropMenu'][0]['display']); |
---|
253 | $this->assertTrue($b->markupSet[1]['dropMenu'][1]['display']); |
---|
254 | } |
---|
255 | |
---|
256 | function testCreerJson() { |
---|
257 | $b = new Barre_outils($this->baseParamsBarre); |
---|
258 | $b->ajouterApres('header1', array( |
---|
259 | "id" => 'Caracteres decodes', |
---|
260 | "name" => "étrange", |
---|
261 | "className" => "outil_fr", |
---|
262 | "openWith" => "[fr]", |
---|
263 | "display" => true, |
---|
264 | )); |
---|
265 | $json = $b->creer_json(); |
---|
266 | $this->assertPattern(',barre_outils_spip = {,', $json); |
---|
267 | $this->assertPattern(',\[{"name":",', $json); |
---|
268 | $this->assertNoPattern(',eacute;,', $json); |
---|
269 | } |
---|
270 | |
---|
271 | function testBoutonsDUneLangue() { |
---|
272 | $b = new Barre_outils($this->baseParamsBarre); |
---|
273 | $ico2 = $ico1 = array( |
---|
274 | "id" => 'ico_fr1', |
---|
275 | "name" => "test apparaissant si langue est le francais", |
---|
276 | "className" => "outil_fr", |
---|
277 | "openWith" => "[fr]", |
---|
278 | "lang" => array("fr"), |
---|
279 | "display" => true, |
---|
280 | ); |
---|
281 | $ico2['id'] = 'ico_fr2'; |
---|
282 | $ico2['lang'] = array("fr", "en", "es"); |
---|
283 | |
---|
284 | $b->ajouterApres('header1', $ico1); |
---|
285 | $b->ajouterApres('ico_fr1', $ico2); |
---|
286 | $this->assertEqual($ico1, $b->get('ico_fr1')); |
---|
287 | $this->assertEqual($ico2, $b->get('ico_fr2')); |
---|
288 | |
---|
289 | // verifier que ces nouveaux array() |
---|
290 | // ne posent pas de problemes dans les recursions |
---|
291 | $b->cacherTout(); |
---|
292 | $this->assertFalse($b->markupSet[1]['display']); |
---|
293 | $b->afficher('ico_fr1'); |
---|
294 | $this->assertTrue($b->markupSet[1]['display']); |
---|
295 | $b->cacherTout(); |
---|
296 | $b->afficher(array('ico_fr1', 'ico_fr2')); |
---|
297 | $this->assertTrue($b->markupSet[1]['display']); |
---|
298 | |
---|
299 | // la langue est bien transmise au json |
---|
300 | $json = $b->creer_json(); |
---|
301 | $this->assertPattern(',"lang":\[,', $json); |
---|
302 | } |
---|
303 | |
---|
304 | |
---|
305 | function testFonctionsJavacriptDansParametreNeDoitPasEtreEntreguillemetsDansJson() { |
---|
306 | $b = new Barre_outils($this->baseParamsBarre); |
---|
307 | $clean = array( |
---|
308 | "id" => 'clean', |
---|
309 | "name" => _T('barreoutils:barre_clean'), |
---|
310 | "className" => "outil_clean", |
---|
311 | // function doit etre echappe |
---|
312 | "replaceWith" => 'function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") }', |
---|
313 | "display" => true, |
---|
314 | ); |
---|
315 | $b->ajouterApres('header1', $clean); |
---|
316 | $json = $b->creer_json(); |
---|
317 | // pas de :"function(... ..." |
---|
318 | $this->assertPattern('/:function\(/', $json); |
---|
319 | } |
---|
320 | |
---|
321 | function testParametreFunctionsDansJson() { |
---|
322 | $b = new Barre_outils($this->baseParamsBarre); |
---|
323 | $b->functions = "function dido(){}"; |
---|
324 | $json = $b->creer_json(); |
---|
325 | // function n'est plus dans la barre |
---|
326 | $this->expectError(new PatternExpectation("/Undefined property: Barre_outils::\\\$functions/i")); |
---|
327 | $b->functions; |
---|
328 | // mais uniquement en fin du fichier json |
---|
329 | $this->assertPattern('/function dido\(/', $json); |
---|
330 | } |
---|
331 | |
---|
332 | function testAjouterFonctions() { |
---|
333 | $b = new Barre_outils($this->baseParamsBarre); |
---|
334 | $b->ajouterFonction("function dido(){}"); |
---|
335 | $this->assertPattern('/function dido\(/', $b->functions); |
---|
336 | } |
---|
337 | |
---|
338 | /* |
---|
339 | function squeletteTest(){ |
---|
340 | $sq = new SqueletteTest("SimpleTest"); |
---|
341 | $sq->addInsertHead(); |
---|
342 | $sq->addToBody(" |
---|
343 | <div class='formulaire_spip'> |
---|
344 | <form> |
---|
345 | <textarea name='texte' class='texte'></textarea> |
---|
346 | </form> |
---|
347 | </div> |
---|
348 | "); |
---|
349 | return $sq; |
---|
350 | } |
---|
351 | |
---|
352 | function testPresenceBarreOutilPublique(){ |
---|
353 | include_spip('simpletest/browser'); |
---|
354 | include_spip('simpletest/web_tester'); |
---|
355 | |
---|
356 | $sq = $this->squeletteTest(); |
---|
357 | |
---|
358 | $browser = &new SimpleBrowser(); |
---|
359 | $browser->get($f=$this->urlTestCode($sq->code())); |
---|
360 | $browser->setField('texte', 'me'); |
---|
361 | $this->dump($browser->getField('texte')); |
---|
362 | $this->dump($browser->getContent()); |
---|
363 | #$this->dump($c); |
---|
364 | #$this->assertPattern('/jquery\.markitup_pour_spip\.js/', $c); |
---|
365 | }*/ |
---|
366 | } |
---|