/
InitFormTests.pm
854 lines (745 loc) · 30.5 KB
/
InitFormTests.pm
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
package InitFormTests;
use v5.14;
# TODO: Should we check untitled labels? There is some special processing there.
=pod
For the cairo release, we had agreed on the following algorithm:
The order of priority of field initialization should be as follows: For a given form field
* If a value was passed in by a corresponding query parameter, that value should be taken, else
* If the existing topic has a corresponding field value, that value should be taken, else
* If there is no existing topic and there is a templatetopic and there is a corresponding field value, that value should be taken, else
* If there is an initialization value defined in the formtemplate, that value should be taken, else
* The field value should be empty.
There is some question as to what should happen to [[%SYSTEMWEB%.Macros][Macros]].
* Of course the text is taken literally (i.e., variables are not expanded) when it is in the existing form of the topic being edited
* When values are taken from a template topic, embedded variables are not expanded.
* However, variables in values copied from a form are expanded.
The latter serves to, e.g., create timestamps when expanding =%<nop>SERVERTIME{"$day $mon $year $hour:$min"}%=. But there is currently now way of getting a variable unexpanded, so that it could be expanded later, from the form or template. (Note that EditTablePlugin allows the use of escapes, such as =$percnt=, =$dollar=, or =$nop= to prevent expansion.)
Secondly, it is maybe somewhat unintuitive that when text is taken from a template it is expanded.
Note further that a template is not used when an existing topic is edited, even if there is no form attached to that topic.
The testcases below assume that the correct interpretation is the one used in EditTablePlugin.
=cut
use Foswiki::UI::Edit();
use Unit::Request();
use Try::Tiny;
use Moo;
use namespace::clean;
extends qw( FoswikiTestCase );
my $testweb = "TemporaryTestWeb";
my $testtopic1 = "InitTestTopic1";
my $testtopic2 = "InitTestTopic2";
my $testtopic3 = "InitTestTopic3";
my $testform = "InitTestForm";
my $testtmpl = "InitTestTemplate";
my $testuser1 = "TestUser1";
my $testuser2 = "TestUser2";
my $setup_failure = '';
my $aurl; # Holds the %ATTACHURL%
my $testtmpl1 = <<'HERE';
-- Main.WikiGuest - 20 Aug 2005
HERE
my $testform1 = <<'HERE';
| *Name* | *Type* | *Size* | *Values* | *Tooltip messages* | *Mandatory* | *Default* |
| Issue Name | text | 73 | My first defect over-ridden | Illustrative name of issue | M | My first defect |
| Issue Description | textarea | 55x5 | Simple description of problem | Short description of issue | |Simple description of problem |
| Issue Type | select | 1 | Defect, Enhancement, Other | | | |
| History1 | label | 1 | %ATTACHURL% | | | %ATTACHURL%|
| History2 | text | 20 | %ATTACHURL% | | | %ATTACHURL%|
| History3 | label | 1 | $percntATTACHURL% | | |e |
| History4 | text | 2 | this will not be used as its over-ridden by the next line | | | |
| History4 | text | 20 | $percntATTACHURL% | | |$percntATTACHURL% |
| NewWithDefault | text | 20 | $percntATTACHURL% | the default col over-rides value | | is it a plane? |
| [[NewWithDefaultOnly][default only]] | text | 20 | | | | is it another plane? |
| Default To Hidden | select | 1 | Defect, Enhancement, Hidden, Other | | | Hidden |
| Default To Enhancement | radio | 1 | Defect, Enhancement, Hidden, Other | | | Enhancement |
| Enhancement Checkbox | checkbox | 4 | Defect, Enhancement, Hidden, Other | | | Enhancement |
HERE
my $testtext1 = <<'HERE';
Needs the following
* TestFormInitFormA - Form to be attached
Then call <a href="%SCRIPTURL{"edit"}%/%WEB%/%TOPIC%?formtemplate=$testform">Edit</a>
HERE
my $testtext2 = <<'HERE';
Needs the following
* TestFormInitFormA - Form to be attached
Then call <a href="%SCRIPTURL{"edit"}%/%WEB%/%TOPIC%?formtemplate=$testform">Edit</a>
HERE
my $testtext3 = <<'HERE';
...no text...
HERE
my $edittmpl1 = <<'HERE';
%FORMFIELDS%
HERE
# Set up the test fixture
around set_up => sub {
my $orig = shift;
my $this = shift;
$orig->( $this, @_ );
$this->createNewFoswikiSession( $Foswiki::cfg{AdminUserLogin},
$this->request );
Foswiki::Func::createWeb($testweb);
$this->createNewFoswikiSession( undef, $this->request );
if ( $this->session->can('getPubURL') ) {
# FW 1.2 and later
$aurl =
$this->session->getPubURL( $testweb, $testform, undef,
absolute => 1 );
}
else {
# up to FW 1.1.9
$aurl = $this->session->getPubUrl( 1, $testweb, $testform );
}
my ($to) = Foswiki::Func::readTopic( $testweb, $testtopic1 );
$to->put(
'TOPICINFO',
{
author => "WikiGuest",
date => "1159721050",
format => "1.1",
reprev => "1.3",
version => "1.3"
}
);
Foswiki::Func::saveTopic( $testweb, $testtopic1, $to, $testtext1 );
($to) = Foswiki::Func::readTopic( $testweb, $testtopic2 );
$to->put(
'TOPICINFO',
{
author => "WikiGuest",
date => "1159721050",
format => "1.1",
reprev => "1.3",
version => "1.3"
}
);
$to->put( 'FORM', { name => "$testform" } );
$to->putKeyed(
'FIELD',
{
name => "IssueName",
title => "Issue Name",
value => "_An issue_"
}
);
$to->putKeyed(
'FIELD',
{
name => "IssueDescription",
title => "Issue Description",
value => "---+ Example problem"
}
);
$to->putKeyed(
'FIELD',
{
name => "IssueType",
title => "Issue Type",
value => "Defect"
}
);
$to->putKeyed(
'FIELD',
{
name => "History1",
title => "History1",
value => "%SCRIPTURL%"
}
);
$to->putKeyed(
'FIELD',
{
name => "History2",
title => "History2",
value => "%SCRIPTURL%"
}
);
$to->putKeyed(
'FIELD',
{
name => "History3",
title => "History3",
value => '$percntSCRIPTURL%'
}
);
$to->putKeyed(
'FIELD',
{
name => "History4",
title => "History4",
value => '$percntSCRIPTURL%'
}
);
Foswiki::Func::saveTopic( $testweb, $testtopic2, $to, $testtext2 );
($to) = Foswiki::Func::readTopic( $testweb, $testtopic3 );
$to->put(
'TOPICINFO',
{
author => "WikiGuest",
date => "1159721050",
format => "1.1",
reprev => "1.3",
version => "1.3"
}
);
$to->put( 'FORM', { name => "InitTestForm" } );
$to->putKeyed(
'FIELD',
{
name => "IssueName",
title => "Issue Name",
value => "My first defect"
}
);
$to->putKeyed(
'FIELD',
{
name => "IssueDescription",
title => "Issue Description",
value => "Simple description of problem"
}
);
$to->putKeyed(
'FIELD',
{
name => "IssueType",
title => "Issue Type",
value => "Defect"
}
);
$to->putKeyed(
'FIELD',
{
name => "History1",
title => "History1",
value => "%SCRIPTURL%"
}
);
$to->putKeyed(
'FIELD',
{
name => "History3",
title => "History3",
value => '$percntSCRIPTURL%'
}
);
Foswiki::Func::saveTopic( $testweb, $testtopic3, $to, $testtext3 );
($to) = Foswiki::Func::readTopic( $testweb, $testform );
$to->put(
'TOPICINFO',
{
author => "guest",
date => "1025373031",
format => "1.0",
version => "1.3"
}
);
$to->put( 'TOPICPARENT', { name => "WebHome" } );
Foswiki::Func::saveTopic( $testweb, $testform, $to, $testform1 );
($to) = Foswiki::Func::readTopic( $testweb, $testtmpl );
$to->put(
'TOPICINFO',
{
author => "WikiGuest",
date => "1124568292",
format => "1.1",
version => "1.2"
}
);
$to->put( 'FORM', { name => "$testform" } );
$to->putKeyed(
'FIELD',
{
name => "IssueName",
title => "Issue Name",
value => "_An issue_"
}
);
$to->putKeyed(
'FIELD',
{
name => "IssueDescription",
title => "Issue Description",
value => "---+ Example problem"
}
);
$to->putKeyed(
'FIELD',
{
name => "IssueType",
title => "Issue Type",
value => "Defect"
}
);
$to->putKeyed(
'FIELD',
{
name => "History1",
title => "History1",
value => "%SCRIPTURL%"
}
);
$to->putKeyed(
'FIELD',
{
name => "History2",
title => "History2",
value => "%SCRIPTURL%"
}
);
$to->putKeyed(
'FIELD',
{
name => "History3",
title => "History3",
value => '$percntSCRIPTURL%'
}
);
$to->putKeyed(
'FIELD',
{
name => "History4",
title => "History4",
value => '$percntSCRIPTURL%'
}
);
Foswiki::Func::saveTopic( $testweb, $testtmpl, $to, $testtmpl1 );
Foswiki::Func::saveTopic( $testweb, "MyeditTemplate", undef, $edittmpl1 );
$this->session->enterContext('edit');
return;
};
around tear_down => sub {
my $orig = shift;
my $this = shift;
$this->removeWebFixture( $this->session, $testweb );
$orig->($this);
return;
};
# The right form values are created
sub get_formfield {
# Not done at this point. Could walk the form to the right field and then
# do a more precise comparison.
my ( $fld, $text ) = @_;
return $text;
}
sub setup_formtests {
my ( $this, $web, $topic, $params ) = @_;
my $q = Unit::Request->new();
$q->path_info("/$web/$topic");
#$this->session->webName = $web;
#$this->session->topicName = $topic;
require Foswiki::Attrs;
my $attr = Foswiki::Attrs->new($params);
foreach my $k ( keys %{$attr} ) {
next if $k eq '_RAW';
$q->param( -name => $k, -value => $attr->{$k} );
}
$this->createNewFoswikiSession( undef, $q );
$this->session->enterContext('edit');
# Now generate the form. We pass a template which throws everything away
# but the form to allow for simpler analysis.
my ( $text, $tmpl ) =
Foswiki::UI::Edit::init_edit( $this->session, 'myedit' );
return $tmpl;
}
sub test_form {
my $this = shift;
my $text = setup_formtests( $this, $testweb, $testtopic1,
"formtemplate=\"$testweb.$testform\"" );
my $value = 'My first defect';
$value = 'My first defect over-ridden'
if ( $this->check_dependency('Foswiki,<,1.2') );
$this->assert_html_matches(
'<input type="text" name="IssueName" value="'
. $value
. '" size="73" class="foswikiInputField foswikiMandatory" />',
get_formfield( 1, $text )
);
$this->assert_html_matches(
'<textarea name="IssueDescription" rows="5" cols="55" class="foswikiTextarea">
Simple description of problem</textarea>', get_formfield( 2, $text )
);
$this->assert_html_matches(
'<select name="IssueType" class="foswikiSelect" size="1"><option class="foswikiOption">Defect</option><option class="foswikiOption">Enhancement</option><option class="foswikiOption">Other</option></select>',
get_formfield( 3, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History1" value="' . $aurl . '" />',
get_formfield( 4, $text ) );
$this->assert_html_matches(
'<input type="text" name="History2" value="'
. $aurl
. '" size="20" class="foswikiInputField" />',
get_formfield( 5, $text )
);
$value = 'e';
$value = '%ATTACHURL%' if ( $this->check_dependency('Foswiki,<,1.2') );
$this->assert_html_matches(
'<input type="hidden" name="History3" value="' . $value . '" />',
#.'<div class="foswikiFormLabel">http://quiet/~sven/core/pub/TemporaryTestWeb/InitTestTopic1</div>',
get_formfield( 6, $text )
);
if ( $this->check_dependency('Foswiki,<,1.2') ) {
#TODO: SMELL: in 1.1 (need to test 1.0), duplicate fields in the form will result in duplicate html,
$this->assert_html_matches(
'<input type="text" name="History4" value="this will not be used as its over-ridden by the next line" size="2" class="foswikiInputField" />',
get_formfield( 8, $text )
);
}
else {
# $this->assert_html_not_matches(
#'<input type="text" name="History4" value="this will not be used as its over-ridden by the next line" size="2" class="foswikiInputField" />',
# get_formfield( 8, $text )
# );
}
$this->assert_html_matches(
'<input type="text" name="History4" value="%ATTACHURL%" size="20" class="foswikiInputField" />',
get_formfield( 9, $text )
);
#| NewWithDefault | text | 20 | $percntATTACHURL% | the default col over-rides value | | is it a plane? |
$value = 'is it a plane?';
$value = '%ATTACHURL%' if ( $this->check_dependency('Foswiki,<,1.2') );
$this->assert_html_matches(
'<input type="text" name="NewWithDefault" value="'
. $value
. '" size="20" class="foswikiInputField" />',
get_formfield( 10, $text )
);
#| [[NewWithDefaultOnly][default only]] | text | 20 | | | | is it another plane? |
$value = ' value="is it another plane?"';
$value = '' if ( $this->check_dependency('Foswiki,<,1.2') );
$this->assert_html_matches(
'<input type="text" name="defaultonly"'
. $value
. ' size="20" class="foswikiInputField" />',
get_formfield( 11, $text )
);
#| Default To Hidden | select | 1 | Defect, Enhancement, Hidden, Other | | | Hidden |
$value = ' selected="selected"';
$value = '' if ( $this->check_dependency('Foswiki,<,1.2') );
$this->assert_html_matches(
'<select name="DefaultToHidden" class="foswikiSelect" size="1"><option class="foswikiOption">Defect</option><option class="foswikiOption">Enhancement</option><option class="foswikiOption"'
. $value
. '>Hidden</option><option class="foswikiOption">Other</option></select>',
get_formfield( 12, $text )
);
#| Default To Enhancement | radio | 1 | Defect, Enhancement, Hidden, Other | | | Enhancement |
$value = 'checked="checked" ';
$value = '' if ( $this->check_dependency('Foswiki,<,1.2') );
$this->assert_html_matches(
'<input type="radio" name="DefaultToEnhancement" value="Defect" title="Defect" class="foswikiRadioButton"/>Defect</label></td></tr><tr><td><label><input type="radio" name="DefaultToEnhancement" value="Enhancement" '
. $value
. ' title="Enhancement" class="foswikiRadioButton"/>Enhancement</label></td></tr><tr><td><label><input type="radio" name="DefaultToEnhancement" value="Hidden" title="Hidden" class="foswikiRadioButton"/>Hidden</label></td></tr><tr><td><label><input type="radio" name="DefaultToEnhancement" value="Other" title="Other" class="foswikiRadioButton"/>Other</label>',
get_formfield( 13, $text )
);
#| Enhancement Checkbox | checkbox | 4 | Defect, Enhancement, Hidden, Other | | | Enhancement |
$value = 'checked="checked" ';
$value = '' if ( $this->check_dependency('Foswiki,<,1.2') );
$this->assert_html_matches(
'<input type="checkbox" name="EnhancementCheckbox" value="Defect" title="Defect" class="foswikiCheckbox"/>Defect</label></td><td><label><input type="checkbox" name="EnhancementCheckbox" value="Enhancement" '
. $value
. ' title="Enhancement" class="foswikiCheckbox"/>Enhancement</label></td><td><label><input type="checkbox" name="EnhancementCheckbox" value="Hidden" title="Hidden" class="foswikiCheckbox"/>Hidden</label></td><td><label><input type="checkbox" name="EnhancementCheckbox" value="Other" title="Other" class="foswikiCheckbox"/>Other</label>',
get_formfield( 14, $text )
);
return;
}
sub test_tmpl_form {
# Pass formTemplate and templateTopic
my $this = shift;
my $text = setup_formtests( $this, $testweb, $testtopic1,
"formtemplate=\"$testweb.$testform\" templatetopic=\"$testweb.$testtmpl\""
);
$this->assert_html_matches(
'<input type="text" name="IssueName" value="My first defect" size="73" class="foswikiInputField foswikiMandatory" />',
get_formfield( 1, $text )
);
$this->assert_html_matches(
'<textarea name="IssueDescription" rows="5" cols="55" class="foswikiTextarea">
Simple description of problem</textarea>', get_formfield( 2, $text )
);
$this->assert_html_matches(
'<select name="IssueType" class="foswikiSelect" size="1"><option class="foswikiOption">Defect</option><option class="foswikiOption">Enhancement</option><option class="foswikiOption">Other</option></select>',
get_formfield( 3, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History1" value="' . $aurl . '" />',
get_formfield( 4, $text ) );
$this->assert_html_matches(
'<input type="text" name="History2" value="'
. $aurl
. '" size="20" class="foswikiInputField" />',
get_formfield( 5, $text )
);
my $value = 'e';
$value = '%ATTACHURL%' if ( $this->check_dependency('Foswiki,<,1.2') );
$this->assert_html_matches(
'<input type="hidden" name="History3" value="' . $value . '" />',
#.'<div class="foswikiFormLabel">http://quiet/~sven/core/pub/TemporaryTestWeb/InitTestTopic1</div>',
get_formfield( 6, $text )
);
$this->assert_html_matches(
'<input type="text" name="History4" value="%ATTACHURL%" size="20" class="foswikiInputField" />',
get_formfield( 7, $text )
);
return;
}
sub test_tmpl_form_new {
# Pass formTemplate and templateTopic to empty topic
my $this = shift;
my $text = setup_formtests( $this, $testweb, "${testtopic1}XXXXXXXXXX",
"formtemplate=\"$testweb.$testform\" templatetopic=\"$testweb.$testtmpl\""
);
$this->assert_html_matches(
'<input type="text" name="IssueName" value="_An issue_" size="73" class="foswikiInputField foswikiMandatory" />',
get_formfield( 1, $text )
);
$this->assert_html_matches(
'<textarea name="IssueDescription" rows="5" cols="55" class="foswikiTextarea">
---+ Example problem</textarea>', get_formfield( 2, $text )
);
$this->assert_html_matches(
'<select name="IssueType" class="foswikiSelect" size="1"><option class="foswikiOption" selected="selected">Defect</option><option class="foswikiOption">Enhancement</option><option class="foswikiOption">Other</option></select>',
get_formfield( 3, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History1" value="%SCRIPTURL%" />',
get_formfield( 4, $text ) );
$this->assert_html_matches(
'<input type="text" name="History2" value="%SCRIPTURL%" size="20" class="foswikiInputField" />',
get_formfield( 5, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History3" value="%SCRIPTURL%" />',
get_formfield( 6, $text ) );
$this->assert_html_matches(
'<input type="text" name="History4" value="%SCRIPTURL%" size="20" class="foswikiInputField" />',
get_formfield( 7, $text )
);
return;
}
sub test_tmpl_form_existingform {
# Pass formTemplate and templateTopic to topic with form
my $this = shift;
my $text = setup_formtests( $this, $testweb, "$testtopic2",
"formtemplate=\"$testweb.$testform\" templatetopic=\"$testweb.$testtmpl\""
);
$this->assert_html_matches(
'<input type="text" name="IssueName" value="_An issue_" size="73" class="foswikiInputField foswikiMandatory" />',
get_formfield( 1, $text )
);
$this->assert_html_matches(
'<textarea name="IssueDescription" rows="5" cols="55" class="foswikiTextarea">
---+ Example problem</textarea>', get_formfield( 2, $text )
);
$this->assert_html_matches(
'<select name="IssueType" class="foswikiSelect" size="1"><option class="foswikiOption" selected="selected">Defect</option><option class="foswikiOption">Enhancement</option><option class="foswikiOption">Other</option></select>',
get_formfield( 3, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History1" value="%SCRIPTURL%" />',
get_formfield( 4, $text ) );
$this->assert_html_matches(
'<input type="text" name="History2" value="%SCRIPTURL%" size="20" class="foswikiInputField" />',
get_formfield( 5, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History3" value="%SCRIPTURL%" />',
get_formfield( 6, $text ) );
$this->assert_html_matches(
'<input type="text" name="History4" value="%SCRIPTURL%" size="20" class="foswikiInputField" />',
get_formfield( 7, $text )
);
return;
}
sub test_tmpl_form_params {
# Pass query parameters
my $this = shift;
my $text = setup_formtests( $this, $testweb, "$testtopic1",
"formtemplate=\"$testweb.$testform\" templatetopic=\"$testweb.$testtmpl\" IssueName=\"_An issue_\" IssueDescription=\"---+ Example problem\" IssueType=\"Defect\" History1=\"%SCRIPTURL%\" History2=\"%SCRIPTURL%\" History3=\"\$percntSCRIPTURL%\" History4=\"\$percntSCRIPTURL%\" "
);
$this->assert_html_matches(
'<input type="text" name="IssueName" value="_An issue_" size="73" class="foswikiInputField foswikiMandatory" />',
get_formfield( 1, $text )
);
$this->assert_html_matches(
'<textarea name="IssueDescription" rows="5" cols="55" class="foswikiTextarea">
---+ Example problem</textarea>', get_formfield( 2, $text )
);
$this->assert_html_matches(
'<select name="IssueType" class="foswikiSelect" size="1"><option class="foswikiOption" selected="selected">Defect</option><option class="foswikiOption">Enhancement</option><option class="foswikiOption">Other</option></select>',
get_formfield( 3, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History1" value="%SCRIPTURL%" />',
get_formfield( 4, $text ) );
$this->assert_html_matches(
'<input type="text" name="History2" value="%SCRIPTURL%" size="20" class="foswikiInputField" />',
get_formfield( 5, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History3" value="%SCRIPTURL%" />',
get_formfield( 6, $text ) );
$this->assert_html_matches(
'<input type="text" name="History4" value="%SCRIPTURL%" size="20" class="foswikiInputField" />',
get_formfield( 7, $text )
);
return;
}
sub test_tmpl_form_existingform_params {
# Pass query parameters, with field values present
my $this = shift;
my $text = setup_formtests( $this, $testweb, "$testtopic2",
"formtemplate=\"$testweb.$testform\" templatetopic=\"$testweb.$testtmpl\" IssueName=\"My first defect\" IssueDescription=\"Simple description of problem\" IssueType=\"Enhancement\" History1=\"%ATTACHURL%\" History2=\"%ATTACHURL%\" History3=\"\$percntATTACHURL%\" History4=\"\$percntATTACHURL%\" "
);
$this->assert_html_matches(
'<input type="text" name="IssueName" value="My first defect" size="73" class="foswikiInputField foswikiMandatory" />',
get_formfield( 1, $text )
);
$this->assert_html_matches(
'<textarea name="IssueDescription" rows="5" cols="55" class="foswikiTextarea">
Simple description of problem</textarea>', get_formfield( 2, $text )
);
$this->assert_html_matches(
'<select name="IssueType" class="foswikiSelect" size="1"><option class="foswikiOption">Defect</option><option class="foswikiOption" selected="selected">Enhancement</option><option class="foswikiOption">Other</option></select>',
get_formfield( 3, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History1" value="%ATTACHURL%" />',
get_formfield( 4, $text ) );
$this->assert_html_matches(
'<input type="text" name="History2" value="%ATTACHURL%" size="20" class="foswikiInputField" />',
get_formfield( 5, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History3" value="%ATTACHURL%" />',
get_formfield( 6, $text ) );
$this->assert_html_matches(
'<input type="text" name="History4" value="%ATTACHURL%" size="20" class="foswikiInputField" />',
get_formfield( 7, $text )
);
return;
}
sub test_tmpl_form_new_params {
# Pass query parameters, new topic
my $this = shift;
my $text = setup_formtests( $this, $testweb, "${testtopic1}XXXXXXXXXX",
"formtemplate=\"$testweb.$testform\" templatetopic=\"$testweb.$testtmpl\" IssueName=\"My first defect\" IssueDescription=\"Simple description of problem\" IssueType=\"Enhancement\" History1=\"%ATTACHURL%\" History2=\"%ATTACHURL%\" History3=\"\$percntATTACHURL%\" History4=\"\$percntATTACHURL%\" "
);
$this->assert_html_matches(
'<input type="text" name="IssueName" value="My first defect" size="73" class="foswikiInputField foswikiMandatory" />',
get_formfield( 1, $text )
);
$this->assert_html_matches(
'<textarea name="IssueDescription" rows="5" cols="55" class="foswikiTextarea">
Simple description of problem</textarea>', get_formfield( 2, $text )
);
$this->assert_html_matches(
'<select name="IssueType" class="foswikiSelect" size="1"><option class="foswikiOption">Defect</option><option class="foswikiOption" selected="selected">Enhancement</option><option class="foswikiOption">Other</option></select>',
get_formfield( 3, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History1" value="%ATTACHURL%" />',
get_formfield( 4, $text ) );
$this->assert_html_matches(
'<input type="text" name="History2" value="%ATTACHURL%" size="20" class="foswikiInputField" />',
get_formfield( 5, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History3" value="%ATTACHURL%" />',
get_formfield( 6, $text ) );
$this->assert_html_matches(
'<input type="text" name="History4" value="%ATTACHURL%" size="20" class="foswikiInputField" />',
get_formfield( 7, $text )
);
return;
}
sub test_tmpl_form_notext_params {
# Pass query parameters, no text
my $this = shift;
my $text = setup_formtests( $this, $testweb, $testtopic1,
"formtemplate=\"$testweb.$testform\" templatetopic=\"$testweb.$testtmpl\" IssueName=\"My first defect\" IssueDescription=\"Simple description of problem\" IssueType=\"Enhancement\" History1=\"%ATTACHURL%\" History2=\"%ATTACHURL%\" History3=\"\$percntATTACHURL%\" History4=\"\$percntATTACHURL%\" text=\"\""
);
$this->assert_html_matches(
'<input type="text" name="IssueName" value="My first defect" size="73" class="foswikiInputField foswikiMandatory" />',
get_formfield( 1, $text )
);
$this->assert_html_matches(
'<textarea name="IssueDescription" rows="5" cols="55" class="foswikiTextarea">
Simple description of problem</textarea>', get_formfield( 2, $text )
);
$this->assert_html_matches(
'<select name="IssueType" class="foswikiSelect" size="1"><option class="foswikiOption">Defect</option><option class="foswikiOption" selected="selected">Enhancement</option><option class="foswikiOption">Other</option></select>',
get_formfield( 3, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History1" value="%ATTACHURL%" />',
get_formfield( 4, $text ) );
$this->assert_html_matches(
'<input type="text" name="History2" value="%ATTACHURL%" size="20" class="foswikiInputField" />',
get_formfield( 5, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History3" value="%ATTACHURL%" />',
get_formfield( 6, $text ) );
$this->assert_html_matches(
'<input type="text" name="History4" value="%ATTACHURL%" size="20" class="foswikiInputField" />',
get_formfield( 7, $text )
);
return;
}
# Purpose: Just edit the form topic, do not provide any init values
# Verifies: All values are kept intact, in particular:
# * No expansion of Foswiki variables (%SCRIPTURL%)
# * No expansion if $percnt
sub test_dont_expand_on_edit {
my $this = shift;
my $text = setup_formtests( $this, $testweb, $testtopic3 );
$this->assert_html_matches(
'<input type="text" name="IssueName" value="My first defect" size="73" class="foswikiInputField foswikiMandatory" />',
get_formfield( 1, $text )
);
$this->assert_html_matches(
'<textarea name="IssueDescription" rows="5" cols="55" class="foswikiTextarea">
Simple description of problem</textarea>', get_formfield( 2, $text )
);
# $this->assert_matches(qr/<select [^>]+><option ([^>]+| selected)>Defect<\/option>/, get_formfield(3, $text));
$this->assert_html_matches(
'<select name="IssueType" class="foswikiSelect" size="1"><option class="foswikiOption" selected="selected">Defect</option><option class="foswikiOption">Enhancement</option><option class="foswikiOption">Other</option></select>',
get_formfield( 3, $text )
);
$this->assert_html_matches(
'<input type="hidden" name="History1" value="%SCRIPTURL%" />',
get_formfield( 4, $text ) );
$this->assert_html_matches(
'<input type="hidden" name="History3" value="$percntSCRIPTURL%" />',
get_formfield( 6, $text ) );
return;
}
# Item10874, originally Item10446
# Test that ?formtemplate=MyForm works without web prefix on an unsaved topic
sub test_unsavedtopic_rendersform {
my $this = shift;
my $query = Unit::Request->new(
{
webName => [$testweb],
topicName => ['MissingTopic'],
formtemplate => ["$testform"]
}
);
$query->path_info("/$testweb/MissingTopic");
$query->method('POST');
my $fatwilly = $this->createNewFoswikiSession( undef, $query );
my ($text) = $this->capture(
sub {
no strict 'refs';
&{ $this->getUIFn('edit') }($fatwilly);
use strict 'refs';
$Foswiki::engine->finalize( $fatwilly->response,
$fatwilly->request );
}
);
$this->assert_html_matches(
'<input type="text" name="IssueName" value="My first defect" size="73" class="foswikiInputField foswikiMandatory" />',
get_formfield( 6, $text )
);
return;
}
1;