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