diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Framework/Csv2vcard.php | 57 | ||||
-rw-r--r-- | tests/Framework/Utils.php | 13 | ||||
-rw-r--r-- | tests/phpunit.xml | 1 | ||||
-rw-r--r-- | tests/src/Csv2vcard/email.csv | 5 | ||||
-rw-r--r-- | tests/src/Csv2vcard/email.vcf | 20 | ||||
-rw-r--r-- | tests/src/Csv2vcard/tb_plain.csv | 2 | ||||
-rw-r--r-- | tests/src/Csv2vcard/tb_plain.vcf | 18 |
7 files changed, 116 insertions, 0 deletions
diff --git a/tests/Framework/Csv2vcard.php b/tests/Framework/Csv2vcard.php new file mode 100644 index 000000000..6fa3e163c --- /dev/null +++ b/tests/Framework/Csv2vcard.php @@ -0,0 +1,57 @@ +<?php + +/** + * Test class to test rcube_csv2vcard class + * + * @package Tests + */ +class Framework_Csv2vcard extends PHPUnit_Framework_TestCase +{ + + function test_import_generic() + { + $csv = new rcube_csv2vcard; + + // empty input + $csv->import(''); + $this->assertSame(array(), $csv->export()); + } + + function test_import_tb_plain() + { + $csv_text = file_get_contents(TESTS_DIR . '/src/Csv2vcard/tb_plain.csv'); + $vcf_text = file_get_contents(TESTS_DIR . '/src/Csv2vcard/tb_plain.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); + } + + function test_import_email() + { + $csv_text = file_get_contents(TESTS_DIR . '/src/Csv2vcard/email.csv'); + $vcf_text = file_get_contents(TESTS_DIR . '/src/Csv2vcard/email.vcf'); + + $csv = new rcube_csv2vcard; + $csv->import($csv_text); + $result = $csv->export(); + + $this->assertCount(4, $result); + + $vcard = ''; + foreach ($result as $vcf) { + $vcard .= $vcf->export(false) . "\n"; + } + + $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/Utils.php b/tests/Framework/Utils.php index e58835956..ec61c5d4b 100644 --- a/tests/Framework/Utils.php +++ b/tests/Framework/Utils.php @@ -193,4 +193,17 @@ class Framework_Utils extends PHPUnit_Framework_TestCase $mod = rcube_utils::mod_css_styles("background:\\0075\\0072\\006c( javascript:alert('xss') )", 'rcmbody'); $this->assertEquals("/* evil! */", $mod, "Don't allow encoding quirks (2)"); } + + /** + * Check rcube_utils::explode_quoted_string() compat. with explode() + */ + function test_explode_quoted_string_compat() + { + $data = array('', 'a,b,c', 'a', ',', ',a'); + + foreach ($data as $text) { + $result = rcube_utils::explode_quoted_string(',', $text); + $this->assertSame(explode(',', $text), $result); + } + } } diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 43c3b767d..2e52b7795 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -8,6 +8,7 @@ <file>Framework/Cache.php</file> <file>Framework/Charset.php</file> <file>Framework/ContentFilter.php</file> + <file>Framework/Csv2vcard.php</file> <file>Framework/Html.php</file> <file>Framework/Imap.php</file> <file>Framework/ImapGeneric.php</file> diff --git a/tests/src/Csv2vcard/email.csv b/tests/src/Csv2vcard/email.csv new file mode 100644 index 000000000..1556d9142 --- /dev/null +++ b/tests/src/Csv2vcard/email.csv @@ -0,0 +1,5 @@ +Primary Email +test1@domain.tld +test2@domain.tld +test3@domain.tld +test4@domain.tld diff --git a/tests/src/Csv2vcard/email.vcf b/tests/src/Csv2vcard/email.vcf new file mode 100644 index 000000000..69912a639 --- /dev/null +++ b/tests/src/Csv2vcard/email.vcf @@ -0,0 +1,20 @@ +BEGIN:VCARD +VERSION:3.0 +FN:test1@domain.tld +EMAIL;TYPE=INTERNET;TYPE=PREF:test1@domain.tld +END:VCARD +BEGIN:VCARD +VERSION:3.0 +FN:test2@domain.tld +EMAIL;TYPE=INTERNET;TYPE=PREF:test2@domain.tld +END:VCARD +BEGIN:VCARD +VERSION:3.0 +FN:test3@domain.tld +EMAIL;TYPE=INTERNET;TYPE=PREF:test3@domain.tld +END:VCARD +BEGIN:VCARD +VERSION:3.0 +FN:test4@domain.tld +EMAIL;TYPE=INTERNET;TYPE=PREF:test4@domain.tld +END:VCARD diff --git a/tests/src/Csv2vcard/tb_plain.csv b/tests/src/Csv2vcard/tb_plain.csv new file mode 100644 index 000000000..94ea766c0 --- /dev/null +++ b/tests/src/Csv2vcard/tb_plain.csv @@ -0,0 +1,2 @@ +First Name,Last Name,Display Name,Nickname,Primary Email,Secondary Email,Screen Name,Work Phone,Home Phone,Fax Number,Pager Number,Mobile Number,Home Address,Home Address 2,Home City,Home State,Home ZipCode,Home Country,Work Address,Work Address 2,Work City,Work State,Work ZipCode,Work Country,Job Title,Department,Organization,Web Page 1,Web Page 2,Birth Year,Birth Month,Birth Day,Custom 1,Custom 2,Custom 3,Custom 4,Notes, +Firstname,Lastname,Displayname,Nick,test@domain.tld,next@domain.tld,,phone work,phone home,fax,pager,mobile,Priv address,,City,region,xx-xxx,USA,Addr work,,city,region,33-333,Poland,title,department,Organization,http://page.com,http://webpage.tld,1970,11,15,,,,,, diff --git a/tests/src/Csv2vcard/tb_plain.vcf b/tests/src/Csv2vcard/tb_plain.vcf new file mode 100644 index 000000000..aace259d8 --- /dev/null +++ b/tests/src/Csv2vcard/tb_plain.vcf @@ -0,0 +1,18 @@ +BEGIN:VCARD +VERSION:3.0 +FN:Displayname +N:Lastname;Firstname;;; +NICKNAME:Nick +EMAIL;TYPE=INTERNET;TYPE=PREF:test@domain.tld +EMAIL;TYPE=INTERNET;TYPE=OTHER:next@domain.tld +TEL;TYPE=work:phone work +TEL;TYPE=home:phone home +TEL;TYPE=fax:fax +TEL;TYPE=cell:mobile +TITLE:title +X-DEPARTMENT:department +ORG:Organization +URL;TYPE=homepage:http://page.com +URL;TYPE=other:http://webpage.tld +BDAY;VALUE=date:1970-11-15 +END:VCARD |