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