"Fossies" - the Fresh Open Source Software Archive

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

    1 <?php
    2 
    3 declare(strict_types=1);
    4 
    5 namespace Sabre\DAV;
    6 
    7 use Sabre\HTTP;
    8 
    9 class HTTPPreferParsingTest extends \Sabre\DAVServerTest
   10 {
   11     public function assertParseResult($input, $expected)
   12     {
   13         $httpRequest = new HTTP\Request('GET', '/foo', [
   14             'Prefer' => $input,
   15         ]);
   16 
   17         $server = new Server();
   18         $server->httpRequest = $httpRequest;
   19 
   20         $this->assertEquals(
   21             $expected,
   22             $server->getHTTPPrefer()
   23         );
   24     }
   25 
   26     public function testParseSimple()
   27     {
   28         $this->assertParseResult(
   29             'return-asynch',
   30             [
   31                 'respond-async' => true,
   32                 'return' => null,
   33                 'handling' => null,
   34                 'wait' => null,
   35             ]
   36         );
   37     }
   38 
   39     public function testParseValue()
   40     {
   41         $this->assertParseResult(
   42             'wait=10',
   43             [
   44                 'respond-async' => false,
   45                 'return' => null,
   46                 'handling' => null,
   47                 'wait' => '10',
   48             ]
   49         );
   50     }
   51 
   52     public function testParseMultiple()
   53     {
   54         $this->assertParseResult(
   55             'return-minimal, strict,lenient',
   56             [
   57                 'respond-async' => false,
   58                 'return' => 'minimal',
   59                 'handling' => 'lenient',
   60                 'wait' => null,
   61             ]
   62         );
   63     }
   64 
   65     public function testParseWeirdValue()
   66     {
   67         $this->assertParseResult(
   68             'BOOOH',
   69             [
   70                 'respond-async' => false,
   71                 'return' => null,
   72                 'handling' => null,
   73                 'wait' => null,
   74                 'boooh' => true,
   75             ]
   76         );
   77     }
   78 
   79     public function testBrief()
   80     {
   81         $httpRequest = new HTTP\Request('GET', '/foo', [
   82             'Brief' => 't',
   83         ]);
   84 
   85         $server = new Server();
   86         $server->httpRequest = $httpRequest;
   87 
   88         $this->assertEquals([
   89             'respond-async' => false,
   90             'return' => 'minimal',
   91             'handling' => null,
   92             'wait' => null,
   93         ], $server->getHTTPPrefer());
   94     }
   95 
   96     /**
   97      * propfindMinimal.
   98      */
   99     public function testpropfindMinimal()
  100     {
  101         $request = new HTTP\Request('PROPFIND', '/', [
  102             'Prefer' => 'return-minimal',
  103         ]);
  104         $request->setBody(<<<BLA
  105 <?xml version="1.0"?>
  106 <d:propfind xmlns:d="DAV:">
  107     <d:prop>
  108         <d:something />
  109         <d:resourcetype />
  110     </d:prop>
  111 </d:propfind>
  112 BLA
  113         );
  114 
  115         $response = $this->request($request);
  116 
  117         $body = $response->getBodyAsString();
  118 
  119         $this->assertEquals(207, $response->getStatus(), $body);
  120 
  121         $this->assertTrue(false !== strpos($body, 'resourcetype'), $body);
  122         $this->assertTrue(false === strpos($body, 'something'), $body);
  123     }
  124 
  125     public function testproppatchMinimal()
  126     {
  127         $request = new HTTP\Request('PROPPATCH', '/', ['Prefer' => 'return-minimal']);
  128         $request->setBody(<<<BLA
  129 <?xml version="1.0"?>
  130 <d:propertyupdate xmlns:d="DAV:">
  131     <d:set>
  132         <d:prop>
  133             <d:something>nope!</d:something>
  134         </d:prop>
  135     </d:set>
  136 </d:propertyupdate>
  137 BLA
  138         );
  139 
  140         $this->server->on('propPatch', function ($path, PropPatch $propPatch) {
  141             $propPatch->handle('{DAV:}something', function ($props) {
  142                 return true;
  143             });
  144         });
  145 
  146         $response = $this->request($request);
  147 
  148         $this->assertEquals('', $response->getBodyAsString(), 'Expected empty body: '.$response->getBodyAsString());
  149         $this->assertEquals(204, $response->status);
  150     }
  151 
  152     public function testproppatchMinimalError()
  153     {
  154         $request = new HTTP\Request('PROPPATCH', '/', ['Prefer' => 'return-minimal']);
  155         $request->setBody(<<<BLA
  156 <?xml version="1.0"?>
  157 <d:propertyupdate xmlns:d="DAV:">
  158     <d:set>
  159         <d:prop>
  160             <d:something>nope!</d:something>
  161         </d:prop>
  162     </d:set>
  163 </d:propertyupdate>
  164 BLA
  165         );
  166 
  167         $response = $this->request($request);
  168 
  169         $body = $response->getBodyAsString();
  170 
  171         $this->assertEquals(207, $response->status);
  172         $this->assertTrue(false !== strpos($body, 'something'));
  173         $this->assertTrue(false !== strpos($body, '403 Forbidden'), $body);
  174     }
  175 }