Changeset 483
- Timestamp:
- 07/01/07 17:16:21 (2 years ago)
- Files:
-
- trunk/build/manifests/testapp.mn (modified) (2 diffs)
- trunk/build/manifests/testapp.mn (modified) (2 diffs)
- trunk/lib/jelix-modules/junittests/classes/junittestcase.class.php (modified) (2 diffs)
- trunk/lib/jelix-modules/junittests/classes/junittestcase.class.php (modified) (2 diffs)
- trunk/lib/jelix/dao/jDaoBase.class.php (modified) (2 diffs)
- trunk/lib/jelix/dao/jDaoBase.class.php (modified) (2 diffs)
- trunk/lib/jelix/dao/jDaoGenerator.class.php (modified) (3 diffs)
- trunk/lib/jelix/dao/jDaoGenerator.class.php (modified) (3 diffs)
- trunk/lib/jelix/forms/jForms.class.php (modified) (2 diffs)
- trunk/lib/jelix/forms/jForms.class.php (modified) (2 diffs)
- trunk/lib/jelix/forms/jFormsBase.class.php (modified) (3 diffs)
- trunk/lib/jelix/forms/jFormsBase.class.php (modified) (3 diffs)
- trunk/testapp/modules/jelix_tests/daos/description.dao.xml (added)
- trunk/testapp/modules/jelix_tests/daos/description.dao.xml (added)
- trunk/testapp/modules/jelix_tests/forms (added)
- trunk/testapp/modules/jelix_tests/forms (added)
- trunk/testapp/modules/jelix_tests/forms/product.form.xml (added)
- trunk/testapp/modules/jelix_tests/forms/product.form.xml (added)
- trunk/testapp/modules/jelix_tests/tests/jdao.main_api.html.php (modified) (1 diff)
- trunk/testapp/modules/jelix_tests/tests/jdao.main_api.html.php (modified) (1 diff)
- trunk/testapp/modules/jelix_tests/tests/jforms.compiler.html.php (modified) (1 diff)
- trunk/testapp/modules/jelix_tests/tests/jforms.compiler.html.php (modified) (1 diff)
- trunk/testapp/modules/jelix_tests/tests/jforms.html.php (added)
- trunk/testapp/modules/jelix_tests/tests/jforms.html.php (added)
- trunk/testapp/modules/jelix_tests/tests/jforms.with_dao.html.php (added)
- trunk/testapp/modules/jelix_tests/tests/jforms.with_dao.html.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/build/manifests/testapp.mn
r473 r483 90 90 cd testapp/modules/jelix_tests/daos 91 91 products.dao.xml 92 description.dao.xml 93 cd testapp/modules/jelix_tests/forms 94 product.form.xml 92 95 93 96 cd testapp/modules/jelix_tests/tests/ … … 109 112 jdb.1_queries.html.php 110 113 jdb.2_queries_with_pdo.html.php 114 jforms.html.php 111 115 jforms.compiler.html.php 116 jforms.with_dao.html.php 112 117 jtpl.expressions_parsing.html_cli.php 113 118 utils.jfilter.html_cli.php 114 115 119 116 120 cd testapp/var trunk/build/manifests/testapp.mn
r473 r483 90 90 cd testapp/modules/jelix_tests/daos 91 91 products.dao.xml 92 description.dao.xml 93 cd testapp/modules/jelix_tests/forms 94 product.form.xml 92 95 93 96 cd testapp/modules/jelix_tests/tests/ … … 109 112 jdb.1_queries.html.php 110 113 jdb.2_queries_with_pdo.html.php 114 jforms.html.php 111 115 jforms.compiler.html.php 116 jforms.with_dao.html.php 112 117 jtpl.expressions_parsing.html_cli.php 113 118 utils.jfilter.html_cli.php 114 115 119 116 120 cd testapp/var trunk/lib/jelix-modules/junittests/classes/junittestcase.class.php
r468 r483 157 157 158 158 if(!$ok) 159 $this->fail($name.' : objets non identiques'.$errormessage);159 $this->fail($name.' : non identical objects'.$errormessage); 160 160 return $ok; 161 161 … … 180 180 $n = $key ++; 181 181 } 182 if($this->assertTrue(isset($value[$n]),$name.'['.$n.'] doesn\'t exists'.$errormessage)){ 182 /*$this->dump($n, 'n='); 183 $this->dump($value, 'value'); 184 if(isset($value[$n])) 185 $this->dump($value[$n],'value de n OK'); 186 else 187 $this->dump('!!!!! value de n pas ok');*/ 188 if($this->assertTrue(array_key_exists($n,$value),$name.'['.$n.'] doesn\'t exist arrrg'.$errormessage)){ 183 189 $v = $value[$n]; 184 190 $ok &= $this->_checkIdentical($child, $v, $name.'['.$n.']',$errormessage); trunk/lib/jelix-modules/junittests/classes/junittestcase.class.php
r468 r483 157 157 158 158 if(!$ok) 159 $this->fail($name.' : objets non identiques'.$errormessage);159 $this->fail($name.' : non identical objects'.$errormessage); 160 160 return $ok; 161 161 … … 180 180 $n = $key ++; 181 181 } 182 if($this->assertTrue(isset($value[$n]),$name.'['.$n.'] doesn\'t exists'.$errormessage)){ 182 /*$this->dump($n, 'n='); 183 $this->dump($value, 'value'); 184 if(isset($value[$n])) 185 $this->dump($value[$n],'value de n OK'); 186 else 187 $this->dump('!!!!! value de n pas ok');*/ 188 if($this->assertTrue(array_key_exists($n,$value),$name.'['.$n.'] doesn\'t exist arrrg'.$errormessage)){ 183 189 $v = $value[$n]; 184 190 $ok &= $this->_checkIdentical($child, $v, $name.'['.$n.']',$errormessage); trunk/lib/jelix/dao/jDaoBase.class.php
r471 r483 48 48 * @var array 49 49 */ 50 protected $_properties=array(); 50 protected $_properties = array(); 51 52 /** 53 * list of id of primary key properties 54 * @var array 55 */ 56 protected $_pkFields = array(); 51 57 52 58 /** … … 116 122 public function setPk(){ 117 123 $args=func_get_args(); 118 if(count($args) == 0) throw new jException('jelix~dao.error.keys.missing');119 124 if(count($args)==1 && is_array($args[0])){ 120 125 $args=$args[0]; 121 126 } 122 $i=0; 123 foreach($this->_properties as $prop=>$infos){ 124 if($infos['isPk']){ 125 if($i>= count($args)) 126 throw new jException('jelix~dao.error.keys.missing'); 127 $this->$prop = $args[$i++]; 128 } 127 if(count($args) == 0 || count($args) != count($this->_pkFields) ) 128 throw new jException('jelix~dao.error.keys.missing'); 129 130 foreach($this->_pkFields as $k=>$prop){ 131 $this->$prop = $args[$k]; 129 132 } 130 133 return true; 134 } 135 136 /** 137 * return the value of fields corresponding to the primary key 138 * @return mixed the value or an array of values if there is several pk 139 * @since 1.0beta3 140 */ 141 public function getPk(){ 142 if(count($this->_pkFields) == 1){ 143 return $this->{$this->_pkFields[0]}; 144 }else{ 145 $list = array(); 146 foreach($this->_pkFields as $k=>$prop){ 147 $list[] = $this->$prop; 148 } 149 return $list; 150 } 131 151 } 132 152 } trunk/lib/jelix/dao/jDaoBase.class.php
r471 r483 48 48 * @var array 49 49 */ 50 protected $_properties=array(); 50 protected $_properties = array(); 51 52 /** 53 * list of id of primary key properties 54 * @var array 55 */ 56 protected $_pkFields = array(); 51 57 52 58 /** … … 116 122 public function setPk(){ 117 123 $args=func_get_args(); 118 if(count($args) == 0) throw new jException('jelix~dao.error.keys.missing');119 124 if(count($args)==1 && is_array($args[0])){ 120 125 $args=$args[0]; 121 126 } 122 $i=0; 123 foreach($this->_properties as $prop=>$infos){ 124 if($infos['isPk']){ 125 if($i>= count($args)) 126 throw new jException('jelix~dao.error.keys.missing'); 127 $this->$prop = $args[$i++]; 128 } 127 if(count($args) == 0 || count($args) != count($this->_pkFields) ) 128 throw new jException('jelix~dao.error.keys.missing'); 129 130 foreach($this->_pkFields as $k=>$prop){ 131 $this->$prop = $args[$k]; 129 132 } 130 133 return true; 134 } 135 136 /** 137 * return the value of fields corresponding to the primary key 138 * @return mixed the value or an array of values if there is several pk 139 * @since 1.0beta3 140 */ 141 public function getPk(){ 142 if(count($this->_pkFields) == 1){ 143 return $this->{$this->_pkFields[0]}; 144 }else{ 145 $list = array(); 146 foreach($this->_pkFields as $k=>$prop){ 147 $list[] = $this->$prop; 148 } 149 return $list; 150 } 131 151 } 132 152 } trunk/lib/jelix/dao/jDaoGenerator.class.php
r450 r483 62 62 $src[] = ' require_once ( JELIX_LIB_DAO_PATH .\'jDaoBase.class.php\');'; 63 63 64 //----------------------- 65 // Build the record class 66 //----------------------- 67 68 $src[] = "\nclass ".$this->_DaoRecordClassName.' extends jDaoRecordBase {'; 69 70 $properties=array(); 71 72 foreach ($this->_datasParser->getProperties() as $id=>$field){ 73 $properties[$id] = get_object_vars($field); 74 $src[] =' public $'.$id.';'; 75 } 76 77 $src[] = ' protected $_properties = '.var_export($properties, true).';'; 78 79 $src[] = '}'; 80 81 //-------------------- 82 // Build the dao class 83 //-------------------- 84 85 // prepare some values to generate methods 64 // prepare some values to generate properties and methods 86 65 87 66 list($sqlFromClause, $sqlWhereClause)= $this->_getFromClause(); … … 97 76 } 98 77 78 //----------------------- 79 // Build the record class 80 //----------------------- 81 82 $src[] = "\nclass ".$this->_DaoRecordClassName.' extends jDaoRecordBase {'; 83 84 $properties=array(); 85 86 foreach ($this->_datasParser->getProperties() as $id=>$field){ 87 $properties[$id] = get_object_vars($field); 88 $src[] =' public $'.$id.';'; 89 } 90 91 $src[] = ' protected $_properties = '.var_export($properties, true).';'; 92 $src[] = ' protected $_pkFields = array('.$this->_writeFieldNamesWith ($start = '\'', $end='\'', $beetween = ',', $pkFields).');'; 93 94 $src[] = '}'; 95 96 //-------------------- 97 // Build the dao class 98 //-------------------- 99 100 99 101 $src[] = "\nclass ".$this->_DaoClassName.' extends jDaoFactoryBase {'; 100 102 $src[] =' protected $_tables = '.var_export($tables, true).';'; … … 105 107 $src[] =' protected $_DaoRecordClassName=\''.$this->_DaoRecordClassName.'\';'; 106 108 $src[] =' protected $_pkFields = array('.$this->_writeFieldNamesWith ($start = '\'', $end='\'', $beetween = ',', $pkFields).');'; 107 108 109 109 110 $src[] = ' '; trunk/lib/jelix/dao/jDaoGenerator.class.php
r450 r483 62 62 $src[] = ' require_once ( JELIX_LIB_DAO_PATH .\'jDaoBase.class.php\');'; 63 63 64 //----------------------- 65 // Build the record class 66 //----------------------- 67 68 $src[] = "\nclass ".$this->_DaoRecordClassName.' extends jDaoRecordBase {'; 69 70 $properties=array(); 71 72 foreach ($this->_datasParser->getProperties() as $id=>$field){ 73 $properties[$id] = get_object_vars($field); 74 $src[] =' public $'.$id.';'; 75 } 76 77 $src[] = ' protected $_properties = '.var_export($properties, true).';'; 78 79 $src[] = '}'; 80 81 //-------------------- 82 // Build the dao class 83 //-------------------- 84 85 // prepare some values to generate methods 64 // prepare some values to generate properties and methods 86 65 87 66 list($sqlFromClause, $sqlWhereClause)= $this->_getFromClause(); … … 97 76 } 98 77 78 //----------------------- 79 // Build the record class 80 //----------------------- 81 82 $src[] = "\nclass ".$this->_DaoRecordClassName.' extends jDaoRecordBase {'; 83 84 $properties=array(); 85 86 foreach ($this->_datasParser->getProperties() as $id=>$field){ 87 $properties[$id] = get_object_vars($field); 88 $src[] =' public $'.$id.';'; 89 } 90 91 $src[] = ' protected $_properties = '.var_export($properties, true).';'; 92 $src[] = ' protected $_pkFields = array('.$this->_writeFieldNamesWith ($start = '\'', $end='\'', $beetween = ',', $pkFields).');'; 93 94 $src[] = '}'; 95 96 //-------------------- 97 // Build the dao class 98 //-------------------- 99 100 99 101 $src[] = "\nclass ".$this->_DaoClassName.' extends jDaoFactoryBase {'; 100 102 $src[] =' protected $_tables = '.var_export($tables, true).';'; … … 105 107 $src[] =' protected $_DaoRecordClassName=\''.$this->_DaoRecordClassName.'\';'; 106 108 $src[] =' protected $_pkFields = array('.$this->_writeFieldNamesWith ($start = '\'', $end='\'', $beetween = ',', $pkFields).');'; 107 108 109 109 110 $src[] = ' '; trunk/lib/jelix/forms/jForms.class.php
r473 r483 91 91 */ 92 92 static public function fill($formSel,$formId=JFORMS_DEFAULT_ID){ 93 if($formId === null) $formId=JFORMS_DEFAULT_ID;94 93 $form = self::get($formSel,$formId); 95 94 if($form) … … 113 112 } 114 113 } 115 116 114 } 117 115 trunk/lib/jelix/forms/jForms.class.php
r473 r483 91 91 */ 92 92 static public function fill($formSel,$formId=JFORMS_DEFAULT_ID){ 93 if($formId === null) $formId=JFORMS_DEFAULT_ID;94 93 $form = self::get($formSel,$formId); 95 94 if($form) … … 113 112 } 114 113 } 115 116 114 } 117 115 trunk/lib/jelix/forms/jFormsBase.class.php
r473 r483 71 71 //if($value !== null) on commente pour le moment, 72 72 //@todo à prevoir un meilleur test, pour les formulaires sur plusieurs pages 73 if($value === null) $value=''; 73 74 $this->_container->datas[$name]= $value; 74 75 } … … 118 119 } 119 120 } 121 120 122 /** 121 123 * save datas using a dao. 122 124 * it call insert or update depending the value of the formId stored in the container 123 125 * @param string $daoSelector the selector of a dao file 126 * @return mixed the primary key of the new record in a case of inserting 124 127 * @see jDao 125 128 */ … … 136 139 $dao->insert($daorec); 137 140 } 141 return $daorec->getPk(); 138 142 } 139 143 trunk/lib/jelix/forms/jFormsBase.class.php
r473 r483 71 71 //if($value !== null) on commente pour le moment, 72 72 //@todo à prevoir un meilleur test, pour les formulaires sur plusieurs pages 73 if($value === null) $value=''; 73 74 $this->_container->datas[$name]= $value; 74 75 } … … 118 119 } 119 120 } 121 120 122 /** 121 123 * save datas using a dao. 122 124 * it call insert or update depending the value of the formId stored in the container 123 125 * @param string $daoSelector the selector of a dao file 126 * @return mixed the primary key of the new record in a case of inserting 124 127 * @see jDao 125 128 */ … … 136 139 $dao->insert($daorec); 137 140 } 141 return $daorec->getPk(); 138 142 } 139 143 trunk/testapp/modules/jelix_tests/tests/jdao.main_api.html.php
r468 r483 32 32 33 33 function testRecordCheck() { 34 //TODO 34 35 $record = jDao::createRecord ('products'); 36 $this->assertEqual($record->id , ''); 37 $record->setPk(5); 38 $this->assertEqual($record->id , 5); 39 40 $this->assertEqual($record->getPk(), 5); 41 42 $record = jDao::createRecord ('description'); 43 $this->assertEqual($record->id , ''); 44 $this->assertEqual($record->lang , ''); 45 46 $record->setPk(5,'fr'); 47 $this->assertEqual($record->id , 5); 48 $this->assertEqual($record->lang , 'fr'); 49 50 $record->setPk(array(4,'en')); 51 $this->assertEqual($record->id , 4); 52 $this->assertEqual($record->lang , 'en'); 53 54 $pk = $record->getPk(); 55 $this->assertEqual($pk, array(4,'en')); 35 56 } 36 57 trunk/testapp/modules/jelix_tests/tests/jdao.main_api.html.php
r468 r483 32 32 33 33 function testRecordCheck() { 34 //TODO 34 35 $record = jDao::createRecord ('products'); 36 $this->assertEqual($record->id , ''); 37 $record->setPk(5); 38 $this->assertEqual($record->id , 5); 39 40 $this->assertEqual($record->getPk(), 5); 41 42 $record = jDao::createRecord ('description'); 43 $this->assertEqual($record->id , ''); 44 $this->assertEqual($record->lang , ''); 45 46 $record->setPk(5,'fr'); 47 $this->assertEqual($record->id , 5); 48 $this->assertEqual($record->lang , 'fr'); 49 50 $record->setPk(array(4,'en')); 51 $this->assertEqual($record->id , 4); 52 $this->assertEqual($record->lang , 'en'); 53 54 $pk = $record->getPk(); 55 $this->assertEqual($pk, array(4,'en')); 35 56 } 36 57 trunk/testapp/modules/jelix_tests/tests/jforms.compiler.html.php
r473 r483 26 26 27 27 28 class UTjforms extends jUnitTestCase {28 class UTjformsCompiler extends jUnitTestCase { 29 29 30 30 protected $_XmlControls = array( trunk/testapp/modules/jelix_tests/tests/jforms.compiler.html.php
r473 r483 26 26 27 27 28 class UTjforms extends jUnitTestCase {28 class UTjformsCompiler extends jUnitTestCase { 29 29 30 30 protected $_XmlControls = array(
