mirror of
				https://bitbucket.org/jsuto/piler.git
				synced 2025-10-31 14:32:27 +01:00 
			
		
		
		
	gui: added unit tests for Piler_Mime_Decoder class
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
		
							
								
								
									
										32
									
								
								tests/EmailTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								tests/EmailTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| <?php | ||||
|  | ||||
| use PHPUnit\Framework\TestCase; | ||||
|  | ||||
| include_once("webui/system/model.php"); | ||||
| include_once("webui/model/search/search.php"); | ||||
|  | ||||
|  | ||||
| final class SearchSearchTest extends TestCase { | ||||
|  | ||||
|    public function providerTestFixEmailAddressForSphinx() { | ||||
|       return [ | ||||
|          ['aaa@aaa.fu', 'aaaXaaaXfu'], | ||||
|          ['list-507327664@mail.aaa.fu', 'listX507327664XmailXaaaXfu'], | ||||
|          ['aaa+bbb@aaa.fu', 'aaaXbbbXaaaXfu'], | ||||
|          ['ahahah_aiai@aaa.fu', 'ahahahXaiaiXaaaXfu'], | ||||
|          ['aaa|@bbb@ccc.fu', 'aaa|bbbXcccXfu'] | ||||
|       ]; | ||||
|    } | ||||
|  | ||||
|  | ||||
|    /** | ||||
|     * @dataProvider providerTestFixEmailAddressForSphinx | ||||
|     */ | ||||
|  | ||||
|    public function test_get_boundary($input, $expected_result) { | ||||
|       $result = ModelSearchSearch::fix_email_address_for_sphinx($input); | ||||
|       $this->assertEquals($result, $expected_result); | ||||
|    } | ||||
|  | ||||
|  | ||||
| } | ||||
							
								
								
									
										28
									
								
								tests/FormatTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								tests/FormatTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| <?php | ||||
|  | ||||
| use PHPUnit\Framework\TestCase; | ||||
|  | ||||
| include_once("webui/system/model.php"); | ||||
| include_once("webui/model/health/health.php"); | ||||
|  | ||||
| final class FormatTest extends TestCase | ||||
| { | ||||
|  | ||||
|    public function providerTestTimeFormatValues(){ | ||||
|       return [ | ||||
|          ['0', '0.00 ms'], | ||||
|          ['15', '15.00 sec'], | ||||
|          ['0.87', '870.00 ms'] | ||||
|       ]; | ||||
|    } | ||||
|  | ||||
|    /** | ||||
|     * @dataProvider providerTestTimeFormatValues | ||||
|     */ | ||||
|  | ||||
|    public function test_format_time_1($timeval, $expected_result) { | ||||
|       $result = ModelHealthHealth::format_time($timeval); | ||||
|       $this->assertEquals($result, $expected_result); | ||||
|    } | ||||
|  | ||||
| } | ||||
							
								
								
									
										35
									
								
								tests/MiscTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								tests/MiscTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| <?php | ||||
|  | ||||
| use PHPUnit\Framework\TestCase; | ||||
|  | ||||
| define('DIR_SYSTEM', dirname(dirname(__FILE__)) . '/webui/system/'); | ||||
|  | ||||
| include_once("webui/system/model.php"); | ||||
| include_once("webui/model/search/message.php"); | ||||
|  | ||||
| final class SearchMessageTest extends TestCase { | ||||
|  | ||||
|    public function providerTestNiceSizeValues() { | ||||
|       return [ | ||||
|          ['0', '1k'], | ||||
|          ['1000', '1k'], | ||||
|          ['2000', '2k'], | ||||
|          ['4300', '4k'], | ||||
|          ['4700', '5k'], | ||||
|          ['3000000', '3.0M'], | ||||
|          ['4240000', '4.2M'], | ||||
|          ['6810000', '6.8M'] | ||||
|       ];  | ||||
|    } | ||||
|  | ||||
|    /** | ||||
|     * @dataProvider providerTestNiceSizeValues | ||||
|     */ | ||||
|  | ||||
|    public function test_nice_size($input, $expected_result) { | ||||
|       $result = ModelSearchMessage::NiceSize($input); | ||||
|       $this->assertEquals($result, $expected_result); | ||||
|    } | ||||
|  | ||||
|  | ||||
| } | ||||
							
								
								
									
										39
									
								
								tests/ParseMessageTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								tests/ParseMessageTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| <?php | ||||
