From 6d3ca014245d31e9ac60625916c7a66a6d29ba89 Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 29 Jan 2020 00:49:21 +0000 Subject: [PATCH] format --- core/basepage.php | 7 ++++--- core/database.php | 3 ++- core/event.php | 2 +- core/tests/block.test.php | 3 ++- core/tests/polyfills.test.php | 9 ++++++--- core/util.php | 9 ++++++--- ext/alias_editor/main.php | 9 ++++++--- ext/alias_editor/test.php | 6 ++++-- ext/autocomplete/test.php | 6 ++++-- ext/bulk_add/test.php | 6 ++++-- ext/image_hash_ban/test.php | 3 +-- ext/ipban/test.php | 9 ++++++--- ext/pools/test.php | 3 ++- ext/random_image/main.php | 2 +- ext/random_image/theme.php | 4 +++- ext/tag_edit/test.php | 6 +++--- ext/tips/main.php | 18 ++++++++++++------ ext/upload/test.php | 3 +-- ext/wiki/main.php | 18 ++++++++++++------ tests/bootstrap.php | 12 ++++++------ themes/default/page.class.php | 4 +++- themes/material/page.class.php | 4 +++- themes/warm/page.class.php | 4 +++- 23 files changed, 95 insertions(+), 55 deletions(-) diff --git a/core/basepage.php b/core/basepage.php index 2df4579c..47904f8a 100644 --- a/core/basepage.php +++ b/core/basepage.php @@ -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; } } diff --git a/core/database.php b/core/database.php index 0ed0ddfa..83a3cf17 100644 --- a/core/database.php +++ b/core/database.php @@ -46,7 +46,8 @@ class Database */ public $query_count = 0; - public function __construct(string $dsn) { + public function __construct(string $dsn) + { $this->dsn = $dsn; } diff --git a/core/event.php b/core/event.php index 579ad6d4..b035269c 100644 --- a/core/event.php +++ b/core/event.php @@ -228,7 +228,7 @@ class CommandEvent extends Event } } - if(!defined("CLI_LOG_LEVEL")) { + if (!defined("CLI_LOG_LEVEL")) { define("CLI_LOG_LEVEL", $log_level); } diff --git a/core/tests/block.test.php b/core/tests/block.test.php index 7db5c2d4..41a1de25 100644 --- a/core/tests/block.test.php +++ b/core/tests/block.test.php @@ -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( "

head

body
\n", diff --git a/core/tests/polyfills.test.php b/core/tests/polyfills.test.php index cbd33f40..ea7a3d1a 100644 --- a/core/tests/polyfills.test.php +++ b/core/tests/polyfills.test.php @@ -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( "", 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"]]) diff --git a/core/util.php b/core/util.php index c8e8c190..83b2be64 100644 --- a/core/util.php +++ b/core/util.php @@ -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())); } diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index 3cc8207b..f72dd233 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -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"); diff --git a/ext/alias_editor/test.php b/ext/alias_editor/test.php index 6b9dd782..9829cec3 100644 --- a/ext/alias_editor/test.php +++ b/ext/alias_editor/test.php @@ -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"); diff --git a/ext/autocomplete/test.php b/ext/autocomplete/test.php index d53fe37a..4df7675c 100644 --- a/ext/autocomplete/test.php +++ b/ext/autocomplete/test.php @@ -1,8 +1,10 @@ anon_name))); $page = $this->get_page('api/internal/autocomplete', ["s"=>"not-a-tag"]); $this->assertEquals(200, $page->code); diff --git a/ext/bulk_add/test.php b/ext/bulk_add/test.php index 2f2ba2a3..7a19755c 100644 --- a/ext/bulk_add/test.php +++ b/ext/bulk_add/test.php @@ -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"); diff --git a/ext/image_hash_ban/test.php b/ext/image_hash_ban/test.php index 5ca209f8..3381a618 100644 --- a/ext/image_hash_ban/test.php +++ b/ext/image_hash_ban/test.php @@ -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); } diff --git a/ext/ipban/test.php b/ext/ipban/test.php index f0b88d0b..1c6dbb5e 100644 --- a/ext/ipban/test.php +++ b/ext/ipban/test.php @@ -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 } diff --git a/ext/pools/test.php b/ext/pools/test.php index edf09544..06ac0d18 100644 --- a/ext/pools/test.php +++ b/ext/pools/test.php @@ -1,7 +1,8 @@ get_page('pool/list'); $this->assert_title("Pools"); diff --git a/ext/random_image/main.php b/ext/random_image/main.php index 9fb4b343..516ad037 100644 --- a/ext/random_image/main.php +++ b/ext/random_image/main.php @@ -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) diff --git a/ext/random_image/theme.php b/ext/random_image/theme.php index 80ba9360..7e4702ab 100644 --- a/ext/random_image/theme.php +++ b/ext/random_image/theme.php @@ -1,5 +1,7 @@ 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); } } diff --git a/ext/tips/main.php b/ext/tips/main.php index 3daf4f13..fe78a05a 100644 --- a/ext/tips/main.php +++ b/ext/tips/main.php @@ -1,10 +1,12 @@ 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]); } diff --git a/ext/upload/test.php b/ext/upload/test.php index 77985bd8..5cda4eca 100644 --- a/ext/upload/test.php +++ b/ext/upload/test.php @@ -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"); diff --git a/ext/wiki/main.php b/ext/wiki/main.php index 2c958021..c58038d9 100644 --- a/ext/wiki/main.php +++ b/ext/wiki/main.php @@ -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", diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3b28c268..46c7992e 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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"); } } diff --git a/themes/default/page.class.php b/themes/default/page.class.php index b3b34c2f..5fc0f7ef 100644 --- a/themes/default/page.class.php +++ b/themes/default/page.class.php @@ -1,2 +1,4 @@