PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/jelix/jelix-trunk/
PHP | 478 lines | 390 code | 50 blank | 38 comment | 0 complexity | 8bbb90d5664ca2c113defa01df6dcbf9 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause, JSON, GPL-3.0, LGPL-3.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 id="'.$this->formname.'_identity"><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 id="'.$this->formname.'_identity"><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. /*
  129. <choice ref="status">
  130. <label>Task Status</label
  131. <item value="new"><label>New</label>
  132. </item>
  133. <item value="assigned"><label>Assigned</label>
  134. <input ref="nom" required="true"><label>Name</label></input>
  135. <input ref="prenom" required="true"><label>Firstname</label></input>
  136. </item>
  137. <item value="closed"><label>Closed</label>
  138. <menulist ref="reason" required="true">
  139. <label>Reason</label>
  140. <item value="aa">fixed</item>
  141. <item value="bb">won t fixed</item>
  142. <item value="cc">later</item>
  143. <alert type="required">Hey, specify a reason !</alert>
  144. </menulist>
  145. </item>
  146. </choice>
  147. */
  148. $choice= new jFormsControlChoice('status');
  149. $choice->label='Task Status';
  150. $choice->createItem('new','New');
  151. $choice->createItem('assigned','Assigned');
  152. $choice->createItem('closed','Closed');
  153. $ctrlnom= new jFormsControlinput('nom');
  154. $ctrlnom->required=true;
  155. $ctrlnom->label='Name';
  156. $choice->addChildControl($ctrlnom,'assigned');
  157. $ctrlprenom= new jFormsControlinput('prenom');
  158. $ctrlprenom->defaultValue='robert';
  159. $ctrlprenom->label='Firstname';
  160. $choice->addChildControl($ctrlprenom,'assigned');
  161. $ctrlreason= new jFormsControlMenulist('reason');
  162. $ctrlreason->required=true;
  163. $ctrlreason->label='Reason ';
  164. $ctrlreason->alertRequired='Hey, specify a reason !';
  165. $ctrlreason->datasource= new jFormsStaticDatasource();
  166. $ctrlreason->datasource->data = array(
  167. 'aa'=>'fixed',
  168. 'bb'=>'won t fixed',
  169. 'cc'=>'later',
  170. );
  171. $choice->addChildControl($ctrlreason,'closed');
  172. $this->form->addControl($choice);
  173. $choice->setReadOnly(false);
  174. // output of the label of <choice>
  175. ob_start();$this->builder->outputControlLabel($choice);$out = ob_get_clean();
  176. $this->assertEqualOrDiff('<span class="jforms-label" id="'.$this->formname.'_status_label">Task Status</span>'."\n", $out);
  177. // ouput of the whole <choice>, with original values
  178. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  179. $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";
  180. $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";
  181. $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";
  182. $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";
  183. $expected .= '</li>'."\n";
  184. $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";
  185. $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";
  186. $expected .= ' <select name="reason" id="'.$this->formname.'_reason" class="jforms-ctrl-menulist jforms-required" size="1">'."\n".'<option value="" selected="selected"></option>'."\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";
  187. $expected .= '</li>'."\n";
  188. $expected .= '</ul>'."\n\n";
  189. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  190. $this->assertEqualOrDiff($expected, $out);
  191. $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  192. c.errInvalid=\'"Task Status" field is invalid\';
  193. jFormsJQ.tForm.addControl(c);
  194. c2 = c;
  195. c2.items[\'new\']=[];
  196. c = new jFormsJQControlString(\'nom\', \'Name\');
  197. c.required = true;
  198. c.errRequired=\'"Name" field is required\';
  199. c.errInvalid=\'"Name" field is invalid\';
  200. c2.addControl(c, \'assigned\');
  201. c = new jFormsJQControlString(\'prenom\', \'Firstname\');
  202. c.errInvalid=\'"Firstname" field is invalid\';
  203. c2.addControl(c, \'assigned\');
  204. c = new jFormsJQControlString(\'reason\', \'Reason \');
  205. c.required = true;
  206. c.errRequired=\'Hey, specify a reason !\';
  207. c.errInvalid=\'"Reason " field is invalid\';
  208. c2.addControl(c, \'closed\');
  209. c2.activate(\'\');
  210. ', $this->builder->getJsContent());
  211. // ouput of the whole <choice>, with the first item selected
  212. $this->form->getContainer()->data['status']='assigned';
  213. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  214. $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";
  215. $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";
  216. $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";
  217. $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";
  218. $expected .= '</li>'."\n";
  219. $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";
  220. $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";
  221. $expected .= ' <select name="reason" id="'.$this->formname.'_reason" class="jforms-ctrl-menulist jforms-required" size="1">'."\n".'<option value="" selected="selected"></option>'."\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";
  222. $expected .= '</li>'."\n";
  223. $expected .= '</ul>'."\n\n";
  224. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  225. $this->assertEqualOrDiff($expected, $out);
  226. $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  227. c.errInvalid=\'"Task Status" field is invalid\';
  228. jFormsJQ.tForm.addControl(c);
  229. c2 = c;
  230. c2.items[\'new\']=[];
  231. c = new jFormsJQControlString(\'nom\', \'Name\');
  232. c.required = true;
  233. c.errRequired=\'"Name" field is required\';
  234. c.errInvalid=\'"Name" field is invalid\';
  235. c2.addControl(c, \'assigned\');
  236. c = new jFormsJQControlString(\'prenom\', \'Firstname\');
  237. c.errInvalid=\'"Firstname" field is invalid\';
  238. c2.addControl(c, \'assigned\');
  239. c = new jFormsJQControlString(\'reason\', \'Reason \');
  240. c.required = true;
  241. c.errRequired=\'Hey, specify a reason !\';
  242. c.errInvalid=\'"Reason " field is invalid\';
  243. c2.addControl(c, \'closed\');
  244. c2.activate(\'assigned\');
  245. ', $this->builder->getJsContent());
  246. // ouput of the whole <choice>, with the second item selected
  247. $this->form->getContainer()->data['status']='new';
  248. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  249. $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";
  250. $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";
  251. $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";
  252. $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";
  253. $expected .= '</li>'."\n";
  254. $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";
  255. $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";
  256. $expected .= ' <select name="reason" id="'.$this->formname.'_reason" class="jforms-ctrl-menulist jforms-required" size="1">'."\n".'<option value="" selected="selected"></option>'."\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";
  257. $expected .= '</li>'."\n";
  258. $expected .= '</ul>'."\n\n";
  259. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  260. $this->assertEqualOrDiff($expected, $out);
  261. $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  262. c.errInvalid=\'"Task Status" field is invalid\';
  263. jFormsJQ.tForm.addControl(c);
  264. c2 = c;
  265. c2.items[\'new\']=[];
  266. c = new jFormsJQControlString(\'nom\', \'Name\');
  267. c.required = true;
  268. c.errRequired=\'"Name" field is required\';
  269. c.errInvalid=\'"Name" field is invalid\';
  270. c2.addControl(c, \'assigned\');
  271. c = new jFormsJQControlString(\'prenom\', \'Firstname\');
  272. c.errInvalid=\'"Firstname" field is invalid\';
  273. c2.addControl(c, \'assigned\');
  274. c = new jFormsJQControlString(\'reason\', \'Reason \');
  275. c.required = true;
  276. c.errRequired=\'Hey, specify a reason !\';
  277. c.errInvalid=\'"Reason " field is invalid\';
  278. c2.addControl(c, \'closed\');
  279. c2.activate(\'new\');
  280. ', $this->builder->getJsContent());
  281. // ouput of the whole <choice>, with the third item selected
  282. $this->form->getContainer()->data['status']='closed';
  283. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  284. $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";
  285. $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";
  286. $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";
  287. $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";
  288. $expected .= '</li>'."\n";
  289. $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";
  290. $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";
  291. $expected .= ' <select name="reason" id="'.$this->formname.'_reason" class="jforms-ctrl-menulist jforms-required" size="1">'."\n".'<option value="" selected="selected"></option>'."\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";
  292. $expected .= '</li>'."\n";
  293. $expected .= '</ul>'."\n\n";
  294. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  295. $this->assertEqualOrDiff($expected, $out);
  296. $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  297. c.errInvalid=\'"Task Status" field is invalid\';
  298. jFormsJQ.tForm.addControl(c);
  299. c2 = c;
  300. c2.items[\'new\']=[];
  301. c = new jFormsJQControlString(\'nom\', \'Name\');
  302. c.required = true;
  303. c.errRequired=\'"Name" field is required\';
  304. c.errInvalid=\'"Name" field is invalid\';
  305. c2.addControl(c, \'assigned\');
  306. c = new jFormsJQControlString(\'prenom\', \'Firstname\');
  307. c.errInvalid=\'"Firstname" field is invalid\';
  308. c2.addControl(c, \'assigned\');
  309. c = new jFormsJQControlString(\'reason\', \'Reason \');
  310. c.required = true;
  311. c.errRequired=\'Hey, specify a reason !\';
  312. c.errInvalid=\'"Reason " field is invalid\';
  313. c2.addControl(c, \'closed\');
  314. c2.activate(\'closed\');
  315. ', $this->builder->getJsContent());
  316. // ouput of the whole <choice>, in readonly mode, with the third item selected
  317. $choice->setReadOnly(true);
  318. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  319. $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";
  320. $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";
  321. $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";
  322. $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";
  323. $expected .= '</li>'."\n";
  324. $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";
  325. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_reason" id="'.$this->formname.'_reason_label">Reason </label>'."\n";
  326. $expected .= ' <select name="reason" id="'.$this->formname.'_reason" class="jforms-ctrl-menulist jforms-readonly" size="1">'."\n".'<option value="" selected="selected"></option>'."\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";
  327. $expected .= '</li>'."\n";
  328. $expected .= '</ul>'."\n\n";
  329. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  330. $this->assertEqualOrDiff($expected, $out);
  331. $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  332. c.errInvalid=\'"Task Status" field is invalid\';
  333. jFormsJQ.tForm.addControl(c);
  334. c2 = c;
  335. c2.items[\'new\']=[];
  336. c = new jFormsJQControlString(\'nom\', \'Name\');
  337. c.required = true;
  338. c.errRequired=\'"Name" field is required\';
  339. c.errInvalid=\'"Name" field is invalid\';
  340. c2.addControl(c, \'assigned\');
  341. c = new jFormsJQControlString(\'prenom\', \'Firstname\');
  342. c.errInvalid=\'"Firstname" field is invalid\';
  343. c2.addControl(c, \'assigned\');
  344. c = new jFormsJQControlString(\'reason\', \'Reason \');
  345. c.required = true;
  346. c.errRequired=\'Hey, specify a reason !\';
  347. c.errInvalid=\'"Reason " field is invalid\';
  348. c2.addControl(c, \'closed\');
  349. c2.activate(\'closed\');
  350. ', $this->builder->getJsContent());
  351. // ouput of the <choice>, with a deactivated item
  352. $this->form->getContainer()->data['status']='closed';
  353. $choice->deactivateItem('assigned');
  354. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  355. $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";
  356. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_1" readonly="readonly" type="radio" value="closed" checked="checked" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>'."\n";
  357. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_reason" id="'.$this->formname.'_reason_label">Reason </label>'."\n";
  358. $expected .= ' <select name="reason" id="'.$this->formname.'_reason" class="jforms-ctrl-menulist jforms-readonly" size="1">'."\n".'<option value="" selected="selected"></option>'."\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";
  359. $expected .= '</li>'."\n";
  360. $expected .= '</ul>'."\n\n";
  361. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  362. $this->assertEqualOrDiff($expected, $out);
  363. $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  364. c.errInvalid=\'"Task Status" field is invalid\';
  365. jFormsJQ.tForm.addControl(c);
  366. c2 = c;
  367. c2.items[\'new\']=[];
  368. c = new jFormsJQControlString(\'reason\', \'Reason \');
  369. c.required = true;
  370. c.errRequired=\'Hey, specify a reason !\';
  371. c.errInvalid=\'"Reason " field is invalid\';
  372. c2.addControl(c, \'closed\');
  373. c2.activate(\'closed\');
  374. ', $this->builder->getJsContent());
  375. }
  376. public function testFormWithExternalUrlAsAction(){
  377. $this->builder->setAction('http://www.jelix.org/dummy.php',array());
  378. ob_start();
  379. $this->builder->outputHeader(array('method'=>'post'));
  380. $out = ob_get_clean();
  381. $result ='<form action="http://www.jelix.org/dummy.php" method="post" id="'.$this->builder->getName().'"><script type="text/javascript">
  382. //<![CDATA[
  383. jFormsJQ.selectFillUrl=\''.$GLOBALS['gJConfig']->urlengine['basePath'].'index.php?module=jelix&action=jforms:getListData\';
  384. jFormsJQ.config = {locale:\''.$GLOBALS['gJConfig']->locale.'\',basePath:\''.$GLOBALS['gJConfig']->urlengine['basePath'].'\',jqueryPath:\''.$GLOBALS['gJConfig']->urlengine['jqueryPath'].'\',jelixWWWPath:\''.$GLOBALS['gJConfig']->urlengine['jelixWWWPath'].'\'};
  385. jFormsJQ.tForm = new jFormsJQForm(\'jforms_formtesthtmlbuilder\',\'formtesthtmlbuilder\',\'0\');
  386. jFormsJQ.tForm.setErrorDecorator(new jFormsJQErrorDecoratorHtml());
  387. jFormsJQ.declareForm(jFormsJQ.tForm);
  388. //]]>
  389. </script><div class="jforms-hiddens"><input type="hidden" name="__JFORMS_TOKEN__" value="'.$this->container->token.'"/>
  390. </div>';
  391. $this->assertEqualOrDiff($result, $out);
  392. $this->assertEqualOrDiff('', $this->builder->getJsContent());
  393. $this->builder->setAction('http://www.jelix.org/dummy.php',array('foo'=>'bar'));
  394. ob_start();
  395. $this->builder->outputHeader(array('method'=>'post'));
  396. $out = ob_get_clean();
  397. $result ='<form action="http://www.jelix.org/dummy.php" method="post" id="'.$this->builder->getName().'"><script type="text/javascript">
  398. //<![CDATA[
  399. jFormsJQ.selectFillUrl=\''.$GLOBALS['gJConfig']->urlengine['basePath'].'index.php?module=jelix&action=jforms:getListData\';
  400. jFormsJQ.config = {locale:\''.$GLOBALS['gJConfig']->locale.'\',basePath:\''.$GLOBALS['gJConfig']->urlengine['basePath'].'\',jqueryPath:\''.$GLOBALS['gJConfig']->urlengine['jqueryPath'].'\',jelixWWWPath:\''.$GLOBALS['gJConfig']->urlengine['jelixWWWPath'].'\'};
  401. jFormsJQ.tForm = new jFormsJQForm(\'jforms_formtesthtmlbuilder1\',\'formtesthtmlbuilder\',\'0\');
  402. jFormsJQ.tForm.setErrorDecorator(new jFormsJQErrorDecoratorHtml());
  403. jFormsJQ.declareForm(jFormsJQ.tForm);
  404. //]]>
  405. </script><div class="jforms-hiddens"><input type="hidden" name="foo" value="bar"/>
  406. <input type="hidden" name="__JFORMS_TOKEN__" value="'.$this->container->token.'"/>
  407. </div>';
  408. $this->assertEqualOrDiff($result, $out);
  409. $this->assertEqualOrDiff('', $this->builder->getJsContent());
  410. $this->builder->setAction('https://www.jelix.org/dummy.php',array());
  411. ob_start();
  412. $this->builder->outputHeader(array('method'=>'get'));
  413. $out = ob_get_clean();
  414. $result ='<form action="https://www.jelix.org/dummy.php" method="get" id="'.$this->builder->getName().'"><script type="text/javascript">
  415. //<![CDATA[
  416. jFormsJQ.selectFillUrl=\''.$GLOBALS['gJConfig']->urlengine['basePath'].'index.php?module=jelix&action=jforms:getListData\';
  417. jFormsJQ.config = {locale:\''.$GLOBALS['gJConfig']->locale.'\',basePath:\''.$GLOBALS['gJConfig']->urlengine['basePath'].'\',jqueryPath:\''.$GLOBALS['gJConfig']->urlengine['jqueryPath'].'\',jelixWWWPath:\''.$GLOBALS['gJConfig']->urlengine['jelixWWWPath'].'\'};
  418. jFormsJQ.tForm = new jFormsJQForm(\'jforms_formtesthtmlbuilder2\',\'formtesthtmlbuilder\',\'0\');
  419. jFormsJQ.tForm.setErrorDecorator(new jFormsJQErrorDecoratorHtml());
  420. jFormsJQ.declareForm(jFormsJQ.tForm);
  421. //]]>
  422. </script><div class="jforms-hiddens"><input type="hidden" name="__JFORMS_TOKEN__" value="'.$this->container->token.'"/>
  423. </div>';
  424. $this->assertEqualOrDiff($result, $out);
  425. $this->assertEqualOrDiff('', $this->builder->getJsContent());
  426. }
  427. }