format
This commit is contained in:
parent
e8a72b0291
commit
6d3ca01424
23 changed files with 95 additions and 55 deletions
|
@ -260,9 +260,10 @@ class BasePage
|
|||
* Find a block which contains the given text
|
||||
* (Useful for unit tests)
|
||||
*/
|
||||
public function find_block(string $text): ?Block {
|
||||
foreach($this->blocks as $block) {
|
||||
if($block->header == $text) {
|
||||
public function find_block(string $text): ?Block
|
||||
{
|
||||
foreach ($this->blocks as $block) {
|
||||
if ($block->header == $text) {
|
||||
return $block;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,8 @@ class Database
|
|||
*/
|
||||
public $query_count = 0;
|
||||
|
||||
public function __construct(string $dsn) {
|
||||
public function __construct(string $dsn)
|
||||
{
|
||||
$this->dsn = $dsn;
|
||||
}
|
||||
|
||||
|
|
|
@ -228,7 +228,7 @@ class CommandEvent extends Event
|
|||
}
|
||||
}
|
||||
|
||||
if(!defined("CLI_LOG_LEVEL")) {
|
||||
if (!defined("CLI_LOG_LEVEL")) {
|
||||
define("CLI_LOG_LEVEL", $log_level);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@ require_once "core/block.php";
|
|||
|
||||
class BlockTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function test_basic() {
|
||||
public function test_basic()
|
||||
{
|
||||
$b = new Block("head", "body");
|
||||
$this->assertEquals(
|
||||
"<section id='headmain'><h3 data-toggle-sel='#headmain' class=''>head</h3><div class='blockbody'>body</div></section>\n",
|
||||
|
|
|
@ -97,14 +97,16 @@ class PolyfillsTest extends \PHPUnit\Framework\TestCase
|
|||
$this->assertEquals(parse_shorthand_int("1231231231"), 1231231231);
|
||||
}
|
||||
|
||||
public function test_autodate() {
|
||||
public function test_autodate()
|
||||
{
|
||||
$this->assertEquals(
|
||||
"<time datetime='2012-06-23T16:14:22+00:00'>June 23, 2012; 16:14</time>",
|
||||
autodate("2012-06-23 16:14:22")
|
||||
);
|
||||
}
|
||||
|
||||
public function test_validate_input() {
|
||||
public function test_validate_input()
|
||||
{
|
||||
$_POST = [
|
||||
"foo" => " bar ",
|
||||
"to_null" => " ",
|
||||
|
@ -195,7 +197,8 @@ class PolyfillsTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function test_stringer() {
|
||||
public function test_stringer()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'["foo"=>"bar", "baz"=>[1, 2, 3], "qux"=>["a"=>"b"]]',
|
||||
stringer(["foo"=>"bar", "baz"=>[1,2,3], "qux"=>["a"=>"b"]])
|
||||
|
|
|
@ -468,7 +468,8 @@ function get_debug_info(): string
|
|||
|
||||
/** @privatesection */
|
||||
|
||||
function require_all(array $files): void {
|
||||
function require_all(array $files): void
|
||||
{
|
||||
foreach ($files as $filename) {
|
||||
if (basename($filename)[0] != "_") {
|
||||
require_once $filename;
|
||||
|
@ -476,7 +477,8 @@ function require_all(array $files): void {
|
|||
}
|
||||
}
|
||||
|
||||
function _load_core_files() {
|
||||
function _load_core_files()
|
||||
{
|
||||
require_all(array_merge(
|
||||
zglob("core/*.php"),
|
||||
zglob("core/imageboard/*.php"),
|
||||
|
@ -484,7 +486,8 @@ function _load_core_files() {
|
|||
));
|
||||
}
|
||||
|
||||
function _load_theme_files() {
|
||||
function _load_theme_files()
|
||||
{
|
||||
require_all(_get_themelet_files(get_theme()));
|
||||
}
|
||||
|
||||
|
|
|
@ -39,10 +39,12 @@ class AddAliasEvent extends Event
|
|||
}
|
||||
}
|
||||
|
||||
class DeleteAliasEvent extends Event {
|
||||
class DeleteAliasEvent extends Event
|
||||
{
|
||||
public $oldtag;
|
||||
|
||||
public function __construct(string $oldtag) {
|
||||
public function __construct(string $oldtag)
|
||||
{
|
||||
$this->oldtag = $oldtag;
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +144,8 @@ class AliasEditor extends Extension
|
|||
log_info("alias_editor", "Added alias for {$event->oldtag} -> {$event->newtag}", "Added alias");
|
||||
}
|
||||
|
||||
public function onDeleteAlias(DeleteAliasEvent $event) {
|
||||
public function onDeleteAlias(DeleteAliasEvent $event)
|
||||
{
|
||||
global $database;
|
||||
$database->execute("DELETE FROM aliases WHERE oldtag=:oldtag", ["oldtag" => $event->oldtag]);
|
||||
log_info("alias_editor", "Deleted alias for {$event->oldtag}", "Deleted alias");
|
||||
|
|
|
@ -21,7 +21,8 @@ class AliasEditorTest extends ShimmiePHPUnitTestCase
|
|||
$this->assert_no_text("Add");
|
||||
}
|
||||
|
||||
public function testAliasOneToOne() {
|
||||
public function testAliasOneToOne()
|
||||
{
|
||||
$this->log_in_as_admin();
|
||||
|
||||
$this->get_page("alias/export/aliases.csv");
|
||||
|
@ -48,7 +49,8 @@ class AliasEditorTest extends ShimmiePHPUnitTestCase
|
|||
$this->assert_no_text("test1");
|
||||
}
|
||||
|
||||
public function testAliasOneToMany() {
|
||||
public function testAliasOneToMany()
|
||||
{
|
||||
$this->log_in_as_admin();
|
||||
|
||||
$this->get_page("alias/export/aliases.csv");
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
class AutoCompleteTest extends ShimmiePHPUnitTestCase {
|
||||
public function testAuth() {
|
||||
class AutoCompleteTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testAuth()
|
||||
{
|
||||
send_event(new UserLoginEvent(User::by_name($this->anon_name)));
|
||||
$page = $this->get_page('api/internal/autocomplete', ["s"=>"not-a-tag"]);
|
||||
$this->assertEquals(200, $page->code);
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
class BulkAddTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testInvalidDir() {
|
||||
public function testInvalidDir()
|
||||
{
|
||||
send_event(new UserLoginEvent(User::by_name($this->admin_name)));
|
||||
$bae = send_event(new BulkAddEvent('asdf'));
|
||||
$this->assertContains(
|
||||
|
@ -12,7 +13,8 @@ class BulkAddTest extends ShimmiePHPUnitTestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testValidDir() {
|
||||
public function testValidDir()
|
||||
{
|
||||
send_event(new UserLoginEvent(User::by_name($this->admin_name)));
|
||||
send_event(new BulkAddEvent('tests'));
|
||||
$page = $this->get_page("post/list/hash=17fc89f372ed3636e28bd25cc7f3bac1/1");
|
||||
|
|
|
@ -23,8 +23,7 @@ class ImageBanTest extends ShimmiePHPUnitTestCase
|
|||
try {
|
||||
$this->post_image("tests/pbx_screenshot.jpg", "pbx");
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
catch(UploadException $e) {
|
||||
} catch (UploadException $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,13 +4,15 @@ class IPBanTest extends ShimmiePHPUnitTestCase
|
|||
{
|
||||
# FIXME: test that the IP is actually banned
|
||||
|
||||
public function testAccess() {
|
||||
public function testAccess()
|
||||
{
|
||||
$page = $this->get_page('ip_ban/list');
|
||||
$this->assertEquals(403, $page->code);
|
||||
$this->assertEquals("Permission Denied", $page->title);
|
||||
}
|
||||
|
||||
public function testIPBan() {
|
||||
public function testIPBan()
|
||||
{
|
||||
global $database;
|
||||
|
||||
$this->log_in_as_admin();
|
||||
|
@ -46,7 +48,8 @@ class IPBanTest extends ShimmiePHPUnitTestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function test_all() {
|
||||
public function test_all()
|
||||
{
|
||||
$this->log_in_as_admin();
|
||||
$this->get_page('ip_ban/list?r_all=on'); // just test it doesn't crash for now
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php declare(strict_types=1);
|
||||
class PoolsTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testAnon() {
|
||||
public function testAnon()
|
||||
{
|
||||
$this->get_page('pool/list');
|
||||
$this->assert_title("Pools");
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class RandomImage extends Extension
|
|||
throw new SCoreException("Error: too many arguments.");
|
||||
}
|
||||
$image = Image::by_random($search_terms);
|
||||
if(!$image) {
|
||||
if (!$image) {
|
||||
throw new SCoreException(
|
||||
"Couldn't find any images randomly",
|
||||
Tag::implode($search_terms)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php declare(strict_types=1);
|
||||
use function MicroHTML\{DIV,A,IMG};
|
||||
use function MicroHTML\DIV;
|
||||
use function MicroHTML\A;
|
||||
use function MicroHTML\IMG;
|
||||
|
||||
class RandomImageTheme extends Themelet
|
||||
{
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php declare(strict_types=1);
|
||||
class TagEditTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testValidChange() {
|
||||
public function testValidChange()
|
||||
{
|
||||
$this->log_in_as_user();
|
||||
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
|
||||
$image = Image::by_id($image_id);
|
||||
|
@ -25,8 +26,7 @@ class TagEditTest extends ShimmiePHPUnitTestCase
|
|||
try {
|
||||
send_event(new TagSetEvent($image, []));
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
catch(SCoreException $e) {
|
||||
} catch (SCoreException $e) {
|
||||
$this->assertEquals("Tried to set zero tags", $e->error);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
class CreateTipEvent extends Event {
|
||||
class CreateTipEvent extends Event
|
||||
{
|
||||
public $enable;
|
||||
public $image;
|
||||
public $text;
|
||||
public function __construct(bool $enable, string $image, string $text) {
|
||||
public function __construct(bool $enable, string $image, string $text)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->enable = $enable;
|
||||
$this->image = $image;
|
||||
|
@ -12,9 +14,11 @@ class CreateTipEvent extends Event {
|
|||
}
|
||||
}
|
||||
|
||||
class DeleteTipEvent extends Event {
|
||||
class DeleteTipEvent extends Event
|
||||
{
|
||||
public $tip_id;
|
||||
public function __construct(int $tip_id) {
|
||||
public function __construct(int $tip_id)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->tip_id = $tip_id;
|
||||
}
|
||||
|
@ -121,7 +125,8 @@ class Tips extends Extension
|
|||
$this->theme->manageTips($url, $images);
|
||||
}
|
||||
|
||||
public function onCreateTip(CreateTipEvent $event) {
|
||||
public function onCreateTip(CreateTipEvent $event)
|
||||
{
|
||||
global $database;
|
||||
$database->execute(
|
||||
"
|
||||
|
@ -176,7 +181,8 @@ class Tips extends Extension
|
|||
$database->execute("UPDATE tips SET enable = :enable WHERE id = :id", ["enable"=>$enable, "id"=>$tipID]);
|
||||
}
|
||||
|
||||
public function onDeleteTip(DeleteTipEvent $event) {
|
||||
public function onDeleteTip(DeleteTipEvent $event)
|
||||
{
|
||||
global $database;
|
||||
$database->execute("DELETE FROM tips WHERE id = :id", ["id"=>$event->tip_id]);
|
||||
}
|
||||
|
|
|
@ -42,8 +42,7 @@ class UploadTest extends ShimmiePHPUnitTestCase
|
|||
try {
|
||||
$this->post_image("data/huge.jpg", "test");
|
||||
$this->assertTrue(false, "Uploading huge.jpg didn't fail...");
|
||||
}
|
||||
catch (UploadException $e) {
|
||||
} catch (UploadException $e) {
|
||||
$this->assertEquals("File too large (3.0MB > 1.0MB)", $e->error);
|
||||
}
|
||||
unlink("data/huge.jpg");
|
||||
|
|
|
@ -15,21 +15,25 @@ class WikiUpdateEvent extends Event
|
|||
}
|
||||
}
|
||||
|
||||
class WikiDeleteRevisionEvent extends Event {
|
||||
class WikiDeleteRevisionEvent extends Event
|
||||
{
|
||||
public $title;
|
||||
public $revision;
|
||||
|
||||
public function __construct($title, $revision) {
|
||||
public function __construct($title, $revision)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->title = $title;
|
||||
$this->revision = $revision;
|
||||
}
|
||||
}
|
||||
|
||||
class WikiDeletePageEvent extends Event {
|
||||
class WikiDeletePageEvent extends Event
|
||||
{
|
||||
public $title;
|
||||
|
||||
public function __construct($title) {
|
||||
public function __construct($title)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->title = $title;
|
||||
}
|
||||
|
@ -216,7 +220,8 @@ class Wiki extends Extension
|
|||
}
|
||||
}
|
||||
|
||||
public function onWikiDeleteRevision(WikiDeleteRevisionEvent $event) {
|
||||
public function onWikiDeleteRevision(WikiDeleteRevisionEvent $event)
|
||||
{
|
||||
global $database;
|
||||
$database->Execute(
|
||||
"DELETE FROM wiki_pages WHERE title=:title AND revision=:rev",
|
||||
|
@ -224,7 +229,8 @@ class Wiki extends Extension
|
|||
);
|
||||
}
|
||||
|
||||
public function onWikiDeletePage(WikiDeletePageEvent $event) {
|
||||
public function onWikiDeletePage(WikiDeletePageEvent $event)
|
||||
{
|
||||
global $database;
|
||||
$database->Execute(
|
||||
"DELETE FROM wiki_pages WHERE title=:title",
|
||||
|
|
|
@ -7,7 +7,9 @@ require_once "core/polyfills.php";
|
|||
require_once "core/util.php";
|
||||
|
||||
$_SERVER['QUERY_STRING'] = '/';
|
||||
if(file_exists("tests/trace.json")) unlink("tests/trace.json");
|
||||
if (file_exists("tests/trace.json")) {
|
||||
unlink("tests/trace.json");
|
||||
}
|
||||
|
||||
global $cache, $config, $database, $user, $page, $_tracer;
|
||||
_sanitise_environment();
|
||||
|
@ -146,7 +148,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase
|
|||
protected function page_to_text(string $section=null)
|
||||
{
|
||||
global $page;
|
||||
if($page->mode == PageMode::PAGE) {
|
||||
if ($page->mode == PageMode::PAGE) {
|
||||
$text = $page->title . "\n";
|
||||
foreach ($page->blocks as $block) {
|
||||
if (is_null($section) || $section == $block->section) {
|
||||
|
@ -155,11 +157,9 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
elseif($page->mode == PageMode::DATA) {
|
||||
} elseif ($page->mode == PageMode::DATA) {
|
||||
return $page->data;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->assertTrue(false, "Page mode is not PAGE or DATA");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
<?php declare(strict_types=1);
|
||||
class Page extends BasePage {}
|
||||
class Page extends BasePage
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
<?php declare(strict_types=1);
|
||||
class Page extends BasePage {}
|
||||
class Page extends BasePage
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
<?php declare(strict_types=1);
|
||||
class Page extends BasePage {}
|
||||
class Page extends BasePage
|
||||
{
|
||||
}
|
||||
|
|
Reference in a new issue