aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2024-05-18 11:30:29 +0200
committerHarald Eilertsen <haraldei@anduin.net>2024-06-13 13:34:20 +0200
commit62aefadc27002f9d47f391b15520a82d5c3d6ecc (patch)
treee12e40ba254315f463867b4ff60abda4530c02c2
parent6e0d0e38321dda6075586c12244c73eff6623565 (diff)
downloadvolse-hubzilla-62aefadc27002f9d47f391b15520a82d5c3d6ecc.tar.gz
volse-hubzilla-62aefadc27002f9d47f391b15520a82d5c3d6ecc.tar.bz2
volse-hubzilla-62aefadc27002f9d47f391b15520a82d5c3d6ecc.zip
Module\Rpost: Add basic test and fix session access.
Just a basic test to ensure that the module `get()` method behaves somewhat reasonable when no query params are given. Had to make a small change to the Rpost module itself. Since the `$_SESSION` superglobal may not always be set (and is not in the test), use `isset` instead of `array_key_exists` to check if we have saved query params in the session. In general, isset is safer than array_key_exists if there's a chance that the array itself may not exist.
-rw-r--r--Zotlabs/Module/Rpost.php2
-rw-r--r--tests/unit/Module/RpostTest.php31
2 files changed, 32 insertions, 1 deletions
diff --git a/Zotlabs/Module/Rpost.php b/Zotlabs/Module/Rpost.php
index 23324ee3a..4979fdd7c 100644
--- a/Zotlabs/Module/Rpost.php
+++ b/Zotlabs/Module/Rpost.php
@@ -140,7 +140,7 @@ class Rpost extends \Zotlabs\Web\Controller {
// If we have saved rpost session variables, but nothing in the current $_REQUEST, recover the saved variables
- if((! array_key_exists('body',$_REQUEST)) && (array_key_exists('rpost',$_SESSION))) {
+ if((! array_key_exists('body',$_REQUEST)) && isset($_SESSION['rpost'])) {
$_REQUEST = $_SESSION['rpost'];
unset($_SESSION['rpost']);
}
diff --git a/tests/unit/Module/RpostTest.php b/tests/unit/Module/RpostTest.php
new file mode 100644
index 000000000..796901520
--- /dev/null
+++ b/tests/unit/Module/RpostTest.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Tests for Rpost module.
+ *
+ * SPDX-FileCopyrightText: 2024 Hubzilla Community
+ * SPDX-FileContributor: Harald Eilertsen
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+class RpostTest extends \Zotlabs\Tests\Unit\Module\TestCase {
+ public function test_get_with_no_args(): void {
+ // Mock `local_chanel()` to emulate a valid logged in channel
+ $lc_mock = $this->getFunctionMock('Zotlabs\Module', 'local_channel')
+ ->expects($this->any())
+ ->willReturn(42);
+
+ // Set basic access controls to keep AccessList happy.
+ \App::$channel = [
+ 'channel_allow_cid' => null,
+ 'channel_allow_gid' => null,
+ 'channel_deny_cid' => null,
+ 'channel_deny_gid' => null,
+ ];
+
+ $this->get('rpost');
+
+ $this->assertPageContains('<form id="profile-jot-form"');
+ $this->assertPageContains('<input type="hidden" name="profile_uid" value="42"');
+ }
+}