git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5827 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
227 lines
8.7 KiB
PHP
227 lines
8.7 KiB
PHP
<?php
|
|
/** DomFramework - Tests
|
|
@package domframework
|
|
@author Dominique Fournier <dominique@fournier38.fr> */
|
|
|
|
/** Test the mail.php file */
|
|
class mailTest extends PHPUnit_Framework_TestCase
|
|
{
|
|
public function test_setBodyText1 ()
|
|
{
|
|
$mail = new mail ();
|
|
$mail->setBodyText ("TEST");
|
|
$res = $mail->getMail ();
|
|
$this->assertRegExp ("#TEST\n$#", $res);
|
|
}
|
|
|
|
public function test_setBodyHTML1 ()
|
|
{
|
|
$mail = new mail ();
|
|
$mail->setBodyHTML ("TEST");
|
|
$res = $mail->getMail ();
|
|
$this->assertRegExp ("#^\r\nTEST\n$#m", $res);
|
|
}
|
|
|
|
public function test_setGetBodyText1 ()
|
|
{
|
|
$mail = new mail ();
|
|
$mail->setBodyText ("TEST");
|
|
$res = $mail->getBodyText ();
|
|
$this->assertSame ("TEST\n", $res);
|
|
}
|
|
|
|
public function test_setGetBodyHtml1 ()
|
|
{
|
|
$mail = new mail ();
|
|
$mail->setBodyHtml ("TEST");
|
|
$res = $mail->getBodyHtml ();
|
|
$this->assertSame ("TEST\n", $res);
|
|
}
|
|
|
|
public function test_setFrom1 ()
|
|
{
|
|
$mail = new mail ();
|
|
$mail->setFrom ("test@example.com", "Test Exa1mple Com");
|
|
$res = $mail->getFrom ();
|
|
$this->assertSame ("Test Exa1mple Com <test@example.com>\r\n", $res);
|
|
}
|
|
|
|
public function test_addTo1 ()
|
|
{
|
|
$mail = new mail ();
|
|
$mail->addTo ("test@example.com", "Test Exa1mple Com");
|
|
$res = $mail->getTo ();
|
|
$this->assertSame ("Test Exa1mple Com <test@example.com>\r\n", $res);
|
|
}
|
|
|
|
public function test_addTo2 ()
|
|
{
|
|
$mail = new mail ();
|
|
$mail->addTo ("test@example.com", "Test Exa1mple Com");
|
|
$res = $mail->getMail ();
|
|
$this->assertRegexp ("#^To: Test Exa1mple Com <test@example.com>\r$#m", $res);
|
|
}
|
|
|
|
public function test_setDateTimestamp1 ()
|
|
{
|
|
$mail = new mail ();
|
|
$time = time ();
|
|
$mail->setDateTimestamp ($time);
|
|
$res = $mail->getDateTimestamp ();
|
|
$this->assertSame ($res, $time);
|
|
}
|
|
|
|
public function test_setDateTimestamp2 ()
|
|
{
|
|
$mail = new mail ();
|
|
$time = time ();
|
|
$mail->setDateTimestamp ($time);
|
|
$res = $mail->getMail ();
|
|
$this->assertRegexp ("#^Date: ".preg_quote (date ("r", $time))."\r$#m", $res);
|
|
}
|
|
|
|
public function test_convertPeopleToArray1 ()
|
|
{
|
|
$mail = new mail ();
|
|
$res = $mail->convertPeopleToArray ("toto toto <toto@toto.com>");
|
|
$this->assertSame ($res, array (array ("name"=>"toto toto",
|
|
"mail"=>"toto@toto.com")));
|
|
}
|
|
|
|
public function test_convertPeopleToArray2 ()
|
|
{
|
|
$mail = new mail ();
|
|
$res = $mail->convertPeopleToArray ("<toto@toto.com>");
|
|
$this->assertSame ($res, array (array ("name"=>"",
|
|
"mail"=>"toto@toto.com")));
|
|
}
|
|
|
|
public function test_convertPeopleToArray3 ()
|
|
{
|
|
$mail = new mail ();
|
|
$res = $mail->convertPeopleToArray ("toto@toto.com,titi@titi.com");
|
|
$this->assertSame ($res, array (array ("name" => "",
|
|
"mail" => "toto@toto.com"),
|
|
array ("name" => "",
|
|
"mail" => "titi@titi.com")));
|
|
}
|
|
|
|
public function test_convertPeopleToArray4 ()
|
|
{
|
|
$mail = new mail ();
|
|
$res = $mail->convertPeopleToArray ("toto@toto.com");
|
|
$this->assertSame ($res, array (array ("name"=>"",
|
|
"mail"=>"toto@toto.com")));
|
|
}
|
|
|
|
public function test_convertPeopleToArray5 ()
|
|
{
|
|
$mail = new mail ();
|
|
$res = $mail->convertPeopleToArray (" <toto@toto.com> , <titi@titi.com>");
|
|
$this->assertSame ($res, array (array ("name" => "",
|
|
"mail" => "toto@toto.com"),
|
|
array ("name" => "",
|
|
"mail" => "titi@titi.com")));
|
|
}
|
|
|
|
public function test_convertPeopleToArray6 ()
|
|
{
|
|
$mail = new mail ();
|
|
$res = $mail->convertPeopleToArray ("ToTo <toto@toto.com> , <titi@titi.com>");
|
|
$this->assertSame ($res, array (array ("name" => "ToTo",
|
|
"mail" => "toto@toto.com"),
|
|
array ("name" => "",
|
|
"mail" => "titi@titi.com")));
|
|
}
|
|
|
|
/** Read all the headers and return them as JSON object
|
|
*/
|
|
public function testHeadersToJSON1 ()
|
|
{
|
|
$mail = new mail ();
|
|
$mail->readMail ( // {{{
|
|
"Return-Path: <dominique.fournier@grenoble.cnrs.fr>
|
|
Delivered-To: dominique@fournier38.fr
|
|
Received: from mail-postfix-mx.fournier38.fr ([192.168.1.103])
|
|
by mail-dovecot.fournier38.fr with LMTP
|
|
id z706BqQt7V15IAAAA28uxw
|
|
(envelope-from <dominique.fournier@grenoble.cnrs.fr>)
|
|
for <dominique@fournier38.fr>; Sun, 08 Dec 2019 18:06:44 +0100
|
|
Received: from mailgw-out1.grenoble.cnrs.fr (mailgw-out1.grenoble.cnrs.fr [147.173.1.68])
|
|
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
|
|
(No client certificate requested)
|
|
by mail-postfix-mx.fournier38.fr (Postfix) with ESMTPS id 8A2DF820733
|
|
for <dominique@fournier38.fr>; Sun, 8 Dec 2019 18:06:43 +0100 (CET)
|
|
DMARC-Filter: OpenDMARC Filter v1.3.2 mail-postfix-mx.fournier38.fr 8A2DF820733
|
|
Delivered-To: dominique.fournier@grenoble.cnrs.fr
|
|
Received: from [192.168.1.154] (82-64-55-197.subs.proxad.net [82.64.55.197])
|
|
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
|
|
(No client certificate requested)
|
|
by mailgw-out1.grenoble.cnrs.fr (Postfix) with ESMTPSA id 458EDBFCE4
|
|
for <dominique@fournier38.fr>; Sun, 8 Dec 2019 18:08:06 +0100 (CET)
|
|
From: Dominique Fournier <dominique.fournier@grenoble.cnrs.fr>
|
|
Subject: Analyse de texte
|
|
To: Dominique Fournier / Fournier38 <dominique@fournier38.fr>
|
|
Message-ID: <81d7982f-7fee-96b4-078f-a6365234356f@grenoble.cnrs.fr>
|
|
Date: Sun, 8 Dec 2019 18:08:06 +0100
|
|
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
|
|
Thunderbird/68.2.2
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=utf-8; format=flowed
|
|
Content-Language: en-US
|
|
Content-Transfer-Encoding: 7bit
|
|
Authentication-Results: mail-postfix-mx.fournier38.fr;
|
|
dkim=none;
|
|
dmarc=none;
|
|
spf=pass (mail-postfix-mx.fournier38.fr: domain of dominique.fournier@grenoble.cnrs.fr designates 147.173.1.68 as permitted sender) smtp.mailfrom=dominique.fournier@grenoble.cnrs.fr
|
|
X-Spamd-Bar: --------------------------------------------------------------------------------------------------
|
|
|
|
https://openclassrooms.com/fr/courses/4470541-analysez-vos-donnees-textuelles/4854971-nettoyez-et-normalisez-les-donnees
|
|
|
|
http://www.nltk.org/nltk_data/
|
|
|
|
http://www.cs.cmu.edu/~ralf/langid.html
|
|
");
|
|
// }}}
|
|
$this->assertSame ($mail->getHeaders (), array (
|
|
["Return-Path" => "<dominique.fournier@grenoble.cnrs.fr>\n"],
|
|
["Delivered-To" => "dominique@fournier38.fr\n"],
|
|
["Received" => "from mail-postfix-mx.fournier38.fr ([192.168.1.103])
|
|
by mail-dovecot.fournier38.fr with LMTP
|
|
id z706BqQt7V15IAAAA28uxw
|
|
(envelope-from <dominique.fournier@grenoble.cnrs.fr>)
|
|
for <dominique@fournier38.fr>; Sun, 08 Dec 2019 18:06:44 +0100\n"],
|
|
["Received" => "from mailgw-out1.grenoble.cnrs.fr (mailgw-out1.grenoble.cnrs.fr [147.173.1.68])
|
|
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
|
|
(No client certificate requested)
|
|
by mail-postfix-mx.fournier38.fr (Postfix) with ESMTPS id 8A2DF820733
|
|
for <dominique@fournier38.fr>; Sun, 8 Dec 2019 18:06:43 +0100 (CET)\n"],
|
|
["DMARC-Filter" => "OpenDMARC Filter v1.3.2 mail-postfix-mx.fournier38.fr 8A2DF820733\n"],
|
|
["Delivered-To" => "dominique.fournier@grenoble.cnrs.fr\n"],
|
|
["Received" => "from [192.168.1.154] (82-64-55-197.subs.proxad.net [82.64.55.197])
|
|
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
|
|
(No client certificate requested)
|
|
by mailgw-out1.grenoble.cnrs.fr (Postfix) with ESMTPSA id 458EDBFCE4
|
|
for <dominique@fournier38.fr>; Sun, 8 Dec 2019 18:08:06 +0100 (CET)\n"],
|
|
["From" => "Dominique Fournier <dominique.fournier@grenoble.cnrs.fr>\n"],
|
|
["Subject" => "Analyse de texte\n"],
|
|
["To" => "Dominique Fournier / Fournier38 <dominique@fournier38.fr>\n"],
|
|
["Message-ID" => "<81d7982f-7fee-96b4-078f-a6365234356f@grenoble.cnrs.fr>\n"],
|
|
["Date" => "Sun, 8 Dec 2019 18:08:06 +0100\n"],
|
|
["User-Agent" => "Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
|
|
Thunderbird/68.2.2\n"],
|
|
["MIME-Version" => "1.0\n"],
|
|
["Content-Type" => "text/plain; charset=utf-8; format=flowed\n"],
|
|
["Content-Language" => "en-US\n"],
|
|
["Content-Transfer-Encoding" => "7bit\n"],
|
|
["Authentication-Results" => "mail-postfix-mx.fournier38.fr;
|
|
dkim=none;
|
|
dmarc=none;
|
|
spf=pass (mail-postfix-mx.fournier38.fr: domain of dominique.fournier@grenoble.cnrs.fr designates 147.173.1.68 as permitted sender) smtp.mailfrom=dominique.fournier@grenoble.cnrs.fr\n"],
|
|
["X-Spamd-Bar" => "--------------------------------------------------------------------------------------------------\n"],
|
|
|
|
|
|
));
|
|
}
|
|
}
|