336 |
// Destruction de la classe Utils |
// Destruction de la classe Utils |
337 |
$f->__destruct(); |
$f->__destruct(); |
338 |
} |
} |
339 |
|
|
340 |
|
/** |
341 |
|
* Teste la fonction sendMail() de la classe Utils. |
342 |
|
*/ |
343 |
|
public function test_04_utils_sendmail() { |
344 |
|
|
345 |
|
// Instance de la classe Utils |
346 |
|
require_once "../obj/utils.class.php"; |
347 |
|
@session_start(); |
348 |
|
$_SESSION['collectivite'] = 1; |
349 |
|
$_SESSION['login'] = "admin"; |
350 |
|
$_SERVER['REQUEST_URI'] = ""; |
351 |
|
$f = new utils("nohtml"); |
352 |
|
$f->disableLog(); |
353 |
|
|
354 |
|
// Paramétrage |
355 |
|
$objet = '[openADS] Test de l\'envoi de mail'; |
356 |
|
$corps = 'Ne pas répondre.'; |
357 |
|
$email = '[email protected]'; |
358 |
|
|
359 |
|
// Succès |
360 |
|
$case_1 = $f->sendMail( |
361 |
|
iconv('UTF-8', 'CP1252', $objet), |
362 |
|
iconv('UTF-8', 'CP1252', $corps), |
363 |
|
iconv('UTF-8', 'CP1252', $email)); |
364 |
|
$this->assertEquals(true, $case_1); |
365 |
|
|
366 |
|
// Échec cause email invalide |
367 |
|
$case_2 = $f->sendMail( |
368 |
|
iconv('UTF-8', 'CP1252', $objet), |
369 |
|
iconv('UTF-8', 'CP1252', $corps), |
370 |
|
iconv('UTF-8', 'CP1252', 'email_incorrect')); |
371 |
|
$this->assertEquals(false, $case_2); |
372 |
|
|
373 |
|
// Échec cause mauvaise configuration du compte mail |
374 |
|
$file_path = PATH_OPENMAIRIE.'../dyn/mail.inc.php'; |
375 |
|
$old_file_content = file_get_contents($file_path); |
376 |
|
$line_password = array(); |
377 |
|
preg_match_all("/^.*mail_pass.*,$/m", $old_file_content, $line_password); |
378 |
|
$old_line_password = $line_password[0]; |
379 |
|
$new_line_password = ' \'mail_pass\' => \'1234\','; |
380 |
|
$new_file_content = str_replace($old_line_password, $new_line_password, $old_file_content); |
381 |
|
// Reconfiguration incorrecte pour ce test |
382 |
|
file_put_contents($file_path, $new_file_content); |
383 |
|
$f->__destruct(); |
384 |
|
$f = new utils("nohtml"); |
385 |
|
$f->disableLog(); |
386 |
|
// Tentative d'envoi |
387 |
|
$case_3 = $f->sendMail( |
388 |
|
iconv('UTF-8', 'CP1252', $objet), |
389 |
|
iconv('UTF-8', 'CP1252', $corps), |
390 |
|
iconv('UTF-8', 'CP1252', $email)); |
391 |
|
// Reconfiguration valide pour la suite des tests |
392 |
|
file_put_contents($file_path, $old_file_content); |
393 |
|
$f->__destruct(); |
394 |
|
$f = new utils("nohtml"); |
395 |
|
$f->disableLog(); |
396 |
|
// Vérification |
397 |
|
$this->assertEquals(false, $case_3); |
398 |
|
// Destruction de la classe Utils |
399 |
|
$f->__destruct(); |
400 |
|
} |
401 |
} |
} |
402 |
|
|
403 |
?> |
?> |