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