Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1775 Rev 1793
Line 1... Line 1...
1
<?php
1
<?php
Line 2... Line 2...
2
 
2
 
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'])) {
-
 
5
	printf(<<<EOF
-
 
6
%s [fichiers de test]
-
 
7
  --help|-h: cette aide
-
 
8
  -debug|-d: informations sur les requêtes curl
-
 
9
  [-u|--user = 22506]
-
 
10
  [-d|--domain = "http://cel"]
-
 
11
  --pass|-p:  pour l'authentifiation
-
 
12
  --email|-e: pour l'authentifiation
-
 
13
  --phpsessid|-P: pour l'authentifiation, alternative à -e/-p
4
if(isset($options['h']) || isset($options['help'])) {
14
 
-
 
15
* --phpsessid permet de passer un identifiant de session PHP pour effectuer l'export.
-
 
16
Exemple:
-
 
17
$ sqlite3 ~/.mozilla/firefox/*.default/cookies.sqlite<<<"SELECT * FROM moz_cookies WHERE baseDomain = 'cel' AND name = 'PHPSESSID';"
-
 
18
 
-
 
19
* [fichiers de test]: un ou plusieurs fichier(s) de test valide(s), commençant par "phptests/" et finissant en ".test.php"
-
 
20
  Exemple: phptests/a*.test.php ou bien phptests/latitude-virgule.test.php
-
 
21
 
-
 
22
Exemple:
-
 
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*
-
 
25
 
-
 
26
EOF
-
 
27
, /* relax emacs*/
-
 
28
		   basename(__FILE__));
5
	die(basename(__FILE__) . ' [-u|--user = 22506] [-d|--domain = http://cel]');
29
	die;
Line -... Line 30...
-
 
30
}
-
 
31
 
-
 
32
// stocke les test
-
 
33
define('_TESTDIR', dirname(__FILE__) . '/' . 'phptests');
-
 
34
// stocke les CSV générés à partir des test (répertoire de cache)
6
}
35
define('_RUNDIR', dirname(__FILE__) . '/' . 'run');
7
 
36
 
8
define('USER', isset($options['u']) ? $options['u'] : (isset($options['user']) ? $options['user'] : 22506));
37
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'));
38
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));
39
define('EMAIL', isset($options['e']) ? $options['e'] : (isset($options['email']) ? $options['email'] : NULL));
Line 19... Line 48...
19
	cel_delete_all_images();
48
	cel_delete_all_images();
20
	cel_upload_image('image-test.jpg');
49
	cel_upload_image('image-test.jpg');
21
	cel_upload_image('image-test2.jpg');
50
	cel_upload_image('image-test2.jpg');
22
}
51
}
Line 23... Line 52...
23
 
52
 
24
if(! is_dir('phptests')) die('no phptests/');
53
if(! is_dir(_TESTDIR)) die('no phptests/ directory inside ' . __DIR__);
25
if(! is_dir('run')) mkdir('run');
54
if(! is_dir(_RUNDIR)) mkdir(_RUNDIR);
26
if(! is_dir('run')) die('no run/');
-
 
27
 
55
if(! is_dir(_RUNDIR)) die('no run/ directory inside ' . __DIR__);
28
 
56
 
29
$all_tests = glob('phptests/*.test.php');
57
$all_tests = array_map('basename', glob(_TESTDIR . '/*.test.php'));
-
 
58
$tests = array_intersect(array_map('basename', $argv), $all_tests);
30
$tests = array_intersect($argv, $all_tests);
59
						 
Line -... Line 60...
-
 
60
if(!$tests) $tests = $all_tests;
-
 
61
 
31
if(!$tests) $tests = $all_tests;
62
//@array_walk(glob('run/*'), function(&$i) { unlink($i);});
-
 
63
 
32
 
64
foreach($tests as $test) {
-
 
65
	setupTestEnv();
33
foreach($tests as $test) {
66
	$testfile = _TESTDIR . '/' . $test;
34
	setupTestEnv(); @array_walk(glob('run/*'), function(&$i) { unlink($i);});
67
 
35
	// cache car l'upload de fichier PHP-curl ne peut être
68
	// cache car l'upload de fichier PHP-curl ne peut être
36
	// simulé avec le contenu d'une variable (cf CURLOPT_POSTFIELDS et @fichier)
-
 
-
 
69
	// simulé avec le contenu d'une variable (cf CURLOPT_POSTFIELDS et @fichier)
37
	$runfile = 'run/' . basename($test);
70
	$runfile = _RUNDIR . '/' . $test;
-
 
71
 
-
 
72
	$test_array = require($testfile);
-
 
73
 
-
 
74
	$cols = isset($test_array['dumpCols']) ? $test_array['dumpCols'] : 'standard';
38
	if(!is_file($runfile)) {
75
 
39
		$test_array = require($test);
76
	if(!is_file($runfile) || filemtime($runfile) < filemtime($testfile)) {
40
		$csv = genCSV($test_array['data']);
77
		$csv = genCSV($test_array['data']);
Line 41... Line 78...
41
		file_put_contents($runfile, $csv);
78
		file_put_contents($runfile, $csv);
42
	}
79
	}
43
 
80
 
Line 44... Line 81...
44
	echo "\tcurl -F \"upload=@$runfile\" -F utilisateur=" . USER . " \"" . DOMAIN . "/jrest/ImportXLS\"\n";
81
	echo "\tcurl -F \"upload=@$runfile\" -F utilisateur=" . USER . " \"" . DOMAIN . "/jrest/ImportXLS\"\n";
45
	echo "$test: ";
82
	echo "$test: ";
46
	$var_expected = include(str_replace('.test.', '.result.', $test));
83
	$var_expected = include(_TESTDIR . '/' . str_replace('.test.', '.result.', $test));
47
 
84
 
Line -... Line 85...
-
 
85
	$retour = import($runfile);
48
	$retour = import($runfile);
86
	$count_warn = 0;
Line 49... Line 87...
49
	$count_warn = 0;
87
	preg_match('/^ligne /', $retour, $count_warn);
50
	preg_match('/^ligne /', $retour, $count_warn);
88
	$count_warn = count($count_warn);
51
	$count_warn = count($count_warn);
89
 
52
 
90
	$result = getCSV_line(export($cols), 1);