1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Saito - The Threaded Web Forum |
6
|
|
|
* |
7
|
|
|
* @copyright Copyright (c) the Saito Project Developers |
8
|
|
|
* @link https://github.com/Schlaefer/Saito |
9
|
|
|
* @license http://opensource.org/licenses/MIT |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Installer\Test\TestCase\Controller; |
13
|
|
|
|
14
|
|
|
use Cake\Core\Configure; |
15
|
|
|
use Cake\Datasource\ConnectionManager; |
16
|
|
|
use Cake\Filesystem\File; |
17
|
|
|
use Cake\ORM\TableRegistry; |
18
|
|
|
use Installer\Lib\DbVersion; |
19
|
|
|
use Installer\Lib\InstallerState; |
20
|
|
|
use Installer\Lib\IntegrationTestCase; |
21
|
|
|
|
22
|
|
|
class InstallControllerTest extends IntegrationTestCase |
23
|
|
|
{ |
24
|
|
|
protected $isUpdated = false; |
25
|
|
|
|
26
|
|
|
public function setUp(): void |
27
|
|
|
{ |
28
|
|
|
parent::setUp(); |
29
|
|
|
$this->dropTables(); |
30
|
|
|
$this->createInstallerToken(); |
31
|
|
|
InstallerState::reset(); |
32
|
|
|
|
33
|
|
|
Configure::write('Saito.installed', false); |
34
|
|
|
Configure::write('Saito.updated', false); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function tearDown(): void |
38
|
|
|
{ |
39
|
|
|
$this->createInstallerToken(); |
40
|
|
|
$this->dropTables(); |
41
|
|
|
InstallerState::reset(); |
42
|
|
|
parent::tearDown(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testIndex() |
46
|
|
|
{ |
47
|
|
|
$this->get('/'); |
48
|
|
|
|
49
|
|
|
$this->assertRedirect('install/dbconnection'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testWrongInstallerState() |
53
|
|
|
{ |
54
|
|
|
$actions = [ |
55
|
|
|
'salt', |
56
|
|
|
'connected', |
57
|
|
|
'migrate', |
58
|
|
|
'data', |
59
|
|
|
'finished', |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
foreach ($actions as $action) { |
63
|
|
|
$this->get('install/' . $action); |
64
|
|
|
$this->assertRedirect('/'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testMigrateAndData() |
69
|
|
|
{ |
70
|
|
|
InstallerState::set('migrate'); |
71
|
|
|
$this->post('install/migrate'); |
72
|
|
|
|
73
|
|
|
$email = '[email protected]'; |
74
|
|
|
$this->post( |
75
|
|
|
'install/data', |
76
|
|
|
[ |
77
|
|
|
'username' => 'admin', |
78
|
|
|
'password' => 'admin', |
79
|
|
|
'password_confirm' => 'admin', |
80
|
|
|
'user_email' => $email, |
81
|
|
|
] |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$this->assertRedirect('install/finished'); |
85
|
|
|
|
86
|
|
|
$Settings = TableRegistry::getTableLocator()->get('Settings'); |
87
|
|
|
$this->assertEquals($email, $Settings->findByName('forum_email')->first()->get('value')); |
88
|
|
|
|
89
|
|
|
$dbVersion = (new DbVersion($Settings))->get(); |
90
|
|
|
$this->assertEquals(Configure::read('Saito.v'), $dbVersion); |
91
|
|
|
|
92
|
|
|
$Users = TableRegistry::getTableLocator()->get('Users'); |
93
|
|
|
$admin = $Users->get(1); |
94
|
|
|
$this->assertTextContains('$2y$', $admin->get('password')); |
95
|
|
|
$this->assertEquals($email, $admin->get('user_email')); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testConnectedDbExists() |
99
|
|
|
{ |
100
|
|
|
InstallerState::set('connected'); |
101
|
|
|
$this->createSettings(); |
102
|
|
|
(new DbVersion(TableRegistry::get('Settings')))->set('4.10.0'); |
|
|
|
|
103
|
|
|
|
104
|
|
|
$token = new File(CONFIG . 'installer'); |
105
|
|
|
$this->assertTrue($token->exists()); |
106
|
|
|
|
107
|
|
|
$this->get('install/connected'); |
108
|
|
|
|
109
|
|
|
$this->assertResponseCode(200); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
private function createInstallerToken() |
113
|
|
|
{ |
114
|
|
|
(new File(CONFIG . 'installer'))->create(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
private function createSettings() |
118
|
|
|
{ |
119
|
|
|
$connection = ConnectionManager::get('test'); |
120
|
|
|
$connection->execute('DROP TABLE IF EXISTS `settings`;'); |
121
|
|
|
$connection->execute('CREATE TABLE `settings` (id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT);'); |
122
|
|
|
$connection->execute('ALTER TABLE settings ADD `name` VARCHAR(100) NULL DEFAULT NULL AFTER `id`;'); |
123
|
|
|
$connection->execute('ALTER TABLE settings ADD `value` VARCHAR(100) NULL DEFAULT NULL AFTER `id`;'); |
124
|
|
|
$connection->execute("INSERT INTO `settings` (`id`, `name`, `value`) VALUES ('1', 'db_version', NULL);"); |
125
|
|
|
$connection->execute("INSERT INTO `settings` (`id`, `name`, `value`) VALUES ('2', 'forum_email', NULL);"); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.