1<?php
2
3namespace Sabre\CardDAV;
4
5use Sabre\HTTP;
6
7class VCFExportTest extends \Sabre\DAVServerTest {
8
9    protected $setupCardDAV = true;
10    protected $autoLogin = 'user1';
11    protected $setupACL = true;
12
13    protected $carddavAddressBooks = array(
14        array(
15            'id' => 'book1',
16            'uri' => 'book1',
17            'principaluri' => 'principals/user1',
18        )
19    );
20    protected $carddavCards = array(
21        'book1' => array(
22            "card1" => "BEGIN:VCARD\r\nFN:Person1\r\nEND:VCARD\r\n",
23            "card2" => "BEGIN:VCARD\r\nFN:Person2\r\nEND:VCARD",
24            "card3" => "BEGIN:VCARD\r\nFN:Person3\r\nEND:VCARD\r\n",
25            "card4" => "BEGIN:VCARD\nFN:Person4\nEND:VCARD\n",
26        )
27    );
28
29    function setUp() {
30
31        parent::setUp();
32        $this->server->addPlugin(
33            new VCFExportPlugin()
34        );
35
36    }
37
38    function testSimple() {
39
40        $this->assertInstanceOf('Sabre\\CardDAV\\VCFExportPlugin', $this->server->getPlugin('vcf-export'));
41
42    }
43
44    function testExport() {
45
46        $request = HTTP\Sapi::createFromServerArray(array(
47            'REQUEST_URI' => '/addressbooks/user1/book1?export',
48            'QUERY_STRING' => 'export',
49            'REQUEST_METHOD' => 'GET',
50        ));
51
52        $response = $this->request($request);
53        $this->assertEquals(200, $response->status, $response->body);
54
55        $expected = "BEGIN:VCARD
56FN:Person1
57END:VCARD
58BEGIN:VCARD
59FN:Person2
60END:VCARD
61BEGIN:VCARD
62FN:Person3
63END:VCARD
64BEGIN:VCARD
65FN:Person4
66END:VCARD
67";
68        // We actually expected windows line endings
69        $expected = str_replace("\n","\r\n", $expected);
70
71        $this->assertEquals($expected, $response->body);
72
73    }
74
75}
76