Merge branch 'master' into fmc-custom
[openemr.git] / Tests / InstallerTest.php
blob21a629ca6ae71f3fbb287d6a3cea8857259305d4
1 <?php
2 /* Copyright © 2010 by Andrew Moore <amoore@cpan.org> */
3 /* Licensing information appears at the end of this file. */
4 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../library/classes');
5 require_once 'PHPUnit/Framework.php';
6 require_once 'Installer.class.php';
8 class InstallerTest extends PHPUnit_Framework_TestCase
11 protected $installer;
12 protected $post_variables;
14 protected function setUp()
16 $this->post_variables = array( 'login' => 'boris',
17 'iuser' => 'initialuser',
18 'iuname' => 'initialusername',
19 'igroup' => 'initialgroup',
20 'pass' => 'validpassword',
21 'server' => 'localhost',
22 'port' => '3306',
23 'root' => 'root',
24 'rootpass' => 'notapass',
25 'dbname' => 'openemr_test',
26 'collate' => '',
27 'openemrBasePath' => '',
28 'openemrWebPath' => '',
30 $this->manualPath = '';
31 $this->installer = new Installer( $this->post_variables, $this->manualPath );
34 public function testAttributes()
36 foreach ($this->post_variables as $attribute => $value) {
37 $this->assertEquals( $value, $this->installer->$attribute, "fetching $attribute from Installer object" );
41 /**
42 * @dataProvider loginValidatorData
44 public function testLoginValidator( $login, $expected_return )
46 $post_variables = $this->post_variables;
47 $post_variables['login'] = $login;
48 $installer = new Installer( $post_variables, $this->manualPath );
49 $this->assertEquals($expected_return, $installer->login_is_valid(), "testing login: '$login'" );
52 /* dataProvider for testLoginValidator */
53 public static function loginValidatorData() {
54 return array( array( 'boris', TRUE ),
55 array( '', FALSE )
59 public function testIuserValidator()
61 $this->assertEquals(TRUE, $this->installer->iuser_is_valid());
64 public function testIuserIsInvalid()
66 $post_variables = $this->post_variables;
67 $post_variables['iuser'] = 'initial user';
68 $installer = new Installer( $post_variables, $this->manualPath );
70 $this->assertEquals(FALSE, $installer->iuser_is_valid());
73 public function testPasswordValidator()
75 $this->assertEquals(TRUE, $this->installer->password_is_valid());
78 public function testPasswordIsInvalid()
80 $post_variables = $this->post_variables;
81 $post_variables['pass'] = '';
82 $installer = new Installer( $post_variables, $this->manualPath );
84 $this->assertEquals(FALSE, $installer->password_is_valid());
87 public function testRootDatabaseConnection()
89 $this->assertEquals(TRUE, $this->installer->root_database_connection(), 'creating root database connection' );
92 public function testGaclFilesExist()
94 $this->assertFileExists( $this->installer->gaclSetupScript1, $this->installer->gaclSetupScript1 );
95 $this->assertFileExists( $this->installer->gaclSetupScript2, $this->installer->gaclSetupScript2 );
98 public function testUserDatabaseConnection()
100 $rootdbh = $this->installer->root_database_connection();
101 $this->installer->drop_database(); // may or may not exist.
102 $this->assertEquals(TRUE, $this->installer->create_database(), 'creating user database' );
103 $this->assertEquals(TRUE, $this->installer->grant_privileges(), 'granting privileges' );
104 $this->assertEquals(TRUE, $this->installer->user_database_connection(), 'creating user database connection' );
107 public function testDumpfiles()
109 $rootdbh = $this->installer->root_database_connection();
110 $this->installer->drop_database(); // may or may not exist.
111 $this->assertEquals(TRUE, $this->installer->create_database(), 'creating user database' );
112 $this->assertEquals(TRUE, $this->installer->grant_privileges(), 'granting privileges' );
113 $this->assertEquals(TRUE, $this->installer->user_database_connection(), 'creating user database connection' );
114 $dumpresults = $this->installer->load_dumpfiles();
115 $this->assertEquals(TRUE, $dumpresults, 'installing dumpfiles' );
118 // public function testGacl()
119 // {
120 // $rootdbh = $this->installer->root_database_connection();
121 // $this->installer->drop_database(); // may or may not exist.
122 // $this->assertEquals(TRUE, $this->installer->create_database(), 'creating user database' );
123 // $this->assertEquals(TRUE, $this->installer->grant_privileges(), 'granting privileges' );
124 // $this->assertEquals(TRUE, $this->installer->user_database_connection(), 'creating user database connection' );
125 // $dumpresults = $this->installer->load_dumpfiles();
126 // $this->assertEquals(TRUE, $dumpresults, 'installing dumpfiles' );
127 // $user_results = $this->installer->add_initial_user();
128 // $this->installer->install_gacl();
129 // $this->installer->configure_gacl();
130 // }
132 public function testConfFile()
134 $this->assertEquals( TRUE, $this->installer->write_configuration_file(), 'wrote configuration file' );
140 This file is free software: you can redistribute it and/or modify it under the
141 terms of the GNU General Public License as publish by the Free Software
142 Foundation.
144 This file is distributed in the hope that it will be useful, but WITHOUT ANY
145 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
146 PARTICULAR PURPOSE. See the GNU Gneral Public License for more details.
148 You should have received a copy of the GNU General Public Licence along with
149 this file. If not see <http://www.gnu.org/licenses/>.