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

86 lines
2.9 KiB
PHP
Raw Normal View History

2021-12-14 18:32:47 +00:00
<?php
declare(strict_types=1);
namespace Shimmie2;
class ResolutionLimitTest extends ShimmiePHPUnitTestCase
{
2024-01-15 14:31:51 +00:00
public function testResLimitOK(): void
{
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
2024-01-15 14:31:51 +00:00
public function testResLimitSmall(): void
{
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();
$e = $this->assertException(UploadException::class, function () {
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
});
$this->assertEquals("Post too small", $e->getMessage());
}
2009-07-19 03:48:25 +00:00
2024-01-15 14:31:51 +00:00
public function testResLimitLarge(): void
{
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
$e = $this->assertException(UploadException::class, function () {
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
});
$this->assertEquals("Post too large", $e->getMessage());
}
2009-07-19 03:48:25 +00:00
2024-01-15 14:31:51 +00:00
public function testResLimitRatio(): 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", "16:9");
2009-07-19 03:48:25 +00:00
$e = $this->assertException(UploadException::class, function () {
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
});
$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
}