need to specify use of onsetDate as member function rather than global
[openemr.git] / Tests / InstallerTest.php
blobe7439dcb610f1fd41c6bf37e372cec7f23834ba4
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 'loginhost' => 'localhost',
23 'port' => '3306',
24 'root' => 'root',
25 'rootpass' => 'notapass',
26 'dbname' => 'openemr_test_suite',
27 'collate' => '',
28 'site' => 'default',
30 $this->installer = new Installer( $this->post_variables );
33 public function testAttributes()
35 foreach ($this->post_variables as $attribute => $value) {
36 $this->assertEquals( $value, $this->installer->$attribute, "fetching $attribute from Installer object" );
40 public function testFilePaths()
42 $this->assertFileExists( $this->installer->conffile );
43 $this->assertFileExists( $this->installer->gaclSetupScript1 );
44 $this->assertFileExists( $this->installer->gaclSetupScript2 );
47 /**
48 * @dataProvider loginValidatorData
50 public function testLoginValidator( $login, $expected_return )
52 $post_variables = $this->post_variables;
53 $post_variables['login'] = $login;
54 $installer = new Installer( $post_variables );
55 $this->assertEquals($expected_return, $installer->login_is_valid(), "testing login: '$login'" );
58 /* dataProvider for testLoginValidator */
59 public static function loginValidatorData() {
60 return array( array( 'boris', TRUE ),
61 array( '', FALSE )
65 public function testIuserValidator()
67 $this->assertEquals(TRUE, $this->installer->iuser_is_valid());
70 public function testIuserIsInvalid()
72 $post_variables = $this->post_variables;
73 $post_variables['iuser'] = 'initial user';
74 $installer = new Installer( $post_variables );
76 $this->assertEquals(FALSE, $installer->iuser_is_valid());
79 public function testPasswordValidator()
81 $this->assertEquals(TRUE, $this->installer->password_is_valid());
84 public function testPasswordIsInvalid()
86 $post_variables = $this->post_variables;
87 $post_variables['pass'] = '';
88 $installer = new Installer( $post_variables );
90 $this->assertEquals(FALSE, $installer->password_is_valid());
93 public function testRootDatabaseConnection()
95 $this->assertEquals(TRUE, $this->installer->root_database_connection(), 'creating root database connection' );
98 public function testGaclFilesExist()
100 $this->assertFileExists( $this->installer->gaclSetupScript1, $this->installer->gaclSetupScript1 );
101 $this->assertFileExists( $this->installer->gaclSetupScript2, $this->installer->gaclSetupScript2 );
104 public function testUserDatabaseConnection()
106 $rootdbh = $this->installer->root_database_connection();
107 $this->installer->drop_database(); // may or may not exist.
108 $this->assertEquals(TRUE, $this->installer->create_database(), 'creating user database' );
109 $this->assertEquals(TRUE, $this->installer->grant_privileges(), 'granting privileges' );
110 $this->assertEquals(TRUE, $this->installer->user_database_connection(), 'creating user database connection' );
113 public function testDumpfiles()
115 $rootdbh = $this->installer->root_database_connection();
116 $this->installer->drop_database(); // may or may not exist.
117 $this->assertEquals(TRUE, $this->installer->create_database(), 'creating user database' );
118 $this->assertEquals(TRUE, $this->installer->grant_privileges(), 'granting privileges' );
119 $this->assertEquals(TRUE, $this->installer->user_database_connection(), 'creating user database connection' );
120 $dumpresults = $this->installer->load_dumpfiles();
121 $this->assertEquals(TRUE, $dumpresults, 'installing dumpfiles' );
124 // public function testGacl()
125 // {
126 // $rootdbh = $this->installer->root_database_connection();
127 // $this->installer->drop_database(); // may or may not exist.
128 // $this->assertEquals(TRUE, $this->installer->create_database(), 'creating user database' );
129 // $this->assertEquals(TRUE, $this->installer->grant_privileges(), 'granting privileges' );
130 // $this->assertEquals(TRUE, $this->installer->user_database_connection(), 'creating user database connection' );
131 // $dumpresults = $this->installer->load_dumpfiles();
132 // $this->assertEquals(TRUE, $dumpresults, 'installing dumpfiles' );
133 // $user_results = $this->installer->add_initial_user();
134 // $this->installer->install_gacl();
135 // $this->installer->configure_gacl();
136 // }
138 public function testConfFile()
140 $this->assertEquals( TRUE, $this->installer->write_configuration_file(), 'wrote configuration file' );
143 public function tearDown()
145 $installer = $this->installer;
146 $installer->drop_database();
151 This file is free software: you can redistribute it and/or modify it under the
152 terms of the GNU General Public License as publish by the Free Software
153 Foundation.
155 This file is distributed in the hope that it will be useful, but WITHOUT ANY
156 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
157 PARTICULAR PURPOSE. See the GNU Gneral Public License for more details.
159 You should have received a copy of the GNU General Public Licence along with
160 this file. If not see <http://www.gnu.org/licenses/>.