ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
XAccelTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
27
28use PHPUnit\Framework\Attributes\BackupGlobals;
29use PHPUnit\Framework\Attributes\BackupStaticProperties;
30use PHPUnit\Framework\Attributes\PreserveGlobalState;
31use PHPUnit\Framework\Attributes\RunInSeparateProcess;
32use PHPUnit\Framework\Attributes\Test;
33use PHPUnit\Framework\MockObject\MockObject;
36use PHPUnit\Framework\TestCase;
37use Psr\Http\Message\ResponseInterface;
39
45#[BackupGlobals(false)]
46#[BackupStaticProperties(false)]
47#[PreserveGlobalState(false)]
48class XAccelTest extends TestCase
49{
54
58 protected function setUp(): void
59 {
60 $this->httpServiceMock = $this->getMockBuilder(Services::class)
61 ->disableOriginalConstructor()
62 ->getMock();
63 }
64
65 #[Test]
66 public function testPrepareWhichShouldSucceed(): void
67 {
68 $expectedContentValue = '';
69
70 $response = $this->getMockBuilder(ResponseInterface::class)
71 ->disableOriginalConstructor()
72 ->getMock();
73
74 $response->expects($this->once())
75 ->method('withHeader')
76 ->with(ResponseHeader::CONTENT_TYPE, $expectedContentValue)
77 ->willReturnSelf();
78
79 $this->httpServiceMock->expects($this->once())
80 ->method('response')
81 ->willReturn($response);
82
83 $this->httpServiceMock->expects($this->once())
84 ->method('saveResponse')
85 ->with($response);
86
87 $this->httpServiceMock->expects($this->never())
88 ->method('sendResponse');
89
90 $xAccel = new XAccel($this->httpServiceMock);
91 $xAccel->prepare("this path is never used in this method", null);
92
93 $this->assertTrue(true);
94 }
95
96 #[Test]
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
127 #[Test]
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:30
$response
Definition: xapitoken.php:93