From 7afb01e4889761f4b420b37d626a8c96f41434fa Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 23 Jul 2024 12:24:42 +0200 Subject: Redirect help to about page when locale but no topic specified in URL --- tests/unit/Module/HelpTest.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/unit/Module/HelpTest.php') diff --git a/tests/unit/Module/HelpTest.php b/tests/unit/Module/HelpTest.php index c345d5e52..353a40def 100644 --- a/tests/unit/Module/HelpTest.php +++ b/tests/unit/Module/HelpTest.php @@ -104,6 +104,11 @@ class HelpTest extends \Zotlabs\Tests\Unit\Module\TestCase { $this->get('help'); } + public function test_getting_locale_with_no_topic_should_redirect_to_about_page_for_locale(): void { + $this->expectRedirectTo('help/de/about/about'); + $this->get('help/de'); + } + public function test_find_help_file_returns_first_match(): void { // Stub file exists, to always return true $fe_stub = $this->getFunctionMock('Zotlabs\Lib\Traits', 'file_exists'); -- cgit v1.2.3 From 898fb4f80039bf1ec920f931d4e8c00162bf4ef8 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 23 Jul 2024 18:51:22 +0200 Subject: Refactor HelpTest.php. Move default stubs to a function to make them reusable. --- tests/unit/Module/HelpTest.php | 52 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'tests/unit/Module/HelpTest.php') diff --git a/tests/unit/Module/HelpTest.php b/tests/unit/Module/HelpTest.php index 353a40def..64e4a2663 100644 --- a/tests/unit/Module/HelpTest.php +++ b/tests/unit/Module/HelpTest.php @@ -31,30 +31,7 @@ class HelpTest extends \Zotlabs\Tests\Unit\Module\TestCase { * ["html"] */ public function test_get_request_when_help_file_exists(string $ext): void { - // Stub file exists, to only retur true for the file with the current - // extension - $fe_stub = $this->getFunctionMock('Zotlabs\Lib\Traits', 'file_exists'); - $fe_stub - ->expects($this->any()) - ->willReturnCallback( - fn (string $path) => $path === "doc/en/about/help_topic.{$ext}" - ); - - // Use a value map to make the `file_get_contents` stub return the - // correct content for the file types. - $file_content_map = [ - [ 'doc/en/about/help_topic.md', "### Help heading\n\$Projectname help content" ], - [ 'doc/en/about/help_topic.bb', "[h3]Help heading[/h3]\n\n\$Projectname help content" ], - [ 'doc/en/about/help_topic.html', "

Help heading

\$Projectname help content

" ], - ]; - - // Stub `file_get_contents` to plant our own content. - $fgc_stub = $this->getFunctionMock('Zotlabs\Module', 'file_get_contents'); - $fgc_stub - ->expects($this->once()) - ->willReturnMap($file_content_map); - - + $stubs = $this->prepare_stubs($ext); $this->get("help/about/help_topic"); // Check that markdown content was correctly rendered @@ -181,4 +158,31 @@ class HelpTest extends \Zotlabs\Tests\Unit\Module\TestCase { $this->assertPageContains('

This is the included file.

'); } + + private function prepare_stubs(string $ext): array { + // Stub file exists, to only retur true for the file with the current + // extension + $fe_stub = $this->getFunctionMock('Zotlabs\Lib\Traits', 'file_exists'); + $fe_stub + ->expects($this->any()) + ->willReturnCallback( + fn (string $path) => $path === "doc/en/about/help_topic.{$ext}" + ); + + // Use a value map to make the `file_get_contents` stub return the + // correct content for the file types. + $file_content_map = [ + [ 'doc/en/about/help_topic.md', "### Help heading\n\$Projectname help content" ], + [ 'doc/en/about/help_topic.bb', "[h3]Help heading[/h3]\n\n\$Projectname help content" ], + [ 'doc/en/about/help_topic.html', "

Help heading

\$Projectname help content

" ], + ]; + + // Stub `file_get_contents` to plant our own content. + $fgc_stub = $this->getFunctionMock('Zotlabs\Module', 'file_get_contents'); + $fgc_stub + ->expects($this->once()) + ->willReturnMap($file_content_map); + + return [ 'file_exists' => $fe_stub, 'file_get_contents' => $fgc_stub ]; + } } -- cgit v1.2.3 From 1bd52867fb463a4b34cd2c4a9b9ace8b570e18b4 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 23 Jul 2024 18:52:12 +0200 Subject: Fallback to english help topic if localized topic is not found. --- tests/unit/Module/HelpTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/unit/Module/HelpTest.php') diff --git a/tests/unit/Module/HelpTest.php b/tests/unit/Module/HelpTest.php index 64e4a2663..2e5494f7c 100644 --- a/tests/unit/Module/HelpTest.php +++ b/tests/unit/Module/HelpTest.php @@ -103,6 +103,15 @@ class HelpTest extends \Zotlabs\Tests\Unit\Module\TestCase { $this->get('help/first'); } + public function test_fall_back_to_english_if_localized_topic_dont_exist(): void { + \App::$language = 'nb'; + + $stubs = $this->prepare_stubs('bb'); + $this->get('help/about/help_topic'); + + $this->assertPageContains('Hubzilla Documentation: About'); + } + public function test_includes(): void { // Stub `file_get_contents` to plant our own content. $fgc_stub = $this->getFunctionMock('Zotlabs\Module', 'file_get_contents'); -- cgit v1.2.3 From 61f9ad8274d662a056aff05407771fb450a2ab35 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Wed, 24 Jul 2024 11:46:18 +0200 Subject: Add a notice to help pages when defaulting to english. --- tests/unit/Module/HelpTest.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/unit/Module/HelpTest.php') diff --git a/tests/unit/Module/HelpTest.php b/tests/unit/Module/HelpTest.php index 2e5494f7c..81d2e9287 100644 --- a/tests/unit/Module/HelpTest.php +++ b/tests/unit/Module/HelpTest.php @@ -110,6 +110,7 @@ class HelpTest extends \Zotlabs\Tests\Unit\Module\TestCase { $this->get('help/about/help_topic'); $this->assertPageContains('Hubzilla Documentation: About'); + $this->assertPageContains('This page is not yet available in your preferred language'); } public function test_includes(): void { -- cgit v1.2.3 From d3093dce1bfd4685d5e11f828689630862f77bda Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Wed, 24 Jul 2024 11:57:41 +0200 Subject: Improve translation message for help pages. Display the target language instead of "your preferred language". Makes it a bit more explicit. --- tests/unit/Module/HelpTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/unit/Module/HelpTest.php') diff --git a/tests/unit/Module/HelpTest.php b/tests/unit/Module/HelpTest.php index 81d2e9287..2c1d31570 100644 --- a/tests/unit/Module/HelpTest.php +++ b/tests/unit/Module/HelpTest.php @@ -110,7 +110,7 @@ class HelpTest extends \Zotlabs\Tests\Unit\Module\TestCase { $this->get('help/about/help_topic'); $this->assertPageContains('Hubzilla Documentation: About'); - $this->assertPageContains('This page is not yet available in your preferred language'); + $this->assertPageContains('This page is not yet available in norsk bokmål'); } public function test_includes(): void { -- cgit v1.2.3