2 #-----------------------------------------------------#
3 # Plugin : Couteau Suisse - Licence : GPL #
4 # Auteur : Patrice Vanneufville, 2006 #
5 # Contact : patrice¡.!vanneufville¡@!laposte¡.!net #
6 # Infos : http://www.spip-contrib.net/?article2166 #
7 #-----------------------------------------------------#
10 Cette page test certaines fonctions presentes dans le plugin
11 Pour rajouter des tests, rdv tout en bas de cette page !
14 include_spip('inc/texte');
15 include_spip('inc/layer');
16 include_spip("inc/presentation");
18 function exec_test_couteau_suisse() {
19 cs_log("DEDUT : exec_test_couteau_suisse()");
20 global $connect_statut, $connect_toutes_rubriques;
24 // initialisation generale forcee : recuperation de $outils;
25 cs_initialisation(true);
27 $commencer_page = charger_fonction('commencer_page', 'inc');
28 echo $commencer_page(_T('couteauprive:titre_tests'), "configuration", 'couteau_suisse');
30 echo '<br /><br /><br />', gros_titre(_T('couteauprive:titre_tests'), '', false),
31 '<div style="width:98%; text-align:left; margin:0 auto">';
32 // et hop, on lance les tests !
37 cs_log(" FIN : exec_test_couteau_suisse()");
40 // renvoie un tableau contenant le texte original et sa transfrmation par la fonction $fonction
41 // $textes est un tableau de chaines
42 function cs_test_fun(&$textes, $fonction) {
44 if (!function_exists($fonction)) return array('erreur' => "$fonction() introuvable : outil non activé !");
45 foreach ($textes as $i=>$t) {
47 $a["$i. test"] = htmlentities($t, ENT_COMPAT
, $GLOBALS['meta']['charset']);
48 // $a["\$resultat[$i]"] = htmlentities($b);
49 $a["$i. résultat"] = str_replace("\n",'\n', $b);
54 // affiche un cadre de titre $titre base sur les donnees de $array
55 function test_outil($array, $titre) {
58 echo "<a id=$i></a>",debut_cadre_trait_couleur($icone,true,'',"$i. $titre");
59 foreach($array as $s=>$v) if(is_array($v))
60 foreach($v as $s2=>$v2) echo "\n<b>{$s}[$s2]</b> = ".trim($v2)."<br />";
61 else echo "\n<b>$s</b> = ".trim($v)."<br />";
62 echo fin_cadre_trait_couleur(true);
65 // affiche un text en rouge
66 function cs_red($s){ return "<span style='color:red;'>$s</span>"; }
68 // effectue tous les tests !
69 function cs_les_tests() {
70 global $icone, $metas_vars, $metas_outils;
71 $icone = find_in_path('img/couteau-24.gif');
73 test_outil($_SERVER, 'Echo de : $_SERVER[]');
74 test_outil($_ENV, 'Echo de : $_ENV[]');
75 global $HTTP_ENV_VARS;
76 test_outil($HTTP_ENV_VARS, 'Echo de : $HTTP_ENV_VARS');
77 $a = array('DOCUMENT_ROOT'=>getenv('DOCUMENT_ROOT'),
78 'REQUEST_URI'=>getenv('REQUEST_URI'),
79 'SCRIPT_NAME'=>getenv('SCRIPT_NAME'),
80 'PHP_SELF'=>getenv('PHP_SELF'),
82 test_outil($a, 'Echo de : getenv()');
84 // lecture des variables stockees en meta
85 test_outil($metas_outils, 'Outils actifs : $metas_outils[]');
86 test_outil($metas_vars, 'Contenu des variables : $metas_vars[]');
88 // test de url_absolue()
89 $relative_path = find_in_path('img/smileys');
90 $realpath = str_replace("\\", "/", realpath($relative_path));
91 $root = preg_replace(',/$,', '', $_SERVER['DOCUMENT_ROOT']);
92 $test_result=substr($realpath, strlen($root));
93 $dir = dirname(!empty($_SERVER['REQUEST_URI']) ?
$_SERVER['REQUEST_URI'] :
94 (!empty($_SERVER['PHP_SELF']) ?
$_SERVER['PHP_SELF'] :
95 (!empty($_SERVER['SCRIPT_NAME']) ?
$_SERVER['SCRIPT_NAME'] : str_replace('\\','/',__FILE__
)
97 $a = array('DOCUMENT_ROOT'=>$_SERVER['DOCUMENT_ROOT'],
98 'REQUEST_URI'=>$_SERVER['REQUEST_URI'],
99 'SCRIPT_NAME'=>$_SERVER['SCRIPT_NAME'],
100 'PHP_SELF'=>$_SERVER['PHP_SELF'],
101 '__FILE__'=>__FILE__
,
103 "find_in_path('img/smileys')"=>find_in_path('img/smileys'),
104 "str_replace('\\', '/', realpath('$relative_path'))"=>$realpath,
105 "substr('$realpath', strlen('$root'))"=>cs_red($test_result),
106 "return?"=>(strlen($root) && strpos($realpath, $root)===0)?
'oui':'non',
107 "url_absolue('$relative_path')"=>url_absolue($relative_path),
109 "cs_canonicalize('$dir'.'/'.'$relative_path')"=>cs_red(cs_canonicalize($dir.'/'.$relative_path)),
111 test_outil($a, 'Test sur : url_absolue()');
113 // test de cs_canonicalize()
114 $dir = $dir.'/'.$relative_path;
115 $address = str_replace("//", "/", $dir);
116 $address1 = $address2 = explode('/', $address);
117 $keys = array_keys($address2, '..');
118 foreach($keys as $keypos => $key) array_splice($address2, $key - ($keypos * 2 +
1), 2);
119 $address3 = preg_replace(',([^.])\./,', '\1', implode('/', $address2));
120 $a = array('$dir'=>$dir,
121 '$address'=>$address,
122 "explode('/', '$address')"=>$address1,
123 'array_keys($dessus, "..")'=>$keys,
124 'array_spliced()'=>$address2,
125 '$resultat'=>cs_red($address3),
127 test_outil($a, 'Test sur : cs_canonicalize()');
129 // charger mes_fonctions, utile pour les filtres ou certains outils
130 include_spip('public/parametrer');
132 // test de typo_exposants()
133 include_spip('inc/charsets');
135 "Pr Paul, Dr Jules, Prs Pierre & Paul, Drs Pierre & Paul. Surveiller : Pré-St-Gervais ou Dré",
136 "Ste Lucie, St-Lucien, St.Patrick, St Patrick, st-jules (laisser?), Sts Pierre & Paul, STe Lucie (laisser?)",
137 "Bse Lucie, Bx-Lucien, Bx.Patrick, Bx Patrick, bx-jules (laisser?), Bses Jeanne & Julie",
138 "Ier, Iers, Iier, Iiers, Ire (laisser?), Ires (laisser?), Ière, 1ière, 1ères, 1ières",
139 unicode2charset("Accents : Ière, 1ière, 1ères, 1ières - ro, vo, rro, 1o, 2o, 22o, Mgr J.XXIII"),
140 unicode2charset("Ie IIème IIIe IVe Ve VIe VIIe VIIIe IXe Xe XIe XVe XXe"),
141 unicode2charset("Erreurs de typo : 2me, 3ème, 4ième, 5mes, 6èmes, 7ièmes"),
142 unicode2charset("Cas problématique du L (50) : XLe XLème XLième Lème LIe"),
143 "1er 1ers, 1eres, 2e 2es, IIIe IIIes, 2nd 22nd 21nd 2ndes. Vve Martin Cie Tartuffe, 3 Bd Voltaire.",
144 "3 ou 4 m², 3 ou 4 m2 et 2 m3. 50 Mds ou 50 Mns ! Sté, Stés, Stés, Ste, Ets, Éts, Éts, Éts, Éts ...",
145 "Mlle, Mlles, Mme, Mmes et erreurs Melle, Melles",
146 "Me, Me martin, Me Martin, Mes M.&T., MMes M.&T.",
147 'avant <a href="www.mon-1er-lien.com" title="Mon 1er titre">Mon 1er lien</a> et <img src="image.jpg" alt="logo 6e" title="Cliquez!">',
148 'avant [Mon 1er lien->www.mon-1er-lien.com] apres le "test"!',
149 'on est passé du 7e au 15e rang, pas du 17e au 5e, des 7es aux 3emes !',
150 'on est passé du 7eme au 15ème rang, pas du 17ieme au 5ème',
152 test_outil(cs_test_fun($textes, 'typo_exposants'), 'Test sur : typo_exposants() - Charset du site : '.$GLOBALS['meta']['charset']);
154 // test de typo_guillemets()
156 'avant <i class="style">le</i> "test"!',
157 'avant <code class="code">toto</code>. apres le "test"!',
158 'avant '.echappe_html('<script>toto</script>', 'TEST', true).'apres le "test"!',
159 'avant '.echappe_html('<code class="code">toto</code>', 'TEST', true).'apres le "test"!',
160 'avant <a href="www.monlien.com" title="Mon titre" target="_blank">Mon lien</a> apres le "test"!',
161 'avant [Mon lien->www.monlien.com] apres le "test"!',
163 test_outil(cs_test_fun($textes, 'typo_guillemets'), 'Test sur : typo_guillemets()');
167 "Doubles : :-(( :-)) :)) :'-)) :\92-))",
168 "Simples : :-> :-> :-( :-D :-) |-) :'-) :\92-) :'-D :\92-D :'-( :\92-( :-( :o) B-) ;-) :-p :-P' :-| :-/ :-o :-O",
169 "les courts (reconnus s'il y a un espace avant) : :) :( ;) :| |) :/ :(",
171 test_outil(cs_test_fun($textes, 'cs_smileys_pre_typo'), 'Test sur : cs_smileys_pre_typo()');
175 "__degrade.png__\n__ornement.png__",
176 "\n__6__\n__5__\n__4__\n__3__\n__2__\n__1__\n__0__\n",
178 if(function_exists('filets_sep'))
179 test_outil(cs_test_fun($textes, create_function('$t','return propre(filets_sep($t));')), 'Test sur : filets_sep()');
181 // test des liens orphelins
182 $GLOBALS["liens_orphelins_etendu"]=true;
184 "http://google.fr et <html>http://google.fr</html> et <code>http://google.fr</code> et <cite>http://google.fr</cite>",
185 "Voici : http://google.fr. Voici :http://www.google.fr. Voici http://www.google.fr",
186 "voici : https://mabanque.fr ou encore ftp://mabanque.fr!",
187 "www.google.fr ou bien : www.google.fr",
188 "http://user:password@www.commentcamarche.net:80/glossair/glossair.php3 et http://serveur:port/repertoire/fichier.html",
189 "ftp://serveur/repertoire/fichier.qqchose, ou encore ftp.stockage.fr/tropdelaballe...",
190 "file:///disque|/repertoire/fichier.qqchose et : file:///c|/tmp/fichier.txt",
191 "mailto:nom@organisation.domaine et : mailto:Fabien.Gandon@sophia.inria.fr",
192 "telnet://bbs.monsite.com/ et telnet://Nom:Password@serveur.ici:port",
193 "telnet://gandonf:abcde@gopa.insa.fr:23",
194 "gopher://serveur.ici:port/repertoire/fichier#marqueur et gopher://gopher.monsite.com/",
195 "newsrc://serveur:port/repertoire/nom.de.la.news",
196 "wais://host.ici:port/database et wais://wais.monsite.com/",
197 "news:fr.comp.lang.c++ et pkoi pas : <div toto='ici.rien'></div>http://google.fr",
198 "moi+moi@world.com, mailto:moi-moi@world.com, mailto:nom@provider.com?subject=renseignement",
199 "moi+moi@kekpar.tm.fr, mailto:moi-moi@kekpar.tm.fr, mailto:nom@provider.com.tm.fr?subject=renseignement",
200 'une image ? <img src="http://mailer.e-flux.com/mail_images/toto.jpg" alt="" />',
201 '[<img src="http://mailer.e-flux.com/mail_images/toto.jpg" alt="" />->http://www.americas-society.org/] ',
203 // test_outil(cs_test_fun($textes, 'typo'), 'Test sur : echappements');
204 test_outil(cs_test_fun($textes, 'liens_orphelins'), 'Test sur : liens_orphelins()');
207 "mailto:nom@organisation.domaine et : mailto:Fabien.Gandon@sophia.inria.fr (on supprime ces liens)",
208 "moi+moi@world.com, mailto:moi-moi@world.com, mailto:nom@provider.com?subject=renseignement",
209 "pat@moi.com [->pat@moi.com] [pat->pat@moi.com]",
210 "pat@moi.com.tm.fr [->pat@moi.com.tm.fr] [pat->pat@moi.com.tm.fr]",
211 "<a href='mailto:moi@toto.com'>Moi</a> et : <a href='mailto:moi@toto.com'>moi@toto.com</a>",
212 "<a href='mailto:moi@kekpar.tm.fr'>Moi</a> et : <a href='mailto:moi@kekpar.tm.fr'>moi@kekpar.tm.fr</a>",
213 '[Navigation->/@mot.html] <a class="spip_out" href="/@mot.html">Navigation</a>',
215 test_outil(cs_test_fun($textes, 'mailcrypt'), 'Test sur : mailcrypt()');
218 define('_COULEURS_FONDS', 1); define('_COULEURS_SET', 1);
219 define('_COULEURS_PERSO', "bas =#99CC11, haut= brown, test= bleu");
220 couleurs_installe_dist();
221 print_r(couleurs_pre_typo("to[bas]to[/bas]to[haut]to[/haut]toto[test]to[/couleur]to\nto[bg bas]to[/bg]to[bg haut]to[/bg]toto[bg test]to[/bg test]to\n"));
222 print_r(couleurs_pre_typo("to[red]to[/red]to[bleu]to[/bleu]toto[rouge]to[/couleur]to\nto[bg red]to[/bg]to[bg bleu]to[/bg]toto[bg rouge]to[/bg rouge]to\n"));