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 along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * Standard Alcatel-Lucent disclaimer for contributing to open source
26 * "The test suite ("Contribution") has not been tested and/or
27 * validated for release as or in products, combinations with products or
28 * other commercial use. Any use of the Contribution is entirely made at
29 * the user's own responsibility and the user can not rely on any features,
30 * functionalities or performances Alcatel-Lucent has attributed to the
33 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
34 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
35 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
36 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
37 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
38 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
39 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
41 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
46 * Create a initial database suitable for running the tests.
47 * The initial database is made of:
48 * The initial database given by the package.
49 * + An admin account (login: admin, password: myadmin)
50 * + A simple project (projectA)
53 ini_set('memory_limit', '16M');
55 $config = getenv('CONFIG_PHP') ? getenv('CONFIG_PHP'): dirname(__FILE__).'/config.php';
59 print "ERROR: File 'config.php' is not correctly configured, aborting.\n";
63 // Search location of fusionforge main directory (gforge).
64 $forge_root = dirname(dirname(dirname(__FILE__))).'/src';
65 if (!file_exists($forge_root)) {
66 $forge_root = dirname(dirname(dirname(__FILE__))).'/gforge';
67 if (!file_exists($forge_root)) {
68 $forge_root = '/usr/share/gforge';
69 if (!file_exists($forge_root)) {
70 $forge_root = '/opt/gforge';
71 if (!file_exists($forge_root)) {
72 print "ERROR: Unable to guess location of fusionforge main directory (gforge), aborting.\n";
79 if (!function_exists('pg_connect')) {
80 print "ERROR: Missing pgsql on PHP to run tests on PostgreSQL, aborting.\n";
84 system("echo \"DROP SCHEMA public CASCADE;CREATE SCHEMA public;\" | psql -q -Upostgres ".DB_NAME." > /var/log/fusionforge-init.log 2>&1");
85 system("echo \"GRANT ALL ON SCHEMA public TO ".DB_USER.";\" | psql -q -Upostgres ".DB_NAME." >> /var/log/fusionforge-init.log 2>&1");
87 system("psql -q -U".DB_USER." ".DB_NAME." -f $forge_root/db/gforge.sql >> /var/log/fusionforge-init.log 2>&1");
88 system("php $forge_root/db/upgrade-db.php >> /var/log/gforge-upgrade-db.log 2>&1");
90 $session_hash = '000TESTSUITE000';
92 require_once $forge_root.'/www/env.inc.php';
93 require_once $gfcommon.'include/pre.php';
95 $files = glob(dirname(__FILE__)."/sql/*.sql");
96 foreach ($files as $filename) {
97 system("psql -q -U".DB_USER." ".DB_NAME." -f $filename 2>&1 | grep -v ': NOTICE: ' | egrep -v '^(NOTICE|DETAIL:)' | egrep -v '^(Creating|Applying|Initializing) '");
100 system("echo \"VACUUM FULL ANALYZE;\" | psql -q -Upostgres ".DB_NAME);
103 // Create the initial admin account and activate it directly.
105 $user = new GFUser();
107 $user_id = $user->create(FORGE_ADMIN_USERNAME, 'Forge', 'Admin', FORGE_ADMIN_PASSWORD, FORGE_ADMIN_PASSWORD,
108 'nobody@nowhere.com', 1, 1, 1,'GMT','',0,1,'', '','','','','','US',false);
111 print "ERROR: Creating user: ".$user->getErrorMessage().':'.db_error()."\n";
115 $user->setStatus('A');
118 print "ERROR: Error creating admin account, no id returned, aborting.\n";
120 // Register the user in master group to get full admin rights.
121 $res = db_query_params ('INSERT INTO user_group (user_id,group_id,admin_flags, role_id) VALUES ($1,1,$2,17)',
125 $res = db_query_params ('INSERT INTO pfo_user_role VALUES ($1, 3)',