Subversion Repositories eFlore/Applications.cel

Rev

Rev 1768 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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) {
1769 raphael 33
	setupTestEnv(); @array_walk(glob('run/*'), function(&$i) { unlink($i);});
1768 raphael 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)) {
1769 raphael 38
		$test_array = require($test);
39
		$csv = genCSV($test_array);
1768 raphael 40
		file_put_contents($runfile, $csv);
41
	}
42
 
1769 raphael 43
	echo "\tcurl -F \"upload=@$runfile\" -F utilisateur=" . USER . " \"" . DOMAIN . "/jrest/ImportXLS\"\n";
44
	echo "$test: ";
1768 raphael 45
	$var_expected = include(str_replace('.test.', '.result.', $test));
46
 
47
	$retour = import($runfile);
48
	$count_warn = 0;
49
	preg_match('/^ligne /', $retour, $count_warn);
50
	$count_warn = count($count_warn);
51
 
52
	$result = getCSV_line(export(), 1);
53
	unset($result['date_creation'], $result['date_modification'], $result['id_observation']);
54
 
1769 raphael 55
	//var_dump(champsLongToShort2($test_array));die;
1768 raphael 56
	if($var_expected) {
1769 raphael 57
		$d1 = array_diff($var_expected, $result);
58
		$d2 = array_diff($result, $var_expected);
59
		if(!$d1 && !$d2) echo "OK\n";
1768 raphael 60
		else {
61
			echo "FAIL\n";
1769 raphael 62
			if($d1) print_r($d1);
63
			if($d2) print_r($d2);
1768 raphael 64
			//var_dump($var_expected, $result);
65
		}
1769 raphael 66
		echo $retour;
67
		if($count_warn) { echo "warnings: $count_warn\n"; }
1768 raphael 68
	}
69
	else {
1769 raphael 70
		echo $retour;
71
		if($count_warn) { echo "warnings: $count_warn\n"; }
72
 
73
		echo '<?php return ' . var_export($result, true) . ';';
1768 raphael 74
	}
1769 raphael 75
 
1768 raphael 76
}
77
 
78
// sed -i -e '1{/<?php return/!s:^:<?php return :}' -e '${/^)$/s:$:;:}' phptests/*.result.php