jelix-jpu /testapp/modules/jelix_tests/tests/jforms.htmllightbuilder2.html_cli.php

Language PHP Lines 373
MD5 Hash 248608343c7b98f26143247240568fc0
Repository https://bitbucket.org/doubleface/jelix-jpu View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<?php
/**
* @package     testapp
* @subpackage  unittest module
* @author      Jouanneau Laurent
* @contributor Julien Issler
* @copyright   2007-2008 Jouanneau laurent
* @copyright   2008 Julien Issler
* @link        http://www.jelix.org
* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
*/

require_once(JELIX_LIB_PATH.'forms/jFormsBase.class.php');
require_once(JELIX_LIB_PATH.'forms/jFormsBuilderBase.class.php');
require_once(JELIX_LIB_PATH.'forms/jFormsDataContainer.class.php');
require_once(JELIX_LIB_PATH.'plugins/jforms/htmllight/htmllight.jformsbuilder.php');

class testHTMLLightForm2 extends jFormsBase {
}

class testJFormsHtmlLightBuilder2 extends htmllightJformsBuilder {
    function getJsContent() { $js= $this->jsContent; $this->jsContent = '';return $js;}
    function clearJs() { $this->jsContent = ''; }
}


class UTjformsHTMLLightBuilder2 extends jUnitTestCaseDb {

    protected static $mysharedfixture;
    function testStart() {
        self::$mysharedfixture = new stdClass;
        self::$mysharedfixture->container = new jFormsDataContainer('formtestlightB','');
        self::$mysharedfixture->form = new testHTMLLightForm2('formtestlightB', self::$mysharedfixture->container, true );
        self::$mysharedfixture->builder = new testJFormsHtmlLightBuilder2(self::$mysharedfixture->form);
        self::$mysharedfixture->formname = self::$mysharedfixture->builder->getName();
    }

