ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
MessageDecoratorTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\HTTP;
4 
6 
7  protected $inner;
8  protected $outer;
9 
10  function setUp() {
11 
12  $this->inner = new Request();
13  $this->outer = new RequestDecorator($this->inner);
14 
15  }
16 
17  function testBody() {
18 
19  $this->outer->setBody('foo');
20  $this->assertEquals('foo', stream_get_contents($this->inner->getBodyAsStream()));
21  $this->assertEquals('foo', stream_get_contents($this->outer->getBodyAsStream()));
22  $this->assertEquals('foo', $this->inner->getBodyAsString());
23  $this->assertEquals('foo', $this->outer->getBodyAsString());
24  $this->assertEquals('foo', $this->inner->getBody());
25  $this->assertEquals('foo', $this->outer->getBody());
26 
27  }
28 
29  function testHeaders() {
30 
31  $this->outer->setHeaders([
32  'a' => 'b',
33  ]);
34 
35  $this->assertEquals(['a' => ['b']], $this->inner->getHeaders());
36  $this->assertEquals(['a' => ['b']], $this->outer->getHeaders());
37 
38  $this->outer->setHeaders([
39  'c' => 'd',
40  ]);
41 
42  $this->assertEquals(['a' => ['b'], 'c' => ['d']], $this->inner->getHeaders());
43  $this->assertEquals(['a' => ['b'], 'c' => ['d']], $this->outer->getHeaders());
44 
45  $this->outer->addHeaders([
46  'e' => 'f',
47  ]);
48 
49  $this->assertEquals(['a' => ['b'], 'c' => ['d'], 'e' => ['f']], $this->inner->getHeaders());
50  $this->assertEquals(['a' => ['b'], 'c' => ['d'], 'e' => ['f']], $this->outer->getHeaders());
51  }
52 
53  function testHeader() {
54 
55  $this->assertFalse($this->outer->hasHeader('a'));
56  $this->assertFalse($this->inner->hasHeader('a'));
57  $this->outer->setHeader('a', 'c');
58  $this->assertTrue($this->outer->hasHeader('a'));
59  $this->assertTrue($this->inner->hasHeader('a'));
60 
61  $this->assertEquals('c', $this->inner->getHeader('A'));
62  $this->assertEquals('c', $this->outer->getHeader('A'));
63 
64  $this->outer->addHeader('A', 'd');
65 
66  $this->assertEquals(
67  ['c', 'd'],
68  $this->inner->getHeaderAsArray('A')
69  );
70  $this->assertEquals(
71  ['c', 'd'],
72  $this->outer->getHeaderAsArray('A')
73  );
74 
75  $success = $this->outer->removeHeader('a');
76 
77  $this->assertTrue($success);
78  $this->assertNull($this->inner->getHeader('A'));
79  $this->assertNull($this->outer->getHeader('A'));
80 
81  $this->assertFalse($this->outer->removeHeader('i-dont-exist'));
82  }
83 
84  function testHttpVersion() {
85 
86  $this->outer->setHttpVersion('1.0');
87 
88  $this->assertEquals('1.0', $this->inner->getHttpVersion());
89  $this->assertEquals('1.0', $this->outer->getHttpVersion());
90 
91  }
92 
93 }
The Request class represents a single HTTP request.
Definition: Request.php:18
$success
Definition: Utf8Test.php:86