PageRenderTime 58ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html_cli.php

https://bitbucket.org/doubleface/jelix-jpu
PHP | 1441 lines | 1402 code | 22 blank | 17 comment | 22 complexity | c76bae4f28f1d2ef855496ecae1c9e98 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * @package testapp
  4. * @subpackage unittest module
  5. * @author Jouanneau Laurent
  6. * @contributor Dominique Papin, Julien Issler
  7. * @copyright 2007-2008 Jouanneau laurent
  8. * @copyright 2008 Dominique Papin
  9. * @copyright 2008 Julien Issler
  10. * @link http://www.jelix.org
  11. * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  12. */
  13. require_once(JELIX_LIB_PATH.'forms/jFormsBase.class.php');
  14. require_once(JELIX_LIB_PATH.'forms/jFormsBuilderBase.class.php');
  15. require_once(JELIX_LIB_PATH.'forms/jFormsDataContainer.class.php');
  16. require_once(JELIX_LIB_PATH.'plugins/jforms/html/html.jformsbuilder.php');
  17. class testHMLForm extends jFormsBase {
  18. }
  19. class testJFormsHtmlBuilder extends htmlJformsBuilder {
  20. function getJsContent() { $js= $this->jsContent; $this->jsContent = '';return $js;}
  21. function clearJs() { $this->jsContent = ''; }
  22. }
  23. class UTjformsHTMLBuilder extends jUnitTestCaseDb {
  24. protected static $mysharedfixture;
  25. function testStart() {
  26. self::$mysharedfixture = new stdClass;
  27. $GLOBALS['gJConfig']->locale = 'en_EN';
  28. self::$mysharedfixture->container = new jFormsDataContainer('formtest','');
  29. self::$mysharedfixture->form = new testHMLForm('formtest', self::$mysharedfixture->container, true );
  30. self::$mysharedfixture->form->securityLevel = 0;
  31. self::$mysharedfixture->builder = new testJFormsHtmlBuilder(self::$mysharedfixture->form);
  32. }
  33. function testOutputHeader(){
  34. self::$mysharedfixture->builder->setAction('jelix_tests~urlsig:url1',array());
  35. ob_start();
  36. self::$mysharedfixture->builder->outputHeader(array('method'=>'post'));
  37. $out = ob_get_clean();
  38. $result ='<form action="'.$GLOBALS['gJConfig']->urlengine['basePath'].'index.php" method="post" id="'.self::$mysharedfixture->builder->getName().'"><script type="text/javascript">
  39. //<![CDATA[
  40. jFormsJQ.tForm = new jFormsJQForm(\'jforms_formtest\');
  41. jFormsJQ.tForm.setErrorDecorator(new jFormsJQErrorDecoratorAlert());
  42. jFormsJQ.tForm.setHelpDecorator(new jFormsJQHelpDecoratorAlert());
  43. jFormsJQ.declareForm(jFormsJQ.tForm);
  44. //]]>
  45. </script><div class="jforms-hiddens"><input type="hidden" name="module" value="jelix_tests"/>
  46. <input type="hidden" name="action" value="urlsig:url1"/>
  47. </div>';
  48. $this->assertEqualOrDiff($result, $out);
  49. $this->assertEqualOrDiff('', self::$mysharedfixture->builder->getJsContent());
  50. self::$mysharedfixture->form->securityLevel = 1;
  51. self::$mysharedfixture->builder->setAction('jelix_tests~urlsig:url1',array('foo'=>'b>ar'));
  52. ob_start();
  53. self::$mysharedfixture->builder->outputHeader(array('method'=>'get'));
  54. $out = ob_get_clean();
  55. $result ='<form action="'.$GLOBALS['gJConfig']->urlengine['basePath'].'index.php" method="get" id="'.self::$mysharedfixture->builder->getName().'"><script type="text/javascript">
  56. //<![CDATA[
  57. jFormsJQ.tForm = new jFormsJQForm(\'jforms_formtest1\');
  58. jFormsJQ.tForm.setErrorDecorator(new jFormsJQErrorDecoratorAlert());
  59. jFormsJQ.tForm.setHelpDecorator(new jFormsJQHelpDecoratorAlert());
  60. jFormsJQ.declareForm(jFormsJQ.tForm);
  61. //]]>
  62. </script><div class="jforms-hiddens"><input type="hidden" name="foo" value="b&gt;ar"/>
  63. <input type="hidden" name="module" value="jelix_tests"/>
  64. <input type="hidden" name="action" value="urlsig:url1"/>
  65. <input type="hidden" name="__JFORMS_TOKEN__" value="'.self::$mysharedfixture->container->token.'"/>
  66. </div>';
  67. $this->assertEqualOrDiff($result, $out);
  68. self::$mysharedfixture->formname = self::$mysharedfixture->builder->getName();
  69. $this->assertEqualOrDiff('', self::$mysharedfixture->builder->getJsContent());
  70. self::$mysharedfixture->form->securityLevel = 0;
  71. }
  72. function testOutputFooter(){
  73. ob_start();
  74. self::$mysharedfixture->builder->outputFooter();
  75. $out = ob_get_clean();
  76. $this->assertEqualOrDiff('<script type="text/javascript">
  77. //<![CDATA[
  78. (function(){var c, c2;
  79. })();
  80. //]]>
  81. </script></form>', $out);
  82. }
  83. function testOutputInput(){
  84. $ctrl= new jFormsControlinput('input1');
  85. $ctrl->datatype= new jDatatypeString();
  86. $ctrl->label='Votre nom';
  87. self::$mysharedfixture->form->addControl($ctrl);
  88. ob_start();self::$mysharedfixture->builder->outputControlLabel($ctrl);$out = ob_get_clean();
  89. $this->assertEqualOrDiff('<label class="jforms-label" for="'.self::$mysharedfixture->formname.'_input1">Votre nom</label>', $out);
  90. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  91. $this->assertEqualOrDiff('<input type="text" name="input1" id="'.self::$mysharedfixture->formname.'_input1" value=""/>', $out);
  92. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'input1\', \'Votre nom\');
  93. c.errInvalid=\'"Votre nom" field is invalid\';
  94. jFormsJQ.tForm.addControl(c);
  95. ', self::$mysharedfixture->builder->getJsContent());
  96. self::$mysharedfixture->form->setData('input1','toto');
  97. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  98. $this->assertEqualOrDiff('<input type="text" name="input1" id="'.self::$mysharedfixture->formname.'_input1" value="toto"/>', $out);
  99. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'input1\', \'Votre nom\');
  100. c.errInvalid=\'"Votre nom" field is invalid\';
  101. jFormsJQ.tForm.addControl(c);
  102. ', self::$mysharedfixture->builder->getJsContent());
  103. $ctrl->defaultValue='laurent';
  104. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  105. $this->assertEqualOrDiff('<input type="text" name="input1" id="'.self::$mysharedfixture->formname.'_input1" value="toto"/>', $out);
  106. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'input1\', \'Votre nom\');
  107. c.errInvalid=\'"Votre nom" field is invalid\';
  108. jFormsJQ.tForm.addControl(c);
  109. ', self::$mysharedfixture->builder->getJsContent());
  110. self::$mysharedfixture->form->removeControl($ctrl->ref);
  111. self::$mysharedfixture->form->addControl($ctrl);
  112. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  113. $this->assertEqualOrDiff('<input type="text" name="input1" id="'.self::$mysharedfixture->formname.'_input1" value="laurent"/>', $out);
  114. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'input1\', \'Votre nom\');
  115. c.errInvalid=\'"Votre nom" field is invalid\';
  116. jFormsJQ.tForm.addControl(c);
  117. ', self::$mysharedfixture->builder->getJsContent());
  118. $ctrl->required=true;
  119. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  120. $this->assertEqualOrDiff('<input type="text" name="input1" id="'.self::$mysharedfixture->formname.'_input1" class=" jforms-required" value="laurent"/>', $out);
  121. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'input1\', \'Votre nom\');
  122. c.required = true;
  123. c.errRequired=\'"Votre nom" field is required\';
  124. c.errInvalid=\'"Votre nom" field is invalid\';
  125. jFormsJQ.tForm.addControl(c);
  126. ', self::$mysharedfixture->builder->getJsContent());
  127. $ctrl->setReadOnly(true);
  128. $ctrl->required=false;
  129. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  130. $this->assertEqualOrDiff('<input type="text" name="input1" id="'.self::$mysharedfixture->formname.'_input1" readonly="readonly" class=" jforms-readonly" value="laurent"/>', $out);
  131. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'input1\', \'Votre nom\');
  132. c.errInvalid=\'"Votre nom" field is invalid\';
  133. jFormsJQ.tForm.addControl(c);
  134. ', self::$mysharedfixture->builder->getJsContent());
  135. $ctrl->setReadOnly(false);
  136. $ctrl->help='some help';
  137. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  138. $this->assertEqualOrDiff('<input type="text" name="input1" id="'.self::$mysharedfixture->formname.'_input1" value="laurent"/><span class="jforms-help"><a href="javascript:jFormsJQ.showHelp(\''. self::$mysharedfixture->formname.'\',\'input1\')">?</a></span>', $out);
  139. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'input1\', \'Votre nom\');
  140. c.help=\'some help\';
  141. c.errInvalid=\'"Votre nom" field is invalid\';
  142. jFormsJQ.tForm.addControl(c);
  143. ', self::$mysharedfixture->builder->getJsContent());
  144. $ctrl->help="some \nhelp with ' and\nline break.";
  145. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  146. $this->assertEqualOrDiff('<input type="text" name="input1" id="'.self::$mysharedfixture->formname.'_input1" value="laurent"/><span class="jforms-help"><a href="javascript:jFormsJQ.showHelp(\''. self::$mysharedfixture->formname.'\',\'input1\')">?</a></span>', $out);
  147. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'input1\', \'Votre nom\');
  148. c.help=\'some \nhelp with \\\' and\nline break.\';
  149. c.errInvalid=\'"Votre nom" field is invalid\';
  150. jFormsJQ.tForm.addControl(c);
  151. ', self::$mysharedfixture->builder->getJsContent());
  152. $ctrl->hint='ceci est un tooltip';
  153. $ctrl->help='some help';
  154. ob_start();self::$mysharedfixture->builder->outputControlLabel($ctrl);$out = ob_get_clean();
  155. $this->assertEqualOrDiff('<label class="jforms-label" for="'.self::$mysharedfixture->formname.'_input1" title="ceci est un tooltip">Votre nom</label>', $out);
  156. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  157. $this->assertEqualOrDiff('<input type="text" name="input1" id="'.self::$mysharedfixture->formname.'_input1" title="ceci est un tooltip" value="laurent"/><span class="jforms-help"><a href="javascript:jFormsJQ.showHelp(\''. self::$mysharedfixture->formname.'\',\'input1\')">?</a></span>', $out);
  158. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'input1\', \'Votre nom\');
  159. c.help=\'some help\';
  160. c.errInvalid=\'"Votre nom" field is invalid\';
  161. jFormsJQ.tForm.addControl(c);
  162. ', self::$mysharedfixture->builder->getJsContent());
  163. $ctrl->help='';
  164. $ctrl->hint='';
  165. $ctrl->datatype->addFacet('maxLength',5);
  166. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  167. $this->assertEqualOrDiff('<input type="text" name="input1" id="'.self::$mysharedfixture->formname.'_input1" maxlength="5" value="laurent"/>', $out);
  168. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'input1\', \'Votre nom\');
  169. c.maxLength = \'5\';
  170. c.errInvalid=\'"Votre nom" field is invalid\';
  171. jFormsJQ.tForm.addControl(c);
  172. ', self::$mysharedfixture->builder->getJsContent());
  173. }
  174. function testOutputCheckbox(){
  175. $ctrl= new jFormsControlCheckbox('chk1');
  176. $ctrl->datatype= new jDatatypeString();
  177. $ctrl->label='Une option';
  178. self::$mysharedfixture->form->addControl($ctrl);
  179. ob_start();self::$mysharedfixture->builder->outputControlLabel($ctrl);$out = ob_get_clean();
  180. $this->assertEqualOrDiff('<label class="jforms-label" for="'.self::$mysharedfixture->formname.'_chk1">Une option</label>', $out);
  181. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  182. $this->assertEqualOrDiff('<input type="checkbox" name="chk1" id="'.self::$mysharedfixture->formname.'_chk1" value="1"/>', $out);
  183. $this->assertEqualOrDiff('c = new jFormsJQControlBoolean(\'chk1\', \'Une option\');
  184. c.errInvalid=\'"Une option" field is invalid\';
  185. jFormsJQ.tForm.addControl(c);
  186. ', self::$mysharedfixture->builder->getJsContent());
  187. self::$mysharedfixture->form->setData('chk1','1');
  188. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  189. $this->assertEqualOrDiff('<input type="checkbox" name="chk1" id="'.self::$mysharedfixture->formname.'_chk1" checked="checked" value="1"/>', $out);
  190. $this->assertEqualOrDiff('c = new jFormsJQControlBoolean(\'chk1\', \'Une option\');
  191. c.errInvalid=\'"Une option" field is invalid\';
  192. jFormsJQ.tForm.addControl(c);
  193. ', self::$mysharedfixture->builder->getJsContent());
  194. $ctrl= new jFormsControlCheckbox('chk2');
  195. $ctrl->datatype= new jDatatypeString();
  196. $ctrl->label='Une option';
  197. self::$mysharedfixture->form->addControl($ctrl);
  198. ob_start();self::$mysharedfixture->builder->outputControlLabel($ctrl);$out = ob_get_clean();
  199. $this->assertEqualOrDiff('<label class="jforms-label" for="'.self::$mysharedfixture->formname.'_chk2">Une option</label>', $out);
  200. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  201. $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.self::$mysharedfixture->formname.'_chk2" value="1"/>', $out);
  202. $this->assertEqualOrDiff('c = new jFormsJQControlBoolean(\'chk2\', \'Une option\');
  203. c.errInvalid=\'"Une option" field is invalid\';
  204. jFormsJQ.tForm.addControl(c);
  205. ', self::$mysharedfixture->builder->getJsContent());
  206. $ctrl->defaultValue='1';
  207. self::$mysharedfixture->form->removeControl($ctrl->ref);
  208. self::$mysharedfixture->form->addControl($ctrl);
  209. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  210. $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.self::$mysharedfixture->formname.'_chk2" checked="checked" value="1"/>', $out);
  211. $this->assertEqualOrDiff('c = new jFormsJQControlBoolean(\'chk2\', \'Une option\');
  212. c.errInvalid=\'"Une option" field is invalid\';
  213. jFormsJQ.tForm.addControl(c);
  214. ', self::$mysharedfixture->builder->getJsContent());
  215. self::$mysharedfixture->form->setData('chk2', '0');
  216. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  217. $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.self::$mysharedfixture->formname.'_chk2" value="1"/>', $out);
  218. $this->assertEqualOrDiff('c = new jFormsJQControlBoolean(\'chk2\', \'Une option\');
  219. c.errInvalid=\'"Une option" field is invalid\';
  220. jFormsJQ.tForm.addControl(c);
  221. ', self::$mysharedfixture->builder->getJsContent());
  222. $ctrl->setReadOnly(true);
  223. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  224. $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.self::$mysharedfixture->formname.'_chk2" readonly="readonly" class=" jforms-readonly" value="1"/>', $out);
  225. $this->assertEqualOrDiff('c = new jFormsJQControlBoolean(\'chk2\', \'Une option\');
  226. c.errInvalid=\'"Une option" field is invalid\';
  227. jFormsJQ.tForm.addControl(c);
  228. ', self::$mysharedfixture->builder->getJsContent());
  229. self::$mysharedfixture->form->setData('chk2', '1');
  230. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  231. $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.self::$mysharedfixture->formname.'_chk2" readonly="readonly" class=" jforms-readonly" checked="checked" value="1"/>', $out);
  232. $this->assertEqualOrDiff('c = new jFormsJQControlBoolean(\'chk2\', \'Une option\');
  233. c.errInvalid=\'"Une option" field is invalid\';
  234. jFormsJQ.tForm.addControl(c);
  235. ', self::$mysharedfixture->builder->getJsContent());
  236. $ctrl->hint='ceci est un tooltip';
  237. ob_start();self::$mysharedfixture->builder->outputControlLabel($ctrl);$out = ob_get_clean();
  238. $this->assertEqualOrDiff('<label class="jforms-label" for="'.self::$mysharedfixture->formname.'_chk2" title="ceci est un tooltip">Une option</label>', $out);
  239. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  240. $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.self::$mysharedfixture->formname.'_chk2" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" checked="checked" value="1"/>', $out);
  241. $this->assertEqualOrDiff('c = new jFormsJQControlBoolean(\'chk2\', \'Une option\');
  242. c.errInvalid=\'"Une option" field is invalid\';
  243. jFormsJQ.tForm.addControl(c);
  244. ', self::$mysharedfixture->builder->getJsContent());
  245. }
  246. function testOutputCheckboxes(){
  247. $ctrl= new jFormsControlcheckboxes('choixsimple');
  248. $ctrl->datatype= new jDatatypeString();
  249. $ctrl->label='Vos choix';
  250. $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findAll','name','id');
  251. self::$mysharedfixture->form->addControl($ctrl);
  252. $records = array(
  253. array('id'=>'10', 'name'=>'foo', 'price'=>'12'),
  254. array('id'=>'11', 'name'=>'bar', 'price'=>'54'),
  255. array('id'=>'23', 'name'=>'baz', 'price'=>'97'),
  256. );
  257. $this->insertRecordsIntoTable('product_test', array('id','name','price'), $records, true);
  258. ob_start();self::$mysharedfixture->builder->outputControlLabel($ctrl);$out = ob_get_clean();
  259. $this->assertEqualOrDiff('<span class="jforms-label">Vos choix</span>', $out);
  260. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  261. $result='<span class="jforms-chkbox jforms-ctl-choixsimple"><input type="checkbox" name="choixsimple[]" id="'.self::$mysharedfixture->formname.'_choixsimple_0" value="10"/><label for="'.self::$mysharedfixture->formname.'_choixsimple_0">foo</label></span>';
  262. $result.='<span class="jforms-chkbox jforms-ctl-choixsimple"><input type="checkbox" name="choixsimple[]" id="'.self::$mysharedfixture->formname.'_choixsimple_1" value="11"/><label for="'.self::$mysharedfixture->formname.'_choixsimple_1">bar</label></span>';
  263. $result.='<span class="jforms-chkbox jforms-ctl-choixsimple"><input type="checkbox" name="choixsimple[]" id="'.self::$mysharedfixture->formname.'_choixsimple_2" value="23"/><label for="'.self::$mysharedfixture->formname.'_choixsimple_2">baz</label></span>';
  264. $this->assertEqualOrDiff($result, $out);
  265. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'choixsimple[]\', \'Vos choix\');
  266. c.errInvalid=\'"Vos choix" field is invalid\';
  267. jFormsJQ.tForm.addControl(c);
  268. ', self::$mysharedfixture->builder->getJsContent());
  269. self::$mysharedfixture->form->setData('choixsimple',11);
  270. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  271. $result='<span class="jforms-chkbox jforms-ctl-choixsimple"><input type="checkbox" name="choixsimple[]" id="'.self::$mysharedfixture->formname.'_choixsimple_0" value="10"/><label for="'.self::$mysharedfixture->formname.'_choixsimple_0">foo</label></span>';
  272. $result.='<span class="jforms-chkbox jforms-ctl-choixsimple"><input type="checkbox" name="choixsimple[]" id="'.self::$mysharedfixture->formname.'_choixsimple_1" value="11" checked="checked"/><label for="'.self::$mysharedfixture->formname.'_choixsimple_1">bar</label></span>';
  273. $result.='<span class="jforms-chkbox jforms-ctl-choixsimple"><input type="checkbox" name="choixsimple[]" id="'.self::$mysharedfixture->formname.'_choixsimple_2" value="23"/><label for="'.self::$mysharedfixture->formname.'_choixsimple_2">baz</label></span>';
  274. $this->assertEqualOrDiff($result, $out);
  275. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'choixsimple[]\', \'Vos choix\');
  276. c.errInvalid=\'"Vos choix" field is invalid\';
  277. jFormsJQ.tForm.addControl(c);
  278. ', self::$mysharedfixture->builder->getJsContent());
  279. $ctrl= new jFormsControlcheckboxes('choixmultiple');
  280. $ctrl->datatype= new jDatatypeString();
  281. $ctrl->label='Vos choix';
  282. $ctrl->datasource= new jFormsStaticDatasource();
  283. $ctrl->datasource->data = array(
  284. '10'=>'foo',
  285. '11'=>'bar',
  286. '23'=>'baz',
  287. );
  288. self::$mysharedfixture->form->addControl($ctrl);
  289. ob_start();self::$mysharedfixture->builder->outputControlLabel($ctrl);$out = ob_get_clean();
  290. $this->assertEqualOrDiff('<span class="jforms-label">Vos choix</span>', $out);
  291. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  292. $result='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.self::$mysharedfixture->formname.'_choixmultiple_0" value="10"/><label for="'.self::$mysharedfixture->formname.'_choixmultiple_0">foo</label></span>';
  293. $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.self::$mysharedfixture->formname.'_choixmultiple_1" value="11"/><label for="'.self::$mysharedfixture->formname.'_choixmultiple_1">bar</label></span>';
  294. $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.self::$mysharedfixture->formname.'_choixmultiple_2" value="23"/><label for="'.self::$mysharedfixture->formname.'_choixmultiple_2">baz</label></span>';
  295. $this->assertEqualOrDiff($result, $out);
  296. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'choixmultiple[]\', \'Vos choix\');
  297. c.errInvalid=\'"Vos choix" field is invalid\';
  298. jFormsJQ.tForm.addControl(c);
  299. ', self::$mysharedfixture->builder->getJsContent());
  300. self::$mysharedfixture->form->setData('choixmultiple',11);
  301. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  302. $result='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.self::$mysharedfixture->formname.'_choixmultiple_0" value="10"/><label for="'.self::$mysharedfixture->formname.'_choixmultiple_0">foo</label></span>';
  303. $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.self::$mysharedfixture->formname.'_choixmultiple_1" value="11" checked="checked"/><label for="'.self::$mysharedfixture->formname.'_choixmultiple_1">bar</label></span>';
  304. $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.self::$mysharedfixture->formname.'_choixmultiple_2" value="23"/><label for="'.self::$mysharedfixture->formname.'_choixmultiple_2">baz</label></span>';
  305. $this->assertEqualOrDiff($result, $out);
  306. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'choixmultiple[]\', \'Vos choix\');
  307. c.errInvalid=\'"Vos choix" field is invalid\';
  308. jFormsJQ.tForm.addControl(c);
  309. ', self::$mysharedfixture->builder->getJsContent());
  310. self::$mysharedfixture->form->setData('choixmultiple',array(10,23));
  311. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  312. $result='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.self::$mysharedfixture->formname.'_choixmultiple_0" value="10" checked="checked"/><label for="'.self::$mysharedfixture->formname.'_choixmultiple_0">foo</label></span>';
  313. $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.self::$mysharedfixture->formname.'_choixmultiple_1" value="11"/><label for="'.self::$mysharedfixture->formname.'_choixmultiple_1">bar</label></span>';
  314. $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.self::$mysharedfixture->formname.'_choixmultiple_2" value="23" checked="checked"/><label for="'.self::$mysharedfixture->formname.'_choixmultiple_2">baz</label></span>';
  315. $this->assertEqualOrDiff($result, $out);
  316. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'choixmultiple[]\', \'Vos choix\');
  317. c.errInvalid=\'"Vos choix" field is invalid\';
  318. jFormsJQ.tForm.addControl(c);
  319. ', self::$mysharedfixture->builder->getJsContent());
  320. $ctrl->setReadOnly(true);
  321. $ctrl->hint='ceci est un tooltip';
  322. ob_start();self::$mysharedfixture->builder->outputControlLabel($ctrl);$out = ob_get_clean();
  323. $this->assertEqualOrDiff('<span class="jforms-label" title="ceci est un tooltip">Vos choix</span>', $out);
  324. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  325. $result='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.self::$mysharedfixture->formname.'_choixmultiple_0" value="10" checked="checked" readonly="readonly" class=" jforms-readonly"/><label for="'.self::$mysharedfixture->formname.'_choixmultiple_0">foo</label></span>';
  326. $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.self::$mysharedfixture->formname.'_choixmultiple_1" value="11" readonly="readonly" class=" jforms-readonly"/><label for="'.self::$mysharedfixture->formname.'_choixmultiple_1">bar</label></span>';
  327. $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.self::$mysharedfixture->formname.'_choixmultiple_2" value="23" checked="checked" readonly="readonly" class=" jforms-readonly"/><label for="'.self::$mysharedfixture->formname.'_choixmultiple_2">baz</label></span>';
  328. $this->assertEqualOrDiff($result, $out);
  329. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'choixmultiple[]\', \'Vos choix\');
  330. c.errInvalid=\'"Vos choix" field is invalid\';
  331. jFormsJQ.tForm.addControl(c);
  332. ', self::$mysharedfixture->builder->getJsContent());
  333. }
  334. function testOutputRadiobuttons(){
  335. $ctrl= new jFormsControlradiobuttons('rbchoixsimple');
  336. $ctrl->datatype= new jDatatypeString();
  337. $ctrl->label='Votre choix';
  338. $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findAll','name','id');
  339. self::$mysharedfixture->form->addControl($ctrl);
  340. ob_start();self::$mysharedfixture->builder->outputControlLabel($ctrl);$out = ob_get_clean();
  341. $this->assertEqualOrDiff('<span class="jforms-label">Votre choix</span>', $out);
  342. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  343. $result='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_0" value="10"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_0">foo</label></span>';
  344. $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_1" value="11"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_1">bar</label></span>';
  345. $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_2" value="23"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_2">baz</label></span>';
  346. $this->assertEqualOrDiff($result, $out);
  347. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'rbchoixsimple\', \'Votre choix\');
  348. c.errInvalid=\'"Votre choix" field is invalid\';
  349. jFormsJQ.tForm.addControl(c);
  350. ', self::$mysharedfixture->builder->getJsContent());
  351. self::$mysharedfixture->form->setData('rbchoixsimple',11);
  352. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  353. $result='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_0" value="10"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_0">foo</label></span>';
  354. $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_1" value="11" checked="checked"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_1">bar</label></span>';
  355. $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_2" value="23"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_2">baz</label></span>';
  356. $this->assertEqualOrDiff($result, $out);
  357. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'rbchoixsimple\', \'Votre choix\');
  358. c.errInvalid=\'"Votre choix" field is invalid\';
  359. jFormsJQ.tForm.addControl(c);
  360. ', self::$mysharedfixture->builder->getJsContent());
  361. $ctrl->datasource= new jFormsStaticDatasource();
  362. $ctrl->datasource->data = array(
  363. '10'=>'foo',
  364. '11'=>'bar',
  365. '23'=>'baz',
  366. );
  367. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  368. $result='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_0" value="10"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_0">foo</label></span>';
  369. $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_1" value="11" checked="checked"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_1">bar</label></span>';
  370. $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_2" value="23"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_2">baz</label></span>';
  371. $this->assertEqualOrDiff($result, $out);
  372. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'rbchoixsimple\', \'Votre choix\');
  373. c.errInvalid=\'"Votre choix" field is invalid\';
  374. jFormsJQ.tForm.addControl(c);
  375. ', self::$mysharedfixture->builder->getJsContent());
  376. self::$mysharedfixture->form->setData('rbchoixsimple',23);
  377. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  378. $result='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_0" value="10"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_0">foo</label></span>';
  379. $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_1" value="11"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_1">bar</label></span>';
  380. $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_2" value="23" checked="checked"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_2">baz</label></span>';
  381. $this->assertEqualOrDiff($result, $out);
  382. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'rbchoixsimple\', \'Votre choix\');
  383. c.errInvalid=\'"Votre choix" field is invalid\';
  384. jFormsJQ.tForm.addControl(c);
  385. ', self::$mysharedfixture->builder->getJsContent());
  386. $ctrl->setReadOnly(true);
  387. $ctrl->hint='ceci est un tooltip';
  388. ob_start();self::$mysharedfixture->builder->outputControlLabel($ctrl);$out = ob_get_clean();
  389. $this->assertEqualOrDiff('<span class="jforms-label" title="ceci est un tooltip">Votre choix</span>', $out);
  390. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  391. $result='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_0" value="10" readonly="readonly" class=" jforms-readonly"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_0">foo</label></span>';
  392. $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_1" value="11" readonly="readonly" class=" jforms-readonly"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_1">bar</label></span>';
  393. $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_2" value="23" checked="checked" readonly="readonly" class=" jforms-readonly"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_2">baz</label></span>';
  394. $this->assertEqualOrDiff($result, $out);
  395. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'rbchoixsimple\', \'Votre choix\');
  396. c.errInvalid=\'"Votre choix" field is invalid\';
  397. jFormsJQ.tForm.addControl(c);
  398. ', self::$mysharedfixture->builder->getJsContent());
  399. self::$mysharedfixture->builder->clearJs();
  400. $ctrl->datasource = new jFormsStaticDatasource();
  401. $ctrl->datasource->data = array('1'=>'Yes','0'=>'No');
  402. self::$mysharedfixture->form->setReadOnly('rbchoixsimple',false);
  403. self::$mysharedfixture->form->setData('rbchoixsimple',null);
  404. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  405. $result='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_0" value="1"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_0">Yes</label></span>';
  406. $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_1" value="0"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_1">No</label></span>';
  407. $this->assertEqualOrDiff($result, $out);
  408. self::$mysharedfixture->form->setData('rbchoixsimple',0);
  409. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  410. $result='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_0" value="1"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_0">Yes</label></span>';
  411. $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.self::$mysharedfixture->formname.'_rbchoixsimple_1" value="0" checked="checked"/><label for="'.self::$mysharedfixture->formname.'_rbchoixsimple_1">No</label></span>';
  412. $this->assertEqualOrDiff($result, $out);
  413. self::$mysharedfixture->builder->clearJs();
  414. }
  415. function testOutputMenulist(){
  416. $ctrl= new jFormsControlmenulist('menulist1');
  417. $ctrl->datatype= new jDatatypeString();
  418. $ctrl->label='Votre choix';
  419. $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findAll','name','id');
  420. self::$mysharedfixture->form->addControl($ctrl);
  421. ob_start();self::$mysharedfixture->builder->outputControlLabel($ctrl);$out = ob_get_clean();
  422. $this->assertEqualOrDiff('<label class="jforms-label" for="'.self::$mysharedfixture->formname.'_menulist1">Votre choix</label>', $out);
  423. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  424. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" size="1">';
  425. $result.='<option value="" selected="selected"></option>';
  426. $result.='<option value="10">foo</option>';
  427. $result.='<option value="11">bar</option>';
  428. $result.='<option value="23">baz</option>';
  429. $result.='</select>';
  430. $this->assertEqualOrDiff($result, $out);
  431. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'menulist1\', \'Votre choix\');
  432. c.errInvalid=\'"Votre choix" field is invalid\';
  433. jFormsJQ.tForm.addControl(c);
  434. ', self::$mysharedfixture->builder->getJsContent());
  435. self::$mysharedfixture->form->setData('menulist1',11);
  436. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  437. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" size="1">';
  438. $result.='<option value=""></option>';
  439. $result.='<option value="10">foo</option>';
  440. $result.='<option value="11" selected="selected">bar</option>';
  441. $result.='<option value="23">baz</option>';
  442. $result.='</select>';
  443. $this->assertEqualOrDiff($result, $out);
  444. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'menulist1\', \'Votre choix\');
  445. c.errInvalid=\'"Votre choix" field is invalid\';
  446. jFormsJQ.tForm.addControl(c);
  447. ', self::$mysharedfixture->builder->getJsContent());
  448. $ctrl->datasource= new jFormsStaticDatasource();
  449. $ctrl->datasource->data = array(
  450. '10'=>'foo',
  451. '11'=>'bar',
  452. '23'=>'baz',
  453. );
  454. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  455. $this->assertEqualOrDiff($result, $out);
  456. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'menulist1\', \'Votre choix\');
  457. c.errInvalid=\'"Votre choix" field is invalid\';
  458. jFormsJQ.tForm.addControl(c);
  459. ', self::$mysharedfixture->builder->getJsContent());
  460. $ctrl->setReadOnly(true);
  461. $ctrl->hint='ceci est un tooltip';
  462. ob_start();self::$mysharedfixture->builder->outputControlLabel($ctrl);$out = ob_get_clean();
  463. $this->assertEqualOrDiff('<label class="jforms-label" for="'.self::$mysharedfixture->formname.'_menulist1" title="ceci est un tooltip">Votre choix</label>', $out);
  464. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  465. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" title="ceci est un tooltip" class=" jforms-readonly" size="1">';
  466. $result.='<option value=""></option>';
  467. $result.='<option value="10">foo</option>';
  468. $result.='<option value="11" selected="selected">bar</option>';
  469. $result.='<option value="23">baz</option>';
  470. $result.='</select>';
  471. $this->assertEqualOrDiff($result, $out);
  472. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'menulist1\', \'Votre choix\');
  473. c.errInvalid=\'"Votre choix" field is invalid\';
  474. jFormsJQ.tForm.addControl(c);
  475. ', self::$mysharedfixture->builder->getJsContent());
  476. $ctrl->required = true;
  477. self::$mysharedfixture->form->setData('menulist1',"23");
  478. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  479. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" title="ceci est un tooltip" class=" jforms-readonly" size="1">';
  480. $result.='<option value="10">foo</option>';
  481. $result.='<option value="11">bar</option>';
  482. $result.='<option value="23" selected="selected">baz</option>';
  483. $result.='</select>';
  484. $this->assertEqualOrDiff($result, $out);
  485. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'menulist1\', \'Votre choix\');
  486. c.required = true;
  487. c.errRequired=\'"Votre choix" field is required\';
  488. c.errInvalid=\'"Votre choix" field is invalid\';
  489. jFormsJQ.tForm.addControl(c);
  490. ', self::$mysharedfixture->builder->getJsContent());
  491. $ctrl->required = false;
  492. self::$mysharedfixture->form->setData('menulist1',"");
  493. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  494. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" title="ceci est un tooltip" class=" jforms-readonly" size="1">';
  495. $result.='<option value="" selected="selected"></option>';
  496. $result.='<option value="10">foo</option>';
  497. $result.='<option value="11">bar</option>';
  498. $result.='<option value="23">baz</option>';
  499. $result.='</select>';
  500. $this->assertEqualOrDiff($result, $out);
  501. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'menulist1\', \'Votre choix\');
  502. c.errInvalid=\'"Votre choix" field is invalid\';
  503. jFormsJQ.tForm.addControl(c);
  504. ', self::$mysharedfixture->builder->getJsContent());
  505. $ctrl->setReadOnly(false);
  506. $ctrl->hint='';
  507. $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findByMaxId','name','id','','15');
  508. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  509. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" size="1">';
  510. $result.='<option value="" selected="selected"></option>';
  511. $result.='<option value="10">foo</option>';
  512. $result.='<option value="11">bar</option>';
  513. $result.='</select>';
  514. $this->assertEqualOrDiff($result, $out);
  515. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'menulist1\', \'Votre choix\');
  516. c.errInvalid=\'"Votre choix" field is invalid\';
  517. jFormsJQ.tForm.addControl(c);
  518. ', self::$mysharedfixture->builder->getJsContent());
  519. $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findByMaxId','name','id','','11');
  520. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  521. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" size="1">';
  522. $result.='<option value="" selected="selected"></option>';
  523. $result.='<option value="10">foo</option>';
  524. $result.='</select>';
  525. $this->assertEqualOrDiff($result, $out);
  526. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'menulist1\', \'Votre choix\');
  527. c.errInvalid=\'"Votre choix" field is invalid\';
  528. jFormsJQ.tForm.addControl(c);
  529. ', self::$mysharedfixture->builder->getJsContent());
  530. self::$mysharedfixture->form->setData('menulist1',"10");
  531. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  532. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" size="1">';
  533. $result.='<option value=""></option>';
  534. $result.='<option value="10" selected="selected">foo</option>';
  535. $result.='</select>';
  536. $this->assertEqualOrDiff($result, $out);
  537. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'menulist1\', \'Votre choix\');
  538. c.errInvalid=\'"Votre choix" field is invalid\';
  539. jFormsJQ.tForm.addControl(c);
  540. ', self::$mysharedfixture->builder->getJsContent());
  541. self::$mysharedfixture->form->setData('menulist1',"");
  542. self::$mysharedfixture->form->addControl(new jFormsControlHidden('hidden1'));
  543. self::$mysharedfixture->form->setData('hidden1',"25");
  544. $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findByMaxId','name','id','',null, 'hidden1');
  545. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  546. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" size="1">';
  547. $result.='<option value="" selected="selected"></option>';
  548. $result.='<option value="10">foo</option>';
  549. $result.='<option value="11">bar</option>';
  550. $result.='<option value="23">baz</option>';
  551. $result.='</select>';
  552. $this->assertEqualOrDiff($result, $out);
  553. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'menulist1\', \'Votre choix\');
  554. c.errInvalid=\'"Votre choix" field is invalid\';
  555. jFormsJQ.tForm.addControl(c);
  556. ', self::$mysharedfixture->builder->getJsContent());
  557. self::$mysharedfixture->form->setData('hidden1',"15");
  558. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  559. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" size="1">';
  560. $result.='<option value="" selected="selected"></option>';
  561. $result.='<option value="10">foo</option>';
  562. $result.='<option value="11">bar</option>';
  563. $result.='</select>';
  564. $this->assertEqualOrDiff($result, $out);
  565. self::$mysharedfixture->form->setData('menulist1',"10");
  566. self::$mysharedfixture->form->setData('hidden1',"11");
  567. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  568. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" size="1">';
  569. $result.='<option value=""></option>';
  570. $result.='<option value="10" selected="selected">foo</option>';
  571. $result.='</select>';
  572. $this->assertEqualOrDiff($result, $out);
  573. self::$mysharedfixture->form->setData('menulist1',"");
  574. $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findByMaxId','name,price','id','','25',null);
  575. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  576. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" size="1">';
  577. $result.='<option value="" selected="selected"></option>';
  578. $result.='<option value="10">foo12</option>';
  579. $result.='<option value="11">bar54</option>';
  580. $result.='<option value="23">baz97</option>';
  581. $result.='</select>';
  582. $this->assertEqualOrDiff($result, $out);
  583. $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findByMaxId','name,price','id','','25',null,' - ');
  584. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  585. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" size="1">';
  586. $result.='<option value="" selected="selected"></option>';
  587. $result.='<option value="10">foo - 12</option>';
  588. $result.='<option value="11">bar - 54</option>';
  589. $result.='<option value="23">baz - 97</option>';
  590. $result.='</select>';
  591. $this->assertEqualOrDiff($result, $out);
  592. $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findBetweenId','name,price','id','','9,25',null,' - ');
  593. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  594. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" size="1">';
  595. $result.='<option value="" selected="selected"></option>';
  596. $result.='<option value="10">foo - 12</option>';
  597. $result.='<option value="11">bar - 54</option>';
  598. $result.='<option value="23">baz - 97</option>';
  599. $result.='</select>';
  600. $this->assertEqualOrDiff($result, $out);
  601. $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findBetweenId','name,price','id','','10,25',null,' - ');
  602. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  603. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" size="1">';
  604. $result.='<option value="" selected="selected"></option>';
  605. $result.='<option value="11">bar - 54</option>';
  606. $result.='<option value="23">baz - 97</option>';
  607. $result.='</select>';
  608. $this->assertEqualOrDiff($result, $out);
  609. self::$mysharedfixture->form->addControl(new jFormsControlHidden('hidden2'));
  610. self::$mysharedfixture->form->setData('hidden1',"9");
  611. self::$mysharedfixture->form->setData('hidden2',"25");
  612. $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findBetweenId','name,price','id','',null,'hidden1,hidden2',' - ');
  613. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  614. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" size="1">';
  615. $result.='<option value="" selected="selected"></option>';
  616. $result.='<option value="10">foo - 12</option>';
  617. $result.='<option value="11">bar - 54</option>';
  618. $result.='<option value="23">baz - 97</option>';
  619. $result.='</select>';
  620. $this->assertEqualOrDiff($result, $out);
  621. self::$mysharedfixture->form->setData('hidden1',"10");
  622. self::$mysharedfixture->form->setData('hidden2',"25");
  623. $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findBetweenId','name,price','id','',null,'hidden1,hidden2',' - ');
  624. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  625. $result='<select name="menulist1" id="'.self::$mysharedfixture->formname.'_menulist1" size="1">';
  626. $result.='<option value="" selected="selected"></option>';
  627. $result.='<option value="11">bar - 54</option>';
  628. $result.='<option value="23">baz - 97</option>';
  629. $result.='</select>';
  630. $this->assertEqualOrDiff($result, $out);
  631. self::$mysharedfixture->form->removeControl('hidden2');
  632. self::$mysharedfixture->form->setData('hidden1',"11");
  633. self::$mysharedfixture->builder->clearJs();
  634. }
  635. function testOutputListbox(){
  636. $ctrl= new jFormsControllistbox('listbox1');
  637. $ctrl->datatype= new jDatatypeString();
  638. $ctrl->label='Votre choix';
  639. $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findAll','name','id');
  640. self::$mysharedfixture->form->addControl($ctrl);
  641. ob_start();self::$mysharedfixture->builder->outputControlLabel($ctrl);$out = ob_get_clean();
  642. $this->assertEqualOrDiff('<label class="jforms-label" for="'.self::$mysharedfixture->formname.'_listbox1">Votre choix</label>', $out);
  643. ob_start();self::$mysharedfixture->builder->outputControl($ctrl);$out = ob_get_clean();
  644. $result='<select name="listbox1" id="'.self::$mysharedfixture->formname.'_listbox1" size="4">';
  645. $result.='<option value="10">foo</option>';
  646. $result.='<option value="11">bar</option>';
  647. $result.='<option value="23">baz</option>';
  648. $result.='</select>';
  649. $this->assertEqualOrDiff($result

Large files files are truncated, but you can click here to view the full file