1 |
fmichon |
9227 |
<?php |
2 |
|
|
/** |
3 |
|
|
* Ce script contient la définition de la classe 'DigitalizedDocumentCommon'. |
4 |
|
|
* |
5 |
|
|
* @package openads |
6 |
|
|
* @version SVN : $Id$ |
7 |
|
|
*/ |
8 |
|
|
|
9 |
softime |
9282 |
require_once "../tests/resources/omtestcase.class.php"; |
10 |
|
|
require_once "../obj/digitalizedDocument.class.php"; |
11 |
fmichon |
9227 |
|
12 |
softime |
9282 |
|
13 |
fmichon |
9227 |
/** |
14 |
|
|
* Cette classe permet de faire des tests unitaires sur la classe DigitalizedDocument |
15 |
|
|
* |
16 |
|
|
* La constante DEBUG doit être définis sur DEGUG_MODE ou PRODUCTION_MODE |
17 |
|
|
* |
18 |
|
|
* Lors de l'envoi de la commande ajouter --bootstrap bootstrap.php |
19 |
|
|
* |
20 |
|
|
* Jeu de données utilisé : |
21 |
|
|
* Le dossier d'instruction PC0130551200001P0 et PC0130551200002P0 du jeu de données de |
22 |
|
|
* base, ainsi que les dossiers sans P0 PA0130551200001 et DP0130551200001 |
23 |
|
|
* les dossiers et document présent dans binary_files/test_digitalizedDocument |
24 |
|
|
*/ |
25 |
softime |
9282 |
abstract class DigitalizedDocumentCommon extends OMTestCase { |
26 |
fmichon |
9227 |
|
27 |
|
|
/** |
28 |
|
|
* Fonction lancée en début de classe |
29 |
|
|
*/ |
30 |
|
|
public static function common_setUpBeforeClass() { |
31 |
softime |
9282 |
|
32 |
fmichon |
9227 |
// Création des dossiers PC0130551200001.P0 et PC0130551200002 dans le |
33 |
|
|
// dossier de numérisation |
34 |
|
|
mkdir('../var/digitalization/Todo/PC0130551200001.P0/'); |
35 |
|
|
chmod('../var/digitalization/Todo/PC0130551200001.P0/', 0777); |
36 |
|
|
mkdir('../var/digitalization/Todo/PC0130551200002.P0/'); |
37 |
|
|
chmod('../var/digitalization/Todo/PC0130551200002.P0/', 0777); |
38 |
|
|
// Récupération du document |
39 |
|
|
copy('binary_files/20091106AUTPCP.pdf', '../var/digitalization/Todo/PC0130551200001.P0/20091106AUTPCP.pdf'); |
40 |
|
|
copy('binary_files/20091106AUTPCP-1.pdf', '../var/digitalization/Todo/PC0130551200001.P0/20091106AUTPCP-1.pdf'); |
41 |
softime |
10573 |
copy('binary_files/20121212PC31_1.pdf', '../var/digitalization/Todo/PC0130551200001.P0/20121212PC31_1.pdf'); |
42 |
|
|
copy('binary_files/20121212PC31_1-1.pdf', '../var/digitalization/Todo/PC0130551200001.P0/20121212PC31_1-1.pdf'); |
43 |
|
|
copy('binary_files/20130207F6.pdf', '../var/digitalization/Todo/PC0130551200001.P0/20130207F6.pdf'); |
44 |
fmichon |
9227 |
// Création des dossiers sans le suffixe P0 |
45 |
|
|
mkdir('../var/digitalization/Todo/PA0130551200001/'); |
46 |
|
|
chmod('../var/digitalization/Todo/PA0130551200001/', 0777); |
47 |
|
|
mkdir('../var/digitalization/Todo/DP0130551200001/'); |
48 |
|
|
chmod('../var/digitalization/Todo/DP0130551200001/', 0777); |
49 |
|
|
// Récupération du document |
50 |
|
|
copy('binary_files/20091106AUTPCP.pdf', '../var/digitalization/Todo/PA0130551200001/20091106AUTPCP.pdf'); |
51 |
|
|
copy('binary_files/20091106AUTPCP-1.pdf', '../var/digitalization/Todo/PA0130551200001/20091106AUTPCP-1.pdf'); |
52 |
softime |
10573 |
copy('binary_files/20121212PC31_1.pdf', '../var/digitalization/Todo/PA0130551200001/20121212PC31_1.pdf'); |
53 |
|
|
copy('binary_files/20121212PC31_1-1.pdf', '../var/digitalization/Todo/PA0130551200001/20121212PC31_1-1.pdf'); |
54 |
|
|
copy('binary_files/20130207F6.pdf', '../var/digitalization/Todo/PA0130551200001/20130207F6.pdf'); |
55 |
fmichon |
9227 |
} |
56 |
|
|
|
57 |
|
|
/** |
58 |
|
|
* Fonction lancée en fin de classe |
59 |
|
|
*/ |
60 |
|
|
public static function common_tearDownAfterClass() { |
61 |
|
|
// Suppression du document 20091106AUTPCP.pdf |
62 |
|
|
unlink('../var/digitalization/Todo/PC0130551200001.P0/20091106AUTPCP.pdf'); |
63 |
|
|
unlink('../var/digitalization/Todo/PC0130551200001.P0/20091106AUTPCP-1.pdf'); |
64 |
|
|
unlink('../var/digitalization/Todo/PA0130551200001/20091106AUTPCP.pdf'); |
65 |
|
|
unlink('../var/digitalization/Todo/PA0130551200001/20091106AUTPCP-1.pdf'); |
66 |
|
|
|
67 |
|
|
// Suppression des dossiers PC0130551200001.P0 et PC0130551200002.P0 |
68 |
|
|
if(file_exists('../var/digitalization/Todo/PC0130551200001.P0')) { |
69 |
|
|
rmdir('../var/digitalization/Todo/PC0130551200001.P0'); |
70 |
|
|
} |
71 |
|
|
if(file_exists('../var/digitalization/Todo/PC0130551200002.P0')) { |
72 |
|
|
rmdir('../var/digitalization/Todo/PC0130551200002.P0'); |
73 |
|
|
} |
74 |
|
|
// Suppression des dossiers sans P0 |
75 |
|
|
if(file_exists('../var/digitalization/Todo/PA0130551200001')) { |
76 |
|
|
rmdir('../var/digitalization/Todo/PA0130551200001'); |
77 |
|
|
} |
78 |
|
|
if(file_exists('../var/digitalization/Todo/DP0130551200001')) { |
79 |
|
|
rmdir('../var/digitalization/Todo/DP0130551200001'); |
80 |
|
|
} |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
/** |
84 |
|
|
* Méthode lancée en fin de traitement |
85 |
|
|
*/ |
86 |
|
|
public function common_tearDown() { |
87 |
softime |
9282 |
parent::common_tearDown(); |
88 |
softime |
13528 |
// |
89 |
softime |
9282 |
$this->clean_session(); |
90 |
fmichon |
9227 |
} |
91 |
|
|
|
92 |
|
|
/** |
93 |
softime |
14064 |
* Est-ce que l'uid passé en paramètre est lié à un enregistrement *document_numerise* ? |
94 |
|
|
* |
95 |
|
|
* @param string $uid Identifiant d'un fichier dans le système de stockage. |
96 |
|
|
* |
97 |
|
|
* @return boolean |
98 |
fmichon |
9227 |
*/ |
99 |
softime |
13528 |
private function checkLinkFile($f, $uid) { |
100 |
softime |
14064 |
$qres = $f->get_one_result_from_db_query( |
101 |
|
|
sprintf( |
102 |
|
|
'SELECT |
103 |
|
|
document_numerise |
104 |
|
|
FROM |
105 |
|
|
%1$sdocument_numerise |
106 |
|
|
WHERE |
107 |
|
|
uid = \'%2$s\'', |
108 |
|
|
DB_PREFIXE, |
109 |
|
|
$f->db->escapeSimple($uid) |
110 |
|
|
), |
111 |
|
|
array( |
112 |
|
|
"origin" => __METHOD__, |
113 |
|
|
) |
114 |
|
|
); |
115 |
|
|
if ($qres["result"]) { |
116 |
fmichon |
9227 |
return true; |
117 |
|
|
} |
118 |
|
|
return false; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
/** |
122 |
softime |
14064 |
* Retourne l'identifant du fichier dans le système de stockage lié à l'enregistrement *document_numerise* passé en paramètre. |
123 |
|
|
* |
124 |
|
|
* @param integer $document_numerise Identifiant de l'enregistrement *document_numerise*. |
125 |
|
|
* |
126 |
|
|
* @return string|null |
127 |
fmichon |
9227 |
*/ |
128 |
softime |
13528 |
private function get_uid_by_id($f, $document_numerise) { |
129 |
softime |
14064 |
$qres = $f->get_one_result_from_db_query( |
130 |
|
|
sprintf( |
131 |
|
|
'SELECT |
132 |
|
|
uid |
133 |
|
|
FROM |
134 |
|
|
%1$sdocument_numerise |
135 |
|
|
WHERE |
136 |
|
|
document_numerise=%2$d', |
137 |
|
|
DB_PREFIXE, |
138 |
|
|
intval($document_numerise) |
139 |
|
|
), |
140 |
|
|
array( |
141 |
|
|
"origin" => __METHOD__, |
142 |
|
|
) |
143 |
|
|
); |
144 |
|
|
return $qres["result"]; |
145 |
fmichon |
9227 |
} |
146 |
|
|
|
147 |
|
|
/** |
148 |
|
|
* Test la fonction listFiles |
149 |
|
|
*/ |
150 |
|
|
public function testListFiles() { |
151 |
softime |
13528 |
// Instanciation de la classe *om_application* |
152 |
|
|
$f = $this->get_inst_om_application("admin", "admin"); |
153 |
|
|
$f->disableLog(); |
154 |
|
|
$digitalizedDocument = new DigitalizedDocument($f); |
155 |
fmichon |
9227 |
//Nom possible de dossier |
156 |
|
|
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
157 |
|
|
$path_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
158 |
|
|
|
159 |
|
|
//Retour de la fonction listFiles |
160 |
softime |
13528 |
$listFiles = $digitalizedDocument->listFiles($path); |
161 |
|
|
$listFiles_no_p0 = $digitalizedDocument->listFiles($path_no_p0); |
162 |
fmichon |
9227 |
//On vérifie les documents retourné |
163 |
|
|
$this->assertContains("20091106AUTPCP-1.pdf", $listFiles); |
164 |
|
|
$this->assertContains("20091106AUTPCP.pdf", $listFiles); |
165 |
softime |
10573 |
$this->assertContains("20121212PC31_1.pdf", $listFiles); |
166 |
|
|
$this->assertContains("20121212PC31_1-1.pdf", $listFiles); |
167 |
|
|
$this->assertContains("20130207F6.pdf", $listFiles); |
168 |
fmichon |
9227 |
// Même chose pour les dossiers sans P0 |
169 |
|
|
$this->assertContains("20091106AUTPCP-1.pdf", $listFiles_no_p0); |
170 |
|
|
$this->assertContains("20091106AUTPCP.pdf", $listFiles_no_p0); |
171 |
softime |
10573 |
$this->assertContains("20121212PC31_1.pdf", $listFiles_no_p0); |
172 |
|
|
$this->assertContains("20121212PC31_1-1.pdf", $listFiles_no_p0); |
173 |
|
|
$this->assertContains("20130207F6.pdf", $listFiles_no_p0); |
174 |
fmichon |
9227 |
|
175 |
|
|
//Nom de dossier vide |
176 |
|
|
$path = "../var/digitalization/Todo/PC0130551200002.P0"; |
177 |
|
|
$path_no_p0 = "../var/digitalization/Todo/DP0130551200001"; |
178 |
|
|
//Retour de la fontion listFiles |
179 |
softime |
13528 |
$listFiles = $digitalizedDocument->listFiles($path); |
180 |
|
|
$listFiles_no_p0 = $digitalizedDocument->listFiles($path_no_p0); |
181 |
fmichon |
9227 |
//On vérifie que le tableau retourné est vide |
182 |
|
|
$this->assertEquals($listFiles, null); |
183 |
|
|
$this->assertEquals($listFiles_no_p0, null); |
184 |
softime |
13528 |
$digitalizedDocument->__destruct(); |
185 |
|
|
// Destruction de la classe *om_application* |
186 |
|
|
$f->__destruct(); |
187 |
fmichon |
9227 |
} |
188 |
|
|
|
189 |
|
|
/* |
190 |
|
|
* Test la fonction extractMetadataFromFilename |
191 |
|
|
*/ |
192 |
|
|
public function testExtractMetadataFromFilename() { |
193 |
softime |
13528 |
// Instanciation de la classe *om_application* |
194 |
|
|
$f = $this->get_inst_om_application("admin", "admin"); |
195 |
|
|
$f->disableLog(); |
196 |
|
|
$digitalizedDocument = new DigitalizedDocument($f); |
197 |
fmichon |
9227 |
//Nom possible de document |
198 |
|
|
$filename = "20091106AUTPCP.pdf"; |
199 |
|
|
//Retour de la fonction extractMetadataFromFilename |
200 |
softime |
13528 |
$extractMetadataFromFilename = $digitalizedDocument->extractMetadataFromFilename($filename); |
201 |
fmichon |
9227 |
//On vérifie les données retournées |
202 |
|
|
$this->assertEquals($extractMetadataFromFilename["title"], "AUTPCP"); |
203 |
|
|
$this->assertEquals($extractMetadataFromFilename["dateEvenementDocument"], "06/11/2009"); |
204 |
|
|
|
205 |
|
|
//Nom possible de document avec version |
206 |
|
|
$filename = "20130420ART-1.pdf"; |
207 |
|
|
//Retour de la fonction extractMetadataFromFilename |
208 |
softime |
13528 |
$extractMetadataFromFilename = $digitalizedDocument->extractMetadataFromFilename($filename); |
209 |
fmichon |
9227 |
//On vérifie les données retournées |
210 |
|
|
$this->assertEquals($extractMetadataFromFilename["title"], "ART"); |
211 |
|
|
$this->assertEquals($extractMetadataFromFilename["dateEvenementDocument"], "20/04/2013"); |
212 |
softime |
10573 |
|
213 |
|
|
//Nom possible de document avec code de nomenclature externe |
214 |
|
|
$filename = "20121212PC31_1.pdf"; |
215 |
|
|
//Retour de la fonction extractMetadataFromFilename |
216 |
softime |
13528 |
$extractMetadataFromFilename = $digitalizedDocument->extractMetadataFromFilename($filename); |
217 |
softime |
10573 |
//On vérifie les données retournées |
218 |
|
|
$this->assertEquals($extractMetadataFromFilename["title"], "PC31_1"); |
219 |
|
|
$this->assertEquals($extractMetadataFromFilename["dateEvenementDocument"], "12/12/2012"); |
220 |
|
|
|
221 |
|
|
//Nom possible de document avec code de nomenclature externe et version |
222 |
|
|
$filename = "20121212PC31_1-1.pdf"; |
223 |
|
|
//Retour de la fonction extractMetadataFromFilename |
224 |
softime |
13528 |
$extractMetadataFromFilename = $digitalizedDocument->extractMetadataFromFilename($filename); |
225 |
softime |
10573 |
//On vérifie les données retournées |
226 |
|
|
$this->assertEquals($extractMetadataFromFilename["title"], "PC31_1"); |
227 |
|
|
$this->assertEquals($extractMetadataFromFilename["dateEvenementDocument"], "12/12/2012"); |
228 |
|
|
|
229 |
fmichon |
9227 |
//Nom erroné de document |
230 |
|
|
$filename = "20591212.pdf"; |
231 |
|
|
//Retour de la fonction extractMetadataFromFilename |
232 |
softime |
13528 |
$extractMetadataFromFilename = $digitalizedDocument->extractMetadataFromFilename($filename); |
233 |
fmichon |
9227 |
//On vérifie que le tableau retourné est vide |
234 |
|
|
$this->assertEquals($extractMetadataFromFilename, null); |
235 |
softime |
13528 |
$digitalizedDocument->__destruct(); |
236 |
|
|
// Destruction de la classe *om_application* |
237 |
|
|
$f->__destruct(); |
238 |
fmichon |
9227 |
} |
239 |
|
|
|
240 |
|
|
/** |
241 |
|
|
* Test la fonction extractMetadataToFilestorage |
242 |
|
|
*/ |
243 |
|
|
public function testExtractMetadataToFilestorage() { |
244 |
softime |
13528 |
// Instanciation de la classe *om_application* |
245 |
|
|
$f = $this->get_inst_om_application("admin", "admin"); |
246 |
|
|
$f->disableLog(); |
247 |
|
|
$digitalizedDocument = new DigitalizedDocument($f); |
248 |
fmichon |
9227 |
//Nom possible de dossier |
249 |
|
|
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
250 |
|
|
$path_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
251 |
|
|
//Nom possible de document |
252 |
|
|
$filename = "20091106AUTPCP.pdf"; |
253 |
|
|
//Retour de la fonction extractMetadataToFilestorage |
254 |
softime |
13528 |
$extractMetadataToFilestorage = $digitalizedDocument->extractMetadataToFilestorage($path, $filename); |
255 |
|
|
$extractMetadataToFilestorage_no_p0 = $digitalizedDocument->extractMetadataToFilestorage($path_no_p0, $filename); |
256 |
fmichon |
9227 |
//On vérifie les données retournées |
257 |
|
|
$this->assertEquals($extractMetadataToFilestorage['filename'], '20091106AUTPCP.pdf'); |
258 |
|
|
$this->assertEquals($extractMetadataToFilestorage['size'], '17435'); |
259 |
|
|
$this->assertEquals($extractMetadataToFilestorage['mimetype'], 'application/pdf'); |
260 |
|
|
// Pour le dossier sans P0 |
261 |
|
|
$this->assertEquals($extractMetadataToFilestorage_no_p0['filename'], '20091106AUTPCP.pdf'); |
262 |
|
|
$this->assertEquals($extractMetadataToFilestorage_no_p0['size'], '17435'); |
263 |
|
|
$this->assertEquals($extractMetadataToFilestorage_no_p0['mimetype'], 'application/pdf'); |
264 |
softime |
10573 |
|
265 |
|
|
//Nom possible de document avec une nomenclature externe |
266 |
|
|
$filename = "20121212PC31_1.pdf"; |
267 |
|
|
//Retour de la fonction extractMetadataToFilestorage |
268 |
softime |
13528 |
$extractMetadataToFilestorage = $digitalizedDocument->extractMetadataToFilestorage($path, $filename); |
269 |
|
|
$extractMetadataToFilestorage_no_p0 = $digitalizedDocument->extractMetadataToFilestorage($path_no_p0, $filename); |
270 |
softime |
10573 |
//On vérifie les données retournées |
271 |
|
|
$this->assertEquals($extractMetadataToFilestorage['filename'], '20121212PC31_1.pdf'); |
272 |
|
|
$this->assertEquals($extractMetadataToFilestorage['size'], '17435'); |
273 |
|
|
$this->assertEquals($extractMetadataToFilestorage['mimetype'], 'application/pdf'); |
274 |
|
|
// Pour le dossier sans P0 |
275 |
|
|
$this->assertEquals($extractMetadataToFilestorage_no_p0['filename'], '20121212PC31_1.pdf'); |
276 |
|
|
$this->assertEquals($extractMetadataToFilestorage_no_p0['size'], '17435'); |
277 |
|
|
$this->assertEquals($extractMetadataToFilestorage_no_p0['mimetype'], 'application/pdf'); |
278 |
|
|
|
279 |
fmichon |
9227 |
//Chemin document erroné |
280 |
|
|
$path = ""; |
281 |
|
|
$path_no_p0 = ""; |
282 |
|
|
//Nom possible de document |
283 |
|
|
$filename = "20091106AUTPCP.pdf"; |
284 |
|
|
//Retour de la fonction extractMetadataToFilestorage |
285 |
softime |
13528 |
$extractMetadataToFilestorage = $digitalizedDocument->extractMetadataToFilestorage($path, $filename); |
286 |
|
|
$extractMetadataToFilestorage_no_p0 = $digitalizedDocument->extractMetadataToFilestorage($path_no_p0, $filename); |
287 |
fmichon |
9227 |
//On vérifie que le retour est null |
288 |
|
|
$this->assertEquals($extractMetadataToFilestorage, null); |
289 |
|
|
$this->assertEquals($extractMetadataToFilestorage_no_p0, null); |
290 |
softime |
13528 |
$digitalizedDocument->__destruct(); |
291 |
|
|
// Destruction de la classe *om_application* |
292 |
|
|
$f->__destruct(); |
293 |
fmichon |
9227 |
} |
294 |
|
|
|
295 |
|
|
/** |
296 |
|
|
* Test la fonction createFileTemporary |
297 |
|
|
*/ |
298 |
|
|
public function testCreateFileTemporary() { |
299 |
softime |
13528 |
// Instanciation de la classe *om_application* |
300 |
|
|
$f = $this->get_inst_om_application("admin", "admin"); |
301 |
|
|
$f->disableLog(); |
302 |
|
|
$digitalizedDocument = new DigitalizedDocument($f); |
303 |
fmichon |
9227 |
// XXX hack temporaire : la commande suivante permet de ne pas avoir d'erreurs de |
304 |
|
|
// permissions système dues à l'enchaînement des tests *testREST.php* et |
305 |
|
|
// *testDigitalizedDocument.php* |
306 |
|
|
exec("sudo chmod 777 -R ../var > /dev/null 2>&1"); |
307 |
|
|
|
308 |
|
|
//Nom possible d'un répertoire |
309 |
|
|
$foldername = "PC0130551200001.P0"; |
310 |
|
|
$foldername_no_p0 = "PA0130551200001"; |
311 |
|
|
//Nom possible de dossier |
312 |
|
|
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
313 |
|
|
$path_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
314 |
|
|
//Nom possible de document |
315 |
|
|
$filename = "20091106AUTPCP.pdf"; |
316 |
|
|
//Construit les métadonnées |
317 |
|
|
$metadata = array(); |
318 |
|
|
//Données récupérées pour le filestorage |
319 |
softime |
13528 |
$metadata = $digitalizedDocument->extractMetadataToFilestorage($path, $filename); |
320 |
|
|
$metadata_no_p0 = $digitalizedDocument->extractMetadataToFilestorage($path_no_p0, $filename); |
321 |
fmichon |
9227 |
//Recupère le contenu du fichier |
322 |
|
|
$file_content = file_get_contents($path.'/'.$filename); |
323 |
|
|
$file_content_no_p0 = file_get_contents($path.'/'.$filename); |
324 |
|
|
|
325 |
|
|
//Retour de la fonction createFile |
326 |
softime |
13528 |
$createFile = $digitalizedDocument->createFileTemporary($file_content, $metadata); |
327 |
|
|
$createFile_no_p0 = $digitalizedDocument->createFileTemporary($file_content_no_p0, $metadata_no_p0); |
328 |
fmichon |
9227 |
//On vérifie que l'action s'est bien déroulée |
329 |
softime |
13528 |
$file_exists_filestorage = $digitalizedDocument->filestorage->get_temporary($createFile); |
330 |
|
|
$file_exists_filestorage_no_p0 = $digitalizedDocument->filestorage->get_temporary($createFile_no_p0); |
331 |
fmichon |
9227 |
$this->assertTrue($file_exists_filestorage != null); |
332 |
|
|
$this->assertTrue($file_exists_filestorage_no_p0 != null); |
333 |
softime |
13528 |
$digitalizedDocument->__destruct(); |
334 |
|
|
// Destruction de la classe *om_application* |
335 |
|
|
$f->__destruct(); |
336 |
fmichon |
9227 |
} |
337 |
|
|
|
338 |
|
|
/** |
339 |
|
|
* Test la fonction createDocumentNumerise |
340 |
|
|
*/ |
341 |
|
|
public function testCreateDocumentNumerise() { |
342 |
softime |
13528 |
// Instanciation de la classe *om_application* |
343 |
|
|
$f = $this->get_inst_om_application("admin", "admin"); |
344 |
|
|
$f->disableLog(); |
345 |
|
|
$digitalizedDocument = new DigitalizedDocument($f); |
346 |
fmichon |
9227 |
//Nom possible d'un répertoire |
347 |
|
|
$foldername = "PC0130551200001.P0"; |
348 |
|
|
$foldername_no_p0 = "PA0130551200001"; |
349 |
|
|
//Identifiant du dossier |
350 |
|
|
$dossier = "PC0130551200001P0"; |
351 |
|
|
$dossier_no_p0 = "PA0130551200001"; |
352 |
|
|
//Nom possible de dossier |
353 |
|
|
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
354 |
|
|
$path_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
355 |
|
|
//Nom du document |
356 |
|
|
$filename = "20091106AUTPCP.pdf"; |
357 |
|
|
//Création du fichier |
358 |
|
|
$newfile = "20091106RIPC05.pdf"; |
359 |
|
|
copy($path.'/'.$filename, $path.'/'.$newfile); |
360 |
|
|
copy($path_no_p0.'/'.$filename, $path_no_p0.'/'.$newfile); |
361 |
|
|
//Instance document_numerise |
362 |
|
|
require_once "../obj/document_numerise.class.php"; |
363 |
softime |
13528 |
$document_numerise = new document_numerise("]", $f->db, NULL); |
364 |
fmichon |
9227 |
|
365 |
|
|
//Construit les métadonnées |
366 |
|
|
$metadata = array(); |
367 |
|
|
$metadata_no_p0 = array(); |
368 |
|
|
//Données récupérées pour le filestorage |
369 |
softime |
13528 |
$metadata = $digitalizedDocument->extractMetadataToFilestorage($path, $newfile); |
370 |
|
|
$metadata_no_p0 = $digitalizedDocument->extractMetadataToFilestorage($path_no_p0, $newfile); |
371 |
fmichon |
9227 |
|
372 |
|
|
//Recupère le contenu du fichier |
373 |
|
|
$file_content = file_get_contents($path.'/'.$newfile); |
374 |
|
|
$file_content_no_p0 = file_get_contents($path_no_p0.'/'.$newfile); |
375 |
|
|
|
376 |
|
|
//Créer le fichier temporaire |
377 |
softime |
13528 |
$uid = $digitalizedDocument->createFileTemporary($file_content, $metadata); |
378 |
|
|
$uid_no_p0 = $digitalizedDocument->createFileTemporary($file_content_no_p0, $metadata_no_p0); |
379 |
fmichon |
9227 |
|
380 |
|
|
//Retour de la fonction createFileStorage |
381 |
softime |
13528 |
$createDocumentNumerise = $digitalizedDocument->createDocumentNumerise($document_numerise, $uid, $dossier, $newfile, $f->db, NULL); |
382 |
|
|
$createDocumentNumerise_no_p0 = $digitalizedDocument->createDocumentNumerise($document_numerise, $uid_no_p0, $dossier_no_p0, $newfile, $f->db, NULL); |
383 |
fmichon |
9227 |
|
384 |
|
|
//Supprime le fichier laissé dans le dossier Todo |
385 |
|
|
unlink($path.'/'.$newfile); |
386 |
|
|
unlink($path_no_p0.'/'.$newfile); |
387 |
|
|
|
388 |
|
|
//On vérifie que le fichier a bien été créé dans le filestorage |
389 |
softime |
13528 |
$uid = $this->get_uid_by_id($f, $createDocumentNumerise); |
390 |
|
|
$uid_no_p0 = $this->get_uid_by_id($f, $createDocumentNumerise_no_p0); |
391 |
fmichon |
9227 |
|
392 |
softime |
13528 |
$file_exists_filestorage = $digitalizedDocument->filestorage->get($uid); |
393 |
|
|
$file_exists_filestorage_no_p0 = $digitalizedDocument->filestorage->get($uid_no_p0); |
394 |
fmichon |
9227 |
|
395 |
|
|
$this->assertTrue($file_exists_filestorage != null); |
396 |
|
|
$this->assertTrue($file_exists_filestorage_no_p0 != null); |
397 |
|
|
|
398 |
|
|
//Uid pas présent dans la bdd |
399 |
|
|
$uid = uniqid(); |
400 |
|
|
$uid_no_p0 = uniqid(); |
401 |
|
|
//On vérifie que false est bien retourné |
402 |
softime |
13528 |
$this->assertEquals($this->checkLinkFile($f, $uid), false); |
403 |
|
|
$this->assertEquals($this->checkLinkFile($f, $uid_no_p0), false); |
404 |
|
|
$digitalizedDocument->__destruct(); |
405 |
|
|
// Destruction de la classe *om_application* |
406 |
|
|
$f->__destruct(); |
407 |
fmichon |
9227 |
} |
408 |
|
|
|
409 |
|
|
/** |
410 |
|
|
* Test la fonction moveDocumentNumerise |
411 |
|
|
*/ |
412 |
|
|
public function testMoveDocumentNumerise() { |
413 |
softime |
13528 |
// Instanciation de la classe *om_application* |
414 |
|
|
$f = $this->get_inst_om_application("admin", "admin"); |
415 |
|
|
$f->disableLog(); |
416 |
|
|
$digitalizedDocument = new DigitalizedDocument($f); |
417 |
fmichon |
9227 |
//Dossier source |
418 |
|
|
$pathSrc = "../var/digitalization/Todo/PC0130551200001.P0"; |
419 |
|
|
$pathSrc_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
420 |
|
|
//Dossier de destination |
421 |
|
|
$pathDes = "../var/digitalization/Done/PC0130551200001.P0"; |
422 |
|
|
$pathDes_no_p0 = "../var/digitalization/Done/PA0130551200001"; |
423 |
|
|
//Nom du fichier |
424 |
|
|
$filename = "20091106AUTPCP.pdf"; |
425 |
|
|
//Retour de la fonction moveDocumentNumerise |
426 |
softime |
13528 |
$moveFile = $digitalizedDocument->moveDocumentNumerise($pathSrc, $pathDes, $filename); |
427 |
|
|
$moveFile_no_p0 = $digitalizedDocument->moveDocumentNumerise($pathSrc_no_p0, $pathDes_no_p0, $filename); |
428 |
fmichon |
9227 |
//On vérifie que l'action s'est bien déroulée |
429 |
|
|
//Le document doit être présent dans la destination |
430 |
|
|
$file_exists_destination = file_exists($pathDes.'/'.$filename); |
431 |
|
|
$file_exists_destination_no_p0 = file_exists($pathDes_no_p0.'/'.$filename); |
432 |
|
|
$this->assertEquals($file_exists_destination, true); |
433 |
|
|
$this->assertEquals($file_exists_destination_no_p0, true); |
434 |
|
|
//Le document ne doit plus être présent dans la source |
435 |
|
|
$file_exists_source = file_exists($pathSrc.'/'.$filename); |
436 |
|
|
$file_exists_source_no_p0 = file_exists($pathSrc_no_p0.'/'.$filename); |
437 |
|
|
$this->assertEquals($file_exists_source, false); |
438 |
|
|
$this->assertEquals($file_exists_source_no_p0, false); |
439 |
|
|
|
440 |
|
|
//Remet le fichier dans todo pour les autres tests |
441 |
|
|
rename($pathDes.'/'.$filename, $pathSrc.'/'.$filename); |
442 |
|
|
rename($pathDes_no_p0.'/'.$filename, $pathSrc_no_p0.'/'.$filename); |
443 |
softime |
13528 |
$digitalizedDocument->__destruct(); |
444 |
|
|
// Destruction de la classe *om_application* |
445 |
|
|
$f->__destruct(); |
446 |
fmichon |
9227 |
} |
447 |
|
|
|
448 |
|
|
/** |
449 |
|
|
* Test la fonction purgeFiles |
450 |
|
|
*/ |
451 |
|
|
public function testPurgeFiles() { |
452 |
softime |
13528 |
// Instanciation de la classe *om_application* |
453 |
|
|
$f = $this->get_inst_om_application("admin", "admin"); |
454 |
|
|
$f->disableLog(); |
455 |
|
|
$digitalizedDocument = new DigitalizedDocument($f); |
456 |
fmichon |
9227 |
//Dossier source |
457 |
|
|
$pathSrc = "../var/digitalization/Todo/PC0130551200001.P0"; |
458 |
|
|
$pathSrc_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
459 |
|
|
//Dossier de destination |
460 |
|
|
$pathDes = "../var/digitalization/Done/PC0130551200001.P0"; |
461 |
|
|
$pathDes_no_p0 = "../var/digitalization/Done/PA0130551200001"; |
462 |
|
|
//Création dossier |
463 |
|
|
if (!file_exists($pathDes)) { |
464 |
|
|
mkdir("../var/digitalization/Done/PC0130551200001.P0"); |
465 |
|
|
} |
466 |
|
|
if (!file_exists($pathDes_no_p0)) { |
467 |
|
|
mkdir("../var/digitalization/Done/PA0130551200001"); |
468 |
|
|
} |
469 |
|
|
//Nom du fichier |
470 |
|
|
$filename = "20091106AUTPCP.pdf"; |
471 |
|
|
//Met le fichier dans Done |
472 |
|
|
copy($pathSrc.'/'.$filename, $pathDes.'/'.$filename); |
473 |
|
|
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$filename); |
474 |
|
|
|
475 |
|
|
//fichier |
476 |
|
|
$file = $pathDes.'/'.$filename; |
477 |
|
|
$file_no_p0 = $pathDes_no_p0.'/'.$filename; |
478 |
|
|
//Date de l'import du document |
479 |
|
|
$dateImport = "2012-01-01"; |
480 |
|
|
//Nombre jour |
481 |
|
|
$nbDay = 60; |
482 |
|
|
//Retour de la fonction purge |
483 |
softime |
13528 |
$purgeFiles = $digitalizedDocument->purgeFiles($file, $dateImport, $nbDay); |
484 |
fmichon |
9227 |
//On vérifie que l'action s'est bien déroulée |
485 |
|
|
$this->assertEquals($purgeFiles, true); |
486 |
|
|
|
487 |
|
|
//Création du fichier |
488 |
|
|
$newfile = "20091106RIPC05.pdf"; |
489 |
|
|
copy($pathSrc.'/'.$filename, $pathDes.'/'.$newfile); |
490 |
|
|
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$newfile); |
491 |
|
|
//fichier |
492 |
|
|
$file = $pathDes.'/'.$newfile; |
493 |
|
|
$file_no_p0 = $pathDes_no_p0.'/'.$newfile; |
494 |
|
|
//Retour de la fonction purge sans les paramètres de date |
495 |
softime |
13528 |
$purgeFiles = $digitalizedDocument->purgeFiles($file); |
496 |
|
|
$purgeFiles_no_p0 = $digitalizedDocument->purgeFiles($file_no_p0); |
497 |
fmichon |
9227 |
//On vérifie que l'action s'est bien déroulée |
498 |
|
|
$this->assertEquals($purgeFiles, true); |
499 |
|
|
$this->assertEquals($purgeFiles_no_p0, true); |
500 |
|
|
|
501 |
|
|
//Création du fichier |
502 |
|
|
$newfile = "20091106DGPC03.pdf"; |
503 |
|
|
copy($pathSrc.'/'.$filename, $pathDes.'/'.$newfile); |
504 |
|
|
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$newfile); |
505 |
|
|
|
506 |
|
|
//fichier |
507 |
|
|
$file = $pathDes.'/'.$newfile; |
508 |
|
|
$file_no_p0 = $pathDes_no_p0.'/'.$newfile; |
509 |
|
|
//Date de l'import du document |
510 |
|
|
$dateImport = date('d-m-Y'); |
511 |
|
|
//Nombre jour |
512 |
|
|
$nbDay = 60; |
513 |
|
|
//Retour de la fonction purge |
514 |
softime |
13528 |
$purgeFiles = $digitalizedDocument->purgeFiles($file, $dateImport, $nbDay); |
515 |
|
|
$purgeFiles_no_p0 = $digitalizedDocument->purgeFiles($file_no_p0, $dateImport, $nbDay); |
516 |
fmichon |
9227 |
|
517 |
|
|
//On vérifie que l'action s'est bien déroulée |
518 |
|
|
$this->assertEquals($purgeFiles, false); |
519 |
|
|
$this->assertEquals($purgeFiles_no_p0, false); |
520 |
|
|
|
521 |
|
|
//Supprime le fichier laissé dans le dossier Done |
522 |
|
|
unlink($pathDes.'/'.$newfile); |
523 |
|
|
unlink($pathDes_no_p0.'/'.$newfile); |
524 |
softime |
13528 |
$digitalizedDocument->__destruct(); |
525 |
|
|
// Destruction de la classe *om_application* |
526 |
|
|
$f->__destruct(); |
527 |
fmichon |
9227 |
} |
528 |
|
|
|
529 |
|
|
/** |
530 |
|
|
* Test la fonction run_import |
531 |
|
|
*/ |
532 |
|
|
public function test_run_import() { |
533 |
softime |
13528 |
// Instanciation de la classe *om_application* |
534 |
|
|
$f = $this->get_inst_om_application("admin", "admin"); |
535 |
|
|
$f->disableLog(); |
536 |
|
|
$digitalizedDocument = new DigitalizedDocument($f); |
537 |
fmichon |
9227 |
//Nom de dossier |
538 |
|
|
$pathSrc = "../var/digitalization/Todo/PC0130551200001.P0"; |
539 |
|
|
$pathSrc_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
540 |
|
|
//Nom dossier destination |
541 |
|
|
$pathDes = "../var/digitalization/Done/PC0130551200001.P0"; |
542 |
|
|
$pathDes_no_p0 = "../var/digitalization/Done/PA0130551200001"; |
543 |
|
|
//Renomme le fichier pdf |
544 |
|
|
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
545 |
softime |
13528 |
$listFiles = $digitalizedDocument->listFiles($pathSrc); |
546 |
|
|
$listFiles_no_p0 = $digitalizedDocument->listFiles($pathSrc_no_p0); |
547 |
fmichon |
9227 |
//On vérifie les documents retourné |
548 |
|
|
rename($pathSrc.'/'."20091106AUTPCP.pdf", $pathSrc.'/'."20091106NDL.pdf"); |
549 |
|
|
rename($pathSrc.'/'."20091106AUTPCP-1.pdf", $pathSrc.'/'."20091106NDL-1.pdf"); |
550 |
|
|
rename($pathSrc_no_p0.'/'."20091106AUTPCP.pdf", $pathSrc_no_p0.'/'."20091106NDL.pdf"); |
551 |
|
|
rename($pathSrc_no_p0.'/'."20091106AUTPCP-1.pdf", $pathSrc_no_p0.'/'."20091106NDL-1.pdf"); |
552 |
|
|
|
553 |
|
|
//Retour de la fonction run_import |
554 |
softime |
13528 |
$run_import = $digitalizedDocument->run_import($pathSrc, $pathDes); |
555 |
|
|
$run_import_no_p0 = $digitalizedDocument->run_import($pathSrc_no_p0, $pathDes_no_p0); |
556 |
fmichon |
9227 |
//On vérifie que l'action s'est bien déroulée |
557 |
|
|
$this->assertEquals($run_import, true); |
558 |
|
|
$this->assertEquals($run_import_no_p0, true); |
559 |
softime |
13528 |
$this->assertEquals(count($digitalizedDocument->filenameError), 0); |
560 |
fmichon |
9227 |
|
561 |
|
|
//Replace les fichiers dans le fichier source |
562 |
|
|
copy($pathDes.'/'."20091106NDL.pdf", $pathSrc.'/'."20091106AUTPCP.pdf"); |
563 |
|
|
copy($pathDes.'/'."20091106NDL-1.pdf", $pathSrc.'/'."20091106AUTPCP-1.pdf"); |
564 |
|
|
copy($pathDes_no_p0.'/'."20091106NDL.pdf", $pathSrc_no_p0.'/'."20091106AUTPCP.pdf"); |
565 |
|
|
copy($pathDes_no_p0.'/'."20091106NDL-1.pdf", $pathSrc_no_p0.'/'."20091106AUTPCP-1.pdf"); |
566 |
softime |
13528 |
$digitalizedDocument->__destruct(); |
567 |
|
|
// Destruction de la classe *om_application* |
568 |
|
|
$f->__destruct(); |
569 |
fmichon |
9227 |
} |
570 |
|
|
|
571 |
|
|
/** |
572 |
|
|
* Test la fonction run_purge |
573 |
|
|
*/ |
574 |
|
|
public function test_run_purge() { |
575 |
softime |
13528 |
// Instanciation de la classe *om_application* |
576 |
|
|
$f = $this->get_inst_om_application("admin", "admin"); |
577 |
|
|
$f->disableLog(); |
578 |
|
|
$digitalizedDocument = new DigitalizedDocument($f); |
579 |
|
|
// |
580 |
fmichon |
9227 |
copy('binary_files/20091106AUTPCP.pdf', '../var/digitalization/Todo/PC0130551200001.P0/20091106AUTPCP.pdf'); |
581 |
|
|
copy('binary_files/20091106AUTPCP-1.pdf', '../var/digitalization/Todo/PC0130551200001.P0/20091106AUTPCP-1.pdf'); |
582 |
|
|
copy('binary_files/20091106AUTPCP.pdf', '../var/digitalization/Todo/PA0130551200001/20091106AUTPCP.pdf'); |
583 |
|
|
copy('binary_files/20091106AUTPCP-1.pdf', '../var/digitalization/Todo/PA0130551200001/20091106AUTPCP-1.pdf'); |
584 |
|
|
//Dossier source |
585 |
|
|
$pathSrc = "../var/digitalization/Todo/PC0130551200001.P0"; |
586 |
|
|
$pathSrc_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
587 |
|
|
//Dossier de destination |
588 |
|
|
$pathDes = "../var/digitalization/Done/PC0130551200001.P0"; |
589 |
|
|
$pathDes_no_p0 = "../var/digitalization/Done/PA0130551200001"; |
590 |
|
|
//Création dossier |
591 |
|
|
if (!file_exists($pathDes)) { |
592 |
|
|
mkdir("../var/digitalization/Done/PC0130551200001.P0"); |
593 |
|
|
} |
594 |
|
|
if (!file_exists($pathDes_no_p0)) { |
595 |
|
|
mkdir("../var/digitalization/Done/PA0130551200001"); |
596 |
|
|
} |
597 |
|
|
//Nom du fichier |
598 |
|
|
$filename = "20091106AUTPCP.pdf"; |
599 |
|
|
//Met le fichier 20091106AUTPCP dans Done |
600 |
|
|
copy($pathSrc.'/'.$filename, $pathDes.'/'.$filename); |
601 |
|
|
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$filename); |
602 |
|
|
//Création du fichier 20091106RIPC05 |
603 |
|
|
$newfile = "20091106RIPC05.pdf"; |
604 |
|
|
copy($pathSrc.'/'.$filename, $pathDes.'/'.$newfile); |
605 |
|
|
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$newfile); |
606 |
|
|
//Création du fichier 20091106DGPC03 |
607 |
|
|
$newfile = "20091106DGPC03.pdf"; |
608 |
|
|
copy($pathSrc.'/'.$filename, $pathDes.'/'.$newfile); |
609 |
|
|
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$newfile); |
610 |
|
|
|
611 |
|
|
//Retour de la fonction run_purge sans date |
612 |
softime |
13528 |
$run_purge = $digitalizedDocument->run_purge($pathDes); |
613 |
|
|
$run_purge_no_p0 = $digitalizedDocument->run_purge($pathDes_no_p0); |
614 |
fmichon |
9227 |
|
615 |
|
|
//On vérifie que l'action s'est bien déroulée |
616 |
|
|
$this->assertEquals($run_purge, true); |
617 |
|
|
$this->assertEquals($run_purge_no_p0, true); |
618 |
softime |
13528 |
$digitalizedDocument->__destruct(); |
619 |
|
|
// Destruction de la classe *om_application* |
620 |
|
|
$f->__destruct(); |
621 |
fmichon |
9227 |
} |
622 |
|
|
} |