1 |
<?php |
2 |
/** |
3 |
* Ce fichier regroupe les tests unitaire général à l'application OpenADS |
4 |
* |
5 |
* @package openfoncier |
6 |
* @version SVN : $Id$ |
7 |
*/ |
8 |
|
9 |
/** |
10 |
* Cette classe permet de tester unitairement les fonctions de l'application. |
11 |
*/ |
12 |
class General extends PHPUnit_Framework_TestCase { |
13 |
|
14 |
/** |
15 |
* Méthode lancée en début de traitement |
16 |
*/ |
17 |
public function setUp() { |
18 |
|
19 |
// Instancie la timezone |
20 |
date_default_timezone_set('Europe/Paris'); |
21 |
} |
22 |
|
23 |
/** |
24 |
* Méthode lancée en fin de traitement |
25 |
*/ |
26 |
public function tearDown() { |
27 |
|
28 |
// |
29 |
} |
30 |
|
31 |
/** |
32 |
* Test la fonction mois_date() de la classe Utils. |
33 |
*/ |
34 |
public function test_utils_mois_date() { |
35 |
// Instance de la classe Utils |
36 |
require_once "../obj/utils.class.php"; |
37 |
$_SESSION['collectivite'] = 1; |
38 |
$_SESSION['login'] = "admin"; |
39 |
$_SERVER['REQUEST_URI'] = ""; |
40 |
$f = new utils("nohtml"); |
41 |
|
42 |
// Avec des mois |
43 |
|
44 |
// Pour les additions |
45 |
// Initialisation des tableaux |
46 |
$tab_date_dep = array(); |
47 |
$tab_delay = array(); |
48 |
$tab_date_fin = array(); |
49 |
|
50 |
// Tableau des date de départ |
51 |
$tab_date_dep = array( |
52 |
0 => "2013-12-31", |
53 |
1 => "2014-01-31", |
54 |
2 => "2014-01-01", |
55 |
3 => "2014-01-31", |
56 |
4 => "2015-12-31", |
57 |
5 => "", |
58 |
6 => "", |
59 |
7 => "", |
60 |
8 => "2015-12-31", |
61 |
9 => "2015-12-31", |
62 |
10 => "openADS", |
63 |
11 => "openADS", |
64 |
12 => "openADS", |
65 |
); |
66 |
// Tableau des delais |
67 |
$tab_delay = array( |
68 |
0 => "2", |
69 |
1 => "5", |
70 |
2 => "12", |
71 |
3 => "27", |
72 |
4 => "2", |
73 |
5 => "2", |
74 |
6 => "openads", |
75 |
7 => "", |
76 |
8 => "openADS", |
77 |
9 => "", |
78 |
10 => "2", |
79 |
11 => "openads", |
80 |
12 => "", |
81 |
); |
82 |
// Tableau des date résultat |
83 |
$tab_date_fin = array( |
84 |
0 => "2014-02-28", |
85 |
1 => "2014-06-30", |
86 |
2 => "2015-01-01", |
87 |
3 => "2016-04-30", |
88 |
4 => "2016-02-29", |
89 |
5 => null, |
90 |
6 => null, |
91 |
7 => null, |
92 |
8 => "2015-12-31", |
93 |
9 => "2015-12-31", |
94 |
10 => null, |
95 |
11 => null, |
96 |
12 => null, |
97 |
); |
98 |
|
99 |
// Pour chaque date |
100 |
foreach ($tab_date_dep as $key => $date_dep) { |
101 |
// Calcul la date résultat |
102 |
$date_fin = $f->mois_date($date_dep, $tab_delay[$key], "+"); |
103 |
// Vérifie que la date résultat est correct |
104 |
$this->assertEquals($date_fin, $tab_date_fin[$key]); |
105 |
} |
106 |
|
107 |
// Pour les soustractions |
108 |
// Initialisation des tableaux |
109 |
$tab_date_dep = array(); |
110 |
$tab_delay = array(); |
111 |
$tab_date_fin = array(); |
112 |
|
113 |
// Tableau des date de départ |
114 |
$tab_date_dep = array( |
115 |
0 => "2014-01-31", |
116 |
); |
117 |
// Tableau des delais |
118 |
$tab_delay = array( |
119 |
0 => "4", |
120 |
); |
121 |
// Tableau des date résultat |
122 |
$tab_date_fin = array( |
123 |
0 => "2013-09-30", |
124 |
); |
125 |
|
126 |
// Pour chaque date |
127 |
foreach ($tab_date_dep as $key => $date_dep) { |
128 |
// Calcul la date résultat |
129 |
$date_fin = $f->mois_date($date_dep, $tab_delay[$key], "-"); |
130 |
// Vérifie que la date résultat est correct |
131 |
$this->assertEquals($date_fin, $tab_date_fin[$key]); |
132 |
} |
133 |
|
134 |
// Avec des jours |
135 |
|
136 |
// Pour les additions |
137 |
// Initialisation des tableaux |
138 |
$tab_date_dep = array(); |
139 |
$tab_delay = array(); |
140 |
$tab_date_fin = array(); |
141 |
|
142 |
// Tableau des date de départ |
143 |
$tab_date_dep = array( |
144 |
0 => "2013-12-31", |
145 |
1 => "2014-01-31", |
146 |
2 => "2014-01-01", |
147 |
3 => "2014-01-31", |
148 |
4 => "2015-12-31", |
149 |
5 => "", |
150 |
6 => "", |
151 |
7 => "", |
152 |
8 => "2015-12-31", |
153 |
9 => "2015-12-31", |
154 |
10 => "openADS", |
155 |
11 => "openADS", |
156 |
12 => "openADS", |
157 |
); |
158 |
// Tableau des delais |
159 |
$tab_delay = array( |
160 |
0 => "2", |
161 |
1 => "5", |
162 |
2 => "12", |
163 |
3 => "27", |
164 |
4 => "2", |
165 |
5 => "2", |
166 |
6 => "openads", |
167 |
7 => "", |
168 |
8 => "openADS", |
169 |
9 => "", |
170 |
10 => "2", |
171 |
11 => "openads", |
172 |
12 => "", |
173 |
); |
174 |
// Tableau des dates résultats |
175 |
$tab_date_fin = array( |
176 |
0 => "2014-01-02", |
177 |
1 => "2014-02-05", |
178 |
2 => "2014-01-13", |
179 |
3 => "2014-02-27", |
180 |
4 => "2016-01-02", |
181 |
5 => null, |
182 |
6 => null, |
183 |
7 => null, |
184 |
8 => "2015-12-31", |
185 |
9 => "2015-12-31", |
186 |
10 => null, |
187 |
11 => null, |
188 |
12 => null, |
189 |
); |
190 |
|
191 |
// Pour chaque date |
192 |
foreach ($tab_date_dep as $key => $date_dep) { |
193 |
// Calcul la date résultat |
194 |
$date_fin = $f->mois_date($date_dep, $tab_delay[$key], "+", "jour"); |
195 |
// Vérifie que la date résultat est correct |
196 |
$this->assertEquals($date_fin, $tab_date_fin[$key]); |
197 |
} |
198 |
|
199 |
// Pour les soustractions |
200 |
// Initialisation des tableaux |
201 |
$tab_date_dep = array(); |
202 |
$tab_delay = array(); |
203 |
$tab_date_fin = array(); |
204 |
|
205 |
// Tableau des date de départ |
206 |
$tab_date_dep = array( |
207 |
0 => "2014-01-31", |
208 |
); |
209 |
// Tableau des delais |
210 |
$tab_delay = array( |
211 |
0 => "4", |
212 |
); |
213 |
// Tableau des date résultat |
214 |
$tab_date_fin = array( |
215 |
0 => "2014-01-27", |
216 |
); |
217 |
|
218 |
// Pour chaque date |
219 |
foreach ($tab_date_dep as $key => $date_dep) { |
220 |
// Calcul la date résultat |
221 |
$date_fin = $f->mois_date($date_dep, $tab_delay[$key], "-", "jour"); |
222 |
// Vérifie que la date résultat est correct |
223 |
$this->assertEquals($date_fin, $tab_date_fin[$key]); |
224 |
} |
225 |
|
226 |
// Destruction de la classe Utils |
227 |
$f->__destruct(); |
228 |
} |
229 |
|
230 |
} |
231 |
|
232 |
?> |