1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\DAV; 4*a1a3b679SAndreas Boehleruse Sabre\HTTP; 5*a1a3b679SAndreas Boehler 6*a1a3b679SAndreas Boehlerrequire_once 'Sabre/DAV/AbstractServer.php'; 7*a1a3b679SAndreas Boehler 8*a1a3b679SAndreas Boehlerclass ServerEventsTest extends AbstractServer { 9*a1a3b679SAndreas Boehler 10*a1a3b679SAndreas Boehler private $tempPath; 11*a1a3b679SAndreas Boehler 12*a1a3b679SAndreas Boehler private $exception; 13*a1a3b679SAndreas Boehler 14*a1a3b679SAndreas Boehler function testAfterBind() { 15*a1a3b679SAndreas Boehler 16*a1a3b679SAndreas Boehler $this->server->on('afterBind', [$this,'afterBindHandler']); 17*a1a3b679SAndreas Boehler $newPath = 'afterBind'; 18*a1a3b679SAndreas Boehler 19*a1a3b679SAndreas Boehler $this->tempPath = ''; 20*a1a3b679SAndreas Boehler $this->server->createFile($newPath,'body'); 21*a1a3b679SAndreas Boehler $this->assertEquals($newPath, $this->tempPath); 22*a1a3b679SAndreas Boehler 23*a1a3b679SAndreas Boehler } 24*a1a3b679SAndreas Boehler 25*a1a3b679SAndreas Boehler function afterBindHandler($path) { 26*a1a3b679SAndreas Boehler 27*a1a3b679SAndreas Boehler $this->tempPath = $path; 28*a1a3b679SAndreas Boehler 29*a1a3b679SAndreas Boehler } 30*a1a3b679SAndreas Boehler 31*a1a3b679SAndreas Boehler function testAfterResponse() { 32*a1a3b679SAndreas Boehler 33*a1a3b679SAndreas Boehler $mock = $this->getMock('stdClass', array('afterResponseCallback')); 34*a1a3b679SAndreas Boehler $mock->expects($this->once())->method('afterResponseCallback'); 35*a1a3b679SAndreas Boehler 36*a1a3b679SAndreas Boehler $this->server->on('afterResponse', [$mock, 'afterResponseCallback']); 37*a1a3b679SAndreas Boehler 38*a1a3b679SAndreas Boehler $this->server->httpRequest = HTTP\Sapi::createFromServerArray(array( 39*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'GET', 40*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/test.txt', 41*a1a3b679SAndreas Boehler )); 42*a1a3b679SAndreas Boehler 43*a1a3b679SAndreas Boehler $this->server->exec(); 44*a1a3b679SAndreas Boehler 45*a1a3b679SAndreas Boehler } 46*a1a3b679SAndreas Boehler 47*a1a3b679SAndreas Boehler function testBeforeBindCancel() { 48*a1a3b679SAndreas Boehler 49*a1a3b679SAndreas Boehler $this->server->on('beforeBind', [$this,'beforeBindCancelHandler']); 50*a1a3b679SAndreas Boehler $this->assertFalse($this->server->createFile('bla','body')); 51*a1a3b679SAndreas Boehler 52*a1a3b679SAndreas Boehler // Also testing put() 53*a1a3b679SAndreas Boehler $req = HTTP\Sapi::createFromServerArray(array( 54*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'PUT', 55*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/barbar', 56*a1a3b679SAndreas Boehler )); 57*a1a3b679SAndreas Boehler 58*a1a3b679SAndreas Boehler $this->server->httpRequest = $req; 59*a1a3b679SAndreas Boehler $this->server->exec(); 60*a1a3b679SAndreas Boehler 61*a1a3b679SAndreas Boehler $this->assertEquals('',$this->server->httpResponse->status); 62*a1a3b679SAndreas Boehler 63*a1a3b679SAndreas Boehler } 64*a1a3b679SAndreas Boehler 65*a1a3b679SAndreas Boehler function beforeBindCancelHandler() { 66*a1a3b679SAndreas Boehler 67*a1a3b679SAndreas Boehler return false; 68*a1a3b679SAndreas Boehler 69*a1a3b679SAndreas Boehler } 70*a1a3b679SAndreas Boehler 71*a1a3b679SAndreas Boehler function testException() { 72*a1a3b679SAndreas Boehler 73*a1a3b679SAndreas Boehler $this->server->on('exception', [$this, 'exceptionHandler']); 74*a1a3b679SAndreas Boehler 75*a1a3b679SAndreas Boehler $req = HTTP\Sapi::createFromServerArray(array( 76*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'GET', 77*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/not/exisitng', 78*a1a3b679SAndreas Boehler )); 79*a1a3b679SAndreas Boehler $this->server->httpRequest = $req; 80*a1a3b679SAndreas Boehler $this->server->exec(); 81*a1a3b679SAndreas Boehler 82*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\DAV\\Exception\\NotFound', $this->exception); 83*a1a3b679SAndreas Boehler 84*a1a3b679SAndreas Boehler } 85*a1a3b679SAndreas Boehler 86*a1a3b679SAndreas Boehler function exceptionHandler(Exception $exception) { 87*a1a3b679SAndreas Boehler 88*a1a3b679SAndreas Boehler $this->exception = $exception; 89*a1a3b679SAndreas Boehler 90*a1a3b679SAndreas Boehler } 91*a1a3b679SAndreas Boehler 92*a1a3b679SAndreas Boehler function testMethod() { 93*a1a3b679SAndreas Boehler 94*a1a3b679SAndreas Boehler $k = 1; 95*a1a3b679SAndreas Boehler $this->server->on('method', function() use (&$k) { 96*a1a3b679SAndreas Boehler 97*a1a3b679SAndreas Boehler $k+=1; 98*a1a3b679SAndreas Boehler 99*a1a3b679SAndreas Boehler return false; 100*a1a3b679SAndreas Boehler 101*a1a3b679SAndreas Boehler }); 102*a1a3b679SAndreas Boehler $this->server->on('method', function() use (&$k) { 103*a1a3b679SAndreas Boehler 104*a1a3b679SAndreas Boehler $k+=2; 105*a1a3b679SAndreas Boehler 106*a1a3b679SAndreas Boehler return false; 107*a1a3b679SAndreas Boehler 108*a1a3b679SAndreas Boehler }); 109*a1a3b679SAndreas Boehler 110*a1a3b679SAndreas Boehler $this->server->invokeMethod( 111*a1a3b679SAndreas Boehler new HTTP\Request('BLABLA', '/'), 112*a1a3b679SAndreas Boehler new HTTP\Response(), 113*a1a3b679SAndreas Boehler false 114*a1a3b679SAndreas Boehler ); 115*a1a3b679SAndreas Boehler 116*a1a3b679SAndreas Boehler $this->assertEquals(2, $k); 117*a1a3b679SAndreas Boehler 118*a1a3b679SAndreas Boehler 119*a1a3b679SAndreas Boehler } 120*a1a3b679SAndreas Boehler 121*a1a3b679SAndreas Boehler} 122