PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/testapp/tests-jelix/jelix/forms/jforms_htmlbuilder2Test.php

https://github.com/gmarrot/jelix
PHP | 495 lines | 408 code | 49 blank | 38 comment | 0 complexity | 918d153a195c1d36fe84e2d554be01e8 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause
  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/legacy/jFormsBuilderBase.class.php');
  14. include_once(JELIX_LIB_PATH.'forms/legacy/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 jforms_HTMLBuilder2Test extends jUnitTestCaseDb {
  24. protected $form;
  25. protected $container;
  26. protected $builder;
  27. protected $formname;
  28. function setUp() {
  29. self::initClassicRequest(TESTAPP_URL.'index.php');
  30. jApp::pushCurrentModule('jelix_tests');
  31. $_SESSION['JFORMS'] = array();
  32. $this->container = new jFormsDataContainer('formtesthtmlbuilder','0');
  33. $this->form = new testHMLForm2('formtesthtmlbuilder', $this->container, true );
  34. $this->builder = new testJFormsHtmlBuilder2($this->form);
  35. }
  36. function tearDown(){
  37. jApp::popCurrentModule();
  38. }
  39. function testOutputGroup(){
  40. $group= new jFormsControlgroup('identity');
  41. $group->label='Your identity';
  42. $ctrl= new jFormsControlinput('nom');
  43. $ctrl->required=true;
  44. $ctrl->label='Your name';
  45. $group->addChildControl($ctrl);
  46. $ctrl= new jFormsControlinput('prenom');
  47. $ctrl->defaultValue='robert';
  48. $ctrl->label='Your firstname';
  49. $group->addChildControl($ctrl);
  50. $ctrl= new jFormsControlradiobuttons('sexe');
  51. $ctrl->required=true;
  52. $ctrl->label='Vous êtes ';
  53. $ctrl->alertRequired='Vous devez indiquer le sexe, même si vous ne savez pas :-)';
  54. $ctrl->datasource= new jFormsStaticDatasource();
  55. $ctrl->datasource->data = array(
  56. 'h'=>'un homme',
  57. 'f'=>'une femme',
  58. 'no'=>'je ne sais pas',
  59. );
  60. $group->addChildControl($ctrl);
  61. $ctrl= new jFormsControlinput('mail');
  62. $ctrl->datatype= new jDatatypeemail();
  63. $ctrl->label='Votre mail';
  64. $group->addChildControl($ctrl);
  65. $this->form->addControl($group);
  66. ob_start();$this->builder->outputControlLabel($group);$out = ob_get_clean();
  67. $this->assertEquals('', $out);
  68. $expected = '<fieldset id="'.$this->formname.'_identity"><legend>Your identity</legend>'."\n";
  69. $expected .= '<table class="jforms-table-group" border="0">'."\n";
  70. $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";
  71. $expected .= '<td><input name="nom" id="'.$this->formname.'_nom" class="jforms-ctrl-input jforms-required" value="" type="text"/>'."\n".'</td></tr>'."\n";
  72. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_prenom" id="'.$this->formname.'_prenom_label">Your firstname</label>'."\n".'</th>'."\n";
  73. $expected .= '<td><input name="prenom" id="'.$this->formname.'_prenom" class="jforms-ctrl-input" value="robert" type="text"/>'."\n".'</td></tr>'."\n";
  74. $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";
  75. $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";
  76. $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";
  77. $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";
  78. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_mail" id="'.$this->formname.'_mail_label">Votre mail</label>'."\n".'</th>'."\n";
  79. $expected .= '<td><input name="mail" id="'.$this->formname.'_mail" class="jforms-ctrl-input" value="" type="text"/>'."\n".'</td></tr>'."\n</table></fieldset>\n";
  80. ob_start();$this->builder->outputControl($group);$out = ob_get_clean();
  81. $this->assertEquals($expected, $out);
  82. $this->assertEquals('c = new jFormsJQControlString(\'nom\', \'Your name\');
  83. c.required = true;
  84. c.errRequired=\'"Your name" field is required\';
  85. c.errInvalid=\'"Your name" field is invalid\';
  86. jFormsJQ.tForm.addControl(c);
  87. c = new jFormsJQControlString(\'prenom\', \'Your firstname\');
  88. c.errInvalid=\'"Your firstname" field is invalid\';
  89. jFormsJQ.tForm.addControl(c);
  90. c = new jFormsJQControlString(\'sexe\', \'Vous êtes \');
  91. c.required = true;
  92. c.errRequired=\'Vous devez indiquer le sexe, même si vous ne savez pas :-)\';
  93. c.errInvalid=\'"Vous êtes " field is invalid\';
  94. jFormsJQ.tForm.addControl(c);
  95. c = new jFormsJQControlEmail(\'mail\', \'Votre mail\');
  96. c.errInvalid=\'"Votre mail" field is invalid\';
  97. jFormsJQ.tForm.addControl(c);
  98. ', $this->builder->getJsContent());
  99. $group->setReadOnly(true);
  100. $expected = '<fieldset id="'.$this->formname.'_identity"><legend>Your identity</legend>'."\n";
  101. $expected .= '<table class="jforms-table-group" border="0">'."\n";
  102. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_nom" id="'.$this->formname.'_nom_label">Your name</label>'."\n".'</th>'."\n";
  103. $expected .= '<td><input name="nom" id="'.$this->formname.'_nom" readonly="readonly" class="jforms-ctrl-input jforms-readonly" value="" type="text"/>'."\n".'</td></tr>'."\n";
  104. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_prenom" id="'.$this->formname.'_prenom_label">Your firstname</label>'."\n".'</th>'."\n";
  105. $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";
  106. $expected .= '<tr><th scope="row"><span class="jforms-label" id="'.$this->formname.'_sexe_label">Vous êtes </span>'."\n".'</th>'."\n";
  107. $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";
  108. $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";
  109. $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";
  110. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_mail" id="'.$this->formname.'_mail_label">Votre mail</label>'."\n".'</th>'."\n";
  111. $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";
  112. ob_start();$this->builder->outputControl($group);$out = ob_get_clean();
  113. $this->assertEquals($expected, $out);
  114. $this->assertEquals('c = new jFormsJQControlString(\'nom\', \'Your name\');
  115. c.readOnly = true;
  116. c.required = true;
  117. c.errRequired=\'"Your name" field is required\';
  118. c.errInvalid=\'"Your name" field is invalid\';
  119. jFormsJQ.tForm.addControl(c);
  120. c = new jFormsJQControlString(\'prenom\', \'Your firstname\');
  121. c.readOnly = true;
  122. c.errInvalid=\'"Your firstname" field is invalid\';
  123. jFormsJQ.tForm.addControl(c);
  124. c = new jFormsJQControlString(\'sexe\', \'Vous êtes \');
  125. c.readOnly = true;
  126. c.required = true;
  127. c.errRequired=\'Vous devez indiquer le sexe, même si vous ne savez pas :-)\';
  128. c.errInvalid=\'"Vous êtes " field is invalid\';
  129. jFormsJQ.tForm.addControl(c);
  130. c = new jFormsJQControlEmail(\'mail\', \'Votre mail\');
  131. c.readOnly = true;
  132. c.errInvalid=\'"Votre mail" field is invalid\';
  133. jFormsJQ.tForm.addControl(c);
  134. ', $this->builder->getJsContent());
  135. }
  136. function testOutputChoice(){
  137. /*
  138. <choice ref="status">
  139. <label>Task Status</label
  140. <item value="new"><label>New</label>
  141. </item>
  142. <item value="assigned"><label>Assigned</label>
  143. <input ref="nom" required="true"><label>Name</label></input>
  144. <input ref="prenom" required="true"><label>Firstname</label></input>
  145. </item>
  146. <item value="closed"><label>Closed</label>
  147. <menulist ref="reason" required="true">
  148. <label>Reason</label>
  149. <item value="aa">fixed</item>
  150. <item value="bb">won t fixed</item>
  151. <item value="cc">later</item>
  152. <alert type="required">Hey, specify a reason !</alert>
  153. </menulist>
  154. </item>
  155. </choice>
  156. */
  157. $choice= new jFormsControlChoice('status');
  158. $choice->label='Task Status';
  159. $choice->createItem('new','New');
  160. $choice->createItem('assigned','Assigned');
  161. $choice->createItem('closed','Closed');
  162. $ctrlnom= new jFormsControlinput('nom');
  163. $ctrlnom->required=true;
  164. $ctrlnom->label='Name';
  165. $choice->addChildControl($ctrlnom,'assigned');
  166. $ctrlprenom= new jFormsControlinput('prenom');
  167. $ctrlprenom->defaultValue='robert';
  168. $ctrlprenom->label='Firstname';
  169. $choice->addChildControl($ctrlprenom,'assigned');
  170. $ctrlreason= new jFormsControlMenulist('reason');
  171. $ctrlreason->required=true;
  172. $ctrlreason->label='Reason ';
  173. $ctrlreason->alertRequired='Hey, specify a reason !';
  174. $ctrlreason->datasource= new jFormsStaticDatasource();
  175. $ctrlreason->datasource->data = array(
  176. 'aa'=>'fixed',
  177. 'bb'=>'won t fixed',
  178. 'cc'=>'later',
  179. );
  180. $choice->addChildControl($ctrlreason,'closed');
  181. $this->form->addControl($choice);
  182. $choice->setReadOnly(false);
  183. // output of the label of <choice>
  184. ob_start();$this->builder->outputControlLabel($choice);$out = ob_get_clean();
  185. $this->assertEquals('<span class="jforms-label" id="'.$this->formname.'_status_label">Task Status</span>'."\n", $out);
  186. // ouput of the whole <choice>, with original values
  187. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  188. $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";
  189. $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";
  190. $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";
  191. $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";
  192. $expected .= '</li>'."\n";
  193. $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";
  194. $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";
  195. $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";
  196. $expected .= '</li>'."\n";
  197. $expected .= '</ul>'."\n\n";
  198. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  199. $this->assertEquals($expected, $out);
  200. $this->assertEquals('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  201. c.errInvalid=\'"Task Status" field is invalid\';
  202. jFormsJQ.tForm.addControl(c);
  203. c2 = c;
  204. c2.items[\'new\']=[];
  205. c = new jFormsJQControlString(\'nom\', \'Name\');
  206. c.required = true;
  207. c.errRequired=\'"Name" field is required\';
  208. c.errInvalid=\'"Name" field is invalid\';
  209. c2.addControl(c, \'assigned\');
  210. c = new jFormsJQControlString(\'prenom\', \'Firstname\');
  211. c.errInvalid=\'"Firstname" field is invalid\';
  212. c2.addControl(c, \'assigned\');
  213. c = new jFormsJQControlString(\'reason\', \'Reason \');
  214. c.required = true;
  215. c.errRequired=\'Hey, specify a reason !\';
  216. c.errInvalid=\'"Reason " field is invalid\';
  217. c2.addControl(c, \'closed\');
  218. c2.activate(\'\');
  219. ', $this->builder->getJsContent());
  220. // ouput of the whole <choice>, with the first item selected
  221. $this->form->getContainer()->data['status']='assigned';
  222. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  223. $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";
  224. $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";
  225. $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";
  226. $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";
  227. $expected .= '</li>'."\n";
  228. $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";
  229. $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";
  230. $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";
  231. $expected .= '</li>'."\n";
  232. $expected .= '</ul>'."\n\n";
  233. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  234. $this->assertEquals($expected, $out);
  235. $this->assertEquals('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  236. c.errInvalid=\'"Task Status" field is invalid\';
  237. jFormsJQ.tForm.addControl(c);
  238. c2 = c;
  239. c2.items[\'new\']=[];
  240. c = new jFormsJQControlString(\'nom\', \'Name\');
  241. c.required = true;
  242. c.errRequired=\'"Name" field is required\';
  243. c.errInvalid=\'"Name" field is invalid\';
  244. c2.addControl(c, \'assigned\');
  245. c = new jFormsJQControlString(\'prenom\', \'Firstname\');
  246. c.errInvalid=\'"Firstname" field is invalid\';
  247. c2.addControl(c, \'assigned\');
  248. c = new jFormsJQControlString(\'reason\', \'Reason \');
  249. c.required = true;
  250. c.errRequired=\'Hey, specify a reason !\';
  251. c.errInvalid=\'"Reason " field is invalid\';
  252. c2.addControl(c, \'closed\');
  253. c2.activate(\'assigned\');
  254. ', $this->builder->getJsContent());
  255. // ouput of the whole <choice>, with the second item selected
  256. $this->form->getContainer()->data['status']='new';
  257. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  258. $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";
  259. $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";
  260. $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";
  261. $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";
  262. $expected .= '</li>'."\n";
  263. $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";
  264. $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";
  265. $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";
  266. $expected .= '</li>'."\n";
  267. $expected .= '</ul>'."\n\n";
  268. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  269. $this->assertEquals($expected, $out);
  270. $this->assertEquals('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  271. c.errInvalid=\'"Task Status" field is invalid\';
  272. jFormsJQ.tForm.addControl(c);
  273. c2 = c;
  274. c2.items[\'new\']=[];
  275. c = new jFormsJQControlString(\'nom\', \'Name\');
  276. c.required = true;
  277. c.errRequired=\'"Name" field is required\';
  278. c.errInvalid=\'"Name" field is invalid\';
  279. c2.addControl(c, \'assigned\');
  280. c = new jFormsJQControlString(\'prenom\', \'Firstname\');
  281. c.errInvalid=\'"Firstname" field is invalid\';
  282. c2.addControl(c, \'assigned\');
  283. c = new jFormsJQControlString(\'reason\', \'Reason \');
  284. c.required = true;
  285. c.errRequired=\'Hey, specify a reason !\';
  286. c.errInvalid=\'"Reason " field is invalid\';
  287. c2.addControl(c, \'closed\');
  288. c2.activate(\'new\');
  289. ', $this->builder->getJsContent());
  290. // ouput of the whole <choice>, with the third item selected
  291. $this->form->getContainer()->data['status']='closed';
  292. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  293. $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";
  294. $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";
  295. $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";
  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" class="jforms-ctrl-input" value="robert" type="text"/>'."\n".'</span>'."\n";
  297. $expected .= '</li>'."\n";
  298. $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";
  299. $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";
  300. $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";
  301. $expected .= '</li>'."\n";
  302. $expected .= '</ul>'."\n\n";
  303. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  304. $this->assertEquals($expected, $out);
  305. $this->assertEquals('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. // ouput of the whole <choice>, in readonly mode, with the third item selected
  326. $choice->setReadOnly(true);
  327. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  328. $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";
  329. $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";
  330. $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";
  331. $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";
  332. $expected .= '</li>'."\n";
  333. $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";
  334. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_reason" id="'.$this->formname.'_reason_label">Reason </label>'."\n";
  335. $expected .= ' <select name="reason" id="'.$this->formname.'_reason" class="jforms-ctrl-menulist jforms-readonly" disabled="disabled" 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";
  336. $expected .= '</li>'."\n";
  337. $expected .= '</ul>'."\n\n";
  338. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  339. $this->assertEquals($expected, $out);
  340. $this->assertEquals('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  341. c.readOnly = true;
  342. c.errInvalid=\'"Task Status" field is invalid\';
  343. jFormsJQ.tForm.addControl(c);
  344. c2 = c;
  345. c2.items[\'new\']=[];
  346. c = new jFormsJQControlString(\'nom\', \'Name\');
  347. c.readOnly = true;
  348. c.required = true;
  349. c.errRequired=\'"Name" field is required\';
  350. c.errInvalid=\'"Name" field is invalid\';
  351. c2.addControl(c, \'assigned\');
  352. c = new jFormsJQControlString(\'prenom\', \'Firstname\');
  353. c.readOnly = true;
  354. c.errInvalid=\'"Firstname" field is invalid\';
  355. c2.addControl(c, \'assigned\');
  356. c = new jFormsJQControlString(\'reason\', \'Reason \');
  357. c.readOnly = true;
  358. c.required = true;
  359. c.errRequired=\'Hey, specify a reason !\';
  360. c.errInvalid=\'"Reason " field is invalid\';
  361. c2.addControl(c, \'closed\');
  362. c2.activate(\'closed\');
  363. ', $this->builder->getJsContent());
  364. // ouput of the <choice>, with a deactivated item
  365. $this->form->getContainer()->data['status']='closed';
  366. $choice->deactivateItem('assigned');
  367. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  368. $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";
  369. $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";
  370. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_reason" id="'.$this->formname.'_reason_label">Reason </label>'."\n";
  371. $expected .= ' <select name="reason" id="'.$this->formname.'_reason" class="jforms-ctrl-menulist jforms-readonly" disabled="disabled" 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";
  372. $expected .= '</li>'."\n";
  373. $expected .= '</ul>'."\n\n";
  374. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  375. $this->assertEquals($expected, $out);
  376. $this->assertEquals('c = new jFormsJQControlChoice(\'status\', \'Task Status\');
  377. c.readOnly = true;
  378. c.errInvalid=\'"Task Status" field is invalid\';
  379. jFormsJQ.tForm.addControl(c);
  380. c2 = c;
  381. c2.items[\'new\']=[];
  382. c = new jFormsJQControlString(\'reason\', \'Reason \');
  383. c.readOnly = true;
  384. c.required = true;
  385. c.errRequired=\'Hey, specify a reason !\';
  386. c.errInvalid=\'"Reason " field is invalid\';
  387. c2.addControl(c, \'closed\');
  388. c2.activate(\'closed\');
  389. ', $this->builder->getJsContent());
  390. }
  391. public function testFormWithExternalUrlAsAction(){
  392. $this->builder->setAction('http://www.jelix.org/dummy.php',array());
  393. ob_start();
  394. $this->builder->setOptions(array('method'=>'post'));
  395. $this->builder->outputHeader();
  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=\''.jApp::config()->urlengine['basePath'].'index.php/jelix/jforms/getListData\';
  400. jFormsJQ.config = {locale:\''.jApp::config()->locale.'\',basePath:\''.jApp::config()->urlengine['basePath'].'\',jqueryPath:\''.jApp::config()->urlengine['jqueryPath'].'\',jelixWWWPath:\''.jApp::config()->urlengine['jelixWWWPath'].'\'};
  401. jFormsJQ.tForm = new jFormsJQForm(\'jforms_formtesthtmlbuilder\',\'formtesthtmlbuilder\',\'0\');
  402. jFormsJQ.tForm.setErrorDecorator(new jFormsJQErrorDecoratorHtml());
  403. jFormsJQ.declareForm(jFormsJQ.tForm);
  404. //]]>
  405. </script><div class="jforms-hiddens"><input type="hidden" name="__JFORMS_TOKEN__" value="'.$this->container->token.'"/>
  406. </div>';
  407. $this->assertEquals($result, $out);
  408. $this->assertEquals('', $this->builder->getJsContent());
  409. $this->builder->setAction('http://www.jelix.org/dummy.php',array('foo'=>'bar'));
  410. ob_start();
  411. $this->builder->setOptions(array('method'=>'post'));
  412. $this->builder->outputHeader();
  413. $out = ob_get_clean();
  414. $result ='<form action="http://www.jelix.org/dummy.php" method="post" id="'.$this->builder->getName().'"><script type="text/javascript">
  415. //<![CDATA[
  416. jFormsJQ.selectFillUrl=\''.jApp::config()->urlengine['basePath'].'index.php/jelix/jforms/getListData\';
  417. jFormsJQ.config = {locale:\''.jApp::config()->locale.'\',basePath:\''.jApp::config()->urlengine['basePath'].'\',jqueryPath:\''.jApp::config()->urlengine['jqueryPath'].'\',jelixWWWPath:\''.jApp::config()->urlengine['jelixWWWPath'].'\'};
  418. jFormsJQ.tForm = new jFormsJQForm(\'jforms_formtesthtmlbuilder1\',\'formtesthtmlbuilder\',\'0\');
  419. jFormsJQ.tForm.setErrorDecorator(new jFormsJQErrorDecoratorHtml());
  420. jFormsJQ.declareForm(jFormsJQ.tForm);
  421. //]]>
  422. </script><div class="jforms-hiddens"><input type="hidden" name="foo" value="bar"/>
  423. <input type="hidden" name="__JFORMS_TOKEN__" value="'.$this->container->token.'"/>
  424. </div>';
  425. $this->assertEquals($result, $out);
  426. $this->assertEquals('', $this->builder->getJsContent());
  427. $this->builder->setAction('https://www.jelix.org/dummy.php',array());
  428. ob_start();
  429. $this->builder->setOptions(array('method'=>'get'));
  430. $this->builder->outputHeader();
  431. $out = ob_get_clean();
  432. $result ='<form action="https://www.jelix.org/dummy.php" method="get" id="'.$this->builder->getName().'"><script type="text/javascript">
  433. //<![CDATA[
  434. jFormsJQ.selectFillUrl=\''.jApp::config()->urlengine['basePath'].'index.php/jelix/jforms/getListData\';
  435. jFormsJQ.config = {locale:\''.jApp::config()->locale.'\',basePath:\''.jApp::config()->urlengine['basePath'].'\',jqueryPath:\''.jApp::config()->urlengine['jqueryPath'].'\',jelixWWWPath:\''.jApp::config()->urlengine['jelixWWWPath'].'\'};
  436. jFormsJQ.tForm = new jFormsJQForm(\'jforms_formtesthtmlbuilder2\',\'formtesthtmlbuilder\',\'0\');
  437. jFormsJQ.tForm.setErrorDecorator(new jFormsJQErrorDecoratorHtml());
  438. jFormsJQ.declareForm(jFormsJQ.tForm);
  439. //]]>
  440. </script><div class="jforms-hiddens"><input type="hidden" name="__JFORMS_TOKEN__" value="'.$this->container->token.'"/>
  441. </div>';
  442. $this->assertEquals($result, $out);
  443. $this->assertEquals('', $this->builder->getJsContent());
  444. }
  445. }