]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/tests/units/Class/ConfigurationManagerApplicationSettingsTest.php
Add more debug to recycle-test
[bacula/bacula] / gui / baculum / tests / units / Class / ConfigurationManagerApplicationSettingsTest.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2015 Marcin Haba
7  *
8  * The main author of Baculum is Marcin Haba.
9  * The original author of Bacula is Kern Sibbald, with contributions
10  * from many others, a complete list can be found in the file AUTHORS.
11  *
12  * You may use this file and others of this release according to the
13  * license defined in the LICENSE file, which includes the Affero General
14  * Public License, v3.0 ("AGPLv3") and some additional permissions and
15  * terms pursuant to its AGPLv3 Section 7.
16  *
17  * This notice must be preserved when any source code is
18  * conveyed and/or propagated.
19  *
20  * Bacula(R) is a registered trademark of Kern Sibbald.
21  */
22
23 require_once('test_common.php');
24
25 /**
26  * Test cases to read/write/check Baculum configuration file (settings.conf).
27  *
28  * @author Marcin Haba
29  */
30 class ConfigurationManagerApplicationSettingsTest extends PHPUnit_Framework_TestCase {
31
32         public static $application = null;
33
34         public function setUp() {
35                 if (self::$application === null) {
36                         self::$application = new TApplicationTest(BACULUM_ROOT_DIR . 'protected');
37                         self::$application->run();
38                 }
39                 if (file_exists(BACULUM_ROOT_DIR . 'protected/Data')) {
40                         copy_path(BACULUM_ROOT_DIR . 'protected/Data', BACKUP_FILES_PATH);
41                         remove_path(BACULUM_ROOT_DIR . 'protected/Data', true);
42                 }
43         }
44
45         public function tearDown() {
46                 if (file_exists(BACKUP_FILES_PATH)) {
47                         remove_path(BACKUP_FILES_PATH . 'protected/Data', true);
48                         copy_path(BACKUP_FILES_PATH, BACULUM_ROOT_DIR . 'protected/Data');
49                         remove_path(BACKUP_FILES_PATH);
50                 }
51         }
52
53         public function testSetApplicationConfigPostgreSQL() {
54                 $testData = array('db' => array(), 'bconsole' => array(), 'baculum' => array());
55                 $testData['db']['type'] = 'pgsql';
56                 $testData['db']['name'] = 'my database 123';
57                 $testData['db']['login'] = 'admin321';
58                 $testData['db']['password'] = 'Str0NgPa$$w0Rd';
59                 $testData['db']['ip_addr'] = '127.0.0.1';
60                 $testData['db']['port'] = '5433';
61                 $testData['db']['path'] = '';
62                 $testData['bconsole']['bin_path'] = '/usr/local/bacula/sbin/bconsole';
63                 $testData['bconsole']['cfg_path'] = '/usr/local/bacula/etc/bconsole.conf';
64                 $testData['bconsole']['cfg_custom_path'] = '/etc/bacula/bconsole-{user}.conf';
65                 $testData['bconsole']['use_sudo'] = 1;
66                 $testData['baculum']['login'] = 'ganiuszka';
67                 $testData['baculum']['password'] = 'AnOTHe3Str0n6 Pass W OR d';
68                 $testData['baculum']['debug'] = 0;
69                 $testData['baculum']['lang'] = 'pl';
70                 $resultContent = '[db]
71 type = "pgsql"
72 name = "my database 123"
73 login = "admin321"
74 password = "Str0NgPa$$w0Rd"
75 ip_addr = "127.0.0.1"
76 port = "5433"
77 path = ""
78
79 [bconsole]
80 bin_path = "/usr/local/bacula/sbin/bconsole"
81 cfg_path = "/usr/local/bacula/etc/bconsole.conf"
82 cfg_custom_path = "/etc/bacula/bconsole-{user}.conf"
83 use_sudo = "1"
84
85 [baculum]
86 login = "ganiuszka"
87 password = "AnOTHe3Str0n6 Pass W OR d"
88 debug = "0"
89 lang = "pl"
90
91 ';
92                 // check if config does not exist
93                 $result = self::$application->getModule('configuration')->isApplicationConfig();
94                 $this->assertFalse($result);
95
96                 // check saving config
97                 self::$application->getModule('configuration')->setApplicationConfig($testData);
98                 $result = file_get_contents(BACULUM_ROOT_DIR . 'protected/Data/settings.conf');
99                 // compare written config with expected string
100                 $this->assertEquals($resultContent, $result);
101
102                 // check if config already exists
103                 $result = self::$application->getModule('configuration')->isApplicationConfig();
104                 $this->assertTrue($result);
105
106                 // check reading config
107                 $configRead = self::$application->getModule('configuration')->getApplicationConfig();
108                 // compare test data array with read application config as array
109                 $this->assertEquals($testData, $configRead);
110         }
111
112         public function testSetApplicationConfigMySQL() {
113                 $testData = array('db' => array(), 'bconsole' => array(), 'baculum' => array());
114                 $testData['db']['type'] = 'mysql';
115                 $testData['db']['name'] = 'mydatabase538';
116                 $testData['db']['login'] = 'administrator';
117                 $testData['db']['password'] = '#Str0NgPa$##$w0Rd^$#!&#*$@';
118                 $testData['db']['ip_addr'] = '192.168.0.4';
119                 $testData['db']['port'] = '3306';
120                 $testData['db']['path'] = '';
121                 $testData['bconsole']['bin_path'] = '/usr/local/bacula/sbin/bconsole';
122                 $testData['bconsole']['cfg_path'] = '/usr/local/bacula/etc/bconsole.conf';
123                 $testData['bconsole']['cfg_custom_path'] = '/etc/bacula/bconsole-{user}.conf';
124                 $testData['bconsole']['use_sudo'] = 0;
125                 $testData['baculum']['login'] = 'ganiuszka';
126                 $testData['baculum']['password'] = 'Str0n6 Pass4W2OR d';
127                 $testData['baculum']['debug'] = 1;
128                 $testData['baculum']['lang'] = 'en';
129                 $resultContent = '[db]
130 type = "mysql"
131 name = "mydatabase538"
132 login = "administrator"
133 password = "#Str0NgPa$##$w0Rd^$#!&#*$@"
134 ip_addr = "192.168.0.4"
135 port = "3306"
136 path = ""
137
138 [bconsole]
139 bin_path = "/usr/local/bacula/sbin/bconsole"
140 cfg_path = "/usr/local/bacula/etc/bconsole.conf"
141 cfg_custom_path = "/etc/bacula/bconsole-{user}.conf"
142 use_sudo = "0"
143
144 [baculum]
145 login = "ganiuszka"
146 password = "Str0n6 Pass4W2OR d"
147 debug = "1"
148 lang = "en"
149
150 ';
151
152                 // check if config does not exist
153                 $result = self::$application->getModule('configuration')->isApplicationConfig();
154                 $this->assertFalse($result);
155
156                 // check saving config
157                 self::$application->getModule('configuration')->setApplicationConfig($testData);
158                 $result = file_get_contents(BACULUM_ROOT_DIR . 'protected/Data/settings.conf');
159                 // compare written config with expected string
160                 $this->assertEquals($resultContent, $result);
161
162                 // check if config already exists
163                 $result = self::$application->getModule('configuration')->isApplicationConfig();
164                 $this->assertTrue($result);
165
166                 // check reading config
167                 $configRead = self::$application->getModule('configuration')->getApplicationConfig();
168                 // compare test data array with read application config as array
169                 $this->assertEquals($testData, $configRead);
170         }
171
172         public function testSetApplicationConfigSQLite() {
173                 $testData = array('db' => array(), 'bconsole' => array(), 'baculum' => array());
174                 $testData['db']['type'] = 'sqlite';
175                 $testData['db']['name'] = 'bacula';
176                 $testData['db']['login'] = 'bacula';
177                 $testData['db']['password'] = '';
178                 $testData['db']['ip_addr'] = '';
179                 $testData['db']['port'] = '';
180                 $testData['db']['path'] = '/home/gani/mydatabase.db';
181                 $testData['bconsole']['bin_path'] = '/usr/local/bacula/sbin/bconsole';
182                 $testData['bconsole']['cfg_path'] = '/usr/local/bacula/etc/bconsole.conf';
183                 $testData['bconsole']['cfg_custom_path'] = '/etc/bacula/users/bconsole-{user}.conf';
184                 $testData['bconsole']['use_sudo'] = 0;
185                 $testData['baculum']['login'] = 'kekeke';
186                 $testData['baculum']['password'] = 'kekeke';
187                 $testData['baculum']['debug'] = 1;
188                 $testData['baculum']['lang'] = 'en';
189                 $resultContent = '[db]
190 type = "sqlite"
191 name = "bacula"
192 login = "bacula"
193 password = ""
194 ip_addr = ""
195 port = ""
196 path = "/home/gani/mydatabase.db"
197
198 [bconsole]
199 bin_path = "/usr/local/bacula/sbin/bconsole"
200 cfg_path = "/usr/local/bacula/etc/bconsole.conf"
201 cfg_custom_path = "/etc/bacula/users/bconsole-{user}.conf"
202 use_sudo = "0"
203
204 [baculum]
205 login = "kekeke"
206 password = "kekeke"
207 debug = "1"
208 lang = "en"
209
210 ';
211                 // check if config does not exist
212                 $result = self::$application->getModule('configuration')->isApplicationConfig();
213                 $this->assertFalse($result);
214
215                 // check saving config
216                 self::$application->getModule('configuration')->setApplicationConfig($testData);
217                 $result = file_get_contents(BACULUM_ROOT_DIR . 'protected/Data/settings.conf');
218                 // compare written config with expected string
219                 $this->assertEquals($resultContent, $result);
220
221                 // check if config already exists
222                 $result = self::$application->getModule('configuration')->isApplicationConfig();
223                 $this->assertTrue($result);
224
225                 // check reading config
226                 $configRead = self::$application->getModule('configuration')->getApplicationConfig();
227                 // compare test data array with read application config as array
228                 $this->assertEquals($testData, $configRead);
229         }
230 }
231 ?>