ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
XAccelTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
27 
30 use Mockery;
33 
44 class XAccelTest extends TestCase
45 {
50 
54  protected function setUp(): void
55  {
56  $this->httpServiceMock = $this->getMockBuilder(Services::class)
57  ->disableOriginalConstructor()
58  ->getMock();
59  }
60 
64  public function testPrepareWhichShouldSucceed(): void
65  {
66  $expectedContentValue = '';
67 
68  $response = $this->getMockBuilder(ResponseInterface::class)
69  ->disableOriginalConstructor()
70  ->getMock();
71 
72  $response->expects($this->once())
73  ->method('withHeader')
74  ->with(ResponseHeader::CONTENT_TYPE, $expectedContentValue)
75  ->willReturnSelf();
76 
77  $this->httpServiceMock->expects($this->once())
78  ->method('response')
79  ->willReturn($response);
80 
81  $this->httpServiceMock->expects($this->once())
82  ->method('saveResponse')
83  ->with($response);
84 
85  $this->httpServiceMock->expects($this->never())
86  ->method('sendResponse');
87 
88  $xAccel = new XAccel($this->httpServiceMock);
89  $xAccel->prepare("this path is never used in this method", null);
90 
91  $this->assertTrue(true);
92  }
93 
98  {
99  $expectedHeader = 'X-Accel-Redirect';
100  $path = './normal/path';
101 
102  $response = $this->getMockBuilder(ResponseInterface::class)
103  ->disableOriginalConstructor()
104  ->getMock();
105 
106  $response->expects($this->once())
107  ->method('withHeader')
108  ->with($expectedHeader, $path)
109  ->willReturnSelf();
110 
111  $this->httpServiceMock->expects($this->once())
112  ->method('response')
113  ->willReturn($response);
114 
115  $this->httpServiceMock->expects($this->once())
116  ->method('saveResponse')
117  ->with($response);
118 
119  $this->httpServiceMock->expects($this->once())
120  ->method('sendResponse');
121 
122 
123  $xAccel = new XAccel($this->httpServiceMock);
124  $xAccel->deliver($path, false);
125  }
126 
131  {
132  $expectedHeader = 'X-Accel-Redirect';
133  $path = './data/path/to/what/ever';
134  $expectedPath = '/secured-data/path/to/what/ever';
135 
136  $response = $this->getMockBuilder(ResponseInterface::class)
137  ->disableOriginalConstructor()
138  ->getMock();
139 
140  $response->expects($this->once())
141  ->method('withHeader')
142  ->with($expectedHeader, $expectedPath)
143  ->willReturnSelf();
144 
145  $this->httpServiceMock->expects($this->once())
146  ->method('response')
147  ->willReturn($response);
148 
149  $this->httpServiceMock->expects($this->once())
150  ->method('saveResponse')
151  ->with($response);
152 
153  $this->httpServiceMock->expects($this->once())
154  ->method('sendResponse');
155 
156  $xAccel = new XAccel($this->httpServiceMock);
157  $xAccel->deliver($path, false);
158  }
159 }
$response
Definition: xapitoken.php:93
$path
Definition: ltiservices.php:32