1768 |
raphael |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
$options = getopt("hu:d:e:p:P:",array("help", "user:", "domain:", "email:", "pass:", "phpsessid"));
|
|
|
4 |
if(isset($options['h']) || isset($options['help'])) {
|
|
|
5 |
die(basename(__FILE__) . ' [-u|--user = 22506] [-d|--domain = http://cel]');
|
|
|
6 |
}
|
|
|
7 |
|
|
|
8 |
define('USER', isset($options['u']) ? $options['u'] : (isset($options['user']) ? $options['user'] : 22506));
|
|
|
9 |
define('DOMAIN', isset($options['d']) ? $options['d'] : (isset($options['domain']) ? $options['domain'] : 'http://cel'));
|
|
|
10 |
define('EMAIL', isset($options['e']) ? $options['e'] : (isset($options['email']) ? $options['email'] : NULL));
|
|
|
11 |
define('PASS', isset($options['p']) ? $options['p'] : (isset($options['pass']) ? $options['pass'] : NULL));
|
|
|
12 |
define('COOKIE', isset($options['P']) ? $options['P'] : (isset($options['phpsessid']) ? $options['phpsessid'] : NULL));
|
|
|
13 |
|
|
|
14 |
require_once('api.php');
|
|
|
15 |
|
|
|
16 |
function setupTestEnv() {
|
|
|
17 |
cel_delete_all_obs();
|
|
|
18 |
cel_delete_all_images();
|
|
|
19 |
cel_upload_image('image-test.jpg');
|
|
|
20 |
cel_upload_image('image-test2.jpg');
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
if(! is_dir('phptests')) die('no phptests/');
|
|
|
24 |
if(! is_dir('run')) mkdir('run');
|
|
|
25 |
if(! is_dir('run')) die('no run/');
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
$all_tests = glob('phptests/*.test.php');
|
|
|
29 |
$tests = array_intersect($argv, $all_tests);
|
|
|
30 |
if(!$tests) $tests = $all_tests;
|
|
|
31 |
|
|
|
32 |
foreach($tests as $test) {
|
|
|
33 |
setupTestEnv();
|
|
|
34 |
// cache car l'upload de fichier PHP-curl ne peut ĂȘtre
|
|
|
35 |
// simulé avec le contenu d'une variable (cf CURLOPT_POSTFIELDS et @fichier)
|
|
|
36 |
$runfile = 'run/' . basename($test);
|
|
|
37 |
if(!is_file($runfile)) {
|
|
|
38 |
$csv = genCSV(require($test));
|
|
|
39 |
file_put_contents($runfile, $csv);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
$var_expected = include(str_replace('.test.', '.result.', $test));
|
|
|
43 |
|
|
|
44 |
$retour = import($runfile);
|
|
|
45 |
$count_warn = 0;
|
|
|
46 |
preg_match('/^ligne /', $retour, $count_warn);
|
|
|
47 |
$count_warn = count($count_warn);
|
|
|
48 |
|
|
|
49 |
echo $count_warn . "\n";
|
|
|
50 |
$result = getCSV_line(export(), 1);
|
|
|
51 |
unset($result['date_creation'], $result['date_modification'], $result['id_observation']);
|
|
|
52 |
|
|
|
53 |
echo "$test\n";
|
|
|
54 |
if($var_expected) {
|
|
|
55 |
if(! array_diff($var_expected, $result) && ! array_diff($result, $var_expected)) echo "OK\n";
|
|
|
56 |
else {
|
|
|
57 |
echo "FAIL\n";
|
|
|
58 |
//var_dump($var_expected, $result);
|
|
|
59 |
var_dump(array_diff($var_expected, $result), array_diff($result, $var_expected));
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
else {
|
|
|
63 |
echo '<?php return ' . var_export($result, true) . ';'
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
// sed -i -e '1{/<?php return/!s:^:<?php return :}' -e '${/^)$/s:$:;:}' phptests/*.result.php
|