ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
XSendfileTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5 require_once('./libs/composer/vendor/autoload.php');
6 
9 use Mockery;
12 
23 class XSendfileTest extends TestCase
24 {
26 
31 
32 
36  protected function setUp()
37  {
38  parent::setUp();
39 
40  $this->httpServiceMock = Mockery::mock(HTTPServices::class);
41  $this->httpServiceMock->shouldIgnoreMissing();
42 
43  //set remote address to localhost
44  //$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
45 
46  require_once './Services/FileDelivery/classes/FileDeliveryTypes/XSendfile.php';
47  }
48 
49 
54  {
55  $expectedHeader = 'X-Sendfile';
56  $filePath = __FILE__;
57 
58  $response = Mockery::mock(ResponseInterface::class);
59  $response->shouldIgnoreMissing()->shouldReceive("withHeader")->times(1)
60  ->withArgs([ $expectedHeader, $filePath ])->andReturnSelf();
61 
62  $this->httpServiceMock->shouldReceive("response")->times(1)->withNoArgs()
63  ->andReturn($response)->getMock()->shouldReceive("saveResponse")
64  ->times(1)->withArgs([ $response ])->getMock()
65  ->shouldReceive("sendResponse")->times(1)->withNoArgs();
66 
67  $fileDeliveryType = new XSendfile($this->httpServiceMock);
68  $fileDeliveryOk = $fileDeliveryType->deliver($filePath, false);
69 
70  $this->assertTrue($fileDeliveryOk);
71  }
72 }
$response