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