"Fossies" - the Fresh Open Source Software Archive

Member "dav-4.0.3/tests/Sabre/CardDAV/MultiGetTest.php" (10 Jan 2020, 3137 Bytes) of package /linux/www/dav-4.0.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "MultiGetTest.php": 4.0.2_vs_4.0.3.

    1 <?php
    2 
    3 declare(strict_types=1);
    4 
    5 namespace Sabre\CardDAV;
    6 
    7 use Sabre\DAV;
    8 use Sabre\HTTP;
    9 
   10 require_once 'Sabre/HTTP/ResponseMock.php';
   11 
   12 class MultiGetTest extends AbstractPluginTest
   13 {
   14     public function testMultiGet()
   15     {
   16         $request = HTTP\Sapi::createFromServerArray([
   17             'REQUEST_METHOD' => 'REPORT',
   18             'REQUEST_URI' => '/addressbooks/user1/book1',
   19         ]);
   20 
   21         $request->setBody(
   22 '<?xml version="1.0"?>
   23 <c:addressbook-multiget xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
   24     <d:prop>
   25       <d:getetag />
   26       <c:address-data />
   27     </d:prop>
   28     <d:href>/addressbooks/user1/book1/card1</d:href>
   29 </c:addressbook-multiget>'
   30             );
   31 
   32         $response = new HTTP\ResponseMock();
   33 
   34         $this->server->httpRequest = $request;
   35         $this->server->httpResponse = $response;
   36 
   37         $this->server->exec();
   38 
   39         $bodyAsString = $response->getBodyAsString();
   40         $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:'.$bodyAsString);
   41 
   42         // using the client for parsing
   43         $client = new DAV\Client(['baseUri' => '/']);
   44 
   45         $result = $client->parseMultiStatus($bodyAsString);
   46 
   47         $this->assertEquals([
   48             '/addressbooks/user1/book1/card1' => [
   49                 200 => [
   50                     '{DAV:}getetag' => '"'.md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD").'"',
   51                     '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD",
   52                 ],
   53             ],
   54         ], $result);
   55     }
   56 
   57     public function testMultiGetVCard4()
   58     {
   59         $request = HTTP\Sapi::createFromServerArray([
   60             'REQUEST_METHOD' => 'REPORT',
   61             'REQUEST_URI' => '/addressbooks/user1/book1',
   62         ]);
   63 
   64         $request->setBody(
   65 '<?xml version="1.0"?>
   66 <c:addressbook-multiget xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
   67     <d:prop>
   68       <d:getetag />
   69       <c:address-data content-type="text/vcard" version="4.0" />
   70     </d:prop>
   71     <d:href>/addressbooks/user1/book1/card1</d:href>
   72 </c:addressbook-multiget>'
   73             );
   74 
   75         $response = new HTTP\ResponseMock();
   76 
   77         $this->server->httpRequest = $request;
   78         $this->server->httpResponse = $response;
   79 
   80         $this->server->exec();
   81 
   82         $bodyAsString = $response->getBodyAsString();
   83         $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:'.$bodyAsString);
   84 
   85         // using the client for parsing
   86         $client = new DAV\Client(['baseUri' => '/']);
   87 
   88         $result = $client->parseMultiStatus($bodyAsString);
   89 
   90         $prodId = 'PRODID:-//Sabre//Sabre VObject '.\Sabre\VObject\Version::VERSION.'//EN';
   91 
   92         $this->assertEquals([
   93             '/addressbooks/user1/book1/card1' => [
   94                 200 => [
   95                     '{DAV:}getetag' => '"'.md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD").'"',
   96                     '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:4.0\r\n$prodId\r\nUID:12345\r\nEND:VCARD\r\n",
   97                 ],
   98             ],
   99         ], $result);
  100     }
  101 }