|  | ||||
| use PHPUnit\Framework\TestCase; | ||||
|  | ||||
| require_once dirname(dirname(__FILE__)) . '/webui/system/helper/mime.php'; | ||||
|  | ||||
|  | ||||
| final class MailParserTest extends TestCase { | ||||
|  | ||||
|    public function providerTestParseMessage() { | ||||
|       return [ | ||||
|          ["1.eml", 1, ["Liebe Gueste,\n\ndie Einarbeitung der Rechen- und Summenfunktionen ins RK-Formular"]], | ||||
|          ["2.eml", 1, ["Hallo!\nDie seltsamen Zeilenumbr=C3=BCche treten tats=C3=A4chlich auf."]], | ||||
|          ["3.eml", 1, ["\n\nCan we discuss? Send Reply For more information, THANKS."]], | ||||
|          ["4.eml", 2, ["=0D=0A=0D=0A=0D=0A=0D=0A", "<HTML><HEAD>=0D=0A<META http-equiv=3D\"Content-Type\" content=3D\"te="]], | ||||
|          ["5.eml", 2, ["\nHi ,\n\nIf so, stop by and test out our FREE phishing simulator! Find out how", "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1=2E0 Transitional//EN\" \"http://ww=\nw=2Ew3=2Eorg/TR/xhtml1/DTD/xhtml1-transitional=2Edtd\"><html xmlns=3D\"http:/="]], | ||||
|          ["6.eml", 2, ["RGVhciBTaXJzLA0KDQpHbGFkIHRvIGhlYXIgdGhhdCB5b3UncmUgb24gdGhlIGZpbHRyYXRpb24g", "<html><head><meta http-equiv=3D\"content-type\" content=3D\"text/html; charse="]], | ||||
|          ["7.eml", 2, ["Mai ajánlat: \n    \n      Exkluzív!", "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"]], | ||||
|          ["8.eml", 2, ["Hello,\n\nYou have received a newsletter from Chemol Travel.", "<html xmlns=3D\"http://www.w3.org/1999/xhtml\" xmlns:v=3D\"urn:schemas-micro=\nsoft-com:vml\" xmlns:o=3D\"urn:schemas-microsoft-com:office:office\">"]], | ||||
|       ]; | ||||
|  | ||||
|    }    | ||||
|  | ||||
|  | ||||
|    /** | ||||
|     * @dataProvider providerTestParseMessage | ||||
|     */ | ||||
|    public function test_parse_message($input, $expected_part_count, $expected_body) { | ||||
|       $message = file_get_contents(dirname(dirname(__FILE__)) . "/test_files/" . $input); | ||||
|       Piler_Mime_Decode::ParseMessage($message, $parts); | ||||
|  | ||||
|       $this->assertEquals(count($parts), $expected_part_count); | ||||
|  | ||||
|       for($i=0; $i<count($parts); $i++) { | ||||
|          $this->assertEquals($expected_body[$i], substr($parts[$i]['body'], 0, strlen($expected_body[$i]))); | ||||
|       } | ||||
|    } | ||||
|  | ||||
| } | ||||
							
								
								
									
										76
									
								
								tests/SplitMessageTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								tests/SplitMessageTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,76 @@ | ||||
