From 5da0cc138f4330fd07e9c117b3f4261dc1bcbc19 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Wed, 15 May 2024 08:28:19 +0000 Subject: Refactor and cleanup Rbmark module + add tests --- tests/unit/Module/HelpTest.php | 9 ----- tests/unit/Module/RbmarkTest.php | 80 ++++++++++++++++++++++++++++++++++++++++ tests/unit/Module/TestCase.php | 20 +++++++++- 3 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 tests/unit/Module/RbmarkTest.php (limited to 'tests') diff --git a/tests/unit/Module/HelpTest.php b/tests/unit/Module/HelpTest.php index 0f1610db5..3fb7687d3 100644 --- a/tests/unit/Module/HelpTest.php +++ b/tests/unit/Module/HelpTest.php @@ -176,13 +176,4 @@ class HelpTest extends \Zotlabs\Tests\Unit\Module\TestCase { $this->assertPageContains('

This is the included file.

'); } - - /** - * Helper to simplify asserting contents in the rendered page. - * - * @param string $needle The expected string to find. - */ - private function assertPageContains(string $needle): void { - $this->assertStringContainsString($needle, \App::$page['content']); - } } diff --git a/tests/unit/Module/RbmarkTest.php b/tests/unit/Module/RbmarkTest.php new file mode 100644 index 000000000..594e7369b --- /dev/null +++ b/tests/unit/Module/RbmarkTest.php @@ -0,0 +1,80 @@ +getFunctionMock('Zotlabs\Module', 'local_channel'); + $lc_stub + ->expects($this->once()) + ->willReturn(false); + + $this->get('rbmark', ['url' => 'https://bookmarked.url']); + + $this->assertPageContains('value="login" />'); + + // also check that the original query is saved in the session + $this->assertEquals('https://bookmarked.url', $_SESSION['bookmark']['url']); + $this->assertEquals('rbmark', $_SESSION['bookmark']['q']); + } + + public function test_authenticated_get_request_returns_save_bookmark_form(): void { + $lc_stub = $this->getFunctionMock('Zotlabs\Module', 'local_channel'); + $lc_stub + ->expects($this->once()) + ->willReturn(42); + + $this->get('rbmark', [ + 'url' => 'https://bookmarked.url', + 'title' => 'My bookmark', + ]); + + $this->assertPageContains('
assertPageContains('URL of bookmark'); + $this->assertPageContains('value="https://bookmarked.url"'); + $this->assertPageContains('value="My bookmark"'); + } + + public function test_that_params_are_escaped_in_save_bookmark_form(): void { + $lc_stub = $this->getFunctionMock('Zotlabs\Module', 'local_channel'); + $lc_stub + ->expects($this->once()) + ->willReturn(42); + + $this->get('rbmark', [ + 'url' => 'https://bookmarked.url" onload="alert(/boom/)', + 'title' => 'My bookmark">