aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/Module/HelpTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/Module/HelpTest.php')
-rw-r--r--tests/unit/Module/HelpTest.php67
1 files changed, 43 insertions, 24 deletions
diff --git a/tests/unit/Module/HelpTest.php b/tests/unit/Module/HelpTest.php
index c345d5e52..2c1d31570 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', "<h3>Help heading</h3><p>\$Projectname help content</p>" ],
- ];
-
- // 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
@@ -104,6 +81,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');
@@ -121,6 +103,16 @@ 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');
+ $this->assertPageContains('This page is not yet available in norsk bokmål');
+ }
+
public function test_includes(): void {
// Stub `file_get_contents` to plant our own content.
$fgc_stub = $this->getFunctionMock('Zotlabs\Module', 'file_get_contents');
@@ -176,4 +168,31 @@ class HelpTest extends \Zotlabs\Tests\Unit\Module\TestCase {
$this->assertPageContains('<h3>This is the included file.</h3>');
}
+
+ 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', "<h3>Help heading</h3><p>\$Projectname help content</p>" ],
+ ];
+
+ // 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 ];
+ }
}