[SPIP] +2.1.12
[velocampus/web/www.git] / www / plugins / auto / cfg / tests / depot_php.php
1 <?php
2 if (!defined("_ECRIRE_INC_VERSION")) return;
3
4 // nom du test
5 $test = 'cfg:depot_php';
6
7 // recherche test.inc qui nous ouvre au monde spip
8 $deep = 2;
9 $include = '../../tests/test.inc';
10 while (!defined('_SPIP_TEST_INC') && $deep++ < 6) {
11 $include = '../' . $include;
12 @include $include;
13 }
14 if (!defined('_SPIP_TEST_INC')) {
15 die("Pas de $include");
16 }
17
18
19 ### lire_config ###
20
21 // les bases de test
22 $assoc = array(
23 'one' => 'element 1',
24 'two' => 'element 2',
25 'three' => array('un'=>1, 'deux'=>2, 'troisc'=>"3")
26
27 );
28
29 ### ecrire_config ###
30
31 $essais = array();
32 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_zero', 0);
33 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_zeroc', '0');
34 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_chaine', 'une chaine');
35 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_assoc', $assoc);
36 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_serie', serialize($assoc));
37 // chemins
38 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_chemin/casier', $assoc);
39 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_chemin/casier/truc', 'trac');
40
41 $err = tester_fun('ecrire_config', $essais);
42
43 // si le tableau $err est pas vide ca va pas
44 if ($err) {
45 die ('<b>ecrire_config php</b><dl>' . join('', $err) . '</dl>');
46 }
47
48 ### re lire_config ###
49
50 $essais = array();
51 $essais[] = array(0, 'php::tests_cfg_php/test_cfg_zero');
52 $essais[] = array('0', 'php::tests_cfg_php/test_cfg_zeroc');
53 $essais[] = array('une chaine', 'php::tests_cfg_php/test_cfg_chaine');
54 $essais[] = array($assoc, 'php::tests_cfg_php/test_cfg_assoc');
55 $essais[] = array(serialize($assoc), 'php::tests_cfg_php/test_cfg_serie');
56 // chemins
57 $essais[] = array($assoc + array('truc'=>'trac'), 'php::tests_cfg_php/test_cfg_chemin/casier');
58 $essais[] = array('trac', 'php::tests_cfg_php/test_cfg_chemin/casier/truc');
59 $essais[] = array(1, 'php::tests_cfg_php/test_cfg_chemin/casier/three/un');
60 // chemin pas la
61 $essais[] = array(null, 'php::tests_cfg_php/test_cfg_chemin/casier/three/huit');
62
63 $err = tester_fun('lire_config', $essais);
64
65 // si le tableau $err est pas vide ca va pas
66 if ($err) {
67 die ('<b>relecture ecrire_config php</b><dl>' . join('', $err) . '</dl>');
68 }
69
70 ### re effacer_config ###
71
72 $essais = array();
73 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_zero');
74 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_zeroc');
75 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_chaine');
76 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_assoc');
77 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_serie');
78 // chemins
79 // on enleve finement tout test_cfg_chemin : il ne doit rien rester
80 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_chemin/casier/three/huit'); // n'existe pas
81 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_chemin/casier/three/troisc');
82 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_chemin/casier/three/deux');
83 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_chemin/casier/three/un'); // supprime three
84 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_chemin/casier/one');
85 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_chemin/casier/two');
86 $essais[] = array(true, 'php::tests_cfg_php/test_cfg_chemin/casier/truc'); // supprimer chemin/casier
87
88 $err = tester_fun('effacer_config', $essais);
89
90 // si le tableau $err est pas vide ca va pas
91 if ($err) {
92 die ('<b>effacer_config php</b><dl>' . join('', $err) . '</dl>');
93 }
94
95
96 ### re lire_config ###
97
98 $essais = array();
99 $essais[] = array(null, 'php::tests_cfg_php/test_cfg_zero');
100 $essais[] = array(null, 'php::tests_cfg_php/test_cfg_zeroc');
101 $essais[] = array(null, 'php::tests_cfg_php/test_cfg_chaine');
102 $essais[] = array(null, 'php::tests_cfg_php/test_cfg_assoc');
103 $essais[] = array(null, 'php::tests_cfg_php/test_cfg_serie');
104 $essais[] = array(null, 'php::tests_cfg_php/test_cfg_chemin');
105 $essais[] = array(null, 'php::tests_cfg_php');
106
107 $err = tester_fun('lire_config', $essais);
108
109 // si le tableau $err est pas vide ca va pas
110 if ($err) {
111 die ('<b>relecture effacer_config php</b><dl>' . join('', $err) . '</dl>');
112 }
113
114 echo "OK";
115
116 ?>