aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2024-05-19 11:41:45 +0200
committerHarald Eilertsen <haraldei@anduin.net>2024-06-13 13:34:20 +0200
commit5abe14982aff9ed2d9817255ffb8d1752519cf95 (patch)
treeb19dadcfbc611de3bb92082fb2e9416922da2b3a /tests/unit
parent8be9b109fd0672e95cc43877af1b71af8bf3ee6c (diff)
downloadvolse-hubzilla-5abe14982aff9ed2d9817255ffb8d1752519cf95.tar.gz
volse-hubzilla-5abe14982aff9ed2d9817255ffb8d1752519cf95.tar.bz2
volse-hubzilla-5abe14982aff9ed2d9817255ffb8d1752519cf95.zip
tests: More tests for Module\Rpost.
Also refactor the tests a bit to avoid duplicatng code.
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/Module/RpostTest.php58
1 files changed, 44 insertions, 14 deletions
diff --git a/tests/unit/Module/RpostTest.php b/tests/unit/Module/RpostTest.php
index 2f277e66d..106f06fde 100644
--- a/tests/unit/Module/RpostTest.php
+++ b/tests/unit/Module/RpostTest.php
@@ -14,20 +14,7 @@ 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 {
- // 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->get_authenticated();
$this->assertPageContains('<form id="profile-jot-form"');
$this->assertPageContains('<input type="hidden" name="profile_uid" value="42"');
@@ -45,4 +32,47 @@ class RpostTest extends \Zotlabs\Tests\Unit\Module\TestCase {
$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_allow_cid' => null,
+ 'channel_allow_gid' => null,
+ 'channel_deny_cid' => null,
+ 'channel_deny_gid' => null,
+ ];
+
+ $this->get('rpost', $query);
+ }
}