1<?php 2 3namespace Sabre\DAV; 4use Sabre\HTTP; 5 6require_once 'Sabre/DAV/AbstractServer.php'; 7require_once 'Sabre/DAV/TestPlugin.php'; 8 9class ServerPluginTest extends AbstractServer { 10 11 /** 12 * @var Sabre\DAV\TestPlugin 13 */ 14 protected $testPlugin; 15 16 function setUp() { 17 18 parent::setUp(); 19 20 $testPlugin = new TestPlugin(); 21 $this->server->addPlugin($testPlugin); 22 $this->testPlugin = $testPlugin; 23 24 } 25 26 /** 27 */ 28 function testBaseClass() { 29 30 $p = new ServerPluginMock(); 31 $this->assertEquals([],$p->getFeatures()); 32 $this->assertEquals([],$p->getHTTPMethods('')); 33 $this->assertEquals( 34 [ 35 'name' => 'Sabre\DAV\ServerPluginMock', 36 'description' => null, 37 'link' => null 38 ], $p->getPluginInfo() 39 ); 40 41 } 42 43 function testOptions() { 44 45 $serverVars = array( 46 'REQUEST_URI' => '/', 47 'REQUEST_METHOD' => 'OPTIONS', 48 ); 49 50 $request = HTTP\Sapi::createFromServerArray($serverVars); 51 $this->server->httpRequest = ($request); 52 $this->server->exec(); 53 54 $this->assertEquals(array( 55 'DAV' => ['1, 3, extended-mkcol, drinking'], 56 'MS-Author-Via' => ['DAV'], 57 'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT, BEER, WINE'], 58 'Accept-Ranges' => ['bytes'], 59 'Content-Length' => ['0'], 60 'X-Sabre-Version' => [Version::VERSION], 61 ),$this->response->getHeaders()); 62 63 $this->assertEquals(200, $this->response->status); 64 $this->assertEquals('', $this->response->body); 65 $this->assertEquals('OPTIONS',$this->testPlugin->beforeMethod); 66 67 68 } 69 70 function testGetPlugin() { 71 72 $this->assertEquals($this->testPlugin,$this->server->getPlugin(get_class($this->testPlugin))); 73 74 } 75 76 function testUnknownPlugin() { 77 78 $this->assertNull($this->server->getPlugin('SomeRandomClassName')); 79 80 } 81 82 function testGetSupportedReportSet() { 83 84 $this->assertEquals(array(), $this->testPlugin->getSupportedReportSet('/')); 85 86 } 87 88 function testGetPlugins() { 89 90 $this->assertEquals( 91 array( 92 get_class($this->testPlugin) => $this->testPlugin, 93 'core' => $this->server->getPlugin('core'), 94 ), 95 $this->server->getPlugins() 96 ); 97 98 } 99 100 101} 102 103class ServerPluginMock extends ServerPlugin { 104 105 function initialize(Server $s) { } 106 107} 108