Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | 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();
        // 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)) {
                $csv = genCSV(require($test));
                file_put_contents($runfile, $csv);
        }

        $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);

        echo $count_warn . "\n";
        $result = getCSV_line(export(), 1);
        unset($result['date_creation'], $result['date_modification'], $result['id_observation']);

        echo "$test\n";
        if($var_expected) {
                if(! array_diff($var_expected, $result) && ! array_diff($result, $var_expected)) echo "OK\n";
                else {
                        echo "FAIL\n";
                        //var_dump($var_expected, $result);
                        var_dump(array_diff($var_expected, $result), array_diff($result, $var_expected));
                }
        }
        else {
                echo '<?php return ' . var_export($result, true) . ';'
        }
}

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