2020-01-26 13:19:35 +00:00
|
|
|
<?php declare(strict_types=1);
|
2019-05-28 16:59:38 +00:00
|
|
|
class UploadTest extends ShimmiePHPUnitTestCase
|
|
|
|
{
|
|
|
|
public function testUploadPage()
|
|
|
|
{
|
|
|
|
$this->log_in_as_user();
|
|
|
|
|
|
|
|
$this->get_page("upload");
|
|
|
|
$this->assert_title("Upload");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpload()
|
|
|
|
{
|
|
|
|
$this->log_in_as_user();
|
2020-01-29 20:22:50 +00:00
|
|
|
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
|
|
|
|
$this->assertGreaterThan(0, $image_id);
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRejectDupe()
|
|
|
|
{
|
|
|
|
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
|
|
|
|
} catch (UploadException $e) {
|
2019-11-21 17:16:11 +00:00
|
|
|
$this->assertStringContainsString("already has hash", $e->getMessage());
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRejectUnknownFiletype()
|
|
|
|
{
|
2020-01-29 20:22:50 +00:00
|
|
|
$image_id = $this->post_image("index.php", "test");
|
|
|
|
$this->assertEquals(-1, $image_id); // no file handler claimed this
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRejectHuge()
|
|
|
|
{
|
|
|
|
// FIXME: huge.dat is rejected for other reasons; manual testing shows that this works
|
2020-01-28 21:19:59 +00:00
|
|
|
file_put_contents("data/huge.jpg", file_get_contents("tests/pbx_screenshot.jpg") . str_repeat("U", 1024*1024*3));
|
|
|
|
try {
|
|
|
|
$this->post_image("data/huge.jpg", "test");
|
|
|
|
$this->assertTrue(false, "Uploading huge.jpg didn't fail...");
|
2020-01-29 00:49:21 +00:00
|
|
|
} catch (UploadException $e) {
|
2020-01-28 21:19:59 +00:00
|
|
|
$this->assertEquals("File too large (3.0MB > 1.0MB)", $e->error);
|
|
|
|
}
|
|
|
|
unlink("data/huge.jpg");
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2009-07-15 01:42:18 +00:00
|
|
|
}
|