base_url = 'http://localhost/openads/'; // Instanciation de la classe *om_application* $this->f = $this->get_inst_om_application("admin", "admin"); $this->assertTrue($this->f->authenticated, "Erreur d'authentification."); // Activation du paramètre de code entite $sql = 'INSERT INTO '.DB_PREFIXE.'om_parametre (om_parametre, libelle, valeur, om_collectivite)'. "VALUES (nextval('".DB_PREFIXE."om_parametre_seq'), 'option_om_collectivite_entity', 'true', ". "(SELECT om_collectivite FROM ".DB_PREFIXE."om_collectivite WHERE libelle = 'agglo'))"; $res = $this->f->db->query($sql); $this->f->isDatabaseError($res); } /** * Méthode lancée en fin de traitement */ public function common_tearDown() { // Désactivation du paramètre de code entite $sql = 'DELETE FROM '.DB_PREFIXE."om_parametre ". "WHERE libelle = 'option_om_collectivite_entity' ". "AND om_collectivite = (SELECT om_collectivite FROM ".DB_PREFIXE."om_collectivite WHERE libelle = 'agglo')"; $res = $this->f->db->query($sql); $this->f->isDatabaseError($res); parent::common_tearDown(); $this->clean_session(); // Destruction de la classe *om_application* $this->f->__destruct(); } /** * Test la fonction numerotation_urbanisme() de la classe Utils. */ public function test_01_utils_num_urba() { $this->f->disableLog(); foreach(array( // basic success 'CU03035022AA021' => array('expected' => array( 'type' => 'CU', 'departement' => '030', 'commune' => '350', 'annee' => '22', 'division' => 'A', 'numero' => 'A021')), 'CU 030350 22 AA021' => array('expected' => array( 'type' => 'CU', 'departement' => '030', 'commune' => '350', 'annee' => '22', 'division' => 'A', 'numero' => 'A021')), 'CU03035022AA021M02' => array('expected' => array( 'type' => 'CU', 'departement' => '030', 'commune' => '350', 'annee' => '22', 'division' => 'A', 'numero' => 'A021', 'suffixe' => 'M', 'num_suffixe' => '02')), 'CU 030350 22 AA021M02' => array('expected' => array( 'type' => 'CU', 'departement' => '030', 'commune' => '350', 'annee' => '22', 'division' => 'A', 'numero' => 'A021', 'suffixe' => 'M', 'num_suffixe' => '02')), 'CU 030350 22 AA021 M02' => array('expected' => array( 'type' => 'CU', 'departement' => '030', 'commune' => '350', 'annee' => '22', 'division' => 'A', 'numero' => 'A021', 'suffixe' => 'M', 'num_suffixe' => '02')), // with option code entite 'CU03035022AA021U3001' => array('expected' => array( 'type' => 'CU', 'departement' => '030', 'commune' => '350', 'annee' => '22', 'division' => 'A', 'numero' => 'A021', 'entite' => 'U3001')), 'CU03035022AA021M02U3001' => array('expected' => array( 'type' => 'CU', 'departement' => '030', 'commune' => '350', 'annee' => '22', 'division' => 'A', 'numero' => 'A021', 'suffixe' => 'M', 'num_suffixe' => '02', 'entite' => 'U3001')), 'CU 030350 22 AA021 U3001' => array('expected' => array( 'type' => 'CU', 'departement' => '030', 'commune' => '350', 'annee' => '22', 'division' => 'A', 'numero' => 'A021', 'entite' => 'U3001')), 'CU 030350 22 AA021 M02 U3001' => array('expected' => array( 'type' => 'CU', 'departement' => '030', 'commune' => '350', 'annee' => '22', 'division' => 'A', 'numero' => 'A021', 'suffixe' => 'M', 'num_suffixe' => '02', 'entite' => 'U3001')), 'CU03035022AA021 U3001' => array('options' => array('codeentcoll' => '1'), 'expected' => array( 'type' => 'CU', 'departement' => '030', 'commune' => '350', 'annee' => '22', 'division' => 'A', 'numero' => 'A021', 'entite' => 'U3001')), 'DP0150852000011P00LBCOM_1501' => array('expected' => array( 'type' => 'DP', 'departement' => '015', 'commune' => '085', 'annee' => '20', 'division' => '0', 'numero' => '0011', 'suffixe' => 'P', 'num_suffixe' => '00', 'entite' => 'LBCOM_1501')), // ovious fail '' => array('fail' => true), '0' => array('fail' => true), '1' => array('fail' => true), 'A' => array('fail' => true), '18' => array('fail' => true), 'ZZ' => array('fail' => true), '9999999999999999' => array('fail' => true), 'AAAAAAAAAAAAAAAA' => array('fail' => true), // more complex success 'CU03035022AA021' => array('options' => array('case' => true)), 'CU03035022AA021' => array('options' => array('nospace' => true)), 'CU03035022AA021M02' => array('options' => array('nocodeent' => true)), 'CU03035022A0021' => array('options' => array('numintonly' => true)), // more complex fail 'cu03035022aa021' => array('fail' => true, 'options' => array('case' => true)), 'CU 03035022AA021' => array('fail' => true, 'options' => array('nospace' => true)), 'CU03035022AA021 U3001' => array('fail' => true, 'options' => array('nocodeent' => true)), 'CU03035022AA021 U3001' => array('fail' => true, 'options' => array('codeentcoll' => '9999999999' /* invalid */)), 'CU03035022AA021' => array('fail' => true, 'options' => array('numintonly' => true)), ) as $di => $data) { $fail = isset($data['fail']) ? ((bool) $data['fail']) : false; $options = isset($data['options']) ? $data['options'] : array(); $expected = isset($data['expected']) ? $data['expected'] : array(); try { $parsed = $this->f->numerotation_urbanisme($di, $options); } catch(RuntimeException $e) { $this->assertTrue($fail, $di.' (expected to fail: '.var_export($fail, true).') -> '. get_class($e).' '.$e->getMessage()); if (! $fail) { throw $e; } } if (! $fail) { $this->assertTrue(! empty($parsed), $di.': empty ('.var_export($parsed, true).')'); $this->assertTrue(is_array($parsed), $di.': not an array ('.var_export($parsed, true).')'); $this->assertTrue(isset($parsed['di']), $di.': no key "di" ('.var_export($parsed, true).')'); if (! empty($expected)) { foreach($expected as $key => $val) { $this->assertTrue( isset($parsed['di'][$key]), $di.": no key 'di.$key' (".var_export($parsed, true).')'); if (isset($parsed['di'][$key])) { $this->assertTrue( $parsed['di'][$key] === $val, $di.": key '$key' do not match value ".var_export($val, true). " (!== ".var_export($parsed['di'][$key], true).')'); } } } } } } }