ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\CardDAV\ValidateVCardTest Class Reference
+ Inheritance diagram for Sabre\CardDAV\ValidateVCardTest:
+ Collaboration diagram for Sabre\CardDAV\ValidateVCardTest:

Public Member Functions

 setUp ()
 
 request (HTTP\Request $request, $expectedStatus=null)
 
 testCreateFile ()
 
 testCreateFileValid ()
 
 testCreateVCardAutoFix ()
 This test creates an intentionally broken vCard that vobject is able to automatically repair. More...
 
 testCreateVCardStrictFail ()
 This test creates an intentionally broken vCard that vobject is able to automatically repair. More...
 
 testCreateFileNoUID ()
 
 testCreateFileJson ()
 
 testCreateFileVCalendar ()
 
 testUpdateFile ()
 
 testUpdateFileParsableBody ()
 

Protected Attributes

 $server
 
 $cardBackend
 

Detailed Description

Definition at line 11 of file ValidateVCardTest.php.

Member Function Documentation

◆ request()

Sabre\CardDAV\ValidateVCardTest::request ( HTTP\Request  $request,
  $expectedStatus = null 
)

Definition at line 45 of file ValidateVCardTest.php.

References $request.

Referenced by Sabre\CardDAV\ValidateVCardTest\testCreateFile(), Sabre\CardDAV\ValidateVCardTest\testCreateFileJson(), Sabre\CardDAV\ValidateVCardTest\testCreateFileNoUID(), Sabre\CardDAV\ValidateVCardTest\testCreateFileValid(), Sabre\CardDAV\ValidateVCardTest\testCreateFileVCalendar(), Sabre\CardDAV\ValidateVCardTest\testCreateVCardAutoFix(), Sabre\CardDAV\ValidateVCardTest\testCreateVCardStrictFail(), Sabre\CardDAV\ValidateVCardTest\testUpdateFile(), and Sabre\CardDAV\ValidateVCardTest\testUpdateFileParsableBody().

45  {
46 
47  $this->server->httpRequest = $request;
48  $this->server->exec();
49 
50  if ($expectedStatus) {
51 
52  $realStatus = $this->server->httpResponse->getStatus();
53 
54  $msg = '';
55  if ($realStatus !== $expectedStatus) {
56  $msg = 'Response body: ' . $this->server->httpResponse->getBodyAsString();
57  }
58  $this->assertEquals(
59  $expectedStatus,
60  $realStatus,
61  $msg
62  );
63  }
64 
65  return $this->server->httpResponse;
66 
67  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
+ Here is the caller graph for this function:

◆ setUp()

Sabre\CardDAV\ValidateVCardTest::setUp ( )

Definition at line 16 of file ValidateVCardTest.php.

References $principalBackend, $response, and $tree.

16  {
17 
18  $addressbooks = [
19  [
20  'id' => 'addressbook1',
21  'principaluri' => 'principals/admin',
22  'uri' => 'addressbook1',
23  ]
24  ];
25 
26  $this->cardBackend = new Backend\Mock($addressbooks, []);
27  $principalBackend = new DAVACL\PrincipalBackend\Mock();
28 
29  $tree = [
30  new AddressBookRoot($principalBackend, $this->cardBackend),
31  ];
32 
33  $this->server = new DAV\Server($tree);
34  $this->server->sapi = new HTTP\SapiMock();
35  $this->server->debugExceptions = true;
36 
37  $plugin = new Plugin();
38  $this->server->addPlugin($plugin);
39 
40  $response = new HTTP\ResponseMock();
41  $this->server->httpResponse = $response;
42 
43  }
$response
$principalBackend

◆ testCreateFile()

Sabre\CardDAV\ValidateVCardTest::testCreateFile ( )

Definition at line 69 of file ValidateVCardTest.php.

References $request, $response, Sabre\HTTP\Sapi\createFromServerArray(), and Sabre\CardDAV\ValidateVCardTest\request().

69  {
70 
72  'REQUEST_METHOD' => 'PUT',
73  'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf',
74  ]);
75 
76  $response = $this->request($request);
77 
78  $this->assertEquals(415, $response->status);
79 
80  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
request(HTTP\Request $request, $expectedStatus=null)
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
$response
+ Here is the call graph for this function:

◆ testCreateFileJson()

Sabre\CardDAV\ValidateVCardTest::testCreateFileJson ( )

Definition at line 239 of file ValidateVCardTest.php.

References $request, $response, and Sabre\CardDAV\ValidateVCardTest\request().

