This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/res_limit/test.php

84 lines
2.4 KiB
PHP
Raw Normal View History

2009-07-19 03:48:25 +00:00
<?php
2015-09-20 21:40:04 +00:00
class ResLimitTest extends ShimmiePHPUnitTestCase {
2009-07-19 03:48:25 +00:00
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
}
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
}
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
}
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();
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
}
}