3 * Copyright (C) 2008 Alain Peyrat <aljeux@free.fr>
4 * Copyright (C) 2009 Alain Peyrat, Alcatel-Lucent
6 * This file is part of FusionForge.
8 * FusionForge is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published
10 * by the Free Software Foundation; either version 2 of the License,
11 * or (at your option) any later version.
13 * FusionForge is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with FusionForge; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 * Standard Alcatel-Lucent disclaimer for contributing to open source
27 * "The test suite ("Contribution") has not been tested and/or
28 * validated for release as or in products, combinations with products or
29 * other commercial use. Any use of the Contribution is entirely made at
30 * the user's own responsibility and the user can not rely on any features,
31 * functionalities or performances Alcatel-Lucent has attributed to the
34 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
35 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
36 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
37 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
38 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
39 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
40 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
41 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
42 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
47 * Create a initial database suitable for running the tests.
48 * The initial database is made of:
49 * The initial database given by the package.
50 * + An admin account (login: admin, password: myadmin)
51 * + A simple project (projectA)
54 ini_set('memory_limit', '16M');
56 $config = getenv('CONFIG_PHP') ? getenv('CONFIG_PHP'): dirname(__FILE__).'/config.php';
60 print "ERROR: File 'config.php' is not correctly configured, aborting.\n";
64 // Search location of fusionforge main directory (gforge).
65 $forge_root = dirname(dirname(dirname(__FILE__))).'/src';
66 if (!file_exists($forge_root)) {
67 $forge_root = dirname(dirname(dirname(__FILE__))).'/gforge';
68 if (!file_exists($forge_root)) {
69 $forge_root = '/usr/share/gforge';
70 if (!file_exists($forge_root)) {
71 $forge_root = '/opt/gforge';
72 if (!file_exists($forge_root)) {
73 print "ERROR: Unable to guess location of fusionforge main directory (gforge), aborting.\n";
80 if (!function_exists('pg_connect')) {
81 print "ERROR: Missing pgsql on PHP to run tests on PostgreSQL, aborting.\n";
85 system("echo \"DROP SCHEMA public CASCADE;CREATE SCHEMA public;\" | psql -q -Upostgres ".DB_NAME." > /var/log/fusionforge-init.log 2>&1");
86 system("echo \"GRANT ALL ON SCHEMA public TO ".DB_USER.";\" | psql -q -Upostgres ".DB_NAME." >> /var/log/fusionforge-init.log 2>&1");
88 system("psql -q -U".DB_USER." ".DB_NAME." -f $forge_root/db/gforge.sql >> /var/log/fusionforge-init.log 2>&1");
89 system("php $forge_root/db/upgrade-db.php >> /var/log/gforge-upgrade-db.log 2>&1");
91 $adminPassword = 'myadmin';
92 $adminEmail = 'nobody@nowhere.com';
94 $session_hash = '000TESTSUITE000';
96 require_once $forge_root.'/www/env.inc.php';
97 require_once $gfcommon.'include/pre.php';
99 $files = glob(dirname(__FILE__)."/sql/*.sql");
100 foreach ($files as $filename) {
101 system("psql -q -U".DB_USER." ".DB_NAME." -f $filename 2>&1 | grep -v ': NOTICE: ' | egrep -v '^(NOTICE|DETAIL:)' | egrep -v '^(Creating|Applying|Initializing) '");
104 system("echo \"VACUUM FULL ANALYZE;\" | psql -q -Upostgres ".DB_NAME);
107 // Create the initial admin account and activate it directly.
109 $user = new GFUser();
110 $user_id = $user->create('admin', 'Forge', 'Admin', $adminPassword, $adminPassword,
111 $adminEmail, 1, 1, 1,'GMT','',0,1,'', '','','','','','US',false);
114 print "ERROR: Creating user: ".$user->getErrorMessage().':'.db_error()."\n";
118 $user->setStatus('A');
121 print "ERROR: Error creating admin account, no id returned, aborting.\n";
123 // Register the user in master group to get full admin rights.
124 $res = db_query_params ('INSERT INTO user_group (user_id,group_id,admin_flags, role_id) VALUES ($1,1,$2,17)',
128 $res = db_query_params ('INSERT INTO pfo_user_role VALUES ($1, 3)',