_xowiki__create_form_with_form_instance (private)
_xowiki__create_form_with_form_instance
Defined in packages/xowiki/tcl/test/xowiki-test-procs.tcl
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: set _aa_export {} set body_count 1 foreach testcase_body {{ # # Create a new admin user and login # # # Setup of test user_id and login # set user_info [::acs::test::user::create -email xowiki@acs-testing.test -admin] set request_info [::acs::test::login $user_info] set instance /xowiki-test set package_id [::acs::test::require_package_instance -package_key xowiki -empty -instance_name $instance] set testfolder .testfolder try { ########################################################### aa_section "Require test folder" ########################################################### set folder_info [::xowiki::test::require_test_folder -last_request $request_info -instance $instance -folder_name $testfolder -fresh ] set folder_id [dict get $folder_info folder_id] set package_id [dict get $folder_info package_id] aa_true "folder_id '$folder_id' is not 0" {$folder_id != 0} set locale [lang::system::locale] set lang [string range $locale 0 1] set form_name $lang:checkbox-testing.form ########################################################### aa_section "Create Form $form_name" ########################################################### # # The created form contains several checkboxes, which are # nasty to handle. When a checkbox was marked, but is then # unchecked, its value is NOT returned by the # browser. The server has to detect by the fact of # untransmitted values that the instance attribute value # has to be altered. This is very different to the # standard cases, where the edited values are transmitted. # # The created form below handles also more complex cases: # # a) a checkbox box1, where a default is set # b) a repeated checkbox, where one value is provided # c) a compound field, where the compound field definition # contains a default for the subcomponent. ::xowiki::test::create_form -last_request $request_info -instance $instance -path $testfolder -parent_id $folder_id -name $form_name -update [subst { title "Checkbox Testing Form" nls_language $locale text {<p>@_text@</p><p>box1 @box1@ box2 @box2@ box3 @box3@</p>} text.format text/html form {<form>@ignored@ @assignee@ @box1@ @box2@ @box3@ @mycompound@</form>} form.format text/html form_constraints { _page_order:omit _title:omit _nls_language:omit _description:omit ignored:text,disabled _assignee:text,disabled {box1:checkbox,options={1 1} {2 2},horizontal=true,default=1} {box2:checkbox,options={a a} {b b},horizontal=true,repeat=1..3,default=a} {box3:checkbox,options={30 30} {31 31},horizontal=true,default=30,disabled} mycompound:regression_test_mycompound } anon_instances t }] aa_log "Form $form_name created" ########################################################### aa_section "Create an instance of $form_name named '$lang:cb1'" ########################################################### set page_name $lang:cb1 set user_id [dict get $user_info user_id] set another_user_id [::xo::dc get_value get_another_user { select max(user_id) from users where user_id <> :user_id }] set d [::xowiki::test::create_form_page -last_request $request_info -instance $instance -path $testfolder -parent_id $folder_id -form_name $form_name -update [subst { _name $page_name _title "fresh $page_name" _nls_language $locale ignored {I should not be stored} _assignee $another_user_id }]] aa_log "Page $page_name created" set extra_url_parameter {{m edit}} aa_log "Check content of the fresh instance" set d [acs::test::http -last_request $request_info [export_vars -base $instance/$testfolder/$page_name $extra_url_parameter]] acs::test::reply_has_status_code $d 200 set response [dict get $d body] acs::test::dom_html root $response { set f_id [::xowiki::test::get_object_name $root] set CSSclass [::xowiki::test::get_form_CSSclass $root] aa_true "page_name '$f_id' non empty" {$f_id ne ""} aa_true "CSSclass: '$CSSclass' non empty" {$CSSclass ne ""} set id_part [string map {: _} $page_name] set ignored [$root getElementById F.$id_part.ignored] set assignee [$root getElementById F.$id_part._assignee] set page_order [$root getElementById F.$id_part._page_order] set input_box1_1 [$root getElementById F.$id_part.box1:1] set input_box1_2 [$root getElementById F.$id_part.box1:2] set input_box2_1_a [$root getElementById F.$id_part.box2.1:a] set input_box2_1_b [$root getElementById F.$id_part.box2.1:b] set input_box5 [$root getElementById F.$id_part.mycompound.start_on_publish:t] set input_box6 [$root getElementById F.$id_part.box3:30] set input_box7 [$root getElementById F.$id_part.box3:31] aa_equals "ignored text field is empty" [$ignored getAttribute value] "" aa_equals "assignee text field is empty" [$assignee getAttribute value] "" aa_equals "input_box1_1 box checked (box1: simple box)" [$input_box1_1 hasAttribute checked] 1 aa_equals "input_box1_2 box checked (box1: simple box)" [$input_box1_2 hasAttribute checked] 0 aa_equals "input_box2_1_a box checked (box2: repeated box)" [$input_box2_1_a hasAttribute checked] 1 aa_equals "input_box2_1_b box checked (box2: repeated box)" [$input_box2_1_b hasAttribute checked] 0 aa_equals "input_box5 box checked (mycompound)" [$input_box5 hasAttribute checked] 1 aa_equals "input_box6 box checked (box3: simple disabled box)" [$input_box6 hasAttribute checked] 1 aa_equals "input_box7 box checked (box3: simple disabled box)" [$input_box7 hasAttribute checked] 0 aa_equals "page_order should be omitted and not be rendered" $page_order "" #ns_log notice "XXXX box3\n[$input_box6 asHTML] \n[$input_box7 asHTML]" } ########################################################### aa_section "Edit the instance of $form_name" ########################################################### ::xowiki::test::edit_form_page -last_request $request_info -instance $instance -path $testfolder/$page_name -remove {box1 box2.1 mycompound.start_on_publish} -update [subst { _title "edited $page_name" }] aa_log "Check content of the edited instance" set d [acs::test::http -user_info $user_info [export_vars -base $instance/$testfolder/$page_name $extra_url_parameter]] acs::test::reply_has_status_code $d 200 set response [dict get $d body] acs::test::dom_html root $response { set id_part [string map {: _} $page_name] set input_box1 [$root getElementById F.$id_part.box1:1] set input_box2 [$root getElementById F.$id_part.box1:2] set input_box3 [$root getElementById F.$id_part.box2.1:a] set input_box4 [$root getElementById F.$id_part.box2.1:b] set input_box5 [$root getElementById F.$id_part.mycompound.start_on_publish:t] set input_box6 [$root getElementById F.$id_part.box3:30] set input_box7 [$root getElementById F.$id_part.box3:31] aa_equals "input_box1 box checked (box1: simple box)" [$input_box1 hasAttribute checked] 0 aa_equals "input_box2 box checked (box1: simple box)" [$input_box2 hasAttribute checked] 0 aa_equals "input_box3 box checked (box2: repeated box)" [$input_box3 hasAttribute checked] 0 aa_equals "input_box4 box checked (box2: repeated box)" [$input_box4 hasAttribute checked] 0 aa_equals "input_box5 box checked (mycompound)" [$input_box5 hasAttribute checked] 0 aa_equals "input_box6 box checked (box3: simple disabled box)" [$input_box6 hasAttribute checked] 1 aa_equals "input_box7 box checked (box3: simple disabled box)" [$input_box7 hasAttribute checked] 0 #ns_log notice "XXXX box3\n[$input_box6 asHTML] \n[$input_box7 asHTML]" } set form_name $lang:Misc.form ########################################################### aa_section "Create form $form_name" ########################################################### # # Create a form with date fields in different formats # (date is a repeated field). # ::xowiki::test::create_form -last_request $request_info -instance $instance -path $testfolder -parent_id $folder_id -name $form_name -update [subst { title "Form for miscelaneus form fields" nls_language $locale text {<p>@date@</p><p>@date2@</p>} text.format text/html form {<form>@date@ @date2@</form>} form.format text/html form_constraints { _page_order:omit _title:omit _nls_language:omit _description:omit date:date {date2:date,format=DD_MONTH_YYYY_HH24_MI,default=2011-01-01 20:55,disabled} } }] aa_log "Form $form_name created" set page_name $lang:m1 ########################################################### aa_section "Create an instance $page_name of $form_name" ########################################################### ::xowiki::test::create_form_page -last_request $request_info -instance $instance -path $testfolder -parent_id $folder_id -form_name $form_name -update [subst { _name $page_name _title "fresh $page_name" _nls_language $locale }] aa_log "Page $page_name created" set extra_url_parameter {{m edit}} aa_log "Check content of the fresh instance" set d [acs::test::http -last_request $request_info [export_vars -base $instance/$testfolder/$page_name $extra_url_parameter]] acs::test::reply_has_status_code $d 200 set response [dict get $d body] acs::test::dom_html root $response { set f_id [::xowiki::test::get_object_name $root] set CSSclass [::xowiki::test::get_form_CSSclass $root] aa_true "page_name '$f_id' non empty" {$f_id ne ""} aa_true "CSSclass: '$CSSclass' non empty" {$CSSclass ne ""} set id_part F.[string map {: _} $page_name] set input1 [$root getElementById $id_part.date.DD] set input2 [$root getElementById $id_part.date.month] set input3 [$root getElementById $id_part.date.YYYY] aa_true "input1 (1st element of date)" {$input1 ne ""} aa_true "input2 (2nd element of date)" {$input2 ne ""} aa_true "input3 (3rd element of date)" {[$input3 getAttribute value] eq ""} set input4 [$root selectNodes "//select\[@id='$id_part.date2.DD'\]/option\[@selected\]"] set input5 [$root selectNodes "//select\[@id='$id_part.date2.month'\]/option\[@selected\]"] set input6 [$root getElementById $id_part.date2.YYYY] set input7 [$root selectNodes "//select\[@id='$id_part.date2.HH24'\]/option\[@selected\]"] set input8 [$root selectNodes "//select\[@id='$id_part.date2.MI'\]/option\[@selected\]"] aa_true "input4 (1st element of date2)" {[$input4 getAttribute value] eq "1"} aa_true "input5 (2nd element of date2)" {[$input5 getAttribute value] eq "1"} aa_true "input6 (3rd element of date2)" {[$input6 getAttribute value] eq "2011"} aa_true "input7 (4th element of date2)" {[$input7 getAttribute value] eq "20"} aa_true "input8 (5th element of date2)" {[$input8 getAttribute value] eq "55"} } ################################################################################ aa_section "Edit an instance $page_name of $form_name to set the dates" ################################################################################ ::xowiki::test::edit_form_page -last_request $request_info -instance $instance -path $testfolder/$page_name -update [subst { _title "edited $page_name" date.DD 1 date.month 1 date.YYYY 2022 date2.YYYY 2021 }] aa_log "Check content of the edited instance" set d [acs::test::http -user_info $user_info [export_vars -base $instance/$testfolder/$page_name $extra_url_parameter]] acs::test::reply_has_status_code $d 200 #ns_log notice CONTENT=[::xowiki::test::get_content $d] acs::test::dom_html root [::xowiki::test::get_content $d] { set id_part F.[string map {: _} $page_name] set input1 [$root selectNodes "//select\[@id='$id_part.date.DD'\]/option\[@value='1'\]"] set input2 [$root selectNodes "//select\[@id='$id_part.date.month'\]/option\[@value='1'\]"] set input3 [$root getElementById $id_part.date.YYYY] aa_true "input1 (1st element of date)" {$input1 ne ""} aa_true "input2 (2nd element of date)" {$input2 ne ""} aa_true "input3 (3rd element of date)" {[$input3 getAttribute value] eq "2022"} foreach v [list $input1 $input2] { if {$v eq ""} continue aa_true "input selected '[$v getAttribute selected]'" {[$v getAttribute selected] eq "selected"} } set input4 [$root getElementById $id_part.date2.YYYY] aa_true "input4 (year element of date2)" {[$input4 getAttribute value] eq "2011"} } set form_name $lang:Repeat.form ########################################################### aa_section "Create form $form_name" ########################################################### # # Create a form with a repeated field. # ::xowiki::test::create_form -last_request $request_info -instance $instance -path $testfolder -parent_id $folder_id -name $form_name -update [subst { title "Repeat Form" nls_language $locale text {<p>@txt@</p>} text.format text/html form {<form>@txt@</form>} form.format text/html form_constraints { _page_order:omit _title:omit _nls_language:omit _description:omit txt:text,repeat=1..5,default=t1 } }] aa_log "Form $form_name created" set page_name $lang:r1 ########################################################### aa_section "Create an instance $page_name of $form_name" ########################################################### ::xowiki::test::create_form_page -last_request $request_info -instance $instance -path $testfolder -parent_id $folder_id -form_name $form_name -update [subst { _name $page_name _title "fresh $page_name" _nls_language $locale }] aa_log "Page $page_name created" set extra_url_parameter {{m edit}} aa_log "Check content of the fresh instance" set d [acs::test::http -last_request $request_info [export_vars -base $instance/$testfolder/$page_name $extra_url_parameter]] acs::test::reply_has_status_code $d 200 set response [dict get $d body] acs::test::dom_html root $response { set f_id [::xowiki::test::get_object_name $root] set CSSclass [::xowiki::test::get_form_CSSclass $root] aa_true "page_name '$f_id' non empty" {$f_id ne ""} aa_true "CSSclass: '$CSSclass' non empty" {$CSSclass ne ""} set id_part F.[string map {: _} $page_name] set input1 [$root getElementById $id_part.txt.1] set input2 [$root getElementById $id_part.txt.2] aa_equals "input1 (1st element of repeated field)" [$input1 getAttribute value] t1 aa_equals "input2 (2nd element of repeated field)" "" "" } ################################################################################ aa_section "Edit an instance $page_name of $form_name to add 2nd repeated field" ################################################################################ ::xowiki::test::edit_form_page -last_request $request_info -instance $instance -path $testfolder/$page_name -update [subst { _title "edited $page_name" txt.2 t2 }] aa_log "Check content of the edited instance" set d [acs::test::http -user_info $user_info [export_vars -base $instance/$testfolder/$page_name $extra_url_parameter]] acs::test::reply_has_status_code $d 200 #ns_log notice CONTENT=[::xowiki::test::get_content $d] acs::test::dom_html root [::xowiki::test::get_content $d] { set id_part F.[string map {: _} $page_name] set input1 [$root getElementById $id_part.txt.1] set input2 [$root getElementById $id_part.txt.2] aa_log "input1 '$input1' input2 '$input2'" aa_equals "input1 (1st element of repeated field)" [$input1 getAttribute value] t1 aa_equals "input2 (2nd element of repeated field)" [$input2 getAttribute value] t2 } set form_name $lang:repeated-compound.form ########################################################### aa_section "Create Form $form_name" ########################################################### # # We now generate a form where a nested compound field is # used as as template for a repeated field. # ::xowiki::test::create_form -last_request $request_info -instance $instance -path $testfolder -parent_id $folder_id -name $form_name -update [subst { title "Repeated Compound Form" nls_language $locale text {<p>@_text@</p><p>@mycompoundwithrepeat@</p>} text.format text/html form {<form>@mycompoundwithrepeat@</form>} form.format text/html form_constraints { _page_order:omit _title:omit _nls_language:omit _description:omit {mycompoundwithrepeat:regression_test_compound_with_repeat,label=The Compound With Repeat} } }] aa_log "Form $form_name created" set page_name $lang:rc1 ########################################################### aa_section "Create an instance of $form_name named '$page_name'" ########################################################### ::xowiki::test::create_form_page -last_request $request_info -instance $instance -path $testfolder -parent_id $folder_id -form_name $form_name -update [subst { _name $page_name _title "fresh $page_name" _nls_language $locale }] aa_log "Page $page_name created" set extra_url_parameter {{m edit}} aa_log "Check content of the fresh instance" set d [acs::test::http -last_request $request_info [export_vars -base $instance/$testfolder/$page_name $extra_url_parameter]] acs::test::reply_has_status_code $d 200 ::xowiki::test::edit_form_page -last_request $request_info -instance $instance -path $testfolder/$page_name -update [subst { _title "edited $page_name" mycompoundwithrepeat.acheckbox X mycompoundwithrepeat.arepeatedcompound.1.anumber 1 mycompoundwithrepeat.arepeatedcompound.1.acheckbox C mycompoundwithrepeat.arepeatedcompound.2.anumber 2 mycompoundwithrepeat.arepeatedcompound.2.acheckbox B mycompoundwithrepeat.arepeatedcompound.3.anumber 3 mycompoundwithrepeat.arepeatedcompound.3.acheckbox A mycompoundwithrepeat.arepeatedcompound.4.anumber 4 }] aa_log "Check content of the edited instance" set d [acs::test::http -user_info $user_info [export_vars -base $instance/$testfolder/$page_name $extra_url_parameter]] acs::test::reply_has_status_code $d 200 set response [dict get $d body] acs::test::dom_html root $response { set f_id [::xowiki::test::get_object_name $root] set CSSclass [::xowiki::test::get_form_CSSclass $root] aa_true "page_name '$f_id' non empty" {$f_id ne ""} aa_true "CSSclass: '$CSSclass' non empty" {$CSSclass ne ""} set id_part [string map {: _} $page_name] set radio1 [$root getElementById F.$id_part.mycompoundwithrepeat.aradio:X] set radio2 [$root getElementById F.$id_part.mycompoundwithrepeat.aradio:Y] set radio3 [$root getElementById F.$id_part.mycompoundwithrepeat.aradio:Z] aa_equals "Radio 'X' not checked" [$radio1 hasAttribute checked] 0 aa_equals "Radio 'Y' not checked" [$radio2 hasAttribute checked] 0 aa_equals "Radio 'Z' not checked" [$radio3 hasAttribute checked] 0 set anumber_3 [$root getElementById F.$id_part.mycompoundwithrepeat.arepeatedcompound.3.anumber] # Note: we check on purpose for math equality, not string equality aa_true "Number in 3rd repeat field is correct" {[$anumber_3 getAttribute value] == 3} set acheckbox_3_a [$root getElementById F.$id_part.mycompoundwithrepeat.arepeatedcompound.3.acheckbox:A] set acheckbox_3_b [$root getElementById F.$id_part.mycompoundwithrepeat.arepeatedcompound.3.acheckbox:B] set acheckbox_3_c [$root getElementById F.$id_part.mycompoundwithrepeat.arepeatedcompound.3.acheckbox:C] aa_equals "Checkbox in 3rd repeat field 'A' checked" [$acheckbox_3_a hasAttribute checked] 1 aa_equals "Checkbox in 3rd repeat field 'B' not checked" [$acheckbox_3_b hasAttribute checked] 0 aa_equals "Checkbox in 3rd repeat field 'C' not checked" [$acheckbox_3_c hasAttribute checked] 0 } ::xowiki::test::edit_form_page -last_request $request_info -instance $instance -path $testfolder/$page_name -update [subst { _title "twice-edited $page_name" mycompoundwithrepeat.arepeatedcompound.3.aselect B }] aa_log "Check content of the twice-edited instance" set d [acs::test::http -user_info $user_info [export_vars -base $instance/$testfolder/$page_name $extra_url_parameter]] acs::test::reply_has_status_code $d 200 set response [dict get $d body] acs::test::dom_html root $response { set f_id [::xowiki::test::get_object_name $root] set CSSclass [::xowiki::test::get_form_CSSclass $root] aa_true "page_name '$f_id' non empty" {$f_id ne ""} aa_true "CSSclass: '$CSSclass' non empty" {$CSSclass ne ""} set id_part [string map {: _} $page_name] set radio1 [$root getElementById F.$id_part.mycompoundwithrepeat.aradio:X] set radio2 [$root getElementById F.$id_part.mycompoundwithrepeat.aradio:Y] set radio3 [$root getElementById F.$id_part.mycompoundwithrepeat.aradio:Z] aa_equals "Radio 'X' not checked" [$radio1 hasAttribute checked] 0 aa_equals "Radio 'Y' not checked" [$radio2 hasAttribute checked] 0 aa_equals "Radio 'Z' not checked" [$radio3 hasAttribute checked] 0 set anumber_3 [$root getElementById F.$id_part.mycompoundwithrepeat.arepeatedcompound.3.anumber] # Note: we check on purpose for math equality, not string equality aa_true "Number in 3rd repeat field is correct" {[$anumber_3 getAttribute value] == 3} set acheckbox_3_a [$root getElementById F.$id_part.mycompoundwithrepeat.arepeatedcompound.3.acheckbox:A] set acheckbox_3_b [$root getElementById F.$id_part.mycompoundwithrepeat.arepeatedcompound.3.acheckbox:B] set acheckbox_3_c [$root getElementById F.$id_part.mycompoundwithrepeat.arepeatedcompound.3.acheckbox:C] aa_equals "Checkbox in 3rd repeat field 'A' checked" [$acheckbox_3_a hasAttribute checked] 1 aa_equals "Checkbox in 3rd repeat field 'B' not checked" [$acheckbox_3_b hasAttribute checked] 0 aa_equals "Checkbox in 3rd repeat field 'C' not checked" [$acheckbox_3_c hasAttribute checked] 0 set aselect_1_selected [$root selectNodes "//select\[@id='F.$id_part.mycompoundwithrepeat.arepeatedcompound.3.aselect'\]/option\[@selected\]"] aa_equals "Select was set to B" [$aselect_1_selected getAttribute value] B } } on error {errorMsg} { aa_true "Error msg: $errorMsg" 0 } finally { # # In case something has to be cleaned manually, do it here. # if {$package_id ne "" && $instance ne ""} { #set node_id [site_node::get_element -url $instance -element node_id] #site_node::delete -node_id $node_id -delete_package } } }} { aa_log "Running testcase body $body_count" set ::__aa_test_indent [info level] set catch_val [catch $testcase_body msg] if {$catch_val != 0 && $catch_val != 2} { aa_log_result "fail" "create_form_with_form_instance (body $body_count): Error during execution: $msg, stack trace: \n$::errorInfo" } incr body_count }XQL Not present: Generic, PostgreSQL, Oracle