| <?php | ||||
|  | ||||
| use PHPUnit\Framework\TestCase; | ||||
|  | ||||
| require_once dirname(dirname(__FILE__)) . '/webui/system/helper/mime.php'; | ||||
|  | ||||
|  | ||||
| final class SplitMessageTest extends TestCase { | ||||
|  | ||||
|    public function providerTestSplitMessage() { | ||||
|       return [ | ||||
|          ["From: aaa\r\nTo:bbb\r\nSubject: test\r\n\r\nThis is a test", | ||||
|           array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', 'subject' => 'test', 'content-type' => array('type' => 'text/plain')), | ||||
|           "This is a test"], | ||||
|  | ||||
|          ["From: aaa\r\nTo:bbb\r\nCC ccc\r\nSubject: test\r\n\r\nThis is a test", | ||||
|           array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', 'subject' => 'test', 'content-type' => array('type' => 'text/plain')), | ||||
|           "This is a test"], | ||||
|  | ||||
|          ["From: aaa\nTo:bbb\nSubject: test\n\nThis is a test", | ||||
|           array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', 'subject' => 'test', 'content-type' => array('type' => 'text/plain')), | ||||
|           "This is a test"], | ||||
|  | ||||
|          ["From: aaa\r\nTo:bbb\r\nSubject: test\r\n\r\n\r\n\r\nThis is a test\nAaa\n", | ||||
|           array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', 'subject' => 'test', 'content-type' => array('type' => 'text/plain')), | ||||
|           "\n\nThis is a test\nAaa\n"], | ||||
|  | ||||
|          ["From: aaa\r\nTo:bbb\r\nSubject: test\r\nContent-type: text/html\r\n\r\n\r\nThis is a test\nAaa\n", | ||||
|           array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', 'subject' => 'test', 'content-type' => array('type' => 'text/html')), | ||||
|           "\nThis is a test\nAaa\n"], | ||||
|  | ||||
|          ["From: aaa\nTo:bbb\nSubject: test\nContent-Type: text/plain\n\nThis is a test", | ||||
|           array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', 'subject' => 'test', 'content-type' => array('type' => 'text/plain')), | ||||
|           "This is a test"], | ||||
|  | ||||
|          ["From: aaa\nTo:bbb\nSubject: test\nDate: Sun, 17 Apr 2016 22:40:03 +0800\nDKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=chemoltravel.hu; s=ml;\n\tt=1471888357; bh=A/l/HLQe3HM4Xc4jFxAmhaWVCMU=;\n\th=Date:To:From:Subject:Sender:From:To:Subject:Date;\n\tb=JlEqXiAKBOoT/YyXKTMsXnEphh2J6sXxgNmbKbGybjo3cU1rgQEL0m1h26gl5AaBP\nContent-Type: text/plain\n\nThis is a test", | ||||
|           array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'subject' => 'test', 'date' => 'Sun, 17 Apr 2016 22:40:03 +0800', 'dkim-signature' => 'v=1; a=rsa-sha1; c=relaxed/relaxed; d=chemoltravel.hu; s=ml;  t=1471888357; bh=A/l/HLQe3HM4Xc4jFxAmhaWVCMU=;  h=Date:To:From:Subject:Sender:From:To:Subject:Date;  b=JlEqXiAKBOoT/YyXKTMsXnEphh2J6sXxgNmbKbGybjo3cU1rgQEL0m1h26gl5AaBP', 'content-type' => array('type' => 'text/plain')), | ||||
|           "This is a test"], | ||||
|  | ||||
|          ["From: aaa\nTo:bbb\nSubject: test\nContent-Type: text/PLAIN\n\nThis is a test", | ||||
|           array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', 'subject' => 'test', 'content-type' => array('type' => 'text/plain')), | ||||
|           "This is a test"], | ||||
|  | ||||
|          ["From: aaa\nTo:bbb\nSubject: test\nContent-Type: text/plain; charset=\"ISO-8859-1\"\n\nThis is a test", | ||||
|           array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', 'subject' => 'test', 'content-type' => array('type' => 'text/plain', 'charset' => 'ISO-8859-1')), | ||||
|           "This is a test"], | ||||
|  | ||||
|          ["From: aaa\nTo:bbb\nSubject: test\nMIME-Version: 1.0\nContent-Type: multipart/alternative; boundary=\"_=_SWIFT_v4_1460476188_145aa333fc0127705a7e904aab6d1957_=_\"\n\nThis is a test", | ||||
|           array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', 'subject' => 'test', 'mime-version' => '1.0', 'content-type' => array('type' => 'multipart/alternative', 'boundary' => '_=_SWIFT_v4_1460476188_145aa333fc0127705a7e904aab6d1957_=_')), | ||||
|           "This is a test"], | ||||
|  | ||||
|          ["From: aaa\nTo:bbb\nSubject: test\nMIME-Version: 1.0\nContent-Type: multipart/alternative;\n boundary=\"_=_SWIFT_v4_1460476188_145aa333fc0127705a7e904aab6d1957_=_\"\n\nThis is a test", | ||||
|           array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', 'subject' => 'test', 'mime-version' => '1.0', 'content-type' => array('type' => 'multipart/alternative', 'boundary' => '_=_SWIFT_v4_1460476188_145aa333fc0127705a7e904aab6d1957_=_')), | ||||
|           "This is a test"], | ||||
|  | ||||
|          ["From: aaa\nTo:bbb\nSubject: test\nMIME-Version: 1.0\nContent-Type: multipart/related;\n\ttype=\"multipart/alternative\";\n\tboundary=\"----=_NextPart_000_0006_01D195BC.69E26510\"\n\nThis is a test", | ||||
|           array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', 'subject' => 'test', 'mime-version' => '1.0', 'content-type' => array('type' => 'multipart/alternative', 'boundary' => '----=_NextPart_000_0006_01D195BC.69E26510')), | ||||
|           "This is a test"], | ||||
|  | ||||
|  | ||||
|       ];   | ||||
|    }    | ||||
|  | ||||
|  | ||||
|    /** | ||||
|     * @dataProvider providerTestSplitMessage | ||||
|     */ | ||||
|    public function test_split_message($input, $expected_headers, $expected_body) { | ||||
|       Piler_Mime_Decode::splitMessage($input, $headers, $body); | ||||
|  | ||||
|       $this->assertEquals($headers, $expected_headers); | ||||
|       $this->assertEquals($body, $expected_body); | ||||
|    } | ||||
|  | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user