2009-07-19 03:48:25 +00:00
|
|
|
<?php
|
2015-09-20 21:40:04 +00:00
|
|
|
class ResLimitTest extends ShimmiePHPUnitTestCase {
|
2015-09-26 10:17:13 +00:00
|
|
|
public function testResLimitOK() {
|
2015-09-20 21:40:04 +00:00
|
|
|
global $config;
|
|
|
|
$config->set_int("upload_min_height", 0);
|
|
|
|
$config->set_int("upload_min_width", 0);
|
|
|
|
$config->set_int("upload_max_height", 2000);
|
|
|
|
$config->set_int("upload_max_width", 2000);
|
|
|
|
$config->set_string("upload_ratios", "4:3 16:9");
|
2009-07-19 03:48:25 +00:00
|
|
|
|
|
|
|
$this->log_in_as_user();
|
2015-09-20 21:40:04 +00:00
|
|
|
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
|
|
|
|
//$this->assert_response(302);
|
2009-08-19 00:28:48 +00:00
|
|
|
$this->assert_no_text("Image too large");
|
|
|
|
$this->assert_no_text("Image too small");
|
|
|
|
$this->assert_no_text("ratio");
|
2009-07-19 03:48:25 +00:00
|
|
|
}
|
|
|
|
|
2015-09-26 10:17:13 +00:00
|
|
|
public function testResLimitSmall() {
|
2015-09-20 21:40:04 +00:00
|
|
|
global $config;
|
|
|
|
$config->set_int("upload_min_height", 900);
|
|
|
|
$config->set_int("upload_min_width", 900);
|
|
|
|
$config->set_int("upload_max_height", -1);
|
|
|
|
$config->set_int("upload_max_width", -1);
|
|
|
|
$config->set_string("upload_ratios", "4:3 16:9");
|
2009-07-19 03:48:25 +00:00
|
|
|
|
|
|
|
$this->log_in_as_user();
|
2015-09-20 21:40:04 +00:00
|
|
|
try {
|
|
|
|
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
|
|
|
|
}
|
|
|
|
catch(UploadException $e) {
|
|
|
|
$this->assertEquals("Image too small", $e->getMessage());
|
|
|
|
}
|
2009-07-19 03:48:25 +00:00
|
|
|
}
|
|
|
|
|
2015-09-26 10:17:13 +00:00
|
|
|
public function testResLimitLarge() {
|
2015-09-20 21:40:04 +00:00
|
|
|
global $config;
|
|
|
|
$config->set_int("upload_min_height", 0);
|
|
|
|
$config->set_int("upload_min_width", 0);
|
|
|
|
$config->set_int("upload_max_height", 100);
|
|
|
|
$config->set_int("upload_max_width", 100);
|
|
|
|
$config->set_string("upload_ratios", "4:3 16:9");
|
2009-07-19 03:48:25 +00:00
|
|
|
|
2015-09-20 21:40:04 +00:00
|
|
|
try {
|
|
|
|
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
|
|
|
|
}
|
|
|
|
catch(UploadException $e) {
|
|
|
|
$this->assertEquals("Image too large", $e->getMessage());
|
|
|
|
}
|
2009-07-19 03:48:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-09-26 10:17:13 +00:00
|
|
|
public function testResLimitRatio() {
|
2015-09-20 21:40:04 +00:00
|
|
|
global $config;
|
|
|
|
$config->set_int("upload_min_height", -1);
|
|
|
|
$config->set_int("upload_min_width", -1);
|
|
|
|
$config->set_int("upload_max_height", -1);
|
|
|
|
$config->set_int("upload_max_width", -1);
|
|
|
|
$config->set_string("upload_ratios", "16:9");
|
2009-07-19 03:48:25 +00:00
|
|
|
|
2015-09-20 21:40:04 +00:00
|
|
|
try {
|
|
|
|
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
|
|
|
|
}
|
|
|
|
catch(UploadException $e) {
|
|
|
|
$this->assertEquals("Image needs to be in one of these ratios: 16:9", $e->getMessage());
|
|
|
|
}
|
2009-07-19 03:48:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# reset to defaults, otherwise this can interfere with
|
|
|
|
# other extensions' test suites
|
|
|
|
public function tearDown() {
|
2015-09-20 21:40:04 +00:00
|
|
|
parent::tearDown();
|
2015-09-20 22:10:33 +00:00
|
|
|
|
2015-09-20 21:40:04 +00:00
|
|
|
global $config;
|
|
|
|
$config->set_int("upload_min_height", -1);
|
|
|
|
$config->set_int("upload_min_width", -1);
|
|
|
|
$config->set_int("upload_max_height", -1);
|
|
|
|
$config->set_int("upload_max_width", -1);
|
|
|
|
$config->set_string("upload_ratios", "");
|
2009-07-19 03:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-26 02:54:51 +00:00
|
|
|
|