1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) Enalean, 2012. All Rights Reserved. |
4
|
|
|
* |
5
|
|
|
* This file is a part of Tuleap. |
6
|
|
|
* |
7
|
|
|
* Tuleap is free software; you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* Tuleap is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with Tuleap. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
require_once 'common/dao/CodendiDataAccess.class.php'; |
22
|
|
|
require_once 'database.php'; |
23
|
|
|
|
24
|
|
|
// GRANT ALL PRIVILEGES on integration_test.* to 'integration_test'@'localhost' identified by 'welcome0'; |
25
|
|
|
abstract class TuleapDbTestCase extends TuleapTestCase { |
26
|
|
|
protected $mysqli; |
27
|
|
|
|
28
|
|
|
protected static $db_initialized = false; |
29
|
|
|
|
30
|
|
|
private $development_on_going = false; |
31
|
|
|
|
32
|
|
|
private $src_dir = ''; |
33
|
|
|
|
34
|
|
|
public function __construct() { |
35
|
|
|
parent::__construct(); |
36
|
|
|
$this->loadConfiguration(); |
37
|
|
|
$this->mysqli = mysqli_init(); |
38
|
|
|
if (!$this->mysqli->real_connect($GLOBALS['sys_dbhost'], $GLOBALS['sys_dbuser'], $GLOBALS['sys_dbpasswd'])) { |
39
|
|
|
$this->mysqli = false; |
40
|
|
|
} |
41
|
|
|
$this->src_dir = realpath(dirname(__FILE__)."/../.."); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function setUp() { |
45
|
|
|
parent::setUp(); |
46
|
|
|
ForgeConfig::set('DEBUG_MODE', true); |
47
|
|
|
if (self::$db_initialized == false) { |
|
|
|
|
48
|
|
|
self::$db_initialized = true; |
49
|
|
|
$this->initDb(); |
50
|
|
|
} |
51
|
|
|
$this->mysqli->select_db($GLOBALS['sys_dbname']); |
52
|
|
|
db_connect(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function skip() { |
56
|
|
|
parent::skip(); |
57
|
|
|
if (!$this->mysqli) { |
58
|
|
|
echo "== (屮ಠ益ಠ)屮 Y U NO CONFIGURE DATABASE? ==\n"; |
59
|
|
|
} |
60
|
|
|
$this->skipUnless($this->mysqli, '== (屮ಠ益ಠ)屮 Y U NO CONFIGURE DATABASE? =='); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function tearDown() { |
64
|
|
|
unset($GLOBALS['sys_dbhost']); |
65
|
|
|
unset($GLOBALS['sys_dbuser']); |
66
|
|
|
unset($GLOBALS['sys_dbpasswd']); |
67
|
|
|
unset($GLOBALS['sys_dbname']); |
68
|
|
|
parent::tearDown(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Use this method to flag your test as 'under development' |
73
|
|
|
* This will prevent drop of the database before tests and avoid become crasy |
74
|
|
|
* waiting for 50" test execution. |
75
|
|
|
*/ |
76
|
|
|
protected function markThisTestUnderDevelopment() { |
77
|
|
|
self::$db_initialized = true; |
78
|
|
|
$this->development_on_going = true; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
protected function thisTestIsNotUnderDevelopment() { |
82
|
|
|
return !$this->development_on_going; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Use this method if you need to drop the database after a test |
87
|
|
|
*/ |
88
|
|
|
protected function resetDatabase() { |
89
|
|
|
self::$db_initialized = false; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
protected function truncateTable($table) { |
94
|
|
|
$this->mysqli->query("TRUNCATE TABLE $table"); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Execute all statements of given file (bulk imports) |
99
|
|
|
* |
100
|
|
|
* @param String $file |
101
|
|
|
*/ |
102
|
|
|
protected function mysqlLoadFile($file) { |
103
|
|
|
$mysql_cmd = 'mysql -u'.$GLOBALS['sys_dbuser'].' -p'.$GLOBALS['sys_dbpasswd'].' '.$GLOBALS['sys_dbname']; |
104
|
|
|
$cmd = $mysql_cmd.' < '.$this->src_dir.'/'.$file; |
105
|
|
|
system($cmd); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
private function loadConfiguration() { |
109
|
|
|
$config_file = 'tests.inc'; |
110
|
|
|
ForgeConfig::loadFromFile(dirname(__FILE__)."/../../src/etc/$config_file.dist"); |
111
|
|
|
ForgeConfig::loadFromFile(dirname($this->getLocalIncPath())."/$config_file"); |
112
|
|
|
$GLOBALS['sys_dbhost'] = ForgeConfig::get('sys_dbhost'); |
113
|
|
|
$GLOBALS['sys_dbuser'] = ForgeConfig::get('sys_dbuser'); |
114
|
|
|
$GLOBALS['sys_dbpasswd'] = ForgeConfig::get('sys_dbpasswd'); |
115
|
|
|
$GLOBALS['sys_dbname'] = ForgeConfig::get('sys_dbname'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
private function getLocalIncPath() { |
119
|
|
|
return getenv('CODENDI_LOCAL_INC') ? getenv('CODENDI_LOCAL_INC') : '/etc/codendi/conf/local.inc'; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
private function foraceCreateDatabase() { |
123
|
|
|
$this->mysqli->query("DROP DATABASE IF EXISTS ".$GLOBALS['sys_dbname']); |
124
|
|
|
$this->mysqli->query("CREATE DATABASE ".$GLOBALS['sys_dbname']); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
protected function initDb() { |
128
|
|
|
$this->foraceCreateDatabase(); |
129
|
|
|
$this->mysqlLoadFile('src/db/mysql/database_structure.sql'); |
130
|
|
|
$this->mysqlLoadFile('src/db/mysql/database_initvalues.sql'); |
131
|
|
|
$this->mysqlLoadFile('src/db/mysql/trackerv3structure.sql'); |
132
|
|
|
$this->mysqlLoadFile('src/db/mysql/trackerv3values.sql'); |
133
|
|
|
$this->mysqlLoadFile('plugins/tracker_date_reminder/db/install.sql'); |
134
|
|
|
$this->mysqlLoadFile('plugins/tracker_date_reminder/db/examples.sql'); |
135
|
|
|
$this->mysqlLoadFile('plugins/graphontrackers/db/install.sql'); |
136
|
|
|
$this->mysqlLoadFile('plugins/graphontrackers/db/initvalues.sql'); |
137
|
|
|
$this->mysqlLoadFile('plugins/tracker/db/install.sql'); |
138
|
|
|
$this->mysqlLoadFile('plugins/graphontrackersv5/db/install.sql'); |
139
|
|
|
$this->mysqlLoadFile('plugins/statistics/db/install.sql'); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
?> |
144
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.