summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCyrill von Wattenwyl <cvw@adfinis.com>2014-09-02 11:20:52 +0200
committerCyrill von Wattenwyl <cvw@adfinis.com>2014-09-02 11:20:52 +0200
commit11a40dd1fef6c5b78b054617caba4325f95ee386 (patch)
treede2e1d7efd6423ef4d1256dd5c90a972ad172719 /tests
parent187fd666aa2f32dedfe544d69b7cb213698197f2 (diff)
parentba084313bfc9c7a5a83e0611fe4376543cc1653d (diff)
Merge branch 'master' of https://github.com/roundcube/roundcubemail
Conflicts: plugins/password/config.inc.php.dist
Diffstat (limited to 'tests')
-rw-r--r--tests/Framework/Csv2vcard.php18
-rw-r--r--tests/Framework/Html.php9
-rw-r--r--tests/Framework/Html2text.php5
-rw-r--r--tests/Framework/Mime.php3
-rw-r--r--tests/Framework/StringReplacer.php4
-rw-r--r--tests/Framework/Text2Html.php94
-rw-r--r--tests/Framework/Utils.php8
-rw-r--r--tests/Framework/VCard.php35
-rw-r--r--tests/Framework/Washtml.php24
-rw-r--r--tests/MailFunc.php2
-rw-r--r--tests/RcmailFunc.php85
-rw-r--r--tests/phpunit.xml3
-rw-r--r--tests/src/Csv2vcard/gmail.csvbin0 -> 3760 bytes
-rw-r--r--tests/src/Csv2vcard/gmail.vcf25
14 files changed, 304 insertions, 11 deletions
diff --git a/tests/Framework/Csv2vcard.php b/tests/Framework/Csv2vcard.php
index 5d52efc58..4f48dfaa2 100644
--- a/tests/Framework/Csv2vcard.php
+++ b/tests/Framework/Csv2vcard.php
@@ -55,4 +55,22 @@ class Framework_Csv2vcard extends PHPUnit_Framework_TestCase
$vcard = trim(str_replace("\r\n", "\n", $vcard));
$this->assertEquals($vcf_text, $vcard);
}
+
+ function test_import_gmail()
+ {
+ $csv_text = file_get_contents(TESTS_DIR . '/src/Csv2vcard/gmail.csv');
+ $vcf_text = file_get_contents(TESTS_DIR . '/src/Csv2vcard/gmail.vcf');
+
+ $csv = new rcube_csv2vcard;
+ $csv->import($csv_text);
+ $result = $csv->export();
+ $vcard = $result[0]->export(false);
+
+ $this->assertCount(1, $result);
+
+ $vcf_text = trim(str_replace("\r\n", "\n", $vcf_text));
+ $vcard = trim(str_replace("\r\n", "\n", $vcard));
+
+ $this->assertEquals($vcf_text, $vcard);
+ }
}
diff --git a/tests/Framework/Html.php b/tests/Framework/Html.php
index d9466e601..259d73e1a 100644
--- a/tests/Framework/Html.php
+++ b/tests/Framework/Html.php
@@ -54,15 +54,6 @@ class Framework_Html extends PHPUnit_Framework_TestCase
array(
array('data-test' => 'test'), null, ' data-test="test"',
),
- array(
- array('data-test' => 'test'), array('other'), '',
- ),
- array(
- array('data-test' => 'test'), array('data-test'), ' data-test="test"',
- ),
- array(
- array('data-test' => 'test'), array('data-*'), ' data-test="test"',
- ),
);
}
diff --git a/tests/Framework/Html2text.php b/tests/Framework/Html2text.php
index 2c7759f7d..76b1f16cd 100644
--- a/tests/Framework/Html2text.php
+++ b/tests/Framework/Html2text.php
@@ -41,6 +41,11 @@ class rc_html2text extends PHPUnit_Framework_TestCase
'in' => '<b><strong>&#347;</strong></b>',
'out' => 'Ś',
),
+ 6 => array(
+ 'title' => 'Don\'t remove non-printable chars',
+ 'in' => chr(0x002).chr(0x003),
+ 'out' => chr(0x002).chr(0x003),
+ ),
);
}
diff --git a/tests/Framework/Mime.php b/tests/Framework/Mime.php
index d47eba896..43773f1a5 100644
--- a/tests/Framework/Mime.php
+++ b/tests/Framework/Mime.php
@@ -44,6 +44,8 @@ class Framework_Mime extends PHPUnit_Framework_TestCase
23 => '=?UTF-8?B?IlRlc3QsVGVzdCI=?= <test@domain.tld>',
// invalid, but we do our best to parse correctly
24 => '"email@test.com" <>',
+ // valid with redundant quoting (#1490040)
+ 25 => '"user"@"domain.tld"',
);
$results = array(
@@ -73,6 +75,7 @@ class Framework_Mime extends PHPUnit_Framework_TestCase
22 => array(1, 'John Doe @ SomeBusinessName', 'MAILER-DAEMON'),
23 => array(1, 'Test,Test', 'test@domain.tld'),
24 => array(1, '', 'email@test.com'),
+ 25 => array(1, '', 'user@domain.tld'),
);
foreach ($headers as $idx => $header) {
diff --git a/tests/Framework/StringReplacer.php b/tests/Framework/StringReplacer.php
index 0fa7fae34..7d9600a78 100644
--- a/tests/Framework/StringReplacer.php
+++ b/tests/Framework/StringReplacer.php
@@ -42,6 +42,10 @@ class Framework_StringReplacer extends PHPUnit_Framework_TestCase
array('1@1.com www.domain.tld', '<a href="mailto:1@1.com">1@1.com</a> <a href="http://www.domain.tld">www.domain.tld</a>'),
array(' www.domain.tld ', ' <a href="http://www.domain.tld">www.domain.tld</a> '),
array(' www.domain.tld/#!download|856p1|2 ', ' <a href="http://www.domain.tld/#!download|856p1|2">www.domain.tld/#!download|856p1|2</a> '),
+ // #1489898: allow some unicode characters
+ array('https://www.google.com/maps/place/New+York,+État+de+New+York/@40.7056308,-73.9780035,11z/data=!3m1!4b1!4m2!3m1!1s0x89c24fa5d33f083b:0xc80b8f06e177fe62',
+ '<a href="https://www.google.com/maps/place/New+York,+État+de+New+York/@40.7056308,-73.9780035,11z/data=!3m1!4b1!4m2!3m1!1s0x89c24fa5d33f083b:0xc80b8f06e177fe62">https://www.google.com/maps/place/New+York,+État+de+New+York/@40.7056308,-73.9780035,11z/data=!3m1!4b1!4m2!3m1!1s0x89c24fa5d33f083b:0xc80b8f06e177fe62</a>'
+ ),
);
}
diff --git a/tests/Framework/Text2Html.php b/tests/Framework/Text2Html.php
new file mode 100644
index 000000000..8d1325dee
--- /dev/null
+++ b/tests/Framework/Text2Html.php
@@ -0,0 +1,94 @@
+<?php
+
+/**
+ * Test class to test rcube_text2html class
+ *
+ * @package Tests
+ */
+class Framework_Text2Html extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Data for test_text2html()
+ */
+ function data_text2html()
+ {
+ $options = array(
+ 'begin' => '',
+ 'end' => '',
+ 'break' => '<br>',
+ 'links' => false,
+ 'flowed' => false,
+ 'wrap' => false,
+ 'space' => '_', // replace UTF-8 non-breaking space for simpler testing
+ );
+
+ $data[] = array(" aaaa", "_aaaa", $options);
+ $data[] = array("aaaa aaaa", "aaaa_aaaa", $options);
+ $data[] = array("aaaa aaaa", "aaaa__aaaa", $options);
+ $data[] = array("aaaa aaaa", "aaaa___aaaa", $options);
+ $data[] = array("aaaa\taaaa", "aaaa____aaaa", $options);
+ $data[] = array("aaaa\naaaa", "aaaa<br>aaaa", $options);
+ $data[] = array("aaaa\n aaaa", "aaaa<br>_aaaa", $options);
+ $data[] = array("aaaa\n aaaa", "aaaa<br>__aaaa", $options);
+ $data[] = array("aaaa\n aaaa", "aaaa<br>___aaaa", $options);
+ $data[] = array("\taaaa", "____aaaa", $options);
+ $data[] = array("\naaaa", "<br>aaaa", $options);
+ $data[] = array("\n aaaa", "<br>_aaaa", $options);
+ $data[] = array("\n aaaa", "<br>__aaaa", $options);
+ $data[] = array("\n aaaa", "<br>___aaaa", $options);
+ $data[] = array("aaaa\n\nbbbb", "aaaa<br><br>bbbb", $options);
+ $data[] = array(">aaaa \n>aaaa", "<blockquote>aaaa_<br>aaaa</blockquote>", $options);
+ $data[] = array(">aaaa\n>aaaa", "<blockquote>aaaa<br>aaaa</blockquote>", $options);
+ $data[] = array(">aaaa \n>bbbb\ncccc dddd", "<blockquote>aaaa_<br>bbbb</blockquote>cccc_dddd", $options);
+ $data[] = array("aaaa-bbbb/cccc", "aaaa-&#8288;bbbb/&#8288;cccc", $options);
+
+ $options['flowed'] = true;
+
+ $data[] = array(" aaaa", "aaaa", $options);
+ $data[] = array("aaaa aaaa", "aaaa_aaaa", $options);
+ $data[] = array("aaaa aaaa", "aaaa__aaaa", $options);
+ $data[] = array("aaaa aaaa", "aaaa___aaaa", $options);
+ $data[] = array("aaaa\taaaa", "aaaa____aaaa", $options);
+ $data[] = array("aaaa\naaaa", "aaaa<br>aaaa", $options);
+ $data[] = array("aaaa\n aaaa", "aaaa<br>aaaa", $options);
+ $data[] = array("aaaa\n aaaa", "aaaa<br>_aaaa", $options);
+ $data[] = array("aaaa\n aaaa", "aaaa<br>__aaaa", $options);
+ $data[] = array("\taaaa", "____aaaa", $options);
+ $data[] = array("\naaaa", "<br>aaaa", $options);
+ $data[] = array("\n aaaa", "<br>aaaa", $options);
+ $data[] = array("\n aaaa", "<br>_aaaa", $options);
+ $data[] = array("\n aaaa", "<br>__aaaa", $options);
+ $data[] = array("aaaa\n\nbbbb", "aaaa<br><br>bbbb", $options);
+ $data[] = array(">aaaa \n>aaaa", "<blockquote>aaaa aaaa</blockquote>", $options);
+ $data[] = array(">aaaa\n>aaaa", "<blockquote>aaaa<br>aaaa</blockquote>", $options);
+ $data[] = array(">aaaa \n>bbbb\ncccc dddd", "<blockquote>aaaa bbbb</blockquote>cccc_dddd", $options);
+ $data[] = array(chr(0x002).chr(0x003), chr(0x002).chr(0x003), $options);
+
+ $options['flowed'] = false;
+ $options['wrap'] = true;
+
+ $data[] = array(">>aaaa bbbb\n>>\n>>>\n>cccc\n\ndddd eeee",
+ "<blockquote><blockquote>aaaa bbbb<br><br><blockquote><br></blockquote></blockquote>cccc</blockquote><br>dddd eeee", $options);
+ $data[] = array("\n>>aaaa\n\ndddd",
+ "<br><blockquote><blockquote>aaaa</blockquote></blockquote><br>dddd", $options);
+ $data[] = array("aaaa\n>bbbb\n>cccc\n\ndddd\n>>test",
+ "aaaa<blockquote>bbbb<br>cccc</blockquote><br>dddd<blockquote><blockquote>test</blockquote></blockquote>", $options);
+
+ return $data;
+ }
+
+ /**
+ * Test text to html conversion
+ *
+ * @dataProvider data_text2html
+ */
+ function test_text2html($input, $output, $options)
+ {
+ $t2h = new rcube_text2html($input, false, $options);
+
+ $html = $t2h->get_html();
+
+ $this->assertEquals($output, $html);
+ }
+}
diff --git a/tests/Framework/Utils.php b/tests/Framework/Utils.php
index 082aaea3b..560a8bde7 100644
--- a/tests/Framework/Utils.php
+++ b/tests/Framework/Utils.php
@@ -325,8 +325,14 @@ class Framework_Utils extends PHPUnit_Framework_TestCase
function test_normalize_string()
{
$test = array(
- '' => '',
+ '' => '',
'abc def' => 'abc def',
+ 'ÇçäâàåæéêëèïîìÅÉöôòüûùÿøØáíóúñÑÁÂÀãÃÊËÈÍÎÏÓÔõÕÚÛÙýÝ' => 'ccaaaaaeeeeiiiaeooouuuyooaiounnaaaaaeeeiiioooouuuyy',
+ 'ąáâäćçčéęëěíîłľĺńňóôöŕřśšşťţůúűüźžżýĄŚŻŹĆ' => 'aaaaccceeeeiilllnnooorrsssttuuuuzzzyaszzc',
+ 'ß' => 'ss',
+ 'ae' => 'a',
+ 'oe' => 'o',
+ 'ue' => 'u',
);
foreach ($test as $input => $output) {
diff --git a/tests/Framework/VCard.php b/tests/Framework/VCard.php
index 3353b5b13..c23dba844 100644
--- a/tests/Framework/VCard.php
+++ b/tests/Framework/VCard.php
@@ -79,6 +79,25 @@ class Framework_VCard extends PHPUnit_Framework_TestCase
$this->assertEquals("http://domain.tld", $vcard['website:other'][0], "Decode dummy backslash character");
}
+ /**
+ * Some Apple vCard quirks (#1489993)
+ */
+ function test_parse_six()
+ {
+ $vcard = new rcube_vcard("BEGIN:VCARD\n"
+ . "VERSION:3.0\n"
+ . "N:;;;;\n"
+ . "FN:Apple Computer AG\n"
+ . "ITEM1.ADR;type=WORK;type=pref:;;Birgistrasse 4a;Wallisellen-Zürich;;8304;Switzerland\n"
+ . "PHOTO;ENCODING=B:aHR0cDovL3Rlc3QuY29t\n"
+ . "END:VCARD"
+ );
+
+ $result = $vcard->get_assoc();
+
+ $this->assertCount(1, $result['address:work'], "ITEM1.-prefixed entry");
+ }
+
function test_import()
{
$input = file_get_contents($this->_srcpath('apple.vcf'));
@@ -107,6 +126,22 @@ class Framework_VCard extends PHPUnit_Framework_TestCase
// ENCODING=b case (#1488683)
$this->assertEquals("/9j/4AAQSkZJRgABAQA", substr(base64_encode($vcard['photo']), 0, 19), "Photo decoding");
$this->assertEquals("Müller", $vcard['surname'], "Unicode characters");
+
+ $input = str_replace('ENCODING=b:', 'ENCODING=base64;jpeg:', $input);
+
+ $vcards = rcube_vcard::import($input);
+ $vcard = $vcards[0]->get_assoc();
+
+ // ENCODING=base64 case (#1489977)
+ $this->assertEquals("/9j/4AAQSkZJRgABAQA", substr(base64_encode($vcard['photo']), 0, 19), "Photo decoding");
+
+ $input = str_replace('PHOTO;ENCODING=base64;jpeg:', 'PHOTO:data:image/jpeg;base64,', $input);
+
+ $vcards = rcube_vcard::import($input);
+ $vcard = $vcards[0]->get_assoc();
+
+ // vcard4.0 "PHOTO:data:image/jpeg;base64," case (#1489977)
+ $this->assertEquals("/9j/4AAQSkZJRgABAQA", substr(base64_encode($vcard['photo']), 0, 19), "Photo decoding");
}
function test_encodings()
diff --git a/tests/Framework/Washtml.php b/tests/Framework/Washtml.php
index ab1ada05f..f041504d7 100644
--- a/tests/Framework/Washtml.php
+++ b/tests/Framework/Washtml.php
@@ -53,6 +53,16 @@ class Framework_Washtml extends PHPUnit_Framework_TestCase
$washed = $washer->wash($html);
$this->assertEquals('<!-- html ignored --><!-- body ignored --><p>test</p>', $washed, "HTML invalid comments (#1487759)");
+
+ $html = "<p>para1</p><!-- comment --><p>para2</p>";
+ $washed = $washer->wash($html);
+
+ $this->assertEquals('<!-- html ignored --><!-- body ignored --><p>para1</p><!-- node type 8 --><p>para2</p>', $washed, "HTML comments - simple comment");
+
+ $html = "<p>para1</p><!-- <hr> comment --><p>para2</p>";
+ $washed = $washer->wash($html);
+
+ $this->assertEquals('<!-- html ignored --><!-- body ignored --><p>para1</p><!-- node type 8 --><p>para2</p>', $washed, "HTML comments - tags inside (#1489904)");
}
/**
@@ -159,4 +169,18 @@ class Framework_Washtml extends PHPUnit_Framework_TestCase
$this->assertRegExp('|style="font-family: 新細明體; color: red"|', $washed, "Unicode chars in style attribute (#1489697)");
}
+
+ /**
+ * Test style item fixes
+ */
+ function test_style_wash()
+ {
+ $html = "<p style=\"line-height: 1; height: 10\">a</p>";
+
+ $washer = new rcube_washtml;
+ $washed = $washer->wash($html);
+
+ $this->assertRegExp('|line-height: 1;|', $washed, "Untouched line-height (#1489917)");
+ $this->assertRegExp('|; height: 10px|', $washed, "Fixed height units");
+ }
}
diff --git a/tests/MailFunc.php b/tests/MailFunc.php
index ab0074ef2..05f26324e 100644
--- a/tests/MailFunc.php
+++ b/tests/MailFunc.php
@@ -61,7 +61,7 @@ class MailFunc extends PHPUnit_Framework_TestCase
$this->assertRegExp('/<style [^>]+>/', $html2, "Allow styles in safe mode");
$this->assertRegExp('#src="http://evilsite.net/mailings/ex3.jpg"#', $html2, "Allow external images in HTML (safe mode)");
$this->assertRegExp("#url\('?http://evilsite.net/newsletter/image/bg/bg-64.jpg'?\)#", $html2, "Allow external images in CSS (safe mode)");
- $css = '<link rel="stylesheet" .+_u=tmp-[a-z0-9]+\.css.+_action=modcss';
+ $css = '<link rel="stylesheet" .+_action=modcss.+_u=tmp-[a-z0-9]+\.css';
$this->assertRegExp('#'.$css.'#Ui', $html2, "Filter (anonymized) external styleseehts with utils/modcss.inc");
}
diff --git a/tests/RcmailFunc.php b/tests/RcmailFunc.php
new file mode 100644
index 000000000..09b54b22c
--- /dev/null
+++ b/tests/RcmailFunc.php
@@ -0,0 +1,85 @@
+<?php
+
+/**
+ * Test class to test rcmail class
+ *
+ * @package Tests
+ */
+class RcmailFunc extends PHPUnit_Framework_TestCase
+{
+ function setUp()
+ {
+ // set some HTTP env vars
+ $_SERVER['HTTP_HOST'] = 'mail.example.org';
+ $_SERVER['SERVER_PORT'] = '443';
+ $_SERVER['SCRIPT_NAME'] = '/sub/index.php';
+ $_SERVER['HTTPS'] = true;
+
+ rcmail::get_instance()->filename = '';
+ }
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = rcmail::get_instance();
+ $this->assertInstanceOf('rcmail', $object, "Class singleton");
+ }
+
+ /**
+ * Test rcmail::url()
+ */
+ function test_url()
+ {
+ $rcmail = rcmail::get_instance();
+ $this->assertEquals(
+ './?_task=cli&_action=test',
+ $rcmail->url('test'),
+ "Action only"
+ );
+ $this->assertEquals(
+ './?_task=cli&_action=test&_a=AA',
+ $rcmail->url(array('action' => 'test', 'a' => 'AA')),
+ "Unprefixed parameters"
+ );
+ $this->assertEquals(
+ './?_task=cli&_action=test&_b=BB',
+ $rcmail->url(array('_action' => 'test', '_b' => 'BB', '_c' => null)),
+ "Prefixed parameters (skip empty)"
+ );
+ $this->assertEquals(
+ '/sub/?_task=cli&_action=test&_mode=ABS',
+ $rcmail->url(array('_action' => 'test', '_mode' => 'ABS'), true),
+ "Absolute URL"
+ );
+
+ $this->assertEquals(
+ 'https://mail.example.org/sub/?_task=calendar&_action=test&_mode=FQ',
+ $rcmail->url(array('task' => 'calendar', '_action' => 'test', '_mode' => 'FQ'), true, true),
+ "Fully Qualified URL"
+ );
+
+ // with different SCRIPT_NAME values
+ $_SERVER['SCRIPT_NAME'] = 'index.php';
+ $this->assertEquals(
+ '/?_task=cli&_action=test&_mode=ABS',
+ $rcmail->url(array('_action' => 'test', '_mode' => 'ABS'), true),
+ "Absolute URL (root)"
+ );
+ $_SERVER['SCRIPT_NAME'] = '';
+ $this->assertEquals(
+ '/?_task=cli&_action=test&_mode=ABS',
+ $rcmail->url(array('_action' => 'test', '_mode' => 'ABS'), true),
+ "Absolute URL (root)"
+ );
+
+ $_SERVER['HTTPS'] = false;
+ $_SERVER['SERVER_PORT'] = '8080';
+ $this->assertEquals(
+ 'http://mail.example.org:8080/?_task=cli&_action=test&_mode=ABS',
+ $rcmail->url(array('_action' => 'test', '_mode' => 'ABS'), true, true),
+ "Full URL with port"
+ );
+ }
+}
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
index cee3434c1..5c27d0e0d 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -40,11 +40,13 @@
<file>Framework/SpellcheckPspell.php</file>
<file>Framework/Spellchecker.php</file>
<file>Framework/StringReplacer.php</file>
+ <file>Framework/Text2Html.php</file>
<file>Framework/User.php</file>
<file>Framework/Utils.php</file>
<file>Framework/VCard.php</file>
<file>Framework/Washtml.php</file>
<file>MailFunc.php</file>
+ <file>RcmailFunc.php</file>
</testsuite>
<testsuite name="Plugins Tests">
<file>./../plugins/acl/tests/Acl.php</file>
@@ -66,6 +68,7 @@
<file>./../plugins/managesieve/tests/Managesieve.php</file>
<file>./../plugins/managesieve/tests/Parser.php</file>
<file>./../plugins/managesieve/tests/Tokenizer.php</file>
+ <file>./../plugins/managesieve/tests/Vacation.php</file>
<file>./../plugins/markasjunk/tests/Markasjunk.php</file>
<file>./../plugins/new_user_dialog/tests/NewUserDialog.php</file>
<file>./../plugins/new_user_identity/tests/NewUserIdentity.php</file>
diff --git a/tests/src/Csv2vcard/gmail.csv b/tests/src/Csv2vcard/gmail.csv
new file mode 100644
index 000000000..9f67fe9f5
--- /dev/null
+++ b/tests/src/Csv2vcard/gmail.csv
Binary files differ
diff --git a/tests/src/Csv2vcard/gmail.vcf b/tests/src/Csv2vcard/gmail.vcf
new file mode 100644
index 000000000..5337d7e63
--- /dev/null
+++ b/tests/src/Csv2vcard/gmail.vcf
@@ -0,0 +1,25 @@
+BEGIN:VCARD
+VERSION:3.0
+FN:Prefix Firstname Middle Lastname Suffix
+N:Lastname;Firstname;Middle;Prefix;Suffix
+NICKNAME:nick
+BDAY;VALUE=date:1975-12-12
+NOTE:note"note
+CATEGORIES:My Contacts
+EMAIL;TYPE=INTERNET;TYPE=HOME:home@aaa.pl
+EMAIL;TYPE=INTERNET;TYPE=WORK:work@email.pl
+TEL;TYPE=pager:pager
+TEL;TYPE=pref:mainphone
+TEL;TYPE=home:homephone
+TEL;TYPE=homefax:homefax
+TEL;TYPE=cell:mobile
+TEL;TYPE=work:workphone
+TEL;TYPE=workfax:workfax
+X-SPOUSE:spouse
+URL;TYPE=profile:test.com
+URL;TYPE=homepage:home.page.com
+ORG:company
+TITLE:jobtitle
+ADR;TYPE=home:;;home_street;home_city;home_state;home_zip;home_country
+ADR;TYPE=work:;;work_street;work_city;;work_zip;work_country
+END:VCARD