forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstallerTest.php
162 lines (139 loc) · 6.33 KB
/
InstallerTest.php
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/* Copyright © 2010 by Andrew Moore <[email protected]> */
/* Licensing information appears at the end of this file. */
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../../library/classes');
require_once 'PHPUnit/Framework.php';
require_once 'Installer.class.php';
class InstallerTest extends PHPUnit_Framework_TestCase
{
protected $installer;
protected $post_variables;
protected function setUp()
{
$this->post_variables = array( 'login' => 'boris',
'iuser' => 'initialuser',
'iuname' => 'initialusername',
'igroup' => 'initialgroup',
'pass' => 'validpassword',
'server' => 'localhost',
'loginhost' => 'localhost',
'port' => '3306',
'root' => 'root',
'rootpass' => 'notapass',
'dbname' => 'openemr_test_suite',
'collate' => '',
'site' => 'default',
);
$this->installer = new Installer($this->post_variables);
}
public function testAttributes()
{
foreach ($this->post_variables as $attribute => $value) {
$this->assertEquals($value, $this->installer->$attribute, "fetching $attribute from Installer object");
}
}
public function testFilePaths()
{
$this->assertFileExists($this->installer->conffile);
$this->assertFileExists($this->installer->gaclSetupScript1);
$this->assertFileExists($this->installer->gaclSetupScript2);
}
/**
* @dataProvider loginValidatorData
*/
public function testLoginValidator($login, $expected_return)
{
$post_variables = $this->post_variables;
$post_variables['login'] = $login;
$installer = new Installer($post_variables);
$this->assertEquals($expected_return, $installer->login_is_valid(), "testing login: '$login'");
}
/* dataProvider for testLoginValidator */
public static function loginValidatorData()
{
return array( array( 'boris', true ),
array( '', false )
);
}
public function testIuserValidator()
{
$this->assertEquals(true, $this->installer->iuser_is_valid());
}
public function testIuserIsInvalid()
{
$post_variables = $this->post_variables;
$post_variables['iuser'] = 'initial user';
$installer = new Installer($post_variables);
$this->assertEquals(false, $installer->iuser_is_valid());
}
public function testPasswordValidator()
{
$this->assertEquals(true, $this->installer->password_is_valid());
}
public function testPasswordIsInvalid()
{
$post_variables = $this->post_variables;
$post_variables['pass'] = '';
$installer = new Installer($post_variables);
$this->assertEquals(false, $installer->password_is_valid());
}
public function testRootDatabaseConnection()
{
$this->assertEquals(true, $this->installer->root_database_connection(), 'creating root database connection');
}
public function testGaclFilesExist()
{
$this->assertFileExists($this->installer->gaclSetupScript1, $this->installer->gaclSetupScript1);
$this->assertFileExists($this->installer->gaclSetupScript2, $this->installer->gaclSetupScript2);
}
public function testUserDatabaseConnection()
{
$rootdbh = $this->installer->root_database_connection();
$this->installer->drop_database(); // may or may not exist.
$this->assertEquals(true, $this->installer->create_database(), 'creating user database');
$this->assertEquals(true, $this->installer->grant_privileges(), 'granting privileges');
$this->assertEquals(true, $this->installer->user_database_connection(), 'creating user database connection');
}
public function testDumpfiles()
{
$rootdbh = $this->installer->root_database_connection();
$this->installer->drop_database(); // may or may not exist.
$this->assertEquals(true, $this->installer->create_database(), 'creating user database');
$this->assertEquals(true, $this->installer->grant_privileges(), 'granting privileges');
$this->assertEquals(true, $this->installer->user_database_connection(), 'creating user database connection');
$dumpresults = $this->installer->load_dumpfiles();
$this->assertEquals(true, $dumpresults, 'installing dumpfiles');
}
// public function testGacl()
// {
// $rootdbh = $this->installer->root_database_connection();
// $this->installer->drop_database(); // may or may not exist.
// $this->assertEquals(TRUE, $this->installer->create_database(), 'creating user database' );
// $this->assertEquals(TRUE, $this->installer->grant_privileges(), 'granting privileges' );
// $this->assertEquals(TRUE, $this->installer->user_database_connection(), 'creating user database connection' );
// $dumpresults = $this->installer->load_dumpfiles();
// $this->assertEquals(TRUE, $dumpresults, 'installing dumpfiles' );
// $user_results = $this->installer->add_initial_user();
// $this->installer->install_gacl();
// $this->installer->configure_gacl();
// }
public function testConfFile()
{
$this->assertEquals(true, $this->installer->write_configuration_file(), 'wrote configuration file');
}
public function tearDown()
{
$installer = $this->installer;
$installer->drop_database();
}
}
/*
This file is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as publish by the Free Software
Foundation.
This file is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Gneral Public License for more details.
You should have received a copy of the GNU General Public Licence along with
this file. If not see <http:https://www.gnu.org/licenses/>.
*/