outputdl : allow to download a file from filesystem, and manage the partial download if the browser request it
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5374 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
200
Tests/outputdlTest.php
Normal file
200
Tests/outputdlTest.php
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
*/
|
||||
|
||||
/** Test the outputdl.php file */
|
||||
class test_outputdl extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_outputdl_init ()
|
||||
{
|
||||
exec ("rm -f /tmp/testDFWoutputDL*");
|
||||
file_put_contents ("/tmp/testDFWoutputDL",
|
||||
str_repeat (
|
||||
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
|
||||
1000)
|
||||
);
|
||||
symlink ("/etc/passwd", "/tmp/testDFWoutputDL2");
|
||||
symlink ("/tmp/testDFWoutputDL", "/tmp/testDFWoutputDL3");
|
||||
}
|
||||
|
||||
public function test_outputdl_1 ()
|
||||
{
|
||||
// Check the full download content
|
||||
$outputdl = new outputdl ();
|
||||
$this->expectOutputString (str_repeat (
|
||||
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
|
||||
1000));
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
|
||||
}
|
||||
|
||||
public function test_outputdl_Announce_1 ()
|
||||
{
|
||||
// Check the announce of Resume mode Enabled
|
||||
$outputdl = new outputdl ();
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
|
||||
$res = $outputdl->headers ();
|
||||
$this->assertSame (in_array ("Accept-Ranges: bytes", $res), true);
|
||||
}
|
||||
|
||||
public function test_outputdl_Announce_2 ()
|
||||
{
|
||||
// Check the announce of Resume mode Disabled
|
||||
$outputdl = new outputdl ();
|
||||
$outputdl->resumeAllow (false);
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
|
||||
$res = $outputdl->headers ();
|
||||
$this->assertSame (in_array ("Accept-Ranges: none", $res), true);
|
||||
}
|
||||
|
||||
public function test_outputdl_Partial_1 ()
|
||||
{
|
||||
// Check the content get with provided range
|
||||
$outputdl = new outputdl ();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=3-9";
|
||||
$this->expectOutputString ("4567890");
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
|
||||
unset ($_SERVER["HTTP_RANGE"]);
|
||||
}
|
||||
|
||||
public function test_outputdl_Partial_2 ()
|
||||
{
|
||||
// Check the content get with provided range
|
||||
$outputdl = new outputdl ();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=3-";
|
||||
$this->expectOutputString (substr (str_repeat (
|
||||
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
|
||||
1000), 3));
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
|
||||
unset ($_SERVER["HTTP_RANGE"]);
|
||||
}
|
||||
|
||||
public function test_outputdl_Partial_3 ()
|
||||
{
|
||||
// Check the content get with provided range
|
||||
$outputdl = new outputdl ();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=0-";
|
||||
$this->expectOutputString (str_repeat (
|
||||
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
|
||||
1000));
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
|
||||
unset ($_SERVER["HTTP_RANGE"]);
|
||||
}
|
||||
|
||||
public function test_outputdl_Partial_4 ()
|
||||
{
|
||||
// Check the content get with provided range
|
||||
$outputdl = new outputdl ();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=-5";
|
||||
$this->expectOutputString ("wxyz\n");
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
|
||||
unset ($_SERVER["HTTP_RANGE"]);
|
||||
}
|
||||
|
||||
public function test_outputdl_Partial_5 ()
|
||||
{
|
||||
// Check the content get with provided range
|
||||
$outputdl = new outputdl ();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=0-3,6-9";
|
||||
$this->expectOutputString ("--Qm91bmRhcnk=\r
|
||||
Content-Range: bytes 0-3/63000\r
|
||||
Content-Type: application/octet-stream\r
|
||||
\r
|
||||
1234\r
|
||||
--Qm91bmRhcnk=\r
|
||||
Content-Range: bytes 6-9/63000\r
|
||||
Content-Type: application/octet-stream\r
|
||||
\r
|
||||
7890\r
|
||||
--Qm91bmRhcnk=--\r
|
||||
");
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
|
||||
unset ($_SERVER["HTTP_RANGE"]);
|
||||
}
|
||||
|
||||
public function test_outputdl_PartialWrong_1 ()
|
||||
{
|
||||
// Check the invalid provided range
|
||||
unset ($_SERVER["HTTP_RANGE"]);
|
||||
$outputdl = new outputdl ();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=99999-";
|
||||
$this->expectException ("Exception", "Invalid range provided", 416);
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
|
||||
}
|
||||
|
||||
public function test_outputdl_PartialWrong_2 ()
|
||||
{
|
||||
// Check the invalid provided range
|
||||
unset ($_SERVER["HTTP_RANGE"]);
|
||||
$outputdl = new outputdl ();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=9-3";
|
||||
$this->expectException ("Exception", "Invalid range provided", 416);
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
|
||||
}
|
||||
|
||||
public function test_outputdl_PartialWrong_3 ()
|
||||
{
|
||||
// Check the invalid provided range
|
||||
unset ($_SERVER["HTTP_RANGE"]);
|
||||
$outputdl = new outputdl ();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=9-999999";
|
||||
$this->expectException ("Exception", "Invalid range provided", 416);
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
|
||||
}
|
||||
|
||||
public function test_outputdl_PartialWrong_4 ()
|
||||
{
|
||||
// Check the invalid provided range
|
||||
unset ($_SERVER["HTTP_RANGE"]);
|
||||
$outputdl = new outputdl ();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=-";
|
||||
$this->expectException ("Exception", "Invalid range provided", 416);
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
|
||||
}
|
||||
|
||||
public function test_outputdl_invalidBase_1 ()
|
||||
{
|
||||
// Check the base comparison : OK
|
||||
unset ($_SERVER["HTTP_RANGE"]);
|
||||
$outputdl = new outputdl ();
|
||||
$outputdl->base ("/tmp");
|
||||
$this->expectOutputString (str_repeat (
|
||||
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
|
||||
1000));
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
|
||||
}
|
||||
|
||||
public function test_outputdl_invalidBase_2 ()
|
||||
{
|
||||
// Check the base comparison : BAD
|
||||
unset ($_SERVER["HTTP_RANGE"]);
|
||||
$outputdl = new outputdl ();
|
||||
$outputdl->base ("/tmp");
|
||||
$this->expectException ("Exception",
|
||||
"Invalid file to download : out of base", 406);
|
||||
$outputdl->downloadFile ("../../../../../..//etc/passwd");
|
||||
}
|
||||
|
||||
public function test_outputdl_invalidFile_1 ()
|
||||
{
|
||||
// Check the base comparison : BAD Symlink
|
||||
unset ($_SERVER["HTTP_RANGE"]);
|
||||
$outputdl = new outputdl ();
|
||||
$outputdl->base ("/tmp");
|
||||
$this->expectException ("Exception",
|
||||
"Invalid file to download : not a file", 406);
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputDL3");
|
||||
}
|
||||
|
||||
public function test_outputdl_invalidFile_2 ()
|
||||
{
|
||||
// Check the base comparison : Non existing
|
||||
unset ($_SERVER["HTTP_RANGE"]);
|
||||
$outputdl = new outputdl ();
|
||||
$outputdl->base ("/tmp");
|
||||
$this->expectException ("Exception",
|
||||
"Invalid file to download : file doesn't exists", 404);
|
||||
$outputdl->downloadFile ("/tmp/testDFWoutputNON");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user