diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2024-07-23 18:51:22 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2024-07-23 18:51:22 +0200 |
commit | 898fb4f80039bf1ec920f931d4e8c00162bf4ef8 (patch) | |
tree | 6b2b60312c35ab18134272c952a10aa0b6a4f529 /tests | |
parent | 63a01c02148ad51823acb7c6a7c64129ecd6a665 (diff) | |
download | volse-hubzilla-898fb4f80039bf1ec920f931d4e8c00162bf4ef8.tar.gz volse-hubzilla-898fb4f80039bf1ec920f931d4e8c00162bf4ef8.tar.bz2 volse-hubzilla-898fb4f80039bf1ec920f931d4e8c00162bf4ef8.zip |
Refactor HelpTest.php.
Move default stubs to a function to make them reusable.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/Module/HelpTest.php | 52 |
1 files changed, 28 insertions, 24 deletions
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', "<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 @@ -181,4 +158,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 ]; + } } |