upload tests

This commit is contained in:
Shish 2015-09-20 20:28:27 +01:00
parent ff8da5be8e
commit 7bfc959547

View File

@ -1,24 +1,38 @@
<?php <?php
class UploadTest { class UploadTest extends ShimmiePHPUnitTestCase {
function testUpload() { function testUploadPage() {
$this->log_in_as_user(); $this->log_in_as_user();
$this->get_page("upload"); $this->get_page("upload");
$this->assert_title("Upload"); $this->assert_title("Upload");
}
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); function testUpload() {
$this->assert_response(302); $this->log_in_as_user();
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
}
$image_id_2 = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); function testRejectDupe() {
$this->assert_response(200); $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
$this->assert_title("Upload Status");
$this->assert_text("already has hash");
$image_id_3 = $this->post_image("index.php", "test"); try {
$this->assert_response(200); $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
$this->assert_title("Upload Status"); }
$this->assert_text("File type not recognised"); catch(UploadException $e) {
$this->assertContains("already has hash", $e->getMessage());
}
}
function testRejectUnknownFiletype() {
try {
$this->post_image("index.php", "test");
}
catch(UploadException $e) {
$this->assertContains("Invalid or corrupted file", $e->getMessage());
}
}
function testRejectHuge() {
/* /*
// FIXME: huge.dat is rejected for other reasons; manual testing shows that this works // FIXME: huge.dat is rejected for other reasons; manual testing shows that this works
file_put_contents("huge.dat", file_get_contents("tests/pbx_screenshot.jpg") . str_repeat("U", 1024*1024*3)); file_put_contents("huge.dat", file_get_contents("tests/pbx_screenshot.jpg") . str_repeat("U", 1024*1024*3));
@ -28,15 +42,6 @@ class UploadTest {
$this->assert_text("File too large"); $this->assert_text("File too large");
unlink("huge.dat"); unlink("huge.dat");
*/ */
$this->log_out();
$this->log_in_as_admin();
$this->delete_image($image_id_1);
$this->delete_image($image_id_2);
$this->delete_image($image_id_3); # if these were successfully rejected,
//$this->delete_image($image_id_4); # then delete_image is a no-op
$this->log_out();
} }
} }