From 9ba9bf0fdf6ab4a42bdfa78d9b74fa952e438798 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 9 Feb 2024 14:54:37 +0000 Subject: [PATCH] fix tests --- core/tests/UrlsTest.php | 30 ++++++++++++++++++------------ core/urls.php | 10 +++++----- ext/download/test.php | 2 +- ext/link_scan/test.php | 6 +++--- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/core/tests/UrlsTest.php b/core/tests/UrlsTest.php index fd198529..07c1e1ec 100644 --- a/core/tests/UrlsTest.php +++ b/core/tests/UrlsTest.php @@ -25,12 +25,11 @@ class UrlsTest extends TestCase * @param array $vars * @return array */ - function _gst(array $terms): array - { + $gst = function (array $terms): array { $pre = new PageRequestEvent("GET", _get_query(search_link($terms))); $pre->page_matches("post/list"); return $pre->get_search_terms(); - } + }; global $config; foreach([true, false] as $nice_urls) { @@ -38,15 +37,15 @@ class UrlsTest extends TestCase $this->assertEquals( ["bar", "foo"], - _gst(["foo", "bar"]) + $gst(["foo", "bar"]) ); $this->assertEquals( ["AC/DC"], - _gst(["AC/DC"]) + $gst(["AC/DC"]) ); $this->assertEquals( ["cat*", "rating=?"], - _gst(["rating=?", "cat*"]), + $gst(["rating=?", "cat*"]), ); } } @@ -57,13 +56,13 @@ class UrlsTest extends TestCase global $config; foreach([true, false] as $nice_urls) { $config->set_bool('nice_urls', $nice_urls); - + // basic $this->assertEquals( $nice_urls ? "/test/foo" : "/test/index.php?q=foo", make_link("foo") ); - + // remove leading slash from path $this->assertEquals( $nice_urls ? "/test/foo" : "/test/index.php?q=foo", @@ -75,18 +74,18 @@ class UrlsTest extends TestCase $nice_urls ? "/test/foo?a=1&b=2" : "/test/index.php?q=foo&a=1&b=2", make_link("foo", "a=1&b=2") ); - + // hash $this->assertEquals( $nice_urls ? "/test/foo#cake" : "/test/index.php?q=foo#cake", make_link("foo", null, "cake") ); - + // query + hash $this->assertEquals( $nice_urls ? "/test/foo?a=1&b=2#cake" : "/test/index.php?q=foo&a=1&b=2#cake", make_link("foo", "a=1&b=2", "cake") - ); + ); } } @@ -120,7 +119,7 @@ class UrlsTest extends TestCase $this->assertEquals( "tasty/cake", - _get_query("/test/tasty/cake"), + _get_query("/test/tasty/cake"), 'http://$SERVER/$INSTALL_DIR/$PATH should return $PATH' ); $this->assertEquals( @@ -264,4 +263,11 @@ class UrlsTest extends TestCase referer_or("foo", ["cake"]) ); } + + public function tearDown(): void + { + global $config; + $config->set_bool('nice_urls', true); + parent::tearDown(); + } } diff --git a/core/urls.php b/core/urls.php index 7851fc50..747eaae4 100644 --- a/core/urls.php +++ b/core/urls.php @@ -69,9 +69,9 @@ function make_link(?string $page = null, ?string $query = null, ?string $fragmen /** * Figure out the current page from a link that make_link() generated - * + * * SHIT: notes for the future, because the web stack is a pile of hacks - * + * * - According to some specs, "/" is for URL dividers with heiracial * significance and %2F is for slashes that are just slashes. This * is what shimmie currently does - eg if you search for "AC/DC", @@ -83,7 +83,7 @@ function make_link(?string $page = null, ?string $query = null, ?string $fragmen * can parse it for ourselves * - generates * q=post%2Flist - * + * * This function should always return strings with no leading slashes */ function _get_query(?string $uri = null): string @@ -123,10 +123,10 @@ function _get_query(?string $uri = null): string * function should return /gallery * * PHP really, really sucks. - * + * * This function should always return strings with no trailing * slashes, so that it can be used like `get_base_href() . "/data/asset.abc"` - * + * * @param array|null $server_settings */ function get_base_href(?array $server_settings = null): string diff --git a/ext/download/test.php b/ext/download/test.php index 8b638502..26c79c4e 100644 --- a/ext/download/test.php +++ b/ext/download/test.php @@ -10,7 +10,7 @@ class DownloadTest extends ShimmiePHPUnitTestCase { global $page; $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); - $this->get_page("/image/$image_id"); + $this->get_page("image/$image_id"); $this->assertEquals(PageMode::FILE, $page->mode); } } diff --git a/ext/link_scan/test.php b/ext/link_scan/test.php index 075b560d..9fe8a785 100644 --- a/ext/link_scan/test.php +++ b/ext/link_scan/test.php @@ -19,7 +19,7 @@ class LinkScanTest extends ShimmiePHPUnitTestCase But there is no http://example.com/post/view/65432 "; - $page = $this->post_page("post/list", ["search" => $text]); + $page = $this->get_page("post/list", ["search" => $text]); $this->assertEquals(PageMode::REDIRECT, $page->mode); $this->assertEquals("/test/post/list/id%3D{$image_id_1}%2C{$image_id_2}/1", $page->redirect); @@ -35,7 +35,7 @@ class LinkScanTest extends ShimmiePHPUnitTestCase Look at http://example.com/_images/feb01bab5698a11dd87416724c7a89e3/foobar.jpg there is an image or search for e106ea2983e1b77f11e00c0c54e53805 but one that doesn't exist is e106ea2983e1b77f11e00c0c54e50000 o.o"; - $page = $this->post_page("post/list", ["search" => $text]); + $page = $this->get_page("post/list", ["search" => $text]); $this->assertEquals(PageMode::REDIRECT, $page->mode); $this->assertEquals("/test/post/list/id%3D{$image_id_1}%2C{$image_id_2}/1", $page->redirect); @@ -48,7 +48,7 @@ class LinkScanTest extends ShimmiePHPUnitTestCase $this->post_image("tests/favicon.png", "TeStCase"); $text = "Look at feb01bab5698a11dd87416724c7a89e3/foobar.jpg"; - $page = $this->post_page("post/list", ["search" => $text]); + $page = $this->get_page("post/list", ["search" => $text]); $this->assertEquals(PageMode::REDIRECT, $page->mode); $this->assertEquals("/test/post/list/at%20feb01bab5698a11dd87416724c7a89e3%2Ffoobar.jpg%20Look/1", $page->redirect);