| Line 3... |
Line 3... |
| 3 |
$options = getopt("hu:d:e:p:P:D",array("help", "user:", "domain:", "email:", "pass:", "phpsessid", "debug"));
|
3 |
$options = getopt("hu:d:e:p:P:D",array("help", "user:", "domain:", "email:", "pass:", "phpsessid", "debug"));
|
| 4 |
if(isset($options['h']) || isset($options['help'])) {
|
4 |
if(isset($options['h']) || isset($options['help'])) {
|
| 5 |
printf(<<<EOF
|
5 |
printf(<<<EOF
|
| 6 |
%s [fichiers de test]
|
6 |
%s [fichiers de test]
|
| 7 |
--help|-h: cette aide
|
7 |
--help|-h: cette aide
|
| 8 |
-debug|-d: informations sur les requêtes curl
|
8 |
-debug|-D: informations sur les requêtes curl
|
| 9 |
[-u|--user = 22506]
|
9 |
[-u|--user = 22506]
|
| 10 |
[-d|--domain = "http://cel"]
|
10 |
[-d|--domain = "http://cel"]
|
| 11 |
--pass|-p: pour l'authentifiation
|
11 |
--pass|-p: pour l'authentifiation
|
| 12 |
--email|-e: pour l'authentifiation
|
12 |
--email|-e: pour l'authentifiation
|
| 13 |
--phpsessid|-P: pour l'authentifiation, alternative à -e/-p
|
13 |
--phpsessid|-P: pour l'authentifiation, alternative à -e/-p
|
| Line 22... |
Line 22... |
| 22 |
Exemple:
|
22 |
Exemple:
|
| 23 |
$ php IO-fields-unittest.php -P s97knu4axzi6440n1ihja9ppk1
|
23 |
$ php IO-fields-unittest.php -P s97knu4axzi6440n1ihja9ppk1
|
| 24 |
$ php IO-fields-unittest.php -e me@tela -p blah -u 23004 -d http://localhost phptests/determ-espece*
|
24 |
$ php IO-fields-unittest.php -e me@tela -p blah -u 23004 -d http://localhost phptests/determ-espece*
|
| Line 25... |
Line 25... |
| 25 |
|
25 |
|
| - |
|
26 |
Attention: lancer un test supprime TOUTES les observations existantes de l'utilisateur !
|
| 26 |
Attention: lancer un test supprime TOUTES les observations existantes de l'utilisateur !
|
27 |
|
| 27 |
EOF
|
28 |
EOF
|
| 28 |
, /* relax emacs*/
|
29 |
, /* relax emacs*/
|
| 29 |
basename(__FILE__));
|
30 |
basename(__FILE__));
|
| 30 |
die;
|
31 |
die;
|
| Line 33... |
Line 34... |
| 33 |
// stocke les test
|
34 |
// stocke les test
|
| 34 |
define('_TESTDIR', dirname(__FILE__) . '/' . 'phptests');
|
35 |
define('_TESTDIR', dirname(__FILE__) . '/' . 'phptests');
|
| 35 |
// stocke les CSV générés à partir des test (répertoire de cache)
|
36 |
// stocke les CSV générés à partir des test (répertoire de cache)
|
| 36 |
define('_RUNDIR', dirname(__FILE__) . '/' . 'run');
|
37 |
define('_RUNDIR', dirname(__FILE__) . '/' . 'run');
|
| Line 37... |
Line -... |
| 37 |
|
- |
|
| 38 |
define('USER', isset($options['u']) ? $options['u'] : (isset($options['user']) ? $options['user'] : 22506));
|
38 |
|
| 39 |
define('DOMAIN', isset($options['d']) ? $options['d'] : (isset($options['domain']) ? $options['domain'] : 'http://cel'));
|
39 |
define('DOMAIN', isset($options['d']) ? $options['d'] : (isset($options['domain']) ? $options['domain'] : 'http://cel'));
|
| 40 |
define('EMAIL', isset($options['e']) ? $options['e'] : (isset($options['email']) ? $options['email'] : NULL));
|
40 |
define('EMAIL', isset($options['e']) ? $options['e'] : (isset($options['email']) ? $options['email'] : NULL));
|
| 41 |
define('PASS', isset($options['p']) ? $options['p'] : (isset($options['pass']) ? $options['pass'] : NULL));
|
- |
|
| 42 |
define('COOKIE', isset($options['P']) ? $options['P'] : (isset($options['phpsessid']) ? $options['phpsessid'] : NULL));
|
41 |
define('PASS', isset($options['p']) ? $options['p'] : (isset($options['pass']) ? $options['pass'] : NULL));
|
| Line -... |
Line 42... |
| - |
|
42 |
define('DEBUG', isset($options['D']) ? 1 : (isset($options['debug']) ? 1 : 0));
|
| - |
|
43 |
|
| - |
|
44 |
// could be defined by the API::auth()
|
| - |
|
45 |
if(isset($options['u']) || isset($options['user'])) {
|
| - |
|
46 |
define('USER', isset($options['u']) ? $options['u'] : $options['user']);
|
| - |
|
47 |
}
|
| - |
|
48 |
|
| - |
|
49 |
// could be defined by the API::auth()
|
| - |
|
50 |
if(isset($options['P']) || isset($options['phpsessid'])) {
|
| - |
|
51 |
define('COOKIE', isset($options['P']) ? $options['P'] : $options['phpsessid']);
|
| 43 |
define('DEBUG', isset($options['D']) ? 1 : (isset($options['debug']) ? 1 : 0));
|
52 |
}
|
| - |
|
53 |
|
| - |
|
54 |
//require_once('api.php');
|
| - |
|
55 |
require_once('api-old.php');
|
| - |
|
56 |
|
| - |
|
57 |
if(!auth()) {
|
| Line 44... |
Line 58... |
| 44 |
|
58 |
die('auth problem');
|
| 45 |
require_once('api.php');
|
59 |
}
|
| 46 |
|
60 |
|
| 47 |
function setupTestEnv() {
|
61 |
function setupTestEnv() {
|
| Line 77... |
Line 91... |
| 77 |
if(!is_file($runfile) || filemtime($runfile) < filemtime($testfile)) {
|
91 |
if(!is_file($runfile) || filemtime($runfile) < filemtime($testfile)) {
|
| 78 |
$csv = genCSV($test_array['data']);
|
92 |
$csv = genCSV($test_array['data']);
|
| 79 |
file_put_contents($runfile, $csv);
|
93 |
file_put_contents($runfile, $csv);
|
| 80 |
}
|
94 |
}
|
| Line 81... |
Line 95... |
| 81 |
|
95 |
|
| 82 |
echo "\tcurl -F \"upload=@$runfile\" -F utilisateur=" . USER . " \"" . DOMAIN . "/jrest/ImportXLS\"\n";
|
96 |
//echo "\tcurl -F \"upload=@$runfile\" -F utilisateur=" . USER . " \"" . DOMAIN . "/jrest/ImportXLS\"\n";
|
| 83 |
echo "$test: ";
|
97 |
echo "$test: ";
|
| Line 84... |
Line 98... |
| 84 |
$var_expected = include(_TESTDIR . '/' . str_replace('.test.', '.result.', $test));
|
98 |
$var_expected = include(_TESTDIR . '/' . str_replace('.test.', '.result.', $test));
|
| 85 |
|
99 |
|
| 86 |
$retour = import($runfile);
|
100 |
$retour = import($runfile);
|
| 87 |
$count_warn = 0;
|
101 |
$count_warn = 0;
|
| Line 88... |
Line 102... |
| 88 |
preg_match('/^ligne /', $retour, $count_warn);
|
102 |
preg_match('/^ligne /', $retour, $count_warn);
|
| - |
|
103 |
$count_warn = count($count_warn);
|
| 89 |
$count_warn = count($count_warn);
|
104 |
|
| - |
|
105 |
$result = getCSV_line(export($cols), 1);
|
| - |
|
106 |
if(!$result) {
|
| Line 90... |
Line 107... |
| 90 |
|
107 |
echo ("\n!!! export vide, problème probable d'authentification ?\n");
|
| 91 |
$result = getCSV_line(export($cols), 1);
|
108 |
continue;
|
| 92 |
if(!$result) die("\n!!! export vide, problème probable d'authentification ?\n");
|
109 |
}
|
| 93 |
|
110 |
|
| Line 99... |
Line 116... |
| 99 |
$d1 = array_diff($var_expected, $result);
|
116 |
$d1 = array_diff($var_expected, $result);
|
| 100 |
$d2 = array_diff($result, $var_expected);
|
117 |
$d2 = array_diff($result, $var_expected);
|
| 101 |
if(!$d1 && !$d2) echo "OK\n";
|
118 |
if(!$d1 && !$d2) echo "OK\n";
|
| 102 |
else {
|
119 |
else {
|
| 103 |
echo "FAIL\n";
|
120 |
echo "FAIL\n";
|
| 104 |
if($d1) print_r($d1);
|
121 |
if($d1) { echo "expect: "; print_r($d1); }
|
| 105 |
if($d2) print_r($d2);
|
122 |
if($d2) { echo "result: "; print_r($d2); }
|
| 106 |
//var_dump($var_expected, $result);
|
123 |
//var_dump($var_expected, $result);
|
| 107 |
}
|
124 |
}
|
| 108 |
if(DEBUG) echo $retour;
|
125 |
if(DEBUG) echo $retour;
|
| 109 |
if($count_warn && (!isset($test_array['warn']) || $test_array['warn'] != $count_warn)) { echo "warnings: $count_warn\n"; }
|
126 |
if($count_warn && (!isset($test_array['warn']) || $test_array['warn'] != $count_warn)) { echo "warnings: $count_warn\n"; }
|
| 110 |
}
|
127 |
}
|