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 |
mbroquet |
3730 |
// 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 |
nmeucci |
4526 |
// 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 |
mbroquet |
3730 |
} |
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->addToLog("tests/testDigitalizedDocument.php : db->getOne(".$sql.")", VERBOSE_MODE); |
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->addToLog("tests/testDigitalizedDocument.php : db->getOne(".$sql.")", VERBOSE_MODE); |
143 |
|
|
$this->digitalizedDocument->f->isDatabaseError($uid); |
144 |
|
|
|
145 |
|
|
// |
146 |
|
|
return $uid; |
147 |
|
|
|
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
/** |
151 |
|
|
* Test la fonction listFiles |
152 |
|
|
*/ |
153 |
|
|
public function testListFiles() { |
154 |
|
|
|
155 |
|
|
//Nom possible de dossier |
156 |
|
|
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
157 |
nmeucci |
4526 |
$path_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
158 |
|
|
|
159 |
mbroquet |
3730 |
//Retour de la fonction listFiles |
160 |
|
|
$listFiles = $this->digitalizedDocument->listFiles($path); |
161 |
nmeucci |
4526 |
$listFiles_no_p0 = $this->digitalizedDocument->listFiles($path_no_p0); |
162 |
mbroquet |
3730 |
//On vérifie les documents retourné |
163 |
|
|
$this->assertContains("20091106AUTPCP-1.pdf", $listFiles); |
164 |
|
|
$this->assertContains("20091106AUTPCP.pdf", $listFiles); |
165 |
nmeucci |
4526 |
// Même chose pour les dossiers sans P0 |
166 |
|
|
$this->assertContains("20091106AUTPCP-1.pdf", $listFiles_no_p0); |
167 |
|
|
$this->assertContains("20091106AUTPCP.pdf", $listFiles_no_p0); |
168 |
mbroquet |
3730 |
|
169 |
|
|
//Nom de dossier vide |
170 |
|
|
$path = "../var/digitalization/Todo/PC0130551200002.P0"; |
171 |
nmeucci |
4526 |
$path_no_p0 = "../var/digitalization/Todo/DP0130551200001"; |
172 |
mbroquet |
3730 |
//Retour de la fontion listFiles |
173 |
|
|
$listFiles = $this->digitalizedDocument->listFiles($path); |
174 |
nmeucci |
4526 |
$listFiles_no_p0 = $this->digitalizedDocument->listFiles($path_no_p0); |
175 |
mbroquet |
3730 |
//On vérifie que le tableau retourné est vide |
176 |
|
|
$this->assertEquals($listFiles, null); |
177 |
nmeucci |
4526 |
$this->assertEquals($listFiles_no_p0, null); |
178 |
|
|
|
179 |
mbroquet |
3730 |
} |
180 |
|
|
|
181 |
|
|
/* |
182 |
|
|
* Test la fonction extractMetadataFromFilename |
183 |
|
|
*/ |
184 |
|
|
public function testExtractMetadataFromFilename() { |
185 |
|
|
|
186 |
|
|
//Nom possible de document |
187 |
|
|
$filename = "20091106AUTPCP.pdf"; |
188 |
|
|
//Retour de la fonction extractMetadataFromFilename |
189 |
|
|
$extractMetadataFromFilename = $this->digitalizedDocument->extractMetadataFromFilename($filename); |
190 |
|
|
//On vérifie les données retournées |
191 |
|
|
$this->assertEquals($extractMetadataFromFilename["title"], "AUTPCP"); |
192 |
|
|
$this->assertEquals($extractMetadataFromFilename["dateEvenementDocument"], "06/11/2009"); |
193 |
|
|
|
194 |
|
|
//Nom possible de document avec version |
195 |
|
|
$filename = "20130420ART-1.pdf"; |
196 |
|
|
//Retour de la fonction extractMetadataFromFilename |
197 |
|
|
$extractMetadataFromFilename = $this->digitalizedDocument->extractMetadataFromFilename($filename); |
198 |
|
|
//On vérifie les données retournées |
199 |
|
|
$this->assertEquals($extractMetadataFromFilename["title"], "ART"); |
200 |
|
|
$this->assertEquals($extractMetadataFromFilename["dateEvenementDocument"], "20/04/2013"); |
201 |
|
|
|
202 |
|
|
//Nom erroné de document |
203 |
|
|
$filename = "20591212.pdf"; |
204 |
|
|
//Retour de la fonction extractMetadataFromFilename |
205 |
|
|
$extractMetadataFromFilename = $this->digitalizedDocument->extractMetadataFromFilename($filename); |
206 |
|
|
//On vérifie que le tableau retourné est vide |
207 |
|
|
$this->assertEquals($extractMetadataFromFilename, null); |
208 |
|
|
|
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
/** |
212 |
|
|
* Test la fonction extractMetadataToFilestorage |
213 |
|
|
*/ |
214 |
|
|
public function testExtractMetadataToFilestorage() { |
215 |
|
|
|
216 |
|
|
//Nom possible de dossier |
217 |
|
|
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
218 |
nmeucci |
4526 |
$path_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
219 |
mbroquet |
3730 |
//Nom possible de document |
220 |
|
|
$filename = "20091106AUTPCP.pdf"; |
221 |
|
|
//Retour de la fonction extractMetadataToFilestorage |
222 |
|
|
$extractMetadataToFilestorage = $this->digitalizedDocument->extractMetadataToFilestorage($path, $filename); |
223 |
nmeucci |
4526 |
$extractMetadataToFilestorage_no_p0 = $this->digitalizedDocument->extractMetadataToFilestorage($path_no_p0, $filename); |
224 |
mbroquet |
3730 |
//On vérifie les données retournées |
225 |
|
|
$this->assertEquals($extractMetadataToFilestorage['filename'], '20091106AUTPCP.pdf'); |
226 |
|
|
$this->assertEquals($extractMetadataToFilestorage['size'], '17435'); |
227 |
|
|
$this->assertEquals($extractMetadataToFilestorage['mimetype'], 'application/pdf'); |
228 |
nmeucci |
4526 |
// Pour le dossier sans P0 |
229 |
|
|
$this->assertEquals($extractMetadataToFilestorage_no_p0['filename'], '20091106AUTPCP.pdf'); |
230 |
|
|
$this->assertEquals($extractMetadataToFilestorage_no_p0['size'], '17435'); |
231 |
|
|
$this->assertEquals($extractMetadataToFilestorage_no_p0['mimetype'], 'application/pdf'); |
232 |
mbroquet |
3730 |
//Chemin document erroné |
233 |
|
|
$path = ""; |
234 |
nmeucci |
4526 |
$path_no_p0 = ""; |
235 |
mbroquet |
3730 |
//Nom possible de document |
236 |
|
|
$filename = "20091106AUTPCP.pdf"; |
237 |
|
|
//Retour de la fonction extractMetadataToFilestorage |
238 |
|
|
$extractMetadataToFilestorage = $this->digitalizedDocument->extractMetadataToFilestorage($path, $filename); |
239 |
nmeucci |
4526 |
$extractMetadataToFilestorage_no_p0 = $this->digitalizedDocument->extractMetadataToFilestorage($path_no_p0, $filename); |
240 |
mbroquet |
3730 |
//On vérifie que le retour est null |
241 |
|
|
$this->assertEquals($extractMetadataToFilestorage, null); |
242 |
nmeucci |
4526 |
$this->assertEquals($extractMetadataToFilestorage_no_p0, null); |
243 |
mbroquet |
3730 |
|
244 |
|
|
} |
245 |
|
|
|
246 |
|
|
/** |
247 |
|
|
* Test la fonction createFileTemporary |
248 |
|
|
*/ |
249 |
|
|
public function testCreateFileTemporary() { |
250 |
|
|
|
251 |
|
|
//Nom possible d'un répertoire |
252 |
|
|
$foldername = "PC0130551200001.P0"; |
253 |
nmeucci |
4526 |
$foldername_no_p0 = "PA0130551200001"; |
254 |
mbroquet |
3730 |
//Nom possible de dossier |
255 |
|
|
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
256 |
nmeucci |
4526 |
$path_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
257 |
mbroquet |
3730 |
//Nom possible de document |
258 |
|
|
$filename = "20091106AUTPCP.pdf"; |
259 |
|
|
//Construit les métadonnées |
260 |
|
|
$metadata = array(); |
261 |
|
|
//Données récupérées pour le filestorage |
262 |
|
|
$metadata = $this->digitalizedDocument->extractMetadataToFilestorage($path, $filename); |
263 |
nmeucci |
4526 |
$metadata_no_p0 = $this->digitalizedDocument->extractMetadataToFilestorage($path_no_p0, $filename); |
264 |
mbroquet |
3730 |
//Recupère le contenu du fichier |
265 |
|
|
$file_content = file_get_contents($path.'/'.$filename); |
266 |
nmeucci |
4526 |
$file_content_no_p0 = file_get_contents($path.'/'.$filename); |
267 |
mbroquet |
3730 |
|
268 |
|
|
//Retour de la fonction createFile |
269 |
|
|
$createFile = $this->digitalizedDocument->createFileTemporary($file_content, $metadata); |
270 |
nmeucci |
4526 |
$createFile_no_p0 = $this->digitalizedDocument->createFileTemporary($file_content_no_p0, $metadata_no_p0); |
271 |
mbroquet |
3730 |
//On vérifie que l'action s'est bien déroulée |
272 |
|
|
$file_exists_filestorage = $this->digitalizedDocument->filestorage->get_temporary($createFile); |
273 |
nmeucci |
4526 |
$file_exists_filestorage_no_p0 = $this->digitalizedDocument->filestorage->get_temporary($createFile_no_p0); |
274 |
mbroquet |
3730 |
$this->assertTrue($file_exists_filestorage != null); |
275 |
nmeucci |
4526 |
$this->assertTrue($file_exists_filestorage_no_p0 != null); |
276 |
|
|
|
277 |
mbroquet |
3730 |
} |
278 |
|
|
|
279 |
|
|
/** |
280 |
|
|
* Test la fonction createDocumentNumerise |
281 |
|
|
*/ |
282 |
|
|
public function testCreateDocumentNumerise() { |
283 |
|
|
|
284 |
|
|
//Nom possible d'un répertoire |
285 |
|
|
$foldername = "PC0130551200001.P0"; |
286 |
nmeucci |
4526 |
$foldername_no_p0 = "PA0130551200001"; |
287 |
mbroquet |
3730 |
//Identifiant du dossier |
288 |
|
|
$dossier = "PC0130551200001P0"; |
289 |
nmeucci |
4526 |
$dossier_no_p0 = "PA0130551200001"; |
290 |
mbroquet |
3730 |
//Nom possible de dossier |
291 |
|
|
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
292 |
nmeucci |
4526 |
$path_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
293 |
mbroquet |
3730 |
//Nom du document |
294 |
|
|
$filename = "20091106AUTPCP.pdf"; |
295 |
|
|
//Création du fichier |
296 |
|
|
$newfile = "20091106RIPC05.pdf"; |
297 |
|
|
copy($path.'/'.$filename, $path.'/'.$newfile); |
298 |
nmeucci |
4526 |
copy($path_no_p0.'/'.$filename, $path_no_p0.'/'.$newfile); |
299 |
mbroquet |
3730 |
//Instance document_numerise |
300 |
|
|
require_once "../obj/document_numerise.class.php"; |
301 |
|
|
$document_numerise = new document_numerise("]", $this->digitalizedDocument->f->db, NULL); |
302 |
|
|
|
303 |
|
|
//Construit les métadonnées |
304 |
|
|
$metadata = array(); |
305 |
nmeucci |
4526 |
$metadata_no_p0 = array(); |
306 |
mbroquet |
3730 |
//Données récupérées pour le filestorage |
307 |
|
|
$metadata = $this->digitalizedDocument->extractMetadataToFilestorage($path, $newfile); |
308 |
nmeucci |
4526 |
$metadata_no_p0 = $this->digitalizedDocument->extractMetadataToFilestorage($path_no_p0, $newfile); |
309 |
mbroquet |
3730 |
|
310 |
|
|
//Recupère le contenu du fichier |
311 |
|
|
$file_content = file_get_contents($path.'/'.$newfile); |
312 |
nmeucci |
4526 |
$file_content_no_p0 = file_get_contents($path_no_p0.'/'.$newfile); |
313 |
mbroquet |
3730 |
|
314 |
|
|
//Créer le fichier temporaire |
315 |
|
|
$uid = $this->digitalizedDocument->createFileTemporary($file_content, $metadata); |
316 |
nmeucci |
4526 |
$uid_no_p0 = $this->digitalizedDocument->createFileTemporary($file_content_no_p0, $metadata_no_p0); |
317 |
mbroquet |
3730 |
|
318 |
|
|
//Retour de la fonction createFileStorage |
319 |
|
|
$createDocumentNumerise = $this->digitalizedDocument->createDocumentNumerise($document_numerise, $uid, $dossier, $newfile, $this->digitalizedDocument->f->db, NULL); |
320 |
nmeucci |
4526 |
$createDocumentNumerise_no_p0 = $this->digitalizedDocument->createDocumentNumerise($document_numerise, $uid_no_p0, $dossier_no_p0, $newfile, $this->digitalizedDocument->f->db, NULL); |
321 |
mbroquet |
3730 |
|
322 |
|
|
//Supprime le fichier laissé dans le dossier Todo |
323 |
|
|
unlink($path.'/'.$newfile); |
324 |
nmeucci |
4526 |
unlink($path_no_p0.'/'.$newfile); |
325 |
mbroquet |
3730 |
|
326 |
|
|
//On vérifie que le fichier a bien été créé dans le filestorage |
327 |
|
|
$uid = $this->get_uid_by_id($createDocumentNumerise); |
328 |
nmeucci |
4526 |
$uid_no_p0 = $this->get_uid_by_id($createDocumentNumerise_no_p0); |
329 |
|
|
|
330 |
mbroquet |
3730 |
$file_exists_filestorage = $this->digitalizedDocument->filestorage->get($uid); |
331 |
nmeucci |
4526 |
$file_exists_filestorage_no_p0 = $this->digitalizedDocument->filestorage->get($uid_no_p0); |
332 |
|
|
|
333 |
mbroquet |
3730 |
$this->assertTrue($file_exists_filestorage != null); |
334 |
nmeucci |
4526 |
$this->assertTrue($file_exists_filestorage_no_p0 != null); |
335 |
|
|
|
336 |
mbroquet |
3730 |
//Uid pas présent dans la bdd |
337 |
|
|
$uid = uniqid(); |
338 |
nmeucci |
4526 |
$uid_no_p0 = uniqid(); |
339 |
mbroquet |
3730 |
//On vérifie que false est bien retourné |
340 |
|
|
$this->assertEquals($this->checkLinkFile($uid), false); |
341 |
nmeucci |
4526 |
$this->assertEquals($this->checkLinkFile($uid_no_p0), false); |
342 |
|
|
|
343 |
mbroquet |
3730 |
} |
344 |
|
|
|
345 |
|
|
/** |
346 |
|
|
* Test la fonction moveDocumentNumerise |
347 |
|
|
*/ |
348 |
|
|
public function testMoveDocumentNumerise() { |
349 |
|
|
|
350 |
|
|
//Dossier source |
351 |
|
|
$pathSrc = "../var/digitalization/Todo/PC0130551200001.P0"; |
352 |
nmeucci |
4526 |
$pathSrc_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
353 |
mbroquet |
3730 |
//Dossier de destination |
354 |
|
|
$pathDes = "../var/digitalization/Done/PC0130551200001.P0"; |
355 |
nmeucci |
4526 |
$pathDes_no_p0 = "../var/digitalization/Done/PA0130551200001"; |
356 |
mbroquet |
3730 |
//Nom du fichier |
357 |
|
|
$filename = "20091106AUTPCP.pdf"; |
358 |
|
|
//Retour de la fonction moveDocumentNumerise |
359 |
|
|
$moveFile = $this->digitalizedDocument->moveDocumentNumerise($pathSrc, $pathDes, $filename); |
360 |
nmeucci |
4526 |
$moveFile_no_p0 = $this->digitalizedDocument->moveDocumentNumerise($pathSrc_no_p0, $pathDes_no_p0, $filename); |
361 |
mbroquet |
3730 |
//On vérifie que l'action s'est bien déroulée |
362 |
|
|
//Le document doit être présent dans la destination |
363 |
|
|
$file_exists_destination = file_exists($pathDes.'/'.$filename); |
364 |
nmeucci |
4526 |
$file_exists_destination_no_p0 = file_exists($pathDes_no_p0.'/'.$filename); |
365 |
mbroquet |
3730 |
$this->assertEquals($file_exists_destination, true); |
366 |
nmeucci |
4526 |
$this->assertEquals($file_exists_destination_no_p0, true); |
367 |
mbroquet |
3730 |
//Le document ne doit plus être présent dans la source |
368 |
|
|
$file_exists_source = file_exists($pathSrc.'/'.$filename); |
369 |
nmeucci |
4526 |
$file_exists_source_no_p0 = file_exists($pathSrc_no_p0.'/'.$filename); |
370 |
mbroquet |
3730 |
$this->assertEquals($file_exists_source, false); |
371 |
nmeucci |
4526 |
$this->assertEquals($file_exists_source_no_p0, false); |
372 |
mbroquet |
3730 |
|
373 |
|
|
//Remet le fichier dans todo pour les autres tests |
374 |
|
|
rename($pathDes.'/'.$filename, $pathSrc.'/'.$filename); |
375 |
nmeucci |
4526 |
rename($pathDes_no_p0.'/'.$filename, $pathSrc_no_p0.'/'.$filename); |
376 |
mbroquet |
3730 |
|
377 |
|
|
} |
378 |
|
|
|
379 |
|
|
/** |
380 |
|
|
* Test la fonction purgeFiles |
381 |
|
|
*/ |
382 |
|
|
public function testPurgeFiles() { |
383 |
|
|
|
384 |
|
|
//Dossier source |
385 |
|
|
$pathSrc = "../var/digitalization/Todo/PC0130551200001.P0"; |
386 |
nmeucci |
4526 |
$pathSrc_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
387 |
mbroquet |
3730 |
//Dossier de destination |
388 |
|
|
$pathDes = "../var/digitalization/Done/PC0130551200001.P0"; |
389 |
nmeucci |
4526 |
$pathDes_no_p0 = "../var/digitalization/Done/PA0130551200001"; |
390 |
mbroquet |
3730 |
//Création dossier |
391 |
|
|
if (!file_exists($pathDes)) { |
392 |
|
|
mkdir("../var/digitalization/Done/PC0130551200001.P0"); |
393 |
|
|
} |
394 |
nmeucci |
4526 |
if (!file_exists($pathDes_no_p0)) { |
395 |
|
|
mkdir("../var/digitalization/Done/PA0130551200001"); |
396 |
|
|
} |
397 |
mbroquet |
3730 |
//Nom du fichier |
398 |
|
|
$filename = "20091106AUTPCP.pdf"; |
399 |
|
|
//Met le fichier dans Done |
400 |
|
|
copy($pathSrc.'/'.$filename, $pathDes.'/'.$filename); |
401 |
nmeucci |
4526 |
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$filename); |
402 |
mbroquet |
3730 |
|
403 |
|
|
//fichier |
404 |
|
|
$file = $pathDes.'/'.$filename; |
405 |
nmeucci |
4526 |
$file_no_p0 = $pathDes_no_p0.'/'.$filename; |
406 |
mbroquet |
3730 |
//Date de l'import du document |
407 |
|
|
$dateImport = "2012-01-01"; |
408 |
|
|
//Nombre jour |
409 |
|
|
$nbDay = 60; |
410 |
|
|
//Retour de la fonction purge |
411 |
|
|
$purgeFiles = $this->digitalizedDocument->purgeFiles($file, $dateImport, $nbDay); |
412 |
|
|
//On vérifie que l'action s'est bien déroulée |
413 |
|
|
$this->assertEquals($purgeFiles, true); |
414 |
|
|
|
415 |
|
|
//Création du fichier |
416 |
|
|
$newfile = "20091106RIPC05.pdf"; |
417 |
|
|
copy($pathSrc.'/'.$filename, $pathDes.'/'.$newfile); |
418 |
nmeucci |
4526 |
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$newfile); |
419 |
mbroquet |
3730 |
//fichier |
420 |
|
|
$file = $pathDes.'/'.$newfile; |
421 |
nmeucci |
4526 |
$file_no_p0 = $pathDes_no_p0.'/'.$newfile; |
422 |
mbroquet |
3730 |
//Retour de la fonction purge sans les paramètres de date |
423 |
|
|
$purgeFiles = $this->digitalizedDocument->purgeFiles($file); |
424 |
nmeucci |
4526 |
$purgeFiles_no_p0 = $this->digitalizedDocument->purgeFiles($file_no_p0); |
425 |
mbroquet |
3730 |
//On vérifie que l'action s'est bien déroulée |
426 |
|
|
$this->assertEquals($purgeFiles, true); |
427 |
nmeucci |
4526 |
$this->assertEquals($purgeFiles_no_p0, true); |
428 |
mbroquet |
3730 |
|
429 |
|
|
//Création du fichier |
430 |
|
|
$newfile = "20091106DGPC03.pdf"; |
431 |
|
|
copy($pathSrc.'/'.$filename, $pathDes.'/'.$newfile); |
432 |
nmeucci |
4526 |
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$newfile); |
433 |
|
|
|
434 |
mbroquet |
3730 |
//fichier |
435 |
|
|
$file = $pathDes.'/'.$newfile; |
436 |
nmeucci |
4526 |
$file_no_p0 = $pathDes_no_p0.'/'.$newfile; |
437 |
mbroquet |
3730 |
//Date de l'import du document |
438 |
|
|
$dateImport = date('d-m-Y'); |
439 |
|
|
//Nombre jour |
440 |
|
|
$nbDay = 60; |
441 |
|
|
//Retour de la fonction purge |
442 |
|
|
$purgeFiles = $this->digitalizedDocument->purgeFiles($file, $dateImport, $nbDay); |
443 |
nmeucci |
4526 |
$purgeFiles_no_p0 = $this->digitalizedDocument->purgeFiles($file_no_p0, $dateImport, $nbDay); |
444 |
|
|
|
445 |
mbroquet |
3730 |
//On vérifie que l'action s'est bien déroulée |
446 |
|
|
$this->assertEquals($purgeFiles, false); |
447 |
nmeucci |
4526 |
$this->assertEquals($purgeFiles_no_p0, false); |
448 |
mbroquet |
3730 |
|
449 |
|
|
//Supprime le fichier laissé dans le dossier Done |
450 |
|
|
unlink($pathDes.'/'.$newfile); |
451 |
nmeucci |
4526 |
unlink($pathDes_no_p0.'/'.$newfile); |
452 |
mbroquet |
3730 |
|
453 |
|
|
} |
454 |
|
|
|
455 |
|
|
/** |
456 |
|
|
* Test la fonction run_import |
457 |
|
|
*/ |
458 |
|
|
public function test_run_import() { |
459 |
|
|
|
460 |
|
|
//Nom de dossier |
461 |
|
|
$pathSrc = "../var/digitalization/Todo/PC0130551200001.P0"; |
462 |
nmeucci |
4526 |
$pathSrc_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
463 |
mbroquet |
3730 |
//Nom dossier destination |
464 |
|
|
$pathDes = "../var/digitalization/Done/PC0130551200001.P0"; |
465 |
nmeucci |
4526 |
$pathDes_no_p0 = "../var/digitalization/Done/PA0130551200001"; |
466 |
mbroquet |
3730 |
//Renomme le fichier pdf |
467 |
|
|
$path = "../var/digitalization/Todo/PC0130551200001.P0"; |
468 |
|
|
$listFiles = $this->digitalizedDocument->listFiles($pathSrc); |
469 |
nmeucci |
4526 |
$listFiles_no_p0 = $this->digitalizedDocument->listFiles($pathSrc_no_p0); |
470 |
mbroquet |
3730 |
//On vérifie les documents retourné |
471 |
|
|
rename($pathSrc.'/'."20091106AUTPCP.pdf", $pathSrc.'/'."20091106NDL.pdf"); |
472 |
|
|
rename($pathSrc.'/'."20091106AUTPCP-1.pdf", $pathSrc.'/'."20091106NDL-1.pdf"); |
473 |
nmeucci |
4526 |
rename($pathSrc_no_p0.'/'."20091106AUTPCP.pdf", $pathSrc_no_p0.'/'."20091106NDL.pdf"); |
474 |
|
|
rename($pathSrc_no_p0.'/'."20091106AUTPCP-1.pdf", $pathSrc_no_p0.'/'."20091106NDL-1.pdf"); |
475 |
mbroquet |
3730 |
|
476 |
|
|
//Déclarations paramètre |
477 |
|
|
$db = $this->digitalizedDocument->f->db; |
478 |
|
|
$DEBUG = NULL; |
479 |
|
|
//Retour de la fonction run_import |
480 |
|
|
$run_import = $this->digitalizedDocument->run_import($pathSrc, $pathDes, $db, $DEBUG); |
481 |
nmeucci |
4526 |
$run_import_no_p0 = $this->digitalizedDocument->run_import($pathSrc_no_p0, $pathDes_no_p0, $db, $DEBUG); |
482 |
mbroquet |
3730 |
//On vérifie que l'action s'est bien déroulée |
483 |
|
|
$this->assertEquals($run_import, true); |
484 |
nmeucci |
4526 |
$this->assertEquals($run_import_no_p0, true); |
485 |
mbroquet |
3730 |
$this->assertEquals(count($this->digitalizedDocument->filenameError), 0); |
486 |
|
|
|
487 |
|
|
//Replace les fichiers dans le fichier source |
488 |
|
|
copy($pathDes.'/'."20091106NDL.pdf", $pathSrc.'/'."20091106AUTPCP.pdf"); |
489 |
|
|
copy($pathDes.'/'."20091106NDL-1.pdf", $pathSrc.'/'."20091106AUTPCP-1.pdf"); |
490 |
nmeucci |
4526 |
copy($pathDes_no_p0.'/'."20091106NDL.pdf", $pathSrc_no_p0.'/'."20091106AUTPCP.pdf"); |
491 |
|
|
copy($pathDes_no_p0.'/'."20091106NDL-1.pdf", $pathSrc_no_p0.'/'."20091106AUTPCP-1.pdf"); |
492 |
mbroquet |
3730 |
} |
493 |
|
|
|
494 |
|
|
/** |
495 |
|
|
* Test la fonction run_purge |
496 |
|
|
*/ |
497 |
|
|
public function test_run_purge() { |
498 |
|
|
|
499 |
|
|
//Dossier source |
500 |
|
|
$pathSrc = "../var/digitalization/Todo/PC0130551200001.P0"; |
501 |
nmeucci |
4526 |
$pathSrc_no_p0 = "../var/digitalization/Todo/PA0130551200001"; |
502 |
mbroquet |
3730 |
//Dossier de destination |
503 |
|
|
$pathDes = "../var/digitalization/Done/PC0130551200001.P0"; |
504 |
nmeucci |
4526 |
$pathDes_no_p0 = "../var/digitalization/Done/PA0130551200001"; |
505 |
mbroquet |
3730 |
//Création dossier |
506 |
|
|
if (!file_exists($pathDes)) { |
507 |
|
|
mkdir("../var/digitalization/Done/PC0130551200001.P0"); |
508 |
|
|
} |
509 |
nmeucci |
4526 |
if (!file_exists($pathDes_no_p0)) { |
510 |
|
|
mkdir("../var/digitalization/Done/PA0130551200001"); |
511 |
|
|
} |
512 |
mbroquet |
3730 |
//Nom du fichier |
513 |
|
|
$filename = "20091106AUTPCP.pdf"; |
514 |
|
|
//Met le fichier 20091106AUTPCP dans Done |
515 |
|
|
copy($pathSrc.'/'.$filename, $pathDes.'/'.$filename); |
516 |
nmeucci |
4526 |
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$filename); |
517 |
mbroquet |
3730 |
//Création du fichier 20091106RIPC05 |
518 |
|
|
$newfile = "20091106RIPC05.pdf"; |
519 |
|
|
copy($pathSrc.'/'.$filename, $pathDes.'/'.$newfile); |
520 |
nmeucci |
4526 |
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$newfile); |
521 |
mbroquet |
3730 |
//Création du fichier 20091106DGPC03 |
522 |
|
|
$newfile = "20091106DGPC03.pdf"; |
523 |
|
|
copy($pathSrc.'/'.$filename, $pathDes.'/'.$newfile); |
524 |
nmeucci |
4526 |
copy($pathSrc_no_p0.'/'.$filename, $pathDes_no_p0.'/'.$newfile); |
525 |
mbroquet |
3730 |
|
526 |
|
|
//Retour de la fonction run_purge sans date |
527 |
|
|
$run_purge = $this->digitalizedDocument->run_purge($pathDes); |
528 |
nmeucci |
4526 |
$run_purge_no_p0 = $this->digitalizedDocument->run_purge($pathDes_no_p0); |
529 |
|
|
|
530 |
mbroquet |
3730 |
//On vérifie que l'action s'est bien déroulée |
531 |
|
|
$this->assertEquals($run_purge, true); |
532 |
nmeucci |
4526 |
$this->assertEquals($run_purge_no_p0, true); |
533 |
|
|
|
534 |
mbroquet |
3730 |
} |
535 |
|
|
|
536 |
|
|
} |
537 |
|
|
|
538 |
|
|
?> |