--[[
Copyright (c) 2013-2016 Isode Limited.
All rights reserved.
See the COPYING file for more information.
--]]
example_form = [[
Bot ConfigurationFill out this form to configure your new bot!jabber:botSection 1: Bot InfoThis ismy botSection 2: FeaturesnewssearchSection 3: Subscriber List20Section 4: InvitationsTell all your friends about your new bot!]]
form = sluift.from_xml(example_form)
--print(form)
-- Test form properties
assert(form['title'] == 'Bot Configuration')
-- Test boolean field
public_field = form['fields'][5]
assert(public_field['name'] == 'public')
assert(type(public_field['value']) == 'boolean')
assert(public_field['required'] == true)
-- Test multi field
features_field = form['fields'][8]
assert(features_field['name'] == 'features')
assert(type(features_field['value']) == 'table')
assert(#features_field['value'] == 2)
assert(features_field['value'][1] == 'news')
assert(features_field['value'][2] == 'search')
-- Test shortcut index
assert(form['features']['name'] == 'features')
assert(form['FORM_TYPE']['value'] == 'jabber:bot')
-- Test response form
submission = form:create_submission()
assert(#(submission.fields) == 8)
description_submit_value = submission['description']['value']
assert(type(description_submit_value) == 'table')
assert(description_submit_value[1] == 'This is')
assert(description_submit_value[2] == 'my bot')
submission['description'] = 'my description'
assert(submission['description']['value'] == 'my description')
submission['type'] = 'cancel'
-- Test text-multi field
text_multi_field = form['fields'][4]
assert(text_multi_field['name'] == 'description')
assert(type(text_multi_field['value']) == 'table')
--print(sluift.to_xml({type = 'form', data = form}))
-- test parsing an empty form -- this had issues as reported in SWIFT-174
empty_form = [[]]
form = sluift.from_xml(empty_form)
-- and check if we can access all fields without problems
assert(type(form._type))
assert(type(form.title))
assert(type(form.instructions))
assert(type(form.type))
assert(type(form.fields))
assert(type(form.items))
assert(type(form.reported_items))