aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/Module/SetupTest.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-07-06 11:05:22 +0000
committerMario <mario@mariovavti.com>2024-07-06 11:05:22 +0000
commit45275910e606a02b12393714ea3b0409da440d61 (patch)
tree10b2d173d58cb930f8df28fe75af73dd4974c08c /tests/unit/Module/SetupTest.php
parent0c1d0f7498661fb34dcca6f3c6566e757af310a7 (diff)
parentc04e781926a78e514cdf211fa24930a331149072 (diff)
downloadvolse-hubzilla-master.tar.gz
volse-hubzilla-master.tar.bz2
volse-hubzilla-master.zip
Merge branch '9.2RC'master
Diffstat (limited to 'tests/unit/Module/SetupTest.php')
-rw-r--r--tests/unit/Module/SetupTest.php76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/unit/Module/SetupTest.php b/tests/unit/Module/SetupTest.php
new file mode 100644
index 000000000..3575dd477
--- /dev/null
+++ b/tests/unit/Module/SetupTest.php
@@ -0,0 +1,76 @@
+<?php
+/**
+ * SPDX-FileCopyrightText: 2024 Harald Eilertsen
+ * SPDX-FileCopyrightText: 2024 Hubzilla Community
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+namespace Zotlabs\Tests\Unit\Module;
+
+/**
+ * SetupModuleTest
+ *
+ * The Setup module should only be available during site installation. This is
+ * determined by whether there are any accounts present in the database, or
+ * not.
+ *
+ * This is a complex module, so expect the tests to grow as more of it will be
+ * covered.
+ */
+class SetupTest extends TestCase {
+
+ public function test_that_setup_is_available_if_no_accounts_in_db(): void {
+ $this->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;');
+ }
+}