aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/Module/RpostTest.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-07-06 11:05:22 +0000
committerMario <mario@mariovavti.com>2024-07-06 11:05:22 +0000
commit45275910e606a02b12393714ea3b0409da440d61 (patch)
tree10b2d173d58cb930f8df28fe75af73dd4974c08c /tests/unit/Module/RpostTest.php
parent0c1d0f7498661fb34dcca6f3c6566e757af310a7 (diff)
parentc04e781926a78e514cdf211fa24930a331149072 (diff)
downloadvolse-hubzilla-master.tar.gz
volse-hubzilla-master.tar.bz2
volse-hubzilla-master.zip
Merge branch '9.2RC'master
Diffstat (limited to 'tests/unit/Module/RpostTest.php')
-rw-r--r--tests/unit/Module/RpostTest.php81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/unit/Module/RpostTest.php b/tests/unit/Module/RpostTest.php
new file mode 100644
index 000000000..ad94f2f06
--- /dev/null
+++ b/tests/unit/Module/RpostTest.php
@@ -0,0 +1,81 @@
+<?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 {
+
+ /**
+ * Basic test of a get request with no args as an authenticated user.
+ */
+ public function test_get_with_no_args(): void {
+ $this->get_authenticated();
+
+ $this->assertPageContains('<form id="profile-jot-form"');
+ $this->assertPageContains('<input type="hidden" name="profile_uid" value="42"');
+ }
+
+ /**
+ * Display login form if session is not authenticated.
+ */
+ public function test_display_login_form_if_not_logged_in(): void {
+ $lc_mock = $this->getFunctionMock('Zotlabs\Module', 'local_channel')
+ ->expects($this->any())
+ ->willReturn(false);
+
+ $this->get('rpost');
+
+ $this->assertPageContains('<form action="https://hubzilla.test/rpost" id="main_login"');
+ }
+
+ public function test_populates_form_from_query_params(): void {
+ $this->get_authenticated([
+ 'title' => 'This is my title',
+ 'body' => 'The body of the post',
+ 'source' => 'The temple of the Dagon',
+ ]);
+
+ $this->assertPageContains('value="This is my title"');
+ $this->assertPageContains('>The body of the post</textarea>');
+ $this->assertPageContains('value="The temple of the Dagon"');
+ }
+
+ public function test_convert_body_from_html_to_bbcode(): void {
+ $this->get_authenticated([
+ 'body' => "<h1>Awesome page</h1>\r\n<p>Awesome content!</p>",
+ 'type' => 'html',
+ ]);
+
+ $this->assertPageContains(">[h1]Awesome page[/h1]\n\nAwesome content!</textarea>");
+ }
+
+ /**
+ * Private helper method to perform an authenticated GET request.
+ *
+ * @param array $query An associative array of query parameters.
+ */
+ private function get_authenticated(array $query = []): 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_id' => 42,
+ 'channel_location' => null,
+ 'channel_address' => '',
+ 'channel_allow_cid' => '',
+ 'channel_allow_gid' => '',
+ 'channel_deny_cid' => '',
+ 'channel_deny_gid' => '',
+ ];
+
+ $this->get('rpost', $query);
+ }
+}