|
|
|
@ -1086,11 +1086,13 @@ class EngineTest extends TestCase
|
|
|
|
|
// doing this so we can overwrite some parts of the response
|
|
|
|
|
$engine->getLoader()->register('response', function () {
|
|
|
|
|
return new class extends Response {
|
|
|
|
|
public $headersSent = [];
|
|
|
|
|
public function setRealHeader(
|
|
|
|
|
string $header_string,
|
|
|
|
|
bool $replace = true,
|
|
|
|
|
int $response_code = 0
|
|
|
|
|
): self {
|
|
|
|
|
$this->headersSent[] = $header_string;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -1100,6 +1102,37 @@ class EngineTest extends TestCase
|
|
|
|
|
$streamPath = stream_get_meta_data($tmpfile)['uri'];
|
|
|
|
|
$this->expectOutputString('I am a teapot');
|
|
|
|
|
$engine->download($streamPath);
|
|
|
|
|
$this->assertContains('Content-Disposition: attachment; filename="'.basename($streamPath).'"', $engine->response()->headersSent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDownloadWithDefaultFileName(): void
|
|
|
|
|
{
|
|
|
|
|
$engine = new class extends Engine {
|
|
|
|
|
public function getLoader()
|
|
|
|
|
{
|
|
|
|
|
return $this->loader;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
// doing this so we can overwrite some parts of the response
|
|
|
|
|
$engine->getLoader()->register('response', function () {
|
|
|
|
|
return new class extends Response {
|
|
|
|
|
public $headersSent = [];
|
|
|
|
|
public function setRealHeader(
|
|
|
|
|
string $header_string,
|
|
|
|
|
bool $replace = true,
|
|
|
|
|
int $response_code = 0
|
|
|
|
|
): self {
|
|
|
|
|
$this->headersSent[] = $header_string;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
$tmpfile = tmpfile();
|
|
|
|
|
fwrite($tmpfile, 'I am a teapot');
|
|
|
|
|
$streamPath = stream_get_meta_data($tmpfile)['uri'];
|
|
|
|
|
$this->expectOutputString('I am a teapot');
|
|
|
|
|
$engine->download($streamPath, 'something.txt');
|
|
|
|
|
$this->assertContains('Content-Disposition: attachment; filename="something.txt"', $engine->response()->headersSent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDownloadBadPath() {
|
|
|
|
|