diff --git a/tests/Actions/Mail/Index.php b/tests/Actions/Mail/Index.php index 760a36b94..0674d611f 100644 --- a/tests/Actions/Mail/Index.php +++ b/tests/Actions/Mail/Index.php @@ -1,614 +1,614 @@ initOutput(rcmail_action::MODE_HTTP, 'mail', ''); $this->assertInstanceOf('rcmail_action', $action); $this->assertTrue($action->checks()); $_GET = ['_uid' => 10]; // Set expected storage function calls/results rcmail::get_instance()->storage ->registerFunction('set_options') ->registerFunction('get_pagesize', 10) ->registerFunction('set_charset') ->registerFunction('is_connected', true) ->registerFunction('set_folder') ->registerFunction('get_folder', 'INBOX') ->registerFunction('get_folder', 'INBOX') ->registerFunction('get_threading', false) ->registerFunction('get_pagesize', 10) ->registerFunction('get_capability', false) ->registerFunction('get_capability', false) ->registerFunction('set_folder') ->registerFunction('set_page') ->registerFunction('set_threading'); $action->run(); $this->assertSame([], $output->headers); $this->assertNull($output->getOutput()); $this->assertSame('Inbox', $output->getProperty('pagetitle')); $this->assertSame('INBOX', $output->get_env('mailbox')); $this->assertSame(10, $output->get_env('pagesize')); $this->assertSame('/', $output->get_env('delimiter')); $this->assertSame('widescreen', $output->get_env('layout')); $this->assertSame('Drafts', $output->get_env('drafts_mailbox')); $this->assertSame('Trash', $output->get_env('trash_mailbox')); $this->assertSame('Junk', $output->get_env('junk_mailbox')); $this->assertSame(10, $output->get_env('list_uid')); } /** * Test run() method in AJAX mode */ function test_run_ajax() { $action = new rcmail_action_mail_index; $output = $this->initOutput(rcmail_action::MODE_AJAX, 'mail', 'list'); $this->assertTrue($action->checks()); // Set expected storage function calls/results rcmail::get_instance()->storage ->registerFunction('set_options') ->registerFunction('get_pagesize') ->registerFunction('set_charset') ->registerFunction('is_connected', true) ->registerFunction('set_folder') ->registerFunction('get_folder', 'INBOX') ->registerFunction('get_threading', false) ->registerFunction('get_pagesize') ->registerFunction('get_capability', false) ->registerFunction('get_capability', false) ->registerFunction('set_folder') ->registerFunction('set_page') ->registerFunction('set_threading'); $action->run(); $this->assertSame([], $output->headers); $this->assertNull($output->getOutput()); $this->assertSame('', $output->getProperty('pagetitle')); $this->assertSame('INBOX', $output->get_env('mailbox')); $this->assertSame(10, $output->get_env('pagesize')); $this->assertSame(1, $output->get_env('current_page')); $this->assertSame('/', $output->get_env('delimiter')); $this->assertSame('widescreen', $output->get_env('layout')); $this->assertSame('Drafts', $output->get_env('drafts_mailbox')); $this->assertSame('Trash', $output->get_env('trash_mailbox')); $this->assertSame('Junk', $output->get_env('junk_mailbox')); } /** * Test message_list_smart_column_name() method */ function test_message_list_smart_column_name() { $action = new rcmail_action_mail_index; $output = $this->initOutput(rcmail_action::MODE_AJAX, 'mail', 'list'); $output->set_env('mailbox', 'INBOX'); $this->assertSame('from', $action->message_list_smart_column_name()); $output->set_env('mailbox', 'Drafts'); $this->assertSame('to', $action->message_list_smart_column_name()); $output->set_env('mailbox', 'Drafts/Subfolder'); $this->assertSame('to', $action->message_list_smart_column_name()); $output->set_env('mailbox', 'Sent'); $this->assertSame('to', $action->message_list_smart_column_name()); $output->set_env('mailbox', 'Sent/Subfolder'); $this->assertSame('to', $action->message_list_smart_column_name()); } /** * Test message_list() method */ function test_message_list() { $action = new rcmail_action_mail_index; $output = $this->initOutput(rcmail_action::MODE_HTTP, 'mail', 'list'); rcmail::get_instance()->storage->registerFunction('get_folder', 'INBOX'); $result = $action->message_list([]); $this->assertRegExp('/^$/', $result); $listcols = ['threads', 'subject', 'status', 'fromto', 'date', 'size', 'flag', 'attachment']; $this->assertSame($listcols, $output->get_env('listcols')); } /** * Test js_message_list() method */ function test_js_message_list() { $action = new rcmail_action_mail_index; $output = $this->initOutput(rcmail_action::MODE_AJAX, 'mail', 'list'); rcmail::get_instance()->storage ->registerFunction('get_search_set', null) ->registerFunction('get_threading', true) ->registerFunction('get_folder', 'INBOX') ->registerFunction('get_folder', 'INBOX'); $action->js_message_list([]); $this->assertSame(false, $output->get_env('multifolder_listing')); $commands = $output->getProperty('commands'); $this->assertCount(1, $commands); $this->assertSame('set_message_coltypes', $commands[0][0]); } /** * Test options_menu_link() method */ function test_options_menu_link() { $action = new rcmail_action_mail_index; $output = $this->initOutput(rcmail_action::MODE_HTTP, 'mail', ''); $link = $action->options_menu_link(['icon' => 'ico.png']); $expected = 'List options...'; $this->assertSame($expected, $link); } /** * Test messagecount_display() method */ function test_messagecount_display() { $this->markTestIncomplete(); } /** * Test get_messagecount_text() method */ function test_get_messagecount_text() { $this->markTestIncomplete(); } /** * Test send_unread_count() method */ function test_send_unread_count() { $this->markTestIncomplete(); } /** * Test check_safe() method */ function test_check_safe() { $this->markTestIncomplete(); } /** * Test part_image_type() method */ function test_part_image_type() { $this->markTestIncomplete(); } /** * Test address_string() method */ function test_address_string() { $action = new rcmail_action_mail_index; $this->assertSame(null, $action->address_string('')); $result = $action->address_string('test@domain.com'); $expected = 'test@domain.com'; $this->assertSame($expected, $result); $result = $action->address_string('test@domain.com', null, true, true); $expected = '' . 'test@domain.com'; $this->assertSame($expected, $result); setProperty($action, 'PRINT_MODE', true); $result = $action->address_string('test@domain.com'); $expected = '<test@domain.com>'; $this->assertSame($expected, $result); } /** * Test wrap_and_quote() method */ function test_wrap_and_quote() { $action = new rcmail_action_mail_index; $this->assertSame('> ', $action->wrap_and_quote('')); $this->assertSame('', $action->wrap_and_quote('', 72, false)); $result = $action->wrap_and_quote("test1\ntest2"); $expected = "> test1\n> test2"; $this->assertSame($expected, $result); $result = $action->wrap_and_quote("> test1\n> test2"); $expected = ">> test1\n>> test2"; $this->assertSame($expected, $result); } /** * Test attachment_name() method */ function test_attachment_name() { $action = new rcmail_action_mail_index; $part = new rcube_message_part(); $part->mime_id = 1; $part->mimetype = 'text/html'; $this->assertSame('HTML Message', $action->attachment_name($part)); $part->mimetype = 'application/pdf'; $this->assertSame('Part 1.pdf', $action->attachment_name($part)); $part->filename = 'test.pdf'; $this->assertSame('test.pdf', $action->attachment_name($part)); } /** * Test search_filter() method */ function test_search_filter() { $this->markTestIncomplete(); } /** * Test search_interval() method */ function test_search_interval() { $this->markTestIncomplete(); } /** * Test message_error() method */ function test_message_error() { $this->markTestIncomplete(); } /** * Test message_import_form() method */ function test_message_import_form() { $this->markTestIncomplete(); } /** * Helper method to create a HTML message part object */ protected function get_html_part($body = null) { $part = new rcube_message_part; $part->ctype_primary = 'text'; $part->ctype_secondary = 'html'; $part->body = $body ? file_get_contents(TESTS_DIR . $body) : null; $part->replaces = []; return $part; } /** * Class constructor */ function test_class() { $object = new rcmail_action_mail_index; $this->assertInstanceOf('rcmail_action', $object); } /** * Test sanitization of a "normal" html message */ function test_html() { $this->initOutput(rcmail_action::MODE_HTTP, 'mail', ''); $part = $this->get_html_part('src/htmlbody.txt'); $part->replaces = ['ex1.jpg' => 'part_1.2.jpg', 'ex2.jpg' => 'part_1.2.jpg']; $params = ['container_id' => 'foo', 'safe' => false]; // render HTML in normal mode $html = \rcmail_action_mail_index::print_body($part->body, $part, $params); - $this->assertMatchesRegularExpression('/src="'.$part->replaces['ex1.jpg'].'"/', $html, "Replace reference to inline image"); - $this->assertMatchesRegularExpression('#background="program/resources/blocked.gif"#', $html, "Replace external background image"); - $this->assertDoesNotMatchRegularExpression('/ex3.jpg/', $html, "No references to external images"); - $this->assertDoesNotMatchRegularExpression('/]+>/', $html, "No meta tags allowed"); - $this->assertDoesNotMatchRegularExpression('/]+>/', $html, "No form tags allowed"); - $this->assertMatchesRegularExpression('/Subscription form/', $html, "Include contents"); - $this->assertMatchesRegularExpression('//', $html, "No external links allowed"); - $this->assertMatchesRegularExpression('/]+ target="_blank"/', $html, "Set target to _blank"); + $this->assertRegExp('/src="'.$part->replaces['ex1.jpg'].'"/', $html, "Replace reference to inline image"); + $this->assertRegExp('#background="program/resources/blocked.gif"#', $html, "Replace external background image"); + $this->assertNotRegExp('/ex3.jpg/', $html, "No references to external images"); + $this->assertNotRegExp('/]+>/', $html, "No meta tags allowed"); + $this->assertNotRegExp('/]+>/', $html, "No form tags allowed"); + $this->assertRegExp('/Subscription form/', $html, "Include contents"); + $this->assertRegExp('//', $html, "No external links allowed"); + $this->assertRegExp('/]+ target="_blank"/', $html, "Set target to _blank"); // $this->assertTrue($GLOBALS['REMOTE_OBJECTS'], "Remote object detected"); // render HTML in safe mode $params['safe'] = true; $html = \rcmail_action_mail_index::print_body($part->body, $part, $params); $this->assertRegExp('/