aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-06-13 19:07:05 +0000
committerMario <mario@mariovavti.com>2024-06-13 19:07:05 +0000
commitff018b975b47a57433b5f76634f9948164919e25 (patch)
tree408f52fb71a955ab2bf13a3b8f89c6d293b217e6 /tests/unit
parent6e0d0e38321dda6075586c12244c73eff6623565 (diff)
parentfcd657040e90b957068be0c6010faa78020cf05d (diff)
downloadvolse-hubzilla-ff018b975b47a57433b5f76634f9948164919e25.tar.gz
volse-hubzilla-ff018b975b47a57433b5f76634f9948164919e25.tar.bz2
volse-hubzilla-ff018b975b47a57433b5f76634f9948164919e25.zip
Merge branch 'fix-rpost-module' into 'dev'
Refactoring and fixed for Module\Rpost See merge request hubzilla/core!2136
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/Module/RpostTest.php81
-rw-r--r--tests/unit/Module/TestCase.php1
-rw-r--r--tests/unit/includes/NetworkTest.php8
-rw-r--r--tests/unit/includes/dba/_files/config.yml4
4 files changed, 87 insertions, 7 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);
+ }
+}
diff --git a/tests/unit/Module/TestCase.php b/tests/unit/Module/TestCase.php
index e7051e001..f2e19f265 100644
--- a/tests/unit/Module/TestCase.php
+++ b/tests/unit/Module/TestCase.php
@@ -25,6 +25,7 @@ class TestCase extends \Zotlabs\Tests\Unit\UnitTestCase {
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
+ $_SERVER['QUERY_STRING'] = "q={$uri}";
$_REQUEST = $_GET;
\App::init();
diff --git a/tests/unit/includes/NetworkTest.php b/tests/unit/includes/NetworkTest.php
index 5bf175953..a41075f25 100644
--- a/tests/unit/includes/NetworkTest.php
+++ b/tests/unit/includes/NetworkTest.php
@@ -7,12 +7,6 @@
class NetworkTest extends Zotlabs\Tests\Unit\UnitTestCase {
- public function setUp() : void {
- parent::setUp();
-
- \App::set_baseurl("https://mytest.org");
- }
-
/**
* @dataProvider localUrlTestProvider
*/
@@ -23,7 +17,7 @@ class NetworkTest extends Zotlabs\Tests\Unit\UnitTestCase {
public static function localUrlTestProvider() : array {
return [
[ '/some/path', true ],
- [ 'https://mytest.org/some/path', true ],
+ [ 'https://hubzilla.test/some/path', true ],
[ 'https://other.site/some/path', false ],
];
}
diff --git a/tests/unit/includes/dba/_files/config.yml b/tests/unit/includes/dba/_files/config.yml
index e93486857..ac3c8acb0 100644
--- a/tests/unit/includes/dba/_files/config.yml
+++ b/tests/unit/includes/dba/_files/config.yml
@@ -2,6 +2,10 @@
config:
-
cat: system
+ k: baseurl
+ v: https://hubzilla.test
+ -
+ cat: system
k: do_not_check_dns
v: true
-