"Fossies" - the Fresh Open Source Software Archive

Member "dav-4.0.3/tests/Sabre/DAV/Xml/Property/SupportedReportSetTest.php" (10 Jan 2020, 4635 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 "SupportedReportSetTest.php": 4.0.2_vs_4.0.3.

    1 <?php
    2 
    3 declare(strict_types=1);
    4 
    5 namespace Sabre\DAV\Property;
    6 
    7 use Sabre\DAV;
    8 use Sabre\HTTP;
    9 
   10 require_once 'Sabre/HTTP/ResponseMock.php';
   11 require_once 'Sabre/DAV/AbstractServer.php';
   12 
   13 class SupportedReportSetTest extends DAV\AbstractServer
   14 {
   15     public function sendPROPFIND($body)
   16     {
   17         $serverVars = [
   18             'REQUEST_URI' => '/',
   19             'REQUEST_METHOD' => 'PROPFIND',
   20             'HTTP_DEPTH' => '0',
   21         ];
   22 
   23         $request = HTTP\Sapi::createFromServerArray($serverVars);
   24         $request->setBody($body);
   25 
   26         $this->server->httpRequest = ($request);
   27         $this->server->exec();
   28     }
   29 
   30     public function testNoReports()
   31     {
   32         $xml = '<?xml version="1.0"?>
   33 <d:propfind xmlns:d="DAV:">
   34   <d:prop>
   35     <d:supported-report-set />
   36   </d:prop>
   37 </d:propfind>';
   38 
   39         $this->sendPROPFIND($xml);
   40 
   41         $bodyAsString = $this->response->getBodyAsString();
   42         $this->assertEquals(207, $this->response->status, 'We expected a multi-status response. Full response body: '.$bodyAsString);
   43 
   44         $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $bodyAsString);
   45         $xml = simplexml_load_string($body);
   46         $xml->registerXPathNamespace('d', 'urn:DAV');
   47 
   48         $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop');
   49         $this->assertEquals(1, count($data), 'We expected 1 \'d:prop\' element');
   50 
   51         $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set');
   52         $this->assertEquals(1, count($data), 'We expected 1 \'d:supported-report-set\' element');
   53 
   54         $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
   55         $this->assertEquals(1, count($data), 'We expected 1 \'d:status\' element');
   56 
   57         $this->assertEquals('HTTP/1.1 200 OK', (string) $data[0], 'The status for this property should have been 200');
   58     }
   59 
   60     /**
   61      * @depends testNoReports
   62      */
   63     public function testCustomReport()
   64     {
   65         // Intercepting the report property
   66         $this->server->on('propFind', function (DAV\PropFind $propFind, DAV\INode $node) {
   67             if ($prop = $propFind->get('{DAV:}supported-report-set')) {
   68                 $prop->addReport('{http://www.rooftopsolutions.nl/testnamespace}myreport');
   69                 $prop->addReport('{DAV:}anotherreport');
   70             }
   71         }, 200);
   72 
   73         $xml = '<?xml version="1.0"?>
   74 <d:propfind xmlns:d="DAV:">
   75   <d:prop>
   76     <d:supported-report-set />
   77   </d:prop>
   78 </d:propfind>';
   79 
   80         $this->sendPROPFIND($xml);
   81 
   82         $bodyAsString = $this->response->getBodyAsString();
   83         $this->assertEquals(207, $this->response->status, 'We expected a multi-status response. Full response body: '.$bodyAsString);
   84 
   85         $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $bodyAsString);
   86         $xml = simplexml_load_string($body);
   87         $xml->registerXPathNamespace('d', 'urn:DAV');
   88         $xml->registerXPathNamespace('x', 'http://www.rooftopsolutions.nl/testnamespace');
   89 
   90         $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop');
   91         $this->assertEquals(1, count($data), 'We expected 1 \'d:prop\' element');
   92 
   93         $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set');
   94         $this->assertEquals(1, count($data), 'We expected 1 \'d:supported-report-set\' element');
   95 
   96         $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report');
   97         $this->assertEquals(2, count($data), 'We expected 2 \'d:supported-report\' elements');
   98 
   99         $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report');
  100         $this->assertEquals(2, count($data), 'We expected 2 \'d:report\' elements');
  101 
  102         $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report/x:myreport');
  103         $this->assertEquals(1, count($data), 'We expected 1 \'x:myreport\' element. Full body: '.$bodyAsString);
  104 
  105         $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report/d:anotherreport');
  106         $this->assertEquals(1, count($data), 'We expected 1 \'d:anotherreport\' element. Full body: '.$bodyAsString);
  107 
  108         $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
  109         $this->assertEquals(1, count($data), 'We expected 1 \'d:status\' element');
  110 
  111         $this->assertEquals('HTTP/1.1 200 OK', (string) $data[0], 'The status for this property should have been 200');
  112     }
  113 }