239  {
240 
241  $request = new HTTP\Request(
242  'PUT',
243  '/addressbooks/admin/addressbook1/blabla.vcf'
244  );
245  $request->setBody('[ "vcard" , [ [ "VERSION", {}, "text", "4.0"], [ "UID" , {}, "text", "foo" ], [ "FN", {}, "text", "FirstName LastName"] ] ]');
246 
247  $response = $this->request($request);
248 
249  $this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
250 
251  $foo = $this->cardBackend->getCard('addressbook1', 'blabla.vcf');
252  $this->assertEquals("BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nFN:FirstName LastName\r\nEND:VCARD\r\n", $foo['carddata']);
253 
254  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
request(HTTP\Request $request, $expectedStatus=null)
$response
+ Here is the call graph for this function:

◆ testCreateFileNoUID()

Sabre\CardDAV\ValidateVCardTest::testCreateFileNoUID ( )

Definition at line 215 of file ValidateVCardTest.php.

References $request, $response, and Sabre\CardDAV\ValidateVCardTest\request().

215  {
216 
217  $request = new HTTP\Request(
218  'PUT',
219  '/addressbooks/admin/addressbook1/blabla.vcf'
220  );
221  $vcard = <<<VCF
222 BEGIN:VCARD
223 VERSION:4.0
224 FN:Firstname LastName
225 N:LastName;FirstName;;;
226 END:VCARD
227 VCF;
228  $request->setBody($vcard);
229 
230  $response = $this->request($request, 201);
231 
232  $foo = $this->cardBackend->getCard('addressbook1', 'blabla.vcf');
233  $this->assertTrue(
234  strpos($foo['carddata'], 'UID') !== false,
235  print_r($foo, true)
236  );
237  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
request(HTTP\Request $request, $expectedStatus=null)
$response
+ Here is the call graph for this function:

◆ testCreateFileValid()

Sabre\CardDAV\ValidateVCardTest::testCreateFileValid ( )

Definition at line 82 of file ValidateVCardTest.php.

References $request, $response, and Sabre\CardDAV\ValidateVCardTest\request().

82  {
83 
84  $request = new HTTP\Request(
85  'PUT',
86  '/addressbooks/admin/addressbook1/blabla.vcf'
87  );
88 
89  $vcard = <<<VCF
90 BEGIN:VCARD
91 VERSION:4.0
92 UID:foo
93 FN:Firstname LastName
94 N:LastName;FirstName;;;
95 END:VCARD
96 VCF;
97  $request->setBody($vcard);
98 
99  $response = $this->request($request, 201);
100 
101  // The custom Ew header should not be set
102  $this->assertNull(
103  $response->getHeader('X-Sabre-Ew-Gross')
104  );
105  // Valid, non-auto-fixed responses should contain an ETag.
106  $this->assertTrue(
107  $response->getHeader('ETag') !== null,
108  'We did not receive an etag'
109  );
110 
111 
112  $expected = [
113  'uri' => 'blabla.vcf',
114  'carddata' => $vcard,
115  'size' => strlen($vcard),
116  'etag' => '"' . md5($vcard) . '"',
117  ];
118 
119  $this->assertEquals($expected, $this->cardBackend->getCard('addressbook1', 'blabla.vcf'));
120 
121  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
request(HTTP\Request $request, $expectedStatus=null)
$response
+ Here is the call graph for this function:

◆ testCreateFileVCalendar()

Sabre\CardDAV\ValidateVCardTest::testCreateFileVCalendar ( )

Definition at line 256 of file ValidateVCardTest.php.

References $request, $response, Sabre\HTTP\Sapi\createFromServerArray(), and Sabre\CardDAV\ValidateVCardTest\request().

256  {
257 
259  'REQUEST_METHOD' => 'PUT',
260  'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf',
261  ]);
262  $request->setBody("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n");
263 
264  $response = $this->request($request);
265 
266  $this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
267 
268  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
request(HTTP\Request $request, $expectedStatus=null)
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
$response
+ Here is the call graph for this function:

◆ testCreateVCardAutoFix()

Sabre\CardDAV\ValidateVCardTest::testCreateVCardAutoFix ( )

This test creates an intentionally broken vCard that vobject is able to automatically repair.

testCreateFileValid

Definition at line 129 of file ValidateVCardTest.php.

References $request, $response, and Sabre\CardDAV\ValidateVCardTest\request().

129  {
130 
131  $request = new HTTP\Request(
132  'PUT',
133  '/addressbooks/admin/addressbook1/blabla.vcf'
134  );
135 
136  // The error in this vcard is that there's not enough semi-colons in N
137  $vcard = <<<VCF
138 BEGIN:VCARD
139 VERSION:4.0
140 UID:foo
141 FN:Firstname LastName
142 N:LastName;FirstName;;
143 END:VCARD
144 VCF;
145 
146  $request->setBody($vcard);
147 
148  $response = $this->request($request, 201);
149 
150  // Auto-fixed vcards should NOT return an etag
151  $this->assertNull(
152  $response->getHeader('ETag')
153  );
154 
155  // We should have gotten an Ew header
156  $this->assertNotNull(
157  $response->getHeader('X-Sabre-Ew-Gross')
158  );
159 
160  $expectedVCard = <<<VCF
161 BEGIN:VCARD\r
162 VERSION:4.0\r
163 UID:foo\r
164 FN:Firstname LastName\r
165 N:LastName;FirstName;;;\r
166 END:VCARD\r
167 
168 VCF;
169 
170  $expected = [
171  'uri' => 'blabla.vcf',
172  'carddata' => $expectedVCard,
173  'size' => strlen($expectedVCard),
174  'etag' => '"' . md5($expectedVCard) . '"',
175  ];
176 
177  $this->assertEquals($expected, $this->cardBackend->getCard('addressbook1', 'blabla.vcf'));
178 
179  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
request(HTTP\Request $request, $expectedStatus=null)
$response
+ Here is the call graph for this function:

◆ testCreateVCardStrictFail()

Sabre\CardDAV\ValidateVCardTest::testCreateVCardStrictFail ( )

This test creates an intentionally broken vCard that vobject is able to automatically repair.

However, we're supplying a heading asking the server to treat the request as strict, so the server should still let the request fail.

testCreateFileValid

Definition at line 190 of file ValidateVCardTest.php.

References $request, and Sabre\CardDAV\ValidateVCardTest\request().

190  {
191 
192  $request = new HTTP\Request(
193  'PUT',
194  '/addressbooks/admin/addressbook1/blabla.vcf',
195  [
196  'Prefer' => 'handling=strict',
197  ]
198  );
199 
200  // The error in this vcard is that there's not enough semi-colons in N
201  $vcard = <<<VCF
202 BEGIN:VCARD
203 VERSION:4.0
204 UID:foo
205 FN:Firstname LastName
206 N:LastName;FirstName;;
207 END:VCARD
208 VCF;
209 
210  $request->setBody($vcard);
211  $this->request($request, 415);
212 
213  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
request(HTTP\Request $request, $expectedStatus=null)
+ Here is the call graph for this function:

◆ testUpdateFile()

Sabre\CardDAV\ValidateVCardTest::testUpdateFile ( )

Definition at line 270 of file ValidateVCardTest.php.

References $request, $response, and Sabre\CardDAV\ValidateVCardTest\request().

270  {
271 
272  $this->cardBackend->createCard('addressbook1', 'blabla.vcf', 'foo');
273  $request = new HTTP\Request(
274  'PUT',
275  '/addressbooks/admin/addressbook1/blabla.vcf'
276  );
277 
278  $response = $this->request($request, 415);
279 
280  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
request(HTTP\Request $request, $expectedStatus=null)
$response
+ Here is the call graph for this function:

◆ testUpdateFileParsableBody()

Sabre\CardDAV\ValidateVCardTest::testUpdateFileParsableBody ( )

Definition at line 282 of file ValidateVCardTest.php.

References $request, $response, and Sabre\CardDAV\ValidateVCardTest\request().

282  {
283 
284  $this->cardBackend->createCard('addressbook1', 'blabla.vcf', 'foo');
285  $request = new HTTP\Request(
286  'PUT',
287  '/addressbooks/admin/addressbook1/blabla.vcf'
288  );
289 
290  $body = "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nFN:FirstName LastName\r\nEND:VCARD\r\n";
291  $request->setBody($body);
292 
293  $response = $this->request($request, 204);
294 
295  $expected = [
296  'uri' => 'blabla.vcf',
297  'carddata' => $body,
298  'size' => strlen($body),
299  'etag' => '"' . md5($body) . '"',
300  ];
301 
302  $this->assertEquals($expected, $this->cardBackend->getCard('addressbook1', 'blabla.vcf'));
303 
304  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
request(HTTP\Request $request, $expectedStatus=null)
$response
+ Here is the call graph for this function:

Field Documentation

◆ $cardBackend

Sabre\CardDAV\ValidateVCardTest::$cardBackend
protected

Definition at line 14 of file ValidateVCardTest.php.

◆ $server

Sabre\CardDAV\ValidateVCardTest::$server
protected

Definition at line 13 of file ValidateVCardTest.php.


The documentation for this class was generated from the following file: