2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 require_once dirname(__FILE__
) . '/../include/test.inc.php';
24 class CheckDB
extends PlTestCase
26 private static function checkPlatal()
35 public static function dbConsistancyProvider()
39 array('SELECT uid, full_name
41 WHERE hruid IS NULL OR hruid = \'\''),
44 array('SELECT p.pid, pd.public_name, pd.promo
46 LEFT JOIN profile_display AS pd ON (p.pid = pd.pid)
47 WHERE p.hrpid IS NULL OR p.hrpid = \'\''),
50 array('SELECT p.pid, p.hrpid
52 INNER JOIN profile_name AS pn ON (p.pid = pn.pid)
56 array('SELECT DISTINCT g.phonePrefix
57 FROM geoloc_countries AS g
58 WHERE EXISTS (SELECT h.phonePrefix
59 FROM geoloc_countries AS h
60 WHERE h.phonePrefix = g.phonePrefix
61 AND h.phoneFormat != (SELECT i.phoneFormat
62 FROM geoloc_countries AS i
63 WHERE i.phonePrefix = g.phonePrefix
66 'missing countries' =>
67 array('SELECT pa.pid, pa.countryId
68 FROM profile_addresses AS pa
69 LEFT JOIN geoloc_countries AS gc ON (pa.countryId = gc.iso_3166_1_a2)
70 WHERE gc.countryFR IS NULL OR gc.countryFR = \'\''),
73 array('SELECT pid, hrpid, ax_id, COUNT(ax_id) AS c
80 array('SELECT a.alias, g.g_status, eo.storage
81 FROM email_options AS eo
82 INNER JOIN aliases AS a ON (a.uid = eo.uid AND a.type = \'a_vie\')
83 INNER JOIN gapps_accounts AS g ON (g.l_userid = eo.uid)
84 WHERE FIND_IN_SET(\'googleapps\', eo.storage) > 0 AND g.g_status != \'active\'')
88 'profile_binet_enum' => 'text',
89 'profile_corps_enum' => 'name',
90 'profile_corps_rank_enum' => 'name',
91 'profile_education_degree_enum' => 'degree',
92 'profile_education_enum' => 'name',
93 'profile_education_field_enum' => 'field',
94 'profile_job_enum' => 'name',
95 'profile_job_sector_enum' => 'name',
96 'profile_job_subsector_enum' => 'name',
97 'profile_job_subsubsector_enum' => 'name',
98 'profile_langskill_enum' => 'langue_fr',
99 'profile_medal_enum' => 'text',
100 'profile_name_enum' => 'name',
101 'profile_networking_enum' => 'name',
102 'profile_section_enum' => 'text',
103 'profile_skill_enum' => 'text_fr',
108 foreach ($tests as $table => $field) {
109 $testcases[$table . ' description'] =
112 WHERE $field IS NULL OR $field = ''");
117 'freetext_pub' => array('public', 'private'),
118 'medals_pub' => array('public', 'private'),
119 'alias_pub' => array('public', 'private')
121 'profile_addresses' => array(
122 'pub' => array('public', 'ax', 'private')
124 'profile_corps' => array(
125 'corps_pub' => array('public', 'ax', 'private')
127 'profile_job' => array(
128 'pub' => array('public', 'ax', 'private'),
129 'email_pub' => array('public', 'ax', 'private')
131 'profile_networking' => array(
132 'pub' => array('public', 'private')
134 'profile_phones' => array(
135 'pub' => array('public', 'ax', 'private')
137 'profile_photos' => array(
138 'pub' => array('public', 'private')
142 foreach ($tests as $table => $test) {
143 $select = 'p.pid, p.hrpid';
145 foreach ($test as $field => $pubs) {
146 $select .= ", t.$field";
147 $condition = array();
148 foreach ($pubs as $pub) {
149 $condition[] = "t.$field != '$pub'";
151 $where[] = '(' . implode(' AND ', $condition) . ')';
153 $testcases[$table . ' publicity'] =
154 array("SELECT $select
156 INNER JOIN profiles AS p ON (t.pid = p.pid)
157 WHERE " . implode(' OR ', $where));
164 * @dataProvider dbConsistancyProvider
166 public function testDbConsistancy($query)
169 $res = XDB
::query($query);
170 $count = $res->numRows();
171 foreach ($res->fetchAllAssoc() as $key => $item) {
172 echo "\n" . $key . " => {\n";
173 foreach ($item as $field => $value) {
174 echo $field . ' => ' . $value . "\n";
178 $this->assertEquals(0, $count);
181 /* TODO: add check on foreign keys for every table! */
185 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: