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

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

https://bitbucket.org/jelix/jelix-1.2.x
PHP | 426 lines | 367 code | 49 blank | 10 comment | 0 complexity | f5cbb9d02adf31681c3954155b339d44 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, JSON, GPL-3.0, GPL-2.0
  1. <?php
  2. /**
  3. * @package testapp
  4. * @subpackage unittest module
  5. * @author Laurent Jouanneau
  6. * @contributor Julien Issler
  7. * @copyright 2007-2008 Laurent Jouanneau
  8. * @copyright 2008-2010 Julien Issler
  9. * @link http://www.jelix.org
  10. * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  11. */
  12. require_once(JELIX_LIB_PATH.'forms/jFormsBase.class.php');
  13. require_once(JELIX_LIB_PATH.'forms/jFormsBuilderBase.class.php');
  14. include_once(JELIX_LIB_PATH.'forms/jFormsBuilderHtml.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 testHMLForm2 extends jFormsBase {
  18. }
  19. class testJFormsHtmlBuilder2 extends htmlJformsBuilder {
  20. function getJsContent() { $js= $this->jsContent; $this->jsContent = '';return $js;}
  21. function clearJs() { $this->jsContent = ''; }
  22. }
  23. class UTjformsHTMLBuilder2 extends jUnitTestCaseDb {
  24. protected $form;
  25. protected $container;
  26. protected $builder;
  27. protected $formname;
  28. function testStart() {
  29. $this->container = new jFormsDataContainer('formtesthtmlbuilder','0');
  30. $this->form = new testHMLForm2('formtesthtmlbuilder', $this->container, true );
  31. $this->builder = new testJFormsHtmlBuilder2($this->form);
  32. $this->formname = $this->builder->getName();
  33. }
  34. function testOutputGroup(){
  35. $group= new jFormsControlgroup('identity');
  36. $group->label='Your identity';
  37. $ctrl= new jFormsControlinput('nom');
  38. $ctrl->required=true;
  39. $ctrl->label='Your name';
  40. $group->addChildControl($ctrl);
  41. $ctrl= new jFormsControlinput('prenom');
  42. $ctrl->defaultValue='robert';
  43. $ctrl->label='Your firstname';
  44. $group->addChildControl($ctrl);
  45. $ctrl= new jFormsControlradiobuttons('sexe');
  46. $ctrl->required=true;
  47. $ctrl->label='Vous êtes ';
  48. $ctrl->alertRequired='Vous devez indiquer le sexe, même si vous ne savez pas :-)';
  49. $ctrl->datasource= new jFormsStaticDatasource();
  50. $ctrl->datasource->data = array(
  51. 'h'=>'un homme',
  52. 'f'=>'une femme',
  53. 'no'=>'je ne sais pas',
  54. );
  55. $group->addChildControl($ctrl);
  56. $ctrl= new jFormsControlinput('mail');
  57. $ctrl->datatype= new jDatatypeemail();
  58. $ctrl->label='Votre mail';
  59. $group->addChildControl($ctrl);
  60. $this->form->addControl($group);
  61. ob_start();$this->builder->outputControlLabel($group);$out = ob_get_clean();
  62. $this->assertEqualOrDiff('', $out);
  63. $expected = '<fieldset><legend>Your identity</legend>'."\n";
  64. $expected .= '<table class="jforms-table-group" border="0">'."\n";
  65. $expected .= '<tr><th scope="row"><label class="jforms-label jforms-required" for="'.$this->formname.'_nom" id="'.$this->formname.'_nom_label">Your name<span class="jforms-required-star">*</span></label>'."\n".'</th>'."\n";
  66. $expected .= '<td><input name="nom" id="'.$this->formname.'_nom" class="jforms-ctrl-input jforms-required" value="" type="text"/>'."\n".'</td></tr>'."\n";
  67. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_prenom" id="'.$this->formname.'_prenom_label">Your firstname</label>'."\n".'</th>'."\n";
  68. $expected .= '<td><input name="prenom" id="'.$this->formname.'_prenom" class="jforms-ctrl-input" value="robert" type="text"/>'."\n".'</td></tr>'."\n";
  69. $expected .= '<tr><th scope="row"><span class="jforms-label jforms-required" id="'.$this->formname.'_sexe_label">Vous êtes <span class="jforms-required-star">*</span></span>'."\n".'</th>'."\n";
  70. $expected .= '<td><span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_0" class="jforms-ctrl-radiobuttons jforms-required" value="h"/><label for="'.$this->formname.'_sexe_0">un homme</label></span>'."\n";
  71. $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_1" class="jforms-ctrl-radiobuttons jforms-required" value="f"/><label for="'.$this->formname.'_sexe_1">une femme</label></span>'."\n";
  72. $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_2" class="jforms-ctrl-radiobuttons jforms-required" value="no"/><label for="'.$this->formname.'_sexe_2">je ne sais pas</label></span>'."\n\n".'</td></tr>'."\n";
  73. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_mail" id="'.$this->formname.'_mail_label">Votre mail</label>'."\n".'</th>'."\n";
  74. $expected .= '<td><input name="mail" id="'.$this->formname.'_mail" class="jforms-ctrl-input" value="" type="text"/>'."\n".'</td></tr>'."\n</table></fieldset>\n";
  75. ob_start();$this->builder->outputControl($group);$out = ob_get_clean();
  76. $this->assertEqualOrDiff($expected, $out);
  77. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'nom\', \'Your name\');
  78. c.required = true;
  79. c.errRequired=\'"Your name" field is required\';
  80. c.errInvalid=\'"Your name" field is invalid\';
  81. jFormsJQ.tForm.addControl(c);
  82. c = new jFormsJQControlString(\'prenom\', \'Your firstname\');
  83. c.errInvalid=\'"Your firstname" field is invalid\';
  84. jFormsJQ.tForm.addControl(c);
  85. c = new jFormsJQControlString(\'sexe\', \'Vous êtes \');
  86. c.required = true;
  87. c.errRequired=\'Vous devez indiquer le sexe, même si vous ne savez pas :-)\';
  88. c.errInvalid=\'"Vous êtes " field is invalid\';
  89. jFormsJQ.tForm.addControl(c);
  90. c = new jFormsJQControlEmail(\'mail\', \'Votre mail\');
  91. c.errInvalid=\'"Votre mail" field is invalid\';
  92. jFormsJQ.tForm.addControl(c);
  93. ', $this->builder->getJsContent());
  94. $group->setReadOnly(true);
  95. $expected = '<fieldset><legend>Your identity</legend>'."\n";
  96. $expected .= '<table class="jforms-table-group" border="0">'."\n";
  97. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_nom" id="'.$this->formname.'_nom_label">Your name</label>'."\n".'</th>'."\n";
  98. $expected .= '<td><input name="nom" id="'.$this->formname.'_nom" readonly="readonly" class="jforms-ctrl-input jforms-readonly" value="" type="text"/>'."\n".'</td></tr>'."\n";
  99. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_prenom" id="'.$this->formname.'_prenom_label">Your firstname</label>'."\n".'</th>'."\n";
  100. $expected .= '<td><input name="prenom" id="'.$this->formname.'_prenom" readonly="readonly" class="jforms-ctrl-input jforms-readonly" value="robert" type="text"/>'."\n".'</td></tr>'."\n";
  101. $expected .= '<tr><th scope="row"><span class="jforms-label" id="'.$this->formname.'_sexe_label">Vous êtes </span>'."\n".'</th>'."\n";
  102. $expected .= '<td><span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_0" readonly="readonly" class="jforms-ctrl-radiobuttons jforms-readonly" value="h"/><label for="'.$this->formname.'_sexe_0">un homme</label></span>'."\n";
  103. $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_1" readonly="readonly" class="jforms-ctrl-radiobuttons jforms-readonly" value="f"/><label for="'.$this->formname.'_sexe_1">une femme</label></span>'."\n";
  104. $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_2" readonly="readonly" class="jforms-ctrl-radiobuttons jforms-readonly" value="no"/><label for="'.$this->formname.'_sexe_2">je ne sais pas</label></span>'."\n\n".'</td></tr>'."\n";
  105. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_mail" id="'.$this->formname.'_mail_label">Votre mail</label>'."\n".'</th>'."\n";
  106. $expected .= '<td><input name="mail" id="'.$this->formname.'_mail" readonly="readonly" class="jforms-ctrl-input jforms-readonly" value="" type="text"/>'."\n".'</td></tr>'."\n</table></fieldset>\n";
  107. ob_start();$this->builder->outputControl($group);$out = ob_get_clean();
  108. $this->assertEqualOrDiff($expected, $out);
  109. $this->assertEqualOrDiff('c = new jFormsJQControlString(\'nom\', \'Your name\');
  110. c.required = true;
  111. c.errRequired=\'"Your name" field is required\';
  112. c.errInvalid=\'"Your name" field is invalid\';
  113. jFormsJQ.tForm.addControl(c);
  114. c = new jFormsJQControlString(\'prenom\', \'Your firstname\');
  115. c.errInvalid=\'"Your firstname" field is invalid\';
  116. jFormsJQ.tForm.addControl(c);
  117. c = new jFormsJQControlString(\'sexe\', \'Vous êtes \');
  118. c.required = true;
  119. c.errRequired=\'Vous devez indiquer le sexe, même si vous ne savez pas :-)\';
  120. c.errInvalid=\'"Vous êtes " field is invalid\';
  121. jFormsJQ.tForm.addControl(c);
  122. c = new jFormsJQControlEmail(\'mail\', \'Votre mail\');
  123. c.errInvalid=\'"Votre mail" field is invalid\';
  124. jFormsJQ.tForm.addControl(c);
  125. ', $this->builder->getJsContent());
  126. }
  127. function testOutputChoice(){
  128. $choice= new jFormsControlChoice('status');
  129. $choice->label='Task Status';
  130. $choice->createItem('new','New');
  131. $choice->createItem('assigned','Assigned');
  132. $choice->createItem('closed','Closed');
  133. $ctrlnom= new jFormsControlinput('nom');
  134. $ctrlnom->required=true;
  135. $ctrlnom->label='Name';
  136. $choice->addChildControl($ctrlnom,'assigned');
  137. $ctrlprenom= new jFormsControlinput('prenom');
  138. $ctrlprenom->defaultValue='robert';
  139. $ctrlprenom->label='Firstname';
  140. $choice->addChildControl($ctrlprenom,'assigned');
  141. $ctrlreason= new jFormsControlMenulist('reason');
  142. $ctrlreason->required=true;
  143. $ctrlreason->label='Reason ';
  144. $ctrlreason->alertRequired='Hey, specify a reason !';
  145. $ctrlreason->datasource= new jFormsStaticDatasource();
  146. $ctrlreason->datasource->data = array(
  147. 'aa'=>'fixed',
  148. 'bb'=>'won t fixed',
  149. 'cc'=>'later',
  150. );
  151. $choice->addChildControl($ctrlreason,'closed');
  152. $this->form->addControl($choice);
  153. $choice->setReadOnly(false);
  154. ob_start();$this->builder->outputControlLabel($choice);$out = ob_get_clean();
  155. $this->assertEqualOrDiff('<span class="jforms-label" id="'.$this->formname.'_status_label">Task Status</span>'."\n", $out);
  156. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  157. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_0" type="radio" value="new" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>'."\n".'</li>'."\n";
  158. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_1" type="radio" value="assigned" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>'."\n";
  159. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_nom" id="'.$this->formname.'_nom_label">Name<span class="jforms-required-star">*</span></label>'."\n".' <input name="nom" id="'.$this->formname.'_nom" class="jforms-ctrl-input jforms-required" value="" type="text"/>'."\n".'</span>'."\n";
  160. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_prenom" id="'.$this->formname.'_prenom_label">Firstname</label>'."\n".' <input name="prenom" id="'.$this->formname.'_prenom" class="jforms-ctrl-input" value="robert" type="text"/>'."\n".'</span>'."\n";
  161. $expected .= '</li>'."\n";
  162. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_2" type="radio" value="closed" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>'."\n";
  163. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_reason" id="'.$this->formname.'_reason_label">Reason <span class="jforms-required-star">*</span></label>'."\n";
  164. $expected .= ' <select name="reason" id="'.$this->formname.'_reason" class="jforms-ctrl-menulist jforms-required" size="1">'."\n".'<option value="aa">fixed</option>'."\n".'<option value="bb">won t fixed</option>'."\n".'<option value="cc">later</option>'."\n".'</select>'."\n".'</span>'."\n";
  165. $expected .= '</li>'."\n";
  166. $expected .= '</ul>'."\n\n";
  167. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  168. $this->assertEqualOrDiff($expected, $out);
  169. $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  170. c.errInvalid=\'"Task Status" field is invalid\';
  171. jFormsJQ.tForm.addControl(c);
  172. c2 = c;
  173. c2.items[\'new\']=[];
  174. c = new jFormsJQControlString(\'nom\', \'Name\');
  175. c.required = true;
  176. c.errRequired=\'"Name" field is required\';
  177. c.errInvalid=\'"Name" field is invalid\';
  178. c2.addControl(c, \'assigned\');
  179. c = new jFormsJQControlString(\'prenom\', \'Firstname\');
  180. c.errInvalid=\'"Firstname" field is invalid\';
  181. c2.addControl(c, \'assigned\');
  182. c = new jFormsJQControlString(\'reason\', \'Reason \');
  183. c.required = true;
  184. c.errRequired=\'Hey, specify a reason !\';
  185. c.errInvalid=\'"Reason " field is invalid\';
  186. c2.addControl(c, \'closed\');
  187. c2.activate(\'\');
  188. ', $this->builder->getJsContent());
  189. $this->form->getContainer()->data['status']='assigned';
  190. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  191. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_0" type="radio" value="new" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>'."\n".'</li>'."\n";
  192. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_1" type="radio" value="assigned" checked="checked" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>'."\n";
  193. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_nom" id="'.$this->formname.'_nom_label">Name<span class="jforms-required-star">*</span></label>'."\n".' <input name="nom" id="'.$this->formname.'_nom" class="jforms-ctrl-input jforms-required" value="" type="text"/>'."\n".'</span>'."\n";
  194. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_prenom" id="'.$this->formname.'_prenom_label">Firstname</label>'."\n".' <input name="prenom" id="'.$this->formname.'_prenom" class="jforms-ctrl-input" value="robert" type="text"/>'."\n".'</span>'."\n";
  195. $expected .= '</li>'."\n";
  196. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_2" type="radio" value="closed" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>'."\n";
  197. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_reason" id="'.$this->formname.'_reason_label">Reason <span class="jforms-required-star">*</span></label>'."\n";
  198. $expected .= ' <select name="reason" id="'.$this->formname.'_reason" class="jforms-ctrl-menulist jforms-required" size="1">'."\n".'<option value="aa">fixed</option>'."\n".'<option value="bb">won t fixed</option>'."\n".'<option value="cc">later</option>'."\n".'</select>'."\n".'</span>'."\n";
  199. $expected .= '</li>'."\n";
  200. $expected .= '</ul>'."\n\n";
  201. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  202. $this->assertEqualOrDiff($expected, $out);
  203. $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  204. c.errInvalid=\'"Task Status" field is invalid\';
  205. jFormsJQ.tForm.addControl(c);
  206. c2 = c;
  207. c2.items[\'new\']=[];
  208. c = new jFormsJQControlString(\'nom\', \'Name\');
  209. c.required = true;
  210. c.errRequired=\'"Name" field is required\';
  211. c.errInvalid=\'"Name" field is invalid\';
  212. c2.addControl(c, \'assigned\');
  213. c = new jFormsJQControlString(\'prenom\', \'Firstname\');
  214. c.errInvalid=\'"Firstname" field is invalid\';
  215. c2.addControl(c, \'assigned\');
  216. c = new jFormsJQControlString(\'reason\', \'Reason \');
  217. c.required = true;
  218. c.errRequired=\'Hey, specify a reason !\';
  219. c.errInvalid=\'"Reason " field is invalid\';
  220. c2.addControl(c, \'closed\');
  221. c2.activate(\'assigned\');
  222. ', $this->builder->getJsContent());
  223. $this->form->getContainer()->data['status']='new';
  224. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  225. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_0" type="radio" value="new" checked="checked" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>'."\n".'</li>'."\n";
  226. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_1" type="radio" value="assigned" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>'."\n";
  227. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_nom" id="'.$this->formname.'_nom_label">Name<span class="jforms-required-star">*</span></label>'."\n".' <input name="nom" id="'.$this->formname.'_nom" class="jforms-ctrl-input jforms-required" value="" type="text"/>'."\n".'</span>'."\n";
  228. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_prenom" id="'.$this->formname.'_prenom_label">Firstname</label>'."\n".' <input name="prenom" id="'.$this->formname.'_prenom" class="jforms-ctrl-input" value="robert" type="text"/>'."\n".'</span>'."\n";
  229. $expected .= '</li>'."\n";
  230. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_2" type="radio" value="closed" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>'."\n";
  231. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_reason" id="'.$this->formname.'_reason_label">Reason <span class="jforms-required-star">*</span></label>'."\n";
  232. $expected .= ' <select name="reason" id="'.$this->formname.'_reason" class="jforms-ctrl-menulist jforms-required" size="1">'."\n".'<option value="aa">fixed</option>'."\n".'<option value="bb">won t fixed</option>'."\n".'<option value="cc">later</option>'."\n".'</select>'."\n".'</span>'."\n";
  233. $expected .= '</li>'."\n";
  234. $expected .= '</ul>'."\n\n";
  235. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  236. $this->assertEqualOrDiff($expected, $out);
  237. $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  238. c.errInvalid=\'"Task Status" field is invalid\';
  239. jFormsJQ.tForm.addControl(c);
  240. c2 = c;
  241. c2.items[\'new\']=[];
  242. c = new jFormsJQControlString(\'nom\', \'Name\');
  243. c.required = true;
  244. c.errRequired=\'"Name" field is required\';
  245. c.errInvalid=\'"Name" field is invalid\';
  246. c2.addControl(c, \'assigned\');
  247. c = new jFormsJQControlString(\'prenom\', \'Firstname\');
  248. c.errInvalid=\'"Firstname" field is invalid\';
  249. c2.addControl(c, \'assigned\');
  250. c = new jFormsJQControlString(\'reason\', \'Reason \');
  251. c.required = true;
  252. c.errRequired=\'Hey, specify a reason !\';
  253. c.errInvalid=\'"Reason " field is invalid\';
  254. c2.addControl(c, \'closed\');
  255. c2.activate(\'new\');
  256. ', $this->builder->getJsContent());
  257. $this->form->getContainer()->data['status']='closed';
  258. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  259. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_0" type="radio" value="new" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>'."\n".'</li>'."\n";
  260. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_1" type="radio" value="assigned" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>'."\n";
  261. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_nom" id="'.$this->formname.'_nom_label">Name<span class="jforms-required-star">*</span></label>'."\n".' <input name="nom" id="'.$this->formname.'_nom" class="jforms-ctrl-input jforms-required" value="" type="text"/>'."\n".'</span>'."\n";
  262. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_prenom" id="'.$this->formname.'_prenom_label">Firstname</label>'."\n".' <input name="prenom" id="'.$this->formname.'_prenom" class="jforms-ctrl-input" value="robert" type="text"/>'."\n".'</span>'."\n";
  263. $expected .= '</li>'."\n";
  264. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_2" type="radio" value="closed" checked="checked" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>'."\n";
  265. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_reason" id="'.$this->formname.'_reason_label">Reason <span class="jforms-required-star">*</span></label>'."\n";
  266. $expected .= ' <select name="reason" id="'.$this->formname.'_reason" class="jforms-ctrl-menulist jforms-required" size="1">'."\n".'<option value="aa">fixed</option>'."\n".'<option value="bb">won t fixed</option>'."\n".'<option value="cc">later</option>'."\n".'</select>'."\n".'</span>'."\n";
  267. $expected .= '</li>'."\n";
  268. $expected .= '</ul>'."\n\n";
  269. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  270. $this->assertEqualOrDiff($expected, $out);
  271. $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  272. c.errInvalid=\'"Task Status" field is invalid\';
  273. jFormsJQ.tForm.addControl(c);
  274. c2 = c;
  275. c2.items[\'new\']=[];
  276. c = new jFormsJQControlString(\'nom\', \'Name\');
  277. c.required = true;
  278. c.errRequired=\'"Name" field is required\';
  279. c.errInvalid=\'"Name" field is invalid\';
  280. c2.addControl(c, \'assigned\');
  281. c = new jFormsJQControlString(\'prenom\', \'Firstname\');
  282. c.errInvalid=\'"Firstname" field is invalid\';
  283. c2.addControl(c, \'assigned\');
  284. c = new jFormsJQControlString(\'reason\', \'Reason \');
  285. c.required = true;
  286. c.errRequired=\'Hey, specify a reason !\';
  287. c.errInvalid=\'"Reason " field is invalid\';
  288. c2.addControl(c, \'closed\');
  289. c2.activate(\'closed\');
  290. ', $this->builder->getJsContent());
  291. $choice->setReadOnly(true);
  292. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  293. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_0" readonly="readonly" type="radio" value="new" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>'."\n".'</li>'."\n";
  294. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_1" readonly="readonly" type="radio" value="assigned" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>'."\n";
  295. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_nom" id="'.$this->formname.'_nom_label">Name</label>'."\n".' <input name="nom" id="'.$this->formname.'_nom" readonly="readonly" class="jforms-ctrl-input jforms-readonly" value="" type="text"/>'."\n".'</span>'."\n";
  296. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_prenom" id="'.$this->formname.'_prenom_label">Firstname</label>'."\n".' <input name="prenom" id="'.$this->formname.'_prenom" readonly="readonly" class="jforms-ctrl-input jforms-readonly" value="robert" type="text"/>'."\n".'</span>'."\n";
  297. $expected .= '</li>'."\n";
  298. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_2" readonly="readonly" type="radio" value="closed" checked="checked" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>'."\n";
  299. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_reason" id="'.$this->formname.'_reason_label">Reason </label>'."\n";
  300. $expected .= ' <select name="reason" id="'.$this->formname.'_reason" class="jforms-ctrl-menulist jforms-readonly" size="1">'."\n".'<option value="aa">fixed</option>'."\n".'<option value="bb">won t fixed</option>'."\n".'<option value="cc">later</option>'."\n".'</select>'."\n".'</span>'."\n";
  301. $expected .= '</li>'."\n";
  302. $expected .= '</ul>'."\n\n";
  303. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  304. $this->assertEqualOrDiff($expected, $out);
  305. $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  306. c.errInvalid=\'"Task Status" field is invalid\';
  307. jFormsJQ.tForm.addControl(c);
  308. c2 = c;
  309. c2.items[\'new\']=[];
  310. c = new jFormsJQControlString(\'nom\', \'Name\');
  311. c.required = true;
  312. c.errRequired=\'"Name" field is required\';
  313. c.errInvalid=\'"Name" field is invalid\';
  314. c2.addControl(c, \'assigned\');
  315. c = new jFormsJQControlString(\'prenom\', \'Firstname\');
  316. c.errInvalid=\'"Firstname" field is invalid\';
  317. c2.addControl(c, \'assigned\');
  318. c = new jFormsJQControlString(\'reason\', \'Reason \');
  319. c.required = true;
  320. c.errRequired=\'Hey, specify a reason !\';
  321. c.errInvalid=\'"Reason " field is invalid\';
  322. c2.addControl(c, \'closed\');
  323. c2.activate(\'closed\');
  324. ', $this->builder->getJsContent());
  325. }
  326. public function testFormWithExternalUrlAsAction(){
  327. $this->builder->setAction('http://www.jelix.org/dummy.php',array());
  328. ob_start();
  329. $this->builder->outputHeader(array('method'=>'post'));
  330. $out = ob_get_clean();
  331. $result ='<form action="http://www.jelix.org/dummy.php" method="post" id="'.$this->builder->getName().'"><script type="text/javascript">
  332. //<![CDATA[
  333. jFormsJQ.selectFillUrl=\''.$GLOBALS['gJConfig']->urlengine['basePath'].'index.php?module=jelix&action=jforms:getListData\';
  334. jFormsJQ.config = {locale:\''.$GLOBALS['gJConfig']->locale.'\',basePath:\''.$GLOBALS['gJConfig']->urlengine['basePath'].'\',jqueryPath:\''.$GLOBALS['gJConfig']->urlengine['jqueryPath'].'\',jelixWWWPath:\''.$GLOBALS['gJConfig']->urlengine['jelixWWWPath'].'\'};
  335. jFormsJQ.tForm = new jFormsJQForm(\'jforms_formtesthtmlbuilder\',\'formtesthtmlbuilder\',\'0\');
  336. jFormsJQ.tForm.setErrorDecorator(new jFormsJQErrorDecoratorHtml());
  337. jFormsJQ.declareForm(jFormsJQ.tForm);
  338. //]]>
  339. </script><div class="jforms-hiddens"><input type="hidden" name="__JFORMS_TOKEN__" value="'.$this->container->token.'"/>
  340. </div>';
  341. $this->assertEqualOrDiff($result, $out);
  342. $this->assertEqualOrDiff('', $this->builder->getJsContent());
  343. $this->builder->setAction('http://www.jelix.org/dummy.php',array('foo'=>'bar'));
  344. ob_start();
  345. $this->builder->outputHeader(array('method'=>'post'));
  346. $out = ob_get_clean();
  347. $result ='<form action="http://www.jelix.org/dummy.php" method="post" id="'.$this->builder->getName().'"><script type="text/javascript">
  348. //<![CDATA[
  349. jFormsJQ.selectFillUrl=\''.$GLOBALS['gJConfig']->urlengine['basePath'].'index.php?module=jelix&action=jforms:getListData\';
  350. jFormsJQ.config = {locale:\''.$GLOBALS['gJConfig']->locale.'\',basePath:\''.$GLOBALS['gJConfig']->urlengine['basePath'].'\',jqueryPath:\''.$GLOBALS['gJConfig']->urlengine['jqueryPath'].'\',jelixWWWPath:\''.$GLOBALS['gJConfig']->urlengine['jelixWWWPath'].'\'};
  351. jFormsJQ.tForm = new jFormsJQForm(\'jforms_formtesthtmlbuilder1\',\'formtesthtmlbuilder\',\'0\');
  352. jFormsJQ.tForm.setErrorDecorator(new jFormsJQErrorDecoratorHtml());
  353. jFormsJQ.declareForm(jFormsJQ.tForm);
  354. //]]>
  355. </script><div class="jforms-hiddens"><input type="hidden" name="foo" value="bar"/>
  356. <input type="hidden" name="__JFORMS_TOKEN__" value="'.$this->container->token.'"/>
  357. </div>';
  358. $this->assertEqualOrDiff($result, $out);
  359. $this->assertEqualOrDiff('', $this->builder->getJsContent());
  360. $this->builder->setAction('https://www.jelix.org/dummy.php',array());
  361. ob_start();
  362. $this->builder->outputHeader(array('method'=>'get'));
  363. $out = ob_get_clean();
  364. $result ='<form action="https://www.jelix.org/dummy.php" method="get" id="'.$this->builder->getName().'"><script type="text/javascript">
  365. //<![CDATA[
  366. jFormsJQ.selectFillUrl=\''.$GLOBALS['gJConfig']->urlengine['basePath'].'index.php?module=jelix&action=jforms:getListData\';
  367. jFormsJQ.config = {locale:\''.$GLOBALS['gJConfig']->locale.'\',basePath:\''.$GLOBALS['gJConfig']->urlengine['basePath'].'\',jqueryPath:\''.$GLOBALS['gJConfig']->urlengine['jqueryPath'].'\',jelixWWWPath:\''.$GLOBALS['gJConfig']->urlengine['jelixWWWPath'].'\'};
  368. jFormsJQ.tForm = new jFormsJQForm(\'jforms_formtesthtmlbuilder2\',\'formtesthtmlbuilder\',\'0\');
  369. jFormsJQ.tForm.setErrorDecorator(new jFormsJQErrorDecoratorHtml());
  370. jFormsJQ.declareForm(jFormsJQ.tForm);
  371. //]]>
  372. </script><div class="jforms-hiddens"><input type="hidden" name="__JFORMS_TOKEN__" value="'.$this->container->token.'"/>
  373. </div>';
  374. $this->assertEqualOrDiff($result, $out);
  375. $this->assertEqualOrDiff('', $this->builder->getJsContent());
  376. }
  377. }