diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 468c339..80914fe 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -18,5 +18,5 @@ - mysql -u piler -ppiler123 piler1 < /usr/share/piler/db-mysql.sql - cd unit_tests - ./run.sh - - cd .. + - cd ../webui - phpunit diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index a940f77..0000000 --- a/phpunit.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - ./unit_tests/php - - - - - - - diff --git a/unit_tests/php/EmailTest.php b/unit_tests/php/EmailTest.php deleted file mode 100644 index 1861c43..0000000 --- a/unit_tests/php/EmailTest.php +++ /dev/null @@ -1,35 +0,0 @@ -assertEquals($result, $expected_result); - } - - -} diff --git a/unit_tests/php/FormatTest.php b/unit_tests/php/FormatTest.php deleted file mode 100644 index 9b2e85f..0000000 --- a/unit_tests/php/FormatTest.php +++ /dev/null @@ -1,53 +0,0 @@ -assertEquals($result, $expected_result); - } - - - public function providerTestConvertDateStringToYmdByTemplateValues() { - return [ - ['2021.05.01', 'y.m.d', ['0','0','0']], - ['2021.05.01', 'Y.m', ['0','0','0']], - ['2021.05.01', 'Y.m.d.e', ['0','0','0']], - ['2021.05.01', 'Y.m.d', ['2021','05','01']], - ['2021.05.01', 'Y.m.d.', ['0','0','0']], - ['2021.05.01', 'Y-m-d', ['2021','05','01']], - ['12/01/2008', 'm/d/Y', ['2008','12','01']], - ['12-01-2008', 'm-d-Y', ['2008','12','01']], - ]; - } - - /** - * @dataProvider providerTestConvertDateStringToYmdByTemplateValues - */ - - public function test_convert_date_string_to_ymd_by_template($date, $date_template, $expected_result) { - $result = convert_date_string_to_ymd_by_template($date, $date_template); - $this->assertEquals($result, $expected_result); - } - - -} diff --git a/unit_tests/php/ParseMessageTest.php b/unit_tests/php/ParseMessageTest.php deleted file mode 100644 index fbf67cd..0000000 --- a/unit_tests/php/ParseMessageTest.php +++ /dev/null @@ -1,41 +0,0 @@ -=0D=0A"]], - ["8.eml", 2, ["Hello,\n\nYou have received a newsletter from Chemol Travel.", ""]], - ]; - - } - - - /** - * @dataProvider providerTestParseMessage - */ - public function test_parse_message($input, $expected_part_count, $expected_body) { - $message = file_get_contents(TEST_FILES_DIR . $input); - Piler_Mime_Decode::ParseMessage($message, $parts); - - $this->assertEquals(count($parts), $expected_part_count); - - for($i=0; $iassertEquals($expected_body[$i], substr($parts[$i]['body'], 0, strlen($expected_body[$i]))); - } - } - -} diff --git a/unit_tests/php/SplitMessageTest.php b/unit_tests/php/SplitMessageTest.php deleted file mode 100644 index 8947de6..0000000 --- a/unit_tests/php/SplitMessageTest.php +++ /dev/null @@ -1,81 +0,0 @@ - '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\n" . THIS_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\n" . THIS_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\n" . THIS_IS_A_TEST . "\nAaa\n", - array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', SUBJECT => 'test', CONTENT_TYPE => array('type' => TEXT_PLAIN)), - "\n\n" . THIS_IS_A_TEST . "\nAaa\n"], - - ["From: aaa\r\nTo:bbb\r\nSubject: test\r\nContent-type: text/html\r\n\r\n\r\n" . THIS_IS_A_TEST . "\nAaa\n", - array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', SUBJECT => 'test', CONTENT_TYPE => array('type' => 'text/html')), - "\n" . THIS_IS_A_TEST . "\nAaa\n"], - - ["From: aaa\nTo:bbb\nSubject: test\nContent-Type: text/plain\n\n" . THIS_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\n" . THIS_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\n" . THIS_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\n" . THIS_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\n" . THIS_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\n" . THIS_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\n" . THIS_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); - } - - -} diff --git a/webui/phpunit.xml b/webui/phpunit.xml new file mode 100644 index 0000000..18034cd --- /dev/null +++ b/webui/phpunit.xml @@ -0,0 +1,12 @@ + + + + + ./tests + + + + + + + diff --git a/webui/tests/EmailTest.php b/webui/tests/EmailTest.php new file mode 100644 index 0000000..1861c43 --- /dev/null +++ b/webui/tests/EmailTest.php @@ -0,0 +1,35 @@ +assertEquals($result, $expected_result); + } + + +} diff --git a/webui/tests/FormatTest.php b/webui/tests/FormatTest.php new file mode 100644 index 0000000..c971461 --- /dev/null +++ b/webui/tests/FormatTest.php @@ -0,0 +1,53 @@ +assertEquals($result, $expected_result); + } + + + public function providerTestConvertDateStringToYmdByTemplateValues() { + return [ + ['2021.05.01', 'y.m.d', ['0','0','0']], + ['2021.05.01', 'Y.m', ['0','0','0']], + ['2021.05.01', 'Y.m.d.e', ['0','0','0']], + ['2021.05.01', 'Y.m.d', ['2021','05','01']], + ['2021.05.01', 'Y.m.d.', ['0','0','0']], + ['2021.05.01', 'Y-m-d', ['2021','05','01']], + ['12/01/2008', 'm/d/Y', ['2008','12','01']], + ['12-01-2008', 'm-d-Y', ['2008','12','01']], + ]; + } + + /** + * @dataProvider providerTestConvertDateStringToYmdByTemplateValues + */ + + public function test_convert_date_string_to_ymd_by_template($date, $date_template, $expected_result) { + $result = convert_date_string_to_ymd_by_template($date, $date_template); + $this->assertEquals($result, $expected_result); + } + + +} diff --git a/webui/tests/ParseMessageTest.php b/webui/tests/ParseMessageTest.php new file mode 100644 index 0000000..fbf67cd --- /dev/null +++ b/webui/tests/ParseMessageTest.php @@ -0,0 +1,41 @@ +=0D=0A"]], + ["8.eml", 2, ["Hello,\n\nYou have received a newsletter from Chemol Travel.", ""]], + ]; + + } + + + /** + * @dataProvider providerTestParseMessage + */ + public function test_parse_message($input, $expected_part_count, $expected_body) { + $message = file_get_contents(TEST_FILES_DIR . $input); + Piler_Mime_Decode::ParseMessage($message, $parts); + + $this->assertEquals(count($parts), $expected_part_count); + + for($i=0; $iassertEquals($expected_body[$i], substr($parts[$i]['body'], 0, strlen($expected_body[$i]))); + } + } + +} diff --git a/webui/tests/SplitMessageTest.php b/webui/tests/SplitMessageTest.php new file mode 100644 index 0000000..8947de6 --- /dev/null +++ b/webui/tests/SplitMessageTest.php @@ -0,0 +1,81 @@ + '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\n" . THIS_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\n" . THIS_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\n" . THIS_IS_A_TEST . "\nAaa\n", + array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', SUBJECT => 'test', CONTENT_TYPE => array('type' => TEXT_PLAIN)), + "\n\n" . THIS_IS_A_TEST . "\nAaa\n"], + + ["From: aaa\r\nTo:bbb\r\nSubject: test\r\nContent-type: text/html\r\n\r\n\r\n" . THIS_IS_A_TEST . "\nAaa\n", + array('from' => 'aaa', 'to' => 'bbb', 'cc' => '', 'date' => '', SUBJECT => 'test', CONTENT_TYPE => array('type' => 'text/html')), + "\n" . THIS_IS_A_TEST . "\nAaa\n"], + + ["From: aaa\nTo:bbb\nSubject: test\nContent-Type: text/plain\n\n" . THIS_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\n" . THIS_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\n" . THIS_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\n" . THIS_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\n" . THIS_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\n" . THIS_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\n" . THIS_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); + } + + +}