    function testOutputGroup(){

        $group= new jFormsControlgroup('identity');
        $group->label='Your identity';

        $ctrl= new jFormsControlinput('nom');
        $ctrl->required=true;
        $ctrl->label='Your name';
        $group->addChildControl($ctrl);

        $ctrl= new jFormsControlinput('prenom');
        $ctrl->defaultValue='robert';
        $ctrl->label='Your firstname';
        $group->addChildControl($ctrl);

        $ctrl= new jFormsControlradiobuttons('sexe');
        $ctrl->required=true;
        $ctrl->label='Vous êtes ';
        $ctrl->alertRequired='Vous devez indiquer le sexe, même si vous ne savez pas :-)';
        $ctrl->datasource= new jFormsStaticDatasource();
        $ctrl->datasource->data = array(
        'h'=>'un homme',
        'f'=>'une femme',
        'no'=>'je ne sais pas',
        );
        $group->addChildControl($ctrl);

        $ctrl= new jFormsControlinput('mail');
        $ctrl->datatype= new jDatatypeemail();
        $ctrl->label='Votre mail';
        $group->addChildControl($ctrl);

        self::$mysharedfixture->form->addControl($group);


        ob_start();self::$mysharedfixture->builder->outputControlLabel($group);$out = ob_get_clean();
        $this->assertEqualOrDiff('', $out);


        $expected = '<fieldset><legend>Your identity</legend>'."\n";
        $expected .= '<table class="jforms-table-group" border="0">'."\n";
        $expected .= '<tr><th scope="row"><label class="jforms-label jforms-required" for="'.self::$mysharedfixture->formname.'_nom">Your name</label></th>'."\n";
        $expected .= '<td><input type="text" name="nom" id="'.self::$mysharedfixture->formname.'_nom" class=" jforms-required" value=""/></td></tr>'."\n";
        $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.self::$mysharedfixture->formname.'_prenom">Your firstname</label></th>'."\n";
        $expected .= '<td><input type="text" name="prenom" id="'.self::$mysharedfixture->formname.'_prenom" value="robert"/></td></tr>'."\n";
        $expected .= '<tr><th scope="row"><span class="jforms-label jforms-required">Vous êtes </span></th>'."\n";
        $expected .= '<td><span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.self::$mysharedfixture->formname.'_sexe_0" value="h" class=" jforms-required"/><label for="'.self::$mysharedfixture->formname.'_sexe_0">un homme</label></span>';
        $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.self::$mysharedfixture->formname.'_sexe_1" value="f" class=" jforms-required"/><label for="'.self::$mysharedfixture->formname.'_sexe_1">une femme</label></span>';
        $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.self::$mysharedfixture->formname.'_sexe_2" value="no" class=" jforms-required"/><label for="'.self::$mysharedfixture->formname.'_sexe_2">je ne sais pas</label></span></td></tr>'."\n";
        $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.self::$mysharedfixture->formname.'_mail">Votre mail</label></th>'."\n";
        $expected .= '<td><input type="text" name="mail" id="'.self::$mysharedfixture->formname.'_mail" value=""/></td></tr>'."\n</table></fieldset>";


        ob_start();self::$mysharedfixture->builder->outputControl($group);$out = ob_get_clean();
        $this->assertEqualOrDiff($expected, $out);
        $this->assertEqualOrDiff('c = new jFormsControlString(\'nom\', \'Your name\');
c.required = true;
c.errRequired=\'"Your name" field is required\';
c.errInvalid=\'"Your name" field is invalid\';
jForms.tForm.addControl(c);
c = new jFormsControlString(\'prenom\', \'Your firstname\');
c.errInvalid=\'"Your firstname" field is invalid\';
jForms.tForm.addControl(c);
c = new jFormsControlString(\'sexe\', \'Vous êtes \');
c.required = true;
c.errRequired=\'Vous devez indiquer le sexe, même si vous ne savez pas :-)\';
c.errInvalid=\'"Vous êtes " field is invalid\';
jForms.tForm.addControl(c);
c = new jFormsControlEmail(\'mail\', \'Votre mail\');
c.errInvalid=\'"Votre mail" field is invalid\';
jForms.tForm.addControl(c);
', self::$mysharedfixture->builder->getJsContent());

        $group->setReadOnly(true);
        $expected = '<fieldset><legend>Your identity</legend>'."\n";
        $expected .= '<table class="jforms-table-group" border="0">'."\n";
        $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.self::$mysharedfixture->formname.'_nom">Your name</label></th>'."\n";
        $expected .= '<td><input type="text" name="nom" id="'.self::$mysharedfixture->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></td></tr>'."\n";
        $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.self::$mysharedfixture->formname.'_prenom">Your firstname</label></th>'."\n";
        $expected .= '<td><input type="text" name="prenom" id="'.self::$mysharedfixture->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></td></tr>'."\n";
        $expected .= '<tr><th scope="row"><span class="jforms-label">Vous êtes </span></th>'."\n";
        $expected .= '<td><span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.self::$mysharedfixture->formname.'_sexe_0" value="h" readonly="readonly" class=" jforms-readonly"/><label for="'.self::$mysharedfixture->formname.'_sexe_0">un homme</label></span>';
        $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.self::$mysharedfixture->formname.'_sexe_1" value="f" readonly="readonly" class=" jforms-readonly"/><label for="'.self::$mysharedfixture->formname.'_sexe_1">une femme</label></span>';
        $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.self::$mysharedfixture->formname.'_sexe_2" value="no" readonly="readonly" class=" jforms-readonly"/><label for="'.self::$mysharedfixture->formname.'_sexe_2">je ne sais pas</label></span></td></tr>'."\n";
        $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.self::$mysharedfixture->formname.'_mail">Votre mail</label></th>'."\n";
        $expected .= '<td><input type="text" name="mail" id="'.self::$mysharedfixture->formname.'_mail" readonly="readonly" class=" jforms-readonly" value=""/></td></tr>'."\n</table></fieldset>";
        ob_start();self::$mysharedfixture->builder->outputControl($group);$out = ob_get_clean();
        $this->assertEqualOrDiff($expected, $out);
        $this->assertEqualOrDiff('c = new jFormsControlString(\'nom\', \'Your name\');
c.required = true;
c.errRequired=\'"Your name" field is required\';
c.errInvalid=\'"Your name" field is invalid\';
jForms.tForm.addControl(c);
c = new jFormsControlString(\'prenom\', \'Your firstname\');
c.errInvalid=\'"Your firstname" field is invalid\';
jForms.tForm.addControl(c);
c = new jFormsControlString(\'sexe\', \'Vous êtes \');
c.required = true;
c.errRequired=\'Vous devez indiquer le sexe, même si vous ne savez pas :-)\';
c.errInvalid=\'"Vous êtes " field is invalid\';
jForms.tForm.addControl(c);
c = new jFormsControlEmail(\'mail\', \'Votre mail\');
c.errInvalid=\'"Votre mail" field is invalid\';
jForms.tForm.addControl(c);
', self::$mysharedfixture->builder->getJsContent());

    }


    function testOutputChoice(){

        $choice= new jFormsControlChoice('status');
        $choice->label='Task Status';
        $choice->createItem('new','New');
        $choice->createItem('assigned','Assigned');
        $choice->createItem('closed','Closed');

        $ctrl= new jFormsControlinput('nom');
        $ctrl->required=true;
        $ctrl->label='Name';
        $choice->addChildControl($ctrl,'assigned');


        $ctrl= new jFormsControlinput('prenom');
        $ctrl->defaultValue='robert';
        $ctrl->label='Firstname';
        $choice->addChildControl($ctrl,'assigned');

        $ctrl= new jFormsControlMenulist('reason');
        $ctrl->required=true;
        $ctrl->label='Reason ';
        $ctrl->alertRequired='Hey, specify a reason !';
        $ctrl->datasource= new jFormsStaticDatasource();
        $ctrl->datasource->data = array(
        'aa'=>'fixed',
        'bb'=>'won t fixed',
        'cc'=>'later',
        );
        $choice->addChildControl($ctrl,'closed');

        self::$mysharedfixture->form->addControl($choice);


        ob_start();self::$mysharedfixture->builder->outputControlLabel($choice);$out = ob_get_clean();
        $this->assertEqualOrDiff('<label class="jforms-label" for="'.self::$mysharedfixture->formname.'_status">Task Status</label>', $out);


        $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
        $expected .= '<li><label><input type="radio" name="status" id="'.self::$mysharedfixture->formname.'_status_0" value="new" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label> </li>'."\n";
        $expected .= '<li><label><input type="radio" name="status" id="'.self::$mysharedfixture->formname.'_status_1" value="assigned" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>  <span class="jforms-item-controls"><label class="jforms-label" for="'.self::$mysharedfixture->formname.'_nom">Name</label> <input type="text" name="nom" id="'.self::$mysharedfixture->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></span>'."\n";
        $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.self::$mysharedfixture->formname.'_prenom">Firstname</label> <input type="text" name="prenom" id="'.self::$mysharedfixture->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></span>'."\n";
        $expected .= '</li>'."\n";
        $expected .= '<li><label><input type="radio" name="status" id="'.self::$mysharedfixture->formname.'_status_2" value="closed" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>  <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.self::$mysharedfixture->formname.'_reason">Reason </label> <select name="reason" id="'.self::$mysharedfixture->formname.'_reason" class=" jforms-required" size="1"><option value="aa">fixed</option><option value="bb">won t fixed</option><option value="cc">later</option></select></span>'."\n";
        $expected .= '</li>'."\n";
        $expected .= '</ul>'."\n";
        ob_start();self::$mysharedfixture->builder->outputControl($choice);$out = ob_get_clean();
        $this->assertEqualOrDiff($expected, $out);
        $this->assertEqualOrDiff('c = new jFormsControlChoice(\'status\', \'Task Status\');
c.errInvalid=\'"Task Status" field is invalid\';
jForms.tForm.addControl(c);
c2 = c;
c2.items[\'new\']=[];
c = new jFormsControlString(\'nom\', \'Name\');
c.required = true;
c.errRequired=\'"Name" field is required\';
c.errInvalid=\'"Name" field is invalid\';
c2.addControl(c, \'assigned\');
c = new jFormsControlString(\'prenom\', \'Firstname\');
c.errInvalid=\'"Firstname" field is invalid\';
c2.addControl(c, \'assigned\');
c = new jFormsControlString(\'reason\', \'Reason \');
c.required = true;
c.errRequired=\'Hey, specify a reason !\';
c.errInvalid=\'"Reason " field is invalid\';
c2.addControl(c, \'closed\');
c2.activate(\'\');
', self::$mysharedfixture->builder->getJsContent());

        self::$mysharedfixture->form->getContainer()->data['status']='assigned';

        $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
        $expected .= '<li><label><input type="radio" name="status" id="'.self::$mysharedfixture->formname.'_status_0" value="new" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label> </li>'."\n";
        $expected .= '<li><label><input type="radio" name="status" id="'.self::$mysharedfixture->formname.'_status_1" value="assigned" checked="checked" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>  <span class="jforms-item-controls"><label class="jforms-label" for="'.self::$mysharedfixture->formname.'_nom">Name</label> <input type="text" name="nom" id="'.self::$mysharedfixture->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></span>'."\n";
        $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.self::$mysharedfixture->formname.'_prenom">Firstname</label> <input type="text" name="prenom" id="'.self::$mysharedfixture->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></span>'."\n";
        $expected .= '</li>'."\n";
        $expected .= '<li><label><input type="radio" name="status" id="'.self::$mysharedfixture->formname.'_status_2" value="closed" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>  <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.self::$mysharedfixture->formname.'_reason">Reason </label> <select name="reason" id="'.self::$mysharedfixture->formname.'_reason" class=" jforms-required" size="1"><option value="aa">fixed</option><option value="bb">won t fixed</option><option value="cc">later</option></select></span>'."\n";
        $expected .= '</li>'."\n";
        $expected .= '</ul>'."\n";
        ob_start();self::$mysharedfixture->builder->outputControl($choice);$out = ob_get_clean();
        $this->assertEqualOrDiff($expected, $out);
        $this->assertEqualOrDiff('c = new jFormsControlChoice(\'status\', \'Task Status\');
c.errInvalid=\'"Task Status" field is invalid\';
jForms.tForm.addControl(c);
c2 = c;
c2.items[\'new\']=[];
c = new jFormsControlString(\'nom\', \'Name\');
c.required = true;
c.errRequired=\'"Name" field is required\';
c.errInvalid=\'"Name" field is invalid\';
c2.addControl(c, \'assigned\');
c = new jFormsControlString(\'prenom\', \'Firstname\');
c.errInvalid=\'"Firstname" field is invalid\';
c2.addControl(c, \'assigned\');
c = new jFormsControlString(\'reason\', \'Reason \');
c.required = true;
c.errRequired=\'Hey, specify a reason !\';
c.errInvalid=\'"Reason " field is invalid\';
c2.addControl(c, \'closed\');
c2.activate(\'assigned\');
', self::$mysharedfixture->builder->getJsContent());

        self::$mysharedfixture->form->getContainer()->data['status']='new';
        $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
        $expected .= '<li><label><input type="radio" name="status" id="'.self::$mysharedfixture->formname.'_status_0" value="new" checked="checked" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label> </li>'."\n";
        $expected .= '<li><label><input type="radio" name="status" id="'.self::$mysharedfixture->formname.'_status_1" value="assigned" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>  <span class="jforms-item-controls"><label class="jforms-label" for="'.self::$mysharedfixture->formname.'_nom">Name</label> <input type="text" name="nom" id="'.self::$mysharedfixture->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></span>'."\n";
        $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.self::$mysharedfixture->formname.'_prenom">Firstname</label> <input type="text" name="prenom" id="'.self::$mysharedfixture->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></span>'."\n";
        $expected .= '</li>'."\n";
        $expected .= '<li><label><input type="radio" name="status" id="'.self::$mysharedfixture->formname.'_status_2" value="closed" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>  <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.self::$mysharedfixture->formname.'_reason">Reason </label> <select name="reason" id="'.self::$mysharedfixture->formname.'_reason" class=" jforms-required" size="1"><option value="aa">fixed</option><option value="bb">won t fixed</option><option value="cc">later</option></select></span>'."\n";
        $expected .= '</li>'."\n";
        $expected .= '</ul>'."\n";
        ob_start();self::$mysharedfixture->builder->outputControl($choice);$out = ob_get_clean();
        $this->assertEqualOrDiff($expected, $out);
        $this->assertEqualOrDiff('c = new jFormsControlChoice(\'status\', \'Task Status\');
c.errInvalid=\'"Task Status" field is invalid\';
jForms.tForm.addControl(c);
c2 = c;
c2.items[\'new\']=[];
c = new jFormsControlString(\'nom\', \'Name\');
c.required = true;
c.errRequired=\'"Name" field is required\';
c.errInvalid=\'"Name" field is invalid\';
c2.addControl(c, \'assigned\');
c = new jFormsControlString(\'prenom\', \'Firstname\');
c.errInvalid=\'"Firstname" field is invalid\';
c2.addControl(c, \'assigned\');
c = new jFormsControlString(\'reason\', \'Reason \');
c.required = true;
c.errRequired=\'Hey, specify a reason !\';
c.errInvalid=\'"Reason " field is invalid\';
c2.addControl(c, \'closed\');
c2.activate(\'new\');
', self::$mysharedfixture->builder->getJsContent());

        self::$mysharedfixture->form->getContainer()->data['status']='closed';
        $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n";
        $expected .= '<li><label><input type="radio" name="status" id="'.self::$mysharedfixture->formname.'_status_0" value="new" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label> </li>'."\n";
        $expected .= '<li><label><input type="radio" name="status" id="'.self::$mysharedfixture->formname.'_status_1" value="assigned" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>  <span class="jforms-item-controls"><label class="jforms-label" for="'.self::$mysharedfixture->formname.'_nom">Name</label> <input type="text" name="nom" id="'.self::$mysharedfixture->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></span>'."\n";
        $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.self::$mysharedfixture->formname.'_prenom">Firstname</label> <input type="text" name="prenom" id="'.self::$mysharedfixture->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></span>'."\n";
        $expected .= '</li>'."\n";
        $expected .= '<li><label><input type="radio" name="status" id="'.self::$mysharedfixture->formname.'_status_2" value="closed" checked="checked" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>  <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.self::$mysharedfixture->formname.'_reason">Reason </label> <select name="reason" id="'.self::$mysharedfixture->formname.'_reason" class=" jforms-required" size="1"><option value="aa">fixed</option><option value="bb">won t fixed</option><option value="cc">later</option></select></span>'."\n";
        $expected .= '</li>'."\n";
        $expected .= '</ul>'."\n";
        ob_start();self::$mysharedfixture->builder->outputControl($choice);$out = ob_get_clean();
        $this->assertEqualOrDiff($expected, $out);
        $this->assertEqualOrDiff('c = new jFormsControlChoice(\'status\', \'Task Status\');
c.errInvalid=\'"Task Status" field is invalid\';
jForms.tForm.addControl(c);
c2 = c;
c2.items[\'new\']=[];
c = new jFormsControlString(\'nom\', \'Name\');
c.required = true;
c.errRequired=\'"Name" field is required\';
c.errInvalid=\'"Name" field is invalid\';
c2.addControl(c, \'assigned\');
c = new jFormsControlString(\'prenom\', \'Firstname\');
c.errInvalid=\'"Firstname" field is invalid\';
c2.addControl(c, \'assigned\');
c = new jFormsControlString(\'reason\', \'Reason \');
c.required = true;
c.errRequired=\'Hey, specify a reason !\';
c.errInvalid=\'"Reason " field is invalid\';
c2.addControl(c, \'closed\');
c2.activate(\'closed\');
', self::$mysharedfixture->builder->getJsContent());
    }

    public function testFormWithExternalUrlAsAction(){
        self::$mysharedfixture->builder->setAction('http://www.jelix.org/dummy.php',array());
        ob_start();
        self::$mysharedfixture->builder->outputHeader(array('method'=>'post'));
        $out = ob_get_clean();

        $result ='<form action="http://www.jelix.org/dummy.php" method="post" id="'.self::$mysharedfixture->builder->getName().'"><script type="text/javascript">
//<![CDATA[
jForms.tForm = new jFormsForm(\'jforms_formtestlightB\');
jForms.tForm.setErrorDecorator(new jFormsErrorDecoratorAlert());
jForms.tForm.setHelpDecorator(new jFormsHelpDecoratorAlert());
jForms.declareForm(jForms.tForm);
//]]>
</script><div class="jforms-hiddens"><input type="hidden" name="__JFORMS_TOKEN__" value="'.self::$mysharedfixture->container->token.'"/>
</div>';

        $this->assertEqualOrDiff($result, $out);
        $this->assertEqualOrDiff('', self::$mysharedfixture->builder->getJsContent());

        self::$mysharedfixture->builder->setAction('http://www.jelix.org/dummy.php',array('foo'=>'bar'));
        ob_start();
        self::$mysharedfixture->builder->outputHeader(array('method'=>'post'));
        $out = ob_get_clean();

        $result ='<form action="http://www.jelix.org/dummy.php" method="post" id="'.self::$mysharedfixture->builder->getName().'"><script type="text/javascript">
//<![CDATA[
jForms.tForm = new jFormsForm(\'jforms_formtestlightB1\');
jForms.tForm.setErrorDecorator(new jFormsErrorDecoratorAlert());
jForms.tForm.setHelpDecorator(new jFormsHelpDecoratorAlert());
jForms.declareForm(jForms.tForm);
//]]>
</script><div class="jforms-hiddens"><input type="hidden" name="foo" value="bar"/>
<input type="hidden" name="__JFORMS_TOKEN__" value="'.self::$mysharedfixture->container->token.'"/>
</div>';

        $this->assertEqualOrDiff($result, $out);
        $this->assertEqualOrDiff('', self::$mysharedfixture->builder->getJsContent());

        self::$mysharedfixture->builder->setAction('https://www.jelix.org/dummy.php',array());
        ob_start();
        self::$mysharedfixture->builder->outputHeader(array('method'=>'get'));
        $out = ob_get_clean();

        $result ='<form action="https://www.jelix.org/dummy.php" method="get" id="'.self::$mysharedfixture->builder->getName().'"><script type="text/javascript">
//<![CDATA[
jForms.tForm = new jFormsForm(\'jforms_formtestlightB2\');
jForms.tForm.setErrorDecorator(new jFormsErrorDecoratorAlert());
jForms.tForm.setHelpDecorator(new jFormsHelpDecoratorAlert());
jForms.declareForm(jForms.tForm);
//]]>
</script><div class="jforms-hiddens"><input type="hidden" name="__JFORMS_TOKEN__" value="'.self::$mysharedfixture->container->token.'"/>
</div>';

        $this->assertEqualOrDiff($result, $out);
        $this->assertEqualOrDiff('', self::$mysharedfixture->builder->getJsContent());

    }
}
Back to Top