Index: openacs-4/packages/forums/forums.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/forums.info,v diff -u -N -r1.55 -r1.56 --- openacs-4/packages/forums/forums.info 24 Jul 2018 12:45:11 -0000 1.55 +++ openacs-4/packages/forums/forums.info 24 Jul 2018 17:19:58 -0000 1.56 @@ -9,7 +9,7 @@ f t - + OpenACS Online discussion forums. 2017-08-06 @@ -19,14 +19,14 @@ 2 #forums.Forums# - + - + Index: openacs-4/packages/forums/tcl/test/forums-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/tcl/test/forums-procs.tcl,v diff -u -N -r1.10 -r1.11 --- openacs-4/packages/forums/tcl/test/forums-procs.tcl 24 Jul 2018 14:37:47 -0000 1.10 +++ openacs-4/packages/forums/tcl/test/forums-procs.tcl 24 Jul 2018 17:19:58 -0000 1.11 @@ -196,8 +196,8 @@ # set name [ad_generate_random_string] set forum_id [forums::test::new -user_id $user_id $name] - - + + } -teardown_code { # # In order to be able to delete the user, we have first to @@ -248,7 +248,7 @@ set response [forums::test::view \ -user_id $user_id \ -forum_id $forum_id ] - + } -teardown_code { # # Delete the forum. @@ -286,13 +286,12 @@ set forum_id [forums::test::new -user_id $user_id $name] # - # Edit the created forum + # Edit the meta info of the created forum # set response [forums::test::edit \ -user_id $user_id \ - -forum_id $forum_id \ - ] - + -forum_id $forum_id ] + } -teardown_code { if {$forum_id != 0} { forum::delete -forum_id $forum_id @@ -303,127 +302,69 @@ aa_register_case \ -cats {web smoke} \ - -libraries tclwebtest \ - -procs {forums::twt::new forums::twt::new_post} \ - web_message_new { - Posting a new message to an existing forum + -procs { + forum::delete + forum::edit + forum::get + forum::message::delete + forum::message::delete + forum::message::edit + forum::message::get + forum::message::new + forum::message::set_state + forum::new + forum::security::require_post_forum + } \ + -urls { + /message-post + /forum-view + /message-view + /message-post + /moderate/message-edit + /moderate/message-delete + } \ + web_forums_message_and_reply { + Do various operations in a longer test: + - create a forum + - add a forums entry + - reply to the forum + - edit the forums entry + - delete the forums entry } { - + set forum_id 0 + set message_id 0 aa_run_with_teardown -test_code { + # + # Create a new admin user + # + set user_info [acs::test::user::create -admin] + set user_id [dict get $user_info user_id] - tclwebtest::cookies clear - - # Login user - array set user_info [twt::user::create -admin] - twt::user::login $user_info(email) $user_info(password) - - # Create a forum + # + # Create a new forum + # set name [ad_generate_random_string] - forums::twt::new "$name" + set forum_id [forums::test::new -user_id $user_id $name] # Post a message in the created forum - set subject [ad_generate_random_string] - set response [forums::twt::new_post "$name" "$subject"] - aa_display_result -response $response -explanation {Webtest for posting a message in a forum} + set message_id [forums::test::new_postings \ + -user_id $user_id \ + -forum_id $forum_id ] - twt::user::logout - } -} -aa_register_case \ - -cats {web smoke} \ - -libraries tclwebtest \ - -procs {forums::twt::new_post forums::twt::new_post forums::twt::edit_post} \ - web_message_edit { - Editing a message of a forum -} { - - aa_run_with_teardown -test_code { - - tclwebtest::cookies clear - - # Login user - array set user_info [twt::user::create -admin] - twt::user::login $user_info(email) $user_info(password) - - # Create a forum - set name [ad_generate_random_string] - forums::twt::new "$name" - - # Post a message in the created forum - set subject [ad_generate_random_string] - forums::twt::new_post "$name" "$subject" - - # Edit the posted message - set response [forums::twt::edit_post "$name" "$subject"] - aa_display_result -response $response -explanation {Webtest for editing the message of a forum} - - twt::user::logout + } -teardown_code { + if {$message_id != 0} { + forum::message::delete -message_id $message_id + } + if {$forum_id != 0} { + forum::delete -forum_id $forum_id + } + acs::test::user::delete -user_id [dict get $user_info user_id] } } -aa_register_case \ - -cats {web smoke} \ - -libraries tclwebtest \ - -procs {forums::twt::new forums::twt::new_post forums::twt::reply_msg} \ - web_message_reply { - Post a reply a message in the forum -} { - aa_run_with_teardown -test_code { - tclwebtest::cookies clear - - # Login user - array set user_info [twt::user::create -admin] - twt::user::login $user_info(email) $user_info(password) - - # Create a forum - set name [ad_generate_random_string] - forums::twt::new "$name" - - # Post a message in the created forum - set subject [ad_generate_random_string] - forums::twt::new_post "$name" "$subject" - - # Edit the posted message - set response [forums::twt::reply_msg "$name" "$subject"] - aa_display_result -response $response -explanation {Webtest for posting a reply to a msg in the forum} - - twt::user::logout - } -} - -aa_register_case \ - -cats {web smoke} \ - -libraries tclwebtest \ - -procs {forums::twt::new forums::twt::new_post forums::twt::delete_post} \ - web_message_delete { - Delete a message in the forum -} { - aa_run_with_teardown -test_code { - - tclwebtest::cookies clear - - # Login user - array set user_info [twt::user::create -admin] - twt::user::login $user_info(email) $user_info(password) - - # Create a forum - set name [ad_generate_random_string] - forums::twt::new "$name" - - # Post a message in the created forum - set subject [ad_generate_random_string] - forums::twt::new_post "$name" "$subject" - - # Edit the posted message - set response [forums::twt::delete_post "$name" "$subject"] - aa_display_result -response $response -explanation {Webtest for deleting a message posted in the forum} - - twt::user::logout - } -} # Local variables: # mode: tcl # tcl-indent-level: 4 Index: openacs-4/packages/forums/tcl/test/tclwebtest-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/tcl/test/Attic/tclwebtest-procs.tcl,v diff -u -N --- openacs-4/packages/forums/tcl/test/tclwebtest-procs.tcl 23 Jul 2018 18:21:07 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,290 +0,0 @@ -ad_library { - Automated tests. - @author Gerardo Morales (gerardo.morales@gmail.net) - @author Mounir Lallali - - @creation-date 14 June 2005 - -} - -namespace eval forums::twt { - - ad_proc new { name } { - Create a new forum from the UI. - } { - - set response 0 - - # The Forum Admin page url - set forum_admin_page [aa_get_first_url -package_key forums] - ::twt::do_request $forum_admin_page - - # Seting the charter that would be used in the forum creation form - set charter "[ad_generate_random_string] [ad_generate_random_string]" - - # Follows the link of New Forum - tclwebtest::link follow "New Forum" - tclwebtest::form find ~n "forum" - tclwebtest::field find ~n "name" - tclwebtest::field fill "$name" - tclwebtest::field find ~n "charter" - tclwebtest::field fill "$charter" - tclwebtest::form submit - aa_log "Forum $name just to be created" - - set response_url [tclwebtest::response url] - aa_log $forum_admin_page - - if {[string first $forum_admin_page $response_url]!=-1} { - - if { [catch {tclwebtest::link find $name} testerror1] ||[catch {tclwebtest::assert text $charter} testerror2 ] } { - aa_error "The forum $name was not created. The forum name or the charter was not founded in the admin page of forums" - } else { - aa_log "The forum $name was successfully created" - set response 1 - } - - } else { - aa_error "forums::twt::new failed, bad response url : $response_url" - } - - return $response - } - - ad_proc edit { name } { - Edit a forum from the UI. - } { - - set response 0 - - # Call to the forum admin page - set forum_admin_page [aa_get_first_url -package_key forums] - ::twt::do_request $forum_admin_page - - # Follows the link of administration and then admin the forum - tclwebtest::link follow $name - tclwebtest::link follow "Administer" - aa_log "The data of the $name forum will be changed" - - set charter "[ad_generate_random_string] [ad_generate_random_string 8]" - - # Enter the new data and submit - tclwebtest::form find ~n "forum" - tclwebtest::field find ~n "name" - tclwebtest::field fill "Edited $name" - tclwebtest::field find ~n "charter" - tclwebtest::field fill "Edited $charter" - tclwebtest::form submit - aa_log "Form Submited" - - # Testing the edition - set response_url [tclwebtest::response url] - - if {[string first "forum-view" $response_url]!=-1 && [string first $forum_admin_page $response_url]!=-1 } { - - ::twt::do_request $forum_admin_page - - if { [catch {tclwebtest::link find "Edited $name"} testerror1] ||[catch {tclwebtest::assert text "$charter"} testerror2 ] } { - aa_error "The forum $name was not Edited. The forum name or the charter was not founded in the admin page of forums" - } else { - aa_log "The forum $name was successfully edited, new name Edited $name" - set response 1 - } - - } else { - aa_error "forums::twt::edit failed, bad response url : $response_url" - } - - return $response - } - - ad_proc new_post {name subject} { - Post a message from the UI. - } { - - set response 0 - # Seting the Subject and Body of the new post - set msgb "[ad_generate_random_string] [ad_generate_random_string 20]" - - # Call to the forum admin page - set forum_admin_page [aa_get_first_url -package_key forums] - ::twt::do_request $forum_admin_page - - # Follows the link of administration and then the Post a new message - tclwebtest::link follow $name - tclwebtest::link follow "Post a New Message" - - # Enter the data and submit - tclwebtest::form find ~n "message" - tclwebtest::field find ~n "subject" - tclwebtest::field fill "$subject" - tclwebtest::field find ~n "message_body" - tclwebtest::field fill "$msgb" - tclwebtest::form submit - aa_log "New message form submited" - - set response_url [tclwebtest::response url] - - if {[string first "message-view" $response_url]!=-1 && [string first $forum_admin_page $response_url]!=-1 } { - - tclwebtest::link follow "$name" - - # Testing the message - if {[catch {tclwebtest::link follow "$subject"}]} { - aa_error "The messaje was not posted" - } - - if { [catch {tclwebtest::assert text "$msgb"} testerror2 ] } { - aa_error "The body of the message was not correctly posted" - } else { - aa_log "The message was successfully posted" - set response 1 - } - - } else { - aa_error "forums::twt::new_post failed, bad response url : $response_url" - } - - return $response - } - - ad_proc edit_post {name subject} { - Edit a post from the UI - } { - - set response 0 - - # Seting the new body of the message - set msgb2 "[ad_generate_random_string] [ad_generate_random_string 20]" - - # Call to the forum admin page - set forum_admin_page [aa_get_first_url -package_key forums] - ::twt::do_request $forum_admin_page - - - # Follows the link of administration and then Edit the posted message - tclwebtest::link follow $name - tclwebtest::link follow $subject - tclwebtest::link follow Edit - - # Fill and submit the form for editing - tclwebtest::form find ~n "message" - tclwebtest::field find ~n "subject" - tclwebtest::field fill "Edited $subject" - tclwebtest::field find ~n "message_body" - tclwebtest::field fill "$msgb2" - tclwebtest::form submit - aa_log "Edit message form submited" - - set response_url [tclwebtest::response url] - - if {[string first "message-view" $response_url]!=-1 && [string first $forum_admin_page $response_url]!=-1 } { - - # Testing if the new text is in the message - if {[catch {tclwebtest::link follow "Edited $subject"}]} { - aa_error "The messaje was not edited" - } - - if { [catch {tclwebtest::assert text "$msgb2"} testerror2 ] } { - aa_error "The body of the message was not correctly edited" - } else { - aa_log "The message $subject of the forum $name was successfully edited" - set response 1 - } - - } else { - aa_error "forums::twt::edit_post failed, bad response url : $response_url" - } - - return $response - } - - ad_proc delete_post {name subject} { - Delete a post from the UI. - } { - - set response 0 - # Call to the forum admin page - set forum_admin_page [aa_get_first_url -package_key forums] - ::twt::do_request $forum_admin_page - - # Follows the link of administration and then Edit the posted message - tclwebtest::link follow $name - tclwebtest::link follow $subject - tclwebtest::link follow Delete - tclwebtest::link follow Yes - - set response_url [tclwebtest::response url] - - # Testing if the message is not in the forum - if {[string first "forum-view" $response_url]!=-1 && [string first $forum_admin_page $response_url]!=-1 } { - - if {[catch {tclwebtest::link follow "Edited $subject"}]} { - aa_log "The message $subject was successfully deleted in the forum $name" - set response 1 - } else { - aa_error "The message $subject of the forum $name was not deleted" - } - - } else { - aa_error "forums::twt::delete_post failed, bad response url : $response_url" - } - - return $response - } - - ad_proc reply_msg {name subject} { - Post a reply from the UI. - } { - - set response 0 - - # Seting the new body of the message - set msgb_reply "[ad_generate_random_string] [ad_generate_random_string 20]" - - # Call to the forum admin page - set forum_admin_page [aa_get_first_url -package_key forums] - ::twt::do_request $forum_admin_page - - - # Follows the link of administration and then Edit the posted message - tclwebtest::link follow $name - tclwebtest::link follow $subject - tclwebtest::link follow "Post a Reply" - - # Fill and submit the form for editing - tclwebtest::form find ~n "message" - tclwebtest::field find ~n "message_body" - tclwebtest::field fill "$msgb_reply" - tclwebtest::form submit - aa_log "Reply message submitted" - - set response_url [tclwebtest::response url] - - # Testing if the new text is in the message - if {[string first "message-view" $response_url]!=-1 && [string first $forum_admin_page $response_url]!=-1 } { - - if {[catch {tclwebtest::link find "Re: $subject"}]} { - aa_error "The reply message was not posted" - } - - if { [catch {tclwebtest::assert text "$msgb_reply"} testerror2 ] } { - aa_error "The body of the replyed message was not correctly posted" - } else { - aa_log "The reply message to $subject of the forum $name was successfully posted" - set response 1 - } - - } else { - aa_error "forums::twt::reply_msg failed, bad response url : $response_url" - } - - return $response - } - -} -# Local variables: -# mode: tcl -# tcl-indent-level: 4 -# indent-tabs-mode: nil -# End: Index: openacs-4/packages/forums/tcl/test/webtest-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/tcl/test/webtest-procs.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/forums/tcl/test/webtest-procs.tcl 24 Jul 2018 12:45:11 -0000 1.1 +++ openacs-4/packages/forums/tcl/test/webtest-procs.tcl 24 Jul 2018 17:19:58 -0000 1.2 @@ -13,46 +13,46 @@ {-user_id 0} name } { - Create a new forum via the web interface. + Create a new forum via the web interface. } { # Get the forums admin page url - # + # set forums_page [aa_get_first_url -package_key forums] - # - # Get Data and check status code - # - set d [acs::test::http -user_id $user_id $forums_page/admin/forum-new] - aa_equals "Status code valid" [dict get $d status] 200 + # + # Get Data and check status code + # + set d [acs::test::http -user_id $user_id $forums_page/admin/forum-new] + aa_equals "Status code valid" [dict get $d status] 200 - # - # Get the form specific data (action, method and provided form-fields) - # - set form_data [::acs::test::get_form [dict get $d body] {//form[@id="forum"]}] - - # - # Fill in a few values into the form - # - set d [::acs::test::form_reply \ - -user_id $user_id \ - -url [dict get $form_data @action] \ - -update [subst { - name "$name" - charter "bla [ad_generate_random_string] bla [ad_generate_random_string]" - charter.format text/plain - presentation_type $presentation_type - posting_policy $posting_policy - }] \ - [dict get $form_data fields]] - set reply [dict get $d body] + # + # Get the form specific data (action, method and provided form-fields) + # + set form_data [::acs::test::get_form [dict get $d body] {//form[@id="forum"]}] - # - # Check, if the form was correctly validated. - # - aa_false "Reply contains form-error" [string match *form-error* $reply] - aa_equals "Status code valid" [dict get $d status] 302 + # + # Fill in a few values into the form + # + set d [::acs::test::form_reply \ + -user_id $user_id \ + -url [dict get $form_data @action] \ + -update [subst { + name "$name" + charter "bla [ad_generate_random_string] bla [ad_generate_random_string]" + charter.format text/plain + presentation_type $presentation_type + posting_policy $posting_policy + }] \ + [dict get $form_data fields]] + set reply [dict get $d body] + # + # Check, if the form was correctly validated. + # + acs::test::reply_contains_no $d form-error + aa_equals "Status code valid" [dict get $d status] 302 + return [dict get $form_data fields forum_id] } @@ -61,7 +61,7 @@ {-forum_id 0} {-name ""} } { - View a forum via the web interface. + View a forum via the web interface. } { set forums_page [aa_get_first_url -package_key forums] @@ -71,7 +71,7 @@ # set d [::acs::test::http -user_id $user_id $forums_page] aa_equals "Status code valid" [dict get $d status] 200 - + # # Follow the link with the provided link label # @@ -95,12 +95,12 @@ } return $d } - + ad_proc -private edit { {-user_id 0} {-forum_id 0} } { - Edit a forum via the web interface. + Edit a forum via the web interface. } { set forums_page [aa_get_first_url -package_key forums] @@ -109,35 +109,170 @@ $forums_page/admin/forum-edit?forum_id=$forum_id] aa_equals "Status code valid" [dict get $d status] 200 - # - # Get the form specific data (action, method and provided form-fields) - # - set form_data [::acs::test::get_form [dict get $d body] {//form[@id="forum"]}] + # + # Get the form specific data (action, method and provided form-fields) + # + set form_data [::acs::test::get_form [dict get $d body] {//form[@id="forum"]}] - # - # Fill in a few values into the form - # + # + # Fill in a few values into the form + # set old_name [dict get $form_data fields name] set old_charter [dict get $form_data fields name] set new_name "Edited $old_name" set new_charter "Edited $old_charter" - set d [::acs::test::form_reply \ - -user_id $user_id \ - -url [dict get $form_data @action] \ - -update [subst { - name "$new_name" - charter "$new_charter" - }] \ - [dict get $form_data fields]] - set reply [dict get $d body] - aa_false "Reply contains form-error" [string match *form-error* $reply] - if {[string match *form-error* $reply]} { - #set F [open $::acs::rootdir/packages/forums/www/REPLY.html w]; puts $F [dict get $d body]; close $F - } else { + set d [::acs::test::form_reply \ + -user_id $user_id \ + -url [dict get $form_data @action] \ + -update [subst { + name "$new_name" + charter "$new_charter" + }] \ + [dict get $form_data fields]] + + if {[acs::test::reply_contains_no $d form-error]} { set d [acs::test::http -user_id $user_id $forums_page] - aa_true "Overview page contains edited name '$new_name'" [string match *$new_name* [dict get $d body]] - aa_true "Overview page contains edited charter" [string match *$new_charter* [dict get $d body]] + acs::test::reply_contains -prefix "Overview page" $d $new_name + acs::test::reply_contains -prefix "Overview page" $d $new_charter } } + ad_proc -private new_postings { + {-user_id 0} + {-forum_id 0} + } { + Add a posting to the provided forum via the web interface. + + @return message_id + } { + set message_id 0 + set forums_page [aa_get_first_url -package_key forums] + + set d [acs::test::http \ + -user_id $user_id \ + $forums_page/message-post?forum_id=$forum_id] + aa_equals "Edit Message: Status code valid" [dict get $d status] 200 + + # + # Get form data from + # + set form_data [::acs::test::get_form [dict get $d body] {//form[@id="message"]}] + aa_true "Found form on reply page" {[llength $form_data] > 0} + + # + # Build reply + # + set subject "subject [ad_generate_random_string]" + set message_body "body [ad_generate_random_string 20]" + + set d [::acs::test::form_reply \ + -user_id $user_id \ + -url [dict get $form_data @action] \ + -update [subst { + subject "$subject" + message_body "$message_body" + message_body.format text/plain + }] \ + [dict get $form_data fields]] + + acs::test::reply_contains_no $d form-error + aa_equals "Updated message: Status code valid" [dict get $d status] 302 + + aa_log [dict get $form_data fields] + set message_id [dict get $form_data fields message_id] + + # + # Check on the forums overview page, if we find the new subject + # + set d [acs::test::http -user_id $user_id $forums_page/forum-view?forum_id=$forum_id] + aa_equals "View Forum: Status code valid" [dict get $d status] 200 + + acs::test::reply_contains $d $subject + + # + # Check on the forums view page, if we find the new subject and the new body + # + set d [acs::test::http -user_id $user_id $forums_page/message-view?message_id=$message_id] + aa_equals "View Message: Status code valid" [dict get $d status] 200 + + acs::test::reply_contains $d $subject + acs::test::reply_contains $d $message_body + + # + # Post a reply to the last message + # + set d [acs::test::http -user_id $user_id $forums_page/message-post?parent_id=$message_id] + set form_data [::acs::test::get_form [dict get $d body] {//form[@id="message"]}] + aa_true "Found form on edit page for posting reply" {[llength $form_data] > 0} + set reply_message_id [dict get $form_data fields message_id] + + set d [::acs::test::form_reply \ + -user_id $user_id \ + -url [dict get $form_data @action] \ + -update [subst { + message_body "REPLY $message_body" + message_body.format text/plain + }] \ + [dict get $form_data fields]] + acs::test::reply_contains_no $d form-error + aa_equals "Entered forums reply: Status code valid" [dict get $d status] 302 + + # + # The reply should show up on the forums thread page + # + set d [acs::test::http -user_id $user_id $forums_page/message-view?message_id=$message_id] + aa_equals "Message overview: Status code valid" [dict get $d status] 200 + acs::test::reply_contains $d "REPLY $message_body" + + # + # Edit the reply + # + set d [acs::test::http -user_id $user_id $forums_page/moderate/message-edit?message_id=$reply_message_id] + set form_data [::acs::test::get_form [dict get $d body] {//form[@id="message"]}] + aa_true "Found form on edit page for editing reply" {[llength $form_data] > 0} + set old_reply_message_body [dict get $form_data fields message_body] + set new_reply_message_body "$old_reply_message_body EDITED" + aa_true "old message_body contains REPLY" [string match "*REPLY*" $old_reply_message_body] + + set d [::acs::test::form_reply \ + -user_id $user_id \ + -url [dict get $form_data @action] \ + -update [subst { + message_body "$new_reply_message_body" + }] \ + [dict get $form_data fields]] + acs::test::reply_contains_no $d form-error + aa_equals "Entered forums reply: Status code valid" [dict get $d status] 302 + + # + # The edited reply should show up on the forums thread page + # + set d [acs::test::http -user_id $user_id $forums_page/message-view?message_id=$message_id] + aa_equals "Message overview: Status code valid" [dict get $d status] 200 + acs::test::reply_contains $d "$new_reply_message_body" + + # + # Delete the reply + # + set d [acs::test::http -user_id $user_id $forums_page/moderate/message-delete?message_id=$reply_message_id] + aa_equals "Message overview: Status code valid" [dict get $d status] 200 + acs::test::reply_contains $d message-delete?confirm_p + + set d [::acs::test::follow_link \ + -user_id $user_id \ + -base $forums_page/moderate \ + -label Yes \ + -html [dict get $d body]] + aa_equals "Message overview: Status code valid" [dict get $d status] 302 + + # + # The edited reply should no show up up on the forums thread page + # + set d [acs::test::http -user_id $user_id $forums_page/message-view?message_id=$message_id] + aa_equals "Message overview: Status code valid" [dict get $d status] 200 + acs::test::reply_contains_no $d "$new_reply_message_body" + + return $message_id + } + }