Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 61 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
require_once dirname(__FILE__).'/../ScriptEflorePhpUnit.php';

class OutilsTest extends ScriptEflorePhpUnit {

        public function testRecupererTableauConfigAssociatif() {
                $chaineDeParametres = "param1=valeur1,\nparam2=valeur2";
                $tableauDeParametres = Outils::recupererTableauConfig($chaineDeParametres);
                $tableauDeParametresAttendus = array('param1' => 'valeur1','param2' => 'valeur2');
                $this->assertEquals($tableauDeParametresAttendus, $tableauDeParametres);
        }

        public function testRecupererTableauConfigAssociatifAvecEspace() {
                $chaineDeParametres = "param1 =valeur1 , \nparam2  = valeur2";
                $tableauDeParametres = Outils::recupererTableauConfig($chaineDeParametres);
                $tableauDeParametresAttendus = array('param1' => 'valeur1','param2' => 'valeur2');
                $this->assertEquals($tableauDeParametresAttendus, $tableauDeParametres);
        }

        public function testRecupererTableauConfigSimple() {
                $chaineDeParametres = "param1,\nparam2";
                $tableauDeParametres = Outils::recupererTableauConfig($chaineDeParametres);
                $tableauDeParametresAttendus = array('param1', 'param2');
                $this->assertEquals($tableauDeParametresAttendus, $tableauDeParametres);
        }

        public function testRecupererTableauConfigSimpleAvecEspace() {
                $chaineDeParametres = " param1  ,\n param2  ";
                $tableauDeParametres = Outils::recupererTableauConfig($chaineDeParametres);
                $tableauDeParametresAttendus = array('param1', 'param2');
                $this->assertEquals($tableauDeParametresAttendus, $tableauDeParametres);
        }

        public function testExtraireRequetes() {
                $contenuSql = "CREATE TABLE IF NOT EXISTS bdtfx_v1_01 (".
                        "num_nom int(9) NOT NULL DEFAULT '0',".
                        "num_nom_retenu varchar(9) CHARACTER SET utf8 DEFAULT NULL,".
                        ") ENGINE=MyISAM DEFAULT CHARSET=utf8;\n\n".
                        "INSERT INTO bdtfx_meta (guid) VALUES".
                        "('urn:lsid:tela-botanica.org:bdtfx:1.01');\n".
                        "SELECT * FROM ma_table;";
                $tableauDeRequetes = Outils::extraireRequetes($contenuSql);
                $tableauDeRequetesAttendus = array("CREATE TABLE IF NOT EXISTS bdtfx_v1_01 (".
                        "num_nom int(9) NOT NULL DEFAULT '0',".
                        "num_nom_retenu varchar(9) CHARACTER SET utf8 DEFAULT NULL,".
                        ") ENGINE=MyISAM DEFAULT CHARSET=utf8",
                        "INSERT INTO bdtfx_meta (guid) VALUES".
                        "('urn:lsid:tela-botanica.org:bdtfx:1.01')",
                        "SELECT * FROM ma_table");
                $this->assertEquals($tableauDeRequetesAttendus, $tableauDeRequetes);
        }

        public function testAfficherAvancement() {
                ob_start();
                for ($i = 0; $i < 10; $i++) {
                        $tableauDeRequetes = Outils::afficherAvancement("Test");
                }
                $messageFinal = ob_get_clean();
                $messageFinalAttendu = 'Test : 0'.chr(8).'1'.chr(8).'2'.chr(8).'3'.chr(8).'4'.chr(8).'5'.chr(8).'6'.chr(8).'7'.chr(8).'8'.chr(8).'9';
                $this->assertEquals($messageFinalAttendu, $messageFinal);
        }
}
?>