2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2023-01-10 22:44:09 +00:00
|
|
|
|
|
|
|
namespace Shimmie2;
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class SetupTest extends ShimmiePHPUnitTestCase
|
|
|
|
{
|
2024-08-31 23:12:27 +00:00
|
|
|
public function testParseSettings(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
[
|
|
|
|
"mynull" => null,
|
|
|
|
"mystring" => "hello world!",
|
|
|
|
"myint" => 42 * 1024,
|
|
|
|
"mybool_true" => true,
|
|
|
|
"mybool_false" => false,
|
|
|
|
"myarray" => ["hello", "world"],
|
|
|
|
],
|
|
|
|
ConfigSaveEvent::postToSettings([
|
|
|
|
// keys in POST that don't start with _type or _config are ignored
|
|
|
|
"some_post" => "value",
|
|
|
|
// _type with no _config means the value is null
|
|
|
|
"_type_mynull" => "string",
|
|
|
|
// strings left as-is
|
|
|
|
"_type_mystring" => "string",
|
|
|
|
"_config_mystring" => "hello world!",
|
|
|
|
// ints parsed from human-readable form
|
|
|
|
"_type_myint" => "int",
|
|
|
|
"_config_myint" => "42KB",
|
|
|
|
// HTML booleans (HTML checkboxes are "on" or undefined, there is no "off")
|
|
|
|
"_type_mybool_true" => "bool",
|
|
|
|
"_config_mybool_true" => "on",
|
|
|
|
"_type_mybool_false" => "bool",
|
|
|
|
// Arrays are... passed as arrays? Does this work?
|
|
|
|
"_type_myarray" => "array",
|
|
|
|
"_config_myarray" => ["hello", "world"],
|
|
|
|
])
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertException(InvalidInput::class, function () {
|
|
|
|
ConfigSaveEvent::postToSettings([
|
|
|
|
"_type_myint" => "cake",
|
|
|
|
"_config_myint" => "tasty",
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|
2024-01-15 14:31:51 +00:00
|
|
|
public function testNiceUrlsTest(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
# XXX: this only checks that the text is "ok", to check
|
|
|
|
# for a bug where it was coming out as "\nok"; it doesn't
|
|
|
|
# check that niceurls actually work
|
|
|
|
$this->get_page('nicetest');
|
|
|
|
$this->assert_content("ok");
|
|
|
|
$this->assert_no_content("\n");
|
|
|
|
}
|
2009-10-09 11:27:13 +00:00
|
|
|
|
2024-02-11 23:28:48 +00:00
|
|
|
public function testNiceDebug(): void
|
|
|
|
{
|
|
|
|
// the automatic testing for shimmie2-examples depends on this
|
|
|
|
$page = $this->get_page('nicedebug/foo%2Fbar/1');
|
|
|
|
$this->assertEquals('{"args":["nicedebug","foo%2Fbar","1"]}', $page->data);
|
|
|
|
}
|
|
|
|
|
2024-01-15 14:31:51 +00:00
|
|
|
public function testAuthAnon(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2024-02-11 15:47:40 +00:00
|
|
|
$this->assertException(PermissionDenied::class, function () {
|
2024-02-10 23:03:14 +00:00
|
|
|
$this->get_page('setup');
|
|
|
|
});
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2015-09-20 19:44:34 +00:00
|
|
|
|
2024-01-15 14:31:51 +00:00
|
|
|
public function testAuthUser(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
$this->log_in_as_user();
|
2024-02-11 15:47:40 +00:00
|
|
|
$this->assertException(PermissionDenied::class, function () {
|
2024-02-10 23:03:14 +00:00
|
|
|
$this->get_page('setup');
|
|
|
|
});
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2008-10-18 06:40:12 +00:00
|
|
|
|
2024-01-15 14:31:51 +00:00
|
|
|
public function testAuthAdmin(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
$this->log_in_as_admin();
|
|
|
|
$this->get_page('setup');
|
|
|
|
$this->assert_title("Shimmie Setup");
|
|
|
|
$this->assert_text("General");
|
|
|
|
}
|
2009-09-27 14:48:38 +00:00
|
|
|
|
2024-01-15 14:31:51 +00:00
|
|
|
public function testAdvanced(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
$this->log_in_as_admin();
|
|
|
|
$this->get_page('setup/advanced');
|
|
|
|
$this->assert_title("Shimmie Setup");
|
2019-06-18 18:45:59 +00:00
|
|
|
$this->assert_text(ImageConfig::THUMB_QUALITY);
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2008-10-18 06:40:12 +00:00
|
|
|
}
|