blob: 96a5ef932bd7be9c4725d632d7aa216ebacf63f5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<?php
/**
* SPDX-FileCopyrightText: 2024 Harald Eilertsen
* SPDX-FileCopyrightText: 2024 Hubzilla Community
*
* SPDX-License-Identifier: MIT
*/
/**
* 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 SetupModuleTest extends \Zotlabs\Tests\Unit\Module\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;');
}
}
|