"Fossies" - the Fresh Open Source Software Archive

Member "dav-4.0.3/tests/Sabre/DAV/Browser/PluginTest.php" (10 Jan 2020, 6433 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\Browser;
    6 
    7 use Sabre\DAV;
    8 use Sabre\HTTP;
    9 
   10 require_once 'Sabre/DAV/AbstractServer.php';
   11 
   12 class PluginTest extends DAV\AbstractServer
   13 {
   14     protected $plugin;
   15 
   16     public function setUp()
   17     {
   18         parent::setUp();
   19         $this->server->addPlugin($this->plugin = new Plugin());
   20         $this->server->tree->getNodeForPath('')->createDirectory('dir2');
   21     }
   22 
   23     public function testCollectionGet()
   24     {
   25         $request = new HTTP\Request('GET', '/dir');
   26         $this->server->httpRequest = $request;
   27         $this->server->exec();
   28 
   29         $this->assertEquals(200, $this->response->getStatus(), 'Incorrect status received. Full response body: '.$this->response->getBodyAsString());
   30         $this->assertEquals(
   31             [
   32                 'X-Sabre-Version' => [DAV\Version::VERSION],
   33                 'Content-Type' => ['text/html; charset=utf-8'],
   34                 'Content-Security-Policy' => ["default-src 'none'; img-src 'self'; style-src 'self'; font-src 'self';"],
   35             ],
   36             $this->response->getHeaders()
   37         );
   38 
   39         $body = $this->response->getBodyAsString();
   40         $this->assertTrue(false !== strpos($body, '<title>dir'), $body);
   41         $this->assertTrue(false !== strpos($body, '<a href="/dir/child.txt">'));
   42     }
   43 
   44     /**
   45      * Adding the If-None-Match should have 0 effect, but it threw an error.
   46      */
   47     public function testCollectionGetIfNoneMatch()
   48     {
   49         $request = new HTTP\Request('GET', '/dir');
   50         $request->setHeader('If-None-Match', '"foo-bar"');
   51         $this->server->httpRequest = $request;
   52         $this->server->exec();
   53 
   54         $this->assertEquals(200, $this->response->getStatus(), 'Incorrect status received. Full response body: '.$this->response->getBodyAsString());
   55         $this->assertEquals(
   56             [
   57                 'X-Sabre-Version' => [DAV\Version::VERSION],
   58                 'Content-Type' => ['text/html; charset=utf-8'],
   59                 'Content-Security-Policy' => ["default-src 'none'; img-src 'self'; style-src 'self'; font-src 'self';"],
   60             ],
   61             $this->response->getHeaders()
   62         );
   63 
   64         $body = $this->response->getBodyAsString();
   65         $this->assertTrue(false !== strpos($body, '<title>dir'), $body);
   66         $this->assertTrue(false !== strpos($body, '<a href="/dir/child.txt">'));
   67     }
   68 
   69     public function testCollectionGetRoot()
   70     {
   71         $request = new HTTP\Request('GET', '/');
   72         $this->server->httpRequest = ($request);
   73         $this->server->exec();
   74 
   75         $this->assertEquals(200, $this->response->status, 'Incorrect status received. Full response body: '.$this->response->getBodyAsString());
   76         $this->assertEquals(
   77             [
   78                 'X-Sabre-Version' => [DAV\Version::VERSION],
   79                 'Content-Type' => ['text/html; charset=utf-8'],
   80                 'Content-Security-Policy' => ["default-src 'none'; img-src 'self'; style-src 'self'; font-src 'self';"],
   81             ],
   82             $this->response->getHeaders()
   83         );
   84 
   85         $body = $this->response->getBodyAsString();
   86         $this->assertTrue(false !== strpos($body, '<title>/'), $body);
   87         $this->assertTrue(false !== strpos($body, '<a href="/dir/">'));
   88         $this->assertTrue(false !== strpos($body, '<span class="btn disabled">'));
   89     }
   90 
   91     public function testGETPassthru()
   92     {
   93         $request = new HTTP\Request('GET', '/random');
   94         $response = new HTTP\Response();
   95         $this->assertNull(
   96             $this->plugin->httpGet($request, $response)
   97         );
   98     }
   99 
  100     public function testPostOtherContentType()
  101     {
  102         $request = new HTTP\Request('POST', '/', ['Content-Type' => 'text/xml']);
  103         $this->server->httpRequest = $request;
  104         $this->server->exec();
  105 
  106         $this->assertEquals(501, $this->response->status);
  107     }
  108 
  109     public function testPostNoSabreAction()
  110     {
  111         $request = new HTTP\Request('POST', '/', ['Content-Type' => 'application/x-www-form-urlencoded']);
  112         $request->setPostData([]);
  113         $this->server->httpRequest = $request;
  114         $this->server->exec();
  115 
  116         $this->assertEquals(501, $this->response->status);
  117     }
  118 
  119     public function testPostMkCol()
  120     {
  121         $serverVars = [
  122             'REQUEST_URI' => '/',
  123             'REQUEST_METHOD' => 'POST',
  124             'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
  125         ];
  126         $postVars = [
  127             'sabreAction' => 'mkcol',
  128             'name' => 'new_collection',
  129         ];
  130 
  131         $request = HTTP\Sapi::createFromServerArray($serverVars);
  132         $request->setPostData($postVars);
  133         $this->server->httpRequest = $request;
  134         $this->server->exec();
  135 
  136         $this->assertEquals(302, $this->response->status);
  137         $this->assertEquals([
  138             'X-Sabre-Version' => [DAV\Version::VERSION],
  139             'Location' => ['/'],
  140         ], $this->response->getHeaders());
  141 
  142         $this->assertTrue(is_dir(SABRE_TEMPDIR.'/new_collection'));
  143     }
  144 
  145     public function testGetAsset()
  146     {
  147         $request = new HTTP\Request('GET', '/?sabreAction=asset&assetName=favicon.ico');
  148         $this->server->httpRequest = $request;
  149         $this->server->exec();
  150 
  151         $this->assertEquals(200, $this->response->getStatus(), 'Error: '.$this->response->getBodyAsString());
  152         $this->assertEquals([
  153             'X-Sabre-Version' => [DAV\Version::VERSION],
  154             'Content-Type' => ['image/vnd.microsoft.icon'],
  155             'Content-Length' => ['4286'],
  156             'Cache-Control' => ['public, max-age=1209600'],
  157             'Content-Security-Policy' => ["default-src 'none'; img-src 'self'; style-src 'self'; font-src 'self';"],
  158         ], $this->response->getHeaders());
  159     }
  160 
  161     public function testGetAsset404()
  162     {
  163         $request = new HTTP\Request('GET', '/?sabreAction=asset&assetName=flavicon.ico');
  164         $this->server->httpRequest = $request;
  165         $this->server->exec();
  166 
  167         $this->assertEquals(404, $this->response->getStatus(), 'Error: '.$this->response->getBodyAsString());
  168     }
  169 
  170     public function testGetAssetEscapeBasePath()
  171     {
  172         $request = new HTTP\Request('GET', '/?sabreAction=asset&assetName=./../assets/favicon.ico');
  173         $this->server->httpRequest = $request;
  174         $this->server->exec();
  175 
  176         $this->assertEquals(404, $this->response->getStatus(), 'Error: '.$this->response->getBodyAsString());
  177     }
  178 }