_acs-content-repository__content_item (private)

 _acs-content-repository__content_item

Defined in packages/acs-content-repository/tcl/test/content-item-test-procs.tcl

Partial Call Graph (max 5 caller/called nodes):
%3 aa_equals aa_equals (public) aa_false aa_false (public) aa_log aa_log (public) aa_log_result aa_log_result (public) aa_run_with_teardown aa_run_with_teardown (public) _acs-content-repository__content_item _acs-content-repository__content_item _acs-content-repository__content_item->aa_equals _acs-content-repository__content_item->aa_false _acs-content-repository__content_item->aa_log _acs-content-repository__content_item->aa_log_result _acs-content-repository__content_item->aa_run_with_teardown

Testcases:
No testcase defined.
Source code:
        
        set _aa_export {}
        set body_count 1
        foreach testcase_body {{

    aa_run_with_teardown  -rollback  -test_code {

            #########################################################
            # create a cr_folder
            #########################################################
            set first_folder_label [ad_generate_random_string]
            set first_folder_id [db_nextval "acs_object_id_seq"]
            set returned_first_folder_id [content::folder::new  -folder_id $first_folder_id  -label $first_folder_label  -name "test_folder_${first_folder_id}"]

            set root_folder_id [content::item::get_root_folder -item_id $first_folder_id]
            aa_true "Folder $first_folder_id is distinct from root folder $root_folder_id"  {$root_folder_id != $first_folder_id}
            aa_true "Folder $root_folder_id is a root folder"  [content::folder::is_root -folder_id $root_folder_id]


            aa_false "Folder $first_folder_id is not a root folder"  [content::folder::is_root -folder_id $first_folder_id]

            aa_false "'content_revision' is not registered on the folder"  [content::folder::is_registered  -folder_id $first_folder_id  -content_type content_revision]

            content::folder::register_content_type  -folder_id $first_folder_id  -content_type "content_revision"

            aa_true "'content_revision' is now registered on the folder"  [content::folder::is_registered  -folder_id $first_folder_id  -content_type content_revision]

            aa_true "Folder created" {$first_folder_id == $returned_first_folder_id}

            aa_true "Folder is a folder" [content::folder::is_folder -item_id $first_folder_id]

            aa_equals "Folder has the right label"  $first_folder_label [content::folder::get_label -folder_id $first_folder_id]

            set is_empty [content::folder::is_empty -folder_id $first_folder_id]
            aa_true "Folder is empty" [string is true $is_empty]

            #########################################################
            # create another cr_folder
            #########################################################

            set second_folder_id [db_nextval  "acs_object_id_seq"]
            set returned_second_folder_id [content::folder::new  -folder_id $second_folder_id  -name "test_folder_${second_folder_id}"]
            aa_true "Folder 2 created" {$second_folder_id == $returned_second_folder_id}


            #########################################################
            # create a cr_item
            #########################################################

            set test_name "cr_test_item[ad_generate_random_string]"
            set first_item_id [db_nextval  "acs_object_id_seq"]
            set returned_first_item_id [content::item::new  -name "$test_name"  -item_id $first_item_id  -parent_id $first_folder_id  -is_live "t"  -attributes [list [list title "$test_name"]]
                                       ]

            aa_true "First item created" {$first_item_id == $returned_first_item_id}

            set content_type [content::item::get_content_type -item_id $first_item_id]
            aa_true "content_type is '$content_type'" {$content_type eq "content_revision"}

            aa_false "First item is not a folder" [content::folder::is_folder -item_id $first_item_id]

            aa_true "first item exists" {[content::item::get -item_id $first_item_id] == 1}

            content::item::get -item_id $first_item_id -array item_info
            set revision_id [dict get [array get item_info] revision_id]

            aa_equals "content_revision is latest"  [content::revision::is_latest -revision_id $revision_id]  t
            aa_equals "content_revision is live"  [content::revision::is_live -revision_id $revision_id]  t

            aa_true "First item's revision exists"  {[db_string get_revision {
                    select latest_revision from cr_items, cr_revisions
                    where latest_revision=revision_id and cr_items.item_id = :first_item_id
                } -default ""] ne ""}

            # check the folder is not empty now.
            set is_empty [content::folder::is_empty -folder_id $first_folder_id]
            aa_true "Folder 1 is not empty" [string is false $is_empty]

            #########################################################
            # create an index cr_item
            #########################################################

            set index_item_id [content::item::new  -name index  -parent_id $first_folder_id  -is_live "t"  -attributes [list [list title "$test_name"]]]

            aa_equals "Items $index_item_id is index in a folder $first_folder_id"  $index_item_id [content::folder::get_index_page -folder_id $first_folder_id]

            aa_false "Item $index_item_id is not null"  [content::item::content_is_null [db_string rev {
                    select live_revision from cr_items
                    where item_id = :index_item_id
                }]]

            #########################################################
            # create an empty cr_item
            #########################################################

            set empty_item_id [content::item::new  -name emptyboi  -parent_id $first_folder_id  -is_live "t"]

            aa_false "Empty item $empty_item_id has no revision"  [db_0or1row rev {
                    select revision_id from cr_revisions
                    where item_id = :empty_item_id
                }]

            set empty_item_id [content::item::new  -name emptyboi2  -parent_id $first_folder_id  -is_live "t"  -text "I will be empty"]

            aa_false "Empty item $empty_item_id is not null before emptying"  [content::item::content_is_null [db_string rev {
                    select live_revision from cr_items
                    where item_id = :empty_item_id
                }]]

            db_dml empty_the_boi {
                update cr_revisions set
                content = null
                where item_id = :empty_item_id
            }

            aa_true "Empty item $empty_item_id is now null"  [content::item::content_is_null [db_string rev {
                    select live_revision from cr_items
                    where item_id = :empty_item_id
                }]]

            #########################################################
            # create a cr_item with evil string
            #########################################################

            set evil_string {-Bad [BAD] \077 \{ $Bad }
            set evil_test_name  "${evil_string}cr_test_item[ad_generate_random_string]"
            aa_log "evil_test_name is $evil_test_name"
            set evil_item_id [db_nextval  "acs_object_id_seq"]
            set returned_evil_item_id [content::item::new  -name "${evil_test_name}"  -item_id $evil_item_id  -parent_id $first_folder_id  -attributes [list [list title "${evil_test_name}"]]
                                       ]

            aa_true "Evil_name item created" {$evil_item_id == $returned_evil_item_id}

            aa_true "Evil_name item exists" {[content::item::get  -item_id $evil_item_id  -revision latest  -array_name evil_name] == 1}
            aa_true "Evil_name item's revision exists"  {$evil_name(latest_revision) ne ""}

            #########################################################
            # delete the evil_name item
            #########################################################

            # in oracle content_item.del is not a function and cannot
            # return true or false so we have to rely on a query to
            # see if the item exists or not

            content::item::delete -item_id $evil_item_id
            array unset evil_name
            aa_true "evil_name item no longer exists" {
                [content::item::get  -item_id $evil_item_id  -revision "latest"  -array_name evil_name] == 0}
            aa_true "evil_name item revision does not exist" {![info exists evil(latest_revision)]}


            #########################################################
            # create a new content type
            #########################################################

            catch {content::type::delete -content_type "test_type"} errmsg
            set new_type_id [content::type::new  -content_type "test_type"  -pretty_name "test_type"  -pretty_plural "test_type"  -table_name "test_type"  -id_column "test_id"]


            #########################################################
            # create an attribute
            #########################################################
            content::type::attribute::new  -content_type "test_type"  -attribute_name "attribute_name"  -datatype "text"  -pretty_name "Attribute Name"  -pretty_plural "Attribute Names"  -column_spec "text"

            # todo test that new item is NOT allowed to be created
            # unless registered by catching error when creating new
            # item

            #########################################################
            # register new type to folder
            #########################################################

            content::folder::register_content_type  -folder_id $first_folder_id  -content_type "test_type"
            # create an item of that type
            set new_type_item_id [db_nextval  "acs_object_id_seq"]
            set returned_new_type_item_id [content::item::new  -name "test_item_${new_type_item_id}"  -item_id $new_type_item_id  -parent_id $first_folder_id  -is_live "t"  -content_type  "test_type"  -attributes [list [list title "Title"] [list attribute_name "attribute_value"]]]

            #########################################################
            # check that the item exists
            #########################################################

            aa_true "New Type item created" {$new_type_item_id == $returned_new_type_item_id}
            aa_true "New Type item exists" {[content::item::get  -item_id $new_type_item_id  -revision "latest"  -array_name new_type_item] == 1}

            #########################################################
            # check that extended attribute exists
            #########################################################
            aa_equals "Extended attribute set" "attribute_value" $new_type_item(attribute_name)


            set content_type [content::item::get_content_type -item_id $new_type_item_id]
            aa_true "content_type is '$content_type" {$content_type eq "test_type"}

            #########################################################
            # test update of item and attributes
            #########################################################
            content::item::update  -item_id $new_type_item_id  -attributes {{name new_name} {publish_status live}}
            array unset new_type_item
            content::item::get  -item_id $new_type_item_id  -revision "latest"  -array_name new_type_item
            aa_true "Item updated $new_type_item(name) $new_type_item(publish_status)"  {$new_type_item(name) eq "new_name" && $new_type_item(publish_status) eq "live"}

            #########################################################
            # copy it
            #########################################################
            aa_equals "Item cannot be copied in the same folder using the same name"  [content::item::copy  -item_id $new_type_item_id  -target_folder_id $first_folder_id""

            aa_equals "Item cannot be copied in another folder without registering its content type first"  [content::item::copy  -item_id $new_type_item_id  -target_folder_id $second_folder_id""

            aa_log "Registering content type '$content_type' for '$second_folder_id'"
            content::folder::register_content_type  -folder_id $second_folder_id  -content_type $content_type

            set copied_no_sibling_item_id [content::item::copy  -item_id $new_type_item_id  -target_folder_id $second_folder_id]
            aa_true "Item can be copied in another folder using the same name after content type registration"  [string is integer -strict $copied_no_sibling_item_id]

            content::item::get  -item_id $copied_no_sibling_item_id  -array_name copied_no_sibling_item
            foreach att {name attribute_name} value {new_name attribute_value} {
                aa_equals "Copied item '$copied_no_sibling_item_id' has the right $att"  $copied_no_sibling_item($att) $value
            }
            aa_equals "Copied item '$copied_no_sibling_item_id' has an empty title. This is expected"  $copied_no_sibling_item(title) ""


            aa_log "Cleanup the copy so we can test the no cascade cleanup later"
            content::item::delete -item_id $copied_no_sibling_item_id

            set copied_sibling_item_id [content::item::copy  -item_id $new_type_item_id  -target_folder_id $first_folder_id  -name copied_name]

            content::item::get  -item_id $copied_sibling_item_id  -array_name copied_sibling_item
            foreach att {name attribute_name} value {copied_name attribute_value} {
                aa_equals "Sibling copied item '$copied_sibling_item_id' has the right $att"  $copied_sibling_item($att) $value
            }
            aa_equals "Sibling copied item '$copied_sibling_item_id' has an empty title. This is expected"  $copied_sibling_item(title) ""

            #########################################################
            # move the copy
            #########################################################
            #TODO

            #########################################################
            # delete the item
            #########################################################
            #TODO

            #########################################################
            # rename it
            #########################################################

            set new_name "__rename_new_name"
            content::item::rename  -item_id $new_type_item_id  -name $new_name
            content::item::get  -item_id $new_type_item_id  -array_name renamed_item
            aa_true "Item renamed"  {$new_name eq $renamed_item(name)}


            #########################################################
            # publish it
            #########################################################
            #TODO

            #########################################################
            # unpublish it
            #########################################################
            #TODO


            #########################################################
            # new from tmpfile
            #########################################################
            set tmp_item_name [ad_tmpnam "__content_item_test_XXXXXX"]
            set tmp_item_id [content::item::new  -name $tmp_item_name  -title $tmp_item_name  -parent_id $first_folder_id  -tmp_filename $::acs::rootdir/packages/acs-content-repository/tcl/test/test.html]

            aa_true "Item $tmp_item_id counts as null"  [content::item::content_is_null [db_string rev {
                    select live_revision from cr_items
                    where item_id = :tmp_item_id
                }]]

            aa_true "Tmp_filename added cr_item exists"  {[content::item::get_id  -item_path $tmp_item_name  -root_folder_id $first_folder_id]  eq $tmp_item_id}

            aa_true "Tmp_filename added cr_revision exists"  {[content::item::get_latest_revision  -item_id $tmp_item_id] ne ""}




            #########################################################
            # delete first folder and everything in it to clean up
            #########################################################
            content::folder::delete  -folder_id $second_folder_id

            content::folder::delete  -folder_id $first_folder_id  -cascade_p "t"
        }

}} {
          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" "content_item (body $body_count): Error during execution: $msg, stack trace: \n$::errorInfo"
          }
          incr body_count
        }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: