From 63d4b1217216f3d04894090026ed3f01aba9b385 Mon Sep 17 00:00:00 2001 From: thomascube Date: Mon, 2 Mar 2009 14:46:12 +0000 Subject: Create some basic unit tests based in simpletest.org --- tests/mailfunc.php | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 tests/mailfunc.php (limited to 'tests/mailfunc.php') diff --git a/tests/mailfunc.php b/tests/mailfunc.php new file mode 100644 index 000000000..bf9163b7d --- /dev/null +++ b/tests/mailfunc.php @@ -0,0 +1,110 @@ +UnitTestCase('Mail body rendering tests'); + + // simulate environment to successfully include func.inc + $GLOBALS['RCMAIL'] = $RCMAIL = rcmail::get_instance(); + $GLOBALS['OUTPUT'] = $OUTPUT = $RCMAIL->load_gui(); + $RCMAIL->action = 'spell'; + $IMAP = $RCMAIL->imap; + + require_once 'steps/mail/func.inc'; + } + + /** + * Helper method to create a HTML message part object + */ + function get_html_part($body) + { + $part = new rcube_message_part; + $part->ctype_primary = 'text'; + $part->ctype_secondary = 'html'; + $part->body = file_get_contents(TESTS_DIR . $body); + $part->replaces = array(); + return $part; + } + + /** + * Test sanitization of a "normal" html message + */ + function test_html() + { + $part = $this->get_html_part('src/htmlbody.txt'); + $part->replaces = array('ex1.jpg' => 'part_1.2.jpg', 'ex2.jpg' => 'part_1.2.jpg'); + + // render HTML in normal mode + $html = rcmail_print_body($part, array('safe' => false)); + + $this->assertPattern('/src="'.$part->replaces['ex1.jpg'].'"/', $html, "Replace reference to inline image"); + $this->assertPattern('#background="./program/blocked.gif"#', $html, "Replace external background image"); + $this->assertNoPattern('/ex3.jpg/', $html, "No references to external images"); + $this->assertNoPattern('/]+>/', $html, "No meta tags allowed"); + $this->assertNoPattern('/