ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ServerEventsTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\DAV;
4 
5 use Sabre\HTTP;
6 
7 require_once 'Sabre/DAV/AbstractServer.php';
8 
10 
11  private $tempPath;
12 
13  private $exception;
14 
15  function testAfterBind() {
16 
17  $this->server->on('afterBind', [$this, 'afterBindHandler']);
18  $newPath = 'afterBind';
19 
20  $this->tempPath = '';
21  $this->server->createFile($newPath, 'body');
22  $this->assertEquals($newPath, $this->tempPath);
23 
24  }
25 
26  function afterBindHandler($path) {
27 
28  $this->tempPath = $path;
29 
30  }
31 
32  function testAfterResponse() {
33 
34  $mock = $this->getMockBuilder('stdClass')
35  ->setMethods(['afterResponseCallback'])
36  ->getMock();
37  $mock->expects($this->once())->method('afterResponseCallback');
38 
39  $this->server->on('afterResponse', [$mock, 'afterResponseCallback']);
40 
41  $this->server->httpRequest = HTTP\Sapi::createFromServerArray([
42  'REQUEST_METHOD' => 'GET',
43  'REQUEST_URI' => '/test.txt',
44  ]);
45 
46  $this->server->exec();
47 
48  }
49 
50  function testBeforeBindCancel() {
51 
52  $this->server->on('beforeBind', [$this, 'beforeBindCancelHandler']);
53  $this->assertFalse($this->server->createFile('bla', 'body'));
54 
55  // Also testing put()
57  'REQUEST_METHOD' => 'PUT',
58  'REQUEST_URI' => '/barbar',
59  ]);
60 
61  $this->server->httpRequest = $req;
62  $this->server->exec();
63 
64  $this->assertEquals(500, $this->server->httpResponse->getStatus());
65 
66  }
67 
69 
70  return false;
71 
72  }
73 
74  function testException() {
75 
76  $this->server->on('exception', [$this, 'exceptionHandler']);
77 
79  'REQUEST_METHOD' => 'GET',
80  'REQUEST_URI' => '/not/exisitng',
81  ]);
82  $this->server->httpRequest = $req;
83  $this->server->exec();
84 
85  $this->assertInstanceOf('Sabre\\DAV\\Exception\\NotFound', $this->exception);
86 
87  }
88 
90 
91  $this->exception = $exception;
92 
93  }
94 
95  function testMethod() {
96 
97  $k = 1;
98  $this->server->on('method', function($request, $response) use (&$k) {
99 
100  $k += 1;
101 
102  return false;
103 
104  });
105  $this->server->on('method', function($request, $response) use (&$k) {
106 
107  $k += 2;
108 
109  return false;
110 
111  });
112 
113  try {
114  $this->server->invokeMethod(
115  new HTTP\Request('BLABLA', '/'),
116  new HTTP\Response(),
117  false
118  );
119  } catch (Exception $e) {}
120 
121  // Fun fact, PHP 7.1 changes the order when sorting-by-callback.
122  $this->assertTrue($k >= 2 && $k <= 3);
123 
124  }
125 
126 }
$path
Definition: aliased.php:25
The Request class represents a single HTTP request.
Definition: Request.php:18
$req
Definition: getUserInfo.php:20
This class represents a single HTTP response.
Definition: Response.php:12
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
exceptionHandler(Exception $exception)
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107