ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
VCFExportTest.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\CardDAV;
4
5use Sabre\HTTP;
6
8
9 protected $setupCardDAV = true;
10 protected $autoLogin = 'user1';
11 protected $setupACL = true;
12
14 [
15 'id' => 'book1',
16 'uri' => 'book1',
17 'principaluri' => 'principals/user1',
18 ]
19 ];
20 protected $carddavCards = [
21 'book1' => [
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 $plugin = new VCFExportPlugin();
33 $this->server->addPlugin(
34 $plugin
35 );
36
37 }
38
39 function testSimple() {
40
41 $plugin = $this->server->getPlugin('vcf-export');
42 $this->assertInstanceOf('Sabre\\CardDAV\\VCFExportPlugin', $plugin);
43
44 $this->assertEquals(
45 'vcf-export',
46 $plugin->getPluginInfo()['name']
47 );
48
49 }
50
51 function testExport() {
52
54 'REQUEST_URI' => '/addressbooks/user1/book1?export',
55 'QUERY_STRING' => 'export',
56 'REQUEST_METHOD' => 'GET',
57 ]);
58
59 $response = $this->request($request);
60 $this->assertEquals(200, $response->status, $response->body);
61
62 $expected = "BEGIN:VCARD
63FN:Person1
64END:VCARD
65BEGIN:VCARD
66FN:Person2
67END:VCARD
68BEGIN:VCARD
69FN:Person3
70END:VCARD
71BEGIN:VCARD
72FN:Person4
73END:VCARD
74";
75 // We actually expected windows line endings
76 $expected = str_replace("\n", "\r\n", $expected);
77
78 $this->assertEquals($expected, $response->body);
79
80 }
81
83
84 $plugin = $this->server->getPlugin('vcf-export');
85 $actions = '';
86 $addressbook = new AddressBook($this->carddavBackend, []);
87 $this->server->emit('browserButtonActions', ['/foo', $addressbook, &$actions]);
88 $this->assertContains('/foo?export', $actions);
89
90 }
91
93
94 $request = new HTTP\Request(
95 'GET',
96 '/addressbooks/user1/book1?export'
97 );
98
99 $response = $this->request($request, 200);
100 $this->assertEquals('text/directory', $response->getHeader('Content-Type'));
101 $this->assertEquals(
102 'attachment; filename="book1-' . date('Y-m-d') . '.vcf"',
103 $response->getHeader('Content-Disposition')
104 );
105
106 }
107
109
110 $this->carddavBackend->createAddressBook(
111 'principals/user1',
112 'book-b_ad"(ch)ars',
113 []
114 );
115 $this->carddavBackend->createCard(
116 'book-b_ad"(ch)ars',
117 'card1',
118 "BEGIN:VCARD\r\nFN:Person1\r\nEND:VCARD\r\n"
119 );
120
121 $request = new HTTP\Request(
122 'GET',
123 '/addressbooks/user1/book-b_ad"(ch)ars?export'
124 );
125
126 $response = $this->request($request, 200);
127 $this->assertEquals('text/directory', $response->getHeader('Content-Type'));
128 $this->assertEquals(
129 'attachment; filename="book-b_adchars-' . date('Y-m-d') . '.vcf"',
130 $response->getHeader('Content-Disposition')
131 );
132
133 }
134
135}
foreach($paths as $path) $request
Definition: asyncclient.php:32
An exception for terminatinating execution or to throw for unit testing.
The AddressBook class represents a CardDAV addressbook, owned by a specific user.
Definition: AddressBook.php:17
This class may be used as a basis for other webdav-related unittests.
request($request, $expectedStatus=null)
Makes a request, and returns a response object.
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
$response