Index: openacs-4/packages/file-storage/tcl/test/file-storage-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/test/file-storage-procs.tcl,v diff -u -r1.10.2.5 -r1.10.2.6 --- openacs-4/packages/file-storage/tcl/test/file-storage-procs.tcl 11 Mar 2021 18:09:20 -0000 1.10.2.5 +++ openacs-4/packages/file-storage/tcl/test/file-storage-procs.tcl 30 Mar 2021 11:19:39 -0000 1.10.2.6 @@ -147,7 +147,7 @@ file_storage::twt::add_file_to_folder file_storage::twt::delete_file } \ - fs_add_file_to_folder { + fs_add_file_to_folder_twt { Test Upload a File in a Folder. @@ -354,6 +354,55 @@ } } +aa_register_case \ + -cats {web smoke} \ + -procs { + aa_display_result + file_storage::test::call_fs_page + file_storage::test::create_new_folder + file_storage::test::add_file_to_folder + #file_storage::test::delete_file + } \ + fs_add_file_to_folder { + + Test Upload a File in a Folder. + + @author Mounir Lallali +} { + aa_run_with_teardown -test_code { + # + # Setup of test user_id and login + # + set user_info [::acs::test::user::create -admin] + aa_log "user_info = $user_info" + set request_info [::acs::test::login $user_info] + + set d [file_storage::test::call_fs_page -last_request $request_info] + aa_log "call_fs_page done" + + # Create a new folder + set folder_name [ad_generate_random_string] + set folder_description [ad_generate_random_string] + file_storage::test::create_new_folder -last_request $d $folder_name $folder_description + aa_log "new folder created" + + # Add a file to folder + set uploaded_file_name [file_storage::test::create_file [ad_generate_random_string]] + set uploaded_file_description [ad_generate_random_string] + set d [file_storage::test::add_file_to_folder \ + -last_request $d \ + $folder_name \ + $uploaded_file_name \ + $uploaded_file_description] + + #aa_display_result -response $response -explanation {for uploadding a file in a folder} + aa_log "now delete file again" + file_storage::test::delete_first_file -last_request $d $uploaded_file_name + ::acs::test::logout -last_request $d + } +} + + # Local variables: # mode: tcl # tcl-indent-level: 4 Index: openacs-4/packages/file-storage/tcl/test/tclwebtest-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/test/tclwebtest-procs.tcl,v diff -u -r1.9.2.3 -r1.9.2.4 --- openacs-4/packages/file-storage/tcl/test/tclwebtest-procs.tcl 7 Oct 2020 15:57:13 -0000 1.9.2.3 +++ openacs-4/packages/file-storage/tcl/test/tclwebtest-procs.tcl 30 Mar 2021 11:19:39 -0000 1.9.2.4 @@ -15,16 +15,6 @@ ::twt::do_request $fs_page } -ad_proc -private file_storage::twt::create_file { f_name } { - Creates a temporary file. -} { - # Create a temporary file - set file_name "[ad_tmpdir]/$f_name.txt" - exec touch $file_name - exec ls / >> $file_name - exec chmod 777 $file_name - return $file_name -} ad_proc -private file_storage::twt::delete_file { file_name } { Deletes a file. Index: openacs-4/packages/file-storage/tcl/test/webtest-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/test/webtest-procs.tcl,v diff -u -r1.1.2.6 -r1.1.2.7 --- openacs-4/packages/file-storage/tcl/test/webtest-procs.tcl 26 Feb 2021 19:18:24 -0000 1.1.2.6 +++ openacs-4/packages/file-storage/tcl/test/webtest-procs.tcl 30 Mar 2021 11:19:39 -0000 1.1.2.7 @@ -79,6 +79,74 @@ return $d } + ad_proc -private ::file_storage::test::add_file_to_folder { + -last_request:required + folder_name + file_name + file_description + } { + Adds a file to a folder from the UI. + } { + set d [acs::test::follow_link -last_request $last_request -label {Add File}] + #acs::test::reply_has_status_code $d 200 + # + # "Add File" links to a redirect page file-upload-confirm... + # + acs::test::reply_has_status_code $d 302 + set location [::acs::test::get_url_from_location $d] + set d [acs::test::http -last_request $d $location] + + set response [dict get $d body] + set form [acs::test::get_form $response {//form[@id='file-add']}] + + aa_true "add form was returned" {[llength $form] > 2} + set d [::acs::test::form_reply \ + -last_request $d \ + -form $form \ + -update [subst { + upload_file $file_name + upload_file.tmpfile $file_name + title $file_name + description $file_description + }]] + acs::test::reply_has_status_code $d 302 + set location [::acs::test::get_url_from_location $d] + + if { [string match "*\?folder*id*" $location] } { + aa_log "location contains folder*id" + set list_words [split $file_name /] + set short_file_name [lindex $list_words end] + + set d [acs::test::http -last_request $d $location] + acs::test::reply_contains $d $folder_name + } else { + aa_error "file_storage::test::add_file_to_folder failed, bad response url : $response_url" + } + + return $d + } + + ad_proc -private ::file_storage::test::delete_first_file { + -last_request:required + file_name + } { + Delete the current file via Web UI. + } { + + # + # Delete the first displayed file (current rather crude, failure must + # me detectable from return code). + # + set href [acs::test::find_link -last_request $last_request -label {New}] + aa_log "Download link $href" + + regsub -all /file-add $href /delete href + set d [acs::test::http -last_request $last_request $href] + + return $d + } + + ad_proc -private ::file_storage::test::delete_current_folder { -last_request:required } { @@ -96,6 +164,24 @@ acs::test::reply_has_status_code $d 302 return $d } + + ad_proc -private ::file_storage::test::call_fs_page {-last_request} { + Requests the file-storage page. + } { + set fs_page [aa_get_first_url -package_key file-storage] + return [::acs::test::http -last_request $last_request $fs_page] + } + + ad_proc -private ::file_storage::test::create_file { f_name } { + Creates a temporary file. + } { + # Create a temporary file + set file_name "[ad_tmpdir]/$f_name.txt" + exec touch $file_name + exec ls / >> $file_name + exec chmod 777 $file_name + return $file_name + } } # Local variables: