ILIAS  release_7 Revision v7.30-3-g800a261c036
XAccelTest.php
Go to the documentation of this file.
1<?php
9
10require_once('./libs/composer/vendor/autoload.php');
11
14use Mockery;
15use PHPUnit\Framework\TestCase;
16use Psr\Http\Message\ResponseInterface;
17
28class XAccelTest extends TestCase
29{
30 use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
31
36
37
38 protected function setUp() : void
39 {
40 parent::setUp();
41
42 $this->httpServiceMock = Mockery::mock(GlobalHttpState::class);
43 $this->httpServiceMock->shouldIgnoreMissing();
44
45 //set remote address to localhost
46 // $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
47
48 require_once './Services/FileDelivery/classes/FileDeliveryTypes/XAccel.php';
49 }
50
51
56 {
57 $expectedContentValue = '';
58
59 $response = Mockery::mock(ResponseInterface::class);
60 $response->shouldIgnoreMissing()->shouldReceive("withHeader")->times(1)
61 ->withArgs([ ResponseHeader::CONTENT_TYPE, $expectedContentValue ])
62 ->andReturnSelf();
63
64 $this->httpServiceMock->shouldReceive("response")->times(1)->withNoArgs()
65 ->andReturn($response)->getMock()->shouldReceive("saveResponse")
66 ->times(1)->withArgs([ $response ]);
67
68 $xAccel = new XAccel($this->httpServiceMock);
69 $result = $xAccel->prepare("this path is never used in this method");
70
71 $this->assertTrue($result);
72 }
73
74
79 {
80 $expectedHeader = 'X-Accel-Redirect';
81 $path = './normal/path';
82
83 $response = Mockery::mock(ResponseInterface::class);
84 $response->shouldIgnoreMissing()->shouldReceive("withHeader")->times(1)
85 ->withArgs([ $expectedHeader, $path ])->andReturnSelf();
86
87 $this->httpServiceMock->shouldReceive("response")->times(1)->withNoArgs()
88 ->andReturn($response)->getMock()->shouldReceive("saveResponse")
89 ->times(1)->withArgs([ $response ])->getMock()
90 ->shouldReceive("sendResponse")->times(1)->withNoArgs();
91
92 $xAccel = new XAccel($this->httpServiceMock);
93 $xAccel->deliver($path, false);
94 }
95
96
101 {
102 $expectedHeader = 'X-Accel-Redirect';
103 $path = './data/path/to/what/ever';
104 $expectedPath = '/secured-data/path/to/what/ever';
105
106 $response = Mockery::mock(ResponseInterface::class);
107 $response->shouldIgnoreMissing()->shouldReceive("withHeader")->times(1)
108 ->withArgs([ $expectedHeader, $expectedPath ])->andReturnSelf();
109
110 $this->httpServiceMock->shouldReceive("response")->times(1)->withNoArgs()
111 ->andReturn($response)->getMock()->shouldReceive("saveResponse")
112 ->times(1)->withArgs([ $response ])->getMock()
113 ->shouldReceive("sendResponse")->times(1)->withNoArgs();
114
115 $xAccel = new XAccel($this->httpServiceMock);
116 $xAccel->deliver($path, false);
117 }
118}
$result
An exception for terminatinating execution or to throw for unit testing.
Interface GlobalHttpState.
Interface ResponseHeader.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$response