Subversion Repositories eFlore/Applications.cel

Rev

Rev 1768 | Blame | Last modification | View Log | RSS feed

<?php

$options = getopt("hu:d:e:p:P:",array("help", "user:", "domain:", "email:", "pass:", "phpsessid"));
if(isset($options['h']) || isset($options['help'])) {
        die(basename(__FILE__) . ' [-u|--user = 22506] [-d|--domain = http://cel]');
}

define('USER', isset($options['u']) ? $options['u'] : (isset($options['user']) ? $options['user'] : 22506));
define('DOMAIN', isset($options['d']) ? $options['d'] : (isset($options['domain']) ? $options['domain'] : 'http://cel'));
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));

require_once('api.php');

function setupTestEnv() {
        cel_delete_all_obs();
        cel_delete_all_images();
        cel_upload_image('image-test.jpg');
        cel_upload_image('image-test2.jpg');
}

if(! is_dir('phptests')) die('no phptests/');
if(! is_dir('run')) mkdir('run');
if(! is_dir('run')) die('no run/');


$all_tests = glob('phptests/*.test.php');
$tests = array_intersect($argv, $all_tests);
if(!$tests) $tests = $all_tests;

foreach($tests as $test) {
        setupTestEnv(); @array_walk(glob('run/*'), function(&$i) { unlink($i);});
        // cache car l'upload de fichier PHP-curl ne peut ĂȘtre
        // simulé avec le contenu d'une variable (cf CURLOPT_POSTFIELDS et @fichier)
        $runfile = 'run/' . basename($test);
        if(!is_file($runfile)) {
                $test_array = require($test);
                $csv = genCSV($test_array);
                file_put_contents($runfile, $csv);
        }

        echo "\tcurl -F \"upload=@$runfile\" -F utilisateur=" . USER . " \"" . DOMAIN . "/jrest/ImportXLS\"\n";
        echo "$test: ";
        $var_expected = include(str_replace('.test.', '.result.', $test));

        $retour = import($runfile);
        $count_warn = 0;
        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']);

        //var_dump(champsLongToShort2($test_array));die;
        if($var_expected) {
                $d1 = array_diff($var_expected, $result);
                $d2 = array_diff($result, $var_expected);
                if(!$d1 && !$d2) echo "OK\n";
                else {
                        echo "FAIL\n";
                        if($d1) print_r($d1);
                        if($d2) print_r($d2);
                        //var_dump($var_expected, $result);
                }
                echo $retour;
                if($count_warn) { echo "warnings: $count_warn\n"; }
        }
        else {
                echo $retour;
                if($count_warn) { echo "warnings: $count_warn\n"; }

                echo '<?php return ' . var_export($result, true) . ';';
        }

}

// sed -i -e '1{/<?php return/!s:^:<?php return :}' -e '${/^)$/s:$:;:}' phptests/*.result.php