"Fossies" - the Fresh Open Source Software Archive

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

    1 <?php
    2 
    3 declare(strict_types=1);
    4 
    5 namespace Sabre\DAV\PartialUpdate;
    6 
    7 use Sabre\HTTP;
    8 
    9 require_once 'Sabre/DAV/PartialUpdate/FileMock.php';
   10 
   11 class PluginTest extends \Sabre\DAVServerTest
   12 {
   13     protected $node;
   14     protected $plugin;
   15 
   16     public function setUp()
   17     {
   18         $this->node = new FileMock();
   19         $this->tree[] = $this->node;
   20 
   21         parent::setUp();
   22 
   23         $this->plugin = new Plugin();
   24         $this->server->addPlugin($this->plugin);
   25     }
   26 
   27     public function testInit()
   28     {
   29         $this->assertEquals('partialupdate', $this->plugin->getPluginName());
   30         $this->assertEquals(['sabredav-partialupdate'], $this->plugin->getFeatures());
   31         $this->assertEquals([
   32             'PATCH',
   33         ], $this->plugin->getHTTPMethods('partial'));
   34         $this->assertEquals([
   35         ], $this->plugin->getHTTPMethods(''));
   36     }
   37 
   38     public function testPatchNoRange()
   39     {
   40         $this->node->put('aaaaaaaa');
   41         $request = HTTP\Sapi::createFromServerArray([
   42             'REQUEST_METHOD' => 'PATCH',
   43             'REQUEST_URI' => '/partial',
   44         ]);
   45         $response = $this->request($request);
   46 
   47         $this->assertEquals(400, $response->status, 'Full response body:'.$response->getBodyAsString());
   48     }
   49 
   50     public function testPatchNotSupported()
   51     {
   52         $this->node->put('aaaaaaaa');
   53         $request = new HTTP\Request('PATCH', '/', ['X-Update-Range' => '3-4']);
   54         $request->setBody(
   55             'bbb'
   56         );
   57         $response = $this->request($request);
   58 
   59         $this->assertEquals(405, $response->status, 'Full response body:'.$response->getBodyAsString());
   60     }
   61 
   62     public function testPatchNoContentType()
   63     {
   64         $this->node->put('aaaaaaaa');
   65         $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-4']);
   66         $request->setBody(
   67             'bbb'
   68         );
   69         $response = $this->request($request);
   70 
   71         $this->assertEquals(415, $response->status, 'Full response body:'.$response->getBodyAsString());
   72     }
   73 
   74     public function testPatchBadRange()
   75     {
   76         $this->node->put('aaaaaaaa');
   77         $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-4', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => '3']);
   78         $request->setBody(
   79             'bbb'
   80         );
   81         $response = $this->request($request);
   82 
   83         $this->assertEquals(416, $response->status, 'Full response body:'.$response->getBodyAsString());
   84     }
   85 
   86     public function testPatchNoLength()
   87     {
   88         $this->node->put('aaaaaaaa');
   89         $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-5', 'Content-Type' => 'application/x-sabredav-partialupdate']);
   90         $request->setBody(
   91             'bbb'
   92         );
   93         $response = $this->request($request);
   94 
   95         $this->assertEquals(411, $response->status, 'Full response body:'.$response->getBodyAsString());
   96     }
   97 
   98     public function testPatchSuccess()
   99     {
  100         $this->node->put('aaaaaaaa');
  101         $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-5', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => 3]);
  102         $request->setBody(
  103             'bbb'
  104         );
  105         $response = $this->request($request);
  106 
  107         $this->assertEquals(204, $response->status, 'Full response body:'.$response->getBodyAsString());
  108         $this->assertEquals('aaabbbaa', $this->node->get());
  109     }
  110 
  111     public function testPatchNoEndRange()
  112     {
  113         $this->node->put('aaaaa');
  114         $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => '3']);
  115         $request->setBody(
  116             'bbb'
  117         );
  118 
  119         $response = $this->request($request);
  120 
  121         $this->assertEquals(204, $response->getStatus(), 'Full response body:'.$response->getBodyAsString());
  122         $this->assertEquals('aaabbb', $this->node->get());
  123     }
  124 }