Subversion Repositories eFlore/Applications.cel

Rev

Rev 1769 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1769 Rev 1775
Line 1... Line 1...
1
<?php
1
<?php
Line 2... Line 2...
2
 
2
 
3
$options = getopt("hu:d:e:p:P:",array("help", "user:", "domain:", "email:", "pass:", "phpsessid"));
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
	die(basename(__FILE__) . ' [-u|--user = 22506] [-d|--domain = http://cel]');
5
	die(basename(__FILE__) . ' [-u|--user = 22506] [-d|--domain = http://cel]');
Line 6... Line 6...
6
}
6
}
7
 
7
 
8
define('USER', isset($options['u']) ? $options['u'] : (isset($options['user']) ? $options['user'] : 22506));
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'));
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));
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));
Line 11... Line 12...
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));
Line 12... Line 13...
12
define('COOKIE', isset($options['P']) ? $options['P'] : (isset($options['phpsessid']) ? $options['phpsessid'] : NULL));
13
define('DEBUG', isset($options['D']) ? 1 : (isset($options['debug']) ? 1 : 0));
13
 
14
 
Line 34... Line 35...
34
	// cache car l'upload de fichier PHP-curl ne peut être
35
	// 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
	// simulé avec le contenu d'une variable (cf CURLOPT_POSTFIELDS et @fichier)
36
	$runfile = 'run/' . basename($test);
37
	$runfile = 'run/' . basename($test);
37
	if(!is_file($runfile)) {
38
	if(!is_file($runfile)) {
38
		$test_array = require($test);
39
		$test_array = require($test);
39
		$csv = genCSV($test_array);
40
		$csv = genCSV($test_array['data']);
40
		file_put_contents($runfile, $csv);
41
		file_put_contents($runfile, $csv);
41
	}
42
	}
Line 42... Line 43...
42
 
43
 
43
	echo "\tcurl -F \"upload=@$runfile\" -F utilisateur=" . USER . " \"" . DOMAIN . "/jrest/ImportXLS\"\n";
44
	echo "\tcurl -F \"upload=@$runfile\" -F utilisateur=" . USER . " \"" . DOMAIN . "/jrest/ImportXLS\"\n";
Line 47... Line 48...
47
	$retour = import($runfile);
48
	$retour = import($runfile);
48
	$count_warn = 0;
49
	$count_warn = 0;
49
	preg_match('/^ligne /', $retour, $count_warn);
50
	preg_match('/^ligne /', $retour, $count_warn);
50
	$count_warn = count($count_warn);
51
	$count_warn = count($count_warn);
Line 51... Line -...
51
 
-
 
52
	$result = getCSV_line(export(), 1);
52
 
Line 53... Line 53...
53
	unset($result['date_creation'], $result['date_modification'], $result['id_observation']);
53
	$result = getCSV_line(export(isset($test_array['dumpCols']) ? $test_array['dumpCols'] : 'standard'), 1);
54
 
54
 
-
 
55
	//var_dump(champsLongToShort2($test_array['data']));die;
-
 
56
	if($var_expected) {
-
 
57
		$result = __diff_fields($test_array, $result, $var_expected);
55
	//var_dump(champsLongToShort2($test_array));die;
58
		// unset($result['date_creation'], $result['date_modification'], $result['id_observation']);
56
	if($var_expected) {
59
 
57
		$d1 = array_diff($var_expected, $result);
60
		$d1 = array_diff($var_expected, $result);
58
		$d2 = array_diff($result, $var_expected);
61
		$d2 = array_diff($result, $var_expected);
59
		if(!$d1 && !$d2) echo "OK\n";
62
		if(!$d1 && !$d2) echo "OK\n";
60
		else {
63
		else {
61
			echo "FAIL\n";
64
			echo "FAIL\n";
62
			if($d1) print_r($d1);
65
			if($d1) print_r($d1);
63
			if($d2) print_r($d2);
66
			if($d2) print_r($d2);
64
			//var_dump($var_expected, $result);
67
			//var_dump($var_expected, $result);
65
		}
68
		}
66
		echo $retour;
69
		if(DEBUG) echo $retour;
-
 
70
		if($count_warn && (!isset($test_array['warn']) || $test_array['warn'] != $count_warn)) { echo "warnings: $count_warn\n"; }
67
		if($count_warn) { echo "warnings: $count_warn\n"; }
71
	}
68
	}
72
	// pas de résultat de test défini ?
69
	else {
73
	else {
Line 70... Line 74...
70
		echo $retour;
74
		if(DEBUG) echo $retour;
71
		if($count_warn) { echo "warnings: $count_warn\n"; }
75
		if($count_warn && (!isset($test_array['warn']) || $test_array['warn'] != $count_warn)) { echo "warnings: $count_warn\n"; }
-
 
76
 
-
 
77
		echo '<?php return ' . var_export($result, true) . ';';
-
 
78
	}
-
 
79
}
-
 
80
 
-
 
81
 
-
 
82
 
-
 
83
 
-
 
84
 
-
 
85
function __diff_fields($test_array, $result, $var_expected) {
-
 
86
	if(! isset($test_array['cmpCols'])) {
-
 
87
		return array_intersect_key($result, $var_expected);
-
 
88
	}
-
 
89
 
-
 
90
	if($test_array['cmpCols'] == 'def') {
-
 
91
		return array_intersect_key($result, champsLongToShort2($test_array['data']));
-
 
92
	}
-
 
93
 
-
 
94
	$e = array_flip(champsLongToShort2(array_flip(explode(',', ltrim($test_array['cmpCols'], '+-')))));
-
 
95
	if($test_array['cmpCols'][0] == '-') {
-
 
96
		return array_diff_key($result, array_flip(champsLongToShort2($e)));
-
 
97
	}
Line -... Line 98...
-
 
98
	else { //if($test_array['cmpCols'][0] == '+') {
72
 
99
		return array_intersect_key($result, array_flip(champsLongToShort2($e)));
Line 73... Line 100...
73
		echo '<?php return ' . var_export($result, true) . ';';
100
	}