From 7c34a3676d294c9a1acc69f71ab3061074509160 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 30 Apr 2024 06:59:19 +0000 Subject: Rework Help module + begin tests for Setup module --- tests/unit/Module/SetupTest.php | 74 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/unit/Module/SetupTest.php (limited to 'tests/unit/Module/SetupTest.php') diff --git a/tests/unit/Module/SetupTest.php b/tests/unit/Module/SetupTest.php new file mode 100644 index 000000000..96a5ef932 --- /dev/null +++ b/tests/unit/Module/SetupTest.php @@ -0,0 +1,74 @@ +with_no_accounts_in_db(); + $this->get('setup'); + + $this->assertEquals('setup', \App::$page['page_title']); + + // Assert that result _don't_ match "Permission denied" + $this->assertThat( + \App::$page['content'], + $this->logicalNot( + $this->matchesRegularExpression('/Permission denied/') + ) + ); + } + + public function test_that_setup_is_not_available_if_accounts_in_db(): void { + // The fixtures loaded by default add a couple of accounts. + $this->get('setup'); + + $this->assertEquals('setup', \App::$page['page_title']); + $this->assertMatchesRegularExpression('/Permission denied/', \App::$page['content']); + } + + public function test_that_setup_testrewrite_returns_ok(): void { + // We need to stub the `killme` function, as it is called directly from + // the code under test. + $this->stub_killme(); + + $output = ''; + + // Turn on output buffering, as code under test echoes + // directly to the output + ob_start(); + try { + $this->get('setup/testrewrite'); + } catch (\Zotlabs\Tests\Unit\Module\KillmeException) { + $output = ob_get_contents(); + } + + $this->assertEquals('ok', $output); + + ob_end_clean(); + } + + /** + * Delete all accounts from the database. + * + * This is currently needed because we automatically import the database + * fixtures on test start, which contains a couple of accounts already. + */ + private function with_no_accounts_in_db(): void { + q('DELETE FROM account;'); + } +} -- cgit v1.2.3