Commit | Line | Data |
---|---|---|
93b53499 SJ |
1 | <?php |
2 | /*************************************************************************** | |
ba6ae046 | 3 | * Copyright (C) 2003-2013 Polytechnique.org * |
93b53499 SJ |
4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
22 | require_once dirname(__FILE__) . '/../include/test.inc.php'; | |
23 | ||
24 | class CheckDB extends PlTestCase | |
25 | { | |
26 | private static function checkPlatal() | |
27 | { | |
28 | global $platal; | |
29 | if ($platal == null) | |
30 | { | |
31 | $platal = new Xorg(); | |
32 | } | |
33 | } | |
34 | ||
35 | public static function dbConsistancyProvider() | |
36 | { | |
37 | $testcases = array( | |
38 | 'hruid' => | |
39 | array('SELECT uid, full_name | |
40 | FROM accounts | |
41 | WHERE hruid IS NULL OR hruid = \'\''), | |
42 | ||
43 | 'hrpid' => | |
44 | array('SELECT p.pid, pd.public_name, pd.promo | |
45 | FROM profiles AS p | |
46 | LEFT JOIN profile_display AS pd ON (p.pid = pd.pid) | |
47 | WHERE p.hrpid IS NULL OR p.hrpid = \'\''), | |
48 | ||
49 | 'name' => | |
50 | array('SELECT p.pid, p.hrpid | |
51 | FROM profiles AS p | |
52 | INNER JOIN profile_name AS pn ON (p.pid = pn.pid) | |
53 | WHERE name = \'\''), | |
54 | ||
55 | 'phone formatting' => | |
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 | |
64 | LIMIT 1))'), | |
65 | ||
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) | |
1c305d4c | 70 | WHERE gc.country IS NULL OR gc.country = \'\''), |
93b53499 | 71 | |
90a2b1a7 SJ |
72 | 'missing nationalities' => |
73 | array('SELECT p.pid, p.nationality1, p.nationality2, p.nationality3 | |
74 | FROM profiles AS p | |
75 | LEFT JOIN geoloc_countries AS g1 ON (p.nationality1 = g1.iso_3166_1_a2) | |
76 | LEFT JOIN geoloc_countries AS g2 ON (p.nationality2 = g2.iso_3166_1_a2) | |
77 | LEFT JOIN geoloc_countries AS g3 ON (p.nationality3 = g3.iso_3166_1_a2) | |
1c305d4c SJ |
78 | WHERE (p.nationality1 IS NOT NULL AND (g1.nationality IS NULL OR g1.nationality = \'\')) |
79 | OR (p.nationality2 IS NOT NULL AND (g2.nationality IS NULL OR g2.nationality = \'\')) | |
80 | OR (p.nationality3 IS NOT NULL AND (g3.nationality IS NULL OR g3.nationality = \'\'))'), | |
90a2b1a7 | 81 | |
93b53499 SJ |
82 | 'ax_id' => |
83 | array('SELECT pid, hrpid, ax_id, COUNT(ax_id) AS c | |
84 | FROM profiles | |
85 | WHERE ax_id != \'0\' | |
86 | GROUP BY ax_id | |
87 | HAVING c > 1'), | |
88 | ||
89 | 'google apps' => | |
11a28184 SJ |
90 | array('SELECT s.email, g.g_status, r.redirect |
91 | FROM email_redirect_account AS r | |
92 | INNER JOIN email_source_account AS s ON (r.uid = s.uid AND s.type = \'forlife\') | |
93 | INNER JOIN gapps_accounts AS g ON (g.l_userid = r.uid) | |
94 | WHERE r.type = \'googleapps\' AND r.flags = \'active\' AND g.g_status != \'active\'') | |
93b53499 SJ |
95 | ); |
96 | ||
97 | $tests = array( | |
98 | 'profile_binet_enum' => 'text', | |
99 | 'profile_corps_enum' => 'name', | |
100 | 'profile_corps_rank_enum' => 'name', | |
101 | 'profile_education_degree_enum' => 'degree', | |
102 | 'profile_education_enum' => 'name', | |
103 | 'profile_education_field_enum' => 'field', | |
104 | 'profile_job_enum' => 'name', | |
93b53499 SJ |
105 | 'profile_langskill_enum' => 'langue_fr', |
106 | 'profile_medal_enum' => 'text', | |
107 | 'profile_name_enum' => 'name', | |
108 | 'profile_networking_enum' => 'name', | |
109 | 'profile_section_enum' => 'text', | |
110 | 'profile_skill_enum' => 'text_fr', | |
111 | 'groups' => 'nom', | |
112 | 'forums' => 'name', | |
113 | ); | |
114 | ||
115 | foreach ($tests as $table => $field) { | |
116 | $testcases[$table . ' description'] = | |
117 | array("SELECT * | |
118 | FROM $table | |
119 | WHERE $field IS NULL OR $field = ''"); | |
120 | } | |
121 | ||
122 | $tests = array( | |
123 | 'profiles' => array( | |
124 | 'freetext_pub' => array('public', 'private'), | |
125 | 'medals_pub' => array('public', 'private'), | |
126 | 'alias_pub' => array('public', 'private') | |
127 | ), | |
128 | 'profile_addresses' => array( | |
129 | 'pub' => array('public', 'ax', 'private') | |
130 | ), | |
131 | 'profile_corps' => array( | |
132 | 'corps_pub' => array('public', 'ax', 'private') | |
133 | ), | |
134 | 'profile_job' => array( | |
135 | 'pub' => array('public', 'ax', 'private'), | |
136 | 'email_pub' => array('public', 'ax', 'private') | |
137 | ), | |
138 | 'profile_networking' => array( | |
139 | 'pub' => array('public', 'private') | |
140 | ), | |
141 | 'profile_phones' => array( | |
142 | 'pub' => array('public', 'ax', 'private') | |
143 | ), | |
144 | 'profile_photos' => array( | |
145 | 'pub' => array('public', 'private') | |
146 | ), | |
147 | ); | |
148 | ||
149 | foreach ($tests as $table => $test) { | |
150 | $select = 'p.pid, p.hrpid'; | |
151 | $where = array();; | |
152 | foreach ($test as $field => $pubs) { | |
153 | $select .= ", t.$field"; | |
154 | $condition = array(); | |
155 | foreach ($pubs as $pub) { | |
156 | $condition[] = "t.$field != '$pub'"; | |
157 | } | |
158 | $where[] = '(' . implode(' AND ', $condition) . ')'; | |
159 | } | |
160 | $testcases[$table . ' publicity'] = | |
161 | array("SELECT $select | |
162 | FROM $table AS t | |
163 | INNER JOIN profiles AS p ON (t.pid = p.pid) | |
164 | WHERE " . implode(' OR ', $where)); | |
165 | } | |
166 | ||
167 | return $testcases; | |
168 | } | |
169 | ||
170 | /** | |
171 | * @dataProvider dbConsistancyProvider | |
172 | */ | |
173 | public function testDbConsistancy($query) | |
174 | { | |
175 | self::checkPlatal(); | |
176 | $res = XDB::query($query); | |
177 | $count = $res->numRows(); | |
178 | foreach ($res->fetchAllAssoc() as $key => $item) { | |
179 | echo "\n" . $key . " => {\n"; | |
180 | foreach ($item as $field => $value) { | |
181 | echo $field . ' => ' . $value . "\n"; | |
182 | } | |
183 | echo "}\n"; | |
184 | } | |
185 | $this->assertEquals(0, $count); | |
186 | } | |
187 | ||
188 | /* TODO: add check on foreign keys for every table! */ | |
189 | ||
190 | } | |
191 | ||
192 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
193 | ?> |