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

87 lines
3 KiB
PHP
Raw Normal View History

2020-01-26 13:19:35 +00:00
<?php declare(strict_types=1);
class ResolutionLimitTest extends ShimmiePHPUnitTestCase
{
public function testResLimitOK()
{
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();
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
//$this->assert_response(302);
2020-10-26 15:18:37 +00:00
$this->assert_no_text("Post too large");
$this->assert_no_text("Post too small");
$this->assert_no_text("ratio");
}
2009-07-19 03:48:25 +00:00
public function testResLimitSmall()
{
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();
try {
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
2020-01-29 20:22:50 +00:00
$this->assertTrue(false, "Invalid-size image was allowed");
} catch (UploadException $e) {
2020-10-26 15:18:37 +00:00
$this->assertEquals("Post too small", $e->getMessage());
}
}
2009-07-19 03:48:25 +00:00
public function testResLimitLarge()
{
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
try {
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
2020-01-29 20:22:50 +00:00
$this->assertTrue(false, "Invalid-size image was allowed");
} catch (UploadException $e) {
2020-10-26 15:18:37 +00:00
$this->assertEquals("Post too large", $e->getMessage());
}
}
2009-07-19 03:48:25 +00:00
public function testResLimitRatio()
{
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
try {
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
2020-01-29 20:22:50 +00:00
$this->assertTrue(false, "Invalid-size image was allowed");
} catch (UploadException $e) {
2020-10-26 15:18:37 +00:00
$this->assertEquals("Post 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
2019-11-14 18:24:09 +00:00
public function tearDown(): void
{
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", "");
2020-01-29 20:22:50 +00:00
parent::tearDown();
}
2009-07-19 03:48:25 +00:00
}