Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 1774 → Rev 1775

/trunk/jrest/tests/IO-fields-unittest.php
1,6 → 1,6
<?php
 
$options = getopt("hu:d:e:p:P:",array("help", "user:", "domain:", "email:", "pass:", "phpsessid"));
$options = getopt("hu:d:e:p:P:D",array("help", "user:", "domain:", "email:", "pass:", "phpsessid", "debug"));
if(isset($options['h']) || isset($options['help'])) {
die(basename(__FILE__) . ' [-u|--user = 22506] [-d|--domain = http://cel]');
}
10,6 → 10,7
define('EMAIL', isset($options['e']) ? $options['e'] : (isset($options['email']) ? $options['email'] : NULL));
define('PASS', isset($options['p']) ? $options['p'] : (isset($options['pass']) ? $options['pass'] : NULL));
define('COOKIE', isset($options['P']) ? $options['P'] : (isset($options['phpsessid']) ? $options['phpsessid'] : NULL));
define('DEBUG', isset($options['D']) ? 1 : (isset($options['debug']) ? 1 : 0));
 
require_once('api.php');
 
36,7 → 37,7
$runfile = 'run/' . basename($test);
if(!is_file($runfile)) {
$test_array = require($test);
$csv = genCSV($test_array);
$csv = genCSV($test_array['data']);
file_put_contents($runfile, $csv);
}
 
49,11 → 50,13
preg_match('/^ligne /', $retour, $count_warn);
$count_warn = count($count_warn);
 
$result = getCSV_line(export(), 1);
unset($result['date_creation'], $result['date_modification'], $result['id_observation']);
$result = getCSV_line(export(isset($test_array['dumpCols']) ? $test_array['dumpCols'] : 'standard'), 1);
 
//var_dump(champsLongToShort2($test_array));die;
//var_dump(champsLongToShort2($test_array['data']));die;
if($var_expected) {
$result = __diff_fields($test_array, $result, $var_expected);
// unset($result['date_creation'], $result['date_modification'], $result['id_observation']);
 
$d1 = array_diff($var_expected, $result);
$d2 = array_diff($result, $var_expected);
if(!$d1 && !$d2) echo "OK\n";
63,16 → 66,40
if($d2) print_r($d2);
//var_dump($var_expected, $result);
}
echo $retour;
if($count_warn) { echo "warnings: $count_warn\n"; }
if(DEBUG) echo $retour;
if($count_warn && (!isset($test_array['warn']) || $test_array['warn'] != $count_warn)) { echo "warnings: $count_warn\n"; }
}
// pas de résultat de test défini ?
else {
echo $retour;
if($count_warn) { echo "warnings: $count_warn\n"; }
if(DEBUG) echo $retour;
if($count_warn && (!isset($test_array['warn']) || $test_array['warn'] != $count_warn)) { echo "warnings: $count_warn\n"; }
 
echo '<?php return ' . var_export($result, true) . ';';
}
}
 
 
 
 
 
function __diff_fields($test_array, $result, $var_expected) {
if(! isset($test_array['cmpCols'])) {
return array_intersect_key($result, $var_expected);
}
 
if($test_array['cmpCols'] == 'def') {
return array_intersect_key($result, champsLongToShort2($test_array['data']));
}
 
$e = array_flip(champsLongToShort2(array_flip(explode(',', ltrim($test_array['cmpCols'], '+-')))));
if($test_array['cmpCols'][0] == '-') {
return array_diff_key($result, array_flip(champsLongToShort2($e)));
}
else { //if($test_array['cmpCols'][0] == '+') {
return array_intersect_key($result, array_flip(champsLongToShort2($e)));
}
 
// pas de 'cmpCols' définie: comparaison de tous les champs par rapport au tableau de résultats attendus
}
 
// sed -i -e '1{/<?php return/!s:^:<?php return :}' -e '${/^)$/s:$:;:}' phptests/*.result.php