PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/gmarrot/jelix
PHP | 439 lines | 378 code | 51 blank | 10 comment | 0 complexity | 5fe74caeb680b72bbf0e2b4ee66df179 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/htmllight/htmllight.jformsbuilder.php');
  17. class testHTMLLightForm2 extends jFormsBase {
  18. }
  19. class testJFormsHtmlLightBuilder2 extends htmllightJformsBuilder {
  20. function getJsContent() { $js= $this->jsContent; $this->jsContent = '';return $js;}
  21. function clearJs() { $this->jsContent = ''; }
  22. }
  23. class jforms_HTMLLightBuilder2Test 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('formtestlightB','');
  33. $this->form = new testHTMLLightForm2('formtestlightB', $this->container, true );
  34. $this->builder = new testJFormsHtmlLightBuilder2($this->form);
  35. $this->formname = $this->builder->getName();
  36. }
  37. function tearDown(){
  38. jApp::popCurrentModule();
  39. }
  40. function testOutputGroup(){
  41. $group= new jFormsControlgroup('identity');
  42. $group->label='Your identity';
  43. $ctrl= new jFormsControlinput('nom');
  44. $ctrl->required=true;
  45. $ctrl->label='Your name';
  46. $group->addChildControl($ctrl);
  47. $ctrl= new jFormsControlinput('prenom');
  48. $ctrl->defaultValue='robert';
  49. $ctrl->label='Your firstname';
  50. $group->addChildControl($ctrl);
  51. $ctrl= new jFormsControlradiobuttons('sexe');
  52. $ctrl->required=true;
  53. $ctrl->label='Vous êtes ';
  54. $ctrl->alertRequired='Vous devez indiquer le sexe, même si vous ne savez pas :-)';
  55. $ctrl->datasource= new jFormsStaticDatasource();
  56. $ctrl->datasource->data = array(
  57. 'h'=>'un homme',
  58. 'f'=>'une femme',
  59. 'no'=>'je ne sais pas',
  60. );
  61. $group->addChildControl($ctrl);
  62. $ctrl= new jFormsControlinput('mail');
  63. $ctrl->datatype= new jDatatypeemail();
  64. $ctrl->label='Votre mail';
  65. $group->addChildControl($ctrl);
  66. $this->form->addControl($group);
  67. ob_start();$this->builder->outputControlLabel($group);$out = ob_get_clean();
  68. $this->assertEquals('', $out);
  69. $expected = '<fieldset id="'.$this->formname.'_identity"><legend>Your identity</legend>'."\n";
  70. $expected .= '<table class="jforms-table-group" border="0">'."\n";
  71. $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";
  72. $expected .= '<td><input name="nom" id="'.$this->formname.'_nom" class="jforms-ctrl-input jforms-required" value="" type="text"/>'."\n".'</td></tr>'."\n";
  73. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_prenom" id="'.$this->formname.'_prenom_label">Your firstname</label>'."\n".'</th>'."\n";
  74. $expected .= '<td><input name="prenom" id="'.$this->formname.'_prenom" class="jforms-ctrl-input" value="robert" type="text"/>'."\n".'</td></tr>'."\n";
  75. $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";
  76. $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";
  77. $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";
  78. $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";
  79. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_mail" id="'.$this->formname.'_mail_label">Votre mail</label>'."\n".'</th>'."\n";
  80. $expected .= '<td><input name="mail" id="'.$this->formname.'_mail" class="jforms-ctrl-input" value="" type="text"/>'."\n".'</td></tr>'."\n</table></fieldset>\n";
  81. ob_start();$this->builder->outputControl($group);$out = ob_get_clean();
  82. $this->assertEquals($expected, $out);
  83. $this->assertEquals('c = new jFormsControlString(\'nom\', \'Your name\');
  84. c.required = true;
  85. c.errRequired=\'"Your name" field is required\';
  86. c.errInvalid=\'"Your name" field is invalid\';
  87. jForms.tForm.addControl(c);
  88. c = new jFormsControlString(\'prenom\', \'Your firstname\');
  89. c.errInvalid=\'"Your firstname" field is invalid\';
  90. jForms.tForm.addControl(c);
  91. c = new jFormsControlString(\'sexe\', \'Vous êtes \');
  92. c.required = true;
  93. c.errRequired=\'Vous devez indiquer le sexe, même si vous ne savez pas :-)\';
  94. c.errInvalid=\'"Vous êtes " field is invalid\';
  95. jForms.tForm.addControl(c);
  96. c = new jFormsControlEmail(\'mail\', \'Votre mail\');
  97. c.errInvalid=\'"Votre mail" field is invalid\';
  98. jForms.tForm.addControl(c);
  99. ', $this->builder->getJsContent());
  100. $group->setReadOnly(true);
  101. $expected = '<fieldset id="'.$this->formname.'_identity"><legend>Your identity</legend>'."\n";
  102. $expected .= '<table class="jforms-table-group" border="0">'."\n";
  103. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_nom" id="'.$this->formname.'_nom_label">Your name</label>'."\n".'</th>'."\n";
  104. $expected .= '<td><input name="nom" id="'.$this->formname.'_nom" readonly="readonly" class="jforms-ctrl-input jforms-readonly" value="" type="text"/>'."\n".'</td></tr>'."\n";
  105. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_prenom" id="'.$this->formname.'_prenom_label">Your firstname</label>'."\n".'</th>'."\n";
  106. $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";
  107. $expected .= '<tr><th scope="row"><span class="jforms-label" id="'.$this->formname.'_sexe_label">Vous êtes </span>'."\n".'</th>'."\n";
  108. $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";
  109. $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";
  110. $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";
  111. $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_mail" id="'.$this->formname.'_mail_label">Votre mail</label>'."\n".'</th>'."\n";
  112. $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";
  113. ob_start();$this->builder->outputControl($group);$out = ob_get_clean();
  114. $this->assertEquals($expected, $out);
  115. $this->assertEquals('c = new jFormsControlString(\'nom\', \'Your name\');
  116. c.readOnly = true;
  117. c.required = true;
  118. c.errRequired=\'"Your name" field is required\';
  119. c.errInvalid=\'"Your name" field is invalid\';
  120. jForms.tForm.addControl(c);
  121. c = new jFormsControlString(\'prenom\', \'Your firstname\');
  122. c.readOnly = true;
  123. c.errInvalid=\'"Your firstname" field is invalid\';
  124. jForms.tForm.addControl(c);
  125. c = new jFormsControlString(\'sexe\', \'Vous êtes \');
  126. c.readOnly = true;
  127. c.required = true;
  128. c.errRequired=\'Vous devez indiquer le sexe, même si vous ne savez pas :-)\';
  129. c.errInvalid=\'"Vous êtes " field is invalid\';
  130. jForms.tForm.addControl(c);
  131. c = new jFormsControlEmail(\'mail\', \'Votre mail\');
  132. c.readOnly = true;
  133. c.errInvalid=\'"Votre mail" field is invalid\';
  134. jForms.tForm.addControl(c);
  135. ', $this->builder->getJsContent());
  136. }
  137. function testOutputChoice(){
  138. $choice= new jFormsControlChoice('status');
  139. $choice->label='Task Status';
  140. $choice->createItem('new','New');
  141. $choice->createItem('assigned','Assigned');
  142. $choice->createItem('closed','Closed');
  143. $ctrl= new jFormsControlinput('nom');
  144. $ctrl->required=true;
  145. $ctrl->label='Name';
  146. $choice->addChildControl($ctrl,'assigned');
  147. $ctrl= new jFormsControlinput('prenom');
  148. $ctrl->defaultValue='robert';
  149. $ctrl->label='Firstname';
  150. $choice->addChildControl($ctrl,'assigned');
  151. $ctrl= new jFormsControlMenulist('reason');
  152. $ctrl->required=true;
  153. $ctrl->label='Reason ';
  154. $ctrl->alertRequired='Hey, specify a reason !';
  155. $ctrl->datasource= new jFormsStaticDatasource();
  156. $ctrl->datasource->data = array(
  157. 'aa'=>'fixed',
  158. 'bb'=>'won t fixed',
  159. 'cc'=>'later',
  160. );
  161. $choice->addChildControl($ctrl,'closed');
  162. $this->form->addControl($choice);
  163. $choice->setReadOnly(false);
  164. ob_start();$this->builder->outputControlLabel($choice);$out = ob_get_clean();
  165. $this->assertEquals('<span class="jforms-label" id="'.$this->formname.'_status_label">Task Status</span>'."\n", $out);
  166. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  167. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_0" type="radio" value="new" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>'."\n".'</li>'."\n";
  168. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_1" type="radio" value="assigned" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>'."\n";
  169. $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";
  170. $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";
  171. $expected .= '</li>'."\n";
  172. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_2" type="radio" value="closed" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>'."\n";
  173. $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";
  174. $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";
  175. $expected .= '</li>'."\n";
  176. $expected .= '</ul>'."\n\n";
  177. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  178. $this->assertEquals($expected, $out);
  179. $this->assertEquals('c = new jFormsControlChoice(\'status\', \'Task Status\');
  180. c.errInvalid=\'"Task Status" field is invalid\';
  181. jForms.tForm.addControl(c);
  182. c2 = c;
  183. c2.items[\'new\']=[];
  184. c = new jFormsControlString(\'nom\', \'Name\');
  185. c.required = true;
  186. c.errRequired=\'"Name" field is required\';
  187. c.errInvalid=\'"Name" field is invalid\';
  188. c2.addControl(c, \'assigned\');
  189. c = new jFormsControlString(\'prenom\', \'Firstname\');
  190. c.errInvalid=\'"Firstname" field is invalid\';
  191. c2.addControl(c, \'assigned\');
  192. c = new jFormsControlString(\'reason\', \'Reason \');
  193. c.required = true;
  194. c.errRequired=\'Hey, specify a reason !\';
  195. c.errInvalid=\'"Reason " field is invalid\';
  196. c2.addControl(c, \'closed\');
  197. c2.activate(\'\');
  198. ', $this->builder->getJsContent());
  199. $this->form->getContainer()->data['status']='assigned';
  200. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  201. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_0" type="radio" value="new" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>'."\n".'</li>'."\n";
  202. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_1" type="radio" value="assigned" checked="checked" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>'."\n";
  203. $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";
  204. $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";
  205. $expected .= '</li>'."\n";
  206. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_2" type="radio" value="closed" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>'."\n";
  207. $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";
  208. $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";
  209. $expected .= '</li>'."\n";
  210. $expected .= '</ul>'."\n\n";
  211. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  212. $this->assertEquals($expected, $out);
  213. $this->assertEquals('c = new jFormsControlChoice(\'status\', \'Task Status\');
  214. c.errInvalid=\'"Task Status" field is invalid\';
  215. jForms.tForm.addControl(c);
  216. c2 = c;
  217. c2.items[\'new\']=[];
  218. c = new jFormsControlString(\'nom\', \'Name\');
  219. c.required = true;
  220. c.errRequired=\'"Name" field is required\';
  221. c.errInvalid=\'"Name" field is invalid\';
  222. c2.addControl(c, \'assigned\');
  223. c = new jFormsControlString(\'prenom\', \'Firstname\');
  224. c.errInvalid=\'"Firstname" field is invalid\';
  225. c2.addControl(c, \'assigned\');
  226. c = new jFormsControlString(\'reason\', \'Reason \');
  227. c.required = true;
  228. c.errRequired=\'Hey, specify a reason !\';
  229. c.errInvalid=\'"Reason " field is invalid\';
  230. c2.addControl(c, \'closed\');
  231. c2.activate(\'assigned\');
  232. ', $this->builder->getJsContent());
  233. $this->form->getContainer()->data['status']='new';
  234. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  235. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_0" type="radio" value="new" checked="checked" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>'."\n".'</li>'."\n";
  236. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_1" type="radio" value="assigned" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>'."\n";
  237. $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";
  238. $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";
  239. $expected .= '</li>'."\n";
  240. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_2" type="radio" value="closed" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>'."\n";
  241. $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";
  242. $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";
  243. $expected .= '</li>'."\n";
  244. $expected .= '</ul>'."\n\n";
  245. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  246. $this->assertEquals($expected, $out);
  247. $this->assertEquals('c = new jFormsControlChoice(\'status\', \'Task Status\');
  248. c.errInvalid=\'"Task Status" field is invalid\';
  249. jForms.tForm.addControl(c);
  250. c2 = c;
  251. c2.items[\'new\']=[];
  252. c = new jFormsControlString(\'nom\', \'Name\');
  253. c.required = true;
  254. c.errRequired=\'"Name" field is required\';
  255. c.errInvalid=\'"Name" field is invalid\';
  256. c2.addControl(c, \'assigned\');
  257. c = new jFormsControlString(\'prenom\', \'Firstname\');
  258. c.errInvalid=\'"Firstname" field is invalid\';
  259. c2.addControl(c, \'assigned\');
  260. c = new jFormsControlString(\'reason\', \'Reason \');
  261. c.required = true;
  262. c.errRequired=\'Hey, specify a reason !\';
  263. c.errInvalid=\'"Reason " field is invalid\';
  264. c2.addControl(c, \'closed\');
  265. c2.activate(\'new\');
  266. ', $this->builder->getJsContent());
  267. $this->form->getContainer()->data['status']='closed';
  268. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  269. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_0" type="radio" value="new" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>'."\n".'</li>'."\n";
  270. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_1" type="radio" value="assigned" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>'."\n";
  271. $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";
  272. $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";
  273. $expected .= '</li>'."\n";
  274. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_2" type="radio" value="closed" checked="checked" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>'."\n";
  275. $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";
  276. $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";
  277. $expected .= '</li>'."\n";
  278. $expected .= '</ul>'."\n\n";
  279. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  280. $this->assertEquals($expected, $out);
  281. $this->assertEquals('c = new jFormsControlChoice(\'status\', \'Task Status\');
  282. c.errInvalid=\'"Task Status" field is invalid\';
  283. jForms.tForm.addControl(c);
  284. c2 = c;
  285. c2.items[\'new\']=[];
  286. c = new jFormsControlString(\'nom\', \'Name\');
  287. c.required = true;
  288. c.errRequired=\'"Name" field is required\';
  289. c.errInvalid=\'"Name" field is invalid\';
  290. c2.addControl(c, \'assigned\');
  291. c = new jFormsControlString(\'prenom\', \'Firstname\');
  292. c.errInvalid=\'"Firstname" field is invalid\';
  293. c2.addControl(c, \'assigned\');
  294. c = new jFormsControlString(\'reason\', \'Reason \');
  295. c.required = true;
  296. c.errRequired=\'Hey, specify a reason !\';
  297. c.errInvalid=\'"Reason " field is invalid\';
  298. c2.addControl(c, \'closed\');
  299. c2.activate(\'closed\');
  300. ', $this->builder->getJsContent());
  301. $choice->setReadOnly(true);
  302. $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
  303. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_0" readonly="readonly" type="radio" value="new" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>'."\n".'</li>'."\n";
  304. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_1" readonly="readonly" type="radio" value="assigned" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>'."\n";
  305. $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";
  306. $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";
  307. $expected .= '</li>'."\n";
  308. $expected .= '<li><label><input name="status" id="'.$this->formname.'_status_2" readonly="readonly" type="radio" value="closed" checked="checked" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>'."\n";
  309. $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_reason" id="'.$this->formname.'_reason_label">Reason </label>'."\n";
  310. $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";
  311. $expected .= '</li>'."\n";
  312. $expected .= '</ul>'."\n\n";
  313. ob_start();$this->builder->outputControl($choice);$out = ob_get_clean();
  314. $this->assertEquals($expected, $out);
  315. $this->assertEquals('c = new jFormsControlChoice(\'status\', \'Task Status\');
  316. c.readOnly = true;
  317. c.errInvalid=\'"Task Status" field is invalid\';
  318. jForms.tForm.addControl(c);
  319. c2 = c;
  320. c2.items[\'new\']=[];
  321. c = new jFormsControlString(\'nom\', \'Name\');
  322. c.readOnly = true;
  323. c.required = true;
  324. c.errRequired=\'"Name" field is required\';
  325. c.errInvalid=\'"Name" field is invalid\';
  326. c2.addControl(c, \'assigned\');
  327. c = new jFormsControlString(\'prenom\', \'Firstname\');
  328. c.readOnly = true;
  329. c.errInvalid=\'"Firstname" field is invalid\';
  330. c2.addControl(c, \'assigned\');
  331. c = new jFormsControlString(\'reason\', \'Reason \');
  332. c.readOnly = true;
  333. c.required = true;
  334. c.errRequired=\'Hey, specify a reason !\';
  335. c.errInvalid=\'"Reason " field is invalid\';
  336. c2.addControl(c, \'closed\');
  337. c2.activate(\'closed\');
  338. ', $this->builder->getJsContent());
  339. }
  340. public function testFormWithExternalUrlAsAction(){
  341. $this->builder->setAction('http://www.jelix.org/dummy.php',array());
  342. ob_start();
  343. $this->builder->setOptions(array('method'=>'post'));
  344. $this->builder->outputHeader();
  345. $out = ob_get_clean();
  346. $result ='<form action="http://www.jelix.org/dummy.php" method="post" id="'.$this->builder->getName().'"><script type="text/javascript">
  347. //<![CDATA[
  348. jForms.tForm = new jFormsForm(\'jforms_formtestlightB\');
  349. jForms.tForm.setErrorDecorator(new jFormsErrorDecoratorHtml());
  350. jForms.declareForm(jForms.tForm);
  351. //]]>
  352. </script><div class="jforms-hiddens"><input type="hidden" name="__JFORMS_TOKEN__" value="'.$this->container->token.'"/>
  353. </div>';
  354. $this->assertEquals($result, $out);
  355. $this->assertEquals('', $this->builder->getJsContent());
  356. $this->builder->setAction('http://www.jelix.org/dummy.php',array('foo'=>'bar'));
  357. ob_start();
  358. $this->builder->setOptions(array('method'=>'post'));
  359. $this->builder->outputHeader();
  360. $out = ob_get_clean();
  361. $result ='<form action="http://www.jelix.org/dummy.php" method="post" id="'.$this->builder->getName().'"><script type="text/javascript">
  362. //<![CDATA[
  363. jForms.tForm = new jFormsForm(\'jforms_formtestlightB1\');
  364. jForms.tForm.setErrorDecorator(new jFormsErrorDecoratorHtml());
  365. jForms.declareForm(jForms.tForm);
  366. //]]>
  367. </script><div class="jforms-hiddens"><input type="hidden" name="foo" value="bar"/>
  368. <input type="hidden" name="__JFORMS_TOKEN__" value="'.$this->container->token.'"/>
  369. </div>';
  370. $this->assertEquals($result, $out);
  371. $this->assertEquals('', $this->builder->getJsContent());
  372. $this->builder->setAction('https://www.jelix.org/dummy.php',array());
  373. ob_start();
  374. $this->builder->setOptions(array('method'=>'get'));
  375. $this->builder->outputHeader();
  376. $out = ob_get_clean();
  377. $result ='<form action="https://www.jelix.org/dummy.php" method="get" id="'.$this->builder->getName().'"><script type="text/javascript">
  378. //<![CDATA[
  379. jForms.tForm = new jFormsForm(\'jforms_formtestlightB2\');
  380. jForms.tForm.setErrorDecorator(new jFormsErrorDecoratorHtml());
  381. jForms.declareForm(jForms.tForm);
  382. //]]>
  383. </script><div class="jforms-hiddens"><input type="hidden" name="__JFORMS_TOKEN__" value="'.$this->container->token.'"/>
  384. </div>';
  385. $this->assertEquals($result, $out);
  386. $this->assertEquals('', $this->builder->getJsContent());
  387. }
  388. }