ILIAS  release_8 Revision v8.24
XAccelTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
11
14use Mockery;
15use PHPUnit\Framework\TestCase;
16use Psr\Http\Message\ResponseInterface;
17
18/******************************************************************************
19 *
20 * This file is part of ILIAS, a powerful learning management system.
21 *
22 * ILIAS is licensed with the GPL-3.0, you should have received a copy
23 * of said license along with the source code.
24 *
25 * If this is not the case or you just want to try ILIAS, you'll find
26 * us at:
27 * https://www.ilias.de
28 * https://github.com/ILIAS-eLearning
29 *
30 *****************************************************************************/
31
42class XAccelTest extends TestCase
43{
48
52 protected function setUp(): void
53 {
54 $this->httpServiceMock = $this->getMockBuilder(Services::class)
55 ->disableOriginalConstructor()
56 ->getMock();
57 }
58
62 public function testPrepareWhichShouldSucceed(): void
63 {
64 $expectedContentValue = '';
65
66 $response = $this->getMockBuilder(ResponseInterface::class)
67 ->disableOriginalConstructor()
68 ->getMock();
69
70 $response->expects($this->once())
71 ->method('withHeader')
72 ->with(ResponseHeader::CONTENT_TYPE, $expectedContentValue)
73 ->willReturnSelf();
74
75 $this->httpServiceMock->expects($this->once())
76 ->method('response')
77 ->willReturn($response);
78
79 $this->httpServiceMock->expects($this->once())
80 ->method('saveResponse')
81 ->with($response);
82
83 $this->httpServiceMock->expects($this->never())
84 ->method('sendResponse');
85
86 $xAccel = new XAccel($this->httpServiceMock);
87 $result = $xAccel->prepare("this path is never used in this method");
88
89 $this->assertTrue($result);
90 }
91
96 {
97 $expectedHeader = 'X-Accel-Redirect';
98 $path = './normal/path';
99
100 $response = $this->getMockBuilder(ResponseInterface::class)
101 ->disableOriginalConstructor()
102 ->getMock();
103
104 $response->expects($this->once())
105 ->method('withHeader')
106 ->with($expectedHeader, $path)
107 ->willReturnSelf();
108
109 $this->httpServiceMock->expects($this->once())
110 ->method('response')
111 ->willReturn($response);
112
113 $this->httpServiceMock->expects($this->once())
114 ->method('saveResponse')
115 ->with($response);
116
117 $this->httpServiceMock->expects($this->once())
118 ->method('sendResponse');
119
120
121 $xAccel = new XAccel($this->httpServiceMock);
122 $xAccel->deliver($path, false);
123 }
124
129 {
130 $expectedHeader = 'X-Accel-Redirect';
131 $path = './data/path/to/what/ever';
132 $expectedPath = '/secured-data/path/to/what/ever';
133
134 $response = $this->getMockBuilder(ResponseInterface::class)
135 ->disableOriginalConstructor()
136 ->getMock();
137
138 $response->expects($this->once())
139 ->method('withHeader')
140 ->with($expectedHeader, $expectedPath)
141 ->willReturnSelf();
142
143 $this->httpServiceMock->expects($this->once())
144 ->method('response')
145 ->willReturn($response);
146
147 $this->httpServiceMock->expects($this->once())
148 ->method('saveResponse')
149 ->with($response);
150
151 $this->httpServiceMock->expects($this->once())
152 ->method('sendResponse');
153
154 $xAccel = new XAccel($this->httpServiceMock);
155 $xAccel->deliver($path, false);
156 }
157}
Class Services.
Definition: Services.php:38
Interface ResponseHeader.
$path
Definition: ltiservices.php:32
$response