summaryrefslogtreecommitdiff
path: root/tests/Framework/Csv2vcard.php
blob: 5d52efc58bcbd0fdf4bac7b67b69e8287054989a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?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);
    }
}