1 |
<?php |
2 |
/** |
3 |
* Ce fichier regroupe les tests unitaire sur la classe DigitalizedDocument |
4 |
* |
5 |
* @package openads |
6 |
* @version SVN : $Id: testDigitalizedDocument.php 6129 2016-03-08 15:51:07Z stimezouaght $ |
7 |
*/ |
8 |
|
9 |
require_once('../obj/digitalizedDocument.class.php'); |
10 |
// |
11 |
require_once "../obj/utils.class.php"; |
12 |
|
13 |
/** |
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 |
class DigitalizedDocumentTest extends PHPUnit_Framework_TestCase { |
26 |
|
27 |
var $digitalizedDocument = NULL; |
28 |
|
29 |
/** |
30 |
* Fonction lancée en début de classe |
31 |
*/ |
32 |
public static function setUpBeforeClass() { |
33 |
// Création des dossiers PC0130551200001.P0 et PC0130551200002 dans le |
34 |
// dossier de numérisation |
35 |
mkdir('../var/digitalization/Todo/PC0130551200001.P0/'); |
36 |
chmod('../var/digitalization/Todo/PC0130551200001.P0/', 0777); |
37 |
mkdir('../var/digitalization/Todo/PC0130551200002.P0/'); |
38 |
chmod('../var/digitalization/Todo/PC0130551200002.P0/', 0777); |
39 |
// Récupération du document |
40 |
copy('binary_files/20091106AUTPCP.pdf', '../var/digitalization/Todo/PC0130551200001.P0/20091106AUTPCP.pdf'); |
41 |
copy('binary_files/20091106AUTPCP-1.pdf', '../var/digitalization/Todo/PC0130551200001.P0/20091106AUTPCP-1.pdf'); |
42 |
// Création des dossiers sans le suffixe P0 |
43 |
mkdir('../var/digitalization/Todo/PA0130551200001/'); |
44 |
chmod('../var/digitalization/Todo/PA0130551200001/', 0777); |
45 |
mkdir('../var/digitalization/Todo/DP0130551200001/'); |
46 |
chmod('../var/digitalization/Todo/DP0130551200001/', 0777); |
47 |
// Récupération du document |
48 |
copy('binary_files/20091106AUTPCP.pdf', '../var/digitalization/Todo/PA0130551200001/20091106AUTPCP.pdf'); |
49 |
copy('binary_files/20091106AUTPCP-1.pdf', '../var/digitalization/Todo/PA0130551200001/20091106AUTPCP-1.pdf'); |
50 |
} |
51 |
|
52 |
/** |
53 |
* Fonction lancée en fin de classe |
54 |
*/ |
55 |
public static function tearDownAfterClass() { |
56 |
// Suppression du document 20091106AUTPCP.pdf |
57 |
unlink('../var/digitalization/Todo/PC0130551200001.P0/20091106AUTPCP.pdf'); |
58 |
unlink('../var/digitalization/Todo/PC0130551200001.P0/20091106AUTPCP-1.pdf'); |
59 |
unlink('../var/digitalization/Todo/PA0130551200001/20091106AUTPCP.pdf'); |
60 |
unlink('../var/digitalization/Todo/PA0130551200001/20091106AUTPCP-1.pdf'); |
61 |
// Suppression des dossiers PC0130551200001.P0 et PC0130551200002.P0 |
62 |
if(file_exists('../var/digitalization/Todo/PC0130551200001.P0')) { |
63 |
rmdir('../var/digitalization/Todo/PC0130551200001.P0'); |
64 |
} |
65 |
if(file_exists('../var/digitalization/Todo/PC0130551200002.P0')) { |
66 |
rmdir('../var/digitalization/Todo/PC0130551200002.P0'); |
67 |
} |
68 |
// Suppression des dossiers sans P0 |
69 |
if(file_exists('../var/digitalization/Todo/PA0130551200001')) { |
70 |
rmdir('../var/digitalization/Todo/PA0130551200001'); |
71 |
} |
72 |
if(file_exists('../var/digitalization/Todo/DP0130551200001')) { |
73 |
rmdir('../var/digitalization/Todo/DP0130551200001'); |
74 |
} |
75 |
|
76 |
|
77 |
} |
78 |
|
79 |
/** |
80 |
* Fonction lancée en debut de chaque test |
81 |
*/ |
82 |
public function setUp() { |
83 |
// Instancie la timezone |
84 |
date_default_timezone_set('Europe/Paris'); |
85 |
echo ' = '.get_class().'.'.str_replace('test_', '', $this->getName())."\r\n"; |
86 |
@session_start(); |
87 |
$_SESSION['collectivite'] = 1; |
88 |
$_SESSION['login'] = "admin"; |
89 |
$_SERVER['REQUEST_URI'] = ""; |
90 |
$f = new utils("nohtml"); |
91 |
$f->disableLog(); |
92 |
$this->digitalizedDocument = new DigitalizedDocument($f); |
93 |
} |
94 |
|
95 |
public function onNotSuccessfulTest(Exception $e){ |
96 |
echo 'Line '.$e->getLine().' : '.$e->getMessage()."\r\n"; |
97 |
parent::onNotSuccessfulTest($e); |
98 |
} |
99 |
|
100 |
/** |
101 |
* Fonction lancée en fin de chaque test |
102 |
*/ |
103 |
public function tearDown() { |
104 |
//On détruit l'instance de la classe DigitalizedDocument |
105 |
$this->digitalizedDocument->__destruct(); |
106 |
} |
107 |
|
108 |
/** |
109 |
* Fonction permettant de verifier l'ajout dans la base de données |
110 |
*/ |
111 |
private function checkLinkFile($uid) { |
112 |
|
113 |
//Requête qui vérifie dans la bdd si le lien existe |
114 |
$sql = "SELECT document_numerise |
115 |
FROM ".DB_PREFIXE."document_numerise |
116 |
WHERE uid = '".$uid."'"; |
117 |
$document_numerise = $this->digitalizedDocument->f->db->getOne($sql); |
118 |
$this->digitalizedDocument->f->isDatabaseError($document_numerise); |
119 |
|
120 |
//Si le lien a été trouvé on retourne vrai |
121 |
if ($document_numerise) { |
122 |
|
123 |
return true; |
124 |
|
125 |
} |
126 |
|
127 |
//sinon on retourne false |
128 |
return false; |
129 |
} |
130 |
|
131 |
/** |
132 |
* Recupère uid par rapport à l'identifiant |
133 |
*/ |
134 |
private function get_uid_by_id($document_numerise) { |
135 |
|
136 |
//Requête qui vérifie dans la bdd si le lien existe |
137 |
$sql = "SELECT uid |
138 |
FROM ".DB_PREFIXE."document_numerise |
139 |
WHERE document_numerise = '".$document_numerise."'"; |
140 |
$uid = $this->digitalizedDocument->f->db->getOne($sql); |
141 |
$this->digitalizedDocument->f->isDatabaseError($uid); |
142 |
|
143 |
// |
144 |
return $uid; |
145 |
|
146 |
} |
147 |
|
148 |
/** |
149 |
* Test la fonction listFiles |
150 |
*/ |
151 |
public function testListFiles() { |
152 |
|
153 |
//Nom possible de dossier |
154 |
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
155 |
$path_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
156 |
|
157 |
//Retour de la fonction listFiles |
158 |
$listFiles = $this->digitalizedDocument->listFiles($path); |
159 |
$listFiles_no_p0 = $this->digitalizedDocument->listFiles($path_no_p0); |
160 |
//On vérifie les documents retourné |
161 |
$this->assertContains("20091106AUTPCP-1.pdf", $listFiles); |
162 |
$this->assertContains("20091106AUTPCP.pdf", $listFiles); |
163 |
// Même chose pour les dossiers sans P0 |
164 |
$this->assertContains("20091106AUTPCP-1.pdf", $listFiles_no_p0); |
165 |
$this->assertContains("20091106AUTPCP.pdf", $listFiles_no_p0); |
166 |
|
167 |
//Nom de dossier vide |
168 |
$path = "../var/digitalization/Todo/PC0130551200002.P0"; |
169 |
$path_no_p0 = "../var/digitalization/Todo/DP0130551200001"; |
170 |
//Retour de la fontion listFiles |
171 |
$listFiles = $this->digitalizedDocument->listFiles($path); |
172 |
$listFiles_no_p0 = $this->digitalizedDocument->listFiles($path_no_p0); |
173 |
//On vérifie que le tableau retourné est vide |
174 |
$this->assertEquals($listFiles, null); |
175 |
$this->assertEquals($listFiles_no_p0, null); |
176 |
|
177 |
} |
178 |
|
179 |
/* |
180 |
* Test la fonction extractMetadataFromFilename |
181 |
*/ |
182 |
public function testExtractMetadataFromFilename() { |
183 |
|
184 |
//Nom possible de document |
185 |
$filename = "20091106AUTPCP.pdf"; |
186 |
//Retour de la fonction extractMetadataFromFilename |
187 |
$extractMetadataFromFilename = $this->digitalizedDocument->extractMetadataFromFilename($filename); |
188 |
//On vérifie les données retournées |
189 |
$this->assertEquals($extractMetadataFromFilename["title"], "AUTPCP"); |
190 |
$this->assertEquals($extractMetadataFromFilename["dateEvenementDocument"], "06/11/2009"); |
191 |
|
192 |
//Nom possible de document avec version |
193 |
$filename = "20130420ART-1.pdf"; |
194 |
//Retour de la fonction extractMetadataFromFilename |
195 |
$extractMetadataFromFilename = $this->digitalizedDocument->extractMetadataFromFilename($filename); |
196 |
//On vérifie les données retournées |
197 |
$this->assertEquals($extractMetadataFromFilename["title"], "ART"); |
198 |
$this->assertEquals($extractMetadataFromFilename["dateEvenementDocument"], "20/04/2013"); |
199 |
|
200 |
//Nom erroné de document |
201 |
$filename = "20591212.pdf"; |
202 |
//Retour de la fonction extractMetadataFromFilename |
203 |
$extractMetadataFromFilename = $this->digitalizedDocument->extractMetadataFromFilename($filename); |
204 |
//On vérifie que le tableau retourné est vide |
205 |
$this->assertEquals($extractMetadataFromFilename, null); |
206 |
|
207 |
} |
208 |
|
209 |
/** |
210 |
* Test la fonction extractMetadataToFilestorage |
211 |
*/ |
212 |
public function testExtractMetadataToFilestorage() { |
213 |
|
214 |
//Nom possible de dossier |
215 |
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
216 |
$path_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
217 |
//Nom possible de document |
218 |
$filename = "20091106AUTPCP.pdf"; |
219 |
//Retour de la fonction extractMetadataToFilestorage |
220 |
$extractMetadataToFilestorage = $this->digitalizedDocument->extractMetadataToFilestorage($path, $filename); |
221 |
$extractMetadataToFilestorage_no_p0 = $this->digitalizedDocument->extractMetadataToFilestorage($path_no_p0, $filename); |
222 |
//On vérifie les données retournées |
223 |
$this->assertEquals($extractMetadataToFilestorage['filename'], '20091106AUTPCP.pdf'); |
224 |
$this->assertEquals($extractMetadataToFilestorage['size'], '17435'); |
225 |
$this->assertEquals($extractMetadataToFilestorage['mimetype'], 'application/pdf'); |
226 |
// Pour le dossier sans P0 |
227 |
$this->assertEquals($extractMetadataToFilestorage_no_p0['filename'], '20091106AUTPCP.pdf'); |
228 |
$this->assertEquals($extractMetadataToFilestorage_no_p0['size'], '17435'); |
229 |
$this->assertEquals($extractMetadataToFilestorage_no_p0['mimetype'], 'application/pdf'); |
230 |
//Chemin document erroné |
231 |
$path = ""; |
232 |
$path_no_p0 = ""; |
233 |
//Nom possible de document |
234 |
$filename = "20091106AUTPCP.pdf"; |
235 |
//Retour de la fonction extractMetadataToFilestorage |
236 |
$extractMetadataToFilestorage = $this->digitalizedDocument->extractMetadataToFilestorage($path, $filename); |
237 |
$extractMetadataToFilestorage_no_p0 = $this->digitalizedDocument->extractMetadataToFilestorage($path_no_p0, $filename); |
238 |
//On vérifie que le retour est null |
239 |
$this->assertEquals($extractMetadataToFilestorage, null); |
240 |
$this->assertEquals($extractMetadataToFilestorage_no_p0, null); |
241 |
|
242 |
} |
243 |
|
244 |
/** |
245 |
* Test la fonction createFileTemporary |
246 |
*/ |
247 |
public function testCreateFileTemporary() { |
248 |
|
249 |
//Nom possible d'un répertoire |
250 |
$foldername = "PC0130551200001.P0"; |
251 |
$foldername_no_p0 = "PA0130551200001"; |
252 |
//Nom possible de dossier |
253 |
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
254 |
$path_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
255 |
//Nom possible de document |
256 |
$filename = "20091106AUTPCP.pdf"; |
257 |
//Construit les métadonnées |
258 |
$metadata = array(); |
259 |
//Données récupérées pour le filestorage |
260 |
$metadata = $this->digitalizedDocument->extractMetadataToFilestorage($path, $filename); |
261 |
$metadata_no_p0 = $this->digitalizedDocument->extractMetadataToFilestorage($path_no_p0, $filename); |
262 |
//Recupère le contenu du fichier |
263 |
$file_content = file_get_contents($path.'/'.$filename); |
264 |
$file_content_no_p0 = file_get_contents($path.'/'.$filename); |
265 |
|
266 |
//Retour de la fonction createFile |
267 |
$createFile = $this->digitalizedDocument->createFileTemporary($file_content, $metadata); |
268 |
$createFile_no_p0 = $this->digitalizedDocument->createFileTemporary($file_content_no_p0, $metadata_no_p0); |
269 |
//On vérifie que l'action s'est bien déroulée |
270 |
$file_exists_filestorage = $this->digitalizedDocument->filestorage->get_temporary($createFile); |
271 |
$file_exists_filestorage_no_p0 = $this->digitalizedDocument->filestorage->get_temporary($createFile_no_p0); |
272 |
$this->assertTrue($file_exists_filestorage != null); |
273 |
$this->assertTrue($file_exists_filestorage_no_p0 != null); |
274 |
|
275 |
} |
276 |
|
277 |
/** |
278 |
* Test la fonction createDocumentNumerise |
279 |
*/ |
280 |
public function testCreateDocumentNumerise() { |
281 |
|
282 |
//Nom possible d'un répertoire |
283 |
$foldername = "PC0130551200001.P0"; |
284 |
$foldername_no_p0 = "PA0130551200001"; |
285 |
//Identifiant du dossier |
286 |
$dossier = "PC0130551200001P0"; |
287 |
$dossier_no_p0 = "PA0130551200001"; |
288 |
//Nom possible de dossier |
289 |
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
290 |
$path_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
291 |
//Nom du document |
292 |
$filename = "20091106AUTPCP.pdf"; |
293 |
//Création du fichier |
294 |
$newfile = "20091106RIPC05.pdf"; |
295 |
copy($path.'/'.$filename, $path.'/'.$newfile); |
296 |
copy($path_no_p0.'/'.$filename, $path_no_p0.'/'.$newfile); |
297 |
//Instance document_numerise |
298 |
require_once "../obj/document_numerise.class.php"; |
299 |
$document_numerise = new document_numerise("]", $this->digitalizedDocument->f->db, NULL); |
300 |
|
301 |
//Construit les métadonnées |
302 |
$metadata = array(); |
303 |
$metadata_no_p0 = array(); |
304 |
//Données récupérées pour le filestorage |
305 |
$metadata = $this->digitalizedDocument->extractMetadataToFilestorage($path, $newfile); |
306 |
$metadata_no_p0 = $this->digitalizedDocument->extractMetadataToFilestorage($path_no_p0, $newfile); |
307 |
|
308 |
//Recupère le contenu du fichier |
309 |
$file_content = file_get_contents($path.'/'.$newfile); |
310 |
$file_content_no_p0 = file_get_contents($path_no_p0.'/'.$newfile); |
311 |
|
312 |
//Créer le fichier temporaire |
313 |
$uid = $this->digitalizedDocument->createFileTemporary($file_content, $metadata); |
314 |
$uid_no_p0 = $this->digitalizedDocument->createFileTemporary($file_content_no_p0, $metadata_no_p0); |
315 |
|
316 |
//Retour de la fonction createFileStorage |
317 |
$createDocumentNumerise = $this->digitalizedDocument->createDocumentNumerise($document_numerise, $uid, $dossier, $newfile, $this->digitalizedDocument->f->db, NULL); |
318 |
$createDocumentNumerise_no_p0 = $this->digitalizedDocument->createDocumentNumerise($document_numerise, $uid_no_p0, $dossier_no_p0, $newfile, $this->digitalizedDocument->f->db, NULL); |
319 |
|
320 |
//Supprime le fichier laissé dans le dossier Todo |
321 |
unlink($path.'/'.$newfile); |
322 |
unlink($path_no_p0.'/'.$newfile); |
323 |
|
324 |
//On vérifie que le fichier a bien été créé dans le filestorage |
325 |
$uid = $this->get_uid_by_id($createDocumentNumerise); |
326 |
$uid_no_p0 = $this->get_uid_by_id($createDocumentNumerise_no_p0); |
327 |
|
328 |
$file_exists_filestorage = $this->digitalizedDocument->filestorage->get($uid); |
329 |
$file_exists_filestorage_no_p0 = $this->digitalizedDocument->filestorage->get($uid_no_p0); |
330 |
|
331 |
$this->assertTrue($file_exists_filestorage != null); |
332 |
$this->assertTrue($file_exists_filestorage_no_p0 != null); |
333 |
|
334 |
//Uid pas présent dans la bdd |
335 |
$uid = uniqid(); |
336 |
$uid_no_p0 = uniqid(); |
337 |
//On vérifie que false est bien retourné |
338 |
$this->assertEquals($this->checkLinkFile($uid), false); |
339 |
$this->assertEquals($this->checkLinkFile($uid_no_p0), false); |
340 |
|
341 |
} |
342 |
|
343 |
/** |
344 |
* Test la fonction moveDocumentNumerise |
345 |
*/ |
346 |
public function testMoveDocumentNumerise() { |
347 |
|
348 |
//Dossier source |
349 |
$pathSrc = "../var/digitalization/Todo/PC0130551200001.P0"; |
350 |
$pathSrc_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
351 |
//Dossier de destination |
352 |
$pathDes = "../var/digitalization/Done/PC0130551200001.P0"; |
353 |
$pathDes_no_p0 = "../var/digitalization/Done/PA0130551200001"; |
354 |
//Nom du fichier |
355 |
$filename = "20091106AUTPCP.pdf"; |
356 |
//Retour de la fonction moveDocumentNumerise |
357 |
$moveFile = $this->digitalizedDocument->moveDocumentNumerise($pathSrc, $pathDes, $filename); |
358 |
$moveFile_no_p0 = $this->digitalizedDocument->moveDocumentNumerise($pathSrc_no_p0, $pathDes_no_p0, $filename); |
359 |
//On vérifie que l'action s'est bien déroulée |
360 |
//Le document doit être présent dans la destination |
361 |
$file_exists_destination = file_exists($pathDes.'/'.$filename); |
362 |
$file_exists_destination_no_p0 = file_exists($pathDes_no_p0.'/'.$filename); |
363 |
$this->assertEquals($file_exists_destination, true); |
364 |
$this->assertEquals($file_exists_destination_no_p0, true); |
365 |
//Le document ne doit plus être présent dans la source |
366 |
$file_exists_source = file_exists($pathSrc.'/'.$filename); |
367 |
$file_exists_source_no_p0 = file_exists($pathSrc_no_p0.'/'.$filename); |
368 |
$this->assertEquals($file_exists_source, false); |
369 |
$this->assertEquals($file_exists_source_no_p0, false); |
370 |
|
371 |
//Remet le fichier dans todo pour les autres tests |
372 |
rename($pathDes.'/'.$filename, $pathSrc.'/'.$filename); |
373 |
rename($pathDes_no_p0.'/'.$filename, $pathSrc_no_p0.'/'.$filename); |
374 |
|
375 |
} |
376 |
|
377 |
/** |
378 |
* Test la fonction purgeFiles |
379 |
*/ |
380 |
public function testPurgeFiles() { |
381 |
|
382 |
//Dossier source |
383 |
$pathSrc = "../var/digitalization/Todo/PC0130551200001.P0"; |
384 |
$pathSrc_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
385 |
//Dossier de destination |
386 |
$pathDes = "../var/digitalization/Done/PC0130551200001.P0"; |
387 |
$pathDes_no_p0 = "../var/digitalization/Done/PA0130551200001"; |
388 |
//Création dossier |
389 |
if (!file_exists($pathDes)) { |
390 |
mkdir("../var/digitalization/Done/PC0130551200001.P0"); |
391 |
} |
392 |
if (!file_exists($pathDes_no_p0)) { |
393 |
mkdir("../var/digitalization/Done/PA0130551200001"); |
394 |
} |
395 |
//Nom du fichier |
396 |
$filename = "20091106AUTPCP.pdf"; |
397 |
//Met le fichier dans Done |
398 |
copy($pathSrc.'/'.$filename, $pathDes.'/'.$filename); |
399 |
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$filename); |
400 |
|
401 |
//fichier |
402 |
$file = $pathDes.'/'.$filename; |
403 |
$file_no_p0 = $pathDes_no_p0.'/'.$filename; |
404 |
//Date de l'import du document |
405 |
$dateImport = "2012-01-01"; |
406 |
//Nombre jour |
407 |
$nbDay = 60; |
408 |
//Retour de la fonction purge |
409 |
$purgeFiles = $this->digitalizedDocument->purgeFiles($file, $dateImport, $nbDay); |
410 |
//On vérifie que l'action s'est bien déroulée |
411 |
$this->assertEquals($purgeFiles, true); |
412 |
|
413 |
//Création du fichier |
414 |
$newfile = "20091106RIPC05.pdf"; |
415 |
copy($pathSrc.'/'.$filename, $pathDes.'/'.$newfile); |
416 |
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$newfile); |
417 |
//fichier |
418 |
$file = $pathDes.'/'.$newfile; |
419 |
$file_no_p0 = $pathDes_no_p0.'/'.$newfile; |
420 |
//Retour de la fonction purge sans les paramètres de date |
421 |
$purgeFiles = $this->digitalizedDocument->purgeFiles($file); |
422 |
$purgeFiles_no_p0 = $this->digitalizedDocument->purgeFiles($file_no_p0); |
423 |
//On vérifie que l'action s'est bien déroulée |
424 |
$this->assertEquals($purgeFiles, true); |
425 |
$this->assertEquals($purgeFiles_no_p0, true); |
426 |
|
427 |
//Création du fichier |
428 |
$newfile = "20091106DGPC03.pdf"; |
429 |
copy($pathSrc.'/'.$filename, $pathDes.'/'.$newfile); |
430 |
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$newfile); |
431 |
|
432 |
//fichier |
433 |
$file = $pathDes.'/'.$newfile; |
434 |
$file_no_p0 = $pathDes_no_p0.'/'.$newfile; |
435 |
//Date de l'import du document |
436 |
$dateImport = date('d-m-Y'); |
437 |
//Nombre jour |
438 |
$nbDay = 60; |
439 |
//Retour de la fonction purge |
440 |
$purgeFiles = $this->digitalizedDocument->purgeFiles($file, $dateImport, $nbDay); |
441 |
$purgeFiles_no_p0 = $this->digitalizedDocument->purgeFiles($file_no_p0, $dateImport, $nbDay); |
442 |
|
443 |
//On vérifie que l'action s'est bien déroulée |
444 |
$this->assertEquals($purgeFiles, false); |
445 |
$this->assertEquals($purgeFiles_no_p0, false); |
446 |
|
447 |
//Supprime le fichier laissé dans le dossier Done |
448 |
unlink($pathDes.'/'.$newfile); |
449 |
unlink($pathDes_no_p0.'/'.$newfile); |
450 |
|
451 |
} |
452 |
|
453 |
/** |
454 |
* Test la fonction run_import |
455 |
*/ |
456 |
public function test_run_import() { |
457 |
|
458 |
//Nom de dossier |
459 |
$pathSrc = "../var/digitalization/Todo/PC0130551200001.P0"; |
460 |
$pathSrc_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
461 |
//Nom dossier destination |
462 |
$pathDes = "../var/digitalization/Done/PC0130551200001.P0"; |
463 |
$pathDes_no_p0 = "../var/digitalization/Done/PA0130551200001"; |
464 |
//Renomme le fichier pdf |
465 |
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
466 |
$listFiles = $this->digitalizedDocument->listFiles($pathSrc); |
467 |
$listFiles_no_p0 = $this->digitalizedDocument->listFiles($pathSrc_no_p0); |
468 |
//On vérifie les documents retourné |
469 |
rename($pathSrc.'/'."20091106AUTPCP.pdf", $pathSrc.'/'."20091106NDL.pdf"); |
470 |
rename($pathSrc.'/'."20091106AUTPCP-1.pdf", $pathSrc.'/'."20091106NDL-1.pdf"); |
471 |
rename($pathSrc_no_p0.'/'."20091106AUTPCP.pdf", $pathSrc_no_p0.'/'."20091106NDL.pdf"); |
472 |
rename($pathSrc_no_p0.'/'."20091106AUTPCP-1.pdf", $pathSrc_no_p0.'/'."20091106NDL-1.pdf"); |
473 |
|
474 |
//Déclarations paramètre |
475 |
$db = $this->digitalizedDocument->f->db; |
476 |
$DEBUG = NULL; |
477 |
//Retour de la fonction run_import |
478 |
$run_import = $this->digitalizedDocument->run_import($pathSrc, $pathDes, $db, $DEBUG); |
479 |
$run_import_no_p0 = $this->digitalizedDocument->run_import($pathSrc_no_p0, $pathDes_no_p0, $db, $DEBUG); |
480 |
//On vérifie que l'action s'est bien déroulée |
481 |
$this->assertEquals($run_import, true); |
482 |
$this->assertEquals($run_import_no_p0, true); |
483 |
$this->assertEquals(count($this->digitalizedDocument->filenameError), 0); |
484 |
|
485 |
//Replace les fichiers dans le fichier source |
486 |
copy($pathDes.'/'."20091106NDL.pdf", $pathSrc.'/'."20091106AUTPCP.pdf"); |
487 |
copy($pathDes.'/'."20091106NDL-1.pdf", $pathSrc.'/'."20091106AUTPCP-1.pdf"); |
488 |
copy($pathDes_no_p0.'/'."20091106NDL.pdf", $pathSrc_no_p0.'/'."20091106AUTPCP.pdf"); |
489 |
copy($pathDes_no_p0.'/'."20091106NDL-1.pdf", $pathSrc_no_p0.'/'."20091106AUTPCP-1.pdf"); |
490 |
} |
491 |
|
492 |
/** |
493 |
* Test la fonction run_purge |
494 |
*/ |
495 |
public function test_run_purge() { |
496 |
|
497 |
//Dossier source |
498 |
$pathSrc = "../var/digitalization/Todo/PC0130551200001.P0"; |
499 |
$pathSrc_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
500 |
//Dossier de destination |
501 |
$pathDes = "../var/digitalization/Done/PC0130551200001.P0"; |
502 |
$pathDes_no_p0 = "../var/digitalization/Done/PA0130551200001"; |
503 |
//Création dossier |
504 |
if (!file_exists($pathDes)) { |
505 |
mkdir("../var/digitalization/Done/PC0130551200001.P0"); |
506 |
} |
507 |
if (!file_exists($pathDes_no_p0)) { |
508 |
mkdir("../var/digitalization/Done/PA0130551200001"); |
509 |
} |
510 |
//Nom du fichier |
511 |
$filename = "20091106AUTPCP.pdf"; |
512 |
//Met le fichier 20091106AUTPCP dans Done |
513 |
copy($pathSrc.'/'.$filename, $pathDes.'/'.$filename); |
514 |
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$filename); |
515 |
//Création du fichier 20091106RIPC05 |
516 |
$newfile = "20091106RIPC05.pdf"; |
517 |
copy($pathSrc.'/'.$filename, $pathDes.'/'.$newfile); |
518 |
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$newfile); |
519 |
//Création du fichier 20091106DGPC03 |
520 |
$newfile = "20091106DGPC03.pdf"; |
521 |
copy($pathSrc.'/'.$filename, $pathDes.'/'.$newfile); |
522 |
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$newfile); |
523 |
|
524 |
//Retour de la fonction run_purge sans date |
525 |
$run_purge = $this->digitalizedDocument->run_purge($pathDes); |
526 |
$run_purge_no_p0 = $this->digitalizedDocument->run_purge($pathDes_no_p0); |
527 |
|
528 |
//On vérifie que l'action s'est bien déroulée |
529 |
$this->assertEquals($run_purge, true); |
530 |
$this->assertEquals($run_purge_no_p0, true); |
531 |
|
532 |
} |
533 |
|
534 |
} |
535 |
|
536 |
?> |