9 |
/** |
/** |
10 |
* Cette classe permet de tester unitairement les fonctions de l'application. |
* Cette classe permet de tester unitairement les fonctions de l'application. |
11 |
*/ |
*/ |
12 |
class General extends PHPUnit_Framework_TestCase { |
class General extends PHPUnit\Framework\TestCase { |
13 |
|
|
14 |
/** |
/** |
15 |
* Méthode lancée en début de traitement |
* Méthode lancée en début de traitement |
21 |
echo ' = '.get_class().'.'.str_replace('test_', '', $this->getName())."\r\n"; |
echo ' = '.get_class().'.'.str_replace('test_', '', $this->getName())."\r\n"; |
22 |
} |
} |
23 |
|
|
24 |
public function onNotSuccessfulTest(Exception $e){ |
public function onNotSuccessfulTest(Throwable $e){ |
25 |
echo 'Line '.$e->getLine().' : '.$e->getMessage()."\r\n"; |
echo 'Line '.$e->getLine().' : '.$e->getMessage()."\r\n"; |
26 |
parent::onNotSuccessfulTest($e); |
parent::onNotSuccessfulTest($e); |
27 |
} |
} |
248 |
$_SESSION['login'] = "admin"; |
$_SESSION['login'] = "admin"; |
249 |
$_SERVER['REQUEST_URI'] = ""; |
$_SERVER['REQUEST_URI'] = ""; |
250 |
$f = new utils("nohtml"); |
$f = new utils("nohtml"); |
251 |
|
$GLOBALS['f'] = $f; |
252 |
$f->disableLog(); |
$f->disableLog(); |
253 |
|
|
254 |
require_once "../core/om_edition.class.php"; |
$edition = $f->get_inst__om_edition(); |
|
$edition = new edition(); |
|
|
$edition->f = $f; |
|
255 |
// Vérification du logo de collectivité mono dans le cas où : |
// Vérification du logo de collectivité mono dans le cas où : |
256 |
// - un logo multi actif est défini |
// - un logo multi actif est défini |
257 |
// - un logo actif pour la collectivité est défini |
// - un logo actif pour la collectivité est défini |
319 |
// résultat attendu |
// résultat attendu |
320 |
$di = 'PC01'; |
$di = 'PC01'; |
321 |
$inst = 7; |
$inst = 7; |
322 |
$url = 'http://localhost/openads/spg/direct_link.php?obj=dossier_instruction&action=3'; |
$url = 'http://localhost/openads/app/index.php?module=form&direct_link=true&obj=dossier_instruction&action=3'; |
323 |
$url .= '&direct_field=dossier&direct_form=instruction&direct_action=3&direct_idx='.$inst; |
$url .= '&direct_field=dossier&direct_form=instruction&direct_action=3&direct_idx='.$inst; |
324 |
$link = '<a href="'.$url.'">'.$url.'</a>'; |
$link = '<a href="'.$url.'">'.$url.'</a>'; |
325 |
$expected = 'DI : '.$di.'<br/>'; |
$expected = 'DI : '.$di.'<br/>'; |
326 |
$expected .= 'LIEN : '.$link.'<br/>'; |
$expected .= 'LIEN : '.$link.'<br/>'; |
327 |
$expected .= 'INSTRUCTION : '.$inst; |
$expected .= 'INSTRUCTION : '.$inst; |
328 |
// Instance de la classe instruction |
// Instance de la classe instruction |
329 |
require_once "../obj/instruction.class.php"; |
$instr = $f->get_inst__om_dbform(array( |
330 |
$instr = new instruction(']', $f->db, DEBUG); |
"obj" => "instruction", |
331 |
|
"idx" => "]", |
332 |
|
)); |
333 |
// Traitement |
// Traitement |
334 |
$result = $instr->formater_modele($template, $di, $inst); |
$result = $instr->formater_modele($template, $di, $inst); |
335 |
// Vérification du traitement |
// Vérification du traitement |
338 |
$f->__destruct(); |
$f->__destruct(); |
339 |
} |
} |
340 |
|
|
|
/** |
|
|
* Teste la fonction sendMail() de la classe Utils. |
|
|
*/ |
|
|
public function test_04_utils_sendmail() { |
|
|
|
|
|
// Instance de la classe Utils |
|
|
require_once "../obj/utils.class.php"; |
|
|
@session_start(); |
|
|
$_SESSION['collectivite'] = 1; |
|
|
$_SESSION['login'] = "admin"; |
|
|
$_SERVER['REQUEST_URI'] = ""; |
|
|
$f = new utils("nohtml"); |
|
|
$f->disableLog(); |
|
|
|
|
|
// Paramétrage |
|
|
$objet = '[openADS] Test de l\'envoi de mail'; |
|
|
$corps = 'Ne pas répondre.'; |
|
|
$email = '[email protected]'; |
|
|
|
|
|
// Succès |
|
|
$case_1 = $f->sendMail( |
|
|
iconv('UTF-8', 'CP1252', $objet), |
|
|
iconv('UTF-8', 'CP1252', $corps), |
|
|
iconv('UTF-8', 'CP1252', $email)); |
|
|
$this->assertEquals(true, $case_1); |
|
|
|
|
|
// Échec cause email invalide |
|
|
$case_2 = $f->sendMail( |
|
|
iconv('UTF-8', 'CP1252', $objet), |
|
|
iconv('UTF-8', 'CP1252', $corps), |
|
|
iconv('UTF-8', 'CP1252', 'email_incorrect')); |
|
|
$this->assertEquals(false, $case_2); |
|
|
|
|
|
// Échec cause mauvaise configuration du compte mail |
|
|
$file_path = PATH_OPENMAIRIE.'../dyn/mail.inc.php'; |
|
|
$old_file_content = file_get_contents($file_path); |
|
|
$line_password = array(); |
|
|
preg_match_all("/^.*mail_pass.*,$/m", $old_file_content, $line_password); |
|
|
$old_line_password = $line_password[0]; |
|
|
$new_line_password = ' \'mail_pass\' => \'1234\','; |
|
|
$new_file_content = str_replace($old_line_password, $new_line_password, $old_file_content); |
|
|
// Reconfiguration incorrecte pour ce test |
|
|
file_put_contents($file_path, $new_file_content); |
|
|
$f->__destruct(); |
|
|
$f = new utils("nohtml"); |
|
|
$f->disableLog(); |
|
|
// Tentative d'envoi |
|
|
$case_3 = $f->sendMail( |
|
|
iconv('UTF-8', 'CP1252', $objet), |
|
|
iconv('UTF-8', 'CP1252', $corps), |
|
|
iconv('UTF-8', 'CP1252', $email)); |
|
|
// Reconfiguration valide pour la suite des tests |
|
|
file_put_contents($file_path, $old_file_content); |
|
|
$f->__destruct(); |
|
|
$f = new utils("nohtml"); |
|
|
$f->disableLog(); |
|
|
// Vérification |
|
|
$this->assertEquals(false, $case_3); |
|
|
// Destruction de la classe Utils |
|
|
$f->__destruct(); |
|
|
} |
|
341 |
|
|
342 |
/** |
/** |
343 |
* TNR du bug de champs de fusion [*_correspondant] dans la om_requete n°7 "dossier". |
* TNR du bug de champs de fusion [*_correspondant] dans la om_requete n°7 "dossier". |
355 |
$f->disableLog(); |
$f->disableLog(); |
356 |
$GLOBALS["f"] = $f; |
$GLOBALS["f"] = $f; |
357 |
|
|
358 |
require_once "../obj/om_requete.class.php"; |
$om_requete = $f->get_inst__om_dbform(array( |
359 |
$om_requete = new om_requete(7); |
"obj" => "om_requete", |
360 |
|
"idx" => 7, |
361 |
|
)); |
362 |
|
|
363 |
// récupération de la requête SQL |
// récupération de la requête SQL |
364 |
$sql = $om_requete->getVal('requete'); |
$sql = $om_requete->getVal('requete'); |
380 |
// Destruction de la classe Utils |
// Destruction de la classe Utils |
381 |
$f->__destruct(); |
$f->__destruct(); |
382 |
} |
} |
383 |
|
|
384 |
|
/** |
385 |
|
* TNR de la methode factorisé de création de dossier_message |
386 |
|
*/ |
387 |
|
function test_06_TNR_dossier_message() { |
388 |
|
// Instanciation de tout les requis |
389 |
|
require_once "../obj/utils.class.php"; |
390 |
|
@session_start(); |
391 |
|
$_SESSION['collectivite'] = 2; |
392 |
|
$_SESSION['login'] = "admin"; |
393 |
|
$_SERVER['REQUEST_URI'] = ""; |
394 |
|
$f = new utils("nohtml"); |
395 |
|
$f->disableLog(); |
396 |
|
$GLOBALS["f"] = $f; |
397 |
|
$dossier_message_factory = $f->get_inst__om_dbform(array( |
398 |
|
"obj" => "dossier_message", |
399 |
|
"idx" => 0, |
400 |
|
)); |
401 |
|
$dossier_message_val = array(); |
402 |
|
|
403 |
|
$dossier_message_val['contenu'] = 'Test Success'; |
404 |
|
$dossier_message_val['dossier'] = 'AT0130551200001P0'; |
405 |
|
$dossier_message_val['type'] = _('Ajout de pièce(s)'); |
406 |
|
$dossier_message_val['emetteur'] = 'instr'; |
407 |
|
$dossier_message_val['login'] = 'instr'; |
408 |
|
$dossier_message_val['date_emission'] = date('Y-m-d H:i:s'); |
409 |
|
$add = $dossier_message_factory->add_notification_message($dossier_message_val); |
410 |
|
$this->assertEquals(true, $add); |
411 |
|
$this->assertEquals(true, isset($dossier_message_factory->valF[$dossier_message_factory->clePrimaire])); |
412 |
|
$dossier_message = $f->get_inst__om_dbform(array( |
413 |
|
"obj" => "dossier_message", |
414 |
|
"idx" => $dossier_message_factory->valF[$dossier_message_factory->clePrimaire], |
415 |
|
)); |
416 |
|
$this->assertEquals($dossier_message_val['dossier'], $dossier_message->getVal('dossier')); |
417 |
|
$this->assertEquals('t', $dossier_message->getVal('lu')); |
418 |
|
|
419 |
|
$dossier_message_val['contenu'] = 'Test Duplicata'; |
420 |
|
$add = $dossier_message_factory->add_notification_message($dossier_message_val); |
421 |
|
$this->assertEquals(true, $add); |
422 |
|
|
423 |
|
$dossier_message_val['contenu'] = 'Test nouveau type même dossier'; |
424 |
|
$dossier_message_val['type'] = _('Autorisation contestée'); |
425 |
|
$add = $dossier_message_factory->add_notification_message($dossier_message_val); |
426 |
|
$this->assertEquals(true, $add); |
427 |
|
|
428 |
|
$dossier_message_val['contenu'] = 'Test message non lu'; |
429 |
|
$dossier_message_val['dossier'] = 'AZ0130551200001P0'; |
430 |
|
$dossier_message_val['emetteur'] = $f->get_connected_user_login_name(); |
431 |
|
$dossier_message_val['login'] = $_SESSION['login']; |
432 |
|
$add = $dossier_message_factory->add_notification_message($dossier_message_val); |
433 |
|
$this->assertEquals(true, $add); |
434 |
|
$dossier_message = $f->get_inst__om_dbform(array( |
435 |
|
"obj" => "dossier_message", |
436 |
|
"idx" => $dossier_message_factory->valF[$dossier_message_factory->clePrimaire], |
437 |
|
)); |
438 |
|
$this->assertEquals('f', $dossier_message->getVal('lu')); |
439 |
|
|
440 |
|
// Destruction de la classe Utils |
441 |
|
$f->__destruct(); |
442 |
|
} |
443 |
|
|
444 |
|
|
445 |
} |
} |